Package org.codehaus.groovy.ast

Examples of org.codehaus.groovy.ast.ASTNode


        ModuleNode module = unit.getAST( );

        ClassNode classNode = ( ClassNode ) module.getClasses( ).get( 0 );
        List methods = classNode.getDeclaredMethods( "run" );
        MethodNode method = ( MethodNode ) methods.get( 0 );
        ASTNode expr = method.getCode( );

        GroovyExprVisitor visitor = new GroovyExprVisitor( );
        expr.visit( visitor );
        Set refs = visitor.getVariables( );

        List decls = new LinkedList( );
        for ( Iterator declIter = availDecls.iterator( ); declIter.hasNext( ); )
        {
View Full Code Here


        Parameter[] params = new Parameter[2 + localVariableParams.length];
        params[0] = new Parameter(ClassHelper.OBJECT_TYPE, "_outerInstance");
        params[1] = new Parameter(ClassHelper.OBJECT_TYPE, "_thisObject");
        System.arraycopy(localVariableParams, 0, params, 2, localVariableParams.length);

        ASTNode sn = answer.addConstructor(ACC_PUBLIC, params, ClassNode.EMPTY_ARRAY, block);
        sn.setSourcePosition(expression);
       
        correctAccessedVariable(answer,expression);
       
        return answer;
    }
View Full Code Here

        assertInvalidName("a.");
        assertInvalidName("$");
    }

    protected void assertValidName(String name) {
        VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
    }
View Full Code Here

        VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
    }

    protected void assertInvalidName(String name) {
        try {
            VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
            fail("Should have thrown exception due to invalid name: " + name);
        }
        catch (RuntimeParserException e) {
            System.out.println("Caught invalid exception: " + e);
        }
View Full Code Here

        assertInvalidName("a.");
        assertInvalidName("$");
    }

    protected void assertValidName(String name) {
        VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
    }
View Full Code Here

        VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
    }

    protected void assertInvalidName(String name) {
        try {
            VerifierCodeVisitor.assertValidIdentifier(name, "variable name", new ASTNode());
            fail("Should have thrown exception due to invalid name: " + name);
        }
        catch (RuntimeParserException e) {
            System.out.println("Caught invalid exception: " + e);
        }
View Full Code Here

        return Pair.of(start, end);
    }

    @Override
    protected int getStartOffset(@NonNull Context context, @NonNull Object cookie) {
        ASTNode node = (ASTNode) cookie;
        Pair<Integer, Integer> offsets = getOffsets(node, context);
        return offsets.getFirst();
    }
View Full Code Here

        return offsets.getFirst();
    }

    @Override
    protected Location createLocation(@NonNull Context context, @NonNull Object cookie) {
        ASTNode node = (ASTNode) cookie;
        Pair<Integer, Integer> offsets = getOffsets(node, context);
        int fromLine = node.getLineNumber() - 1;
        int fromColumn = node.getColumnNumber() - 1;
        int toLine = node.getLastLineNumber() - 1;
        int toColumn = node.getLastColumnNumber() - 1;
        return Location.create(context.file,
                new DefaultPosition(fromLine, fromColumn, offsets.getFirst()),
                new DefaultPosition(toLine, toColumn, offsets.getSecond()));
    }
View Full Code Here

    }

    private void handleScriptRuntimeException(final GroovyRuntimeException e) {
        outStream.print("message: " + e.getMessage());
        final ModuleNode module = e.getModule();
        final ASTNode astNode = e.getNode();
        int lineNumber = -1;
        if (module != null) {
            lineNumber = module.getLineNumber();
        }
        else if (astNode != null) {
            lineNumber = astNode.getLineNumber();
        }
        else {
            lineNumber = findLineNumberInString(e.getMessage(), lineNumber);
        }
        outStream.print("Line number: " + lineNumber);
View Full Code Here

       new ClassNode(grails.plugin.cache.Cacheable.class)new ClassNode(org.springframework.cache.annotation.Cacheable.class),
       new ClassNode(grails.plugin.cache.CachePut.class),   new ClassNode(org.springframework.cache.annotation.CachePut.class),
       new ClassNode(grails.plugin.cache.CacheEvict.class), new ClassNode(org.springframework.cache.annotation.CacheEvict.class));

  public void visit(final ASTNode[] astNodes, final SourceUnit sourceUnit) {
    final ASTNode firstNode = astNodes[0];
    final ASTNode secondNode = astNodes[1];
    if (!(firstNode instanceof AnnotationNode) || !(secondNode instanceof AnnotatedNode)) {
      throw new RuntimeException("Internal error: wrong types: " + firstNode.getClass().getName() +
          " / " + secondNode.getClass().getName());
    }

    final AnnotationNode grailsCacheAnnotationNode = (AnnotationNode) firstNode;
    final AnnotatedNode annotatedNode = (AnnotatedNode) secondNode;
    final AnnotationNode springCacheAnnotationNode = getCorrespondingSpringAnnotation(
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.ast.ASTNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.