[jbosstools-dev] Problem with CDI Builder creating new 'A' type

Viacheslav Kabanovich scabanovich at exadel.com
Tue Jul 31 16:46:01 EDT 2012


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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jbosstools-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jbosstools-dev/attachments/20120731/150bf66f/attachment.html 


More information about the jbosstools-dev mailing list