Skip to content

Commit

Permalink
Fix for completion of method pointer expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 7, 2017
1 parent 6ebcd26 commit 55ae0f8
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<extension point="org.codehaus.groovy.eclipse.codeassist.completion.completionProposalFilter">
<proposalFilter
name="Mock Filter 1"
proposalFilter="org.codehaus.groovy.eclipse.codeassist.completion.mock.MockProposalFilter1">
proposalFilter="org.codehaus.groovy.eclipse.codeassist.mock.MockProposalFilter1">
<appliesTo
projectNature="org.codehaus.groovy.eclipse.tests.testNature1">
</appliesTo>
</proposalFilter>
<proposalFilter
name="Mock Filter 2"
proposalFilter="org.codehaus.groovy.eclipse.codeassist.completion.mock.MockProposalFilter2">
proposalFilter="org.codehaus.groovy.eclipse.codeassist.mock.MockProposalFilter2">
<appliesTo
projectNature="org.codehaus.groovy.eclipse.tests.testNature1">
</appliesTo>
Expand All @@ -22,13 +22,13 @@
</extension>
<extension point="org.codehaus.groovy.eclipse.codeassist.completion.completionProposalProvider">
<proposalProvider
proposalProvider="org.codehaus.groovy.eclipse.codeassist.completion.mock.MockProposalProvider1">
proposalProvider="org.codehaus.groovy.eclipse.codeassist.mock.MockProposalProvider1">
<appliesTo
projectNature="org.codehaus.groovy.eclipse.tests.testNature1">
</appliesTo>
</proposalProvider>
<proposalProvider
proposalProvider="org.codehaus.groovy.eclipse.codeassist.completion.mock.MockProposalProvider2">
proposalProvider="org.codehaus.groovy.eclipse.codeassist.mock.MockProposalProvider2">
<appliesTo
projectNature="org.codehaus.groovy.eclipse.tests.testNature1">
</appliesTo>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package org.codehaus.groovy.eclipse.codeassist.completion.mock;
/*
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.eclipse.codeassist.mock;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package org.codehaus.groovy.eclipse.codeassist.completion.mock;
/*
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.eclipse.codeassist.mock;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package org.codehaus.groovy.eclipse.codeassist.completion.mock;
/*
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.eclipse.codeassist.mock;

import java.util.List;
import java.util.Set;
Expand All @@ -21,7 +36,6 @@ public static void reset() {
providerCalled = false;
}


public List<IGroovyProposal> getStatementAndExpressionProposals(
ContentAssistContext context, ClassNode completionType,
boolean isStatic, Set<ClassNode> categories) {
Expand All @@ -38,5 +52,4 @@ public List<String> getNewFieldProposals(ContentAssistContext context) {
providerCalled = true;
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package org.codehaus.groovy.eclipse.codeassist.completion.mock;
/*
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.groovy.eclipse.codeassist.mock;

import java.util.List;
import java.util.Set;
Expand All @@ -21,7 +36,6 @@ public static void reset() {
providerCalled = false;
}


public List<IGroovyProposal> getStatementAndExpressionProposals(
ContentAssistContext context, ClassNode completionType,
boolean isStatic, Set<ClassNode> categories) {
Expand All @@ -38,5 +52,4 @@ public List<String> getNewFieldProposals(ContentAssistContext context) {
providerCalled = true;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ abstract class CompletionTestSuite extends GroovyEclipseTestSuite {
}

/**
* Finds the next proposal that matches the passed in name
* Finds the next proposal that matches the passed in name.
*
* @param proposals all proposals
* @param name name to match
* @param isType true if looking for a type proposal
Expand Down Expand Up @@ -132,7 +133,7 @@ abstract class CompletionTestSuite extends GroovyEclipseTestSuite {
}

/**
* Returns the first proposal that matches the criteria passed in
* Returns the first proposal that matches the criteria passed in.
*/
protected ICompletionProposal findFirstProposal(ICompletionProposal[] proposals, String name, boolean isType) {
for (ICompletionProposal proposal : proposals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ConstructorCompletionTests extends CompletionTestSuite {

@Before
void setUp() {
GroovyPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.GROOVY_CONTENT_ASSIST_NOPARENS, false)
GroovyPlugin.default.preferenceStore.setValue(PreferenceConstants.GROOVY_CONTENT_ASSIST_NOPARENS, false)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" def meth(int a, int b) { }\n" +
" def method(int a, int b) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other().meth()", "File", "")
ICompilationUnit unit = addGroovySource("new Other().meth()")

runTest(unit, "meth(", "meth", 2)
}
Expand All @@ -80,7 +80,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" def meth(String d) { }\n" +
" def method(String d) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other().meth()", "File", "")
ICompilationUnit unit = addGroovySource("new Other().meth()")

runTest(unit, "meth(", "meth", 3)
}
Expand All @@ -97,7 +97,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" def meth(String d) { }\n" +
" def method(String d) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other().meth(a)", "File", "")
ICompilationUnit unit = addGroovySource("new Other().meth(a)")

runTest(unit, "meth(", "meth", 3)
}
Expand All @@ -114,7 +114,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" def meth(String d) { }\n" +
" def method(String d) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other().meth(a,b)", "File", "")
ICompilationUnit unit = addGroovySource("new Other().meth(a,b)")

runTest(unit, "meth(a,", "meth", 3)
}
Expand All @@ -126,7 +126,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Other(a) { }\n" +
" Other(int a, int b) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other()", "File", "")
ICompilationUnit unit = addGroovySource("new Other()")

runTest(unit, "Other(", "Other", 2)
}
Expand All @@ -138,7 +138,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Other(a) { }\n" +
" Other(int a, int b) { }\n" +
"}", "Other", "p")
ICompilationUnit unit = addGroovySource("new p.Other()", "File", "")
ICompilationUnit unit = addGroovySource("new p.Other()")

runTest(unit, "Other(", "Other", 2)
}
Expand All @@ -150,7 +150,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Other(a) { }\n" +
" Other(int a, int b) { }\n" +
"}", "Other", "p")
ICompilationUnit unit = addGroovySource("import p.Other\nnew Other()", "File", "")
ICompilationUnit unit = addGroovySource("import p.Other\nnew Other()")

runTest(unit, "Other(", "Other", 2)
}
Expand All @@ -162,7 +162,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Other(a) { }\n" +
" Other(int a, int b) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other(a)", "File", "")
ICompilationUnit unit = addGroovySource("new Other(a)")

runTest(unit, "Other(", "Other", 2)
}
Expand All @@ -174,7 +174,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Other(a) { }\n" +
" Other(int a, int b) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Other(a,b)", "File", "")
ICompilationUnit unit = addGroovySource("new Other(a,b)")

runTest(unit, "Other(a,", "Other", 2)
}
Expand All @@ -190,7 +190,7 @@ final class ContextInformationTests extends CompletionTestSuite {
" Super(String d) { }\n" +
" Super(String d, String e) { }\n" +
"}", "Other", "")
ICompilationUnit unit = addGroovySource("new Super()", "File", "")
ICompilationUnit unit = addGroovySource("new Super()")

runTest(unit, "Super(", "Super", 2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,19 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
}

private ICompilationUnit createJava() {
return addJavaSource(CONTENTS, "Class", "")
return addJavaSource(CONTENTS, "Class")
}

private ICompilationUnit createGroovy() {
return addGroovySource(CONTENTS, "Class", "")
return addGroovySource(CONTENTS, "Class")
}

private ICompilationUnit createGroovyForScript() {
return addGroovySource(SCRIPTCONTENTS, "Script", "")
return addGroovySource(SCRIPTCONTENTS, "Script")
}

private ICompilationUnit createGroovyForClosure() {
return addGroovySource(CLOSURECONTENTS, "Closure", "")
}

private ICompilationUnit createGroovyWithContents(String name, String contents) {
return addGroovySource(contents, name, "")
return addGroovySource(CLOSURECONTENTS, "Closure")
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -144,15 +140,15 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
@Test // GRECLIPSE-1013
void testPopertyVariantOfDGM() {
String contents = "''.toURL().text"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "toURL().t"), GroovyCompletionProposalComputer)
proposalExists(proposals, "text", 1)
}

@Test // GRECLIPSE-1158
void testDateGM() {
String contents = "new Date().toCal"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "toCal"), GroovyCompletionProposalComputer)
proposalExists(proposals, "toCalendar", 1)
}
Expand All @@ -161,7 +157,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
void testProcessGM() {
String contents = "Process p\n" +
"p.get"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "get"), GroovyCompletionProposalComputer)
proposalExists(proposals, "getIn", 1)
}
Expand All @@ -170,7 +166,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
void testEncodingGM() {
String contents = "byte[] p\n" +
"p.encodeBase64"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "encodeBase64"), GroovyCompletionProposalComputer)
proposalExists(proposals, "encodeBase64", 2)
}
Expand All @@ -179,7 +175,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
void testXmlGM() {
String contents = "org.w3c.dom.NodeList p\n" +
"p.iterator"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "iterator"), GroovyCompletionProposalComputer)
proposalExists(proposals, "iterator", 1)
}
Expand All @@ -189,7 +185,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
try {
setDGMFilter("inspect")
String contents = "this.insp"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "insp"), GroovyCompletionProposalComputer)
proposalExists(proposals, "inspect", 0)
setDGMFilter()
Expand All @@ -205,7 +201,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {
try {
setDGMFilter("inspect", "each", "fsafd fdafsd fafds")
String contents = "this.insp"
ICompilationUnit unit = createGroovyWithContents("Script", contents)
ICompilationUnit unit = addGroovySource(contents)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "insp"), GroovyCompletionProposalComputer)
proposalExists(proposals, "inspect", 0)
setDGMFilter()
Expand All @@ -218,7 +214,7 @@ final class DefaultGroovyMethodCompletionTests extends CompletionTestSuite {

@Test // GRECLIPSE-1422
void testNoDups() {
ICompilationUnit unit = createGroovyWithContents("Script", LISTCONTENTS)
ICompilationUnit unit = addGroovySource(LISTCONTENTS)
ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(LISTCONTENTS, "findA"), GroovyCompletionProposalComputer)
// should find 2, not 4. dups removed
proposalExists(proposals, "findAll", 2)
Expand Down
Loading

0 comments on commit 55ae0f8

Please sign in to comment.