Package spoon.reflect.declaration
Interface CtCompilationUnit
-
- All Superinterfaces:
Cloneable
,CtElement
,CtQueryable
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Subinterfaces:
CompilationUnit
- All Known Implementing Classes:
CompilationUnitImpl
,CtCompilationUnitImpl
,NoSourcePosition.NullCompilationUnit
public interface CtCompilationUnit extends CtElement
Defines a compilation unit. In Java, a compilation unit can contain only one public type declaration and other secondary types declarations (not public).
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
CtCompilationUnit.UNIT_TYPE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method 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 typesCtCompilationUnit
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 callingSpoonModelBuilder.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 packageList<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>
EsetParent(CtElement parent)
Manually sets the parent element of the current element.<E extends CtElement>
EsetPosition(SourcePosition position)
Sets the position in the Java source file.-
Methods inherited from interface spoon.reflect.declaration.CtElement
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelow
-
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
-
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Method Detail
-
getUnitType
CtCompilationUnit.UNIT_TYPE getUnitType()
Returns the declaration type of the compilation unit.
-
getFile
File getFile()
Gets the file that corresponds to this compilation unit if any (contains the source code).
-
setFile
CtCompilationUnit setFile(File file)
Sets the file that corresponds to this compilation unit.
-
getLineSeparatorPositions
int[] getLineSeparatorPositions()
- Returns:
- array of offsets in the origin source file, where occurs line separator
-
setLineSeparatorPositions
CtCompilationUnit setLineSeparatorPositions(int[] lineSeparatorPositions)
- Parameters:
lineSeparatorPositions
- array of offsets in the origin source file, where occurs line separator
-
getBinaryFiles
List<File> getBinaryFiles()
Gets all binary (.class) files that corresponds to this compilation unit and have been created by callingSpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...)
.
-
getDeclaredTypes
List<CtType<?>> getDeclaredTypes()
Gets all the types declared in this compilation unit.
-
getDeclaredTypeReferences
List<CtTypeReference<?>> getDeclaredTypeReferences()
Gets references to all the types declared in this compilation unit.
-
setDeclaredTypeReferences
CtCompilationUnit setDeclaredTypeReferences(List<CtTypeReference<?>> types)
Sets the references to types declared in this compilation unit.
-
setDeclaredTypes
CtCompilationUnit setDeclaredTypes(List<CtType<?>> types)
Sets the types declared in this compilation unit. It is here for backward compatibility. It calls internallysetDeclaredTypeReferences(List)
so theCtCompilationUnit
contains type reference only. It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. Note thatCtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.
-
addDeclaredType
CtCompilationUnit addDeclaredType(CtType<?> type)
Add a type to the list of declared types. It is here for backward compatibility. It calls internallyaddDeclaredTypeReference(CtTypeReference)
so theCtCompilationUnit
contains type reference only. It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. Note thatCtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.
-
addDeclaredTypeReference
CtCompilationUnit addDeclaredTypeReference(CtTypeReference<?> type)
Add a type reference to the list of declared types
-
getDeclaredModule
CtModule getDeclaredModule()
Gets the declared module if the compilationUnit is "module-info.java"
-
getDeclaredModuleReference
CtModuleReference getDeclaredModuleReference()
Gets the declared module reference if the compilationUnit is "module-info.java"
-
setDeclaredModule
CtCompilationUnit setDeclaredModule(CtModule module)
Sets the declared module if the compilationUnit is "module-info.java" It is here for backward compatibility. It internally callssetDeclaredModuleReference(CtModuleReference)
It doesn't contain whole CtModule, which belongs to CtModel in primary `java concept` model. Note thatCtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.
-
setDeclaredModuleReference
CtCompilationUnit setDeclaredModuleReference(CtModuleReference module)
Sets the declared module reference if the compilationUnit is "module-info.java"
-
getDeclaredPackage
CtPackage getDeclaredPackage()
Gets the declared package
-
getPackageDeclaration
CtPackageDeclaration getPackageDeclaration()
- Returns:
- the package declaration
-
setDeclaredPackage
CtCompilationUnit setDeclaredPackage(CtPackage ctPackage)
Sets the package declaration using the instance of CtPackage. It is here for backward compatibility. It calls internallysetPackageDeclaration(CtPackageDeclaration)
It doesn't contain whole CtPackage, which belongs to it's parent package or to CtModule in primary `java concept` model. Note thatCtCompilationUnit
represents a secondary model related to mapping of java modules, packages and types to file system.
-
setPackageDeclaration
CtCompilationUnit setPackageDeclaration(CtPackageDeclaration packageDeclaration)
Sets the package declaration
-
getMainType
CtType<?> getMainType()
Searches and returns the main type (the type which has the same name as the file).
-
getOriginalSourceCode
String getOriginalSourceCode()
Gets the original source code as a string.
-
getImports
ModelList<CtImport> getImports()
Get the imports computed for this CU. WARNING: This method is tagged as experimental, as its signature and/or usage might change in future release.- Returns:
- All the imports from the original source code
-
clone
CtCompilationUnit clone()
Description copied from interface:CtElement
Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methodsRefactoring.copyType(CtType)
andRefactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.
-
setImports
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.- Parameters:
imports
- All the imports of the original source code
-
getParent
CtElement getParent()
Description copied from interface:CtElement
Gets the parent of current reference.
-
setParent
<E extends CtElement> E setParent(CtElement parent)
Description copied from interface:CtElement
Manually sets the parent element of the current element.
-
setPosition
<E extends CtElement> E setPosition(SourcePosition position)
Description copied from interface:CtElement
Sets the position in the Java source file. Note that this information is used to feed the line numbers in the generated bytecode if any (which is useful for debugging).- Specified by:
setPosition
in interfaceCtElement
- Parameters:
position
- of this element in the input source files
-
-