Skip to content

Commit

Permalink
test(metamodel): enforce the package design of the metamodel
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus authored and tdurieux committed Nov 9, 2016
1 parent 2a3a2c0 commit 801d1cd
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 69 deletions.
10 changes: 5 additions & 5 deletions src/main/java/spoon/reflect/factory/CompilationUnitFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/spoon/reflect/factory/CoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,6 @@ SourcePosition createSourcePosition(
*/
CompilationUnit createCompilationUnit();

/**
* Creates a virtual compilation unit.
*/
CompilationUnit createVirtualCompilationUnit();

/**
* Create an access to annotation value
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/spoon/reflect/reference/CtTypeReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,7 +50,7 @@ public interface CtTypeReference<T> 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<T> getActualClass();
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/spoon/support/DefaultCoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -648,12 +647,6 @@ public CompilationUnit createCompilationUnit() {
return cu;
}

public CompilationUnit createVirtualCompilationUnit() {
CompilationUnit cu = new CompilationUnitVirtualImpl();
cu.setFactory(getMainFactory());
return cu;
}

public <T> CtThisAccess<T> createThisAccess() {
CtThisAccess<T> e = new CtThisAccessImpl<>();
e.setFactory(getMainFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/spoon/support/util/RtHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/api/NoClasspathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()));
}
}

}
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/compilation/CompilationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/type/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 801d1cd

Please sign in to comment.