diff --git a/src/main/java/spoon/reflect/factory/CompilationUnitFactory.java b/src/main/java/spoon/reflect/factory/CompilationUnitFactory.java index ddbaaa963ad..ba1c2bdc25e 100644 --- a/src/main/java/spoon/reflect/factory/CompilationUnitFactory.java +++ b/src/main/java/spoon/reflect/factory/CompilationUnitFactory.java @@ -16,10 +16,6 @@ */ package spoon.reflect.factory; -import java.io.File; -import java.util.Map; -import java.util.TreeMap; - import spoon.reflect.cu.CompilationUnit; import spoon.reflect.cu.Import; import spoon.reflect.reference.CtFieldReference; @@ -28,6 +24,10 @@ import spoon.support.compiler.jdt.JDTSnippetCompiler; import spoon.support.reflect.cu.ImportImpl; +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + /** * A factory to create some evaluation utilities on the Spoon metamodel. */ @@ -66,7 +66,7 @@ public CompilationUnit create(String filePath) { CompilationUnit cu = cachedCompilationUnits.get(filePath); if (cu == null) { if (filePath.startsWith(JDTSnippetCompiler.SNIPPET_FILENAME_PREFIX)) { - cu = factory.Core().createVirtualCompilationUnit(); + cu = factory.Core().createCompilationUnit(); //put the virtual compilation unit of code snippet into cache too, so the JDTCommentBuilder can found it cachedCompilationUnits.put(filePath, cu); return cu; diff --git a/src/main/java/spoon/reflect/factory/CoreFactory.java b/src/main/java/spoon/reflect/factory/CoreFactory.java index cb1bb59076c..dd600ef079d 100644 --- a/src/main/java/spoon/reflect/factory/CoreFactory.java +++ b/src/main/java/spoon/reflect/factory/CoreFactory.java @@ -485,11 +485,6 @@ SourcePosition createSourcePosition( */ CompilationUnit createCompilationUnit(); - /** - * Creates a virtual compilation unit. - */ - CompilationUnit createVirtualCompilationUnit(); - /** * Create an access to annotation value * diff --git a/src/main/java/spoon/reflect/reference/CtTypeReference.java b/src/main/java/spoon/reflect/reference/CtTypeReference.java index 551367ff7da..f3a69bd72f9 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeReference.java @@ -20,6 +20,7 @@ import spoon.reflect.declaration.CtShadowable; import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.CtTypeInformation; +import spoon.support.SpoonClassNotFoundException; /** * This interface defines a reference to a @@ -49,7 +50,7 @@ public interface CtTypeReference extends CtReference, CtActualTypeContainer, * * @return the Java class or null if the class is not found (not in * classpath) - * @throws spoon.support.reflect.reference.SpoonClassNotFoundException + * @throws SpoonClassNotFoundException * if the class is not in the classpath */ Class getActualClass(); diff --git a/src/main/java/spoon/support/DefaultCoreFactory.java b/src/main/java/spoon/support/DefaultCoreFactory.java index 28e5ace4c4d..e65edd392e9 100644 --- a/src/main/java/spoon/support/DefaultCoreFactory.java +++ b/src/main/java/spoon/support/DefaultCoreFactory.java @@ -141,7 +141,6 @@ import spoon.support.reflect.code.CtWhileImpl; import spoon.support.reflect.cu.CompilationUnitImpl; import spoon.support.reflect.cu.SourcePositionImpl; -import spoon.support.reflect.declaration.CompilationUnitVirtualImpl; import spoon.support.reflect.declaration.CtAnnotationImpl; import spoon.support.reflect.declaration.CtAnnotationMethodImpl; import spoon.support.reflect.declaration.CtAnnotationTypeImpl; @@ -648,12 +647,6 @@ public CompilationUnit createCompilationUnit() { return cu; } - public CompilationUnit createVirtualCompilationUnit() { - CompilationUnit cu = new CompilationUnitVirtualImpl(); - cu.setFactory(getMainFactory()); - return cu; - } - public CtThisAccess createThisAccess() { CtThisAccess e = new CtThisAccessImpl<>(); e.setFactory(getMainFactory()); diff --git a/src/main/java/spoon/support/reflect/reference/SpoonClassNotFoundException.java b/src/main/java/spoon/support/SpoonClassNotFoundException.java similarity index 96% rename from src/main/java/spoon/support/reflect/reference/SpoonClassNotFoundException.java rename to src/main/java/spoon/support/SpoonClassNotFoundException.java index 19bf58cbf7b..c2384aa8b1f 100644 --- a/src/main/java/spoon/support/reflect/reference/SpoonClassNotFoundException.java +++ b/src/main/java/spoon/support/SpoonClassNotFoundException.java @@ -14,7 +14,7 @@ * 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.support.reflect.reference; +package spoon.support; import spoon.SpoonException; diff --git a/src/main/java/spoon/support/compiler/jdt/ContextBuilder.java b/src/main/java/spoon/support/compiler/jdt/ContextBuilder.java index 492854c469b..3b481e33953 100644 --- a/src/main/java/spoon/support/compiler/jdt/ContextBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ContextBuilder.java @@ -46,7 +46,7 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.DefaultJavaPrettyPrinter; import spoon.reflect.visitor.EarlyTerminatingScanner; -import spoon.support.reflect.reference.SpoonClassNotFoundException; +import spoon.support.SpoonClassNotFoundException; import java.util.ArrayDeque; import java.util.ArrayList; diff --git a/src/main/java/spoon/support/reflect/declaration/CompilationUnitVirtualImpl.java b/src/main/java/spoon/support/reflect/declaration/CompilationUnitVirtualImpl.java deleted file mode 100644 index 7836db78c04..00000000000 --- a/src/main/java/spoon/support/reflect/declaration/CompilationUnitVirtualImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2006-2016 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.support.reflect.declaration; - -import java.io.Serializable; - -import spoon.support.reflect.cu.CompilationUnitImpl; - -public class CompilationUnitVirtualImpl extends CompilationUnitImpl implements Serializable { - - @Override - public String getOriginalSourceCode() { - return ""; - } - -} diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index d1e3047283e..e9488437b8b 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -46,7 +46,7 @@ import spoon.reflect.visitor.Query; import spoon.reflect.visitor.filter.ReferenceTypeFilter; import spoon.support.compiler.SnippetCompilationHelper; -import spoon.support.reflect.reference.SpoonClassNotFoundException; +import spoon.support.SpoonClassNotFoundException; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.util.SignatureBasedSortedSet; diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index f57f25a4f9c..7c0546ac186 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -31,6 +31,7 @@ import spoon.reflect.reference.CtTypeParameterReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; +import spoon.support.SpoonClassNotFoundException; import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.util.RtHelper; diff --git a/src/main/java/spoon/support/util/RtHelper.java b/src/main/java/spoon/support/util/RtHelper.java index 358d0ac774a..540f9d5de75 100644 --- a/src/main/java/spoon/support/util/RtHelper.java +++ b/src/main/java/spoon/support/util/RtHelper.java @@ -16,6 +16,15 @@ */ package spoon.support.util; +import spoon.reflect.code.CtExpression; +import spoon.reflect.code.CtInvocation; +import spoon.reflect.code.CtLiteral; +import spoon.reflect.declaration.ModifierKind; +import spoon.reflect.factory.Factory; +import spoon.reflect.reference.CtExecutableReference; +import spoon.reflect.reference.CtFieldReference; +import spoon.reflect.reference.CtTypeReference; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -27,15 +36,6 @@ import java.util.List; import java.util.Set; -import spoon.reflect.code.CtExpression; -import spoon.reflect.code.CtInvocation; -import spoon.reflect.code.CtLiteral; -import spoon.reflect.declaration.ModifierKind; -import spoon.reflect.factory.Factory; -import spoon.reflect.reference.CtExecutableReference; -import spoon.reflect.reference.CtFieldReference; -import spoon.reflect.reference.CtTypeReference; - /** * This class is a helper for runtime reflection. */ diff --git a/src/test/java/spoon/test/api/NoClasspathTest.java b/src/test/java/spoon/test/api/NoClasspathTest.java index 471f093d87d..f40cb2c6e7b 100644 --- a/src/test/java/spoon/test/api/NoClasspathTest.java +++ b/src/test/java/spoon/test/api/NoClasspathTest.java @@ -22,7 +22,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.filter.TypeFilter; -import spoon.support.reflect.reference.SpoonClassNotFoundException; +import spoon.support.SpoonClassNotFoundException; import spoon.support.visitor.SignaturePrinter; import spoon.test.api.testclasses.Bar; diff --git a/src/test/java/spoon/test/architecture/SpoonArchitectureEnforcer.java b/src/test/java/spoon/test/architecture/SpoonArchitectureEnforcer.java index 9a3ce515640..0ee85c12de4 100644 --- a/src/test/java/spoon/test/architecture/SpoonArchitectureEnforcer.java +++ b/src/test/java/spoon/test/architecture/SpoonArchitectureEnforcer.java @@ -1,12 +1,6 @@ package spoon.test.architecture; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.TreeSet; - import org.junit.Test; - import spoon.Launcher; import spoon.SpoonAPI; import spoon.reflect.code.CtConstructorCall; @@ -15,6 +9,12 @@ import spoon.reflect.declaration.ModifierKind; import spoon.reflect.visitor.filter.AbstractFilter; +import java.util.TreeSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + public class SpoonArchitectureEnforcer { @Test @@ -57,4 +57,26 @@ public boolean matches(CtConstructorCall element) { }).size()); } + @Test + public void metamodelPackageRule() throws Exception { + // all implementations of the metamodel classes have a corresponding interface in the appropriate package + 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(); + + 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(); + + for(CtType t : implementations.getModel().getAllTypes()) { + String impl = t.getQualifiedName().replace(".support", "").replace("Impl", ""); + CtType itf = interfaces.getFactory().Type().get(impl); + assertTrue(t.isAssignableFrom(itf.getReference())); + } + } + } diff --git a/src/test/java/spoon/test/compilation/CompilationTest.java b/src/test/java/spoon/test/compilation/CompilationTest.java index f492ed60b8e..0917d83e852 100644 --- a/src/test/java/spoon/test/compilation/CompilationTest.java +++ b/src/test/java/spoon/test/compilation/CompilationTest.java @@ -21,7 +21,7 @@ import spoon.reflect.visitor.filter.TypeFilter; import spoon.support.compiler.jdt.JDTBasedSpoonCompiler; import spoon.support.compiler.jdt.JDTBatchCompiler; -import spoon.support.reflect.reference.SpoonClassNotFoundException; +import spoon.support.SpoonClassNotFoundException; import spoon.test.compilation.testclasses.Bar; import spoon.test.compilation.testclasses.IBar; import spoon.testing.utils.ModelUtils; diff --git a/src/test/java/spoon/test/type/TypeTest.java b/src/test/java/spoon/test/type/TypeTest.java index 3c329313146..5fef0735bca 100644 --- a/src/test/java/spoon/test/type/TypeTest.java +++ b/src/test/java/spoon/test/type/TypeTest.java @@ -35,7 +35,7 @@ import spoon.reflect.reference.CtIntersectionTypeReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.filter.TypeFilter; -import spoon.support.reflect.reference.SpoonClassNotFoundException; +import spoon.support.SpoonClassNotFoundException; import spoon.test.type.testclasses.Mole; import spoon.test.type.testclasses.Pozole;