本文整理汇总了Java中org.codehaus.groovy.ast.CodeVisitorSupport类的典型用法代码示例。如果您正苦于以下问题:Java CodeVisitorSupport类的具体用法?Java CodeVisitorSupport怎么用?Java CodeVisitorSupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeVisitorSupport类属于org.codehaus.groovy.ast包,在下文中一共展示了CodeVisitorSupport类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visit
import org.codehaus.groovy.ast.CodeVisitorSupport; //导入依赖的package包/类
private static void visit(Closure closure, CodeVisitorSupport visitor) {
if (closure != null) {
ClassNode classNode = closure.getMetaClass().getClassNode();
if (classNode == null) {
throw new GroovyRuntimeException(
"DataSet unable to evaluate expression. AST not available for closure: " + closure.getMetaClass().getTheClass().getName() +
". Is the source code on the classpath?");
}
List methods = classNode.getDeclaredMethods("doCall");
if (!methods.isEmpty()) {
MethodNode method = (MethodNode) methods.get(0);
if (method != null) {
Statement statement = method.getCode();
if (statement != null) {
statement.visit(visitor);
}
}
}
}
}
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:DataSet.java
示例2: correctAccessedVariable
import org.codehaus.groovy.ast.CodeVisitorSupport; //导入依赖的package包/类
private static void correctAccessedVariable(final InnerClassNode closureClass, ClosureExpression ce) {
CodeVisitorSupport visitor = new CodeVisitorSupport() {
@Override
public void visitVariableExpression(VariableExpression expression) {
Variable v = expression.getAccessedVariable();
if (v==null) return;
if (!(v instanceof FieldNode)) return;
String name = expression.getName();
FieldNode fn = closureClass.getDeclaredField(name);
if (fn != null) { // only overwrite if we find something more specific
expression.setAccessedVariable(fn);
}
}
};
visitor.visitClosureExpression(ce);
}
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClosureWriter.java
示例3: getUniqueVariableName
import org.codehaus.groovy.ast.CodeVisitorSupport; //导入依赖的package包/类
private String getUniqueVariableName(final String name, Statement code) {
if (code == null) return name;
final Object[] found = new Object[1];
CodeVisitorSupport cv = new CodeVisitorSupport() {
public void visitVariableExpression(VariableExpression expression) {
if (expression.getName().equals(name)) found[0] = Boolean.TRUE;
}
};
code.visit(cv);
if (found[0] != null) return getUniqueVariableName("_" + name, code);
return name;
}
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:EnumCompletionVisitor.java
示例4: checkReturnInObjectInitializer
import org.codehaus.groovy.ast.CodeVisitorSupport; //导入依赖的package包/类
private static void checkReturnInObjectInitializer(List<Statement> init) {
CodeVisitorSupport cvs = new CodeVisitorSupport() {
@Override
public void visitClosureExpression(ClosureExpression expression) {
// return is OK in closures in object initializers
}
public void visitReturnStatement(ReturnStatement statement) {
throw new RuntimeParserException("'return' is not allowed in object initializer", statement);
}
};
for (Statement stm : init) {
stm.visit(cvs);
}
}
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:Verifier.java
注:本文中的org.codehaus.groovy.ast.CodeVisitorSupport类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论