本文整理汇总了Java中com.sun.source.tree.SwitchTree类的典型用法代码示例。如果您正苦于以下问题:Java SwitchTree类的具体用法?Java SwitchTree怎么用?Java SwitchTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwitchTree类属于com.sun.source.tree包,在下文中一共展示了SwitchTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree node, Void unused) {
sync(node);
token("switch");
builder.space();
token("(");
scan(skipParen(node.getExpression()), null);
token(")");
builder.space();
tokenBreakTrailingComment("{", plusTwo);
builder.blankLineWanted(BlankLineWanted.NO);
builder.open(plusTwo);
boolean first = true;
for (CaseTree caseTree : node.getCases()) {
if (!first) {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
scan(caseTree, null);
first = false;
}
builder.close();
builder.forcedBreak();
builder.blankLineWanted(BlankLineWanted.NO);
token("}", plusFour);
return null;
}
示例2: testBlock
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
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;
}
示例3: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Result visitSwitch(SwitchTree node, BreakContext cxt) {
Result result = null;
boolean seenDefault = false;
cxt.loopDepth++;
try {
for (CaseTree caseTree : node.getCases()) {
if (caseTree.getExpression() == null) {
seenDefault = true;
}
if (result == null) {
result = caseTree.accept(this, cxt);
} else {
result = result.or(caseTree.accept(this, cxt));
}
}
if (!seenDefault) {
result = result.or(NEVER_EXITS);
}
return result;
} finally {
cxt.loopDepth--;
}
}
示例4: matchSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Description matchSwitch(SwitchTree tree, VisitorState state) {
Type switchType = ASTHelpers.getType(tree.getExpression());
if (switchType.asElement().getKind() != ElementKind.ENUM) {
return Description.NO_MATCH;
}
// default case is present
if (tree.getCases().stream().anyMatch(c -> c.getExpression() == null)) {
return Description.NO_MATCH;
}
ImmutableSet<String> handled =
tree.getCases()
.stream()
.map(CaseTree::getExpression)
.filter(IdentifierTree.class::isInstance)
.map(e -> ((IdentifierTree) e).getName().toString())
.collect(toImmutableSet());
Set<String> unhandled = Sets.difference(ASTHelpers.enumValues(switchType.asElement()), handled);
if (unhandled.isEmpty()) {
return Description.NO_MATCH;
}
return buildDescription(tree).setMessage(buildMessage(unhandled)).build();
}
示例5: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree node, Void p) {
ExpressionTree expr = node.getExpression();
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);
for (CaseTree caseExpr : node.getCases()) {
ExpressionTree realCaseExpr = caseExpr.getExpression();
if (realCaseExpr != null) {
AnnotatedTypeMirror caseType = atypeFactory.getAnnotatedType(realCaseExpr);
this.commonAssignmentCheck(exprType, caseType, caseExpr,
"switch.type.incompatible", false);
}
}
return super.visitSwitch(node, p);
}
示例6: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Tree visitSwitch(SwitchTree tree, Void p) {
SwitchTree n = make.Switch(tree.getExpression(), tree.getCases());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例7: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
public Boolean visitSwitch(SwitchTree node, TreePath p) {
if (p == null) {
super.visitSwitch(node, p);
return false;
}
SwitchTree st = (SwitchTree) p.getLeaf();
if (!scan(node.getExpression(), st.getExpression(), p)) {
return false;
}
return checkLists(node.getCases(), st.getCases(), p);
}
示例8: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree node, EnumSet<UseTypes> p) {
scan(node.getExpression(), EnumSet.of(UseTypes.READ));
for (CaseTree ct : node.getCases()) {
scan(ct, null);
}
return null;
}
示例9: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Number visitSwitch(SwitchTree node, Void p) {
List<? extends CaseTree> cases = (List<? extends CaseTree>) resolveMultiParameters(node.getCases());
SwitchTree nue = make.Switch(node.getExpression(), cases);
rewrite(node, nue);
return super.visitSwitch(node, p);
}
示例10: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Object visitSwitch(SwitchTree node, Object p) {
depth++;
Object o = super.visitSwitch(node, p);
depth--;
return o;
}
示例11: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitSwitch(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例12: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Boolean visitSwitch(SwitchTree node, Void p) {
boolean lastCaseExit = false;
boolean defaultSeen = false;
Set<Element> enumValues = null;
if (node.getExpression() != null) {
TypeMirror exprType = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
if (isValidType(exprType) && exprType.getKind() == TypeKind.DECLARED) {
Element el = ((DeclaredType)exprType).asElement();
enumValues = new HashSet<>();
for (Element f : el.getEnclosedElements()) {
if (f.getKind() == ElementKind.ENUM_CONSTANT) {
enumValues.add(f);
}
}
}
}
for (CaseTree ct : node.getCases()) {
Boolean res = scan(ct, null);
if (res == Boolean.FALSE) {
return res;
}
lastCaseExit = res == Boolean.TRUE;
if (ct.getExpression() == null) {
defaultSeen = true;
} else if (enumValues != null ) {
TreePath casePath = new TreePath(getCurrentPath(), ct);
Element v = info.getTrees().getElement(new TreePath(
casePath, ct.getExpression()));
if (v != null) {
enumValues.remove(v);
}
}
}
if (enumValues != null && enumValues.isEmpty()) {
defaultSeen = true;
}
return lastCaseExit == Boolean.TRUE && defaultSeen;
}
示例13: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitSwitch(SwitchTree node, Object p) {
if (theExpression == null) {
initExpression(node.getExpression());
}
for (CaseTree cs : node.getCases()) {
if (cs.getExpression() != null) {
TreePath casePath = new TreePath(getCurrentPath(), cs);
TypeMirror caseType = info.getTrees().getTypeMirror(new TreePath(casePath, cs.getExpression()));
return Collections.singletonList(caseType);
}
}
// cannot determine
return null;
}
示例14: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public List<Tree> visitSwitch(SwitchTree node, ExpressionScanner.ExpressionsInfo p) {
List<Tree> result = null;
if (acceptsTree(node)) {
result = scan(node.getExpression(), p);
}
return reduce(result, scan(node.getCases(), p));
}
示例15: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree tree, VisitorState visitorState) {
VisitorState state = visitorState.withPath(getCurrentPath());
for (SwitchTreeMatcher matcher : switchMatchers) {
if (!isSuppressed(matcher, state)) {
try {
reportMatch(matcher.matchSwitch(tree, state), tree, state);
} catch (Throwable t) {
handleError(matcher, t);
}
}
}
return super.visitSwitch(tree, state);
}