Package org.codehaus.groovy.antlr

Examples of org.codehaus.groovy.antlr.GroovySourceAST


   *
   * todo - build API of basic tree mutations like this method.
   */
    public void swapTwoChildren(GroovySourceAST t) {
    // this swaps the two child nodes, see javadoc above for explanation of implementation
    GroovySourceAST a = (GroovySourceAST) t.getFirstChild();
    GroovySourceAST b = (GroovySourceAST) a.getNextSibling();

    t.setFirstChild(b);
    a.setNextSibling(null);
    b.setNextSibling(a);
    }
View Full Code Here


        currentClassDoc.setAsInterfaceDefinition();
    }

    public void visitImport(GroovySourceAST t, int visit) {
        if (visit == OPENING_VISIT) {
            GroovySourceAST child = t.childOfType(GroovyTokenTypes.DOT);
            if (child == null) {
                child = t.childOfType(GroovyTokenTypes.IDENT);
            }
            String importTextWithSlashesInsteadOfDots = recurseDownImportBranch(child);
            importedClassesAndPackages.add(importTextWithSlashesInsteadOfDots);
View Full Code Here

        }
    }
    public String recurseDownImportBranch(GroovySourceAST t) {
        if (t != null) {
            if (t.getType() == GroovyTokenTypes.DOT) {
                GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild();
                GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling();
                return (recurseDownImportBranch(firstChild) + "/" + recurseDownImportBranch(secondChild));
            }
            if (t.getType() == GroovyTokenTypes.IDENT) {
                return t.getText();
            }
View Full Code Here

        }
        return "";
    }
    public void visitExtendsClause(GroovySourceAST t,int visit) {
        if (visit == OPENING_VISIT) {
          GroovySourceAST superClassNode = t.childOfType(GroovyTokenTypes.IDENT);
          if (superClassNode != null) {
            String superClassName = superClassNode.getText();
            currentClassDoc.setSuperClassName(superClassName); // un 'packaged' class name
          }
        }
    }
View Full Code Here

  }

    public void visitVariableDef(GroovySourceAST t, int visit) {
        if (visit == OPENING_VISIT) {
            if (!insideAnonymousInnerClass()) {
                GroovySourceAST parentNode = getParentNode();

                // todo - what about fields in interfaces/enums etc
                if (parentNode != null && parentNode.getType() == GroovyTokenTypes.OBJBLOCK) {  // this should restrict us to just field definitions, and not local variable definitions

                    // field name
                    String fieldName = t.childOfType(GroovyTokenTypes.IDENT).getText();
                    SimpleGroovyFieldDoc currentFieldDoc = new SimpleGroovyFieldDoc(fieldName);
View Full Code Here

        }
    }


    private boolean insideAnonymousInnerClass() {
        GroovySourceAST grandParentNode = getGrandParentNode();
        if (grandParentNode != null && grandParentNode.getType() == GroovyTokenTypes.LITERAL_new) {
            return true;
        }
        return false;
    }
View Full Code Here

            return true;
        }
        return false;
    }
    private void processModifiers(GroovySourceAST t,SimpleGroovyProgramElementDoc programElementDoc) {
        GroovySourceAST modifiers = t.childOfType(GroovyTokenTypes.MODIFIERS);
        if (modifiers != null) {
            AST currentModifier = modifiers.getFirstChild();
            boolean seenNonPublicVisibilityModifier = false;
            while (currentModifier != null) {
                int type = currentModifier.getType();
                switch (type) {
                    case GroovyTokenTypes.LITERAL_protected:
View Full Code Here

  private String getTypeNodeAsText(GroovySourceAST typeNode, String defaultText) {
    String returnValue = defaultText;
    if (typeNode != null &&
        typeNode.getType() == GroovyTokenTypes.TYPE &&
        typeNode.getNumberOfChildren() > 0) {
      GroovySourceAST child = (GroovySourceAST) typeNode.getFirstChild(); // assume type has only one child // todo type of "foo.bar.Wibble"
      switch (child.getType()) {
        // literals
        case GroovyTokenTypes.LITERAL_boolean: returnValue = "boolean"; break
        case GroovyTokenTypes.LITERAL_byte: returnValue = "byte"; break
        case GroovyTokenTypes.LITERAL_char: returnValue = "char"; break
        // note: LITERAL_def never created
        case GroovyTokenTypes.LITERAL_double: returnValue = "double"; break
        case GroovyTokenTypes.LITERAL_float: returnValue = "float"; break
        case GroovyTokenTypes.LITERAL_int: returnValue = "int"; break
        case GroovyTokenTypes.LITERAL_long: returnValue = "long"; break
        case GroovyTokenTypes.LITERAL_short: returnValue = "short"; break
        case GroovyTokenTypes.LITERAL_void: returnValue = "void"; break
       
        // identifiers
        case GroovyTokenTypes.IDENT: returnValue = child.getText(); break
      }
    }
    return returnValue;
  }
View Full Code Here

  }

 
  private void addParametersTo(SimpleGroovyExecutableMemberDoc executableMemberDoc, GroovySourceAST t,int visit) {
    // parameters
    GroovySourceAST parametersNode = t.childOfType(GroovyTokenTypes.PARAMETERS);
    if (parametersNode != null && parametersNode.getNumberOfChildren() > 0) {
      GroovySourceAST currentNode = (GroovySourceAST) parametersNode.getFirstChild();
        while (currentNode != null) {
          String parameterTypeName = getTypeNodeAsText(currentNode.childOfType(GroovyTokenTypes.TYPE),"def");
            String parameterName = getText(currentNode.childOfType(GroovyTokenTypes.IDENT));
            SimpleGroovyParameter parameter = new SimpleGroovyParameter(parameterName);
            parameter.setTypeName(parameterTypeName);
           
            executableMemberDoc.add(parameter);
           
            currentNode = (GroovySourceAST)currentNode.getNextSibling();
        }
    }
  }
View Full Code Here

    public void push(GroovySourceAST t) {
        Iterator itr = visitors.iterator();
        while (itr.hasNext()) {((Visitor)itr.next()).push(t);}
    }
    public GroovySourceAST pop() {
        GroovySourceAST lastNodePopped = null;
        Iterator itr = backToFrontVisitors.iterator();
        while (itr.hasNext()) {lastNodePopped = (GroovySourceAST) ((Visitor)itr.next()).pop();}
        return lastNodePopped;
    }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.antlr.GroovySourceAST

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.