private static JavaType filterWildcard(JavaType javaType) { if (javaType.isTagged(JavaType.WILDCARD)) { return ((WildCardType) javaType).bound; } return javaType; }
public void completeMissingType() { if(type == null || ((JavaType) type).isTagged(JavaType.DEFERRED)) { type = Symbols.unknownType; } }
public void completeMissingType() { if(type == null || ((JavaType) type).isTagged(JavaType.DEFERRED)) { type = Symbols.unknownType; } }
@Override public boolean is(String fullyQualifiedName) { if (tag < CLASS) { // primitive type return fullyQualifiedName.equals(symbol.name); } else if (isTagged(ARRAY)) { return fullyQualifiedName.endsWith("[]") && ((ArrayJavaType) this).elementType.is(fullyQualifiedName.substring(0, fullyQualifiedName.length() - 2)); } else if (isTagged(TYPEVAR)) { return false; } return false; }
public JavaType getUninferedType() { if (uninferedType == null) { return this; } if (uninferedType.isTagged(JavaType.TYPEVAR)) { // produced by a parameterized method where we have not been able to infer return type, so fallback on its leftmost bound return uninferedType.erasure(); } return uninferedType; } }
@Override public boolean isSubtypeOf(String fullyQualifiedName) { if (isTagged(ARRAY)) { return "java.lang.Object".equals(fullyQualifiedName) || (fullyQualifiedName.endsWith("[]") && ((ArrayJavaType) this).elementType.isSubtypeOf(fullyQualifiedName.substring(0, fullyQualifiedName.length() - 2))); } else if (isTagged(TYPEVAR)) { return erasure().isSubtypeOf(fullyQualifiedName); } return false; }
@Override public boolean isSubtypeOf(String fullyQualifiedName) { if (isTagged(ARRAY)) { return "java.lang.Object".equals(fullyQualifiedName) || (fullyQualifiedName.endsWith("[]") && ((ArrayJavaType) this).elementType.isSubtypeOf(fullyQualifiedName.substring(0, fullyQualifiedName.length() - 2))); } else if (isTagged(TYPEVAR)) { return erasure().isSubtypeOf(fullyQualifiedName); } return false; }
private static boolean isUnnecessaryLambdaCast(Type childType, Type parentType) { if (parentType.isSubtypeOf(childType)) { return true; } // intersection type on lambda should not raise an issue : required to make lambda serializable for instance if (((JavaType) childType).isTagged(JavaType.INTERSECTION)) { return false; } List<MethodJavaSymbol> childMethods = getMethodSymbolsOf(childType).collect(Collectors.toList()); return childMethods.isEmpty() || (childMethods.size() == 1 && isSingleAbstractMethodOverride(childMethods.get(0), parentType)); }
private static boolean isUnnecessaryLambdaCast(Type childType, Type parentType) { if (parentType.isSubtypeOf(childType)) { return true; } // intersection type on lambda should not raise an issue : required to make lambda serializable for instance if (((JavaType) childType).isTagged(JavaType.INTERSECTION)) { return false; } List<MethodJavaSymbol> childMethods = getMethodSymbolsOf(childType).collect(Collectors.toList()); return childMethods.isEmpty() || (childMethods.size() == 1 && isSingleAbstractMethodOverride(childMethods.get(0), parentType)); }
@Override public boolean isSubtypeOf(Type superType) { JavaType supType = (JavaType) superType; // Handle covariance of arrays. if (supType.isTagged(ARRAY)) { return elementType.isSubtypeOf(((ArrayType) supType).elementType()); } if (supType.isTagged(WILDCARD)) { return ((WildCardType) superType).isSubtypeOfBound(this); } // Only possibility to be supertype of array without being an array is to be Object. return "java.lang.Object".equals(supType.fullyQualifiedName()); }
private TypeSubstitution inferTypeSubstitutionInWildcardType(MethodJavaSymbol method, TypeSubstitution substitution, WildCardType formalType, JavaType argType, boolean variableArity, List<JavaType> remainingArgTypes) { JavaType newArgType = argType; if (argType.isTagged(JavaType.WILDCARD)) { newArgType = ((WildCardType) argType).bound; } TypeSubstitution newSubstitution = inferTypeSubstitution(method, substitution, formalType.bound, newArgType, variableArity, remainingArgTypes); return mergeTypeSubstitutions(substitution, newSubstitution); }
private TypeSubstitution inferTypeSubstitutionInWildcardType(MethodJavaSymbol method, TypeSubstitution substitution, WildCardType formalType, JavaType argType, boolean variableArity, List<JavaType> remainingArgTypes) { JavaType newArgType = argType; if (argType.isTagged(JavaType.WILDCARD)) { newArgType = ((WildCardType) argType).bound; } TypeSubstitution newSubstitution = inferTypeSubstitution(method, substitution, formalType.bound, newArgType, variableArity, remainingArgTypes); return mergeTypeSubstitutions(substitution, newSubstitution); }
private boolean isRedundantCast(JavaType cast, JavaType expressionType) { JavaType erasedExpressionType = expressionType; if(erasedExpressionType.isTagged(JavaType.TYPEVAR)) { erasedExpressionType = erasedExpressionType.erasure(); } return erasedExpressionType.equals(cast) || (!(cast instanceof JavaType.ParametrizedTypeJavaType) && !cast.isNumerical() && erasedExpressionType.isSubtypeOf(cast)); }
private static boolean subtypeOfTypeVar(JavaType arg, TypeVariableJavaType formal) { for (JavaType bound : formal.bounds()) { if ((bound.isTagged(JavaType.TYPEVAR) && !subtypeOfTypeVar(arg, (TypeVariableJavaType) bound)) || !arg.isSubtypeOf(bound)) { return false; } } return true; }
@Override public boolean isSubtypeOf(Type superType) { if (((JavaType) superType).isTagged(TYPEVAR)) { return false; } if (erasure() == superType.erasure()) { return !((JavaType) superType).isParameterized() || checkSubstitutedTypesCompatibility((ParametrizedTypeJavaType) superType); } if (verifySuperTypes(superType)) { return true; } return ((JavaType) superType).isTagged(WILDCARD) && ((WildCardType) superType).isSubtypeOfBound(this); }
private void checkCast(Type type, MethodInvocationTree mit) { if (type.isArray() && !type.is("java.lang.Object[]")) { Type elementType = ((Type.ArrayType) type).elementType(); if (!((JavaType) elementType).isTagged(JavaType.TYPEVAR)) { reportIssue(mit, "Pass \"new " + elementType.name() + "[0]\" as argument to \"toArray\"."); } } } }
@Override public void visitExpressionStatement(ExpressionStatementTree tree) { super.visitExpressionStatement(tree); ExpressionTree expression = tree.expression(); if (((JavaType) expression.symbolType()).isTagged(JavaType.DEFERRED) && expression.is(Tree.Kind.NEW_CLASS)) { JavaType parametrizedTypeWithObject = resolve.parametrizedTypeWithErasure((ParametrizedTypeJavaType) getType(((NewClassTree) expression).identifier())); setInferedType(parametrizedTypeWithObject, (DeferredType) expression.symbolType()); } }
@Override public void visitExpressionStatement(ExpressionStatementTree tree) { super.visitExpressionStatement(tree); ExpressionTree expression = tree.expression(); if (((JavaType) expression.symbolType()).isTagged(JavaType.DEFERRED) && expression.is(Tree.Kind.NEW_CLASS)) { JavaType parametrizedTypeWithObject = resolve.parametrizedTypeWithErasure((ParametrizedTypeJavaType) getType(((NewClassTree) expression).identifier())); setInferedType(parametrizedTypeWithObject, (DeferredType) expression.symbolType()); } }