8000 generic beans hierarchy by Artyomcool · Pull Request #867 · androidannotations/androidannotations · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Conversation

@Artyomcool
Copy link

PR for #865

Drozdov Artyom added 4 commits January 9, 2014 18:18
@DayS
Copy link
Contributor
DayS commented Jan 10, 2014

Did you test with the second Eclipse for functional test project ? I'm having some trouble to run this instance of Eclipse because of the following error :

java.lang.VerifyError: (class: com/sun/codemodel/JSuperWildcard, method: substituteParams signature: ([Lcom/sun/codemodel/JTypeVar;Ljava/util/List;)Lcom/sun/codemodel/JClass;) Bad access to protected data

I tried to force export of the local codemodel package by adding it to Export-Package in META-INF/MANIFEST.MF but it doesn't change anything.
I'll keep trying, but if nothing work, we should move this class in AA package and use reflection to make substituteParams method public and then call it.

@Artyomcool
Copy link
Author

I didn't run it under eclipse - just mvn test. And this part worked fine for me. The only reason I've put JSuperWildcard under com/sun/codemodel is to make protected method visible for me. But if you are still getting such error - your suggestion about calling this through reflection will work.

@Artyomcool
Copy link
Author

Check if they are loaded with the same class loader - it is the only thing that comes to mind.

@DayS
Copy link
Contributor
DayS commented Jan 10, 2014

@pyricau > Any idea ? As you setup all this, you may known what's happening here

@Artyomcool
Copy link
Author

Could you confirm, that there is no such problem, if you try mvn test?
10.01.2014 18:42 ÐÏÌØÚÏ×ÁÔÅÌØ "Damien" notifications@github.com ÎÁÐÉÓÁÌ:

@pyricau https://github.com/pyricau > Any idea ? As you setup all this,
you may known what's happening here

Reply to this email directly or view it on GitHubhttps://github.com//pull/867#issuecomment-32032284
.

@DayS
Copy link
Contributor
DayS commented Jan 10, 2014

Works with mvn test absolutely not in Eclipse :/

It seems we have a big issue if we have these classes :

@EBean
public class GenericBeanB extends GenericBeanA {
} 

@EBean
public abstract class GenericBeanA {
    @Background
    void method(String list) {
    }
}

In Eclipse, it fails with this exception :

Stacktrace: java.lang.IllegalArgumentException: element is not valid for the containing declared type
at org.eclipse.jdt.internal.compiler.apt.model.TypesImpl.asMemberOf(TypesImpl.java:89)
at org.androidannotations.helper.APTCodeModelHelper.overrideAnnotatedMethod(APTCodeModelHelper.java:126)
at org.androidannotations.handler.BackgroundHandler.process(BackgroundHandler.java:53)
at org.androidannotations.handler.BackgroundHandler.process(BackgroundHandler.java:41)
at org.androidannotations.process.ModelProcessor.processThrowing(ModelProcessor.java:163)
at org.androidannotations.process.ModelProcessor.process(ModelProcessor.java:126)

That's one of the biggest problem with annotation processing. Some IDE use their own internal classes instead of regular ones provided by JDK. So, sometimes it just crash.. But in this specific case, it seems Eclipse's implementation is more strict than Java's classes as it respect the API javadoc.

@DayS
Copy link
Contributor
DayS commented Jan 10, 2014

I'll do some tests and fix this in another PR. Then I'll come back to this one.

@DayS
Copy link
Contributor
DayS commented Jan 10, 2014

Oh. The exception came from a line you added in your PR. I thought it was buggy before this. Could you fix this then ?

@Artyomcool
Copy link
Author

Very strange issue.
Actualy, I don't see that it can be fixed. I mean that internal eclipse compiler don't want to resolve types as it declared in contract:
https://www.cct.lsu.edu/~rguidry/eclipse-doc36/src-html/org/eclipse/jdt/internal/compiler/apt/model/TypesImpl.html
Sources tells me that it will do the job only if element already defined in that class (obviously, it is not an our case).
Other JDK seems to support it in the right way: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/com/sun/tools/javac/model/JavacTypes.java#JavacTypes.asMemberOf%28javax.lang.model.type.DeclaredType%2Cjavax.lang.model.element.Element%29
The thing is that this conversion is the hurt of the PR, I can't just work it around.
Any thoughts? I'm using Android Studio/Intelij Idea as IDE and it relies on the build system (maven or gradle) for generating sources, thats why I didn't have this problem.

@Artyomcool
Copy link
Author

Yeah, there is an issue for that:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382590

@Artyomcool
Copy link
Author

Looks like it is possible to implement the substituting generic params without "asMemberOf" for our particular case. I'll try to do it.

@Artyomcool
Copy link
Author

Hey. Please, check my last commit - I've implemented params lookup ahead of typeMirrorToJClass. mvn test was successful, hope eclipse APT will stop complaining.

@DayS
Copy link
Contributor
DayS commented Jan 11, 2014

Still some issues to run Eclipse (I have a temporary patch by using reflection, but I think it's just a config issue).
But it seems to work, except for simple generic bean like the following :

@EBean
public class SubtypedGenericBean<T extends Number> {
}

Also, could add these classes in functional-test project :

@EBean
public abstract class GenericBeanA<T extends Number> {

    @Background
    void backgroundMethod(T param) {

    }

    @Produce
    public T genericMethod() {
        return null;
    }

}

and

@EBean
public class GenericBeanB extends GenericBeanA<Integer> {

}

@DayS
Copy link
Contributor
DayS commented Jan 11, 2014

BTW, I only have the VerifyError message with second Eclipse for functional-test. So if the last issue is fixed, we could merge it.

@Artyomcool
Copy link
Author

Looks like GenericBeanA shouldn't be abstract. In this case we will cover case for generation GenericBeanA_.
And what exactly version of Eclipse you are using? Maybe I'll play a little bit with class loaders to understand the reason of the VerifyError.

@DayS
Copy link
Contributor
DayS commented Jan 11, 2014

I'm using Eclipse Juno R2.
I should update and try with the last one. As I usually use IntelliJ I didn't keep my Eclipse instance up-to-date.

However, could you try to handle the case of SubtypedGenericBean and add the two other classes un functional-test so I can merge this PR once for all ? :)
The VerifyError is just a non-blocking side-effect and I have to release the 3.0.1 with this PR.

@Artyomcool
Copy link
Author

Yep, I'm working on the subtyped issue at the moment.

@Artyomcool
Copy link
Author

Done. Also added more complicated test cases that I found during fixing your case.

@Artyomcool
Copy link
Author

If the VerifyError still happens after updating eclise - open an issue, I'll be happy to help.

@DayS
Copy link
Contributor
DayS commented Jan 11, 2014

Seems great 👍
Good job

( I'll check tomorrow for VerifyError )

DayS added a commit that referenced this pull request Jan 11, 2014
@DayS DayS merged commit 8f132d8 into androidannotations:develop Jan 11, 2014
@Artyomcool Artyomcool deleted the 865_generic_beans_hierarchy branch January 11, 2014 19:49
@DayS DayS mentioned this pull request Jan 13, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0