Interface CtCompilationUnit

    • Method Detail

      • getFile

        java.io.File getFile()
        Gets the file that corresponds to this compilation unit if any (contains the source code).
      • setFile

        CtCompilationUnit setFile​(java.io.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
      • getDeclaredTypes

        java.util.List<CtType<?>> getDeclaredTypes()
        Gets all the types declared in this compilation unit.
      • getDeclaredTypeReferences

        java.util.List<CtTypeReference<?>> getDeclaredTypeReferences()
        Gets references to all the types declared in this compilation unit.
      • setDeclaredTypeReferences

        CtCompilationUnit setDeclaredTypeReferences​(java.util.List<CtTypeReference<?>> types)
        Sets the references to types declared in this compilation unit.
      • setDeclaredTypes

        CtCompilationUnit setDeclaredTypes​(java.util.List<CtType<?>> types)
        Sets the types declared in this compilation unit. It is here for backward compatibility. It calls internally 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.
      • addDeclaredType

        CtCompilationUnit addDeclaredType​(CtType<?> type)
        Add a type to the list of declared types. It is here for backward compatibility. It calls internally 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.
      • 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 calls 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.
      • 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 internally 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.
      • getMainType

        CtType<?> getMainType()
        Searches and returns the main type (the type which has the same name as the file).
      • getOriginalSourceCode

        java.lang.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 methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
        Specified by:
        clone in interface CtElement
      • setImports

        CtCompilationUnit 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.
        Parameters:
        imports - All the imports of the original source code
      • setParent

        <E extends CtElement> E setParent​(CtElement parent)
        Description copied from interface: CtElement
        Manually sets the parent element of the current element.
        Specified by:
        setParent in interface CtElement
        Type Parameters:
        E - this element's type
        Parameters:
        parent - parent reference.
        Returns:
        this 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 interface CtElement
        Parameters:
        position - of this element in the input source files