Well, at the end of the day, excluding the 'package-info.java' files turns out to
be the easiest way.
Checking for element.exists() does not work in all circumstances :-/
Best regards,
/Xavier
On Aug 1, 2012, at 10:05 AM, Xavier Coulon wrote:
Denis, Viacheslav,
Thanks for your replies. I'm going to look at checking if the created type really
exists - I think it works: element.exist() returned false for the class 'A',
I'm doing more testing today.
Otherwise, I'll skip events related to any 'package-info.java' resource.
Best regards,
/Xavier
On Aug 1, 2012, at 2:42 AM, Denis Golovin wrote:
> Xavier,
>
> Looked through the code and didn't find better way to handle annotation type
resolution ether.
> I guess you can check compilation unit name and skip units with name
"package-info.java".
>
> Denis
>
> On 07/31/2012 01:46 PM, Viacheslav Kabanovich wrote:
>> Hello Xavier,
>>
>> This class is temporary created in a working copy that is discarded in the same
method in order to get IType as context for resolution of referenced types. For example,
package-info.java may have this content
>>
>> @Named
>> package cdi.test.alternative.case1;
>> import javax.inject.*;
>>
>> Neither interface ICompilationUnit, nor IPackageDeclaration have method
resolveType(String) which is needed to resolve 'Named' into
'javax.inject.Named'. I could not find a better solution than creating a temporary
IType. It is never added to the actual Java model of the project, it exists only in a
working copy that is discarded.
>>
>> Java model listeners may get the event on creating this type, but they also
should get the event on its discarding.
>>
>> Best regards,
>> Slava
>>
>> On 07/31/2012 06:34 AM, Xavier Coulon wrote:
>>>
>>> Hello Daniel,
>>>
>>> As I'm trying to fix
https://issues.jboss.org/browse/JBIDE-12095, I found
something a bit strange in the CDIBuilderDelegate when editing a
'package-info.java' file (just adding a space char):
>>> At line 90, the CDIBuilderDelegate#build() method calls the
PackageDelegate#setPackage() method below which creates a 'class A {}' as shown
below.
>>>
>>> public void setPackage(IPackageDeclaration pkg, IRootDefinitionContext
context) {
>>> qualifiedName = pkg.getElementName();
>>> IType contextType = null;
>>> ICompilationUnit u = null;
>>> if(pkg.getParent() instanceof ICompilationUnit) {
>>> try {
>>> u = ((ICompilationUnit)pkg.getParent()).getWorkingCopy(new
NullProgressMonitor());
>>> contextType = u.createType("class A {}", null, false, new
NullProgressMonitor());
>>> } catch (JavaModelException e) {
>>>
>>> }
>>> }
>>> super.setAnnotatable(pkg, contextType, context, 0);
>>> if (u != null) {
>>> try {
>>> u.discardWorkingCopy();
>>> } catch (JavaModelException e) {
>>>
>>> }
>>> }
>>> }
>>>
>>> The JAX-RS plugin catches an event for this type creation but fails later. I
can add some tests to verify that the type really exist, but still, is this necessary
(just asking, don't take is bad) ?
>>>
>>> Thanks.
>>> Best regards,
>>> /Xavier
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> jbosstools-dev mailing list
>>> jbosstools-dev(a)lists.jboss.org
>>>
https://lists.jboss.org/mailman/listinfo/jbosstools-dev
>>
>>
>>
>> _______________________________________________
>> jbosstools-dev mailing list
>> jbosstools-dev(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/jbosstools-dev
>