public class CtCompilationUnitImpl extends CtElementImpl implements CtCompilationUnit
CtCompilationUnit.UNIT_TYPE
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent
Constructor and Description |
---|
CtCompilationUnitImpl() |
Modifier and Type | Method and Description |
---|---|
void |
accept(CtVisitor visitor)
Accepts a visitor
|
CtCompilationUnitImpl |
addDeclaredType(CtType<?> type)
Add a type to the list of declared types.
|
CtCompilationUnitImpl |
addDeclaredTypeReference(CtTypeReference<?> type)
Add a type reference to the list of declared types
|
CtCompilationUnitImpl |
clone()
Clone the element which calls this method in a new object.
|
java.util.List<java.io.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
|
java.util.List<CtTypeReference<?>> |
getDeclaredTypeReferences()
Gets references to all the types declared in this compilation unit.
|
java.util.List<CtType<?>> |
getDeclaredTypes()
Gets all the types declared in this compilation unit.
|
java.io.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).
|
SourcePosition |
getOrCreatePartialSourcePosition() |
java.lang.String |
getOriginalSourceCode()
Gets the original source code as a string.
|
ElementSourceFragment |
getOriginalSourceFragment()
Returns the original source code (maybe different from toString() if a transformation has been applied).
|
CtPackageDeclaration |
getPackageDeclaration() |
CtElement |
getParent()
Gets the parent of current reference.
|
SourcePosition |
getPosition()
Gets the position of this element in input source files
|
CtCompilationUnit.UNIT_TYPE |
getUnitType()
Returns the declaration type of the compilation unit.
|
CtCompilationUnitImpl |
setDeclaredModule(CtModule module)
Sets the declared module if the compilationUnit is "module-info.java"
It is here for backward compatibility.
|
CtCompilationUnitImpl |
setDeclaredModuleReference(CtModuleReference module)
Sets the declared module reference if the compilationUnit is "module-info.java"
|
CtCompilationUnitImpl |
setDeclaredPackage(CtPackage ctPackage)
Sets the package declaration using the instance of CtPackage.
|
CtCompilationUnitImpl |
setDeclaredTypeReferences(java.util.List<CtTypeReference<?>> types)
Sets the references to types declared in this compilation unit.
|
CtCompilationUnit |
setDeclaredTypes(java.util.List<CtType<?>> types)
Sets the types declared in this compilation unit.
|
CtCompilationUnitImpl |
setFile(java.io.File file)
Sets the file that corresponds to this compilation unit.
|
CtCompilationUnitImpl |
setImports(java.util.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.
|
CtCompilationUnitImpl |
setLineSeparatorPositions(int[] lineSeparatorPositions) |
CtCompilationUnitImpl |
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.
|
java.lang.String |
toString() |
addAnnotation, addComment, asIterable, comment, delete, descendantIterator, emptyList, emptySet, equals, filterChildren, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getFactory, getMetadata, getMetadataKeys, getParent, getParent, getPath, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hashCode, hasParent, isImplicit, isParentInitialized, map, map, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setFactory, setImplicit, setPositions, setValueByRole, toStringDebug, unmodifiableList, updateAllParentsBelow
finalize, getClass, notify, notifyAll, wait, wait, wait
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getParent, getParent, getPath, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setPositions, setValueByRole, toStringDebug, updateAllParentsBelow
getFactory, setFactory
filterChildren, map, map
public CtCompilationUnit.UNIT_TYPE getUnitType()
CtCompilationUnit
getUnitType
in interface CtCompilationUnit
public java.io.File getFile()
CtCompilationUnit
getFile
in interface CtCompilationUnit
public CtType<?> getMainType()
CtCompilationUnit
getMainType
in interface CtCompilationUnit
public java.util.List<CtType<?>> getDeclaredTypes()
CtCompilationUnit
getDeclaredTypes
in interface CtCompilationUnit
public java.util.List<CtTypeReference<?>> getDeclaredTypeReferences()
CtCompilationUnit
getDeclaredTypeReferences
in interface CtCompilationUnit
public CtCompilationUnitImpl setDeclaredTypeReferences(java.util.List<CtTypeReference<?>> types)
CtCompilationUnit
setDeclaredTypeReferences
in interface CtCompilationUnit
public CtCompilationUnit setDeclaredTypes(java.util.List<CtType<?>> types)
CtCompilationUnit
CtCompilationUnit.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.setDeclaredTypes
in interface CtCompilationUnit
public CtCompilationUnitImpl addDeclaredType(CtType<?> type)
CtCompilationUnit
CtCompilationUnit.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.addDeclaredType
in interface CtCompilationUnit
public CtCompilationUnitImpl addDeclaredTypeReference(CtTypeReference<?> type)
CtCompilationUnit
addDeclaredTypeReference
in interface CtCompilationUnit
public CtModule getDeclaredModule()
CtCompilationUnit
getDeclaredModule
in interface CtCompilationUnit
public CtModuleReference getDeclaredModuleReference()
CtCompilationUnit
getDeclaredModuleReference
in interface CtCompilationUnit
public CtCompilationUnitImpl setDeclaredModule(CtModule module)
CtCompilationUnit
CtCompilationUnit.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.setDeclaredModule
in interface CtCompilationUnit
public CtCompilationUnitImpl setDeclaredModuleReference(CtModuleReference module)
CtCompilationUnit
setDeclaredModuleReference
in interface CtCompilationUnit
public CtPackage getDeclaredPackage()
CtCompilationUnit
getDeclaredPackage
in interface CtCompilationUnit
public CtPackageDeclaration getPackageDeclaration()
getPackageDeclaration
in interface CtCompilationUnit
public CtCompilationUnitImpl setDeclaredPackage(CtPackage ctPackage)
CtCompilationUnit
CtCompilationUnit.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.setDeclaredPackage
in interface CtCompilationUnit
public CtCompilationUnitImpl setPackageDeclaration(CtPackageDeclaration packageDeclaration)
CtCompilationUnit
setPackageDeclaration
in interface CtCompilationUnit
public CtCompilationUnitImpl setFile(java.io.File file)
CtCompilationUnit
setFile
in interface CtCompilationUnit
public java.util.List<java.io.File> getBinaryFiles()
CtCompilationUnit
SpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...)
.getBinaryFiles
in interface CtCompilationUnit
public java.lang.String getOriginalSourceCode()
CtCompilationUnit
getOriginalSourceCode
in interface CtCompilationUnit
public ModelList<CtImport> getImports()
CtCompilationUnit
getImports
in interface CtCompilationUnit
public CtCompilationUnitImpl setImports(java.util.Collection<CtImport> imports)
CtCompilationUnit
setImports
in interface CtCompilationUnit
imports
- All the imports of the original source codepublic ElementSourceFragment getOriginalSourceFragment()
SourcePositionHolder
getOriginalSourceFragment
in interface SourcePositionHolder
getOriginalSourceFragment
in interface CtElement
getOriginalSourceFragment
in class CtElementImpl
public int[] getLineSeparatorPositions()
getLineSeparatorPositions
in interface CtCompilationUnit
public CtCompilationUnitImpl setLineSeparatorPositions(int[] lineSeparatorPositions)
setLineSeparatorPositions
in interface CtCompilationUnit
lineSeparatorPositions
- array of offsets in the origin source file, where occurs line separatorpublic SourcePosition getPosition()
CtElement
getPosition
in interface SourcePositionHolder
getPosition
in interface CtElement
getPosition
in class CtElementImpl
SourcePosition.isValidPosition()
to detect whether return instance contains start/end indexes.public <E extends CtElement> E setPosition(SourcePosition position)
CtElement
setPosition
in interface CtCompilationUnit
setPosition
in interface CtElement
setPosition
in class CtElementImpl
position
- of this element in the input source filespublic SourcePosition getOrCreatePartialSourcePosition()
SourcePosition
which points to this CompilationUnit
. It always returns same value to safe memory.public void accept(CtVisitor visitor)
CtVisitable
accept
in interface CtVisitable
public CtCompilationUnitImpl clone()
CtElement
Refactoring.copyType(CtType)
and Refactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.clone
in interface CtCompilationUnit
clone
in interface CtElement
clone
in class CtElementImpl
public CtElement getParent() throws ParentNotInitializedException
CtElement
getParent
in interface CtCompilationUnit
getParent
in interface CtElement
getParent
in class CtElementImpl
ParentNotInitializedException
- when the parent of this element is not initializedpublic <E extends CtElement> E setParent(E parent)
CtElement
setParent
in interface CtCompilationUnit
setParent
in interface CtElement
setParent
in class CtElementImpl
parent
- parent reference.public java.lang.String toString()
toString
in interface CtElement
toString
in class CtElementImpl
Environment.getPrettyPrintingMode()
.Copyright © 2007–2021 Inria. All rights reserved.