Bug 202634 - [codeassist] missing super proposal in specific source
Summary: [codeassist] missing super proposal in specific source
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.6 M7   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-07 10:06 EDT by Maxime Daniel CLA
Modified: 2010-04-26 05:06 EDT (History)
1 user (show)

See Also:
srikanth_sankaran: review+


Attachments
proposed fix v1.0 + regression tests (5.96 KB, patch)
2010-03-25 02:37 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v2.0 + regression tests (11.87 KB, patch)
2010-03-29 10:05 EDT, Ayushman Jain CLA
srikanth_sankaran: iplog+
srikanth_sankaran: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2007-09-07 10:06:51 EDT
I20070904-0800

Test case (try to complete after sup):
public class X {
  public static void main(String... args) {
//	foo(null);
  }
  void foo(Object o) {
	sup
  }
}
class Y extends X {
  void foo(Object o) {
	
	super.foo(o);

	if (o instanceof String) {
	}
  }
}
interface I {
}
interface J {
}
Comment 1 David Audel CLA 2007-09-07 10:28:29 EDT
Smaller test case

public class X {
  public static void bar() {

  }
  void foo() {
        sup
  }
}

The bug doesn't occur if a modifier is added to 'foo' or if the static modifier is removed from 'bar'.

public class X {
  public static void bar() {

  }
  public void foo() {
        sup
  }
}

public class X {
  public void bar() {

  }
  void foo() {
        sup
  }
}
Comment 2 Ayushman Jain CLA 2010-03-25 02:37:53 EDT
Created attachment 162955 [details]
proposed fix v1.0 + regression tests

Static modifier is the culprit here. The field CompletionParser$lastModifiers stores the last found modifiers (except for default modifiers like void). While doing the diet parse, we change the field CompletionParser$lastModifiers to reflect the modifier last encountered. Now, while calculating the proposals we just do a parse of the method body for foo via AssistParser#parseBlockStatements(MethodDeclaration, CompilationUnitDeclaration ). The last modifiers field is not changed in this process because we're not looking at the method modifiers. Hence, the above reported problem will occur in any case where the last modifier found during diet parse was static. That is, even the following case will fail to give super proposal


class Try {
	void foo(){
		sup|
	}
	public int abc() {
		return 1;
	}
	public static void def(){}
	void xyz(){}
}

since the lastModifier field was last changed when static was found while parsing header for method 'def'. 

The above patch makes sure we set the field lastModifiers to the modifiers of the method that contains the completion node while we're parsing the body via parseBlockStatements(MethodDeclaration, CompilationUnitDeclaration ). For this, the lastModifiers field also has to be promoted to AssistParser so that it can be set in the above mentioned method.
Comment 3 Ayushman Jain CLA 2010-03-29 10:05:27 EDT
Created attachment 163270 [details]
proposed fix v2.0 + regression tests

Updating the patch to extend the same fix in case of initializers and constructors. Added tests CompletionTests#testBug202634a to f.
Thanks Srikanth for pointing it out.
Comment 4 Srikanth Sankaran CLA 2010-03-30 02:37:02 EDT
Released in HEAD for 3.6M7
Comment 5 Srikanth Sankaran CLA 2010-04-26 05:06:59 EDT
Verified for 3.6M7 using build I20100424-2000