Bug 395604 - Code assist does not work after anonymous class inside in an array initializer
Summary: Code assist does not work after anonymous class inside in an array initializer
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.2.1   Edit
Hardware: PC Windows 7
: P3 normal with 25 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
: 336228 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-12-03 09:35 EST by Viliam Anirud CLA
Modified: 2022-10-04 01:35 EDT (History)
14 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Viliam Anirud CLA 2012-12-03 09:35:51 EST
In the following class the code assist does not give any proposals after the member with anonymous inner class:


public class TestClas {

	public Object[] objects = new Object[] {
		new Object() {
			
		},
		// no code completion of array members after this point
		new Object()
	};
	
}

Reproduces in 3.8.1 as well.
Comment 1 Jay Arthanareeswaran CLA 2012-12-04 00:13:26 EST
Reproduced with HEAD, and all the way back to 3.6.

I am afraid we won't be able to get to this any time soon. Anyone willing to take this up and post a patch is welcome, though!
Comment 2 Dani Megert CLA 2012-12-04 02:22:50 EST
*** Bug 336228 has been marked as a duplicate of this bug. ***
Comment 3 Daniel Goetten CLA 2014-06-27 02:49:36 EDT
Actually this problem also occurs when using anomynous classes in enumerations

<code>
  private enum SomeEnumeration {
    ERRORS(new SomeInterface() {
            @Override
            public boolean someMethod(final Object params) {
                // No code completion at this point

                return true;
            }
        });
  }
</code>
Comment 4 Holger Voormann CLA 2017-11-25 08:11:13 EST
See also https://stackoverflow.com/q/47481597/6505250
Comment 5 Gayan Perera CLA 2017-11-26 02:38:15 EST
Seems like the org.eclipse.jdt.internal.compiler.parser.Parser.identifierLengthPtr becomes -1 and fails with a AIOBException at line 950 in org.eclipse.jdt.internal.codeassist.complete.CompletionParser.buildMoreCompletionContext(Expression) method on JDT master code base. This happens if you make the array element a anonymous class. Otherwise this value is 0. The value becomes -1 for next element completion regardless where the anonymous class element is in the array initialization.

I can further look into this if some one can help me out figuring logic of K_ARRAY_INITIALIZER parsing.
Comment 6 Holger Voormann CLA 2017-11-26 05:36:35 EST
(In reply to Gayan Perera from comment #5)
It seems to have something to do with the expression and identifier stack.

If adding the following line before line 947 ("pushOnGenericsIdentifiers...")
  if (this.identifierLengthPtr >= 0)
and the following line before line 935 ("this.expressionPtr -= ...")
  if (this.expressionLengthPtr > 0)
the content assist is shown in the example as given by the description of this bug (comment 0).
Comment 7 Gayan Perera CLA 2017-11-26 10:00:59 EST
Your suggested patch doesn't work on the JDT Core master branch. A AIOBE is thrown from the org.eclipse.jdt.internal.codeassist.impl.AssistParser.getTypeReference(int). Seems like the expressions and identifier stack gets wrong with the anonymous class definition {}.
Comment 8 Joachim Raue CLA 2019-10-03 06:58:53 EDT
This is extremely annoying in enums, cf.

public enum Foo {
    A(Integer. // No code completion at this point      );

    private final Integer integer;

    private Foo(Integer integer) {
        this.integer = integer;
    }
}

Bugfix strongly appreciated!
Comment 9 ihave question CLA 2019-10-09 12:08:46 EDT
Confirmed still a bug in enum param list.

public enum Bar {
	FOO(Constants.<no suggestion assist here>), BAR(Constants.<nor here>);
	
	private String foo;
	
	private Bar(String foo) {
		this.foo = foo;
	}
	
	public String getFoo() {
		return foo;
	}
}

I can't think of a reason why the fix would be difficult. Don't forget to vote.
Comment 10 Tomer Meidan CLA 2020-07-15 09:23:33 EDT
Is it possible to fix that already?
Comment 11 Eclipse Genie CLA 2022-10-02 14:57:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 12 Juergen Baier CLA 2022-10-04 01:35:32 EDT
I can confirm that the original bug still exists in 2022-09. Please do not close this bug.