Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319638 - [explorer] Expanding a JS file in a Library in the Project explorer results in no children displayed under node
Summary: [explorer] Expanding a JS file in a Library in the Project explorer results i...
Status: CLOSED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.2   Edit
Assignee: Ian Tewksbury CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-12 17:26 EDT by Ian Tewksbury CLA
Modified: 2010-08-30 09:00 EDT (History)
1 user (show)

See Also:
cmjaun: review-
thatnitind: review-
thatnitind: review+


Attachments
Console Log (6.27 KB, text/plain)
2010-07-12 17:26 EDT, Ian Tewksbury CLA
no flags Details
Sample Project (11.77 MB, application/x-zip-compressed)
2010-07-12 17:30 EDT, Ian Tewksbury CLA
no flags Details
Fix Patch (1.89 KB, patch)
2010-07-12 17:31 EDT, Ian Tewksbury CLA
no flags Details | Diff
Possible Fix Patch (1.23 KB, patch)
2010-07-16 16:27 EDT, Ian Tewksbury CLA
thatnitind: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Tewksbury CLA 2010-07-12 17:26:05 EDT
Created attachment 174099 [details]
Console Log

STEPS:
0. Import attached zip and skip to step 6
1. create a static web project
2. create a folder
3. mark that folder as a JavaScript library folder
4. create a file in that folder with some classes in packages in it
5. copy the file into the WebContent folder
6. attempt to expand both the file in the library directory and in the web content directory in the project explorer

RESULTS:
1. the file in the web content directory expands fine showing all the packages and classes in that file

2. the same file expanded when it is in a library folder has nothing listed under it and an error is logged to the console (attached).


CAUSE:
CompolationUnits for files in libraries will not create a working copy of themselves unless explicitly told to.  This is a problem because the CU has to be a working copy in order to get its children to build the results to show under the expanded file.

THE FIX:
Check to see if the requested IClassFile or IJavaScriptUnit has a working copy before attempting to get its children, if it doesn't then explicitly create a working copy, get the children, and then dispose of the working copy.
Comment 1 Ian Tewksbury CLA 2010-07-12 17:30:00 EDT
Created attachment 174100 [details]
Sample Project
Comment 2 Ian Tewksbury CLA 2010-07-12 17:31:34 EDT
Created attachment 174102 [details]
Fix Patch

Fix patch as described in the description. Passes smoke test of project explorer.
Comment 3 Nitin Dahyabhai CLA 2010-07-12 18:24:42 EDT
Rejecting this first patch; the blind casting to IJavaScriptUnit after also testing if "next" were an IClassFile is a problem waiting to happen.
Comment 4 Chris Jaun CLA 2010-07-13 09:28:02 EDT
(In reply to comment #3)
> Rejecting this first patch; the blind casting to IJavaScriptUnit after also
> testing if "next" were an IClassFile is a problem waiting to happen.

Opps...I read right passed that. Good catch Nitin.
Comment 5 Ian Tewksbury CLA 2010-07-13 09:35:33 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > Rejecting this first patch; the blind casting to IJavaScriptUnit after also
> > testing if "next" were an IClassFile is a problem waiting to happen.
> 
> Opps...I read right passed that. Good catch Nitin.

Ditto.  And in my attempt to fix the problem I seem to have found another.  Which is weird because I could have sworn this was working perfectly yesterday.

But some how by creating and releasing the working copy I am getting into some infinite loop that I can't figure out.
Comment 6 Chris Jaun CLA 2010-07-13 09:50:04 EDT
Okay then....can we do something to just make sure we aren't getting any log errors and we can try to fix the node expansion in a future release.
Comment 7 Ian Tewksbury CLA 2010-07-13 11:30:08 EDT
(In reply to comment #6)
> Okay then....can we do something to just make sure we aren't getting any log
> errors and we can try to fix the node expansion in a future release.

Unless we would want to just totally ignore that exception we would have to do a bunch of casting and instance of checking to then determine the package root and see if its source or not and if its not then ignore the error.

The real problem here is there is no such thing as "binary JavaScript" its an idea that was copied over from JDT when JSDT was first created and unfortunately it still sitting around.  In this case the specific issue is in CompilationUnit#validateCompilationUnit.  For a file in a library the returned status is fail because the package root is not source its "binary".  Amazingly enough if you just get rid of this check everything just works.  But I am not sure of the far reaching implications of doing that.

As for my original fix, at this point I don't know why it appeared to work for me yesterday but today there is an issue.  I must have had a patching issue when testing.  Anyways, the problem with the original patch was that every time you create a working copy an ElementChangedEvent gets sent out that the PackageExplorerContentProvider then hears and decides it needs to refresh, in the course of refreshing it creates a working copy, which then sends out an event which the PackageExplorereContentProvider hears....I think you get the picture.  So In an effort to get the patch working I updated the PackageExplorereContentProvider#processDelta to return false for IJavaScriptElementDelta#F_PRIMARY_WORKING_COPY events.  But alas I hit another problem.  The label provider started erroring for the same reason as the PackageExplorerContentProvider, a file in a JS library is neither a working copy nor in a source package root so the CU wont build the structure.

It is at this point that I realized I could probably run around patching up all of these wholes trying to work around this requirement of CompliationUnit#buildStructure that it must be a working copy or in a source package root, or I could just get rid of the source package root requirement.  This brings me back to the beginning of the discussion.  This requirement for the CU to be in a source package root has been there since JSDT was committed to CVS.  My question is, is there a reason.  More precisely, is there any reason we can't remove this requirement?  Is there any reason the CU should care if it is in a source or "binary" package root?  It still has all of its other checks to be sure the file is openable and such.

In the broader scheme of things the whole idea of "binary" JS needs to be removed, but that is definitely not possible for the 3.2.1 time frame.  Any thoughts on removing this package root check for 3.2.1?
Comment 8 Ian Tewksbury CLA 2010-07-13 13:49:50 EDT
I have created Bug 319763 to silence the unnecessary logged error message.  This bug will remain open to track actually fixing it so that files in JS libraries can be expanded to show their packages and classes.
Comment 9 Ian Tewksbury CLA 2010-07-16 16:27:50 EDT
Created attachment 174538 [details]
Possible Fix Patch

My suggestion for a fix is to remove the requirement that a resource be in a source package root for the CU to be valid.  This fixes the problem and I can think of no reason that a JS resource in a "binary" root can't be a valid CU.

Nitin thinks it maybe a sound idea but would like to look into the idea more himself first.
Comment 10 Nitin Dahyabhai CLA 2010-08-16 21:40:58 EDT
Will have to allow it unless the package fragment roots are made to check with each other's exclusion patterns since overlapping library and source folders are now explicitly allowed.

Committed to 3.2.2 and HEAD.  Thanks, Ian.
Comment 11 Ian Tewksbury CLA 2010-08-30 09:00:28 EDT
Verified in latest 3.2.2 builds.