public interface CtCompilationUnit extends CtElement
Modifier and Type | Interface and Description |
---|---|
static class |
CtCompilationUnit.UNIT_TYPE |
Modifier and Type | Method and Description |
---|---|
CtCompilationUnit |
addDeclaredType(CtType<?> type)
Add a type to the list of declared types.
|
CtCompilationUnit |
addDeclaredTypeReference(CtTypeReference<?> type)
Add a type reference to the list of declared types
|
CtCompilationUnit |
clone()
Clone the element which calls this method in a new object.
|
List<File> |
getBinaryFiles()
Gets all binary (.class) files that corresponds to this compilation unit
and have been created by calling
SpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...) . |
CtModule |
getDeclaredModule()
Gets the declared module if the compilationUnit is "module-info.java"
|
CtModuleReference |
getDeclaredModuleReference()
Gets the declared module reference if the compilationUnit is "module-info.java"
|
CtPackage |
getDeclaredPackage()
Gets the declared package
|
List<CtTypeReference<?>> |
getDeclaredTypeReferences()
Gets references to all the types declared in this compilation unit.
|
List<CtType<?>> |
getDeclaredTypes()
Gets all the types declared in this compilation unit.
|
File |
getFile()
Gets the file that corresponds to this compilation unit if any (contains
the source code).
|
ModelList<CtImport> |
getImports()
Get the imports computed for this CU.
|
int[] |
getLineSeparatorPositions() |
CtType<?> |
getMainType()
Searches and returns the main type (the type which has the same name as
the file).
|
String |
getOriginalSourceCode()
Gets the original source code as a string.
|
CtPackageDeclaration |
getPackageDeclaration() |
CtElement |
getParent()
Gets the parent of current reference.
|
CtCompilationUnit.UNIT_TYPE |
getUnitType()
Returns the declaration type of the compilation unit.
|
CtCompilationUnit |
setDeclaredModule(CtModule module)
Sets the declared module if the compilationUnit is "module-info.java"
It is here for backward compatibility.
|
CtCompilationUnit |
setDeclaredModuleReference(CtModuleReference module)
Sets the declared module reference if the compilationUnit is "module-info.java"
|
CtCompilationUnit |
setDeclaredPackage(CtPackage ctPackage)
Sets the package declaration using the instance of CtPackage.
|
CtCompilationUnit |
setDeclaredTypeReferences(List<CtTypeReference<?>> types)
Sets the references to types declared in this compilation unit.
|
CtCompilationUnit |
setDeclaredTypes(List<CtType<?>> types)
Sets the types declared in this compilation unit.
|
CtCompilationUnit |
setFile(File file)
Sets the file that corresponds to this compilation unit.
|
CtCompilationUnit |
setImports(Collection<CtImport> imports)
Set the imports of this CU
WARNING: This method is tagged as experimental, as its signature and/or usage might change in future release.
|
CtCompilationUnit |
setLineSeparatorPositions(int[] lineSeparatorPositions) |
CtCompilationUnit |
setPackageDeclaration(CtPackageDeclaration packageDeclaration)
Sets the package declaration
|
<E extends CtElement> |
setParent(E parent)
Manually sets the parent element of the current element.
|
<E extends CtElement> |
setPosition(SourcePosition position)
Sets the position in the Java source file.
|
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setPositions, setValueByRole, updateAllParentsBelow
getFactory, setFactory
accept
filterChildren, map, map
getOriginalSourceFragment
CtCompilationUnit.UNIT_TYPE getUnitType()
File getFile()
CtCompilationUnit setFile(File file)
int[] getLineSeparatorPositions()
CtCompilationUnit setLineSeparatorPositions(int[] lineSeparatorPositions)
lineSeparatorPositions
- array of offsets in the origin source file, where occurs line separatorList<File> getBinaryFiles()
SpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...)
.List<CtType<?>> getDeclaredTypes()
List<CtTypeReference<?>> getDeclaredTypeReferences()
CtCompilationUnit setDeclaredTypeReferences(List<CtTypeReference<?>> types)
CtCompilationUnit setDeclaredTypes(List<CtType<?>> types)
setDeclaredTypeReferences(List)
so the CtCompilationUnit
contains type reference only.
It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model.
Note that CtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.CtCompilationUnit addDeclaredType(CtType<?> type)
addDeclaredTypeReference(CtTypeReference)
so the CtCompilationUnit
contains type reference only.
It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model.
Note that CtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.CtCompilationUnit addDeclaredTypeReference(CtTypeReference<?> type)
CtModule getDeclaredModule()
CtModuleReference getDeclaredModuleReference()
CtCompilationUnit setDeclaredModule(CtModule module)
setDeclaredModuleReference(CtModuleReference)
It doesn't contain whole CtModule, which belongs to CtModel in primary `java concept` model.
Note that CtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.CtCompilationUnit setDeclaredModuleReference(CtModuleReference module)
CtPackage getDeclaredPackage()
CtPackageDeclaration getPackageDeclaration()
CtCompilationUnit setDeclaredPackage(CtPackage ctPackage)
setPackageDeclaration(CtPackageDeclaration)
It doesn't contain whole CtPackage, which belongs to it's parent package or to CtModule in primary `java concept` model.
Note that CtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.CtCompilationUnit setPackageDeclaration(CtPackageDeclaration packageDeclaration)
CtType<?> getMainType()
String getOriginalSourceCode()
ModelList<CtImport> getImports()
CtCompilationUnit clone()
CtElement
Refactoring.copyType(CtType)
and Refactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.CtCompilationUnit setImports(Collection<CtImport> imports)
imports
- All the imports of the original source codeCtElement getParent()
CtElement
<E extends CtElement> E setParent(E parent)
CtElement
<E extends CtElement> E setPosition(SourcePosition position)
CtElement
setPosition
in interface CtElement
position
- of this element in the input source filesCopyright © 2007–2019 Inria. All rights reserved.