本文整理汇总了Java中org.codehaus.groovy.ast.ASTNode.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java ASTNode.getClass方法的具体用法?Java ASTNode.getClass怎么用?Java ASTNode.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.ASTNode
的用法示例。
在下文中一共展示了ASTNode.getClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRefDescriptor
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private static String getRefDescriptor(ASTNode ref) {
if (ref instanceof FieldNode) {
FieldNode f = (FieldNode) ref;
return "the field "+f.getName()+" ";
} else if (ref instanceof PropertyNode) {
PropertyNode p = (PropertyNode) ref;
return "the property "+p.getName()+" ";
} else if (ref instanceof ConstructorNode) {
return "the constructor "+ref.getText()+" ";
} else if (ref instanceof MethodNode) {
return "the method "+ref.getText()+" ";
} else if (ref instanceof ClassNode) {
return "the super class "+ref+" ";
}
return "<unknown with class "+ref.getClass()+"> ";
}
示例2: pathUpTo
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
public List<TreeContext> pathUpTo(Class<ASTNode> node, ASTNodePredicate predicate) {
List<TreeContext> path = new LinkedList<TreeContext>();
TreeContext current = lastContext;
boolean found = false;
while (current!=null && !found) {
path.add(current);
ASTNode currentNode = current.node;
if (node==null) {
if (predicate.matches(currentNode)) {
found = true;
}
} else {
if (predicate==null) {
if (currentNode==null || node==currentNode.getClass()) {
found = true;
}
} else {
found = currentNode!=null && node==currentNode.getClass() && predicate.matches(currentNode);
}
}
current = current.parent;
}
if (found) {
return path;
}
return Collections.emptyList();
}
示例3: declare
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
private void declare(Variable var, ASTNode expr) {
String scopeType = "scope";
String variableType = "variable";
if (expr.getClass() == FieldNode.class) {
scopeType = "class";
variableType = "field";
} else if (expr.getClass() == PropertyNode.class) {
scopeType = "class";
variableType = "property";
}
StringBuilder msg = new StringBuilder();
msg.append("The current ").append(scopeType);
msg.append(" already contains a ").append(variableType);
msg.append(" of the name ").append(var.getName());
if (currentScope.getDeclaredVariable(var.getName()) != null) {
addError(msg.toString(), expr);
return;
}
for (VariableScope scope = currentScope.getParent(); scope != null; scope = scope.getParent()) {
// if we are in a class and no variable is declared until
// now, then we can break the loop, because we are allowed
// to declare a variable of the same name as a class member
if (scope.getClassScope() != null) break;
if (scope.getDeclaredVariable(var.getName()) != null) {
// variable already declared
addError(msg.toString(), expr);
break;
}
}
// declare the variable even if there was an error to allow more checks
currentScope.putDeclaredVariable(var);
}
示例4: matches
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
@Override
public boolean matches(final ASTNode node) {
return astNodeClass ==node.getClass();
}
示例5: storeInferredReturnType
import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
/**
* Stores the inferred return type of a closure or a method. We are using a separate key to store
* inferred return type because the inferred type of a closure is {@link Closure}, which is different
* from the inferred type of the code of the closure.
*
* @param node a {@link ClosureExpression} or a {@link MethodNode}
* @param type the inferred return type of the code
* @return the old value of the inferred type
*/
protected ClassNode storeInferredReturnType(final ASTNode node, final ClassNode type) {
if (!(node instanceof ClosureExpression)) {
throw new IllegalArgumentException("Storing inferred return type is only allowed on closures but found "+node.getClass());
}
return (ClassNode) node.putNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE, type);
}