Class DefaultJavaClass

    • Constructor Detail

      • DefaultJavaClass

        protected DefaultJavaClass()
      • DefaultJavaClass

        public DefaultJavaClass​(String name)
      • DefaultJavaClass

        public DefaultJavaClass​(JavaSource source)
    • Method Detail

      • isInterface

        public boolean isInterface()
        (API description of Class.isInterface())

        Determines if the specified Class object represents an interface type.

        Specified by:
        isInterface in interface JavaClass
        Returns:
        true if this object represents an interface, otherwise false
      • isPrimitive

        public boolean isPrimitive()
        Equivalent of Class.isPrimitive()
        Specified by:
        isPrimitive in interface JavaClass
        Returns:
        true if this class represents a primitive, otherwise false
      • isVoid

        public boolean isVoid()
        Specified by:
        isVoid in interface JavaClass
        Returns:
        true if this JavaClass is a void, otherwise false
      • isEnum

        public boolean isEnum()
        (API description of Class.isEnum())

        Returns true if and only if this class was declared as an enum in the source code.

        Specified by:
        isEnum in interface JavaClass
        Returns:
        true if this object represents an enum, otherwise false
      • isAnnotation

        public boolean isAnnotation()
        (API description of Class.isAnnotation())

        Returns true if this Class object represents an annotation type. Note that if this method returns true, JavaClass.isInterface() would also return true, as all annotation types are also interfaces.

        Specified by:
        isAnnotation in interface JavaClass
        Returns:
        true if this object represents an annotation, otherwise false
      • isArray

        public boolean isArray()
        Specified by:
        isArray in interface JavaClass
        Returns:
        true if this JavaClass is an array, otherwise false
      • getDimensions

        public int getDimensions()
        Returns the depth of this array, 0 if it's not an array
        Specified by:
        getDimensions in interface JavaClass
        Returns:
        The depth of this array, at least 0
      • setInterface

        public void setInterface​(boolean anInterface)
      • setEnum

        public void setEnum​(boolean anEnum)
      • setAnnotation

        public void setAnnotation​(boolean anAnnotation)
      • addConstructor

        public void addConstructor​(JavaConstructor constructor)
      • addMethod

        public void addMethod​(JavaMethod meth)
      • setSuperClass

        public void setSuperClass​(JavaType type)
      • setImplementz

        public void setImplementz​(List<JavaClass> implementz)
      • addField

        public void addField​(JavaField javaField)
      • setJavaPackage

        public void setJavaPackage​(JavaPackage javaPackage)
        Only used when constructing the model by hand / without source
        Parameters:
        javaPackage - the package
      • getPackageName

        public String getPackageName()
        If this class has a package, the packagename will be returned. Otherwise an empty String.
        Specified by:
        getPackageName in interface JavaClass
        Returns:
        the name of the package, otherwise an empty String
      • getBinaryName

        public String getBinaryName()
        The class or interface must be named by its binary name, which must meet the following constraints:
        • The binary name of a top level type is its canonical name.
        • The binary name of a member type consists of the binary name of its immediately enclosing type, followed by $, followed by the simple name of the member.
        Specified by:
        getBinaryName in interface JavaType
        Returns:
        the binary name
        See Also:
        https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.1
      • getFullyQualifiedName

        public String getFullyQualifiedName()
        Every primitive type, named package, top level class, and top level interface has a fully qualified name:
        • The fully qualified name of a primitive type is the keyword for that primitive type, namely byte, short, char, int, long, float, double, or boolean.
        • The fully qualified name of a named package that is not a subpackage of a named package is its simple name.
        • The fully qualified name of a named package that is a subpackage of another named package consists of the fully qualified name of the containing package, followed by ".", followed by the simple (member) name of the subpackage.
        • The fully qualified name of a top level class or top level interface that is declared in an unnamed package is the simple name of the class or interface.
        • The fully qualified name of a top level class or top level interface that is declared in a named package consists of the fully qualified name of the package, followed by ".", followed by the simple name of the class or interface.
        Each member class, member interface, and array type may have a fully qualified name:
        • A member class or member interface M of another class or interface C has a fully qualified name if and only if C has a fully qualified name.
        • In that case, the fully qualified name of M consists of the fully qualified name of C, followed by ".", followed by the simple name of M.
        • An array type has a fully qualified name if and only if its element type has a fully qualified name.
        • In that case, the fully qualified name of an array type consists of the fully qualified name of the component type of the array type followed by "[]".
        Some examples how names will be translated
         Object > java.lang.Object
         java.util.List > java.util.List
         ?  > ?
         T  > T
         anypackage.Outer.Inner > anypackage.Outer.Inner
         String[][] > java.lang.String[][]
         
        Specified by:
        getFullyQualifiedName in interface JavaType
        Returns:
        the fully qualified name, never null
        See Also:
        JavaClass.getComponentType(), JavaType.getBinaryName(), https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.7
      • getGenericFullyQualifiedName

        public String getGenericFullyQualifiedName()
        The fully qualified name with generic information.
        Specified by:
        getGenericFullyQualifiedName in interface JavaType
        Returns:
        the generic fully qualified name
      • getGenericCanonicalName

        public String getGenericCanonicalName()
        The canonical name with generic information.
        Specified by:
        getGenericCanonicalName in interface JavaType
        Returns:
        the generic canonical name
      • getValue

        public String getValue()
        If there's a reference to this class, use the value used in the code. Otherwise return the simple name. When including all imports, you should be safe to use this method. This won't return generics, so it's java1.4 safe. Examples:
          private String fieldA;             // getValue() will return "String"
          private java.lang.String fieldA;   // getValue() will return "java.lang.String"
          private List>String> aList;  // getValue() will return "List"
         
        Specified by:
        getValue in interface JavaType
        Returns:
        the name of the class as used in the source
      • getGenericValue

        public String getGenericValue()
        A java5+ representation of the class. When including all imports, you should be safe to use this method. Examples:
          private String fieldA;             // getValue() will return "String"
          private java.lang.String fieldA;   // getValue() will return "java.lang.String"
          private List>String> aList;  // getValue() will return "List>String>"
         
        Specified by:
        getGenericValue in interface JavaType
        Returns:
        the generic name of the class as used in the source
      • isInner

        public boolean isInner()
        Specified by:
        isInner in interface JavaClass
        Returns:
        true if this class is an inner class, otherwise false
      • getConstructor

        public JavaConstructor getConstructor​(List<JavaType> parameterTypes)
        Specified by:
        getConstructor in interface JavaClass
        Parameters:
        parameterTypes - the parameter types of the constructor, can be null
        Returns:
        the matching constructor, otherwise null
      • getConstructor

        public JavaConstructor getConstructor​(List<JavaType> parameterTypes,
                                              boolean varArgs)
        Specified by:
        getConstructor in interface JavaClass
        Parameters:
        parameterTypes - the parameter types of the constructor, can be null
        varArgs - define is the constructor has varArgs
        Returns:
        the matching constructor, otherwise null
      • getMethods

        public List<JavaMethod> getMethods​(boolean superclasses)
        Return declared methods and optionally the inherited methods
        Specified by:
        getMethods in interface JavaClass
        Parameters:
        superclasses - true if inherited methods should be returned as well
        Returns:
        all methods
      • getMethodBySignature

        public JavaMethod getMethodBySignature​(String name,
                                               List<JavaType> parameterTypes)
        Specified by:
        getMethodBySignature in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null.
        Returns:
        the matching method, otherwise null
      • getMethod

        public JavaMethod getMethod​(String name,
                                    List<JavaType> parameterTypes,
                                    boolean varArgs)
        This should be the signature for getMethodBySignature.
        Specified by:
        getMethod in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null
        varArgs - define if the method has varArgs
        Returns:
        the matching method, otherwise null
      • getMethodBySignature

        public JavaMethod getMethodBySignature​(String name,
                                               List<JavaType> parameterTypes,
                                               boolean superclasses)
        Specified by:
        getMethodBySignature in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null
        superclasses - to define if superclasses should be included as well
        Returns:
        the matching method, otherwise null
      • getMethodBySignature

        public JavaMethod getMethodBySignature​(String name,
                                               List<JavaType> parameterTypes,
                                               boolean superclasses,
                                               boolean varArg)
        Specified by:
        getMethodBySignature in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null
        superclasses - true if inherited methods should be matched as well
        varArg - define if the method has varArgs
        Returns:
        the matching method, otherwise null
      • getMethodsBySignature

        public List<JavaMethod> getMethodsBySignature​(String name,
                                                      List<JavaType> parameterTypes,
                                                      boolean superclasses)
        Specified by:
        getMethodsBySignature in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null
        superclasses - true if inherited methods should be matched as well
        Returns:
        the matching methods, otherwise null
      • getMethodsBySignature

        public List<JavaMethod> getMethodsBySignature​(String name,
                                                      List<JavaType> parameterTypes,
                                                      boolean superclasses,
                                                      boolean varArg)
        Specified by:
        getMethodsBySignature in interface JavaClass
        Parameters:
        name - the name of the method
        parameterTypes - the parameter types of the method, can be null
        superclasses - true if inherited methods should be matched as well
        varArg - define if the method has varArgs
        Returns:
        the matching methods, otherwise null
      • getEnumConstantByName

        public JavaField getEnumConstantByName​(String name)
        Specified by:
        getEnumConstantByName in interface JavaClass
        Parameters:
        name - the name of the enum constant
        Returns:
        the enumConstant matching the name, otherwise null
      • addInitializer

        public void addInitializer​(JavaInitializer initializer)
      • addClass

        public void addClass​(JavaClass cls)
      • isA

        public boolean isA​(String fullClassName)
        Specified by:
        isA in interface JavaClass
        Parameters:
        fullClassName - the FQN to match with
        Returns:
        true if this is of type FQN, otherwise false
      • isA

        public boolean isA​(JavaClass javaClass)
        Specified by:
        isA in interface JavaClass
        Parameters:
        javaClass - the JavaClass to match with
        Returns:
        true if this is of type javaClass, otherwise false
      • getBeanProperties

        public List<BeanProperty> getBeanProperties()
        Gets bean properties without looking in superclasses or interfaces.
        Specified by:
        getBeanProperties in interface JavaClass
        Returns:
        the bean properties
      • getBeanProperties

        public List<BeanProperty> getBeanProperties​(boolean superclasses)
        Specified by:
        getBeanProperties in interface JavaClass
        Parameters:
        superclasses - to define if superclasses should be included as well
        Returns:
        the bean properties
      • getBeanProperty

        public BeanProperty getBeanProperty​(String propertyName)
        Gets bean property without looking in superclasses or interfaces.
        Specified by:
        getBeanProperty in interface JavaClass
        Parameters:
        propertyName - the name of the property
        Returns:
        the bean property
      • getBeanProperty

        public BeanProperty getBeanProperty​(String propertyName,
                                            boolean superclasses)
        Specified by:
        getBeanProperty in interface JavaClass
        Parameters:
        propertyName - the name of the property
        superclasses - to define if superclasses should be included as well
        Returns:
        the bean property
      • toString

        public String toString()
        Description copied from interface: JavaClass
        (API description of Class.toString()) Converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName. If this Class object represents a primitive type, this method returns the name of the primitive type. If this Class object represents void this method returns "void".
        Specified by:
        toString in interface JavaClass
        Overrides:
        toString in class Object
        Returns:
        a string representation of this class object.
        See Also:
        Class.toString()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object