Skip to content

Commit

Permalink
test: move metamodel related method to class SpoonMetaModel for bette…
Browse files Browse the repository at this point in the history
…r discoverability (#1851)
  • Loading branch information
monperrus authored and pvojtechovsky committed Feb 15, 2018
1 parent 6fbea99 commit 3fcc714
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/test/java/spoon/test/SpoonTestHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.filter.OverridingMethodFilter;
import spoon.support.DerivedProperty;
import spoon.test.metamodel.SpoonMetaModel;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -19,27 +21,7 @@ private SpoonTestHelpers(){
}

public static List<CtType<? extends CtElement>> getAllInstantiableMetamodelInterfaces() {
List<CtType<? extends CtElement>> result = new ArrayList<>();
SpoonAPI interfaces = new Launcher();
interfaces.addInputResource("src/main/java/spoon/reflect/declaration");
interfaces.addInputResource("src/main/java/spoon/reflect/code");
interfaces.addInputResource("src/main/java/spoon/reflect/reference");
interfaces.buildModel();

SpoonAPI implementations = new Launcher();
implementations.addInputResource("src/main/java/spoon/support/reflect/declaration");
implementations.addInputResource("src/main/java/spoon/support/reflect/code");
implementations.addInputResource("src/main/java/spoon/support/reflect/reference");
implementations.buildModel();

for(CtType<? > itf : interfaces.getModel().getAllTypes()) {
String impl = itf.getQualifiedName().replace("spoon.reflect", "spoon.support.reflect")+"Impl";
CtType implClass = implementations.getFactory().Type().get(impl);
if (implClass != null && !implClass.hasModifier(ModifierKind.ABSTRACT)) {
result.add((CtType<? extends CtElement>) itf);
}
}
return result;
return new SpoonMetaModel(new File("src/main/java")).getAllInstantiableMetamodelInterfaces();
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/spoon/test/metamodel/SpoonMetaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@

import java.io.File;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import spoon.Launcher;
import spoon.SpoonAPI;
import spoon.SpoonException;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;
import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.factory.Factory;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtTypeReference;
Expand Down Expand Up @@ -344,4 +349,29 @@ private static <A extends Annotation> CtAnnotation<A> getInheritedAnnotation(CtM
public Factory getFactory() {
return factory;
}

public List<CtType<? extends CtElement>> getAllInstantiableMetamodelInterfaces() {
SpoonAPI interfaces = new Launcher();
interfaces.addInputResource("src/main/java/spoon/reflect/declaration");
interfaces.addInputResource("src/main/java/spoon/reflect/code");
interfaces.addInputResource("src/main/java/spoon/reflect/reference");
interfaces.buildModel();

SpoonAPI implementations = new Launcher();
implementations.addInputResource("src/main/java/spoon/support/reflect/declaration");
implementations.addInputResource("src/main/java/spoon/support/reflect/code");
implementations.addInputResource("src/main/java/spoon/support/reflect/reference");
implementations.buildModel();

List<CtType<? extends CtElement>> result = new ArrayList<>();
for(CtType<? > itf : interfaces.getModel().getAllTypes()) {
String impl = itf.getQualifiedName().replace("spoon.reflect", "spoon.support.reflect")+"Impl";
CtType implClass = implementations.getFactory().Type().get(impl);
if (implClass != null && !implClass.hasModifier(ModifierKind.ABSTRACT)) {
result.add((CtType<? extends CtElement>) itf);
}
}
return result;
}

}

0 comments on commit 3fcc714

Please sign in to comment.