Search in sources :

Example 16 with ErrorCollector

use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.

the class StaticTypeCheckingVisitor method silentlyVisitMethodNode.

/**
 * visit a method call target, to infer the type. Don't report errors right
 * away, that will be done by a later visitMethod call
 */
protected void silentlyVisitMethodNode(final MethodNode directMethodCallCandidate) {
    // visit is authorized because the classnode belongs to the same source unit
    ErrorCollector collector = new ErrorCollector(typeCheckingContext.getErrorCollector().getConfiguration());
    startMethodInference(directMethodCallCandidate, collector);
}
Also used : ErrorCollector(org.codehaus.groovy.control.ErrorCollector)

Example 17 with ErrorCollector

use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.

the class StaticTypeCheckingVisitor method visitMethod.

@Override
public void visitMethod(final MethodNode node) {
    if (shouldSkipMethodNode(node)) {
        // method has already been visited by a static type checking visitor
        return;
    }
    if (!extension.beforeVisitMethod(node)) {
        ErrorCollector collector = (ErrorCollector) node.getNodeMetaData(ERROR_COLLECTOR);
        if (collector != null) {
            typeCheckingContext.getErrorCollector().addCollectorContents(collector);
        } else {
            startMethodInference(node, typeCheckingContext.getErrorCollector());
        }
        node.removeNodeMetaData(ERROR_COLLECTOR);
    }
    extension.afterVisitMethod(node);
}
Also used : ErrorCollector(org.codehaus.groovy.control.ErrorCollector)

Example 18 with ErrorCollector

use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.

the class ExtendedVerifier method visitConstructorOrMethod.

private void visitConstructorOrMethod(MethodNode node, int methodTarget) {
    visitAnnotations(node, methodTarget);
    for (int i = 0; i < node.getParameters().length; i++) {
        Parameter parameter = node.getParameters()[i];
        visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET);
    }
    if (this.currentClass.isAnnotationDefinition() && !node.isStaticConstructor()) {
        ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration());
        AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector);
        visitor.setReportClass(currentClass);
        visitor.checkReturnType(node.getReturnType(), node);
        if (node.getParameters().length > 0) {
            addError("Annotation members may not have parameters.", node.getParameters()[0]);
        }
        if (node.getExceptions().length > 0) {
            addError("Annotation members may not have a throws clause.", node.getExceptions()[0]);
        }
        ReturnStatement code = (ReturnStatement) node.getCode();
        if (code != null) {
            visitor.visitExpression(node.getName(), code.getExpression(), node.getReturnType());
            visitor.checkCircularReference(currentClass, node.getReturnType(), code.getExpression());
        }
        this.source.getErrorCollector().addCollectorContents(errorCollector);
    }
    Statement code = node.getCode();
    if (code != null) {
        code.visit(this);
    }
}
Also used : Statement(org.codehaus.groovy.ast.stmt.Statement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) ErrorCollector(org.codehaus.groovy.control.ErrorCollector)

Example 19 with ErrorCollector

use of org.codehaus.groovy.control.ErrorCollector in project groovy-core by groovy.

the class ProxyGeneratorAdapter method adjustSuperClass.

private Class adjustSuperClass(Class superClass, final Class[] interfaces) {
    boolean isSuperClassAnInterface = superClass.isInterface();
    if (!isSuperClassAnInterface) {
        return superClass;
    }
    Class result = Object.class;
    Set<ClassNode> traits = new LinkedHashSet<ClassNode>();
    // check if it's a trait
    collectTraits(superClass, traits);
    if (interfaces != null) {
        for (Class anInterface : interfaces) {
            collectTraits(anInterface, traits);
        }
    }
    if (!traits.isEmpty()) {
        String name = superClass.getName() + "$TraitAdapter";
        ClassNode cn = new ClassNode(name, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE, traits.toArray(new ClassNode[traits.size()]), null);
        CompilationUnit cu = new CompilationUnit(loader);
        CompilerConfiguration config = new CompilerConfiguration();
        SourceUnit su = new SourceUnit(name + "wrapper", "", config, loader, new ErrorCollector(config));
        cu.addSource(su);
        cu.compile(Phases.CONVERSION);
        su.getAST().addClass(cn);
        cu.compile(Phases.CLASS_GENERATION);
        @SuppressWarnings("unchecked") List<GroovyClass> classes = (List<GroovyClass>) cu.getClasses();
        for (GroovyClass groovyClass : classes) {
            if (groovyClass.getName().equals(name)) {
                return loader.defineClass(name, groovyClass.getBytes());
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) ClassNode(org.codehaus.groovy.ast.ClassNode) GroovyClass(org.codehaus.groovy.tools.GroovyClass) ErrorCollector(org.codehaus.groovy.control.ErrorCollector) SourceUnit(org.codehaus.groovy.control.SourceUnit) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) GroovyClass(org.codehaus.groovy.tools.GroovyClass) GroovyObject(groovy.lang.GroovyObject) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ErrorCollector (org.codehaus.groovy.control.ErrorCollector)19 ArrayList (java.util.ArrayList)6 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)6 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)5 SourceUnit (org.codehaus.groovy.control.SourceUnit)5 List (java.util.List)4 ClassNode (org.codehaus.groovy.ast.ClassNode)4 GroovyClass (org.codehaus.groovy.tools.GroovyClass)4 GroovyObject (groovy.lang.GroovyObject)3 LinkedHashSet (java.util.LinkedHashSet)3 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)3 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)3 Script (groovy.lang.Script)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 ReturnStatement (org.codehaus.groovy.ast.stmt.ReturnStatement)2 Statement (org.codehaus.groovy.ast.stmt.Statement)2 GroovityClassLoader (com.disney.groovity.compile.GroovityClassLoader)1 GroovityCompilerEvent (com.disney.groovity.compile.GroovityCompilerEvent)1 TransformedSource (com.disney.groovity.compile.GroovitySourceTransformer.TransformedSource)1