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

Missing code assist in method invocation when no closing bracket present #292

Closed
mauromol opened this issue May 15, 2017 · 4 comments
Closed
Assignees

Comments

@mauromol
Copy link

This was the old GRECLIPSE-1796.

Consider the following code:

package a
import static org.junit.Assert.*
import org.junit.After;
import org.junit.Test

final class A {
	MyBean m = new MyBean()

	class MyBean {
		String doSomething(String a, Integer b) {
		}
	}

	@Test final void test() {
		assertNull(m.doSom|
	}
}

Let "|" be the cursor position and invoke code assist there. Please note the missing closing bracket for assertNull(Object) method invocation, which is a common situation while you're typing some new code.
As you can see, in this case no relevant suggestions are given by code assist (only some obscure - for me at least - get@ and set@ proposals are shown). I think this is related to the editor resilience to typing errors (the code is not valid Groovy code until you close the unpaired bracket), however, as I said, this situation is quite common when you're typing some new code. JDT for Java code works well in this situation, in fact.

@eric-milles
Copy link
Member

The @Test final void test() { assertNull(m.doSom } is being parsed into a field def. This is what is tripping up content assist. I'm not too good with Antlr, but I'll see if I can error recover on the incomplete method call assertNull(....

There is error recovery for methodCallArgs, but it is failing to get triggered because argList is failing when it hits the closing brace.

methodCallArgs[AST callee]
    :
        LPAREN!
        al:argList!
        RPAREN!
        { if (callee != null && callee.getFirstChild() != null) {
              //method call like obj.method()
              #methodCallArgs = #(create(METHOD_CALL, "(",callee.getFirstChild(),LT(1)), callee, al);
          } else {
              //method call like method() or new Expr(), in the latter case "callee" is null
              #methodCallArgs = #(create(METHOD_CALL, "(",callee, LT(1)), callee, al);
          }
        }
        // GRECLIPSE add
        exception
        catch [RecognitionException e] {
            if (#al!=null) {
                reportError(e);
                // copy of the block above - lets build it (assuming that all that was missing was the RPAREN)
                if (callee != null && callee.getFirstChild() != null) {
                    //method call like obj.method()
                    #methodCallArgs = #(create(METHOD_CALL,"(",callee.getFirstChild(),LT(1)),callee,al);
                } else {
                    //method call like method() or new Expr(), in the latter case "callee" is null
                    #methodCallArgs = #(create(METHOD_CALL,"(",callee,LT(1)),callee,al);
                }
            } else {
                throw e;
            }
        }
        // GRECLIPSE end
    ;

@eric-milles
Copy link
Member

Can you retest with the latest snapshot?

@mauromol
Copy link
Author

mauromol commented Jun 9, 2017

Sorry, I had no time today, but I will certainly do on Monday! Thanks again and have a nice weekend!

@mauromol
Copy link
Author

Hi Eric, I tested this with some basic use cases (included the one reported here) and it seems to work perfectly fine, thank you! :-)

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

No branches or pull requests

2 participants