@Override public Void visitAssignment(AssignmentTree node, Void unused) { scan(node.getExpression(), null); // ignore references to 'this' in the LHS of assignments return null; } },
@Override public Description matchAssignment(AssignmentTree tree, VisitorState state) { return check(ASTHelpers.getType(tree), tree.getExpression()); }
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 String valueArgumentFromCompatibleWithAnnotation(AnnotationTree tree) { ExpressionTree argumentValue = Iterables.getOnlyElement(tree.getArguments()); if (argumentValue.getKind() != Kind.ASSIGNMENT) { // :-| Annotation symbol broken. Punt? return null; } return ASTHelpers.constValue(((AssignmentTree) argumentValue).getExpression(), String.class); }
/** * Gets the value for an argument, or null if the argument does not exist. * * @param annotationTree the AST node for the annotation * @param name the name of the argument whose value to get * @return the value of the argument, or null if the argument does not exist */ @Nullable public static ExpressionTree getArgument(AnnotationTree annotationTree, String name) { for (ExpressionTree argumentTree : annotationTree.getArguments()) { if (argumentTree.getKind() != Tree.Kind.ASSIGNMENT) { continue; } AssignmentTree assignmentTree = (AssignmentTree) argumentTree; if (!assignmentTree.getVariable().toString().equals(name)) { continue; } ExpressionTree expressionTree = assignmentTree.getExpression(); return expressionTree; } return null; }
@Override public Void visitAssignment(AssignmentTree assignmentTree, Void unused) { // Don't count the LHS of the assignment to the variable as a usage. if (Objects.equals(getSymbol(assignmentTree.getVariable()), symbol)) { return scan(assignmentTree.getExpression(), null); } return super.visitAssignment(assignmentTree, null); }
@Override public boolean matches(AssignmentTree t, VisitorState state) { return variableMatcher.matches(t.getVariable(), state) && expressionMatcher.matches(t.getExpression(), state); } };
@Override public Void visitAssignment(AssignmentTree node, Void aVoid) { recordInitialization(node.getVariable(), node.getExpression()); return super.visitAssignment(node, aVoid); }
@Override public Void visitAssignment(AssignmentTree node, Void aVoid) { if (symbol.equals(getSymbol(node.getVariable()))) { initializers.add(new TreePath(getCurrentPath(), node.getExpression())); } return super.visitAssignment(node, aVoid); } }.scan(state.getPath().getParentPath(), null);
@Override public Description matchAssignment(AssignmentTree tree, VisitorState state) { ExpressionTree expression = stripNullCheck(tree.getExpression(), state); if (ASTHelpers.sameVariable(tree.getVariable(), expression)) { return describeForAssignment(tree, state); } return Description.NO_MATCH; }
@Override public Void visitAssignment(AssignmentTree tree, VisitorState state) { checkForInitializer(ASTHelpers.getSymbol(tree.getVariable()), tree.getExpression(), state); return super.visitAssignment(tree, state); }
@Override public UAssign visitAssignment(AssignmentTree tree, Void v) { return UAssign.create(template(tree.getVariable()), template(tree.getExpression())); }
.getSimpleName() .contentEquals("value")) { ExpressionTree expressionTree = assignmentTree.getExpression(); switch (expressionTree.getKind()) { case STRING_LITERAL:
@Override public Choice<Unifier> visitAssignment(AssignmentTree assign, Unifier unifier) { return getVariable() .unify(assign.getVariable(), unifier) .thenChoose(unifications(getExpression(), assign.getExpression())); } }
@Override public Void visitAssignment(AssignmentTree node, Void unused) { Type lhsType = node.getVariable() instanceof ArrayAccessTree ? ((JCArrayAccess) node.getVariable()).getExpression().type : TreeInfo.symbol((JCTree) node.getVariable()).type; generateConstraintsForWrite(lhsType, node.getExpression(), node); return super.visitAssignment(node, unused); }
@Override public Choice<State<JCAssign>> visitAssignment(final AssignmentTree node, State<?> state) { return chooseSubtrees( state, s -> unifyExpression(node.getVariable(), s), s -> unifyExpression(node.getExpression(), s), maker()::Assign) .condition(s -> !(s.result().getVariable() instanceof PlaceholderParamIdent)); }
@Override public Description matchAssignment(AssignmentTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } Type lhsType = ASTHelpers.getType(tree.getVariable()); if (lhsType != null && lhsType.isPrimitive()) { return doUnboxingCheck(state, tree.getExpression()); } Symbol assigned = ASTHelpers.getSymbol(tree.getVariable()); if (assigned == null || assigned.getKind() != ElementKind.FIELD) { // not a field of nullable type return Description.NO_MATCH; } if (Nullness.hasNullableAnnotation(assigned)) { // field already annotated return Description.NO_MATCH; } ExpressionTree expression = tree.getExpression(); if (mayBeNullExpr(state, expression)) { String message = "assigning @Nullable expression to @NonNull field"; return createErrorDescriptionForNullAssignment( MessageTypes.ASSIGN_FIELD_NULLABLE, tree, message, expression, state.getPath()); } return Description.NO_MATCH; }
ExpressionTree rhs = assignmentTree.getExpression(); if (assignmentTree.getExpression().getKind() == METHOD_INVOCATION) {
private Description checkCondition(ExpressionTree condition, VisitorState state) { if (!(condition instanceof AssignmentTree)) { return NO_MATCH; } AssignmentTree assign = (AssignmentTree) condition; return buildDescription(condition) .addFix( SuggestedFix.builder().prefixWith(condition, "(").postfixWith(condition, ")").build()) .addFix( SuggestedFix.replace( /*startPos=*/ state.getEndPosition(assign.getVariable()), /*endPos=*/ ((JCTree) assign.getExpression()).getStartPosition(), " == ")) .build(); } }
ExpressionTree expression = tree.getExpression(); if (ASTHelpers.constValue(expression) != null) {