Search in sources :

Example 11 with ExceptionMessage

use of org.codehaus.groovy.control.messages.ExceptionMessage in project groovy by apache.

the class ASTTransformationCollectorCodeVisitor method findCollectedAnnotations.

private void findCollectedAnnotations(AnnotationNode aliasNode, AnnotatedNode origin, Integer index, Map<Integer, AnnotationCollectorMode> modes, Map<Integer, List<AnnotationNode>> existing, Map<Integer, List<AnnotationNode>> replacements) {
    ClassNode classNode = aliasNode.getClassNode();
    for (AnnotationNode annotation : classNode.getAnnotations()) {
        if (annotation.getClassNode().getName().equals(AnnotationCollector.class.getName())) {
            AnnotationCollectorMode mode = getMode(annotation);
            if (mode == null) {
                mode = AnnotationCollectorMode.DUPLICATE;
            }
            modes.put(index, mode);
            Expression processorExp = annotation.getMember("processor");
            AnnotationCollectorTransform act = null;
            assertStringConstant(processorExp);
            if (processorExp != null) {
                String className = (String) ((ConstantExpression) processorExp).getValue();
                Class klass = loadTransformClass(className, aliasNode);
                if (klass != null) {
                    try {
                        act = (AnnotationCollectorTransform) klass.newInstance();
                    } catch (InstantiationException e) {
                        source.getErrorCollector().addErrorAndContinue(new ExceptionMessage(e, true, source));
                    } catch (IllegalAccessException e) {
                        source.getErrorCollector().addErrorAndContinue(new ExceptionMessage(e, true, source));
                    }
                }
            } else {
                act = new AnnotationCollectorTransform();
            }
            if (act != null) {
                replacements.put(index, act.visit(annotation, aliasNode, origin, source));
                return;
            }
        }
    }
    if (!replacements.containsKey(index)) {
        existing.put(index, Collections.singletonList(aliasNode));
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ExceptionMessage(org.codehaus.groovy.control.messages.ExceptionMessage) AnnotationCollector(groovy.transform.AnnotationCollector) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) AnnotationCollectorMode(groovy.transform.AnnotationCollectorMode)

Aggregations

ExceptionMessage (org.codehaus.groovy.control.messages.ExceptionMessage)11 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)4 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)2 AnnotationCollector (groovy.transform.AnnotationCollector)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 URISyntaxException (java.net.URISyntaxException)2 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)2 Expression (org.codehaus.groovy.ast.expr.Expression)2 LocatedMessage (org.codehaus.groovy.control.messages.LocatedMessage)2 Message (org.codehaus.groovy.control.messages.Message)2 SyntaxErrorMessage (org.codehaus.groovy.control.messages.SyntaxErrorMessage)2 WarningMessage (org.codehaus.groovy.control.messages.WarningMessage)2 GroovyObject (groovy.lang.GroovyObject)1 GroovyShell (groovy.lang.GroovyShell)1