diff --git a/ide-test/org.codehaus.groovy.eclipse.codeassist.completion.test/src/org/codehaus/groovy/eclipse/codeassist/tests/MethodCompletionTests.groovy b/ide-test/org.codehaus.groovy.eclipse.codeassist.completion.test/src/org/codehaus/groovy/eclipse/codeassist/tests/MethodCompletionTests.groovy index 338c81ac75..bd10d59cf9 100644 --- a/ide-test/org.codehaus.groovy.eclipse.codeassist.completion.test/src/org/codehaus/groovy/eclipse/codeassist/tests/MethodCompletionTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.codeassist.completion.test/src/org/codehaus/groovy/eclipse/codeassist/tests/MethodCompletionTests.groovy @@ -15,7 +15,9 @@ */ package org.codehaus.groovy.eclipse.codeassist.tests +import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isParrotParser import static org.junit.Assert.fail +import static org.junit.Assume.assumeTrue import org.codehaus.groovy.ast.ClassNode import org.codehaus.groovy.ast.MethodNode @@ -469,30 +471,70 @@ final class MethodCompletionTests extends CompletionTestSuite { '''.stripIndent()) } + @Test + void testMethodPointer0() { + String contents = 'class Foo { public static Foo instance }\nFoo.&in' + proposalExists(createProposalsAtOffset(contents, getLastIndexOf(contents, 'in')), 'instance', 0) + } + + @Test + void testMethodPointer0a() { + String contents = 'class Foo { public static Foo instance }\nFoo::in' + proposalExists(createProposalsAtOffset(contents, getLastIndexOf(contents, 'in')), 'instance', 0) + } + @Test void testMethodPointer1() { String contents = 'String.&isE' applyProposalAndCheck(checkUniqueProposal(contents, 'isE', 'isEmpty'), contents + 'mpty') } + @Test + void testMethodPointer1a() { + assumeTrue(isParrotParser()) + String contents = 'String::isE' + applyProposalAndCheck(checkUniqueProposal(contents, 'isE', 'isEmpty'), contents + 'mpty') + } + @Test void testMethodPointer2() { String contents = 'String.& isE' applyProposalAndCheck(checkUniqueProposal(contents, 'isE', 'isEmpty'), contents + 'mpty') } + @Test + void testMethodPointer2a() { + assumeTrue(isParrotParser()) + String contents = 'String:: isE' + applyProposalAndCheck(checkUniqueProposal(contents, 'isE', 'isEmpty'), contents + 'mpty') + } + @Test void testMethodPointer3() { String contents = 'String.&isEmpty.mem' applyProposalAndCheck(checkUniqueProposal(contents, 'mem', 'memoize()'), contents + 'oize()') } + @Test + void testMethodPointer3a() { + assumeTrue(isParrotParser()) + String contents = 'String::isEmpty.mem' + applyProposalAndCheck(checkUniqueProposal(contents, 'mem', 'memoize()'), contents + 'oize()') + } + @Test void testMethodPointer4() { String contents = '(String.&isEmpty).mem' applyProposalAndCheck(checkUniqueProposal(contents, 'mem', 'memoize()'), contents + 'oize()') } + @Test + void testMethodPointer4a() { + assumeTrue(isParrotParser()) + String contents = '(String::isEmpty).mem' + applyProposalAndCheck(checkUniqueProposal(contents, 'mem', 'memoize()'), contents + 'oize()') + } + @Test void testAnnotatedMethod1() { String contents = '''\ diff --git a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/ProposalUtils.java b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/ProposalUtils.java index bce4f02d1d..f9065f92be 100644 --- a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/ProposalUtils.java +++ b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/ProposalUtils.java @@ -40,8 +40,6 @@ import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry; import org.eclipse.jdt.ui.text.java.CompletionProposalLabelProvider; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.viewers.StyledString; import org.eclipse.swt.graphics.Image; @@ -306,25 +304,4 @@ public static boolean hasWhitespace(char[] chars) { } return false; } - - /** Checks '.&' operator before replacement offset. */ - public static boolean isMethodPointerCompletion(IDocument document, int replacementOffset) { - try { - boolean seenAmpersand = false; - while (--replacementOffset > 0) { - char c = document.getChar(replacementOffset); - if (Character.isJavaIdentifierPart(c) || (!Character.isWhitespace(c) && c != '&' && c != '.')) break; - if (c == '&') { - if (seenAmpersand) break; - seenAmpersand = true; - } else if (c == '.') { - if (seenAmpersand) - return true; - break; - } - } - } catch (BadLocationException ignore) { - } - return false; - } } diff --git a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/processors/StatementAndExpressionCompletionProcessor.java b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/processors/StatementAndExpressionCompletionProcessor.java index 405dc3ad8d..fab1af6905 100644 --- a/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/processors/StatementAndExpressionCompletionProcessor.java +++ b/ide/org.codehaus.groovy.eclipse.codeassist.completion/src/org/codehaus/groovy/eclipse/codeassist/processors/StatementAndExpressionCompletionProcessor.java @@ -577,5 +577,5 @@ private List chooseProposalCreators() { } public static final Pattern FIELD_ACCESS_COMPLETION = Pattern.compile(".+\\.@\\s*(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)?", Pattern.DOTALL); - public static final Pattern METHOD_POINTER_COMPLETION = Pattern.compile(".+\\.&\\s*(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)?", Pattern.DOTALL); + public static final Pattern METHOD_POINTER_COMPLETION = Pattern.compile(".+(\\.&|::)\\s*(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)?", Pattern.DOTALL); } diff --git a/ide/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/util/TokenStream.java b/ide/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/util/TokenStream.java index c2d532e774..e845fdfd1a 100644 --- a/ide/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/util/TokenStream.java +++ b/ide/org.codehaus.groovy.eclipse.core/src/org/codehaus/groovy/eclipse/core/util/TokenStream.java @@ -151,6 +151,13 @@ public Token next() throws TokenStreamException { last = new Token(Token.Type.METHOD_POINTER, offset + 1, offset + 3, buffer.subSequence(offset + 1, offset + 3).toString()); } break; + case ':': + nextChar(); + if (ch == ':') { + nextChar(); + last = new Token(Token.Type.METHOD_POINTER, offset + 1, offset + 3, buffer.subSequence(offset + 1, offset + 3).toString()); + } + break; case ';': nextChar(); last = new Token(Token.Type.SEMI, offset + 1, offset + 2, buffer.subSequence(offset + 1, offset + 2).toString());