-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
review refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner #1703
review refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner #1703
Changes from 9 commits
a4e3612
1df57af
39ae439
f0b7698
8e88a09
bb1ea21
dcd3e03
9cbdf9d
8990c82
1a07699
75e8812
33b8524
3f85b08
ffd583d
0c44575
3d803d4
b720fef
fa8c088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package spoon.test.architecture; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.SpoonAPI; | ||
import spoon.processing.AbstractManualProcessor; | ||
import spoon.reflect.code.CtConstructorCall; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtConstructor; | ||
import spoon.reflect.declaration.CtElement; | ||
import spoon.reflect.declaration.CtField; | ||
import spoon.reflect.declaration.CtInterface; | ||
import spoon.reflect.declaration.CtMethod; | ||
|
@@ -15,15 +17,21 @@ | |
import spoon.reflect.declaration.ModifierKind; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.reflect.reference.CtTypeReference; | ||
import spoon.reflect.visitor.CtInheritanceScanner; | ||
import spoon.reflect.visitor.CtScanner; | ||
import spoon.reflect.visitor.filter.AbstractFilter; | ||
import spoon.reflect.visitor.filter.TypeFilter; | ||
import spoon.test.metamodel.SpoonMetaModel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
import static spoon.test.metamodel.MMTypeKind.ABSTRACT; | ||
|
||
public class SpoonArchitectureEnforcerTest { | ||
|
||
|
@@ -206,4 +214,32 @@ public boolean matches(CtClass element) { | |
assertTrue(klass.getElements(new TypeFilter<>(CtConstructor.class)).stream().allMatch(x -> x.hasModifier(ModifierKind.PRIVATE))); | ||
} | ||
} | ||
|
||
@Test | ||
public void testInterfacesAreCtScannable() { | ||
// contract: all interface inherited from CtElement should be visited in CtScanner | ||
Launcher interfaces = new Launcher(); | ||
interfaces.addInputResource("src/main/java/spoon/support"); | ||
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.addInputResource("src/main/java/spoon/reflect/visitor/CtScanner.java"); | ||
interfaces.buildModel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SpoonMetaModel needs these packages too |
||
|
||
CtClass<?> ctScanner = interfaces.getFactory().Class().get(CtInheritanceScanner.class); | ||
|
||
List<String> missingMethods = new ArrayList<>(); | ||
|
||
new SpoonMetaModel(interfaces.getFactory()).getMMTypes().forEach(mmType->{ | ||
if(mmType.getKind()==ABSTRACT && mmType.getModelInterface() != null) { | ||
CtInterface abstractIface = mmType.getModelInterface(); | ||
String methodName = "scan"+abstractIface.getSimpleName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thes 2 lines above may be replaced by shorter
|
||
if (ctScanner.getMethodsByName(methodName).isEmpty()) { | ||
missingMethods.add(methodName); | ||
} | ||
} | ||
}); | ||
|
||
assertTrue("The following methods are missing in CtScanner: \n"+ StringUtils.join(missingMethods, "\n"),missingMethods.isEmpty()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the contract of this bug should be:
all non-leaf interfaces of the metamodel should be visited by CtInheritance scanner
the interfaces do not have to inherit from ctelement