diff --git a/src/test/java/spoon/test/SpoonTestHelpers.java b/src/test/java/spoon/test/SpoonTestHelpers.java index ac864b9e392..8b48c4b0d02 100644 --- a/src/test/java/spoon/test/SpoonTestHelpers.java +++ b/src/test/java/spoon/test/SpoonTestHelpers.java @@ -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; @@ -19,27 +21,7 @@ private SpoonTestHelpers(){ } public static List> getAllInstantiableMetamodelInterfaces() { - List> 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) itf); - } - } - return result; + return new SpoonMetaModel(new File("src/main/java")).getAllInstantiableMetamodelInterfaces(); } /** diff --git a/src/test/java/spoon/test/metamodel/SpoonMetaModel.java b/src/test/java/spoon/test/metamodel/SpoonMetaModel.java index b1ed43807b6..e763e8c1a4d 100644 --- a/src/test/java/spoon/test/metamodel/SpoonMetaModel.java +++ b/src/test/java/spoon/test/metamodel/SpoonMetaModel.java @@ -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; @@ -344,4 +349,29 @@ private static CtAnnotation getInheritedAnnotation(CtM public Factory getFactory() { return factory; } + + public List> 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> 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) itf); + } + } + return result; + } + }