Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No code assist on map-style constructor call for property values #409

Closed
mauromol opened this issue Jan 9, 2018 · 3 comments
Closed

No code assist on map-style constructor call for property values #409

mauromol opened this issue Jan 9, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@mauromol
Copy link

mauromol commented Jan 9, 2018

Consider the following:

package test16;
public class MyBean {
	private String foo;
	private String bar;
	public String getFoo() {
		return foo;
	}
	public String getBar() {
		return bar;
	}
}

And the following Groovy class:

package test16
class Test16 {
  void doSomething() {
	  def bean1 = new MyBean()
	  def bean2 = new MyBean(foo: bea|)
  }
}

Invoke code assist at "|", with the purpose of writing bean1.foo: as you can see, no proposal is shown, apart from generic proposals for class names.

@eric-milles eric-milles added this to the v3.0.0 milestone Jan 9, 2018
@eric-milles
Copy link
Member

There's some tension between this and #331. The argument expression is matched and flows through the catch block below. To try and provide named argument proposals, the conditional if (context.location != ContentAssistLocation.STATEMENT) was added.

    public void visitConstructorCallExpression(ConstructorCallExpression expression) {
        if (!check(expression)) {
            return;
        }

        Expression arguments = expression.getArguments();
        checkForAfterClosingParen(expression, arguments);
        ClassNode constructorType = expression.getType();

        if (check(constructorType)) {
            createContext(constructorType, blockStack.getLast(), ContentAssistLocation.CONSTRUCTOR);
        }

        try {
            // see comments in visitMethodCallExpression
            visitArguments(arguments, expression);
        } catch (VisitCompleteException e) {
            if (context.location != ContentAssistLocation.STATEMENT) {
                throw e;
            }
            // completing constructor argument (https://github.com/groovy/groovy-eclipse/issues/331)
        }

        // completion invocation offset is outside of type name and argument expressions; it is probably after opening paren or separating comma

        createContextForCallContext(expression, constructorType, constructorType.getUnresolvedName());
    }

@eric-milles
Copy link
Member

ready to test

@mauromol
Copy link
Author

I confirm this use case works with 3.0.0.xx-201802132346-e47, thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants