private static Optional<ExpressionTree> findArgument( AnnotationTree annotation, String parameter) { for (ExpressionTree argument : annotation.getArguments()) { if (argument.getKind().equals(ASSIGNMENT)) { AssignmentTree assignment = (AssignmentTree) argument; if (assignment.getVariable().toString().equals(parameter)) { return Optional.of(ASTHelpers.stripParentheses(assignment.getExpression())); } } } return Optional.empty(); }
private static boolean isThisIdentifier(ExpressionTree expressionTree) { return expressionTree.getKind().equals(IDENTIFIER) && ((IdentifierTree) expressionTree).getName().toString().equals("this"); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof UBinary) { UBinary that = (UBinary) o; return (this.kind.equals(that.getKind())) && (this.leftOperand.equals(that.getLeftOperand())) && (this.rightOperand.equals(that.getRightOperand())); } return false; }
@Override public final Description matchAnnotation(AnnotationTree annotationTree, VisitorState state) { if (!IS_APPLICATION_OF_AT_INJECT.matches(annotationTree, state)) { return Description.NO_MATCH; } Tree annotatedTree = getCurrentlyAnnotatedNode(state); if (!annotatedTree.getKind().equals(METHOD) || !methodIsConstructor().matches((MethodTree) annotatedTree, state)) { return Description.NO_MATCH; } ClassTree classTree = findEnclosingNode(state.getPath(), ClassTree.class); ImmutableList<Tree> potentiallyAnnotatedTrees = ImmutableList.<Tree>builder().add(classTree).addAll(getConstructors(classTree)).build(); for (Tree potentiallyAnnotatedTree : potentiallyAnnotatedTrees) { if (HAS_AUTO_FACTORY_ANNOTATION.matches(potentiallyAnnotatedTree, state) && (potentiallyAnnotatedTree.getKind().equals(CLASS) || potentiallyAnnotatedTree.equals(annotatedTree))) { return describeMatch(annotationTree, SuggestedFix.delete(annotationTree)); } } return Description.NO_MATCH; }
@Override public boolean matches(MethodTree method, VisitorState state) { List<? extends VariableTree> parameters = method.getParameters(); if (!parameters.isEmpty()) { return false; } BlockTree body = method.getBody(); if (body == null) { return false; } List<? extends StatementTree> statements = body.getStatements(); if (statements.size() != 1) { return false; } StatementTree onlyStatement = Iterables.getOnlyElement(statements); if (!onlyStatement.getKind().equals(RETURN)) { return false; } return EMPTY_SET.matches(((ReturnTree) onlyStatement).getExpression(), state); } };
private static SuggestedFix.Builder addPrivateConstructor(ClassTree classTree) { SuggestedFix.Builder fix = SuggestedFix.builder(); String indent = " "; for (Tree member : classTree.getMembers()) { if (member.getKind().equals(METHOD) && !isGeneratedConstructor((MethodTree) member)) { fix.prefixWith( member, indent + "private " + classTree.getSimpleName() + "() {} // no instances\n" + indent); break; } if (!member.getKind().equals(METHOD)) { indent = ""; } } return fix; } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Parameter) { Parameter that = (Parameter) o; return (this.name.equals(that.name())) && (this.type.equals(that.type())) && (this.index == that.index()) && (this.text.equals(that.text())) && (this.kind.equals(that.kind())) && (this.constant == that.constant()); } return false; }
private boolean isThisCall(StatementTree statementTree, VisitorState state) { if (statementTree.getKind().equals(EXPRESSION_STATEMENT)) { ExpressionTree expression = ((ExpressionStatementTree) statementTree).getExpression(); return Matchers.methodInvocation(THIS_MATCHER).matches(expression, state); } return false; }
@Override public boolean onOverrideMayBeNullExpr( NullAway analysis, ExpressionTree expr, VisitorState state, boolean exprMayBeNull) { if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)) { return exprMayBeNull || isReturnAnnotatedNullable(ASTHelpers.getSymbol((MethodInvocationTree) expr)); } return exprMayBeNull; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof UAssignOp) { UAssignOp that = (UAssignOp) o; return (this.variable.equals(that.getVariable())) && (this.kind.equals(that.getKind())) && (this.expression.equals(that.getExpression())); } return false; }
@Override public boolean apply(Tree tree) { return tree.getKind().equals(METHOD) && isGeneratedConstructor((MethodTree) tree); } }));
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ULiteral) { ULiteral that = (ULiteral) o; return (this.kind.equals(that.getKind())) && ((this.value == null) ? (that.getValue() == null) : this.value.equals(that.getValue())); } return false; }
@Override @Nullable public Choice<Unifier> visitUnary(UnaryTree unary, @Nullable Unifier unifier) { return Choice.condition(getKind().equals(unary.getKind()), unifier) .thenChoose( unifications(getExpression(), ASTHelpers.stripParentheses(unary.getExpression()))); }
@Override public Void visitBinary(BinaryTree binTree, ExpressionTree expr) { if (binTree.getKind().equals(Kind.CONDITIONAL_OR)) { notApplicable = true; } return super.visitBinary(binTree, expr); }
@Override public Choice<Unifier> visitBinary(BinaryTree binary, Unifier unifier) { return Choice.condition(getKind().equals(binary.getKind()), unifier) .thenChoose(unifications(getLeftOperand(), binary.getLeftOperand())) .thenChoose(unifications(getRightOperand(), binary.getRightOperand())); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof UWildcard) { UWildcard that = (UWildcard) o; return (this.kind.equals(that.getKind())) && ((this.bound == null) ? (that.getBound() == null) : this.bound.equals(that.getBound())); } return false; }
@Override public boolean matches(ExpressionTree thisExpression, VisitorState state) { if (thisExpression.getKind().equals(Kind.IDENTIFIER)) { IdentifierTree identifier = (IdentifierTree) thisExpression; if (identifier.getName().contentEquals("this")) { return true; } } return false; } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof UUnary) { UUnary that = (UUnary) o; return (this.kind.equals(that.getKind())) && (this.expression.equals(that.getExpression())); } return false; }
@Override public boolean apply(Tree tree) { return tree.getKind().equals(METHOD) && isGeneratedConstructor((MethodTree) tree); } }));
@Override public Void visitUnary(UnaryTree tree, ExpressionTree expr) { if (tree.getKind().equals(Kind.LOGICAL_COMPLEMENT)) { notApplicable = true; } return super.visitUnary(tree, expr); }