Community
Participate
Working Groups
Build 20040529 The dialog to attach source to a JAR doesn't allow you to choose a project, only a directory. However, projects *are* valid directories which can contain source at the top level. # Setup steps 1. Create a project containing a class with a main method, Hello.java. 2. Put a breakpoint in the main method. 3. Create a JAR containing only Hello.class. # Execution steps 4. Launch Hello.class, making sure the source lookup path is empty. 5. Debug to the breakpoint. You should get the compilation unit editor. 6. Click the "Attach source" button. 7. In the resulting dialog, click "Workspace..." to browse the workspace. 8. In the resulting dialog, select the project containing Hello.java 9. The OK button disables. 7. In the dialog, click "Workspace..."
This isn't actually related to debugging. Simpler steps: 1. Create a project containing a class with a main method, Hello.java (default package). 2. Create a JAR containing only Hello.class. 3. Double-click Hello.class. 4. A class file editor opens. 5. Click "Change attached source...". 6. In the resulting dialog, click "Workspace..." 7. Select the project containing Hello.java. 8. The OK button disables.
I think jdt.core deosn't support this. I manipulated the jdt.ui code to allo picking a project, but the source attachment was not taken by jdt.core. Moving to jdt.core. Let me know if the UI should allow picking a project as source attachment folder
Olivier - pls check expectation, no feature to add; we only want to align core and ui here.
Martin, how do you enable/disable the OK button in the source selection dialog?
You would have to fix it in our code, comment out line dialog.setValidator(validator); in the 'SourceAttachmentBlock' But you can always just type the project path yourself in the text field.
Philippe, Do you have any idea where the /P as a source attachment is discarded?
I am preparing a patch for RC3.
Created attachment 11906 [details] Patch to apply on HEAD
Created attachment 11907 [details] Regression test. Apply on HEAD
Jerome - pls verify
Follow the steps in comment 1, now the button OK should be disabled. If not, type /P if P is the name of the project.
If we don't fix this, then the project == source folder scenario doesn't allow to pick this source folder as a source attachment for subsequent libraries. Fix is safe. Only remaining issue is that this scenario should be leveraged as well in build path wizard, as explained in comment #2. Propose we only fix it if UI can leverage it. Dirk - what is your take ?
The UI wizard does already allow to select and also enter a project. That was done for RC2 and annotated in bug 65191. Is that what you want, or should I disallow it again?
Since the UI already supports it I opt to fix it.
Ok for me as well.
Jerome: pls verify change
Olivier, in SourceMapper#computeRootPath(IContainer, HashSet, boolean) shouldn't the following: if (hasJavaSourceFile) { IPath fullPath = container.getFullPath(); IPath rootPathEntry = fullPath.removeFirstSegments (this.sourcePath.segmentCount()).setDevice(null); this.rootPaths.add(rootPathEntry.toString()); } be this instead ? if (hasJavaSourceFile) { IPath fullPath = container2.getFullPath(); IPath rootPathEntry = fullPath.removeFirstSegments (this.sourcePath.segmentCount()).setDevice(null); this.rootPaths.add(rootPathEntry.toString()); }
Yes, you are right. In this case, container and container2 are the same. This is why it didn't fail with the test case. Please make the change.
Created attachment 12205 [details] New patch Here is a new patch. In fact, "container2" is always the same container than "container". So I simplified that code. Jerome, please review that patch.
I am missing how the following code in SourceMapper#computeAllRootPaths(...) is performing ok: Object target = JavaModel.getTarget(...); if (target instanceof IContainer) { IResource resource = root.getResource(); if (resource.getType() == IResource.FOLDER) { ... } } else if (target instanceof File) { ... } I don't see how this change is improving anything, as it still checks for resource.getType() to be an IResource.FOLDER. Also (cosmetic) for code clarity, first instanceof check should be instanceof IResource, then you go and check against type to be a CONTAINER (?). Indeed, if it is a resource to start with, it is pointless to retest whether it is an io.File after.
Agreed. Changing this code to : if (target instanceof IResource) { IResource resource = (IResource) target; if (resource instanceof IContainer) { ... } } else if (target instanceof File) { ... } is the right change.
To summurarize, the fix consists in changing: - PackageFragmentRoot#findSourceAttachmentRecommendation() - SourceMapper#computeAllRootPaths(...) - SourceMapper#computeRootPath(...) - SourceMapper#findSource(...) to check for IContainer instead of IFolder
Released changes decribed in comment #20 and added regression tests AttachSourceTests#testProjectAsClassFolder1(), #testProjectAsClassFolder2() and #testProjectAsSourceAttachment()
Verified for 3.0RC3 I200406180010