PlaceholderMethod.create( tree.getName(), templater.template(sym.getReturnType()), params.build(), UTemplater.annotationMap(sym)));
switch (methodSymbol.getReturnType().getKind()) { case TYPEVAR: retType = (TypeVar) methodSymbol.getReturnType(); break; default:
&& funcInterfaceMethod.getReturnType().getKind() != TypeKind.VOID) { ExpressionTree resExpr = (ExpressionTree) tree.getBody(); return checkReturnExpression(tree, resExpr, funcInterfaceMethod, state);
!methodSymbol.isStatic() && ((methodSymbol.flags() & Flags.SYNTHETIC) == 0) && types.isSameType(methodSymbol.getReturnType(), state.getSymtab().booleanType) && methodSymbol.getParameters().size() == 1 && types.isSameType(
Type returnType = methodSymbol.getReturnType(); if (ImmutableCollections.isImmutableType(returnType)) { return Description.NO_MATCH;
ASTHelpers.getUpperBound(superSym.getReturnType(), state.getTypes()), futureType, state)) { return false; Type returnType = sym.getReturnType(); return ASTHelpers.isSubtype( ASTHelpers.getUpperBound(returnType, state.getTypes()), futureType, state);
if (!ASTHelpers.isVoidType(method.getReturnType(), state)) { return Description.NO_MATCH;
@Override public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { boolean matches = specializedMatcher().matches(tree, state); if (!matches) { return Description.NO_MATCH; } if (lenient()) { boolean isUnusedReturnValue = allOf( AbstractReturnValueIgnored::isNotConstructorReference, AbstractReturnValueIgnored::isVoidReturningMethodReferenceExpression, // Skip cases where the method we're referencing really does return void. We're only // looking for cases where the referenced method does not return void, but it's being // used on a void-returning functional interface. not((t, s) -> isVoidType(getSymbol(tree).getReturnType(), s)), not((t, s) -> isThrowingFunctionalInterface(s, ((JCMemberReference) t).type)) ).matches(tree, state); if (!isUnusedReturnValue) { if (isValidReturnValueType(tree, state)) { return Description.NO_MATCH; } } } return describeMatch(tree); }
private Description checkReturnExpression( Tree tree, ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol, VisitorState state) { Type returnType = methodSymbol.getReturnType(); if (returnType.isPrimitive()) { // check for unboxing return doUnboxingCheck(state, retExpr); } if (returnType.toString().equals("java.lang.Void")) { return Description.NO_MATCH; } if (NullabilityUtil.isUnannotated(methodSymbol, config) || Nullness.hasNullableAnnotation(methodSymbol)) { return Description.NO_MATCH; } if (mayBeNullExpr(state, retExpr)) { String message = "returning @Nullable expression from method with @NonNull return type"; return createErrorDescriptionForNullAssignment( MessageTypes.RETURN_NULLABLE, tree, message, retExpr, state.getPath()); } return Description.NO_MATCH; }
private String getMethodSignature(Symbol.MethodSymbol method) { // Generate method signature String methodSign = method.enclClass().getQualifiedName().toString() + ":" + (method.isStaticOrInstanceInit() ? "" : getSimpleTypeName(method.getReturnType()) + " ") + method.getSimpleName() + "("; if (!method.getParameters().isEmpty()) { for (Symbol.VarSymbol var : method.getParameters()) { methodSign += getSimpleTypeName(var.type) + ", "; } methodSign = methodSign.substring(0, methodSign.lastIndexOf(',')); } methodSign += ")"; LOG(DEBUG, "DEBUG", "@ method sign: " + methodSign); return methodSign; }
/** Allow creating obsolete types when overriding a method with an obsolete return type. */ private static boolean implementingObsoleteMethod( MethodTree enclosingMethod, VisitorState state, Type type) { MethodSymbol method = ASTHelpers.getSymbol(enclosingMethod); if (method == null) { return false; } if (ASTHelpers.findSuperMethods(method, state.getTypes()).isEmpty()) { // not an override return false; } if (!ASTHelpers.isSameType(method.getReturnType(), type, state)) { return false; } return true; } }
@Override public Description matchMethod(MethodTree tree, VisitorState state) { MethodSymbol sym = ASTHelpers.getSymbol(tree); if (sym == null) { return NO_MATCH; } if (sym.getReturnType().getKind() != TypeKind.VOID) { return NO_MATCH; } AnnotationTree annotation = ASTHelpers.getAnnotationWithSimpleName(tree.getModifiers().getAnnotations(), "Nullable"); if (annotation == null) { return NO_MATCH; } return describeMatch(annotation, SuggestedFix.delete(annotation)); } }
private boolean booleanReturnType(MethodInvocationNode node) { Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(node.getTree()); return methodSymbol != null && methodSymbol.getReturnType().getTag() == TypeTag.BOOLEAN; }
static ClassAndMethod make(MethodSymbol methodSymbol, @Nullable Types types) { // TODO(b/71812955): consider just wrapping methodSymbol instead of copying everything out. ImmutableList<String> annotations = MoreAnnotations.getDeclarationAndTypeAttributes(methodSymbol) .map(Object::toString) .collect(toImmutableList()); ClassSymbol clazzSymbol = (ClassSymbol) methodSymbol.owner; return new ClassAndMethod( clazzSymbol.getQualifiedName().toString(), methodSymbol.getSimpleName().toString(), annotations, methodSymbol.isStatic(), methodSymbol.getReturnType().isPrimitive(), methodSymbol.getReturnType().getTag() == BOOLEAN, hasGenericResult(methodSymbol), knownNonNullMethod(methodSymbol, clazzSymbol, types)); }
@Override public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { if (allOf( (t, s) -> t.getMode() == ReferenceMode.INVOKE, AbstractReturnValueIgnored::isVoidReturningMethodReferenceExpression, // Skip cases where the method we're referencing really does return void. We're only // looking for cases where the referenced method does not return void, but it's being // used on a void-returning functional interface. not((t, s) -> ASTHelpers.isVoidType(ASTHelpers.getSymbol(tree).getReturnType(), s)), not((t, s) -> isThrowingFunctionalInterface(s, ((JCMemberReference) t).type)), specializedMatcher()) .matches(tree, state)) { return describeMatch(tree); } return Description.NO_MATCH; }
Select select(GuardedByExpression base, Symbol.MethodSymbol member) { return Select.create(base, member, member.getReturnType()); }
@Override public Description matchMethod(MethodTree tree, VisitorState state) { MethodSymbol sym = ASTHelpers.getSymbol(tree); if (sym == null) { return NO_MATCH; } return check(sym.getReturnType(), tree.getModifiers().getAnnotations()); }
/** * Returns {@code true} for {@link MethodSymbol}s whose result type is a generic type variable. */ private static boolean hasGenericResult(MethodSymbol methodSymbol) { return methodSymbol.getReturnType().tsym instanceof TypeVariableSymbol; }
@Override public Void visitReturn(ReturnTree node, Void unused) { if (node.getExpression() != null && currentMethodOrInitializerOrLambda instanceof MethodTree) { Type returnType = ((MethodSymbol) TreeInfo.symbolFor((JCTree) currentMethodOrInitializerOrLambda)) .getReturnType(); generateConstraintsForWrite(returnType, node.getExpression(), node); } return super.visitReturn(node, unused); }
private boolean isIgnoredReturnType(JCMethodDecl method, VisitorState state) { Type returnType = method.sym.getReturnType(); // Methods returning a primitive cannot return null. Also ignore Void-returning methods as // the only valid Void value is null, so it's implied. // TODO(kmb): Technically we should assume NULL when we see a call to a method that returns Void return returnType.isPrimitiveOrVoid() || state.getTypes().isSameType(returnType, state.getTypeFromString("java.lang.Void")); }