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 fix: Manage generics from Interface in shadow mode #1914

Merged
merged 46 commits into from
May 23, 2018

Conversation

surli
Copy link
Collaborator

@surli surli commented Mar 15, 2018

Fix #1906

@surli surli changed the title WiP fix: Manage generics from Interface in shadow mode review fix: Manage generics from Interface in shadow mode Mar 15, 2018
@monperrus
Copy link
Collaborator

LGTM!

@pvojtechovsky
Copy link
Collaborator

pvojtechovsky commented Mar 15, 2018

I have tried/tested this code with #1907 and there is still some problem. I have improved the test now so the problem is reproducible here.
Anyway many thanks @surli for this PR it is on good way and it lets me continue with other PRs.

@surli
Copy link
Collaborator Author

surli commented Mar 16, 2018

I have tried/tested this code with #1907 and there is still some problem

Great, thank you, I was not quite confident on my changes ;)

@pvojtechovsky
Copy link
Collaborator

This wrong code is generated by this PR

public abstract interface CtField<T extends java.lang.Object> 
   extends spoon.reflect.code.CtRHSReceiver<A> , 
    spoon.reflect.declaration.CtShadowable , 
   spoon.reflect.declaration.CtTypeMember , 
    spoon.reflect.declaration.CtVariable<T> { ... }

The problem is
CtRHSReceiver<A>
while it should be
CtRHSReceiver<T>

I have extended the test to check that situation

@pvojtechovsky
Copy link
Collaborator

There is some problem with qualified names of interfaces. I have added failing test. For example CtExpression looks like this:

public abstract interface CtExpression<T extends java.lang.Object> extends spoon.reflect.code.CtCodeElement , spoon.reflect.declaration.spoon.reflect.declaration.CtTypedElement<T> , spoon.template.spoon.template.TemplateParameter<T> {

where
spoon.reflect.declaration.spoon.reflect.declaration.CtTypedElement
should be
spoon.reflect.declaration.CtTypedElement

@pvojtechovsky
Copy link
Collaborator

I have found two more problems:

  • CtTypeReference#getSuperInterfaces() returns correctly initialized CtTypeReferences with actual type arguments, but these CtTypeReferences has no parent CtType, so actual type arguments cannot be resolved well. I fixed that problem with last commit
  • CtType#getSuperClass() returns CtTypeReferences without actual type arguments. I have added the failing test. Could you please fix it?

@pvojtechovsky
Copy link
Collaborator

Next problem is with bounding type of actual type arguments of references of parameter types and return types of methods. See failing test.

I am not sure whether it belongs to this PR. May be we merge this one and fix the problem reproduced by last test case in next PR ... but may be it is quite related ... it is up to you, to decide ;-)

By the way, I am really not sure that current behavior of non shadow type (from sources) checked by first part of the test is wanted (see comments in test). For me the shadow class behaves more correct ... but the change would probably destroy many things... hard to estimate...

@surli
Copy link
Collaborator Author

surli commented Mar 23, 2018

For me it should be fixed in this PR: we are trying here to align the behaviour between elements coming from sources and shadow elements, and obviously concerning the generic types, shadow classes are currently badly supported.

Now I don't agree with your comment on the last test:

//is it really correct to have bounding type T?
//There should be NO bounding type - may be a special AST node?

You were talking about the type A of setAssignment with this signature:

public <C extends CtRHSReceiver<A>> C setAssignment(CtExpression<A> assignment)

and A is defined above on the class signature:

public class CtAssignmentImpl<T, A extends T> extends CtStatementImpl implements CtAssignment<T, A>

so for me it shoud really use the bounding type T which should itself be bounding only by object.
Moreover, we normally use the same bounding definition as coming from JDT for source-coming elements, so the definition should be right.

@@ -43,9 +43,9 @@ public void visitPackage(Package aPackage) {
clazz.getPackage();
}
if (clazz.getSuperclass() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok that the check is not on getGenericSuperclass?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I certainly should change that one for safety.

…arameters. Avoid infinite loop when resolving them.
@surli
Copy link
Collaborator Author

surli commented May 18, 2018

Thanks @pvojtechovsky to take back this one. Sorry I'm a lot busy elsewhere these days :-/

@pvojtechovsky pvojtechovsky changed the title WIP fix: Manage generics from Interface in shadow mode review fix: Manage generics from Interface in shadow mode May 20, 2018
@pvojtechovsky pvojtechovsky changed the title review fix: Manage generics from Interface in shadow mode review2 fix: Manage generics from Interface in shadow mode May 20, 2018
@monperrus
Copy link
Collaborator

we have a conflict here. rebase?

Conflicts:
	src/test/java/spoon/test/enums/EnumsTest.java
@pvojtechovsky pvojtechovsky changed the title review2 fix: Manage generics from Interface in shadow mode review fix: Manage generics from Interface in shadow mode May 22, 2018
@pvojtechovsky pvojtechovsky changed the title review fix: Manage generics from Interface in shadow mode review2 fix: Manage generics from Interface in shadow mode May 22, 2018
@pvojtechovsky
Copy link
Collaborator

Merge done, but we should review it after #1998, which is contained in this PR too ... so another merge will be needed

@pvojtechovsky pvojtechovsky changed the title review2 fix: Manage generics from Interface in shadow mode review fix: Manage generics from Interface in shadow mode May 22, 2018
@spoon-bot
Copy link
Collaborator

API changes: 19 (Detected by Revapi)

Old API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-20180522.082726-80 / New API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-SNAPSHOT

The number of parameters of the method have changed.
Old method RtMethod#(Class, String, Class, Type, .Array, .Array, .Array, .Array, int, .Array, .Array, boolean, boolean)
New method RtMethod#(Class, Method, String, Class, Type, .Array, .Array, .Array, .Array, int, .Array, .Array, boolean, boolean)
Breaking binary: breaking,
The number of parameters of the method have changed.
Old method ExecutableRuntimeBuilderContext#(CtConstructor)
New method ExecutableRuntimeBuilderContext#(Executable, CtConstructor)
Breaking binary: breaking,
The number of parameters of the method have changed.
Old method ExecutableRuntimeBuilderContext#(CtMethod)
New method ExecutableRuntimeBuilderContext#(Executable, CtMethod)
Breaking binary: breaking,
The number of parameters of the method have changed.
Old method TypeRuntimeBuilderContext#(CtType)
New method TypeRuntimeBuilderContext#(Type, CtType)
Breaking binary: breaking,
The number of parameters of the method have changed.
Old method TypeReferenceRuntimeBuilderContext#(CtTypeReference)
New method TypeReferenceRuntimeBuilderContext#(Type, CtTypeReference)
Breaking binary: breaking,
Method was removed.
Old method AbstractRuntimeBuilderContext#addArrayReference(CtArrayTypeReference)
New none
Breaking binary: breaking,
Method was removed.
Old method AnnotationRuntimeBuilderContext#addClassReference(CtTypeReference)
New none
Breaking binary: breaking,
Method was removed.
Old method AbstractRuntimeBuilderContext#addInterfaceReference(CtTypeReference)
New none
Breaking binary: breaking,
Method was removed.
Old method AbstractRuntimeBuilderContext#addTypeName(CtTypeReference)
New none
Breaking binary: breaking,
Method was added to an interface.
Old none
New method RuntimeBuilderContext#addTypeReference(CtRole, CtTypeReference)
Breaking binary: non_breaking,
Method was added to an interface.
Old none
New method RuntimeBuilderContext#getTypeParameter(GenericDeclaration, String)
Breaking binary: non_breaking,
The number of parameters of the method have changed.
Old method JavaReflectionTreeBuilder#visitArrayReference(Class)
New method JavaReflectionTreeBuilder#visitArrayReference(CtRole, Type)
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitClassReference(Class)
New none
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitInterfaceReference(Class)
New none
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitMethod(RtMethod)
New none
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitType(ParameterizedType)
New none
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitType(Type)
New none
Breaking binary: breaking,
Method was removed.
Old method JavaReflectionTreeBuilder#visitType(WildcardType)
New none
Breaking binary: breaking,
The number of parameters of the method have changed.
Old method JavaReflectionTreeBuilder#visitTypeParameterReference(TypeVariable)
New method JavaReflectionTreeBuilder#visitTypeParameterReference(CtRole, TypeVariable)
Breaking binary: breaking,

@monperrus
Copy link
Collaborator

#1998 merged. rebase here?

@tdurieux
Copy link
Collaborator

It already been done.

@monperrus monperrus merged commit cb870d1 into INRIA:master May 23, 2018
@monperrus
Copy link
Collaborator

awesome collaborative work, thanks to all!

@tdurieux
Copy link
Collaborator

This would be a nice reflection library!

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.

5 participants