本文整理汇总了Java中com.sun.source.tree.SwitchTree类的典型用法代码示例。如果您正苦于以下问题:Java SwitchTree类的具体用法?Java SwitchTree怎么用?Java SwitchTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwitchTree类属于com.sun.source.tree包,在下文中一共展示了SwitchTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:tranleduy2000,项目名称:javaide,代码行数:27,代码来源:JavaInputAstVisitor.java
示例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;
}
开发者ID:campolake,项目名称:openjdk9,代码行数:34,代码来源:CompletenessStressTest.java
示例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--;
}
}
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:ControlFlowVisitor.java
示例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();
}
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:MissingCasesInEnumSwitch.java
示例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);
}
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:17,代码来源:FenumVisitor.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java
示例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);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CopyFinder.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:SemanticHighlighterBase.java
示例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);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JavaFixUtilities.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DepthVisitor.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeNode.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:Utilities.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ExpectedTypeResolver.java
示例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));
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ExpressionScanner.java
示例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);
}
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ErrorProneScanner.java
示例16: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Choice<State<JCSwitch>> visitSwitch(final SwitchTree node, State<?> state) {
return chooseSubtrees(
state,
s -> unifyExpression(node.getExpression(), s),
s -> unify(node.getCases(), s),
(expr, cases) -> maker().Switch(expr, List.convert(JCCase.class, cases)));
}
开发者ID:google,项目名称:error-prone,代码行数:9,代码来源:PlaceholderUnificationVisitor.java
示例17: matchAncestor
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
/**
* The target of a jump statement (break or continue) is (1) the enclosing loop if the jump is
* unlabeled (2) the enclosing LabeledStatementTree with matching label if the jump is labeled
* (3) the enclosing switch statement if the jump is a break
*
* <p>If the target of a break or continue statement is encountered before reaching a finally
* block, return NO_MATCH.
*/
@Override
protected MatchResult matchAncestor(Tree leaf, Tree prevTree) {
// (1)
if (label == null) {
switch (leaf.getKind()) {
case WHILE_LOOP:
case DO_WHILE_LOOP:
case FOR_LOOP:
case ENHANCED_FOR_LOOP:
return MatchResult.NO_MATCH;
default:
break;
}
}
// (2)
if (label != null
&& leaf instanceof LabeledStatementTree
&& label.equals(((LabeledStatementTree) leaf).getLabel())) {
return MatchResult.NO_MATCH;
}
// (3)
if (jumpType == JumpType.BREAK && leaf instanceof SwitchTree) {
return MatchResult.NO_MATCH;
}
return super.matchAncestor(leaf, prevTree);
}
开发者ID:google,项目名称:error-prone,代码行数:39,代码来源:Finally.java
示例18: matchSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Description matchSwitch(SwitchTree tree, VisitorState state) {
if (tree.getCases().size() != 2 || tree.getCases().get(0).getStatements().isEmpty()) {
return NO_MATCH;
}
return Reachability.canCompleteNormally(
Iterables.getLast(tree.getCases().get(0).getStatements()))
? describeMatch(tree.getCases().get(1))
: NO_MATCH;
}
开发者ID:google,项目名称:error-prone,代码行数:11,代码来源:ReachabilityTest.java
示例19: matchAncestor
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
/**
* The target of a jump statement (break or continue) is
* (1) the enclosing loop if the jump is unlabeled
* (2) the enclosing LabeledStatementTree with matching label if the jump is labeled
* (3) the enclosing switch statement if the jump is a break
*
* If the target of a break or continue statement is encountered before reaching a finally
* block, return NO_MATCH.
*/
@Override
protected MatchResult matchAncestor(Tree leaf, Tree prevTree) {
// (1)
if (label == null) {
switch (leaf.getKind()) {
case WHILE_LOOP:
case DO_WHILE_LOOP:
case FOR_LOOP:
case ENHANCED_FOR_LOOP:
return MatchResult.NO_MATCH;
default:
break;
}
}
// (2)
if (label != null
&& leaf instanceof LabeledStatementTree
&& label.equals(((LabeledStatementTree) leaf).getLabel())) {
return MatchResult.NO_MATCH;
}
// (3)
if (jumpType == JumpType.BREAK && leaf instanceof SwitchTree) {
return MatchResult.NO_MATCH;
}
return super.matchAncestor(leaf, prevTree);
}
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:40,代码来源:Finally.java
示例20: visitSwitch
import com.sun.source.tree.SwitchTree; //导入依赖的package包/类
@Override
public Void visitSwitch(SwitchTree expected, Tree actual) {
Optional<SwitchTree> other = checkTypeAndCast(expected, actual);
if (!other.isPresent()) {
addTypeMismatch(expected, actual);
return null;
}
scan(expected.getExpression(), other.get().getExpression());
parallelScan(expected.getCases(), other.get().getCases());
return null;
}
开发者ID:google,项目名称:compile-testing,代码行数:13,代码来源:TreeDiffer.java
注:本文中的com.sun.source.tree.SwitchTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论