@CheckForNull private static TypeTree getMethodReturnType(ReturnStatementTree returnStatementTree) { MethodTree methodTree = getParentMethod(returnStatementTree); if (methodTree != null) { return methodTree.returnType(); } return null; }
@Override public void visitMethod(MethodTree methodTree) { if (methodTree.returnType() != null ) { String returnTypeName = methodTree.returnType().symbolType().fullyQualifiedName(); checkIfDisallowed(returnTypeName, methodTree.returnType()); } super.visitMethod(methodTree); }
@Override public void visitMethod(MethodTree tree) { checkTypes(tree.returnType()); super.visitMethod(tree); }
private static Optional<String> lookupMatchingStandardInterface(MethodSymbol functionalMethod) { MethodTree declaration = functionalMethod.declaration(); if (!functionalMethod.thrownTypes().isEmpty() || (declaration != null && !declaration.typeParameters().isEmpty())) { return Optional.empty(); } Type returnType = declaration != null ? declaration.returnType().symbolType() : functionalMethod.returnType().type(); return STD_INTERFACE_BY_PARAMETER_COUNT.getOrDefault(functionalMethod.parameterTypes().size(), Collections.emptyList()).stream() .map(standardInterface -> standardInterface.matchingSpecialization(functionalMethod, returnType)) .filter(Objects::nonNull) .findFirst(); }
private static boolean isVoid(MethodTree methodTree) { TypeTree typeTree = methodTree.returnType(); return typeTree.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) typeTree).keyword().text()); } }
private static boolean isFinalizeMethodMember(MethodTree methodTree) { Tree returnType = methodTree.returnType(); boolean returnVoid = returnType != null && returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); return returnVoid && "finalize".equals(methodTree.simpleName().name()); }
private List<? extends Tree> visitMethod(MethodTree tree) { BlockTree methodBody = tree.block(); if(methodBody != null) { // get the last TypeTree returnType = tree.returnType(); if(returnType == null || "void".equals(returnType.firstToken().text())) { executableLines.add(methodBody.closeBraceToken().line()); } return methodBody.body(); } return Collections.emptyList(); }
private static boolean isFinalize(MethodTree methodTree) { if ("finalize".equals(methodTree.simpleName().name())) { Tree returnType = methodTree.returnType(); if (returnType != null && returnType.is(Tree.Kind.PRIMITIVE_TYPE)) { return "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); } } return false; }
private boolean hasNonVoidReturnType(Tree tree) { // Backward compatibility : ignore methods from annotations. if (tree.is(Tree.Kind.METHOD) && !classTrees.peek().is(Tree.Kind.ANNOTATION_TYPE)) { Tree returnType = ((MethodTree) tree).returnType(); return returnType == null || !(returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text())); } return false; }
private static boolean isFinalize(MethodTree methodTree) { if ("finalize".equals(methodTree.simpleName().name())) { Tree returnType = methodTree.returnType(); if (returnType != null && returnType.is(Tree.Kind.PRIMITIVE_TYPE)) { return "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); } } return false; } }
@Override public void visitNode(Tree tree) { if (!hasSemantic()) { return; } MethodTree methodTree = (MethodTree) tree; TypeTree returnType = methodTree.returnType(); if (returnType.symbolType().isPrimitive()) { findNullableAnnotation(methodTree) .ifPresent(annotation -> reportIssue(returnType, String.format("\"%s\" annotation should not be used on primitive types", annotation))); } }
private static boolean isSetter(MethodTree methodTree) { TypeTree returnType = methodTree.returnType(); BlockTree block = methodTree.block(); boolean returnsVoid = returnType.is(Tree.Kind.PRIMITIVE_TYPE) && "void".equals(((PrimitiveTypeTree) returnType).keyword().text()); boolean hasAtLeastOneStatement = block == null || !block.body().isEmpty(); return methodTree.simpleName().name().startsWith("set") && methodTree.parameters().size() == 1 && returnsVoid && hasAtLeastOneStatement; } }
@Override public boolean apply(MethodTree methodTree) { return methodTree.simpleName().name().startsWith(getStartName()) && methodTree.parameters().size() == 1 && methodTree.returnType().symbolType().is("void"); } };
@Override public boolean apply(MethodTree methodTree) { return methodTree.simpleName().name().startsWith(getStartName()) && methodTree.parameters().isEmpty() && !methodTree.returnType().symbolType().is("void"); } };
@Override public boolean apply(MethodTree methodTree) { return methodTree.simpleName().name().startsWith(getStartName()) && methodTree.parameters().isEmpty() && !methodTree.returnType().symbolType().is("void"); } };
@Override public void visitNode(Tree tree) { MethodTree methodTree = (MethodTree) tree; if (!isPrivate(methodTree) && !isOverriding(methodTree)) { methodTree.returnType().accept(new CheckWildcard()); } }
MethodInvariantContext(MethodTree methodTree) { this.methodTree = methodTree; TypeTree returnType = methodTree.returnType(); this.returnStatementTrees = extractReturnStatements(methodTree); methodToCheck = !isConstructorOrVoid(methodTree, returnType) && returnStatementTrees.size() > 1; returnImmutableType = methodToCheck && (returnType.symbolType().isPrimitive() || returnType.symbolType().is("java.lang.String")); }
@Override public void visitMethod(MethodTree tree) { super.visitMethod(tree); if (isPublic(tree.modifiers()) && Boolean.FALSE.equals(tree.isOverriding())) { checkIfAllowed(tree.returnType(), "The return type of this method "); for (VariableTree variableTree : tree.parameters()) { checkIfAllowed(variableTree.type(), "The type of the \"" + variableTree.simpleName() + "\" object "); } } }
@Override public void visitMethod(MethodTree tree) { scan(tree.modifiers()); scan(tree.typeParameters()); scan(tree.returnType()); // skip the simple name scan(tree.parameters()); scan(tree.defaultValue()); scan(tree.throwsClauses()); scan(tree.block()); } }
@Override public void visitMethod(MethodTree tree) { scan(tree.modifiers()); scan(tree.typeParameters()); scan(tree.returnType()); scan(tree.simpleName()); scan(tree.parameters()); scan(tree.defaultValue()); scan(tree.throwsClauses()); scan(tree.block()); }