private static String methodTreeType(MethodTree tree) { return tree.is(Tree.Kind.CONSTRUCTOR) ? "constructor" : "method"; }
private static boolean isNotMethodFromSerializable(MethodTree methodTree, Symbol symbol) { return methodTree.is(Tree.Kind.METHOD) && !SerializableContract.SERIALIZABLE_CONTRACT_METHODS.contains(symbol.name()); } }
private static boolean isNotMethodFromSerializable(MethodTree methodTree, Symbol symbol) { return methodTree.is(Tree.Kind.METHOD) && !SerializableContract.SERIALIZABLE_CONTRACT_METHODS.contains(symbol.name()); } }
private static boolean isExcluded(MethodTree tree) { return tree.is(Tree.Kind.CONSTRUCTOR) || EXCLUDED_SERIALIZABLE_METHODS.anyMatch(tree); }
private static boolean isConstructorWithParameters(MethodTree methodTree) { return methodTree.is(Tree.Kind.CONSTRUCTOR) && !methodTree.parameters().isEmpty(); }
private boolean isConstructorOrAfterCreatedMethod(MethodTree tree) { return tree.is(MethodTree.Kind.CONSTRUCTOR) || (implementedInitializableModel && "afterCreated".equals(tree.symbol().name())); } }
@Override public void visitMethod(MethodTree tree) { if (tree.is(Tree.Kind.METHOD)) { checkMethodTree((MethodTreeImpl) tree); } super.visitMethod(tree); }
private static boolean isEmptyDefaultConstructor(MethodTree constructor) { return constructor.is(Tree.Kind.CONSTRUCTOR) && constructor.parameters().isEmpty() && constructor.block().body().isEmpty(); }
private static boolean constructorOfNonPublicClass(MethodTree methodTree, ClassTree classTree) { return methodTree.is(Kind.CONSTRUCTOR) && !hasPublic(classTree.modifiers()); }
private static boolean isPublicMethod(MethodTree methodTree) { return methodTree.is(Tree.Kind.METHOD) && ModifiersUtils.hasModifier(methodTree.modifiers(), Modifier.PUBLIC); }
@Override public void visitMethod(MethodTree tree) { if (tree.is(Tree.Kind.METHOD)) { checkMethodTree((MethodTreeImpl) tree); } super.visitMethod(tree); }
private void reportUnusedPrivateMethods() { unusedPrivateMethods.stream() .filter(methodTree -> !unresolvedMethodNames.contains(methodTree.simpleName().name())) .forEach(methodTree -> { IdentifierTree simpleName = methodTree.simpleName(); reportIssue(simpleName, String.format("Remove this unused private \"%s\" %s.", simpleName.name(), methodTree.is(Tree.Kind.CONSTRUCTOR) ? "constructor" : "method")); }); }
@Override public void visitMethod(MethodTree tree) { if (tree.block() == null || tree.is(Tree.Kind.CONSTRUCTOR)) { // skip everything for abstract methods (from interfaces or abstract class) and constructors return; } tree.parameters().stream() .filter(p -> IS_ZIP_ENTRY.test(p.symbol().type())) .forEach(p -> context.reportIssue(this, p, ISSUE_MESSAGE)); super.visitMethod(tree); }
@Override public void visitMethod(MethodTree tree) { super.visitMethod(tree); BlockTree block = tree.block(); if (block != null && block.body().isEmpty() && !tree.is(Kind.CONSTRUCTOR) && !containsComment(block)) { context.addIssue(tree, this, "Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation."); } }
@Override public void visitMethod(MethodTree tree) { if (tree.is(MethodTree.Kind.CONSTRUCTOR)) { tree.accept(new CheckUsageInConstructorVisitor(this, context, methodParams(tree))); } super.visitMethod(tree); }
@Override public void visitMethod(MethodTree tree) { super.visitMethod(tree); if ((tree.is(Tree.Kind.CONSTRUCTOR) || isNotOverridden(tree)) && isNotMainMethod(tree)) { for (TypeTree throwClause : tree.throwsClauses()) { Type exceptionType = throwClause.symbolType(); if (isRawException(exceptionType) && !exceptionsThrownByMethodInvocations.contains(exceptionType)) { reportIssue(throwClause); } } } exceptionsThrownByMethodInvocations.clear(); }
@Override public void visitMethod(MethodTree tree) { if ((tree.is(Tree.Kind.CONSTRUCTOR) || isNotOverriden(tree)) && !((MethodTreeImpl) tree).isMainMethod()) { for (TypeTree throwClause : tree.throwsClauses()) { checkExceptionAndRaiseIssue(throwClause); } } super.visitMethod(tree); }
@Override public void visitMethod(MethodTree method) { if (!method.is(Tree.Kind.CONSTRUCTOR) && returnsOptional(method)) { // check that the method is not annotated with @Nullable checkNullableAnnotation(method.modifiers(), "Methods with an \"Optional\" return type should not be \"@Nullable\"."); // check that the method does not return "null" method.accept(new ReturnNullVisitor()); } super.visitMethod(method); }
private void visitMethodWithMVM(IdentifierTree modifiableValueMapUsageIdentifier, Tree usageOfMVM) { int argumentNumber = ((Arguments) usageOfMVM).indexOf(modifiableValueMapUsageIdentifier); MethodInvocationTree methodInvocationWithMVM = (MethodInvocationTree) usageOfMVM.parent(); if (methodInvocationWithMVM != null) { MethodTree methodWithMVM = (MethodTree) methodInvocationWithMVM.symbol().declaration(); if (methodWithMVM != null && methodWithMVM.is(Tree.Kind.METHOD)) { MethodWithMVMVisitor methodWithMVMVisitor = new MethodWithMVMVisitor(this, argumentNumber); methodWithMVM.accept(methodWithMVMVisitor); } } }
@Override public void visitMethod(MethodTree method) { if (!method.is(Tree.Kind.CONSTRUCTOR) && returnsOptional(method)) { // check that the method is not annotated with @Nullable checkNullableAnnotation(method.modifiers(), "Methods with an \"Optional\" return type should not be \"@Nullable\"."); // check that the method does not return "null" method.accept(new ReturnNullVisitor()); } super.visitMethod(method); }