Bug 76657 - [dom] Call for "Quick Fix" for reference to an object's member field
Summary: [dom] Call for "Quick Fix" for reference to an object's member field
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 129330
Blocks:
  Show dependency tree
 
Reported: 2004-10-20 10:23 EDT by ryenus ' CLA
Modified: 2006-04-10 17:15 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ryenus ' CLA 2004-10-20 10:23:48 EDT
For reference to an objects member function/method, such as:
    stringBuffer.toString();
"Quick fix" can help to create a new field/local variable.

So, what about reference to an objects member variable/field? such as:
    gridBagConstrains.insets;
I suggest "Quick fix" can also help to do the similar for this,
since in this case it's an obvious syntax error.

--
Roger Ye
Comment 1 Martin Aeschlimann CLA 2004-10-27 13:17:27 EDT
The problem is that an expression like

gridBagConstrains.insets;

is a syntax error and syntax error prevent the AST to be build.
So there's not much quick fix can do here.
Comment 2 ryenus ' CLA 2004-11-15 11:04:36 EST
I'm not clear about the 'AST' you said, Anyway,
Code like these:

String value = arrayList.get(0);

and a code snippet has an uncaught checked exception

I think they are all syntax error (if i'm right), 
and they can be fix by Quick-Fix

So, why in this case it can not?
any explanation is appreciated, thanks in advance ;-)
Comment 3 Martin Aeschlimann CLA 2004-11-15 12:18:00 EST
There are syntax errors and semantic errors.
Syntax error are problems were the source code could not be parsed at all and 
therefor the Java compiler could not form a compile tree (AST). Semantic 
errors are when the sytax is correct (tree can be build), but some elements 
just could be resolved or are not visible, initialized ect.

Quick fix needs a compile tree (AST) to do anything at all.

We can forward this bug report to jdt.core and ask that the parser should be 
changed to also return a tree for 'gridBagConstrains.insets;' but I think it 
is unlikely that they will do that.

Moving to jdt.core 
Comment 4 ryenus ' CLA 2005-02-04 20:07:12 EST
Hi,

Is there any news about this ticket?
Comment 5 Olivier Thomann CLA 2005-08-30 14:47:10 EDT
gridBagConstrains.insets; is not a valid statement. Therefore the grammar
rejects such cases.
We could however add the following rule in the grammar:
Statement ::= Name ';'
/.$putCase consumeInvalidStatement(); $break ./

Right now we report:
----------
1. ERROR in d:\tests_sources\X.java
 (at line 6)
	a.i;
	  ^
Syntax error, insert "AssignmentOperator ArrayInitializer" to complete Expression
----------
1 problem (1 error)

javac reports:
X.java:6: not a statement
   a.i;
    ^
1 error

which is a bit more helpful.
The only way to return a better error message is to accept this as syntactically
correct and reject the code later.
Philippe, with this new rule, the grammar is still LALR(1). The problem is that
right now no node could be used to represent this construct.
Comment 6 Olivier Thomann CLA 2005-08-30 15:03:44 EDT
We could also not create any node and report the error in the semantic action
attached to this rule. We would report the error against the current reference
context.
Comment 7 Olivier Thomann CLA 2006-03-31 12:32:14 EST
Moving to JDT/UI.
With the statement recovery, a recovered node is created for gridBagConstrains.insets;.

Therefore it might now be possible to add a quickfix for this kind of error.
Comment 8 Martin Aeschlimann CLA 2006-04-07 09:12:10 EDT
waiting for bug 129330 to be fixed
Comment 9 Martin Aeschlimann CLA 2006-04-10 17:10:19 EDT
reopen as bug 129330 has been fixed
Comment 10 Martin Aeschlimann CLA 2006-04-10 17:15:23 EDT
verified that gridBagConstrains.insets; and arr[i]; now work
added tests > 20060410
Comment 11 Martin Aeschlimann CLA 2006-04-10 17:15:39 EDT
mark as fixed