Skip to content
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

Merged
merged 18 commits into from
Nov 13, 2017

Conversation

surli
Copy link
Collaborator

@surli surli commented Nov 9, 2017

Fix #1430

@surli
Copy link
Collaborator Author

surli commented Nov 9, 2017

@monperrus in #1430 you talked about

every abstract non-leaf CtElement

but how do you define a leaf CtElement? If I'm comparing against the package location, there is some interfaces in spoon.reflect.code which are non leaf. It's not perfectly clear for me which interface should be scannable and which one should not be. I currently get the following list of missing method in CtInheritanceScanner:

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

@pvojtechovsky
Copy link
Collaborator

every abstract non-leaf CtElement

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
Copy link
Collaborator

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

@surli surli changed the title Wip refactor: All interfaces inherited from CtElement should be visited in CtScanner Wip refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner Nov 10, 2017
@surli surli changed the title Wip refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner review refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner Nov 10, 2017
@surli surli changed the title review refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner WiP refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner Nov 10, 2017
@surli surli changed the title WiP refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner review refactor: all non-leaf interfaces of the metamodel should be visited by CtInheritanceScanner Nov 10, 2017
new SpoonMetaModel(interfaces.getFactory()).getMMTypes().forEach(mmType->{
if(mmType.getKind()==ABSTRACT && mmType.getModelInterface() != null) {
CtInterface abstractIface = mmType.getModelInterface();
String methodName = "scan"+abstractIface.getSimpleName();
Copy link
Collaborator

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();

@monperrus
Copy link
Collaborator

@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) {
Copy link
Collaborator

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();
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {

@pvojtechovsky
Copy link
Collaborator

Thank You Simon for that work!
I do not persist on fixing of my suggestions. They are optional. Just let me know if you are done. Then this PR is OK for me.


List<String> missingMethods = new ArrayList<>();

new SpoonMetaModel(interfaces.getFactory()).getMMTypes().forEach(mmType -> {
Copy link
Collaborator

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.

@pvojtechovsky
Copy link
Collaborator

there is not checked that visitXxx method calls all scan methods

public void testCtInheritanceScanner() throws Throwable {

You are right, so there is already a test for that.

@pvojtechovsky pvojtechovsky merged commit b62d56e into INRIA:master Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants