Save This Page
Home » groovy-src-1.6.3 » org.codehaus » groovy » ast » [javadoc | source]
org.codehaus.groovy.ast
public class: ClassNode [javadoc | source]
java.lang.Object
   org.codehaus.groovy.ast.ASTNode
      org.codehaus.groovy.ast.AnnotatedNode
         org.codehaus.groovy.ast.ClassNode

All Implemented Interfaces:
    org.objectweb.asm.Opcodes

Direct Known Subclasses:
    LowerCaseClass, MixinNode, InnerClassNode, ConstructedClassWithPackage

Represents a class in the AST.
A ClassNode should be created using the methods in ClassHelper. This ClassNode may be used to represent a class declaration or any other type. This class uses a proxy mechanism allowing to create a class for a plain name at AST creation time. In another phase of the compiler the real ClassNode for the plain name may be found. To avoid the need of exchanging this ClassNode with an instance of the correct ClassNode the correct ClassNode is set as redirect. Most method calls are then redirected to that ClassNode.
There are three types of ClassNodes:
  1. Primary ClassNodes:
    A primary ClassNode is one where we have a source representation which is to be compiled by Groovy and which we have an AST for. The groovy compiler will output one class for each such ClassNode that passes through AsmBytecodeGenerator... not more, not less. That means for example Closures become such ClassNodes too at some point.
  2. ClassNodes create through different sources (typically created from a java.lang.reflect.Class object):
    The compiler will not output classes from these, the methods usually do not contain bodies. These kind of ClassNodes will be used in different checks, but not checks that work on the method bodies. For example if such a ClassNode is a super class to a primary ClassNode, then the abstract method test and others will be done with data based on these. Theoretically it is also possible to mix both (1 and 2) kind of classes in a hierarchy, but this probably works only in the newest Groovy versions. Such ClassNodes normally have to isResolved() returning true without having a redirect.In the Groovy compiler the only version of this, that exists, is a ClassNode created through a Class instance
  3. Labels:
    ClassNodes created through ClassHelper.makeWithoutCaching. They are place holders, its redirect points to the real structure, which can be a label too, but following all redirects it should end with a ClassNode from one of the other two categories. If ResolveVisitor finds such a node, it tries to set the redirects. Any such label created after ResolveVisitor has done its work needs to have a redirect pointing to case 1 or 2. If not the compiler may react strange... this can be considered as a kind of dangling pointer.
    Note: the redirect mechanism is only allowed for classes that are not primary ClassNodes. Typically this is done for classes created by name only. The redirect itself can be any type of ClassNode.
    To describe generic type signature see #getGenericsTypes() and #setGenericsTypes(GenericsType[]) . These methods are not proxied, they describe the type signature used at the point of declaration or the type signatures provided by the class. If the type signatures provided by the class are needed, then a call to #redirect() will help.
    Field Summary
    public static  ClassNode[] EMPTY_ARRAY     
    public static  ClassNode THIS     
    public static  ClassNode SUPER     
    protected  boolean isPrimaryNode     
    protected  Object lazyInitLock     
    protected  Class clazz     
    Fields inherited from org.codehaus.groovy.ast.AnnotatedNode:
    declaringClass
    Constructor:
     public ClassNode(Class c) 
      Creates a ClassNode from a real class. The resulting ClassNode will not be a primary ClassNode.
     public ClassNode(String name,
        int modifiers,
        ClassNode superClass) 
      Parameters:
      name - is the full name of the class
      modifiers - the modifiers,
      superClass - the base class name - use "java.lang.Object" if no direct base class
      Also see:
      org.objectweb.asm.Opcodes
     public ClassNode(String name,
        int modifiers,
        ClassNode superClass,
        ClassNode[] interfaces,
        MixinNode[] mixins) 
      Parameters:
      name - is the full name of the class
      modifiers - the modifiers,
      superClass - the base class name - use "java.lang.Object" if no direct base class
      Also see:
      org.objectweb.asm.Opcodes
    Method from org.codehaus.groovy.ast.ClassNode Summary:
    addConstructor,   addConstructor,   addField,   addField,   addInterface,   addMethod,   addMethod,   addMixin,   addObjectInitializerStatements,   addProperty,   addProperty,   addStaticInitializerStatements,   addSyntheticMethod,   addTransform,   declaresInterface,   equals,   getAbstractMethods,   getAllDeclaredMethods,   getAllInterfaces,   getAnnotations,   getAnnotations,   getCompileUnit,   getComponentType,   getDeclaredConstructors,   getDeclaredField,   getDeclaredMethod,   getDeclaredMethods,   getDeclaredMethodsMap,   getEnclosingMethod,   getField,   getFields,   getGenericsTypes,   getGetterMethod,   getInterfaces,   getMethod,   getMethods,   getMethods,   getMixins,   getModifiers,   getModule,   getName,   getNameWithoutPackage,   getObjectInitializerStatements,   getOuterClass,   getOuterField,   getPackageName,   getPlainNodeReference,   getProperties,   getProperty,   getSetterMethod,   getSuperClass,   getTransforms,   getTypeClass,   getUnresolvedSuperClass,   getUnresolvedSuperClass,   hasDeclaredMethod,   hasMethod,   hasPackageName,   hasPossibleMethod,   hasPossibleStaticMethod,   hasProperty,   hashCode,   implementsInterface,   isAnnotated,   isAnnotationDefinition,   isArray,   isDerivedFrom,   isDerivedFromGroovyObject,   isGenericsPlaceHolder,   isInterface,   isPrimaryClassNode,   isResolved,   isScript,   isScriptBody,   isStaticClass,   isUsingGenerics,   makeArray,   parametersEqual,   redirect,   renameField,   setAnnotated,   setCompileUnit,   setEnclosingMethod,   setGenericsPlaceHolder,   setGenericsTypes,   setInterfaces,   setModule,   setName,   setRedirect,   setScript,   setScriptBody,   setStaticClass,   setSuperClass,   setUnresolvedSuperClass,   setUsingGenerics,   toString,   tryFindPossibleMethod,   visitContents
    Methods from org.codehaus.groovy.ast.AnnotatedNode:
    addAnnotation,   addAnnotations,   getAnnotations,   getAnnotations,   getDeclaringClass,   isSynthetic,   setDeclaringClass,   setSynthetic
    Methods from org.codehaus.groovy.ast.ASTNode:
    getColumnNumber,   getLastColumnNumber,   getLastLineNumber,   getLineNumber,   getText,   setColumnNumber,   setLastColumnNumber,   setLastLineNumber,   setLineNumber,   setSourcePosition,   visit
    Methods from java.lang.Object:
    equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
    Method from org.codehaus.groovy.ast.ClassNode Detail:
     public  void addConstructor(ConstructorNode node) 
     public ConstructorNode addConstructor(int modifiers,
        Parameter[] parameters,
        ClassNode[] exceptions,
        Statement code) 
     public  void addField(FieldNode node) 
     public FieldNode addField(String name,
        int modifiers,
        ClassNode type,
        Expression initialValue) 
     public  void addInterface(ClassNode type) 
     public  void addMethod(MethodNode node) 
     public MethodNode addMethod(String name,
        int modifiers,
        ClassNode returnType,
        Parameter[] parameters,
        ClassNode[] exceptions,
        Statement code) 
      If a method with the given name and parameters is already defined then it is returned otherwise the given method is added to this node. This method is useful for default method adding like getProperty() or invokeMethod() where there may already be a method defined in a class and so the default implementations should not be added if already present.
     public  void addMixin(MixinNode mixin) 
     public  void addObjectInitializerStatements(Statement statements) 
     public  void addProperty(PropertyNode node) 
     public PropertyNode addProperty(String name,
        int modifiers,
        ClassNode type,
        Expression initialValueExpression,
        Statement getterBlock,
        Statement setterBlock) 
     public  void addStaticInitializerStatements(List staticStatements,
        boolean fieldInit) 
     public MethodNode addSyntheticMethod(String name,
        int modifiers,
        ClassNode returnType,
        Parameter[] parameters,
        ClassNode[] exceptions,
        Statement code) 
      Adds a synthetic method as part of the compilation process
     public  void addTransform(Class transform,
        ASTNode node) 
     public boolean declaresInterface(ClassNode classNode) 
     public boolean equals(Object o) 
     public List getAbstractMethods() 
      Returns a list containing MethodNode objects for each abstract method in the class represented by this ClassNode
     public List getAllDeclaredMethods() 
     public Set getAllInterfaces() 
     public List getAnnotations() 
     public List getAnnotations(ClassNode type) 
     public CompileUnit getCompileUnit() 
     public ClassNode getComponentType() 
     public List getDeclaredConstructors() 
     public FieldNode getDeclaredField(String name) 
      Finds a field matching the given name in this class.
     public MethodNode getDeclaredMethod(String name,
        Parameter[] parameters) 
      Finds a method matching the given name and parameters in this class.
     public List getDeclaredMethods(String name) 
      This methods returns a list of all methods of the given name defined in the current class
     public Map getDeclaredMethodsMap() 
     public MethodNode getEnclosingMethod() 
     public FieldNode getField(String name) 
      Finds a field matching the given name in this class or a parent class.
     public List getFields() 
      Returns a list containing FieldNode objects for each field in the class represented by this ClassNode
     public GenericsType[] getGenericsTypes() 
     public MethodNode getGetterMethod(String getterName) 
     public ClassNode[] getInterfaces() 
      Returns an array of ClassNodes representing the interfaces the class implements
     public MethodNode getMethod(String name,
        Parameter[] parameters) 
      Finds a method matching the given name and parameters in this class or any parent class.
     public List getMethods() 
      Returns a list containing MethodNode objects for each method in the class represented by this ClassNode
     public List getMethods(String name) 
      This methods creates a list of all methods with this name of the current class and of all super classes
     public MixinNode[] getMixins() 
     public int getModifiers() 
     public ModuleNode getModule() 
     public String getName() 
     public String getNameWithoutPackage() 
     public List getObjectInitializerStatements() 
     public ClassNode getOuterClass() 
      Helper method to avoid casting to inner class
     public FieldNode getOuterField(String name) 
     public String getPackageName() 
     public ClassNode getPlainNodeReference() 
     public List getProperties() 
     public PropertyNode getProperty(String name) 
     public MethodNode getSetterMethod(String setterName) 
     public ClassNode getSuperClass() 
     public Map getTransforms(CompilePhase phase) 
     public Class getTypeClass() 
     public ClassNode getUnresolvedSuperClass() 
     public ClassNode getUnresolvedSuperClass(boolean useRedirect) 
     public boolean hasDeclaredMethod(String name,
        Parameter[] parameters) 
     public boolean hasMethod(String name,
        Parameter[] parameters) 
     public boolean hasPackageName() 
     public boolean hasPossibleMethod(String name,
        Expression arguments) 
      Returns true if the given method has a possibly matching instance method with the given name and arguments.
     public boolean hasPossibleStaticMethod(String name,
        Expression arguments) 
      Returns true if the given method has a possibly matching static method with the given name and arguments.
     public boolean hasProperty(String name) 
     public int hashCode() 
     public boolean implementsInterface(ClassNode classNode) 
     public boolean isAnnotated() 
     public boolean isAnnotationDefinition() 
     public boolean isArray() 
     public boolean isDerivedFrom(ClassNode type) 
     public boolean isDerivedFromGroovyObject() 
     public boolean isGenericsPlaceHolder() 
     public boolean isInterface() 
     public boolean isPrimaryClassNode() 
      Returns if this instance is a primary ClassNode
     public boolean isResolved() 
     public boolean isScript() 
     public boolean isScriptBody() 
     public boolean isStaticClass() 
      Is this class delcared in a static method (such as a closure / inner class declared in a static method)
     public boolean isUsingGenerics() 
     public ClassNode makeArray() 
      Returns a ClassNode representing an array of the class represented by this ClassNode
     protected boolean parametersEqual(Parameter[] a,
        Parameter[] b) 
     public ClassNode redirect() 
      Returns the ClassNode this ClassNode is redirecting to.
     public  void renameField(String oldName,
        String newName) 
     public  void setAnnotated(boolean flag) 
      Marks if the current class uses annotations or not
     protected  void setCompileUnit(CompileUnit cu) 
     public  void setEnclosingMethod(MethodNode enclosingMethod) 
     public  void setGenericsPlaceHolder(boolean b) 
     public  void setGenericsTypes(GenericsType[] genericsTypes) 
     public  void setInterfaces(ClassNode[] interfaces) 
     public  void setModule(ModuleNode module) 
     public String setName(String name) 
     public  void setRedirect(ClassNode cn) 
      Sets this instance as proxy for the given ClassNode.
     public  void setScript(boolean script) 
     public  void setScriptBody(boolean scriptBody) 
     public  void setStaticClass(boolean staticClass) 
     public  void setSuperClass(ClassNode superClass) 
      Sets the superclass of this ClassNode
     public  void setUnresolvedSuperClass(ClassNode sn) 
     public  void setUsingGenerics(boolean b) 
     public String toString() 
     public MethodNode tryFindPossibleMethod(String name,
        Expression arguments) 
     public  void visitContents(GroovyClassVisitor visitor)