public void testWrapAssignment() throws Exception { String code = "package hierbas.del.litoral;\n\n" + "import java.util.concurrent.atomic.AtomicBoolean;\n\n" + "public class Test {\n" + " public void t(AtomicBoolean ab) {\n" + " new AtomicBoolean();\n" + " }\n" + "}\n"; runWrappingTest(code, new Task<WorkingCopy>() { public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.RESOLVED); CompilationUnitTree cut = workingCopy.getCompilationUnit(); TreeMaker make = workingCopy.getTreeMaker(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(1); ExpressionStatementTree init = (ExpressionStatementTree) method.getBody().getStatements().get(0); AssignmentTree bt = make.Assignment(make.Identifier("ab"), init.getExpression()); workingCopy.rewrite(init, make.ExpressionStatement(bt)); } }, FmtOptions.wrapAssignOps, WrapStyle.WRAP_IF_LONG.name()); }
@Override public Void visitAssignment(AssignmentTree tree, EnumSet<UseTypes> d) { handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getVariable()), EnumSet.of(UseTypes.WRITE)); Tree expr = tree.getExpression(); if (expr instanceof IdentifierTree) { TreePath tp = new TreePath(getCurrentPath(), expr); handlePossibleIdentifier(tp, EnumSet.of(UseTypes.READ)); } scan(tree.getVariable(), EnumSet.of(UseTypes.WRITE)); scan(tree.getExpression(), EnumSet.of(UseTypes.READ)); return null; }
public static ExpressionTree findValue(AnnotationTree m, String name) { for (ExpressionTree et : m.getArguments()) { if (et.getKind() == Kind.ASSIGNMENT) { AssignmentTree at = (AssignmentTree) et; String varName = ((IdentifierTree) at.getVariable()).getName().toString(); if (varName.equals(name)) { return at.getExpression(); } } if (et instanceof LiteralTree/*XXX*/ && "value".equals(name)) { return et; } } return null; }
private static boolean hasNonCleanUpUsages( final Collection<? extends TreePath> usages, final Collection<? super TreePath> cleanupStatements) { for (TreePath usage : usages) { final TreePath parentPath = usage.getParentPath(); final Tree parent = parentPath.getLeaf(); if (parent.getKind() != Tree.Kind.ASSIGNMENT) { return true; } final AssignmentTree assign = (AssignmentTree) parent; if (assign.getVariable() != usage.getLeaf()) { return true; } if (assign.getExpression().getKind() != Tree.Kind.NULL_LITERAL) { return true; } final TreePath parentParent = parentPath.getParentPath(); if (parentParent.getLeaf().getKind() != Tree.Kind.EXPRESSION_STATEMENT) { return true; } cleanupStatements.add(parentParent); } return false; }
private static boolean isAssigned( final Element what, final Iterable<? extends TreePath> where, final Trees trees) { ErrorAwareTreePathScanner<Boolean, Void> scanner = new ErrorAwareTreePathScanner<Boolean, Void>() { @Override public Boolean visitAssignment(AssignmentTree node, Void p) { if (trees.getElement(new TreePath(getCurrentPath(), node.getVariable())) == what) { return true; } return super.visitAssignment(node, p); } @Override public Boolean reduce(Boolean r1, Boolean r2) { return r1 == Boolean.TRUE || r2 == Boolean.TRUE; } }; for (TreePath usage : where) { if (scanner.scan(usage, null) == Boolean.TRUE) { return true; } } return false; }
private void beautifyAssignement(Tree currentTree, Set<Name> needed) { AssignmentTree assigned = (AssignmentTree) ((ExpressionStatementTree) currentTree).getExpression(); ExpressionTree variable = assigned.getVariable(); if (variable.getKind() == Tree.Kind.IDENTIFIER) { IdentifierTree id = (IdentifierTree) variable; if (needed.contains(id.getName())) { this.correspondingTree = treeMaker.ExpressionStatement(assigned.getExpression()); } else { this.correspondingTree = this.addReturn(castToStatementTree(currentTree), getOneFromSet(needed)); } } else { this.correspondingTree = this.addReturn(castToStatementTree(currentTree), getOneFromSet(needed)); } }
/** * Determines whether the catch exception parameter is assigned to. * * @param ctx HintContext - for CompilationInfo * @param variable the inspected variable * @param statements statements that should be checked for assignment * @return true if 'variable' is assigned to within 'statements' */ public static boolean assignsTo(final HintContext ctx, TreePath variable, Iterable<? extends TreePath> statements) { final Element tEl = ctx.getInfo().getTrees().getElement(variable); if (tEl == null || tEl.getKind() != ElementKind.EXCEPTION_PARAMETER) return true; final boolean[] result = new boolean[1]; for (TreePath tp : statements) { new ErrorAwareTreePathScanner<Void, Void>() { @Override public Void visitAssignment(AssignmentTree node, Void p) { if (tEl.equals(ctx.getInfo().getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable())))) { result[0] = true; } return super.visitAssignment(node, p); } }.scan(tp, null); } return result[0]; }
private List<ErrorDescription> handleAssignment(CompilationInfo info, TreePath treePath) { AssignmentTree at = (AssignmentTree) treePath.getLeaf(); String declarationName = getName(at.getVariable()); String actualName = getName(at.getExpression()); if (isConflicting(info, declarationName, actualName)) { long start = info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), at.getVariable()); long end = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), at.getVariable()); if (start != (-1) && end != (-1)) { return Collections.singletonList(ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), "Suspicious names combination", info.getFileObject(), (int) start, (int) end)); } } return null; }
@Override public Boolean visitAssignment(AssignmentTree node, ConstructorData p) { TypeElement oldQName = this.referenceTarget; this.referenceTarget = null; lValueDereference = true; scan(node.getVariable(), null); lValueDereference = false; Boolean constVal = scan(node.getExpression(), p); Element e = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable())); if (e != null) { if (SUPPORTED_VARIABLES.contains(e.getKind())) { recordVariableState(e, new TreePath(getCurrentPath(), node.getExpression())); } else if (shouldProcessUndefined(e)) { Element cv = canonicalUndefined(e); recordVariableState(e, new TreePath(getCurrentPath(), node.getExpression())); } } this.referenceTarget = oldQName; return constVal; }
private void resolveResourceVariable(final WorkingCopy wc, TreePath tp, TreeMaker make, TypeMirror proposedType) { final String name = ((IdentifierTree) tp.getLeaf()).getName().toString(); final Element el = wc.getTrees().getElement(tp); if (el == null) { return; } if (tp.getParentPath().getLeaf().getKind() != Kind.ASSIGNMENT) { //? return ; } AssignmentTree at = (AssignmentTree) tp.getParentPath().getLeaf(); VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(proposedType), at.getExpression()); wc.rewrite(at, vt); }
/** * If we're assigning to an identifier then we see if this identifier has the same name as one of the * non-final params in scope. We only care about assignments to an identifier. * * Thus, a = 5; would be flagged by array[0] = "foo" would not be flagged. The left hand side of the assignment * operation must be an identifier in order for us to flag it. * * @param assignmentTree assignment AST node * @param nonFinalParamsInScope params to check against the LHS of the assignment */ @Override public Void visitAssignment(AssignmentTree assignmentTree, Set<Name> nonFinalParamsInScope) { if (nonFinalParamsInScope != null && !nonFinalParamsInScope.isEmpty()) { ExpressionTree variable = assignmentTree.getVariable(); variable.accept(new SimpleTreeVisitor<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree node, Void aVoid) { if (nonFinalParamsInScope.contains(node.getName())) { // printing a message of type error counts as a compilation error trees.printMessage(Diagnostic.Kind.ERROR, String.format("EFFECTIVELY_FINAL: Assignment to param in `%s`", assignmentTree), node, compilationUnitTree); } return null; } }, null); } return null; }
@Override public String visitAnnotation(AnnotationTree node, Void p) { for (ExpressionTree expressionTree : node.getArguments()) { if (expressionTree instanceof AssignmentTree) { AssignmentTree assignmentTree = (AssignmentTree) expressionTree; ExpressionTree variable = assignmentTree.getVariable(); if (variable instanceof IdentifierTree && ((IdentifierTree) variable).getName().contentEquals(annotationFieldName)) { return scan(expressionTree, p); } } } return null; }
@Override public Void visitAnnotation(AnnotationTree node, Map<ErrorDescription, Integer> p) { Element e = ci.getTrees().getElement(getCurrentPath()); if (e != null) { String annType = ((TypeElement)e).getQualifiedName().toString(); if (annType.startsWith("com.sun.btrace.annotations.")) { // NOI18N isHandler = true; if (annType.equals("com.sun.btrace.annotations.BTrace")) { // NOI18N isBTraceClass = true; for(ExpressionTree et : node.getArguments()) { if (et.getKind() == Tree.Kind.ASSIGNMENT) { String varName = ((AssignmentTree)et).getVariable().toString(); String varValue = ((AssignmentTree)et).getExpression().toString(); if (varName.equals("unsafe") && varValue.toLowerCase().equals("true")) { // NOI18N isUnsafe = true; } } } } } } return super.visitAnnotation(node, p); }
@Override public Void visitAssignment(AssignmentTree node, Map<ErrorDescription, Integer> p) { if (isUnsafe) return super.visitAssignment(node, p); Tree varTree = node.getVariable(); TreePath tp = ci.getTrees().getPath(ci.getCompilationUnit(), varTree); Element e = tp != null ? ci.getTrees().getElement(tp) : null; if (e != null && e.getKind().isField()) { Element parent = e.getEnclosingElement(); if (parent != null && (parent.getKind().isClass() || parent.getKind().isInterface())) { String typeName = ((TypeElement)parent).getQualifiedName().toString(); if (!(typeName.equals(btraceClassName) || typeName.equals("com.cun.btrace.BTraceUtils") || // NOI18N typeName.startsWith("com.sun.btrace.BTraceUtils$"))) { // NOI18N addError(node, ERR_NO_ASSIGNMENT, p); } } } return super.visitAssignment(node, p); }
private void assertCompilerMatchesOnAssignment( final Map<String, Boolean> expectedMatches, String... lines) { final Matcher<ExpressionTree> matcher = new CompileTimeConstantExpressionMatcher(); final Scanner scanner = new Scanner() { @Override public Void visitAssignment(AssignmentTree t, VisitorState state) { ExpressionTree lhs = t.getVariable(); if (expectedMatches.containsKey(lhs.toString())) { boolean matches = matcher.matches(t.getExpression(), state); if (expectedMatches.get(lhs.toString())) { assertTrue("Matcher should match expression" + t.getExpression(), matches); } else { assertFalse("Matcher should not match expression" + t.getExpression(), matches); } } return super.visitAssignment(t, state); } }; CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(scanner), getClass()) .expectResult(Result.OK) .addSourceLines("test/CompileTimeConstantExpressionMatcherTestCase.java", lines) .doTest(); }
/** * Matches patterns like i = i + 1 and i = i - 1 in which i is volatile, and the pattern is not * enclosed by a synchronized block. */ @SuppressWarnings("unchecked") private static Matcher<AssignmentTree> assignmentIncrementDecrementMatcher( ExpressionTree variable) { return allOf( variableFromAssignmentTree( Matchers.<ExpressionTree>hasModifier(Modifier.VOLATILE)), not(inSynchronized()), expressionFromAssignmentTree(adaptMatcherType(ExpressionTree.class, BinaryTree.class, allOf( anyOf( kindIs(Kind.PLUS), kindIs(Kind.MINUS)), binaryTree( sameVariable(variable), Matchers.<ExpressionTree>anything()))))); }
protected boolean isAccessAllowed(Element field, AnnotatedTypeMirror receiver, ExpressionTree accessTree) { AnnotationMirror unused = atypeFactory.getDeclAnnotation(field, Unused.class); if (unused == null) return true; Name when = AnnotationUtils.getElementValueClassName(unused, "when", false); if (receiver.getAnnotation(when) == null) return true; Tree tree = this.enclosingStatement(accessTree); // assigning unused to null is OK return (tree != null && tree.getKind() == Tree.Kind.ASSIGNMENT && ((AssignmentTree)tree).getVariable() == accessTree && ((AssignmentTree)tree).getExpression().getKind() == Tree.Kind.NULL_LITERAL); }
TreeBackedAnnotationValue( AnnotationValue underlyingAnnotationValue, TreePath treePath, PostEnterCanonicalizer canonicalizer) { this.underlyingAnnotationValue = underlyingAnnotationValue; Tree tree = treePath.getLeaf(); if (tree instanceof AssignmentTree) { AssignmentTree assignmentTree = (AssignmentTree) tree; valueTree = assignmentTree.getExpression(); this.treePath = new TreePath(treePath, valueTree); } else { valueTree = tree; this.treePath = treePath; } this.canonicalizer = canonicalizer; }
static AssignmentTree getAnnotationTreeAttribute( AnnotationTree annotation, String attributeName ) { List<? extends ExpressionTree> arguments = annotation.getArguments(); for (ExpressionTree expressionTree : arguments) { if (expressionTree instanceof AssignmentTree) { AssignmentTree assignmentTree = (AssignmentTree) expressionTree; ExpressionTree expression = assignmentTree.getVariable(); if (expression instanceof IdentifierTree) { IdentifierTree identifier = (IdentifierTree) expression; if (identifier.getName().contentEquals(attributeName)) { return assignmentTree; } } } } return null; }
static String getAnnotationTreeAttributeValue( AnnotationTree annotation, String attributeName ) { AssignmentTree tree = getAnnotationTreeAttribute(annotation, attributeName); if (tree == null) { return null; } else { ExpressionTree expression = tree.getExpression(); if (expression instanceof LiteralTree) { Object value = ((LiteralTree) expression).getValue(); return value == null ? null : value.toString(); } return null; } }
protected static AssignmentTree getAnnotationTreeAttribute( AnnotationTree annotation, String attributeName ) { List<? extends ExpressionTree> arguments = annotation.getArguments(); for (ExpressionTree expressionTree : arguments) { if (expressionTree instanceof AssignmentTree) { AssignmentTree assignmentTree = (AssignmentTree) expressionTree; ExpressionTree expression = assignmentTree.getVariable(); if (expression instanceof IdentifierTree) { IdentifierTree identifier = (IdentifierTree) expression; if (identifier.getName().contentEquals(attributeName)) { return assignmentTree; } } } } return null; }
@Override public Tree visitAssignment(AssignmentTree tree, Void p) { AssignmentTree n = make.Assignment(tree.getVariable(), tree.getExpression()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Boolean visitAnnotation(AnnotationTree node, TreePath p) { if (p == null) return super.visitAnnotation(node, p); AnnotationTree t = (AnnotationTree) p.getLeaf(); List<? extends ExpressionTree> arguments = t.getArguments(); if (arguments.size() == 1) { ExpressionTree arg = arguments.get(0); if (arg.getKind() == Kind.ASSIGNMENT) { AssignmentTree at = (AssignmentTree) arg; if ( at.getVariable().getKind() == Kind.IDENTIFIER && isMultistatementWildcardTree(at.getExpression()) && ((IdentifierTree) at.getVariable()).getName().contentEquals("value")) { arguments = Collections.singletonList(at.getExpression()); } } } if (!checkLists(node.getArguments(), arguments, p)) return false; return scan(node.getAnnotationType(), t.getAnnotationType(), p); }
@Override public Object visitIdentifier(IdentifierTree node, Object p) { if (!fieldNames.contains(node.getName())) { return null; } // TODO do not track dependencies for method refs boolean ok = false; Tree parent = getCurrentPath().getParentPath().getLeaf(); switch (parent.getKind()) { case MEMBER_SELECT: // dependency is only introduced by dereferencing the identifier. ok = ((MemberSelectTree)parent).getExpression() != node; break; case ASSIGNMENT: ok = ((AssignmentTree)parent).getVariable() == node; break; } if (ok) { return null; } if (!ok) { if (collectNames) { if (node.getName().equals(insertedName)) { revDependencies.add(member); } } else { addDependency(node.getName()); } } return null; }
public Void visitClass(ClassTree node, Object p) { TypeElement te = (TypeElement)model.getElement(node); if (te != null) { List<Tree> members = new ArrayList<Tree>(node.getMembers()); int pos = putBefore != null ? members.indexOf(putBefore) + 1: members.size(); Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC); //create body: List<StatementTree> statements = new ArrayList(); List<VariableTree> arguments = new ArrayList(); for (VariableElement ve : fields) { AssignmentTree a = make.Assignment(make.MemberSelect(make.Identifier("this"), ve.getSimpleName()), make.Identifier(ve.getSimpleName())); statements.add(make.ExpressionStatement(a)); arguments.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), ve.getSimpleName(), make.Type(ve.asType()), null)); } BlockTree body = make.Block(statements, false); members.add(pos, make.Method(make.Modifiers(mods), "<init>", null, Collections.<TypeParameterTree> emptyList(), arguments, Collections.<ExpressionTree>emptyList(), body, null)); ClassTree decl = make.Class(node.getModifiers(), node.getSimpleName(), node.getTypeParameters(), node.getExtendsClause(), (List<ExpressionTree>)node.getImplementsClause(), members); model.setElement(decl, te); model.setType(decl, model.getType(node)); model.setPos(decl, model.getPos(node)); copy.rewrite(node, decl); } return null; }
public void testIsCompileTimeConstant() throws Exception { prepareTest("Test", "package test; public class Test { private void m(String str) { int i; i = 1 + 1; i = str.length(); } }"); final List<Boolean> result = new ArrayList<Boolean>(); new ErrorAwareTreePathScanner<Void, Void>() { @Override public Void visitAssignment(AssignmentTree node, Void p) { result.add(info.getTreeUtilities().isCompileTimeConstantExpression(new TreePath(getCurrentPath(), node.getExpression()))); return super.visitAssignment(node, p); } }.scan(info.getCompilationUnit(), null); assertEquals(Arrays.asList(true, false), result); }
private static List<? extends TypeMirror> computeAssignment(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { AssignmentTree at = (AssignmentTree) parent.getLeaf(); TypeMirror type = null; if (at.getVariable() == error) { type = info.getTrees().getTypeMirror(new TreePath(parent, at.getExpression())); if (type != null) { //anonymous class? type = JavaPluginUtils.convertIfAnonymous(type); if (type.getKind() == TypeKind.EXECUTABLE) { //TODO: does not actualy work, attempt to solve situations like: //t = Collections.emptyList() //t = Collections.<String>emptyList(); //see also testCreateFieldMethod1 and testCreateFieldMethod2 tests: type = ((ExecutableType) type).getReturnType(); } } } if (at.getExpression() == error) { type = info.getTrees().getTypeMirror(new TreePath(parent, at.getVariable())); } //class or field: if (type == null) { return null; } types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); return Collections.singletonList(type); }
@Override public Void visitAssignment(AssignmentTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitAssignment(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
private ExpressionTree makeParenthesis(ExpressionTree arg) { Class c = arg.getKind().asInterface(); // if the original append argument was an expression, surround it in parenthesis, to get the same toString effect if (c == BinaryTree.class || c == UnaryTree.class || c == CompoundAssignmentTree.class || c == AssignmentTree.class || c == ConditionalExpressionTree.class) { return mk.Parenthesized(arg); } else { return arg; } }
@Override public Boolean visitAssignment(AssignmentTree node, Void p) { // used at the L-value Boolean lval = scan(node.getVariable(), p); if (lval == Boolean.TRUE) { assignedFromVar = true; return true; } Boolean res = scan(node.getExpression(), p); if (res == Boolean.TRUE) { assignedToVar = true; } return false; }
@Override public Object visitAssignment(AssignmentTree node, Object p) { if (!ifEncountered) { return super.visitAssignment(node, p); } Element el = wc.getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable())); if (el == originalVariable) { // assignment should be converted into local var + field assignment ExpressionTree et = mk.Assignment(fieldAccessTree, mk.Assignment(localVarTree, node.getExpression())); wc.rewrite(node, et); } return scan(node.getExpression(), p); }
@Override protected void performRewrite(TransformationContext ctx) throws Exception { ArrayAccessTree aa = (ArrayAccessTree) ctx.getPath().getLeaf(); TreeMaker make = ctx.getWorkingCopy().getTreeMaker(); if (assignment) { AssignmentTree at = (AssignmentTree) ctx.getPath().getParentPath().getLeaf(); ctx.getWorkingCopy().rewrite(at, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(aa.getExpression(), map ? " put" : "set"), Arrays.asList(aa.getIndex(), at.getExpression()))); } else { ctx.getWorkingCopy().rewrite(aa, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(aa.getExpression(), "get"), Collections.singletonList(aa.getIndex()))); } }
/** In case statement is an Assignment, replace it with variable declaration */ private boolean initExpression(StatementTree statement, TreeMaker make, final String name, TypeMirror proposedType, final WorkingCopy wc, TreePath tp) { ExpressionTree exp = ((ExpressionStatementTree) statement).getExpression(); if (exp.getKind() == Kind.ASSIGNMENT) { AssignmentTree at = (AssignmentTree) exp; if (at.getVariable().getKind() == Kind.IDENTIFIER && ((IdentifierTree) at.getVariable()).getName().contentEquals(name)) { //replace the expression statement with a variable declaration: VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(proposedType), at.getExpression()); vt = Utilities.copyComments(wc, statement, vt); wc.rewrite(statement, vt); return true; } } return false; }
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", description = "#DESC_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", category = "assignment_issues", enabled = false, suppressWarnings = "AssignmentToMethodParameter", options=Options.QUERY) //NOI18N @TriggerTreeKind({Kind.ASSIGNMENT, Kind.AND_ASSIGNMENT, Kind.DIVIDE_ASSIGNMENT, Kind.LEFT_SHIFT_ASSIGNMENT, Kind.MINUS_ASSIGNMENT, Kind.MULTIPLY_ASSIGNMENT, Kind.OR_ASSIGNMENT, Kind.PLUS_ASSIGNMENT, Kind.REMAINDER_ASSIGNMENT, Kind.RIGHT_SHIFT_ASSIGNMENT, Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT, Kind.XOR_ASSIGNMENT, Kind.PREFIX_INCREMENT, Kind.PREFIX_DECREMENT, Kind.POSTFIX_INCREMENT, Kind.POSTFIX_DECREMENT}) public static ErrorDescription assignmentToMethodParam(HintContext context) { final TreePath path = context.getPath(); Element element = null; switch (path.getLeaf().getKind()) { case ASSIGNMENT: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((AssignmentTree) path.getLeaf()).getVariable())); break; case PREFIX_INCREMENT: case PREFIX_DECREMENT: case POSTFIX_INCREMENT: case POSTFIX_DECREMENT: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((UnaryTree) path.getLeaf()).getExpression())); break; default: element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((CompoundAssignmentTree) path.getLeaf()).getVariable())); } if (element != null && element.getKind() == ElementKind.PARAMETER) { return ErrorDescriptionFactory.forTree(context, path, NbBundle.getMessage(AssignmentIssues.class, "MSG_AssignmentToMethodParam", element.getSimpleName())); //NOI18N } return null; }
@Override public Void visitAssignment(AssignmentTree node, List<TreePath> p) { if (param == trees.getElement(TreePath.getPath(getCurrentPath(), node.getVariable()))) { p.add(getCurrentPath()); return null; } return super.visitAssignment(node, p); }
/** * Assignment expects the assigned-to variable's type. */ @Override public List<? extends TypeMirror> visitAssignment(AssignmentTree node, Object p) { if (theExpression == null) { initExpression(new TreePath(getCurrentPath(), node.getExpression())); } return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getVariable()))); }
@Override public Void visitAssignment(AssignmentTree node, Void p) { exprBundleName = null; Void d = super.visitAssignment(node, p); if (exprBundleName != null) { Element dest = info.getTrees().getElement(getCurrentPath()); if (dest != null && (dest.getKind() == ElementKind.LOCAL_VARIABLE || dest.getKind() == ElementKind.FIELD)) { variableBundles.put(dest, exprBundleName); } } return d; }