Search in sources :

Example 86 with ClassExpression

use of org.codehaus.groovy.ast.expr.ClassExpression in project groovy by apache.

the class AutoCloneASTTransformation method getStyle.

private static AutoCloneStyle getStyle(AnnotationNode node, String name) {
    final Expression member = node.getMember(name);
    if (member != null && member instanceof PropertyExpression) {
        PropertyExpression prop = (PropertyExpression) member;
        Expression oe = prop.getObjectExpression();
        if (oe instanceof ClassExpression) {
            ClassExpression ce = (ClassExpression) oe;
            if (ce.getType().getName().equals("groovy.transform.AutoCloneStyle")) {
                return AutoCloneStyle.valueOf(prop.getPropertyAsString());
            }
        }
    }
    return null;
}
Also used : PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression)

Example 87 with ClassExpression

use of org.codehaus.groovy.ast.expr.ClassExpression in project groovy by apache.

the class NewifyASTTransformation method checkDuplicateNameClashes.

private void checkDuplicateNameClashes(ListExpression list) {
    final Set<String> seen = new HashSet<String>();
    @SuppressWarnings("unchecked") final List<ClassExpression> classes = (List) list.getExpressions();
    for (ClassExpression ce : classes) {
        final String name = ce.getType().getNameWithoutPackage();
        if (seen.contains(name)) {
            addError("Duplicate name '" + name + "' found during @" + MY_NAME + " processing.", ce);
        }
        seen.add(name);
    }
}
Also used : List(java.util.List) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) HashSet(java.util.HashSet)

Example 88 with ClassExpression

use of org.codehaus.groovy.ast.expr.ClassExpression in project groovy by apache.

the class CompileDynamicProcessor method visit.

public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) {
    AnnotationNode node = new AnnotationNode(COMPILESTATIC_NODE);
    node.addMember("value", new PropertyExpression(new ClassExpression(TYPECHECKINGMODE_NODE), "SKIP"));
    return Collections.singletonList(node);
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression)

Example 89 with ClassExpression

use of org.codehaus.groovy.ast.expr.ClassExpression in project groovy by apache.

the class ImmutableASTTransformation method getKnownImmutableClasses.

private List<String> getKnownImmutableClasses(AnnotationNode node) {
    final List<String> immutableClasses = new ArrayList<String>();
    final Expression expression = node.getMember(MEMBER_KNOWN_IMMUTABLE_CLASSES);
    if (expression == null)
        return immutableClasses;
    if (!(expression instanceof ListExpression)) {
        addError("Use the Groovy list notation [el1, el2] to specify known immutable classes via \"" + MEMBER_KNOWN_IMMUTABLE_CLASSES + "\"", node);
        return immutableClasses;
    }
    final ListExpression listExpression = (ListExpression) expression;
    for (Expression listItemExpression : listExpression.getExpressions()) {
        if (listItemExpression instanceof ClassExpression) {
            immutableClasses.add(listItemExpression.getType().getName());
        }
    }
    return immutableClasses;
}
Also used : ListExpression(org.codehaus.groovy.ast.expr.ListExpression) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) ArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ArrayList(java.util.ArrayList) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ToStringASTTransformation.createToString(org.codehaus.groovy.transform.ToStringASTTransformation.createToString)

Aggregations

ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)89 Expression (org.codehaus.groovy.ast.expr.Expression)54 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)52 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)50 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)47 ClassNode (org.codehaus.groovy.ast.ClassNode)44 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)41 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)35 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)32 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)28 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)26 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)21 MethodNode (org.codehaus.groovy.ast.MethodNode)18 StaticMethodCallExpression (org.codehaus.groovy.ast.expr.StaticMethodCallExpression)17 TupleExpression (org.codehaus.groovy.ast.expr.TupleExpression)17 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)15 FieldNode (org.codehaus.groovy.ast.FieldNode)14 Parameter (org.codehaus.groovy.ast.Parameter)14 BlockStatement (org.codehaus.groovy.ast.stmt.BlockStatement)14 ExpressionStatement (org.codehaus.groovy.ast.stmt.ExpressionStatement)14