当前位置: 首页>>代码示例>>Java>>正文


Java SwitchTree类代码示例

本文整理汇总了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;
}
 
开发者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


注:本文中的com.sun.source.tree.SwitchTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。