com.sun.source.tree.AssignmentTree Java Examples
The following examples show how to use
com.sun.source.tree.AssignmentTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeBackedAnnotationValue.java From buck with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: AddParameterOrLocalFix.java From netbeans with Apache License 2.0 | 6 votes |
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); }
Example #3
Source File: WrappingTest.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example #4
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: JSEmbeddingProvider.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Void visitMethod( final MethodTree m, final List<? super LiteralTree> p) { for (AnnotationTree a : m.getModifiers().getAnnotations()) { final TypeElement ae = (TypeElement) trees.getElement(TreePath.getPath(cu, a.getAnnotationType())); if (ae != null && JS_ANNOTATION.contentEquals(ae.getQualifiedName())) { final List<? extends ExpressionTree> args = a.getArguments(); for (ExpressionTree kvp : args) { if (kvp instanceof AssignmentTree) { final AssignmentTree assignemt = (AssignmentTree) kvp; if (BODY.equals(assignemt.getVariable().toString())) { inEmbedding = true; try { scan(assignemt.getExpression(), p); } finally { inEmbedding = false; } } } } } } return null; }
Example #6
Source File: ConvertToARM.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: ConvertToARM.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: ProspectiveOperation.java From netbeans with Apache License 2.0 | 6 votes |
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)); } }
Example #9
Source File: UseSpecificCatch.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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]; }
Example #10
Source File: SuspiciousNamesCombination.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #11
Source File: Flow.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example #12
Source File: Main.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitAssignment(AssignmentTree node, Void ignored) { TreePath path = TreePath.getPath(getCurrentPath(), node.getExpression()); if (trees.getTypeMirror(path).getKind() == TypeKind.ERROR) throw new AssertionError(path.getLeaf()); return null; }
Example #13
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
public void visitAnnotationArgument(AssignmentTree node) { boolean isArrayInitializer = node.getExpression().getKind() == NEW_ARRAY; sync(node); builder.open(isArrayInitializer ? ZERO : plusFour); scan(node.getVariable(), null); builder.space(); token("="); if (isArrayInitializer) { builder.space(); } else { builder.breakOp(" "); } scan(node.getExpression(), null); builder.close(); }
Example #14
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
private static boolean isArrayValue(ExpressionTree argument) { if (!(argument instanceof AssignmentTree)) { return false; } ExpressionTree expression = ((AssignmentTree) argument).getExpression(); return expression instanceof NewArrayTree && ((NewArrayTree) expression).getType() == null; }
Example #15
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
@Override public Void visitAssignment(AssignmentTree node, Void unused) { sync(node); builder.open(plusFour); scan(node.getVariable(), null); builder.space(); splitToken(operatorName(node)); builder.breakOp(" "); scan(node.getExpression(), null); builder.close(); return null; }
Example #16
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 5 votes |
private TreeNode convertAssignment(AssignmentTree node, TreePath parent) { TreePath path = getTreePath(parent, node); Assignment newNode = new Assignment(); return newNode .setOperator(Assignment.Operator.ASSIGN) .setLeftHandSide((Expression) convert(node.getVariable(), path)) .setRightHandSide((Expression) convert(node.getExpression(), path)); }
Example #17
Source File: NullAway.java From NullAway with MIT License | 5 votes |
/** * @param path tree path to read operation * @return true if it is permissible to perform this read before the field has been initialized, * false otherwise */ private boolean okToReadBeforeInitialized(TreePath path) { TreePath parentPath = path.getParentPath(); Tree leaf = path.getLeaf(); Tree parent = parentPath.getLeaf(); if (parent instanceof AssignmentTree) { // ok if it's actually a write AssignmentTree assignment = (AssignmentTree) parent; return assignment.getVariable().equals(leaf); } else if (parent instanceof BinaryTree) { // ok if we're comparing to null BinaryTree binaryTree = (BinaryTree) parent; Tree.Kind kind = binaryTree.getKind(); if (kind.equals(Tree.Kind.EQUAL_TO) || kind.equals(Tree.Kind.NOT_EQUAL_TO)) { ExpressionTree left = binaryTree.getLeftOperand(); ExpressionTree right = binaryTree.getRightOperand(); return (left.equals(leaf) && right.getKind().equals(Tree.Kind.NULL_LITERAL)) || (right.equals(leaf) && left.getKind().equals(Tree.Kind.NULL_LITERAL)); } } else if (parent instanceof MethodInvocationTree) { // ok if it's invoking castToNonNull and the read is the argument MethodInvocationTree methodInvoke = (MethodInvocationTree) parent; Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(methodInvoke); String qualifiedName = ASTHelpers.enclosingClass(methodSymbol) + "." + methodSymbol.getSimpleName().toString(); if (qualifiedName.equals(config.getCastToNonNullMethod())) { List<? extends ExpressionTree> arguments = methodInvoke.getArguments(); return arguments.size() == 1 && leaf.equals(arguments.get(0)); } } return false; }
Example #18
Source File: NullAway.java From NullAway with MIT License | 5 votes |
@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, config)) { // field already annotated return Description.NO_MATCH; } ExpressionTree expression = tree.getExpression(); if (mayBeNullExpr(state, expression)) { String message = "assigning @Nullable expression to @NonNull field"; return errorBuilder.createErrorDescriptionForNullAssignment( new ErrorMessage(MessageTypes.ASSIGN_FIELD_NULLABLE, message), expression, buildDescription(tree), state); } return Description.NO_MATCH; }
Example #19
Source File: JavaxFacesBeanIsGonnaBeDeprecated.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void performRewrite(TransformationContext ctx) throws Exception { WorkingCopy wc = ctx.getWorkingCopy(); wc.toPhase(JavaSource.Phase.RESOLVED); TreeMaker make = wc.getTreeMaker(); // rewrite annotations in case of ManagedBean if (MANAGED_BEAN.equals(annotation.getAnnotationType().toString())) { ModifiersTree modifiers = ((ClassTree) wc.getTrees().getTree(element)).getModifiers(); AnnotationTree annotationTree = (AnnotationTree) wc.getTrees().getTree(element, annotation); List<ExpressionTree> arguments = new ArrayList<>(); for (ExpressionTree expressionTree : annotationTree.getArguments()) { if (expressionTree.getKind() == Tree.Kind.ASSIGNMENT) { AssignmentTree at = (AssignmentTree) expressionTree; String varName = ((IdentifierTree) at.getVariable()).getName().toString(); if (varName.equals("name")) { //NOI18N ExpressionTree valueTree = make.Identifier(at.getExpression().toString()); arguments.add(valueTree); } } } ModifiersTree newModifiersTree = make.removeModifiersAnnotation(modifiers, (AnnotationTree) wc.getTrees().getTree(element, annotation)); AnnotationTree newTree = GenerationUtils.newInstance(wc).createAnnotation(replacingClass, arguments); newModifiersTree = make.addModifiersAnnotation(newModifiersTree, newTree); wc.rewrite(modifiers, newModifiersTree); } // rewrite imports List<? extends ImportTree> imports = wc.getCompilationUnit().getImports(); ImportTree newImportTree = make.Import(make.QualIdent(replacingClass), false); for (ImportTree importTree : imports) { if (deprecatedClass.equals(importTree.getQualifiedIdentifier().toString())) { wc.rewrite(importTree, newImportTree); } } }
Example #20
Source File: PersistentTimerInEjbLite.java From netbeans with Apache License 2.0 | 5 votes |
public void fixTimerAnnotation(WorkingCopy copy) { TypeElement scheduleAnnotation = copy.getElements().getTypeElement(EJBAPIAnnotations.SCHEDULE); ModifiersTree modifiers = ((MethodTree) copy.getTrees().getPath(methodElement.resolve(copy)).getLeaf()).getModifiers(); TreeMaker tm = copy.getTreeMaker(); for (AnnotationTree at : modifiers.getAnnotations()) { TreePath tp = new TreePath(new TreePath(copy.getCompilationUnit()), at.getAnnotationType()); Element e = copy.getTrees().getElement(tp); if (scheduleAnnotation.equals(e)) { List<? extends ExpressionTree> arguments = at.getArguments(); for (ExpressionTree et : arguments) { if (et.getKind() == Tree.Kind.ASSIGNMENT) { AssignmentTree assignment = (AssignmentTree) et; AssignmentTree newAssignment = tm.Assignment(assignment.getVariable(), tm.Literal(false)); if (EJBAPIAnnotations.PERSISTENT.equals(assignment.getVariable().toString())) { copy.rewrite( modifiers, copy.getTreeUtilities().translate(modifiers, Collections.singletonMap(et, newAssignment))); return; } } } List<ExpressionTree> newArguments = new ArrayList<ExpressionTree>(arguments); ExpressionTree persistenQualIdent = tm.QualIdent(EJBAPIAnnotations.PERSISTENT); newArguments.add(tm.Assignment(persistenQualIdent, tm.Literal(false))); AnnotationTree newAnnotation = tm.Annotation(tp.getLeaf(), newArguments); copy.rewrite(at, newAnnotation); return; } } }
Example #21
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
public static ExpressionTree getAnnotationArgumentTree(AnnotationTree annotationTree, String attrName) { for (ExpressionTree exTree : annotationTree.getArguments()) { if (exTree instanceof AssignmentTree) { ExpressionTree annVar = ((AssignmentTree) exTree).getVariable(); if (annVar instanceof IdentifierTree) { if (attrName.equals(((IdentifierTree) annVar).getName().toString())) { return exTree; } } } } return null; }
Example #22
Source File: WSCompletionProvider.java From netbeans with Apache License 2.0 | 5 votes |
private void createAssignmentResults(CompilationController controller, Env env) throws IOException { TreePath elementPath = env.getPath(); TreePath parentPath = elementPath.getParentPath(); Tree parent = parentPath.getLeaf(); switch (parent.getKind()) { case ANNOTATION : { ExpressionTree var = ((AssignmentTree)elementPath.getLeaf()). getVariable(); if (var!= null && var.getKind() == Kind.IDENTIFIER) { Name name = ((IdentifierTree)var).getName(); if (name.contentEquals("value")) {//NOI18N controller.toPhase(Phase.ELEMENTS_RESOLVED); TypeElement webParamEl = controller.getElements(). getTypeElement("javax.xml.ws.BindingType"); //NOI18N if (webParamEl==null) { hasErrors = true; return; } TypeMirror el = controller.getTrees().getTypeMirror(parentPath); if (el==null || el.getKind() == TypeKind.ERROR) { hasErrors = true; return; } if ( controller.getTypes().isSameType(el,webParamEl.asType())) { for (String mode : BINDING_TYPES) { if (mode.startsWith(env.getPrefix())){ results.add(WSCompletionItem. createEnumItem(mode, "String", env.getOffset())); //NOI18N } } } } } } break; // ANNOTATION } }
Example #23
Source File: JDIWrappersTest.java From netbeans with Apache License 2.0 | 5 votes |
private Element getElement(Tree tree) { TreePath expPath = TreePath.getPath(cut, tree); Element e = trees.getElement(expPath); if (e == null) { if (tree instanceof ParenthesizedTree) { e = getElement(((ParenthesizedTree) tree).getExpression()); //if (e == null) { // System.err.println("Have null element for "+tree); //} //System.err.println("\nHAVE "+e.asType().toString()+" for ParenthesizedTree "+tree); } else if (tree instanceof TypeCastTree) { e = getElement(((TypeCastTree) tree).getType()); //if (e == null) { // System.err.println("Have null element for "+tree); //} //System.err.println("\nHAVE "+e.asType().toString()+" for TypeCastTree "+tree); } else if (tree instanceof AssignmentTree) { e = getElement(((AssignmentTree) tree).getVariable()); } else if (tree instanceof ArrayAccessTree) { e = getElement(((ArrayAccessTree) tree).getExpression()); if (e != null) { TypeMirror tm = e.asType(); if (tm.getKind() == TypeKind.ARRAY) { tm = ((ArrayType) tm).getComponentType(); e = types.asElement(tm); } } //System.err.println("ArrayAccessTree = "+((ArrayAccessTree) tree).getExpression()+", element = "+getElement(((ArrayAccessTree) tree).getExpression())+", type = "+getElement(((ArrayAccessTree) tree).getExpression()).asType()); } } return e; }
Example #24
Source File: FmtCodeGeneration.java From netbeans with Apache License 2.0 | 5 votes |
protected void doModification(ResultIterator resultIterator) throws Exception { WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); copy.toPhase(Phase.RESOLVED); TreeMaker tm = copy.getTreeMaker(); GeneratorUtilities gu = GeneratorUtilities.get(copy); CompilationUnitTree cut = copy.getCompilationUnit(); ClassTree ct = (ClassTree) cut.getTypeDecls().get(0); VariableTree field = (VariableTree)ct.getMembers().get(1); List<Tree> members = new ArrayList<Tree>(); AssignmentTree stat = tm.Assignment(tm.Identifier("name"), tm.Literal("Name")); //NOI18N BlockTree init = tm.Block(Collections.singletonList(tm.ExpressionStatement(stat)), false); members.add(init); members.add(gu.createConstructor(ct, Collections.<VariableTree>emptyList())); members.add(gu.createGetter(field)); ModifiersTree mods = tm.Modifiers(EnumSet.of(Modifier.PRIVATE)); ClassTree inner = tm.Class(mods, "Inner", Collections.<TypeParameterTree>emptyList(), null, Collections.<Tree>emptyList(), Collections.<Tree>emptyList()); //NOI18N members.add(inner); mods = tm.Modifiers(EnumSet.of(Modifier.PRIVATE, Modifier.STATIC)); ClassTree nested = tm.Class(mods, "Nested", Collections.<TypeParameterTree>emptyList(), null, Collections.<Tree>emptyList(), Collections.<Tree>emptyList()); //NOI18N members.add(nested); IdentifierTree nestedId = tm.Identifier("Nested"); //NOI18N VariableTree staticField = tm.Variable(mods, "instance", nestedId, null); //NOI18N members.add(staticField); NewClassTree nct = tm.NewClass(null, Collections.<ExpressionTree>emptyList(), nestedId, Collections.<ExpressionTree>emptyList(), null); stat = tm.Assignment(tm.Identifier("instance"), nct); //NOI18N BlockTree staticInit = tm.Block(Collections.singletonList(tm.ExpressionStatement(stat)), true); members.add(staticInit); members.add(gu.createGetter(staticField)); ClassTree newCT = gu.insertClassMembers(ct, members); copy.rewrite(ct, newCT); }
Example #25
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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()))); }
Example #26
Source File: AssignmentIssues.java From netbeans with Apache License 2.0 | 5 votes |
@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); }
Example #27
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitAssignment(AssignmentTree expected, Tree actual) { Optional<AssignmentTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getVariable(), other.get().getVariable()); scan(expected.getExpression(), other.get().getExpression()); return null; }
Example #28
Source File: Main.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitAssignment(AssignmentTree node, Void ignored) { TreePath path = TreePath.getPath(getCurrentPath(), node.getExpression()); if (trees.getTypeMirror(path).getKind() == TypeKind.ERROR) throw new AssertionError(path.getLeaf()); return null; }
Example #29
Source File: AddParameterOrLocalFix.java From netbeans with Apache License 2.0 | 5 votes |
/** 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; }
Example #30
Source File: Main.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public Void visitAssignment(AssignmentTree node, Void ignored) { TreePath path = TreePath.getPath(getCurrentPath(), node.getExpression()); if (trees.getTypeMirror(path).getKind() == TypeKind.ERROR) throw new AssertionError(path.getLeaf()); return null; }