-
-
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
Conversation
…should be visited in CtScanner
@monperrus in #1430 you talked about
but how do you define a leaf CtElement? If I'm comparing against the package location, there is some interfaces in
scanCtAnnotationFieldAccess
scanCtArrayRead
scanCtArrayWrite
scanCtAssert
scanCtAssignment
scanCtBinaryOperator
scanCtBlock
scanCtBreak
scanCtCase
scanCtCatch
scanCtCatchVariable
scanCtCodeSnippetExpression
scanCtCodeSnippetStatement
scanCtComment
scanCtConditional
scanCtConstructorCall
scanCtContinue
scanCtDo
scanCtExecutableReferenceExpression
scanCtFieldRead
scanCtFieldWrite
scanCtFor
scanCtForEach
scanCtIf
scanCtInvocation
scanCtJavaDoc
scanCtLambda
scanCtLiteral
scanCtLocalVariable
scanCtNewArray
scanCtNewClass
scanCtOperatorAssignment
scanCtReturn
scanCtStatementList
scanCtSuperAccess
scanCtSwitch
scanCtSynchronized
scanCtThisAccess
scanCtThrow
scanCtTry
scanCtTryWithResource
scanCtTypeAccess
scanCtUnaryOperator
scanCtVariableRead
scanCtVariableWrite
scanCtWhile
scanCtAnnotation
scanCtAnnotationMethod
scanCtAnnotationType
scanCtAnonymousExecutable
scanCtClass
scanCtConstructor
scanCtEnum
scanCtEnumValue
scanCtField
scanCtInterface
scanCtMethod
scanCtPackage
scanCtParameter
scanCtTypeParameter
scanCtArrayTypeReference
scanCtCatchVariableReference
scanCtExecutableReference
scanCtFieldReference
scanCtIntersectionTypeReference
scanCtLocalVariableReference
scanCtPackageReference
scanCtParameterReference
scanCtTypeParameterReference
scanCtTypeReference
scanCtUnboundVariableReference
scanCtWildcardReference
|
This might work: new SpoonMetaModel(getFactory()).getMMTypes().forEach(mmType->{
if(mmType.getKind()==ABSTRACT && mmType.getModelInteface()!=null) {
CtInterface abstractIface = mmType.getModelInteface();
//abstractIface is called with each abstract interface of spoon model
}
}); |
|
||
@Test | ||
public void testInterfacesAreCtScannable() { | ||
// contract: all interface inherited from CtElement should be visited in CtScanner |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Thes 2 lines above may be replaced by shorter
String methodName = "scan"+mmType.getName();
@pvojtechovsky would you merge this one? |
@@ -567,7 +567,7 @@ public void visitCtCatch(CtCatch catchBlock) { | |||
elementPrinterHelper.writeComment(catchBlock, CommentOffset.BEFORE); | |||
printer.writeSpace().writeKeyword("catch").writeSpace().writeSeparator("("); | |||
CtCatchVariable<? extends Throwable> parameter = catchBlock.getParameter(); | |||
if (parameter.getMultiTypes().size() > 1) { | |||
if (parameter != null && parameter.getMultiTypes() != null && parameter.getMultiTypes().size() > 1) { |
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.
parameter.getMultiTypes() is never null. I suggest to remove this check.
WDYT?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
SpoonMetaModel needs these packages too
"spoon/support/reflect/declaration",
"spoon/support/reflect/code",
"spoon/support/reflect/reference"
Otherwise meta model is not complete.
@@ -212,6 +216,34 @@ public boolean matches(CtClass element) { | |||
} | |||
|
|||
@Test | |||
public void testInterfacesAreCtScannable() { | |||
// contract: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner |
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.
This test checks that there is a scan method. It is good test. But there is not checked that visitXxx method calls all scan methods for each interface implemented by that non abstract class. I suggest to add this test too. May be as part of another PR?
WDYT?
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.
I thought it was the goal of
public void testCtInheritanceScanner() throws Throwable { |
Thank You Simon for that work! |
|
||
List<String> missingMethods = new ArrayList<>(); | ||
|
||
new SpoonMetaModel(interfaces.getFactory()).getMMTypes().forEach(mmType -> { |
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.
This call will fail after #1714 is merged. Add
"spoon/support/reflect/declaration",
"spoon/support/reflect/code",
"spoon/support/reflect/reference"
packages as resources above to fix it.
You are right, so there is already a test for that. |
Fix #1430