本文整理汇总了Java中com.sun.source.tree.SwitchTree.getCases方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchTree.getCases方法的具体用法?Java SwitchTree.getCases怎么用?Java SwitchTree.getCases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.SwitchTree
的用法示例。
在下文中一共展示了SwitchTree.getCases方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: visitSwitch
import com.sun.source.tree.SwitchTree; //导入方法依赖的package包/类
@Override
public State visitSwitch(SwitchTree node, Void p) {
registerBreakTarget(node);
State s;
if (returnIfRecurse(s= scan(node.getExpression(), p))) {
return s;
}
// look for the default case, but cannot return immediately as some return / break inside could
// slip unnoticed.
boolean defaultFound = false;
Set<Tree> saveBreaks = breakContinueJumps;
Set<Tree> collectBreaks = Collections.emptySet();
State lastState = State.NO;
boolean saveDefinite = definitePath;
definitePath = false;
for (CaseTree ct : node.getCases()) {
if (ct.getExpression() == null) {
defaultFound = true;
}
knownResult = null;
breakContinueJumps = new HashSet<Tree>();
s = scan(ct, p);
if (s == State.RETURN) {
// possible return reachable from the branch, bail out
definitePath = saveDefinite;
return knownResult = s;
// the branch just jumped off
} else {
// the branch recurses. But if the branch also contains breaks out of the switch, or out of outer
// cycles, those breaks must have been found before the recursion instruction. Any jumps to
// nested statements should have been cleared by scan().
boolean self = breakContinueJumps.remove(node);
if (self || !breakContinueJumps.isEmpty()) {
// at least one way out
saveBreaks.addAll(breakContinueJumps);
saveBreaks.addAll(collectBreaks);
breakContinueJumps = saveBreaks;
definitePath = saveDefinite;
recursionPoints.clear();
return State.NO;
}
lastState = s;
}
}
definitePath = saveDefinite;
if (defaultFound) {
return lastState;
} else {
recursionPoints.clear();
return State.NO;
}
}
示例9: visitSwitch
import com.sun.source.tree.SwitchTree; //导入方法依赖的package包/类
public Boolean visitSwitch(SwitchTree node, ConstructorData p) {
scan(node.getExpression(), null);
Map< Element, State> origVariable2State = new HashMap< Element, State>(variable2State);
variable2State = new HashMap< Element, State>();
boolean exhaustive = false;
for (CaseTree ct : node.getCases()) {
variable2State = mergeOr(variable2State, origVariable2State);
if (ct.getExpression() == null) {
exhaustive = true;
}
scan(ct, null);
}
if (!exhaustive) {
variable2State = mergeOr(variable2State, origVariable2State);
}
return null;
}
示例10: performRewrite
import com.sun.source.tree.SwitchTree; //导入方法依赖的package包/类
@Override
protected void performRewrite(final TransformationContext ctx) {
WorkingCopy wc = ctx.getWorkingCopy();
final TreeMaker make = wc.getTreeMaker();
final TreePath tp = ctx.getPath();
SwitchTree st = (SwitchTree) tp.getLeaf();
int insertIndex = 0;
boolean hadDefault = false;
for (CaseTree ct : st.getCases()) {
if (ct.getExpression() == null) {
hadDefault = true;
break;
}
insertIndex++;
}
for (String name : names) {
st = make.insertSwitchCase(st, insertIndex++, make.Case(make.Identifier(name), Collections.singletonList(make.Break(null))));
}
if (!hadDefault && defaultTemplate != null) {
StatementTree stmt = ctx.getWorkingCopy().getTreeUtilities().parseStatement(defaultTemplate, new SourcePositions[1]);
Scope s = ctx.getWorkingCopy().getTrees().getScope(tp);
ctx.getWorkingCopy().getTreeUtilities().attributeTree(stmt, s);
st = GeneratorUtilities.get(ctx.getWorkingCopy()).importFQNs(make.addSwitchCase(st, make.Case(null, Collections.singletonList(stmt))));
new ErrorAwareTreePathScanner<Void, Void>() {
@Override public Void visitIdentifier(IdentifierTree node, Void p) {
if (node.getName().contentEquals("$expression")) {
ExpressionTree expression = ((SwitchTree) tp.getLeaf()).getExpression();
if (expression.getKind() == Tree.Kind.PARENTHESIZED) {
expression = ((ParenthesizedTree) expression).getExpression();
}
if (JavaFixUtilities.requiresParenthesis(expression, node, getCurrentPath().getParentPath().getLeaf())) {
expression = make.Parenthesized(expression);
}
ctx.getWorkingCopy().rewrite(node, expression);
}
return super.visitIdentifier(node, p);
}
}.scan(new TreePath(ctx.getPath(), st), null);
}
wc.rewrite(tp.getLeaf(), st);
}
示例11: visitSwitch
import com.sun.source.tree.SwitchTree; //导入方法依赖的package包/类
@Override
public Node visitSwitch(SwitchTree tree, Void p) {
switchExpr = unbox(scan(tree.getExpression(), p));
extendWithNode(new MarkerNode(tree, "start of switch statement", env.getTypeUtils()));
Label oldBreakTargetL = breakTargetL;
breakTargetL = new Label();
for (CaseTree caseTree : tree.getCases()) {
scan(caseTree, p);
}
addLabelForNextNode(breakTargetL);
breakTargetL = oldBreakTargetL;
return null;
}