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.

Bug 166032 - AE: Expecting JsParseResult on js method rename
Summary: AE: Expecting JsParseResult on js method rename
Status: VERIFIED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Vitezslav Stejskal
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-26 13:55 UTC by Lukas Jungmann
Modified: 2009-05-29 15:45 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
The patch (973 bytes, text/plain)
2009-05-27 14:43 UTC, Marek Fukala
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Jungmann 2009-05-26 13:55:41 UTC
have:

var x = {
    test: function() {
        xxx();
    }
}
function xxx() {}

-do rename on xxx method

if (file in project) {
//ie edited from files/favorites view

=> nothing happens, no occurrences of xxx are found

} else {

=>
java.lang.AssertionError: Expecting JsParseResult, but have org.netbeans.modules.html.editor.gsf.HtmlParserResult@cc6130
	at org.netbeans.modules.javascript.editing.AstUtilities.getParseResult(AstUtilities.java:163)
	at
org.netbeans.modules.refactoring.javascript.plugins.JsRefactoringPlugin$TransformTask.visit(JsRefactoringPlugin.java:236)
	at org.netbeans.modules.refactoring.javascript.plugins.JsRefactoringPlugin$TransformTask.run(JsRefactoringPlugin.java:228)
	at org.netbeans.modules.parsing.api.ParserManager$MultiUserTaskAction.run(ParserManager.java:165)
	at org.netbeans.modules.parsing.api.ParserManager$MultiUserTaskAction.run(ParserManager.java:137)
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:189)
	at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:101)
	at org.netbeans.modules.refactoring.javascript.plugins.JsRefactoringPlugin.processFiles(JsRefactoringPlugin.java:207)
	at org.netbeans.modules.refactoring.javascript.plugins.RenameRefactoringPlugin.prepare(RenameRefactoringPlugin.java:544)
	at org.netbeans.modules.refactoring.api.AbstractRefactoring.pluginsPrepare2(AbstractRefactoring.java:419)
	at org.netbeans.modules.refactoring.api.AbstractRefactoring.pluginsPrepare(AbstractRefactoring.java:403)
	at org.netbeans.modules.refactoring.api.AbstractRefactoring.prepare(AbstractRefactoring.java:214)
	at org.netbeans.modules.refactoring.spi.impl.ParametersPanel$Prepare.run(ParametersPanel.java:802)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:577)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1030)

}
Comment 1 Martin Schovanek 2009-05-26 14:22:03 UTC
FCS stopper, increasing to P1.
Comment 2 Marek Fukala 2009-05-26 14:23:44 UTC
100% reproducible on projects with some html files.

The problem seems to be in parsing.api where JsRefactoringPlugin:236 does:

if (resultIterator.getSnapshot().getMimeType().equals(JsTokenId.JAVASCRIPT_MIME_TYPE)) {
    //only JsParserResult should get here,
    //but the sometimes the parser result instance is HtmlParserResult
    //which then causes the assertion in AstUtilities
}

I tried resultIterator.getParserResult().getSnapshot().getMimeType() with the same result.

In the worst case if the fix in parsing.api is risky for 6.7 I could fix this particular by 

if(result instanceof JsParserResult) {
  //process ...
}

but this is a hack and noone can be sure where else the same problem can appear.

I would propose to fix this properly and for 6.7.
Comment 3 Marek Fukala 2009-05-27 14:39:18 UTC
After discussin with editor team I am attaching a simple patch which workarounds the problem on javascript refactoring
side. 

Vito, please verify the fix and put it to trunk and release67 as we agreed.

Also please add the trunk changeset of the CSL parser factories registrations as we agreed on to this issue so I can
look how it works after that. Thanks!
Comment 4 Jan Jancura 2009-05-27 14:39:56 UTC
There is nothing wrong on Parsing API side. GSFParserFactory returns some parser instance for given set of Sources, so
it should be able to parse them all.
Comment 5 Marek Fukala 2009-05-27 14:43:24 UTC
Created attachment 82863 [details]
The patch
Comment 6 Marek Fukala 2009-05-27 14:45:47 UTC
I didn't say the problem is parsing.api, although ... :-)
Comment 7 Marek Fukala 2009-05-27 14:48:28 UTC
reassigning to Vita, keeping javascript component to make Hanz happy.
Comment 8 Vitezslav Stejskal 2009-05-27 15:47:46 UTC
Ok, thanks for the patch Marku, it looks ok. It's now in jet-main as http://hg.netbeans.org/jet-main/rev/e9009c5103e7.
Jirko could you please retest this?
Comment 9 Quality Engineering 2009-05-28 08:45:06 UTC
Integrated into 'main-golden', will be available in build *200905280201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/e9009c5103e7
User: Marek Fukala <mfukala@netbeans.org>
Log: #166032: going file by file when refactoring multiple sources in order to avoid mixing up different file types when calling ParserManager.parse
Comment 10 Martin Schovanek 2009-05-28 10:51:47 UTC
The AE looks fixed but the rename still does not work when is invoked at function call statement.

to reproduce:
-------------
1) have a .js like (| represents the cursor):
  function hello() {}
  he|llo();
2) invoke Rename [Ctrl + R]
3) choose Preview

ERROR: Rename found 0 occurrences. 
Comment 11 Marian Mirilovic 2009-05-28 16:26:10 UTC
vstejskal, 
please transplant your part of code into release67 today (before 10pm CEST), mschovanek will report separate issue for
Rename case -> we'll track that issue as a stopper for FCS not for RC1
Comment 12 David Strupl 2009-05-28 16:31:24 UTC
I have tested the behaviour: it is different whether you invoke the rename on invocation place (doesn't work) or on
definition place (works).

The newly created issue migth be even P3 since the rename works - from the place where I would invoke it (function
definition) ;-)
Comment 13 Vitezslav Stejskal 2009-05-28 17:08:55 UTC
"rename still does not work" - This is probably unrelated to the AE. It does not work in 6.5 either. I looked in the
JsRenameHandler and it treats the function references as variables, which is of course wrong.

This seems to be poorly implemented anyway, just add to your example 'var hello;' and see what happens. The function
reference hello(); is colored as a variable (green in the default scheme). When the rename refactoring is initiated
either on var hello; it will rename just the variable declaration. If it's initiated on the function declaration it will
rename both the function declaration and the function call. If it's initiated on the function call, it will again rename
only the variable declaration. This all was tested in Nb6.5 and I assume 6.7 behaves the same.

Anyway, since you confirmed that the AE is fixed, I'll transplant the fix to release67 clone and close this issue as
FIXED. I'll then either find an existing issue describing the broken rename or file a new one.
Comment 14 Martin Schovanek 2009-05-28 17:18:10 UTC
I created a separate issue for the broken Rename case. See issue #166203. 
Comment 15 Vitezslav Stejskal 2009-05-28 17:19:26 UTC
Good, thanks. The fix was transplanted to release67 as http://hg.netbeans.org/release67/rev/1a9a7e848e72.
Comment 16 Martin Schovanek 2009-05-29 15:44:00 UTC
Verified in release67 by QE.
Comment 17 Martin Schovanek 2009-05-29 15:45:40 UTC
v.