Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 164311

Summary: Code completion unavailable for static methods
Product: [Eclipse Project] JDT Reporter: Lars Gråmark <lars.gramark>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2.1   
Target Milestone: 3.3 M4   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Lars Gråmark CLA 2006-11-13 07:53:54 EST
Code completion doesn't work as expected in some cases. In the class below, 
content assistance is unavailable for the AnyClass methods. I've placed the AnyClass as an inner static class to simplify but it might as well be created as a separate class.

Code completion however succeeds when I make any of the following changes:
1. When replacing the comparison operator ">" to a "<" in the if-statement.
2. Removing the paranthesis in the if-statement, ie changing "if (0 > (10))" to if "(0 > 10)"
3. or removing the LOOP_WHILE label.

public class Test
{
    public static class AnyClass
    {
        public static void callMe()
        {
            System.out.println("whatever");
        }
    }

    public void method1()
    {
        LOOP_WHILE:
        while (true)
        {
            if (0 > (10))
            {
                break LOOP_WHILE;
            }
        }
        AnyClass.callMe(); //code completion fails here
    }
}
Comment 1 David Audel CLA 2006-11-15 10:08:53 EST
An exception occurs during code completion

java.lang.ArrayIndexOutOfBoundsException: -1
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.buildMoreCompletionContext(CompletionParser.java:617)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.attachOrphanCompletionNode(CompletionParser.java:446)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.updateRecoveryState(CompletionParser.java:3869)
	at org.eclipse.jdt.internal.compiler.parser.Parser.resumeOnSyntaxError(Parser.java:10062)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8902)
	at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1314)
	at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1167)
	at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:292)
	at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:255)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:1930)
	at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:123)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:316)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:309)
Comment 2 David Audel CLA 2006-11-16 12:51:42 EST
Created attachment 54002 [details]
Proposed fix
Comment 3 David Audel CLA 2006-11-16 12:59:14 EST
Released for 3.3 M4.

Test added
  CompletionTests#testBug164311()

Thanks for the test case which is the simplest test case to reproduce the bug. The labeled control statement and the '>' followed by a '(' are necessary to reproduce it.
Comment 4 Olivier Thomann CLA 2006-12-11 14:23:34 EST
Verified for 3.3M4 with I20061211-1119