Class JavaClass

java.lang.Object
org.jtool.srcmodel.JavaElement
org.jtool.srcmodel.JavaClass

public class JavaClass extends JavaElement
An object representing a class, an interface, an enum, or an anonymous class for a lambda expression.
  • Field Details

    • ArrayClassFqn

      public static final QualifiedName ArrayClassFqn
      The constant value that represents the array class.
  • Constructor Details

    • JavaClass

      protected JavaClass()
      Create a new empty object for storing nothing.
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.TypeDeclaration node, JavaFile jfile) throws JavaElementException
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this class or interface
      jfile - the file that declares this class
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.AnonymousClassDeclaration node, JavaFile jfile) throws JavaElementException
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this anonymous class
      jfile - the file that declares this class
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.EnumDeclaration node, JavaFile jfile) throws JavaElementException
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this class holding the enum constant declarations
      jfile - the file that declares this class
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration node, JavaFile jfile) throws JavaElementException
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this annotation type
      jfile - the file that declares this class
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ITypeBinding tbinding, JavaFile jfile) throws JavaElementException
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - an AST node for this class
      tbinding - type binding information on this class
      jfile - a file that declares this class
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaClass

      public JavaClass(org.eclipse.jdt.core.dom.LambdaExpression node, org.eclipse.jdt.core.dom.ITypeBinding tbinding, String name, JavaMethod jmethod)
      Creates a new object representing a class. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this anonymous class for a lambda expression
      tbinding - type binding information on this class
      name - the name of this class
      jmethod - a method that encloses this class
  • Method Details

    • getJavaProject

      public JavaProject getJavaProject()
      Returns the project which this class exists in.
      Specified by:
      getJavaProject in class JavaElement
      Returns:
      the project
    • getFile

      public JavaFile getFile()
      Returns the file that declares this class.
      Specified by:
      getFile in class JavaElement
      Returns:
      the declaring file
    • getQualifiedName

      public QualifiedName getQualifiedName()
      Returns the fully-qualified name of this class.
      Specified by:
      getQualifiedName in class JavaElement
      Returns:
      the fully-qualified class name
    • getName

      public String getName()
      Returns the name of this class.
      Returns:
      the class name
    • getClassName

      public String getClassName()
      Returns the fully-qualified name of this class.
      Returns:
      the fully-qualified class name
    • getModifiers

      public int getModifiers()
      The the value that stores information on the modifiers of this class.
      Returns:
      the modifier value of this class
    • getTypeBinding

      public org.eclipse.jdt.core.dom.ITypeBinding getTypeBinding()
      Returns the type binding information on this class.
      Returns:
      the type binding information
    • isInProject

      public boolean isInProject()
      Tests if this class exists inside the target project, which can resent the corresponding source code.
      Returns:
      true if this class exists inside the target project, otherwise false
    • getDeclaringClass

      public JavaClass getDeclaringClass()
      Returns the class that declares this class.
      Returns:
      the declaring class, or null if this class is not enclosed by any class
    • getDeclaringMethod

      public JavaMethod getDeclaringMethod()
      Returns the method that declares this class.
      Returns:
      the declaring method, or null if this class is not enclosed by any method
    • getPackage

      public JavaPackage getPackage()
      Returns the package that this class belongs to.
      Returns:
      the package of this class, or null if this class does not have its source code
    • isClass

      public boolean isClass()
      Tests if this is a class.
      Returns:
      true if this is a class, otherwise false
    • isInterface

      public boolean isInterface()
      Tests if this is an interface.
      Returns:
      true if this is an interface, otherwise false
    • isEnum

      public boolean isEnum()
      Tests if this is a class holding the enum constant declarations.
      Returns:
      true if this is an enum, otherwise false
    • isAnonymous

      public boolean isAnonymous()
      Tests if this is an anonymous class.
      Returns:
      true if this is an anonymous class, otherwise false
    • isLambda

      public boolean isLambda()
      Tests if this is an anonymous class for the lambda expression.
      Returns:
      true if this is an anonymous class for the lambda expression, otherwise false
    • isPublic

      public boolean isPublic()
      Tests if this class has the public visibility.
      Returns:
      true if this class has the public visibility, otherwise false
    • isProtected

      public boolean isProtected()
      Tests if this class has the protected visibility.
      Returns:
      true if this class has the protected visibility, otherwise false
    • isPrivate

      public boolean isPrivate()
      Tests if this class has the private visibility.
      Returns:
      true if this class has the private visibility, otherwise false
    • isDefault

      public boolean isDefault()
      Tests if this class has the default visibility.
      Returns:
      true if this class has the default visibility, otherwise false
    • isFinal

      public boolean isFinal()
      Tests if this is a final class.
      Returns:
      true if this is a final class, otherwise false
    • isAbstract

      public boolean isAbstract()
      Tests if this is an abstract class.
      Returns:
      true if this is an abstract class, otherwise false
    • isStatic

      public boolean isStatic()
      Tests if this is a static class.
      Returns:
      true if this is a static class, otherwise false
    • isStrictfp

      public boolean isStrictfp()
      Tests if this is a strict-floating-point class.
      Returns:
      true if this is a strict-floating-point class, otherwise false
    • getSuperClassName

      public String getSuperClassName()
      Returns the name of the super class of this class.
      Returns:
      the super class name, or null if this is an interface
    • getSuperInterfaceNames

      public Set<String> getSuperInterfaceNames()
      Return the collection of the super interfaces of this class.
      Returns:
      the super interfaces names
    • getField

      public JavaField getField(String name)
      Obtains a field enclosed in this class, having a given name.
      Parameters:
      name - the name of the field to be retrieved
      Returns:
      the found field, or null if a corresponding field is not found
    • getFields

      public List<JavaField> getFields()
      Obtains fields enclosed in this class.
      Returns:
      the collection of the fields
    • getSortedFields

      public List<JavaField> getSortedFields()
      Obtains fields enclosed in this class, which are sorted in the dictionary order.
      Returns:
      the sorted list of the fields
    • addMethod

      public void addMethod(JavaMethod jmethod)
      Adds a method enclosed in this class. This method is not intended to be invoked by clients.
      Parameters:
      jmethod - the method to be added
    • getMethod

      public JavaMethod getMethod(String sig)
      Obtains a method enclosed in this class, having a given name.
      Parameters:
      sig - the signature of the method to be retrieved
      Returns:
      the found method, or null if a corresponding method is not found
    • getInitializer

      public JavaMethod getInitializer()
      Obtains a static initializer enclosed in this class.
      Returns:
      the static initializer, or null if this class does not have any static initializer
    • getMethods

      public List<JavaMethod> getMethods()
      Obtains methods enclosed in this class.
      Returns:
      the collection of the methods
    • getSortedMethods

      public List<JavaMethod> getSortedMethods()
      Obtains methods enclosed in this class, which are sorted in the dictionary order.
      Returns:
      the sorted list of the methods
    • addInnerClass

      public void addInnerClass(JavaClass jclass)
      Adds an inner class enclosed in this class. This method is not intended to be invoked by clients.
      Parameters:
      jclass - the method to be added
    • getInnerClasses

      public List<JavaClass> getInnerClasses()
      Obtains classes enclosed in this class.
      Returns:
      the collection of the inner classes
    • getSortedInnerClasses

      public List<JavaClass> getSortedInnerClasses()
      Obtains classes enclosed in this class, which are sorted in the dictionary order.
      Returns:
      the sorted list of the classes
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(JavaClass jclass)
      Tests if a given class is equal to this class.
      Parameters:
      jclass - the class to be checked
      Returns:
      the true if the given class is equal to this class
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Obtains information on this class.
      Overrides:
      toString in class Object
      Returns:
      the string representing the information
    • sortFields

      public static List<JavaField> sortFields(List<? extends JavaField> list)
      Sorts the list of fields.
      Parameters:
      list - the field list
      Returns:
      the sorted field list
    • sortMethods

      public static List<JavaMethod> sortMethods(List<? extends JavaMethod> list)
      Sorts the list of methods.
      Parameters:
      list - the method list
      Returns:
      the sorted method list
    • sortClasses

      public static List<JavaClass> sortClasses(List<? extends JavaClass> list)
      Sorts the list of classes.
      Parameters:
      list - the class list
      Returns:
      the sorted class list
    • addUsedClass

      public void addUsedClass(JavaClass jclass)
      Adds a class used by this class. This method is not intended to be invoked by clients.
      Parameters:
      jclass - the class to be added
    • getSuperClass

      public JavaClass getSuperClass()
      Returns the super class of this class.
      Returns:
      the super class
    • getSuperInterfaces

      public Set<JavaClass> getSuperInterfaces()
      Obtains super interfaces of this class.
      Returns:
      the collection of the super interfaces
    • getUsedClasses

      public Set<JavaClass> getUsedClasses()
      Obtains classes used by this class.
      Returns:
      the collection of the used classes, an empty set when this class does not have its corresponding file
    • getEfferentClasses

      public Set<JavaClass> getEfferentClasses()
      Obtains classes required by this class.
      Returns:
      the collection of the required classes
    • getChildren

      public Set<JavaClass> getChildren()
      Obtains child classes of this class.
      Returns:
      the list of the child classes
    • isChildOf

      public boolean isChildOf(JavaClass jclass)
      Tests if this class is a child of a given parent class.
      Parameters:
      jclass - the possible parent class
      Returns:
      true if this class is a child of the given class, otherwise false
    • getAllSuperClasses

      public List<JavaClass> getAllSuperClasses()
      Obtains super classes in the distance order. The closest ancestor (i.e. parent) is located at the first position.
      Returns:
      the ordered list of the super classes
    • getAllSuperInterfaces

      public Set<JavaClass> getAllSuperInterfaces()
      Obtains super interfaces.
      Returns:
      the collection of the super interfaces
    • getAncestors

      public Set<JavaClass> getAncestors()
      Obtains ancestors of this class.
      Returns:
      the collection of the ancestors
    • getDescendants

      public Set<JavaClass> getDescendants()
      Obtains descendants of this class.
      Returns:
      the collection of the descendants
    • getEfferentClassesInProject

      public Set<JavaClass> getEfferentClassesInProject()
      Obtains classes required by this class that has its corresponding file.
      Returns:
      the collection of the required classes
    • getAfferentClasses

      public Set<JavaClass> getAfferentClasses()
      Obtains classes requiring this class.
      Returns:
      the collection of the requiring classes
    • getAfferentClassesInProject

      public Set<JavaClass> getAfferentClassesInProject()
      Obtains classes requiring this class, which have their corresponding files.
      Returns:
      the collection of the requiring classes
    • getObsoleteClasses

      public Set<JavaClass> getObsoleteClasses()
      Obtains classes that are obsolete at the same time when this class is updated.
      Returns:
      the collection of the obsolete classes