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


Java SimpleTreeVisitor类代码示例

本文整理汇总了Java中com.sun.source.util.SimpleTreeVisitor的典型用法代码示例。如果您正苦于以下问题:Java SimpleTreeVisitor类的具体用法?Java SimpleTreeVisitor怎么用?Java SimpleTreeVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleTreeVisitor类属于com.sun.source.util包,在下文中一共展示了SimpleTreeVisitor类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitAssignment

import com.sun.source.util.SimpleTreeVisitor; //导入依赖的package包/类
/**
 * If we're assigning to an identifier then we see if this identifier has the same name as one of the
 * non-final params in scope. We only care about assignments to an identifier.
 *
 * Thus, a = 5; would be flagged by array[0] = "foo" would not be flagged. The left hand side of the assignment
 * operation must be an identifier in order for us to flag it.
 *
 * @param assignmentTree assignment AST node
 * @param nonFinalParamsInScope params to check against the LHS of the assignment
 */
@Override
public Void visitAssignment(AssignmentTree assignmentTree, Set<Name> nonFinalParamsInScope) {
    if (nonFinalParamsInScope != null && !nonFinalParamsInScope.isEmpty()) {
        ExpressionTree variable = assignmentTree.getVariable();
        variable.accept(new SimpleTreeVisitor<Void, Void>() {
            @Override
            public Void visitIdentifier(IdentifierTree node, Void aVoid) {
                if (nonFinalParamsInScope.contains(node.getName())) {
                    // printing a message of type error counts as a compilation error
                    trees.printMessage(Diagnostic.Kind.ERROR,
                            String.format("EFFECTIVELY_FINAL: Assignment to param in `%s`", assignmentTree),
                            node, compilationUnitTree);
                }
                return null;
            }

        }, null);
    }
    return null;
}
 
开发者ID:massfords,项目名称:effectively-final,代码行数:31,代码来源:EffectivelyFinalVisitor.java

示例2: matches

import com.sun.source.util.SimpleTreeVisitor; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree t, VisitorState state) {
  return firstNonNull(
      t.accept(
          new SimpleTreeVisitor<Boolean, Void>() {
            @Override
            public Boolean visitConditionalExpression(
                ConditionalExpressionTree tree, Void unused) {
              return reduce(
                  tree.getTrueExpression().accept(this, null),
                  tree.getFalseExpression().accept(this, null));
            }

            @Override
            protected Boolean defaultAction(Tree node, Void aVoid) {
              Object constValue = ASTHelpers.constValue(node);
              return constValue != null;
            }

            public Boolean reduce(Boolean lhs, Boolean rhs) {
              return firstNonNull(lhs, false) && firstNonNull(rhs, false);
            }
          },
          null),
      false);
}
 
开发者ID:google,项目名称:error-prone,代码行数:27,代码来源:CompileTimeConstantExpressionMatcher.java


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