Class JavaFile

java.lang.Object
org.jtool.srcmodel.JavaFile

public class JavaFile extends Object
An object representing a Java source file.
  • Constructor Details

    • JavaFile

      public JavaFile(org.eclipse.jdt.core.dom.CompilationUnit cu, String path, String source, String charset, JavaProject jproject)
      Creates a new object representing a file. This constructor is not intended to be invoked by clients.
      Parameters:
      cu - the compilation unit of this file
      path - the absolute path of this file in the file system
      source - the contents of this file
      charset - the character set of the contents of this file
      jproject - the project that this file exists
  • Method Details

    • getCompilationUnit

      public org.eclipse.jdt.core.dom.CompilationUnit getCompilationUnit()
      Returns the compilation unit created by the Eclipse's JDT parser.
      Returns:
      the compilation unit of this file
    • getJavaProject

      public JavaProject getJavaProject()
      Returns the project that this file exists.
      Returns:
      the project of this file
    • getPath

      public String getPath()
      Returns the absolute path that indicates the location of this file in the file system.
      Returns:
      the absolute path of this file
    • getRelativePath

      public String getRelativePath()
      Returns the relative path of this file based on the project path.
      Returns:
      the string of the relative path of this file
    • getName

      public String getName()
      returns the name of this file.
      Returns:
      the file name
    • getSource

      public String getSource()
      Returns the contents of this file, which represents source code.
      Returns:
      the contents of this file
    • getCharset

      public String getCharset()
      Returns the character set of the contents of this file.
      Returns:
      the character set for this file
    • getCreatedTime

      public ZonedDateTime getCreatedTime()
      Returns the time when this file was created.
      Returns:
      the created time
    • hasParseErrors

      public boolean hasParseErrors()
      Tests if a parse error occurred.
      Returns:
      true if a parse error occurred, otherwise false
    • setPackage

      public void setPackage(JavaPackage jpackage)
      Sets a package declared in this file. This method is not intended to be invoked by clients.
      Parameters:
      jpackage - the package for this file
    • getPackage

      public JavaPackage getPackage()
      Returns the project that this file exists. All the classes declared in this file belong to the package.
      Returns:
      the package for this file
    • getClasses

      public Set<JavaClass> getClasses()
      Returns classes declared in this file.
      Returns:
      the collection of the declared classes
    • addImport

      public void addImport(org.eclipse.jdt.core.dom.ASTNode node)
      Adds an AST node corresponding to an import declaration appearing in this file. This method is not intended to be invoked by clients.
      Parameters:
      node - the corresponding AST node
    • getImports

      public List<org.eclipse.jdt.core.dom.ASTNode> getImports()
      Returns AST nodes corresponding to the import declarations appearing in this file.
      Returns:
      the collection of the AST nodes related to the import declarations
    • equals

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

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

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

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

      public static String getRelativePath(String path, String base)
      Obtains the relative path of a given path
      Parameters:
      path - the path string that indicates the location of this file
      base - the path string that indicates the base location
      Returns:
      the string of the relative path
    • changeExtension

      public static String changeExtension(String path, String ext)
      Creates the path string of a file after its file extension is changed into a given string.
      Parameters:
      path - the the original path string
      ext - the new file extension
      Returns:
      the created file path string