This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I am going through this code I inherited and have found a section of that does not appear to work correctly. The code is taking a SourceDocument and trying to find the main class using an Identifier. I think the name it is using with the Identifier is incorrect. Here is the code, I have added comments: ClassElement syncElement = null; Identifier id = Identifier.create(getName()); // getName() returns a string "com.portfolio.Test1" SourceElement source = getSourceElementFromSourceFile(); //Returns a valid SourceDocument Task task = source.prepare(); task.waitFinished(); /* This code I added for a check */ ClassElement[] ce = source.getClasses(); //Only one class is return which is correct for( int i=0; i<ce.length; i++){ System.out.println("Found Class in Source:"+ce[i].getSignature()); //Prints out "com/portfolio/Test1" } /* */ System.out.println("Now trying to find id:"+id.getFullName() ); //Prints out "com.portfolio.Test1" syncElement = source.getClass(id); //Always returns null! The question is, what is the format of the String needed to be passed to the create method of the Identifier? I think this line is bad: Identifier id = Identifier.create(getName()); // getName() returns a string "com.portfolio.Test1" it should be not with "." but with "/" like this: Identifier id = Identifier.create("com/portfolio/Test1"); >>Follow up, changing the "." to "/" didn't work as well
Created attachment 4689 [details] Follow up e-mail from Sun with some additional information
Aha. Now I understand what's going on: SourceElement.getClass() accepts either an unqualified identifier (Identifier.create("Test1") in your case), or a identifier matching exactly the class one (Identifier.create("com.portfolio.Test1", "Test1") in your example). Your code passed the Identifier with full qualification but no source name (== the full one by default) and the element was not found. I will add the possibility to lookup using canonical class name as well into the trunk; on released products, please use unqualified name search, which is guaranteed to work.
Fixed in trunk: /cvs/openide/src/org/openide/src/MemoryCollection.java,v <-- MemoryCollection.java new revision: 1.27; previous revision: 1.26 /cvs/java/src/org/netbeans/modules/java/model/InnerClassCollection.java,v <-- InnerClassCollection.java new revision: 1.5; previous revision: 1.4 /cvs/java/src/org/netbeans/modules/java/model/TopClassCollection.java,v <-- TopClassCollection.java new revision: 1.6; previous revision: 1.5
Honza B, can you verify this issue? Thanks.
Verified in NB 3.5
Reorganization of java component