Class ModelBuilder

java.lang.Object
org.jtool.jxplatform.builder.ModelBuilder
Direct Known Subclasses:
IncrementalModelBuilder, ModelBuilderBatch

public abstract class ModelBuilder extends Object
A builder that builds models from Java source code.
  • Field Details

    • br

      public static final String br
      A line break symbol, "\n" for macOS and Linux, "\r\n" for Windows
    • builderImpl

      protected org.jtool.jxplatform.project.ModelBuilderImpl builderImpl
      The implementation module of this model builder.
  • Constructor Details

    • ModelBuilder

      protected ModelBuilder()
      Creates a new, empty object that builds Java models.
  • Method Details

    • getModelBuilderImpl

      public org.jtool.jxplatform.project.ModelBuilderImpl getModelBuilderImpl()
      Obtains the implementation module of this model builder.
      Returns:
      the implementation module.
    • setSourcecodeAnalysisChain

      public void setSourcecodeAnalysisChain(int analysisChain)
      Sets the maximum number of a chain when analyzing class defined in source-code.
      Parameters:
      analysisChain - the maximum number of the chain
    • setBytecodeAnalysisLevel

      public void setBytecodeAnalysisLevel(int analysisChain)
      Sets the maximum number of a chain when analyzing byte-code classes.
      Parameters:
      analysisChain - the maximum number of the chain
    • analyzeBytecode

      public void analyzeBytecode(boolean bool)
      Sets whether byte-code analysis is performed.
      Parameters:
      bool - true if byte-code analysis is performed, otherwise false
    • analyzeBytecode

      public boolean analyzeBytecode()
      Tests if byte-code analysis is performed.
      Returns:
      true if byte-code analysis is performed, otherwise false
    • useCache

      public void useCache(boolean bool)
      Sets whether byte-code analysis is performed.
      Parameters:
      bool - true if byte-code analysis is performed, otherwise false
    • useCache

      public boolean useCache()
      Tests if byte-code analysis is performed.
      Returns:
      true if byte-code analysis is performed, otherwise false
    • build

      public List<JavaProject> build(String name, String target)
      Builds a source code model for target projects.
      Parameters:
      name - the name of the created model
      target - the directory storing the target projects
      Returns:
      the collection of created project data
    • build

      public JavaProject build(String name, String target, String classpath)
      Builds a source code model for a target project.
      Parameters:
      name - the name of the created model
      target - the directory storing the target project
      classpath - the path where the needed class (or jar) files are located
      Returns:
      the created project data
    • build

      public JavaProject build(String name, String target, String classpath, String srcpath, String binpath)
      Builds a source code model for a target project.
      Parameters:
      name - the name of the created model
      target - the directory storing the target project
      classpath - the path where the needed class (or jar) files are located
      srcpath - the path where the source files are located
      binpath - the path where the binary files are located
      Returns:
      the created project data
    • build

      public JavaProject build(String name, String target, String[] classpath, String[] srcpath, String[] binpath)
      Builds a source code model for a target project.
      Parameters:
      name - the name of the created model
      target - the directory storing the target project
      classpath - the collection of the paths where the needed class (or jar) files are located
      srcpath - the collection of the paths where the source files are located
      binpath - the collection of the paths where the binary files are located
      Returns:
      the created project data
    • unbuild

      public void unbuild()
      Disposes the created models.
    • copyJavaFile

      public JavaFile copyJavaFile(JavaFile jfile)
      Creates a copy of the file
      Parameters:
      jfile - the file to be copied
      Returns:
      the copy
    • getUnregisteredJavaFile

      public JavaFile getUnregisteredJavaFile(String filepath, String code, JavaProject jproject)
      Create a temporary object corresponding to a file without registering project repository.
      Parameters:
      filepath - the path of the file
      code - the contents of the file
      jproject - the project that should contain the file
      Returns:
      the created file
    • getUnregisteredJavaFile

      public JavaFile getUnregisteredJavaFile(String filepath, String code, JavaProject jproject, String charset)
      Create a temporary object corresponding to a file without registering project repository.
      Parameters:
      filepath - the path of the file
      code - the contents of the file
      jproject - the project that should contain the file
      charset - the character set of the file
      Returns:
      the created file
    • findCFG

      public CFG findCFG(JavaProject jproject, String fqn)
      Finds a CFG for a class element having a given fully-qualified name.
      Parameters:
      jproject - the project containing the class element
      fqn - the fully-qualified name of the class member (className#memeberName)
      Returns:
      the found CFG, or null if no CFG is found
    • findCCFG

      public CCFG findCCFG(JavaProject jproject, String fqn)
      Finds a CCFG for a class having a given fully-qualified name.
      Parameters:
      jproject - the project containing the class
      fqn - the fully-qualified name for the class (className)
      Returns:
      the found CFG, or null if no CFG is found
    • getCFG

      public CFG getCFG(JavaMethod jmethod, boolean force)
      Obtains a CFG for a given method.
      Parameters:
      jmethod - the method of interest
      force - true if the CFG will be forcibly recreated, or false if a CFG stored in the repository will be reused
      Returns:
      the created or found CFG, or null if no CFG is created or found
    • getCFG

      public CFG getCFG(JavaMethod jmethod)
      Finds a CFG for a given method.
      Parameters:
      jmethod - the method of interest
      Returns:
      the created or found CFG, or null if no CFG is created or found
    • getCFG

      public CFG getCFG(JavaField jfield, boolean force)
      Obtains a CFG for a given method.
      Parameters:
      jfield - the field of interest
      force - true if the CFG will be forcibly recreated, or false if a CFG stored in the repository will be reused
      Returns:
      the created or found CFG, or null if no CFG is created or found
    • getCFG

      public CFG getCFG(JavaField jfield)
      Obtains a CFG for a given field.
      Parameters:
      jfield - the field of interest
      Returns:
      the created or found CFG, or null if no CFG is created or found
    • getCCFG

      public CCFG getCCFG(JavaClass jclass, boolean force)
      Obtains a CCFG for a given class.
      Parameters:
      jclass - the class of interest
      force - true if the CCFG will be forcibly recreated, or false if a CCFG stored in the repository will be reused
      Returns:
      the created or found CCFG
    • getCCFG

      public CCFG getCCFG(JavaClass jclass)
      Obtains a CCFG for a given class.
      Parameters:
      jclass - the class of interest
      Returns:
      the created or found CCFG
    • getCallGraph

      public CallGraph getCallGraph(JavaProject jproject)
      Obtains a call graph for methods within a project.
      Parameters:
      jproject - the target project
      Returns:
      the created call graph
    • findPDG

      public PDG findPDG(JavaProject jproject, String fqn)
      Finds a PDG for a class member having a given fully-qualified name.
      Parameters:
      jproject - the project containing the class element
      fqn - the fully-qualified name of the class member (className#memeberName)
      Returns:
      the found PDG, or null if no PDG is found
    • findClDG

      public ClDG findClDG(JavaProject jproject, String fqn)
      Finds a ClDG for a class having a given fully-qualified name.
      Parameters:
      jproject - the project containing the class
      fqn - the fully-qualified name for the class (className)
      Returns:
      the found ClDG, or null if no ClDG is found
    • getPDG

      public PDG getPDG(JavaProject jproject, CFG cfg, boolean force, boolean whole)
      Obtains a PDG for a given CFG for a method or a field.
      Parameters:
      jproject - the project containing the target CFG
      cfg - the target CFG
      force - true if the PDG will be forcibly re-created, or false if a PDG stored in the repository will be reused
      whole - true if the PDG will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getPDG

      public PDG getPDG(JavaProject jproject, CFG cfg)
      Obtains a PDG for a given CFG for a method or a field from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jproject - the project containing the target CFG
      cfg - the target CFG
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getPDG

      public PDG getPDG(JavaMethod jmethod, boolean force, boolean whole)
      Obtains a PDG for a given method.
      Parameters:
      jmethod - the method of interest
      force - true if the PDG will be forcibly re-created, or false if a PDG stored in the repository will be reused
      whole - true if the PDG will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getPDG

      public PDG getPDG(JavaMethod jmethod)
      Obtains a PDG for a given method from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jmethod - the method of interest
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getPDG

      public PDG getPDG(JavaField jfield, boolean force, boolean whole)
      Obtains a PDG for a given field.
      Parameters:
      jfield - the field of interest
      force - true if the PDG will be forcibly re-created, or false if a PDG stored in the repository will be reused
      whole - true if the PDG will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getPDG

      public PDG getPDG(JavaField jfield)
      Obtains a PDG for a given field from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jfield - the field of interest
      Returns:
      the created or found PDG, or null if no PDG is created or found
    • getClDG

      public ClDG getClDG(JavaProject jproject, CCFG ccfg, boolean force, boolean whole)
      Obtains a ClDG for a given CCFG for a class.
      Parameters:
      jproject - the project containing the target CCFG
      ccfg - the target CCFG
      force - true if the ClDG will be forcibly recreated, or false if a ClDG stored in the repository will be reused
      whole - true if a ClDG will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found ClDG, or null if no ClDG is created or found
    • getClDG

      public ClDG getClDG(JavaProject jproject, CCFG ccfg)
      Obtains a ClDG for a given CCFG for a class from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jproject - the project containing the target CCFG
      ccfg - the target CCFG
      Returns:
      the created or found ClDG, or null if no ClDG is created or found
    • getClDG

      public ClDG getClDG(JavaClass jclass, boolean force, boolean whole)
      Obtains a ClDG for a given class.
      Parameters:
      jclass - the class of interest
      force - true if the PDG will be forcibly recreated, or false if a ClDG stored in the repository will be reused
      whole - true if a ClDG will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found ClDG, or null if no ClDG is created or found
    • getClDG

      public ClDG getClDG(JavaClass jclass)
      Obtains a ClDG for a given class from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jclass - the class of interest
      Returns:
      the created or found ClDG, or null if no ClDG is created or found
    • getSDG

      public SDG getSDG(JavaProject jproject, boolean force)
      Obtains an SDG for all classes in a project, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jproject - the target project
      force - true if an SDG will be forcibly recreated, or false if an SDG stored in the repository will be reused
      Returns:
      the created or found SDG
    • getSDG

      public SDG getSDG(JavaProject jproject)
      Obtains an SDG for all classes in a project from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jproject - the target project
      Returns:
      the created or found SDG
    • getDependencyGraph

      public DependencyGraph getDependencyGraph(JavaClass jclass, boolean force, boolean whole)
      Obtains a dependency graph for classes related to a given class.
      Parameters:
      jclass - the class of interest
      force - true if the dependency graph will be forcibly recreated, or false if a dependency graph stored in the repository will be reused
      whole - true if a dependency graph will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found dependency graph
    • getDependencyGraph

      public DependencyGraph getDependencyGraph(JavaClass jclass)
      Obtains a dependency graph for classes related to a given class from the cache, using the whole information related to calls to methods and accesses to fields of outside classes.
      Parameters:
      jclass - the class of interest
      Returns:
      the created or found dependency graph
    • getDependencyGraph

      public DependencyGraph getDependencyGraph(Set<JavaClass> classes, boolean force, boolean whole)
      Obtains a dependency graph for classes related to given classes.
      Parameters:
      classes - the collection of the classes of interest
      force - true if a dependency graph will be forcibly recreated, or false if a dependency graph stored in the repository will be reused
      whole - true if a dependency graph will be created with the whole information related to calls to methods and accesses to fields of outside classes
      Returns:
      the created or found dependency graph
    • getgetDependencyGraph

      public DependencyGraph getgetDependencyGraph(Set<JavaClass> classes)
      Obtains a dependency graph for classes related to given classes from the cache.
      Parameters:
      classes - the collection of the classes of interest
      Returns:
      the created or found dependency graph
    • setConsoleVisible

      public void setConsoleVisible(boolean visible)
      Sets whether information is displayed on console.
      Parameters:
      visible - true if the information is displayed, otherwise false
    • getAllClassesForward

      public Set<JavaClass> getAllClassesForward(JavaClass jclass)
      Obtains the classes forward related to a given class.
      Parameters:
      jclass - the class of interest
      Returns:
      the collection of classes used by the class
    • getAllClassesBackward

      public Set<JavaClass> getAllClassesBackward(JavaClass jclass)
      Obtains the classes backward related to a given class.
      Parameters:
      jclass - the class of interest
      Returns:
      the collection of classes using the class
    • getAllMethodsForward

      public Set<JavaMethod> getAllMethodsForward(JavaMethod jmethod)
      Obtains the methods forward related to a given class.
      Parameters:
      jmethod - the method of interest
      Returns:
      the collection of methods called by the method
    • getAllMethodsBackward

      public Set<JavaMethod> getAllMethodsBackward(JavaMethod jmethod)
      Obtains the methods backward related to a given class.
      Parameters:
      jmethod - the method of interest
      Returns:
      the collection of methods calling the method