com.sun.source.tree.LabeledStatementTree Java Examples

The following examples show how to use com.sun.source.tree.LabeledStatementTree. 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: CopyFinder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean visitLabeledStatement(LabeledStatementTree node, TreePath p) {
    if (p == null) {
        return super.visitLabeledStatement(node, p); 
    }
    LabeledStatementTree lst = (LabeledStatementTree)p.getLeaf();
    
    String ident = lst.getLabel().toString();

    if (ident.startsWith("$")) { // NOI18N
        if (bindState.variables2Names.containsKey(ident)) {
            if (!node.getLabel().contentEquals(bindState.variables2Names.get(ident))) {
                return false;
            }
        } else {
            bindState.variables2Names.put(ident, node.getLabel().toString());
        }
    } else {
        if (!node.getLabel().toString().equals(ident)) {
            return false;
        }
    }
    return scan(node.getStatement(), lst.getStatement(), p);
}
 
Example #2
Source File: RenameRefactoringPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String clashes(TreePath path, final String newName, CompilationInfo info) {
    TreePath parent = path.getParentPath();
    while(parent != null) {
        if(parent.getLeaf().getKind() == Tree.Kind.LABELED_STATEMENT) {
            LabeledStatementTree parentLabel = (LabeledStatementTree) parent.getLeaf();
            if(newName.equals(parentLabel.getLabel().toString())) {
                return NbBundle.getMessage(RenameRefactoringPlugin.class, "ERR_LabelClash", newName);
            }
        }
        parent = parent.getParentPath();
    }
    final String[] result = new String[1];
    new ErrorAwareTreeScanner<Void, Void>() {
        
        @Override
        public Void visitLabeledStatement(LabeledStatementTree tree, Void p) {
            if(newName.equals(tree.getLabel().toString())) {
                result[0] = NbBundle.getMessage(RenameRefactoringPlugin.class, "ERR_LabelClash", newName);
            }
            return super.visitLabeledStatement(tree, p);
        }
    }.scan(path.getLeaf(), null);
    return result[0];
}
 
Example #3
Source File: TreeDuplicator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Tree visitLabeledStatement(LabeledStatementTree tree, Void p) {
    LabeledStatementTree n = make.LabeledStatement(tree.getLabel(), tree.getStatement());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
Example #4
Source File: MoreTrees.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<TreePath> visitLabeledStatement(@Nullable LabeledStatementTree node, Void v) {
  if (node == null) {
    return Optional.absent();
  } else if (isMatch(node, node.getLabel())) {
    return currentPathPlus(node);
  }

  return super.visitLabeledStatement(node, v);
}
 
Example #5
Source File: TreeDiffer.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitLabeledStatement(LabeledStatementTree expected, Tree actual) {
  Optional<LabeledStatementTree> other = checkTypeAndCast(expected, actual);
  if (!other.isPresent()) {
    addTypeMismatch(expected, actual);
    return null;
  }

  checkForDiff(expected.getLabel().contentEquals(other.get().getLabel()),
      "Expected statement label to be <%s> but was <%s>.",
      expected.getLabel(), other.get().getLabel());

  scan(expected.getStatement(), other.get().getStatement());
  return null;
}
 
Example #6
Source File: TreeConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private TreeNode convertLabeledStatement(LabeledStatementTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  return new LabeledStatement()
      .setLabel(
          (SimpleName) new SimpleName(node.getLabel().toString()).setPosition(getPosition(node)))
      .setBody((Statement) convert(node.getStatement(), path));
}
 
Example #7
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitLabeledStatement(LabeledStatementTree node, Void unused) {
  sync(node);
  builder.open(ZERO);
  visit(node.getLabel());
  token(":");
  builder.forcedBreak();
  builder.close();
  scan(node.getStatement(), null);
  return null;
}
 
Example #8
Source File: CompletenessStressTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean testBlock(StringWriter writer, SourcePositions sp, String text, CompilationUnitTree cut, BlockTree blockTree) {
    boolean success = true;
    for (StatementTree st : blockTree.getStatements()) {
        if (isLegal(st)) {
            success &= testStatement(writer, sp, text, cut, st);
        }
        if (st instanceof IfTree) {
            IfTree ifTree = (IfTree) st;
            success &= testBranch(writer, sp, text, cut, ifTree.getThenStatement());
            success &= testBranch(writer, sp, text, cut, ifTree.getElseStatement());
        } else if (st instanceof WhileLoopTree) {
            WhileLoopTree whileLoopTree = (WhileLoopTree) st;
            success &= testBranch(writer, sp, text, cut, whileLoopTree.getStatement());
        } else if (st instanceof DoWhileLoopTree) {
            DoWhileLoopTree doWhileLoopTree = (DoWhileLoopTree) st;
            success &= testBranch(writer, sp, text, cut, doWhileLoopTree.getStatement());
        } else if (st instanceof ForLoopTree) {
            ForLoopTree forLoopTree = (ForLoopTree) st;
            success &= testBranch(writer, sp, text, cut, forLoopTree.getStatement());
        } else if (st instanceof LabeledStatementTree) {
            LabeledStatementTree labelTree = (LabeledStatementTree) st;
            success &= testBranch(writer, sp, text, cut, labelTree.getStatement());
        } else if (st instanceof SwitchTree) {
            SwitchTree switchTree = (SwitchTree) st;
            for (CaseTree caseTree : switchTree.getCases()) {
                for (StatementTree statementTree : caseTree.getStatements()) {
                    success &= testBranch(writer, sp, text, cut, statementTree);
                }
            }
        }
    }
    return success;
}
 
Example #9
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Void visitLabeledStatement(LabeledStatementTree node, Void unused) {
    sync(node);
    builder.open(ZERO);
    visit(node.getLabel());
    token(":");
    builder.forcedBreak();
    builder.close();
    scan(node.getStatement(), null);
    return null;
}
 
Example #10
Source File: TreeNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitLabeledStatement(LabeledStatementTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();
    
    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitLabeledStatement(tree, below);
    
    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
 
Example #11
Source File: LabelsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Void visitLabeledStatement(LabeledStatementTree node, Object p) {
    System.err.println("visitLabeledStatement: " + node.getLabel());
    super.visitLabeledStatement(node, p);
    LabeledStatementTree copy = make.setLabel(node, node.getLabel() + "0");
    this.copy.rewrite(node, copy);
    return null;
}
 
Example #12
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitLabeledStatement(LabeledStatementTree node, Void unused) {
    sync(node);
    builder.open(ZERO);
    visit(node.getLabel());
    token(":");
    builder.forcedBreak();
    builder.close();
    scan(node.getStatement(), null);
    return null;
}
 
Example #13
Source File: TryCatchFinally.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Note: if the labeled statement is 1st, in efab.scan(), the visit method is called without
 * prior scan(tree, param). This LabeledStatement is actually a target of break+continue, so
 * it must be also added to seenTrees.s
 */
@Override
public Void visitLabeledStatement(LabeledStatementTree node, Collection<TreePath> p) {
    seenTrees.add(node);
    return super.visitLabeledStatement(node, p);
}
 
Example #14
Source File: Flow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitContinue(ContinueTree node, ConstructorData p) {
    StatementTree loop = info.getTreeUtilities().getBreakContinueTarget(getCurrentPath());

    if (loop == null) {
        super.visitContinue(node, p);
        return null;
    }

    Tree resumePoint;

    if (loop.getKind() == Kind.LABELED_STATEMENT) {
        loop = ((LabeledStatementTree) loop).getStatement();
    }
    
    switch (loop.getKind()) {
        case WHILE_LOOP:
            resumePoint = ((WhileLoopTree) loop).getCondition();
            break;
        case FOR_LOOP: {
                ForLoopTree flt = (ForLoopTree)loop;
                resumePoint = null;
                if (flt.getUpdate() != null && !flt.getUpdate().isEmpty()) {
                    // resume will react on the 1st Tree of the update statement (always processed left to right)
                    resumePoint = flt.getUpdate().get(0);
                } 
                if (resumePoint == null) {
                    resumePoint = flt.getCondition();
                }
                if (resumePoint == null) {
                    resumePoint = flt.getStatement();
                }
        }
            break;
        case DO_WHILE_LOOP:
            resumePoint = ((DoWhileLoopTree) loop).getCondition();
            break;
        case ENHANCED_FOR_LOOP:
            resumePoint = ((EnhancedForLoopTree) loop).getStatement();
            break;
        default:
            resumePoint = null;
            break;
    }

    if (resumePoint != null) {
        recordResume(resumeBefore, resumePoint, variable2State);
    }

    variable2State = new HashMap< Element, State>();

    super.visitContinue(node, p);
    return null;
}
 
Example #15
Source File: Flow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitLabeledStatement(LabeledStatementTree node, ConstructorData p) {
    super.visitLabeledStatement(node, p);
    return null;
}
 
Example #16
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<? extends TypeMirror> visitLabeledStatement(LabeledStatementTree node, Object p) {
    return null;
}
 
Example #17
Source File: InfiniteRecursion.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public State visitLabeledStatement(LabeledStatementTree node, Void p) {
    registerBreakTarget(node);
    registerBreakTarget(node.getStatement());
    return super.visitLabeledStatement(node, p);
}
 
Example #18
Source File: TreeMirrorMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public JCTree visitLabeledStatement(LabeledStatementTree node, Void p) {
	return node.getStatement().accept(this, p);
}
 
Example #19
Source File: ErrorDescriptionFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
private static int[] computeNameSpan(Tree tree, HintContext context) {
    switch (tree.getKind()) {
        case LABELED_STATEMENT:
            return context.getInfo().getTreeUtilities().findNameSpan((LabeledStatementTree) tree);
        case METHOD:
            return context.getInfo().getTreeUtilities().findNameSpan((MethodTree) tree);
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            return context.getInfo().getTreeUtilities().findNameSpan((ClassTree) tree);
        case VARIABLE:
            return context.getInfo().getTreeUtilities().findNameSpan((VariableTree) tree);
        case MEMBER_SELECT:
            //XXX:
            MemberSelectTree mst = (MemberSelectTree) tree;
            int[] span = context.getInfo().getTreeUtilities().findNameSpan(mst);

            if (span == null) {
                int end = (int) context.getInfo().getTrees().getSourcePositions().getEndPosition(context.getInfo().getCompilationUnit(), tree);
                span = new int[] {end - mst.getIdentifier().length(), end};
            }
            return span;
        case METHOD_INVOCATION:
            return computeNameSpan(((MethodInvocationTree) tree).getMethodSelect(), context);
        case BLOCK:
            Collection<? extends TreePath> prefix = context.getMultiVariables().get("$$1$");
            
            if (prefix != null) {
                BlockTree bt = (BlockTree) tree;
                
                if (bt.getStatements().size() > prefix.size()) {
                    return computeNameSpan(bt.getStatements().get(prefix.size()), context);
                }
            }
        default:
            int start = (int) context.getInfo().getTrees().getSourcePositions().getStartPosition(context.getInfo().getCompilationUnit(), tree);
            if (    StatementTree.class.isAssignableFrom(tree.getKind().asInterface())
                && tree.getKind() != Kind.EXPRESSION_STATEMENT
                && tree.getKind() != Kind.BLOCK) {
                TokenSequence<?> ts = context.getInfo().getTokenHierarchy().tokenSequence();
                ts.move(start);
                if (ts.moveNext()) {
                    return new int[] {ts.offset(), ts.offset() + ts.token().length()};
                }
            }
            return new int[] {
                start,
                Math.min((int) context.getInfo().getTrees().getSourcePositions().getEndPosition(context.getInfo().getCompilationUnit(), tree),
                         findLineEnd(context.getInfo(), start)),
            };
    }
}
 
Example #20
Source File: Breadcrumbs.java    From compile-testing with Apache License 2.0 4 votes vote down vote up
@Override
public String visitLabeledStatement(LabeledStatementTree reference, Void v) {
  return (reference != null) ? detailedKindString(reference, reference.getLabel()) : "";
}
 
Example #21
Source File: GeneratorUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitLabeledStatement(LabeledStatementTree node, Object p) {
    return scan(node.getStatement(), p);
}