Skip to content

Commit

Permalink
Merge pull request #42899 from Shadow-Devil/fix-redundant-casts
Browse files Browse the repository at this point in the history
Fix redundant casts
  • Loading branch information
warunalakshitha authored Jun 11, 2024
2 parents a92dce6 + 6874aa0 commit 04a642d
Show file tree
Hide file tree
Showing 47 changed files with 84 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static String getErrorStringValue(Throwable error) {
* @return Reformatted unicode string.
*/
public static String convertUnicode(char character) {
return "\\u{" + Integer.toHexString((int) character) + "}";
return "\\u{" + Integer.toHexString(character) + "}";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.ArrayType;
import io.ballerina.runtime.api.types.JsonType;
import io.ballerina.runtime.api.types.MapType;
import io.ballerina.runtime.api.types.StructureType;
Expand Down Expand Up @@ -385,7 +384,7 @@ private static Object convertMapToJson(BMap<?, ?> map, List<TypeValuePair> unres
}

private static Object convertArrayToJson(BArray array, List<TypeValuePair> unresolvedValues) {
BArray newArray = ValueCreator.createArrayValue((ArrayType) PredefinedTypes.TYPE_JSON_ARRAY);
BArray newArray = ValueCreator.createArrayValue(PredefinedTypes.TYPE_JSON_ARRAY);
for (int i = 0; i < array.size(); i++) {
Object newValue = convertToJsonType(array.get(i), unresolvedValues);
newArray.add(i, newValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BParameterizedType(Type paramValueType, int paramIndex) {

@Override
public <V extends Object> V getZeroValue() {
return (V) paramValueType.getZeroValue();
return paramValueType.getZeroValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public void addData(V data) {
checkInherentTypeViolation(dataMap, tableType);
K key = this.keyWrapper.wrapKey(dataMap);

if (containsKey((K) key)) {
if (containsKey(key)) {
throw ErrorCreator.createError(TABLE_HAS_A_VALUE_FOR_KEY_ERROR,
ErrorHelper.getErrorDetails(ErrorCodes.TABLE_HAS_A_VALUE_FOR_KEY, key));
}
Expand Down Expand Up @@ -680,7 +680,7 @@ public V putData(V data) {
if (entries.containsKey(hash)) {
return updateExistingEntry(key, data, entry, hash);
}
return putNewData((K) key, data, entry, hash);
return putNewData(key, data, entry, hash);
}

private V updateExistingEntry(K key, V data, Map.Entry<K, V> entry, Long hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void removeChildren(String qname) {
List<Integer> toRemove = new ArrayList<>();
for (int i = 0; i < children.size(); i++) {
BXml child = children.get(i);
if (child.getNodeType() == ELEMENT && ((XmlItem) child).getElementName().equals(qname)) {
if (child.getNodeType() == ELEMENT && child.getElementName().equals(qname)) {
toRemove.add(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public void visit(BLangJoinClause joinClause) {
}
this.scope = joinClause.env;
this.acceptNode(joinClause.collection, joinClause.env);
this.acceptNode((BLangNode) joinClause.onClause, joinClause.env);
this.acceptNode(joinClause.onClause, joinClause.env);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void visit(BLangFromClause fromClause) {
public void visit(BLangJoinClause joinClause) {
lookupNode(joinClause.collection);
lookupNode((BLangNode) joinClause.variableDefinitionNode);
lookupNode((BLangNode) joinClause.onClause);
lookupNode(joinClause.onClause);
}

@Override
Expand Down Expand Up @@ -639,7 +639,7 @@ public void visit(BLangRecordLiteral recordLiteral) {
@Override
public void visit(BLangTupleVarRef varRefExpr) {
lookupNodes(varRefExpr.expressions);
lookupNode((BLangNode) varRefExpr.restParam);
lookupNode(varRefExpr.restParam);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public void visit(BLangFromClause fromClause) {
@Override
public void visit(BLangJoinClause joinClause) {
find((BLangNode) joinClause.variableDefinitionNode);
find((BLangOnClause) joinClause.onClause);
find(joinClause.onClause);
find(joinClause.collection);
}

Expand Down Expand Up @@ -813,7 +813,7 @@ public void visit(BLangRecordLiteral recordLiteral) {
@Override
public void visit(BLangTupleVarRef varRefExpr) {
find(varRefExpr.expressions);
find((BLangNode) varRefExpr.restParam);
find(varRefExpr.restParam);
}

@Override
Expand All @@ -822,7 +822,7 @@ public void visit(BLangRecordVarRef varRefExpr) {
find(recordRefField.getBindingPattern());
}

find((BLangNode) varRefExpr.restParam);
find(varRefExpr.restParam);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8591,7 +8591,7 @@ private BLangInvocation createLanglibXMLInvocation(Location pos, String function
invocationNode.requiredArgs = requiredArgs;
invocationNode.restArgs = rewriteExprs(restArgs);

invocationNode.setBType(((BInvokableType) invocationNode.symbol.type).getReturnType());
invocationNode.setBType(invocationNode.symbol.type.getReturnType());
invocationNode.langLibInvocation = true;
return invocationNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ private List<BVarSymbol> getIntroducedSymbols(BLangVariable variable) {
} else {
// Simple binding
if (variable.symbol != null) {
symbols.add(((BLangSimpleVariable) variable).symbol);
symbols.add(variable.symbol);
}
}
return symbols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ public BLangNode transform(ObjectTypeDescriptorNode objTypeDescNode) {
}

if (objTypeDescNode.parent().kind() == SyntaxKind.DISTINCT_TYPE_DESC) {
((BLangType) objectTypeNode).flagSet.add(Flag.DISTINCT);
objectTypeNode.flagSet.add(Flag.DISTINCT);
}
return deSugarTypeAsUserDefType(objectTypeNode);
}
Expand Down Expand Up @@ -2362,7 +2362,7 @@ private Iterator<FunctionArgumentNode> getArgumentNodesIterator(NewExpressionNod
}
} else {
ParenthesizedArgList argList =
(ParenthesizedArgList) ((ExplicitNewExpressionNode) expression).parenthesizedArgList();
((ExplicitNewExpressionNode) expression).parenthesizedArgList();
argumentsIter = argList.arguments().iterator();
}

Expand Down Expand Up @@ -4184,8 +4184,8 @@ private BLangSimpleVariableDef getVariableDefinition(TypeDescriptorNode typeDesc

@Override
public BLangNode transform(IntersectionTypeDescriptorNode intersectionTypeDescriptorNode) {
BLangType lhsType = (BLangType) createTypeNode(intersectionTypeDescriptorNode.leftTypeDesc());
BLangType rhsType = (BLangType) createTypeNode(intersectionTypeDescriptorNode.rightTypeDesc());
BLangType lhsType = createTypeNode(intersectionTypeDescriptorNode.leftTypeDesc());
BLangType rhsType = createTypeNode(intersectionTypeDescriptorNode.rightTypeDesc());

BLangIntersectionTypeNode intersectionType;
if (rhsType.getKind() == NodeKind.INTERSECTION_TYPE_NODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private <T extends Node> List<T> cloneList(List<T> nodes) {
}
List<T> cloneList = new ArrayList<>(nodes.size());
for (T node : nodes) {
T clone = (T) clone(node);
T clone = clone(node);
cloneList.add(clone);
}
return cloneList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private BLangConstantValue calculateDivision(BLangConstantValue lhs, BLangConsta
dlog.error(currentPos, DiagnosticErrorCode.INT_RANGE_OVERFLOW_ERROR);
return new BLangConstantValue(null, this.currentConstSymbol.type);
}
result = (Long) ((Long) lhs.value / (Long) rhs.value);
result = (Long) lhs.value / (Long) rhs.value;
break;
case TypeTags.FLOAT:
result = String.valueOf(Double.parseDouble(String.valueOf(lhs.value))
Expand All @@ -501,7 +501,7 @@ private BLangConstantValue calculateMod(BLangConstantValue lhs, BLangConstantVal
switch (Types.getImpliedType(this.currentConstSymbol.type).tag) {
case TypeTags.INT:
case TypeTags.BYTE: // Byte will be a compiler error.
result = (Long) ((Long) lhs.value % (Long) rhs.value);
result = (Long) lhs.value % (Long) rhs.value;
break;
case TypeTags.FLOAT:
result = String.valueOf(Double.parseDouble(String.valueOf(lhs.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ public void visit(BLangJoinClause joinClause) {
(BLangVariable) joinClause.variableDefinitionNode.getVariable());
analyzeNode(joinClause.collection, env);
if (joinClause.onClause != null) {
analyzeNode((BLangNode) joinClause.onClause, env);
analyzeNode(joinClause.onClause, env);
}
}

Expand Down Expand Up @@ -2624,14 +2624,14 @@ private void checkAssignment(BLangExpression varRef) {
BLangRecordVarRef recordVarRef = (BLangRecordVarRef) varRef;
recordVarRef.recordRefFields.forEach(field -> checkAssignment(field.variableReference));
if (recordVarRef.restParam != null) {
checkAssignment((BLangExpression) recordVarRef.restParam);
checkAssignment(recordVarRef.restParam);
}
return;
case TUPLE_VARIABLE_REF:
BLangTupleVarRef tupleVarRef = (BLangTupleVarRef) varRef;
tupleVarRef.expressions.forEach(this::checkAssignment);
if (tupleVarRef.restParam != null) {
checkAssignment((BLangExpression) tupleVarRef.restParam);
checkAssignment(tupleVarRef.restParam);
}
return;
case ERROR_VARIABLE_REF:
Expand Down Expand Up @@ -2877,7 +2877,7 @@ private void populateUnusedVariableMapForMembers(Map<BSymbol, Location> unusedLo
populateUnusedVariableMapForMembers(unusedLocalVariables, member.valueBindingPattern);
}

populateUnusedVariableMapForMembers(unusedLocalVariables, (BLangVariable) recordVariable.restParam);
populateUnusedVariableMapForMembers(unusedLocalVariables, recordVariable.restParam);
break;
case TUPLE_VARIABLE:
BLangTupleVariable tupleVariable = (BLangTupleVariable) variable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public void visit(BLangJoinClause joinClause) {
SymbolEnv joinEnv = joinClause.env;
analyzeNode((BLangNode) joinClause.getVariableDefinitionNode(), joinEnv);
analyzeNode(joinClause.collection, joinEnv);
analyzeNode((BLangNode) joinClause.onClause, joinEnv);
analyzeNode(joinClause.onClause, joinEnv);
}

@Override
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public void visit(BLangTupleVarRef varRefExpr) {
analyzeNode(expression, env);
}

BLangExpression restParam = (BLangExpression) varRefExpr.restParam;
BLangExpression restParam = varRefExpr.restParam;
if (restParam != null) {
analyzeNode(restParam, env);
}
Expand All @@ -1178,7 +1178,7 @@ public void visit(BLangRecordVarRef varRefExpr) {
analyzeNode(recordRefField.variableReference, env);
}

BLangExpression restParam = (BLangExpression) varRefExpr.restParam;
BLangExpression restParam = varRefExpr.restParam;
if (restParam != null) {
analyzeNode(restParam, env);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2509,7 +2509,7 @@ private void checkRecordVarRefEquivalency(Location pos, BLangRecordVarRef lhsVar
if (Types.getImpliedType(varRefRest.getBType()).tag == TypeTags.RECORD) {
lhsRefType = varRefRest.getBType();
} else {
lhsRefType = ((BLangSimpleVarRef) lhsVarRef.restParam).getBType();
lhsRefType = lhsVarRef.restParam.getBType();
}

BType rhsRestConstraint = rhsRecordType.restFieldType == symTable.noType ? symTable.neverType
Expand Down Expand Up @@ -2604,7 +2604,7 @@ private void checkTupleVarRefEquivalency(Location pos, BLangTupleVarRef target,
if ((target.expressions.size() > i)) {
varRefExpr = target.expressions.get(i);
} else {
varRefExpr = (BLangExpression) target.restParam;
varRefExpr = target.restParam;
}

BType sourceType = sourceTypes.get(i);
Expand Down Expand Up @@ -4586,7 +4586,7 @@ private void setTypeOfVarRefForBindingPattern(BLangExpression expr, AnalyzerData
recordVarRef.recordRefFields
.forEach(refKeyValue -> setTypeOfVarRefForBindingPattern(refKeyValue.variableReference, data));
if (recordVarRef.restParam != null) {
setTypeOfVarRefForBindingPattern((BLangExpression) recordVarRef.restParam, data);
setTypeOfVarRefForBindingPattern(recordVarRef.restParam, data);
}
return;
case ERROR_VARIABLE_REF:
Expand Down Expand Up @@ -4624,7 +4624,7 @@ private void checkInvalidTypeDef(BLangExpression expr) {
checkInvalidTypeDef(tupleExpr);
}
if (tupleVarRef.restParam != null) {
checkInvalidTypeDef((BLangExpression) tupleVarRef.restParam);
checkInvalidTypeDef(tupleVarRef.restParam);
}
return;
case RECORD_VARIABLE_REF:
Expand All @@ -4633,7 +4633,7 @@ private void checkInvalidTypeDef(BLangExpression expr) {
checkInvalidTypeDef(refKeyValue.variableReference);
}
if (recordVarRef.restParam != null) {
checkInvalidTypeDef((BLangExpression) recordVarRef.restParam);
checkInvalidTypeDef(recordVarRef.restParam);
}
return;
case ERROR_VARIABLE_REF:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4294,9 +4294,9 @@ private void validateFieldsAndSetReadOnlyType(List<BLangNode> typeDefNodes, Symb

Set<Flag> flagSet;
if (typeNode.getKind() == NodeKind.OBJECT_TYPE) {
flagSet = ((BLangObjectTypeNode) typeNode).flagSet;
flagSet = typeNode.flagSet;
} else if (typeNode.getKind() == NodeKind.USER_DEFINED_TYPE) {
flagSet = ((BLangUserDefinedType) typeNode).flagSet;
flagSet = typeNode.flagSet;
} else {
flagSet = new HashSet<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ private BType computeIntersectionType(BLangIntersectionTypeNode intersectionType
if (typeNode == null) {
flagSet = new HashSet<>();
} else if (typeNode.getKind() == NodeKind.OBJECT_TYPE) {
flagSet = ((BLangObjectTypeNode) typeNode).flagSet;
flagSet = typeNode.flagSet;
} else if (typeNode.getKind() == NodeKind.USER_DEFINED_TYPE) {
flagSet = typeNode.flagSet;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private BType getTypeMatchingFloatOrDecimal(BType finiteType, List<BType> member
}
}

finiteType = getFiniteTypeWithValuesOfSingleType((BUnionType) expType, type);
finiteType = getFiniteTypeWithValuesOfSingleType(expType, type);
if (finiteType != symTable.semanticError) {
BType setType = setLiteralValueAndGetType(literalExpr, finiteType, data);
if (literalExpr.isFiniteContext) {
Expand Down Expand Up @@ -3270,7 +3270,7 @@ public void visit(BLangRecordVarRef varRefExpr, AnalyzerData data) {
fields.put(field.name.value, field);
}

BLangExpression restParam = (BLangExpression) varRefExpr.restParam;
BLangExpression restParam = varRefExpr.restParam;
if (restParam != null) {
checkExpr(restParam, data);
unresolvedReference = !isValidVariableReference(restParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ private BType blangTypeUpdate(BLangExpression expression) {
expression.setBType(type);
return type;
case LITERAL:
return ((BLangLiteral) expression).getBType();
return expression.getBType();
case BINARY_EXPR:
type = blangTypeUpdate(((BLangBinaryExpr) expression).lhsExpr);
expression.setBType(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ public BType updateSelfReferencedWithNewType(BType source, BType s, BType target
return new BTableType(tableType.tag, target, tableType.tsymbol,
tableType.flags);
} else if (tableType.constraint instanceof BMapType) {
return updateSelfReferencedWithNewType(source, (BMapType) tableType.constraint, target);
return updateSelfReferencedWithNewType(source, tableType.constraint, target);
}
}
return s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static Minutiae createWhitespaceMinutiae(String text) {
// TODO Validate the given text for whitespace characters
STMinutiae internalNode = (STMinutiae) STNodeFactory.createMinutiae(
SyntaxKind.WHITESPACE_MINUTIAE, text);
return Minutiae.createUnlinked((STMinutiae) internalNode);
return Minutiae.createUnlinked(internalNode);
}

public static Minutiae createEndOfLineMinutiae(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static BXml selectDescendants(BXml xml, BString[] qnames) {
}
qnameList.add(strQname);
}
return (BXml) xml.descendants(qnameList);
return xml.descendants(qnameList);
} catch (Throwable e) {
ErrorHelper.handleXMLException(OPERATION, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class Elements {
public static BXml elements(BXml xml, Object name) {
try {
if (name instanceof BString) {
return (BXml) xml.elements(((BString) name).getValue());
return xml.elements(((BString) name).getValue());
}
return (BXml) xml.elements();
return xml.elements();
} catch (Throwable e) {
ErrorHelper.handleXMLException(OPERATION, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public static BXml get(BXml xmlVal, long i) {
throw ErrorHelper.getRuntimeException(ErrorCodes.XML_SEQUENCE_INDEX_OUT_OF_RANGE, size, i);
}

return (BXml) childrenList.get((int) i);
return childrenList.get((int) i);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public static BMap<BString, BString> getAttributes(BXml xmlVal) {
"getAttributes", "element");
}

return (BMap<BString, BString>) xmlVal.getAttributesMap();
return xmlVal.getAttributesMap();
}
}
Loading

0 comments on commit 04a642d

Please sign in to comment.