summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-08-31 08:16:23 (EDT)
committerKaren Butzke2012-08-31 08:16:23 (EDT)
commit8e884ee1f86ca2c7512ecac40c74a4db156a09b9 (patch)
treef96df3b621887f9a3b0ae1e8fd131b55e31c4a1b
parentfe2f822e2966f6ca3b37934fc6541746a983164c (diff)
downloadwebtools.dali-8e884ee1f86ca2c7512ecac40c74a4db156a09b9.zip
webtools.dali-8e884ee1f86ca2c7512ecac40c74a4db156a09b9.tar.gz
webtools.dali-8e884ee1f86ca2c7512ecac40c74a4db156a09b9.tar.bz2
Fixed filtering of completion proposals after my recent refactoring -
adding quotes as necessary in the proposal computer itself
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java42
3 files changed, 80 insertions, 9 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
index 093e713..06d8068 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/StringTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -4939,7 +4939,6 @@ public final class StringTools {
*/
private static void convertToJavaStringLiteralOn_(char[] string, StringBuilder sb, int len) {
sb.ensureCapacity(sb.length() + len + 5);
- sb.append(QUOTE);
for (char c : string) {
switch (c) {
case '\b': // backspace
@@ -4971,7 +4970,6 @@ public final class StringTools {
break;
}
}
- sb.append(QUOTE);
}
public static void convertToJavaStringLiteralOn(String string, Writer writer) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
index 85ca7bd..35a3a7a 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java
@@ -25,7 +25,10 @@ import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
+import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.jaxb.core.JaxbProject;
import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin;
import org.eclipse.jpt.jaxb.core.context.java.JavaContextNode;
@@ -113,6 +116,12 @@ public class JaxbJavaCompletionProposalComputer
CompletionContext cc = context.getCoreContext();
+ // the context's "token" is really a sort of "prefix" - it does NOT
+ // correspond to the "start" and "end" we get below...
+ char[] prefix = cc.getToken();
+ Filter<String> filter = this.buildPrefixFilter(prefix);
+ // the token "kind" tells us if we are in a String literal already - CompletionContext.TOKEN_KIND_STRING_LITERAL
+ int tokenKind = cc.getTokenKind();
// the token "start" is the offset of the token's first character
int tokenStart = cc.getTokenStart();
// the token "end" is the offset of the token's last character (yuk)
@@ -123,6 +132,7 @@ public class JaxbJavaCompletionProposalComputer
// System.out.println("token start: " + tokenStart);
// System.out.println("token end: " + tokenEnd);
+// System.out.println("token kind: " + tokenKind);
// String source = cu.getSource();
// String token = source.substring(Math.max(0, tokenStart), Math.min(source.length(), tokenEnd + 1));
// System.out.println("token: =>" + token + "<=");
@@ -131,15 +141,22 @@ public class JaxbJavaCompletionProposalComputer
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
for (JavaContextNode javaNode : javaNodes) {
- for (String proposal : javaNode.getCompletionProposals(context.getInvocationOffset())) {
- // using proposal.length() -1 as cursor position puts the cursor just inside end quotes
- // useful for further content assist if necessary
- proposals.add(new CompletionProposal(proposal, tokenStart, tokenEnd - tokenStart + 1, proposal.length() - 1));
+ for (String proposal : this.getCompletionProposals(javaNode, context.getInvocationOffset(), filter)) {
+ if (tokenKind == CompletionContext.TOKEN_KIND_STRING_LITERAL) {//already quoted
+ proposals.add(new CompletionProposal(proposal, tokenStart, tokenEnd - tokenStart - 1, proposal.length()));
+ }
+ else {//add the quotes
+ proposals.add(new CompletionProposal("\"" + proposal + "\"", tokenStart, tokenEnd - tokenStart + 1, proposal.length() + 2)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
}
return proposals;
}
+ private Iterable<String> getCompletionProposals(JavaContextNode javaNode, int pos, Filter<String> filter) {
+ return new FilteringIterable<String>(javaNode.getCompletionProposals(pos), filter);
+ }
+
private IFile getCorrespondingResource(ICompilationUnit cu) {
try {
return (IFile) cu.getCorrespondingResource();
@@ -162,4 +179,22 @@ public class JaxbJavaCompletionProposalComputer
// do nothing
}
+ private Filter<String> buildPrefixFilter(char[] prefix) {
+ return (prefix == null) ?
+ Filter.Transparent.<String>instance() :
+ new IgnoreCasePrefixFilter(prefix);
+ }
+
+ private static class IgnoreCasePrefixFilter
+ implements Filter<String>
+ {
+ private final String prefix;
+ IgnoreCasePrefixFilter(char[] prefix) {
+ super();
+ this.prefix = new String(prefix);
+ }
+ public boolean accept(String s) {
+ return StringTools.stringStartsWithIgnoreCase(s, this.prefix);
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
index 5afb4eb..2354605 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java
@@ -23,7 +23,10 @@ import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
+import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.jpa.core.JpaFile;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
@@ -113,6 +116,12 @@ public class JpaJavaCompletionProposalComputer
CompletionContext cc = context.getCoreContext();
+ // the context's "token" is really a sort of "prefix" - it does NOT
+ // correspond to the "start" and "end" we get below...
+ char[] prefix = cc.getToken();
+ Filter<String> filter = this.buildPrefixFilter(prefix);
+ // the token "kind" tells us if we are in a String literal already - CompletionContext.TOKEN_KIND_STRING_LITERAL
+ int tokenKind = cc.getTokenKind();
// the token "start" is the offset of the token's first character
int tokenStart = cc.getTokenStart();
// the token "end" is the offset of the token's last character (yuk)
@@ -123,6 +132,7 @@ public class JpaJavaCompletionProposalComputer
// System.out.println("token start: " + tokenStart);
// System.out.println("token end: " + tokenEnd);
+// System.out.println("token kind: " + tokenKind);
// String source = cu.getSource();
// String token = source.substring(Math.max(0, tokenStart), Math.min(source.length(), tokenEnd + 1));
// System.out.println("token: =>" + token + "<=");
@@ -131,13 +141,22 @@ public class JpaJavaCompletionProposalComputer
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
for (JpaStructureNode structureNode : rootStructureNodes) {
- for (String s : ((JavaPersistentType) structureNode).getCompletionProposals(context.getInvocationOffset())) {
- proposals.add(new CompletionProposal(s, tokenStart, tokenEnd - tokenStart + 1, s.length()));
+ for (String s : this.getCompletionProposals((JavaPersistentType) structureNode, context.getInvocationOffset(), filter)) {
+ if (tokenKind == CompletionContext.TOKEN_KIND_STRING_LITERAL) {//already quoted
+ proposals.add(new CompletionProposal(s, tokenStart + 1, tokenEnd - tokenStart - 1, s.length()));
+ }
+ else {//add the quotes
+ proposals.add(new CompletionProposal("\"" + s + "\"", tokenStart, tokenEnd - tokenStart + 1, s.length() + 2)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
}
return proposals;
}
+ private Iterable<String> getCompletionProposals(JavaPersistentType structureNode, int pos, Filter<String> filter) {
+ return new FilteringIterable<String>(structureNode.getCompletionProposals(pos), filter);
+ }
+
private IFile getCorrespondingResource(ICompilationUnit cu) {
try {
return (IFile) cu.getCorrespondingResource();
@@ -163,4 +182,23 @@ public class JpaJavaCompletionProposalComputer
public void sessionEnded() {
// do nothing
}
+
+ private Filter<String> buildPrefixFilter(char[] prefix) {
+ return (prefix == null) ?
+ Filter.Transparent.<String>instance() :
+ new IgnoreCasePrefixFilter(prefix);
+ }
+
+ private static class IgnoreCasePrefixFilter
+ implements Filter<String>
+ {
+ private final String prefix;
+ IgnoreCasePrefixFilter(char[] prefix) {
+ super();
+ this.prefix = new String(prefix);
+ }
+ public boolean accept(String s) {
+ return StringTools.stringStartsWithIgnoreCase(s, this.prefix);
+ }
+ }
}