Search in sources :

Example 66 with ClassNode

use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.

the class Traits method findHelpers.

static TraitHelpersTuple findHelpers(final ClassNode trait) {
    ClassNode helperClassNode = null;
    ClassNode fieldHelperClassNode = null;
    Iterator<InnerClassNode> innerClasses = trait.redirect().getInnerClasses();
    if (innerClasses != null && innerClasses.hasNext()) {
        // trait defined in same source unit
        while (innerClasses.hasNext()) {
            ClassNode icn = innerClasses.next();
            if (icn.getName().endsWith(Traits.FIELD_HELPER)) {
                fieldHelperClassNode = icn;
            } else if (icn.getName().endsWith(Traits.TRAIT_HELPER)) {
                helperClassNode = icn;
            }
        }
    } else {
        // precompiled trait
        try {
            final ClassLoader classLoader = trait.getTypeClass().getClassLoader();
            String helperClassName = Traits.helperClassName(trait);
            helperClassNode = ClassHelper.make(classLoader.loadClass(helperClassName));
            try {
                fieldHelperClassNode = ClassHelper.make(classLoader.loadClass(Traits.fieldHelperClassName(trait)));
            } catch (ClassNotFoundException e) {
            // not a problem, the field helper may be absent
            }
        } catch (ClassNotFoundException e) {
            throw new GroovyBugError("Couldn't find trait helper classes on compile classpath!", e);
        }
    }
    return new TraitHelpersTuple(helperClassNode, fieldHelperClassNode);
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) GroovyBugError(org.codehaus.groovy.GroovyBugError) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode)

Example 67 with ClassNode

use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.

the class Java5 method configureTypeArguments.

private GenericsType[] configureTypeArguments(Type[] ta) {
    if (ta.length == 0)
        return null;
    GenericsType[] gts = new GenericsType[ta.length];
    for (int i = 0; i < ta.length; i++) {
        ClassNode t = configureType(ta[i]);
        if (ta[i] instanceof WildcardType) {
            GenericsType[] gen = t.getGenericsTypes();
            gts[i] = gen[0];
        } else {
            gts[i] = new GenericsType(t);
        }
    }
    return gts;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) WildcardType(java.lang.reflect.WildcardType) GenericsType(org.codehaus.groovy.ast.GenericsType)

Example 68 with ClassNode

use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.

the class Java5 method configureWildcardType.

private ClassNode configureWildcardType(WildcardType wildcardType) {
    ClassNode base = ClassHelper.makeWithoutCaching("?");
    base.setRedirect(ClassHelper.OBJECT_TYPE);
    //TODO: more than one lower bound for wildcards?
    ClassNode[] lowers = configureTypes(wildcardType.getLowerBounds());
    ClassNode lower = null;
    // TODO: is it safe to remove this? What was the original intention?
    if (lowers != null)
        lower = lowers[0];
    ClassNode[] upper = configureTypes(wildcardType.getUpperBounds());
    GenericsType t = new GenericsType(base, upper, lower);
    t.setWildcard(true);
    ClassNode ref = ClassHelper.makeWithoutCaching(Object.class, false);
    ref.setGenericsTypes(new GenericsType[] { t });
    return ref;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) GenericsType(org.codehaus.groovy.ast.GenericsType)

Example 69 with ClassNode

use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.

the class Java5 method makeClassNode.

private ClassNode makeClassNode(CompileUnit cu, Type t, Class c) {
    ClassNode back = null;
    if (cu != null)
        back = cu.getClass(c.getName());
    if (back == null)
        back = ClassHelper.make(c);
    if (!(t instanceof Class)) {
        ClassNode front = configureType(t);
        front.setRedirect(back);
        return front;
    }
    return back.getPlainNodeReference();
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode)

Example 70 with ClassNode

use of org.codehaus.groovy.ast.ClassNode in project groovy-core by groovy.

the class Java5 method configureTypeVariableDefinition.

public static GenericsType configureTypeVariableDefinition(ClassNode base, ClassNode[] cBounds) {
    ClassNode redirect = base.redirect();
    base.setRedirect(null);
    GenericsType gt;
    if (cBounds == null || cBounds.length == 0) {
        gt = new GenericsType(base);
    } else {
        gt = new GenericsType(base, cBounds, null);
        gt.setName(base.getName());
        gt.setPlaceholder(true);
    }
    base.setRedirect(redirect);
    return gt;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) GenericsType(org.codehaus.groovy.ast.GenericsType)

Aggregations

ClassNode (org.codehaus.groovy.ast.ClassNode)869 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)348 MethodNode (org.codehaus.groovy.ast.MethodNode)193 GenericsType (org.codehaus.groovy.ast.GenericsType)154 LowestUpperBoundClassNode (org.codehaus.groovy.ast.tools.WideningCategories.LowestUpperBoundClassNode)148 Expression (org.codehaus.groovy.ast.expr.Expression)146 Parameter (org.codehaus.groovy.ast.Parameter)135 FieldNode (org.codehaus.groovy.ast.FieldNode)126 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)118 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)117 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)113 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)103 ArrayList (java.util.ArrayList)95 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)92 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)75 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)74 LinkedList (java.util.LinkedList)71 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)71 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)62 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)61