@Override public boolean matches(MethodTree methodTree, VisitorState state) { return methodTree.getName().contentEquals(methodName); } };
@Override public boolean matches(MethodTree methodTree, VisitorState state) { return methodTree.getName().toString().startsWith(prefix); } };
private static Optional<String> getName(Tree tree) { if (tree instanceof MethodTree) { return Optional.of(((MethodTree) tree).getName().toString()); } if (tree instanceof ClassTree) { return Optional.of(((ClassTree) tree).getSimpleName().toString()); } return Optional.empty(); } }
private void handleMapAnonClass( MaplikeMethodRecord methodRecord, MethodInvocationTree observableDotMap, ClassTree annonClassBody, VisitorState state) { for (Tree t : annonClassBody.getMembers()) { if (t instanceof MethodTree && ((MethodTree) t).getName().toString().equals(methodRecord.getInnerMethodName())) { observableCallToInnerMethodOrLambda.put(observableDotMap, (MethodTree) t); } } }
private void handleFilterAnonClass( StreamTypeRecord streamType, MethodInvocationTree observableDotFilter, ClassTree annonClassBody, VisitorState state) { for (Tree t : annonClassBody.getMembers()) { if (t instanceof MethodTree && ((MethodTree) t).getName().toString().equals("test")) { filterMethodOrLambdaSet.add(t); observableCallToInnerMethodOrLambda.put(observableDotFilter, (MethodTree) t); handleChainFromFilter(streamType, observableDotFilter, t, state); } } }
private String getSuggestedSignature() { return String.format("%s(%s)", methodTree().getName(), getSuggestedParameters()); }
@Override public Description matchMethod(MethodTree tree, VisitorState state) { return handle(tree, tree.getName(), tree.getModifiers(), state); }
@Override public boolean matches(MethodTree methodTree, VisitorState state) { return ASTHelpers.getSymbol(methodTree) .getEnclosingElement() .getQualifiedName() .contentEquals(className) && methodTree.getName().contentEquals(methodName); } };
@Override public Description matchClass(ClassTree classTree, VisitorState state) { if (!ASTHelpers.isSubtype( ASTHelpers.getType(classTree), state.getSymtab().throwableType, state)) { return Description.NO_MATCH; } ImmutableList<MethodTree> methods = classTree.getMembers().stream() .filter(m -> m instanceof MethodTree) .map(m -> (MethodTree) m) .collect(toImmutableList()); if (methods.stream().anyMatch(m -> m.getName().contentEquals("getMessage"))) { return Description.NO_MATCH; } return methods.stream() .filter(m -> Matchers.toStringMethodDeclaration().matches(m, state)) .findFirst() .map(m -> describeMatch(classTree, SuggestedFixes.renameMethod(m, "getMessage", state))) .orElse(Description.NO_MATCH); } }
private void processImplementationMethod(MethodTree methodTree) { String methodName = methodTree.getName().toString(); if ("toString".equals(methodName) || "equals".equals(methodName)
String fixedName = methodTree.getName().toString();
@Override public Description matchLiteral(LiteralTree tree, VisitorState state) { // Is there a literal matching the message SWIG uses to indicate a // destructor problem? if (tree.getValue() == null || !tree.getValue().equals("C++ destructor does not have public access")) { return NO_MATCH; } // Is it within a delete method? MethodTree enclosingMethodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class); Name name = enclosingMethodTree.getName(); if (!name.contentEquals("delete")) { return NO_MATCH; } // Does the enclosing class lack a finalizer? if (ENCLOSING_CLASS_HAS_FINALIZER.matches(enclosingMethodTree, state)) { return NO_MATCH; } return buildDescription(tree).build(); } }
SuggestedFixes.addModifiers(method, state, Modifier.FINAL); if (optionalSuggestedFix.isPresent()) { matchedMethods.add(method.getName().toString()); fix.merge(optionalSuggestedFix.get()); if (firstMatchedMethod == null) {
@Override public boolean matches(TryTree tryTree, VisitorState state) { MethodTree enclosingMethodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class); if (enclosingMethodTree == null) { // e.g. a class initializer return true; } Name name = enclosingMethodTree.getName(); return JUnitMatchers.looksLikeJUnit3SetUp.matches(enclosingMethodTree, state) || JUnitMatchers.looksLikeJUnit3TearDown.matches(enclosingMethodTree, state) || name.contentEquals("main") // TODO(schmitt): Move to JUnitMatchers? || name.contentEquals("suite") || Matchers.hasAnnotation(JUNIT_BEFORE_ANNOTATION).matches(enclosingMethodTree, state) || Matchers.hasAnnotation(JUNIT_AFTER_ANNOTATION).matches(enclosingMethodTree, state); } }
/** Be warned, only changes method name at the declaration. */ public static SuggestedFix renameMethod( MethodTree tree, final String replacement, VisitorState state) { // Search tokens from beginning of method tree to beginning of method body. int basePos = ((JCTree) tree).getStartPosition(); int endPos = tree.getBody() != null ? ((JCTree) tree.getBody()).getStartPosition() : state.getEndPosition(tree); List<ErrorProneToken> methodTokens = ErrorProneTokens.getTokens( state.getSourceCode().subSequence(basePos, endPos).toString(), state.context); for (ErrorProneToken token : methodTokens) { if (token.kind() == TokenKind.IDENTIFIER && token.name().equals(tree.getName())) { int nameStartPosition = basePos + token.pos(); int nameEndPosition = basePos + token.endPos(); return SuggestedFix.builder() .replace(nameStartPosition, nameEndPosition, replacement) .build(); } } // Method name not found. throw new AssertionError(); }
@Override @Nullable public Choice<Unifier> visitMethod(MethodTree decl, @Nullable Unifier unifier) { return getName() .unify(decl.getName(), unifier) .thenChoose(unifications(getReturnType(), decl.getReturnType())) .thenChoose(unifications(getParameters(), decl.getParameters())) .thenChoose(unifications(getThrows(), decl.getThrows())) .thenChoose(unifications(getBody(), decl.getBody())); }
TreeScanner<Boolean, Void> findSuper = new FindSuperTreeScanner(tree.getName().toString()); if (findSuper.scan(tree, null)) { return Description.NO_MATCH;
@Override public UMethodDecl visitMethod(MethodTree decl, Void v) { return UMethodDecl.create( visitModifiers(decl.getModifiers(), null), decl.getName(), templateType(decl.getReturnType()), cast(templateStatements(decl.getParameters()), UVariableDecl.class), templateExpressions(decl.getThrows()), (UBlock) template(decl.getBody())); }
String methodName = methodTree.getName().toString(); if (methodName.startsWith("disabl") || methodName.startsWith("ignor")) { return buildDescription(methodTree)
if (currentMethod.getName().equals(method.name)) { MethodSymbol currentMethodSymbol = ASTHelpers.getSymbol(currentMethod); if (currentMethodSymbol.overrides(