Bug 202634

Summary: [codeassist] missing super proposal in specific source
Product: [Eclipse Project] JDT Reporter: Maxime Daniel <maxime_daniel>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: srikanth_sankaran
Version: 3.4Flags: srikanth_sankaran: review+
Target Milestone: 3.6 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + regression tests
none
proposed fix v2.0 + regression tests srikanth_sankaran: iplog+, srikanth_sankaran: review+

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