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


Java ASTNode.getClass方法代码示例

本文整理汇总了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()+"> ";
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClassCompletionVerifier.java

示例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();
}
 
开发者ID:apache,项目名称:groovy,代码行数:29,代码来源:ContextualClassCodeVisitor.java

示例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);
}
 
开发者ID:apache,项目名称:groovy,代码行数:38,代码来源:VariableScopeVisitor.java

示例4: matches

import org.codehaus.groovy.ast.ASTNode; //导入方法依赖的package包/类
@Override
public boolean matches(final ASTNode node) {
    return astNodeClass ==node.getClass();
}
 
开发者ID:apache,项目名称:groovy,代码行数:5,代码来源:ContextualClassCodeVisitor.java

示例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);
}
 
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:StaticTypeCheckingVisitor.java


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