Search in sources :

Example 1 with ResolveVisitor

use of org.codehaus.groovy.control.ResolveVisitor in project groovy by apache.

the class GenericsUtils method resolveClassNode.

private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
    ClassNode dummyClass = new ClassNode("dummy", 0, ClassHelper.OBJECT_TYPE);
    dummyClass.setModule(new ModuleNode(sourceUnit));
    dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
    MethodNode dummyMN = new MethodNode("dummy", 0, parsedNode, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
    dummyMN.setGenericsTypes(mn.getGenericsTypes());
    dummyClass.addMethod(dummyMN);
    ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {

        @Override
        public void addError(final String msg, final ASTNode expr) {
            sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
        }
    };
    visitor.startResolving(dummyClass, sourceUnit);
    return dummyMN.getReturnType();
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) IncorrectTypeHintException(groovy.transform.stc.IncorrectTypeHintException) MethodNode(org.codehaus.groovy.ast.MethodNode) ASTNode(org.codehaus.groovy.ast.ASTNode) ResolveVisitor(org.codehaus.groovy.control.ResolveVisitor) ModuleNode(org.codehaus.groovy.ast.ModuleNode)

Example 2 with ResolveVisitor

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

the class GenericsUtils method resolveClassNode.

private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
    ClassNode dummyClass = new ClassNode("dummy", 0, ClassHelper.OBJECT_TYPE);
    dummyClass.setModule(new ModuleNode(sourceUnit));
    dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
    MethodNode dummyMN = new MethodNode("dummy", 0, parsedNode, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
    dummyMN.setGenericsTypes(mn.getGenericsTypes());
    dummyClass.addMethod(dummyMN);
    ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {

        @Override
        protected void addError(final String msg, final ASTNode expr) {
            sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
        }
    };
    visitor.startResolving(dummyClass, sourceUnit);
    return dummyMN.getReturnType();
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) IncorrectTypeHintException(groovy.transform.stc.IncorrectTypeHintException) MethodNode(org.codehaus.groovy.ast.MethodNode) ASTNode(org.codehaus.groovy.ast.ASTNode) ResolveVisitor(org.codehaus.groovy.control.ResolveVisitor) ModuleNode(org.codehaus.groovy.ast.ModuleNode)

Aggregations

IncorrectTypeHintException (groovy.transform.stc.IncorrectTypeHintException)2 ASTNode (org.codehaus.groovy.ast.ASTNode)2 ClassNode (org.codehaus.groovy.ast.ClassNode)2 MethodNode (org.codehaus.groovy.ast.MethodNode)2 ModuleNode (org.codehaus.groovy.ast.ModuleNode)2 ResolveVisitor (org.codehaus.groovy.control.ResolveVisitor)2