Package org.jtool.srcmodel
Class JavaFile
java.lang.Object
org.jtool.srcmodel.JavaFile
An object representing a Java source file.
-
Constructor Summary
ConstructorsConstructorDescriptionJavaFile
(org.eclipse.jdt.core.dom.CompilationUnit cu, String path, String source, String charset, JavaProject jproject) Creates a new object representing a file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addImport
(org.eclipse.jdt.core.dom.ASTNode node) Adds an AST node corresponding to an import declaration appearing in this file.static String
changeExtension
(String path, String ext) Creates the path string of a file after its file extension is changed into a given string.boolean
boolean
Tests if a given file is equal to this file.Returns the character set of the contents of this file.Returns classes declared in this file.org.eclipse.jdt.core.dom.CompilationUnit
Returns the compilation unit created by the Eclipse's JDT parser.Returns the time when this file was created.List<org.eclipse.jdt.core.dom.ASTNode>
Returns AST nodes corresponding to the import declarations appearing in this file.Returns the project that this file exists.getName()
returns the name of this file.Returns the project that this file exists.getPath()
Returns the absolute path that indicates the location of this file in the file system.Returns the relative path of this file based on the project path.static String
getRelativePath
(String path, String base) Obtains the relative path of a given pathReturns the contents of this file, which represents source code.int
hashCode()
boolean
Tests if a parse error occurred.void
setPackage
(JavaPackage jpackage) Sets a package declared in this file.toString()
Obtains information on this 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 filepath
- the absolute path of this file in the file systemsource
- the contents of this filecharset
- the character set of the contents of this filejproject
- 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
Returns the project that this file exists.- Returns:
- the project of this file
-
getPath
Returns the absolute path that indicates the location of this file in the file system.- Returns:
- the absolute path of this file
-
getRelativePath
Returns the relative path of this file based on the project path.- Returns:
- the string of the relative path of this file
-
getName
returns the name of this file.- Returns:
- the file name
-
getSource
Returns the contents of this file, which represents source code.- Returns:
- the contents of this file
-
getCharset
Returns the character set of the contents of this file.- Returns:
- the character set for this file
-
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, otherwisefalse
-
setPackage
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
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
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
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
-
equals
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() -
toString
Obtains information on this file. -
getRelativePath
Obtains the relative path of a given path- Parameters:
path
- the path string that indicates the location of this filebase
- the path string that indicates the base location- Returns:
- the string of the relative path
-
changeExtension
Creates the path string of a file after its file extension is changed into a given string.- Parameters:
path
- the the original path stringext
- the new file extension- Returns:
- the created file path string
-