Skip to content
Browse files

Fix for GRECLIPSE-269 content assist in multiline strings

  • Loading branch information...
1 parent b379410 commit b656156353564761370e8d555bf38cf6a583dd57 @aeisenberg aeisenberg committed Feb 4, 2013
View
34 ...tion.test/src/org/codehaus/groovy/eclipse/codeassist/tests/GroovyLikeCompletionTests.java
@@ -375,6 +375,40 @@ public void testNamedArguments3() throws Exception {
GroovyPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.GROOVY_CONTENT_NAMED_ARGUMENTS, false);
}
+ // GRECLIPSE-268
+ // disabled because groovy will parse the following as an empty constant expression
+ public void _testGString1() throws Exception {
+ ICompilationUnit unit = create("\"\"\"\"\"\"");
+ fullBuild();
+ ICompletionProposal[] proposals = performContentAssist(unit, "\"\"\"".length(), GroovyCompletionProposalComputer.class);
+ assertEquals("Should not have found any proposals, but found:\n" + printProposals(proposals), 0, proposals.length);
+ }
+
+ // GRECLIPSE-268
+ public void testGString2() throws Exception {
+ ICompilationUnit unit = create("\"\"\"${this}\"\"\"");
+ fullBuild();
+ ICompletionProposal[] proposals = performContentAssist(unit, "\"\"\"".length(), GroovyCompletionProposalComputer.class);
+ assertEquals("Should not have found any proposals, but found:\n" + printProposals(proposals), 0, proposals.length);
+ }
+
+ // GRECLIPSE-268
+ public void testGString3() throws Exception {
+ ICompilationUnit unit = create("\"\"\"this\"\"\"");
+ fullBuild();
+ ICompletionProposal[] proposals = performContentAssist(unit, "\"\"\"this".length(), GroovyCompletionProposalComputer.class);
+ assertEquals("Should not have found any proposals, but found:\n" + printProposals(proposals), 0, proposals.length);
+ }
+
+ // GRECLIPSE-268
+ public void testGString4() throws Exception {
+ String contents = "def flarb;\n\"\"\"${flarb}\"\"\"";
+ ICompilationUnit unit = create(contents);
+ fullBuild();
+ ICompletionProposal[] proposals = performContentAssist(unit, getIndexOf(contents, "${flarb"), GroovyCompletionProposalComputer.class);
+ checkReplacementString(proposals, "flarb", 1);
+ }
+
private ICompilationUnit createGroovy() throws Exception {
return createGroovy("GroovyLikeCompletions", SCRIPTCONTENTS);
}
View
4 ide/org.codehaus.groovy.eclipse.codeassist.completion/plugin.xml
@@ -39,6 +39,10 @@
<partition
type="__java_string">
</partition>
+ <!-- this is not an error, pde does not recognize this as a valid partition type -->
+ <partition
+ type="__groovy_multiline_string">
+ </partition>
</javaCompletionProposalComputer>
</extension>
<extension
View
16 ...completion/src/org/codehaus/groovy/eclipse/codeassist/requestor/CompletionNodeFinder.java
@@ -56,6 +56,7 @@
import org.codehaus.groovy.ast.expr.DeclarationExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.FieldExpression;
+import org.codehaus.groovy.ast.expr.GStringExpression;
import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.ast.expr.MapExpression;
import org.codehaus.groovy.ast.expr.MethodCallExpression;
@@ -775,6 +776,21 @@ public void visitMapExpression(MapExpression expression) {
}
}
+ @Override
+ public void visitGStringExpression(GStringExpression expression) {
+ visitListOfExpressions(expression.getValues());
+
+ // now check to see if we are in a string
+ List<ConstantExpression> strings = expression.getStrings();
+ for (ConstantExpression stringExpr : strings) {
+ if (doTest(stringExpr)) {
+ // inside of a string, no completions available
+ context = null;
+ throw new VisitCompleteException();
+ }
+ }
+ }
+
/**
* @param expression
* @return true iff this expression is an argument in the enclosing ALE

0 comments on commit b656156

Please sign in to comment.
Something went wrong with that request. Please try again.