Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiP refactor: Add import in types #2085

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/spoon/metamodel/Metamodel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import spoon.SpoonException;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.code.CtImportHolder;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;
Expand Down Expand Up @@ -185,6 +186,7 @@ public static Set<CtType<?>> getAllMetamodelInterfaces() {
result.add(factory.Type().get(spoon.reflect.reference.CtModuleReference.class));
result.add(factory.Type().get(spoon.reflect.declaration.CtUsedService.class));
result.add(factory.Type().get(CtModuleDirective.class));
result.add(factory.Type().get(CtImportHolder.class));
return result;
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/spoon/reflect/code/CtImportHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package spoon.reflect.code;

import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.declaration.CtImport;

import java.util.Set;

import static spoon.reflect.path.CtRole.IMPORT;

/**
* An ImportHolder is any element that can support an header with an import.
* Currently it can be a CtType or a CtPackage via a package-info.ava
*/
public interface CtImportHolder {

@PropertyGetter(role = IMPORT)
Set<CtImport> getImports();

@PropertySetter(role = IMPORT)
<C extends CtImportHolder> C addImport(CtImport ctImport);

@PropertySetter(role = IMPORT)
<C extends CtImportHolder> C setImports(Set<CtImport> ctImport);
}
10 changes: 2 additions & 8 deletions src/main/java/spoon/reflect/cu/CompilationUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
* Defines a compilation unit. In Java, a compilation unit can contain only one
Expand Down Expand Up @@ -142,12 +143,5 @@ enum UNIT_TYPE {
* Get the imports computed for this CU
* @return All the imports from the original source code
*/
Collection<CtImport> getImports();

/**
* Set the imports of this CU
* @param imports All the imports of the original source code
*/
void setImports(Collection<CtImport> imports);

Set<CtImport> getImports();
}
5 changes: 4 additions & 1 deletion src/main/java/spoon/reflect/declaration/CtPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
*/
package spoon.reflect.declaration;

import spoon.reflect.code.CtImportHolder;
import spoon.reflect.reference.CtPackageReference;
import spoon.support.DerivedProperty;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.path.CtRole;

import java.util.Collection;
import java.util.Set;

import static spoon.reflect.path.CtRole.IMPORT;
import static spoon.reflect.path.CtRole.SUB_PACKAGE;
import static spoon.reflect.path.CtRole.CONTAINED_TYPE;

/**
* This element defines a package declaration. The packages are represented by a
* tree.
*/
public interface CtPackage extends CtNamedElement, CtShadowable {
public interface CtPackage extends CtNamedElement, CtShadowable, CtImportHolder {

/**
* The separator for a string representation of a package.
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/spoon/reflect/declaration/CtType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
*/
package spoon.reflect.declaration;

import spoon.reflect.code.CtImportHolder;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.DerivedProperty;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import static spoon.reflect.path.CtRole.IMPORT;
import static spoon.reflect.path.CtRole.METHOD;
import static spoon.reflect.path.CtRole.FIELD;
import static spoon.reflect.path.CtRole.INTERFACE;
Expand All @@ -38,7 +41,7 @@
*
* The type parameter T refers to the actual class that this type represents.
*/
public interface CtType<T> extends CtNamedElement, CtTypeInformation, CtTypeMember, CtFormalTypeDeclarer, CtShadowable {
public interface CtType<T> extends CtNamedElement, CtTypeInformation, CtTypeMember, CtFormalTypeDeclarer, CtShadowable, CtImportHolder {
/**
* The string separator in a Java innertype qualified name.
*/
Expand Down
Loading