-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CtCompilationUnit for future import and sniper improvements (…
- v11.2.1-beta-4
- v11.2.1-beta-3
- v11.2.1-beta-2
- v11.2.1-beta-1
- v11.2.0
- v11.1.1-beta-23
- v11.1.1-beta-22
- v11.1.1-beta-21
- v11.1.1-beta-20
- v11.1.1-beta-19
- v11.1.1-beta-18
- v11.1.1-beta-17
- v11.1.1-beta-16
- v11.1.1-beta-15
- v11.1.1-beta-14
- v11.1.1-beta-13
- v11.1.1-beta-12
- v11.1.1-beta-11
- v11.1.1-beta-10
- v11.1.1-beta-9
- v11.1.1-beta-8
- v11.1.1-beta-7
- v11.1.1-beta-6
- v11.1.1-beta-5
- v11.1.1-beta-4
- v11.1.1-beta-3
- v11.1.1-beta-2
- v11.1.1-beta-1
- v11.1.0
- v11.0.1-beta-18
- v11.0.1-beta-17
- v11.0.0
- v10.4.2
- v10.4.1
- v10.4.0
- spoon-decompiler-0.1.0
- spoon-core-10.3.0
- spoon-core-10.2.0
- spoon-core-10.1.1
- spoon-core-10.1.0
- spoon-core-10.0.0
- spoon-core-9.1.0
- spoon-core-9.0.0
- spoon-core-8.3.0
- spoon-core-8.2.0
- spoon-core-8.1.0
- spoon-core-8.0.0
- spoon-core-7.5.0
- spoon-core-7.4.0
- spoon-core-7.3.0
- spoon-core-7.2.0
1 parent
6b09be9
commit 96d3150
Showing
38 changed files
with
1,046 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
src/main/java/spoon/reflect/declaration/CtCompilationUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
/** | ||
* Copyright (C) 2006-2018 INRIA and contributors | ||
* Spoon - http://spoon.gforge.inria.fr/ | ||
* | ||
* This software is governed by the CeCILL-C License under French law and | ||
* abiding by the rules of distribution of free software. You can use, modify | ||
* and/or redistribute the software under the terms of the CeCILL-C license as | ||
* circulated by CEA, CNRS and INRIA at http://www.cecill.info. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. | ||
* | ||
* The fact that you are presently reading this means that you have had | ||
* knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
package spoon.reflect.declaration; | ||
|
||
import java.io.File; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import spoon.reflect.annotations.PropertyGetter; | ||
import spoon.reflect.annotations.PropertySetter; | ||
import spoon.reflect.cu.SourcePosition; | ||
import spoon.reflect.path.CtRole; | ||
import spoon.reflect.reference.CtModuleReference; | ||
import spoon.reflect.reference.CtTypeReference; | ||
import spoon.support.DerivedProperty; | ||
import spoon.support.Experimental; | ||
import spoon.support.UnsettableProperty; | ||
|
||
/** | ||
* Defines a compilation unit. In Java, a compilation unit can contain only one | ||
* public type declaration and other secondary types declarations (not public). | ||
*/ | ||
@Experimental | ||
public interface CtCompilationUnit extends CtElement { | ||
enum UNIT_TYPE { | ||
TYPE_DECLARATION, | ||
PACKAGE_DECLARATION, | ||
MODULE_DECLARATION, | ||
UNKNOWN | ||
} | ||
|
||
/** | ||
* Returns the declaration type of the compilation unit. | ||
*/ | ||
UNIT_TYPE getUnitType(); | ||
/** | ||
* Gets the file that corresponds to this compilation unit if any (contains | ||
* the source code). | ||
*/ | ||
File getFile(); | ||
|
||
/** | ||
* Sets the file that corresponds to this compilation unit. | ||
*/ | ||
CtCompilationUnit setFile(File file); | ||
|
||
/** | ||
* @return array of offsets in the origin source file, where occurs line separator | ||
*/ | ||
int[] getLineSeparatorPositions(); | ||
|
||
/** | ||
* @param lineSeparatorPositions array of offsets in the origin source file, where occurs line separator | ||
*/ | ||
CtCompilationUnit setLineSeparatorPositions(int[] lineSeparatorPositions); | ||
/** | ||
* Gets all binary (.class) files that corresponds to this compilation unit | ||
* and have been created by calling | ||
* {@link spoon.SpoonModelBuilder#compile(spoon.SpoonModelBuilder.InputType...)}. | ||
*/ | ||
List<File> getBinaryFiles(); | ||
|
||
/** | ||
* Gets all the types declared in this compilation unit. | ||
*/ | ||
@DerivedProperty | ||
List<CtType<?>> getDeclaredTypes(); | ||
|
||
/** | ||
* Gets references to all the types declared in this compilation unit. | ||
*/ | ||
@PropertyGetter(role = CtRole.DECLARED_TYPE_REF) | ||
List<CtTypeReference<?>> getDeclaredTypeReferences(); | ||
|
||
/** | ||
* Sets the references to types declared in this compilation unit. | ||
*/ | ||
@PropertySetter(role = CtRole.DECLARED_TYPE_REF) | ||
CtCompilationUnit setDeclaredTypeReferences(List<CtTypeReference<?>> types); | ||
|
||
/** | ||
* Sets the types declared in this compilation unit. | ||
* It is here for backward compatibility. | ||
* It calls internally {@link #setDeclaredTypeReferences(List)} | ||
* so the {@link CtCompilationUnit} contains type reference only. | ||
* It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. | ||
* Note that {@link CtCompilationUnit} represents a secondary model related to mapping of java modules, packages and types to file system. | ||
*/ | ||
@DerivedProperty | ||
CtCompilationUnit setDeclaredTypes(List<CtType<?>> types); | ||
|
||
/** | ||
* Add a type to the list of declared types. | ||
* It is here for backward compatibility. | ||
* It calls internally {@link #addDeclaredTypeReference(CtTypeReference)} | ||
* so the {@link CtCompilationUnit} contains type reference only. | ||
* It doesn't contain whole type, which belongs to it's CtPackage in primary `java concept` model. | ||
* Note that {@link CtCompilationUnit} represents a secondary model related to mapping of java modules, packages and types to file system. | ||
*/ | ||
@DerivedProperty | ||
CtCompilationUnit addDeclaredType(CtType<?> type); | ||
|
||
/** | ||
* Add a type reference to the list of declared types | ||
*/ | ||
@PropertySetter(role = CtRole.DECLARED_TYPE_REF) | ||
CtCompilationUnit addDeclaredTypeReference(CtTypeReference<?> type); | ||
|
||
/** | ||
* Gets the declared module if the compilationUnit is "module-info.java" | ||
*/ | ||
@DerivedProperty | ||
CtModule getDeclaredModule(); | ||
|
||
/** | ||
* Gets the declared module reference if the compilationUnit is "module-info.java" | ||
*/ | ||
@PropertyGetter(role = CtRole.DECLARED_MODULE_REF) | ||
CtModuleReference getDeclaredModuleReference(); | ||
|
||
/** | ||
* Sets the declared module if the compilationUnit is "module-info.java" | ||
* It is here for backward compatibility. | ||
* It internally calls {@link #setDeclaredModuleReference(CtModuleReference)} | ||
* It doesn't contain whole CtModule, which belongs to CtModel in primary `java concept` model. | ||
* Note that {@link CtCompilationUnit} represents a secondary model related to mapping of java modules, packages and types to file system. | ||
*/ | ||
@DerivedProperty | ||
CtCompilationUnit setDeclaredModule(CtModule module); | ||
/** | ||
* Sets the declared module reference if the compilationUnit is "module-info.java" | ||
*/ | ||
@PropertySetter(role = CtRole.DECLARED_MODULE_REF) | ||
CtCompilationUnit setDeclaredModuleReference(CtModuleReference module); | ||
|
||
/** | ||
* Gets the declared package | ||
*/ | ||
@DerivedProperty | ||
CtPackage getDeclaredPackage(); | ||
|
||
/** | ||
* @return the package declaration | ||
*/ | ||
@PropertyGetter(role = CtRole.PACKAGE_DECLARATION) | ||
CtPackageDeclaration getPackageDeclaration(); | ||
|
||
/** | ||
* Sets the package declaration using the instance of CtPackage. | ||
* It is here for backward compatibility. | ||
* It calls internally {@link #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 {@link CtCompilationUnit} represents a secondary model related to mapping of java modules, packages and types to file system. | ||
*/ | ||
@DerivedProperty | ||
CtCompilationUnit setDeclaredPackage(CtPackage ctPackage); | ||
|
||
/** | ||
* Sets the package declaration | ||
*/ | ||
@PropertySetter(role = CtRole.PACKAGE_DECLARATION) | ||
CtCompilationUnit setPackageDeclaration(CtPackageDeclaration packageDeclaration); | ||
|
||
/** | ||
* Searches and returns the main type (the type which has the same name as | ||
* the file). | ||
*/ | ||
@DerivedProperty | ||
CtType<?> getMainType(); | ||
|
||
/** | ||
* Gets the original source code as a string. | ||
*/ | ||
String getOriginalSourceCode(); | ||
|
||
/** | ||
* 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. | ||
* @return All the imports from the original source code | ||
*/ | ||
@Experimental | ||
@PropertyGetter(role = CtRole.DECLARED_IMPORT) | ||
List<CtImport> getImports(); | ||
|
||
@Override | ||
CtCompilationUnit clone(); | ||
|
||
/** | ||
* Set the imports of this CU | ||
* WARNING: This method is tagged as experimental, as its signature and/or usage might change in future release. | ||
* @param imports All the imports of the original source code | ||
*/ | ||
@Experimental | ||
@PropertySetter(role = CtRole.DECLARED_IMPORT) | ||
CtCompilationUnit setImports(Collection<CtImport> imports); | ||
|
||
@Override | ||
@DerivedProperty | ||
CtElement getParent(); | ||
|
||
@Override | ||
@UnsettableProperty | ||
<E extends CtElement> E setParent(E parent); | ||
|
||
@Override | ||
@UnsettableProperty | ||
<E extends CtElement> E setPosition(SourcePosition position); | ||
} |
Oops, something went wrong.