Class CtCompilationUnitImpl
java.lang.Object
spoon.support.reflect.declaration.CtElementImpl
spoon.support.reflect.declaration.CtCompilationUnitImpl
- All Implemented Interfaces:
Serializable,Cloneable,FactoryAccessor,SourcePositionHolder,CtCompilationUnit,CtElement,CtQueryable,CtVisitable
- Direct Known Subclasses:
CompilationUnitImpl
Implements a compilation unit. In Java, a compilation unit can contain only one
public type declaration and other secondary types declarations (not public).
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface spoon.reflect.declaration.CtCompilationUnit
CtCompilationUnit.UNIT_TYPE -
Field Summary
Fields inherited from class spoon.support.reflect.declaration.CtElementImpl
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAccepts a visitoraddDeclaredType(CtType<?> type)Add a type to the list of declared types.addDeclaredTypeReference(CtTypeReference<?> type)Add a type reference to the list of declared typesclone()Clone the element which calls this method in a new object.Gets all binary (.class) files that corresponds to this compilation unit and have been created by callingSpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...).Gets the declared module if the compilationUnit is "module-info.java"Gets the declared module reference if the compilationUnit is "module-info.java"Gets the declared packageList<CtTypeReference<?>>Gets references to all the types declared in this compilation unit.Gets all the types declared in this compilation unit.getFile()Gets the file that corresponds to this compilation unit if any (contains the source code).Get the imports computed for this CU.int[]CtType<?>Searches and returns the main type (the type which has the same name as the file).Gets the original source code as a string.Returns the original source code (maybe different from toString() if a transformation has been applied).Gets the parent of current reference.Gets the position of this element in input source filesReturns the declaration type of the compilation unit.setDeclaredModule(CtModule module)Sets the declared module if the compilationUnit is "module-info.java" It is here for backward compatibility.Sets the declared module reference if the compilationUnit is "module-info.java"setDeclaredPackage(CtPackage ctPackage)Sets the package declaration using the instance of CtPackage.setDeclaredTypeReferences(List<CtTypeReference<?>> types)Sets the references to types declared in this compilation unit.setDeclaredTypes(List<CtType<?>> types)Sets the types declared in this compilation unit.Sets the file that corresponds to this compilation unit.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.setLineSeparatorPositions(int[] lineSeparatorPositions)setPackageDeclaration(CtPackageDeclaration packageDeclaration)Sets the package declaration<E extends CtElement>
EManually sets the parent element of the current element.<E extends CtElement>
EsetPosition(SourcePosition position)Sets the position in the Java source file.toString()Methods inherited from class spoon.support.reflect.declaration.CtElementImpl
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, updateAllParentsBelowMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface spoon.reflect.declaration.CtElement
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, updateAllParentsBelowMethods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, mapMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Constructor Details
-
CtCompilationUnitImpl
public CtCompilationUnitImpl()
-
-
Method Details
-
getUnitType
Description copied from interface:CtCompilationUnitReturns the declaration type of the compilation unit.- Specified by:
getUnitTypein interfaceCtCompilationUnit
-
getFile
Description copied from interface:CtCompilationUnitGets the file that corresponds to this compilation unit if any (contains the source code).- Specified by:
getFilein interfaceCtCompilationUnit
-
getMainType
Description copied from interface:CtCompilationUnitSearches and returns the main type (the type which has the same name as the file).- Specified by:
getMainTypein interfaceCtCompilationUnit
-
getDeclaredTypes
Description copied from interface:CtCompilationUnitGets all the types declared in this compilation unit.- Specified by:
getDeclaredTypesin interfaceCtCompilationUnit
-
getDeclaredTypeReferences
Description copied from interface:CtCompilationUnitGets references to all the types declared in this compilation unit.- Specified by:
getDeclaredTypeReferencesin interfaceCtCompilationUnit
-
setDeclaredTypeReferences
Description copied from interface:CtCompilationUnitSets the references to types declared in this compilation unit.- Specified by:
setDeclaredTypeReferencesin interfaceCtCompilationUnit
-
setDeclaredTypes
Description copied from interface:CtCompilationUnitSets the types declared in this compilation unit. It is here for backward compatibility. It calls internallyCtCompilationUnit.setDeclaredTypeReferences(List)so theCtCompilationUnitcontains type reference only. It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. Note thatCtCompilationUnitrepresents a secondary model related to mapping of java modules, packages and types to file system.- Specified by:
setDeclaredTypesin interfaceCtCompilationUnit
-
addDeclaredType
Description copied from interface:CtCompilationUnitAdd a type to the list of declared types. It is here for backward compatibility. It calls internallyCtCompilationUnit.addDeclaredTypeReference(CtTypeReference)so theCtCompilationUnitcontains type reference only. It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. Note thatCtCompilationUnitrepresents a secondary model related to mapping of java modules, packages and types to file system.- Specified by:
addDeclaredTypein interfaceCtCompilationUnit
-
addDeclaredTypeReference
Description copied from interface:CtCompilationUnitAdd a type reference to the list of declared types- Specified by:
addDeclaredTypeReferencein interfaceCtCompilationUnit
-
getDeclaredModule
Description copied from interface:CtCompilationUnitGets the declared module if the compilationUnit is "module-info.java"- Specified by:
getDeclaredModulein interfaceCtCompilationUnit
-
getDeclaredModuleReference
Description copied from interface:CtCompilationUnitGets the declared module reference if the compilationUnit is "module-info.java"- Specified by:
getDeclaredModuleReferencein interfaceCtCompilationUnit
-
setDeclaredModule
Description copied from interface:CtCompilationUnitSets the declared module if the compilationUnit is "module-info.java" It is here for backward compatibility. It internally callsCtCompilationUnit.setDeclaredModuleReference(CtModuleReference)It doesn't contain whole CtModule, which belongs to CtModel in primary `java concept` model. Note thatCtCompilationUnitrepresents a secondary model related to mapping of java modules, packages and types to file system.- Specified by:
setDeclaredModulein interfaceCtCompilationUnit
-
setDeclaredModuleReference
Description copied from interface:CtCompilationUnitSets the declared module reference if the compilationUnit is "module-info.java"- Specified by:
setDeclaredModuleReferencein interfaceCtCompilationUnit
-
getDeclaredPackage
Description copied from interface:CtCompilationUnitGets the declared package- Specified by:
getDeclaredPackagein interfaceCtCompilationUnit
-
getPackageDeclaration
- Specified by:
getPackageDeclarationin interfaceCtCompilationUnit- Returns:
- the package declaration
-
setDeclaredPackage
Description copied from interface:CtCompilationUnitSets the package declaration using the instance of CtPackage. It is here for backward compatibility. It calls internallyCtCompilationUnit.setPackageDeclaration(CtPackageDeclaration)It doesn't contain whole CtPackage, which belongs to it's parent package or to CtModule in primary `java concept` model. Note thatCtCompilationUnitrepresents a secondary model related to mapping of java modules, packages and types to file system.- Specified by:
setDeclaredPackagein interfaceCtCompilationUnit
-
setPackageDeclaration
Description copied from interface:CtCompilationUnitSets the package declaration- Specified by:
setPackageDeclarationin interfaceCtCompilationUnit
-
setFile
Description copied from interface:CtCompilationUnitSets the file that corresponds to this compilation unit.- Specified by:
setFilein interfaceCtCompilationUnit
-
getBinaryFiles
Description copied from interface:CtCompilationUnitGets all binary (.class) files that corresponds to this compilation unit and have been created by callingSpoonModelBuilder.compile(spoon.SpoonModelBuilder.InputType...).- Specified by:
getBinaryFilesin interfaceCtCompilationUnit
-
getOriginalSourceCode
Description copied from interface:CtCompilationUnitGets the original source code as a string.- Specified by:
getOriginalSourceCodein interfaceCtCompilationUnit
-
getImports
Description copied from interface:CtCompilationUnitGet the imports computed for this CU. WARNING: This method is tagged as experimental, as its signature and/or usage might change in future release.- Specified by:
getImportsin interfaceCtCompilationUnit- Returns:
- All the imports from the original source code
-
setImports
Description copied from interface:CtCompilationUnitSet the imports of this CU WARNING: This method is tagged as experimental, as its signature and/or usage might change in future release.- Specified by:
setImportsin interfaceCtCompilationUnit- Parameters:
imports- All the imports of the original source code
-
getOriginalSourceFragment
Description copied from interface:SourcePositionHolderReturns the original source code (maybe different from toString() if a transformation has been applied). Warning: this is a advanced method which cannot be considered as part of the stable API- Specified by:
getOriginalSourceFragmentin interfaceCtElement- Specified by:
getOriginalSourceFragmentin interfaceSourcePositionHolder- Overrides:
getOriginalSourceFragmentin classCtElementImpl
-
getLineSeparatorPositions
public int[] getLineSeparatorPositions()- Specified by:
getLineSeparatorPositionsin interfaceCtCompilationUnit- Returns:
- array of offsets in the origin source file, where occurs line separator
-
setLineSeparatorPositions
- Specified by:
setLineSeparatorPositionsin interfaceCtCompilationUnit- Parameters:
lineSeparatorPositions- array of offsets in the origin source file, where occurs line separator
-
getPosition
Description copied from interface:CtElementGets the position of this element in input source files- Specified by:
getPositionin interfaceCtElement- Specified by:
getPositionin interfaceSourcePositionHolder- Overrides:
getPositionin classCtElementImpl- Returns:
- Source file and line number of this element.
It never returns null. Use
SourcePosition.isValidPosition()to detect whether return instance contains start/end indexes.
-
setPosition
Description copied from interface:CtElementSets 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:
setPositionin interfaceCtCompilationUnit- Specified by:
setPositionin interfaceCtElement- Overrides:
setPositionin classCtElementImpl- Parameters:
position- of this element in the input source files
-
getOrCreatePartialSourcePosition
- Returns:
- a
SourcePositionwhich points to thisCompilationUnit. It always returns same value to safe memory.
-
accept
Description copied from interface:CtVisitableAccepts a visitor- Specified by:
acceptin interfaceCtVisitable
-
clone
Description copied from interface:CtElementClone 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.- Specified by:
clonein interfaceCtCompilationUnit- Specified by:
clonein interfaceCtElement- Overrides:
clonein classCtElementImpl
-
getParent
Description copied from interface:CtElementGets the parent of current reference.- Specified by:
getParentin interfaceCtCompilationUnit- Specified by:
getParentin interfaceCtElement- Overrides:
getParentin classCtElementImpl- Throws:
ParentNotInitializedException- when the parent of this element is not initialized
-
setParent
Description copied from interface:CtElementManually sets the parent element of the current element.- Specified by:
setParentin interfaceCtCompilationUnit- Specified by:
setParentin interfaceCtElement- Overrides:
setParentin classCtElementImpl- Type Parameters:
E- this element's type- Parameters:
parent- parent reference.- Returns:
- this element
-
toString
- Specified by:
toStringin interfaceCtElement- Overrides:
toStringin classCtElementImpl- Returns:
- the source code of this element according to the setting of
Environment.getPrettyPrintingMode().
-