Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jaxb
diff options
context:
space:
mode:
authorKaren Butzke2012-09-05 17:05:28 -0400
committerKaren Butzke2012-09-06 10:05:19 -0400
commitd1074325f2fb45d2d996ca555f40b09533a11d30 (patch)
tree97aadf18683a3fdab7de3b012b89ec949147926c /jaxb
parent310c14b5db2728dce4d42f103b2c1935a3445d64 (diff)
downloadwebtools.dali-d1074325f2fb45d2d996ca555f40b09533a11d30.tar.gz
webtools.dali-d1074325f2fb45d2d996ca555f40b09533a11d30.tar.xz
webtools.dali-d1074325f2fb45d2d996ca555f40b09533a11d30.zip
Correctly fixed java code completion filtering
Diffstat (limited to 'jaxb')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java8
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/xpath/java/XPath.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/JaxbJavaCompletionProposalComputer.java43
10 files changed, 52 insertions, 17 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java
index f98a1f8b81..f63c8da31c 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java
@@ -757,7 +757,7 @@ public class GenericJavaClassMapping
}
protected Iterable<String> getPropProposals() {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<JaxbPersistentAttribute, String>(getAllLocallyDefinedAttributes()) {
@Override
protected String transform(JaxbPersistentAttribute o) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java
index 2d30d4d855..25ef901619 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java
@@ -128,7 +128,7 @@ public class GenericJavaXmlNs
protected Iterable<String> getNamespaceURICompletionProposals(int pos) {
String packageNamespace = getJaxbPackageInfo().getJaxbPackage().getNamespace();
Iterable<String> result = (StringTools.stringIsEmpty(packageNamespace)) ?
- EmptyIterable.instance() : new SingleElementIterable(StringTools.convertToJavaStringLiteral(packageNamespace));
+ EmptyIterable.instance() : new SingleElementIterable(StringTools.convertToJavaStringLiteralContent(packageNamespace));
XsdSchema schema = getJaxbPackageInfo().getJaxbPackage().getXsdSchema();
if (schema != null) {
result = new CompositeIterable<String>(result, schema.getNamespaceProposals());
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
index fa57eba990..f078f68bef 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlSchema.java
@@ -272,7 +272,7 @@ public class GenericJavaXmlSchema
}
protected Iterable<String> getNamespaceProposals() {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<SchemaEntry, String>(
getJaxbProject().getSchemaLibrary().getSchemaEntries()) {
@Override
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
index fc98c5565e..b23b2fdc03 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSchema.java
@@ -180,11 +180,11 @@ public class XsdSchema
}
public Iterable<String> getNamespaceProposals() {
- return StringTools.convertToJavaStringLiterals(getNamespaces());
+ return StringTools.convertToJavaStringLiteralContents(getNamespaces());
}
public Iterable<String> getTypeNameProposals(String namespace) {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<XsdTypeDefinition, String>(this.getTypeDefinitions(namespace)) {
@Override
protected String transform(XsdTypeDefinition o) {
@@ -194,7 +194,7 @@ public class XsdSchema
}
public Iterable<String> getSimpleTypeNameProposals(String namespace) {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<XsdSimpleTypeDefinition, String>(this.getSimpleTypeDefinitions(namespace)) {
@Override
protected String transform(XsdSimpleTypeDefinition o) {
@@ -204,7 +204,7 @@ public class XsdSchema
}
public Iterable<String> getElementNameProposals(String namespace) {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<XsdElementDeclaration, String>(this.getElementDeclarations(namespace)) {
@Override
protected String transform(XsdElementDeclaration o) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java
index ab70c88271..320a18f87d 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdSimpleTypeDefinition.java
@@ -95,7 +95,7 @@ public class XsdSimpleTypeDefinition
}
public Iterable<String> getEnumValueProposals() {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<XSDEnumerationFacet, String>(getXSDComponent().getEnumerationFacets()) {
@Override
protected String transform(XSDEnumerationFacet enumFacet) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java
index 05ad2a3297..155ffe4bfa 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/xsd/XsdTypeDefinition.java
@@ -67,7 +67,7 @@ public abstract class XsdTypeDefinition<A extends XSDTypeDefinition>
public abstract XsdAttributeUse getAttribute(String namespace, String name);
public Iterable<String> getAttributeNameProposals(String namespace) {
- return StringTools.convertToJavaStringLiterals(getAttributeNames(namespace));
+ return StringTools.convertToJavaStringLiteralContents(getAttributeNames(namespace));
}
public abstract Iterable<String> getAttributeNames(String namespace);
@@ -83,7 +83,7 @@ public abstract class XsdTypeDefinition<A extends XSDTypeDefinition>
}
public Iterable<String> getElementNameProposals(String namespace, boolean recurseChildren) {
- return StringTools.convertToJavaStringLiterals(getElementNames(namespace, recurseChildren));
+ return StringTools.convertToJavaStringLiteralContents(getElementNames(namespace, recurseChildren));
}
public abstract Iterable<String> getElementNames(String namespace, boolean recurseChildren);
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java
index 45c9b856ee..da7158ff8d 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java
@@ -146,7 +146,7 @@ public class ELJavaXmlInverseReferenceMapping
return EmptyIterable.instance();
}
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<JaxbPersistentAttribute, String>(referencedClassMapping.getAllLocallyDefinedAttributes()) {
@Override
protected String transform(JaxbPersistentAttribute o) {
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java
index 132b5c56d0..62309ef3a0 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java
@@ -155,7 +155,7 @@ public class ELJavaXmlJoinNode
if (referencedClassMapping != null) {
result = new CompositeIterable<String>(
result,
- StringTools.convertToJavaStringLiterals(referencedClassMapping.getKeyXPaths()));
+ StringTools.convertToJavaStringLiteralContents(referencedClassMapping.getKeyXPaths()));
}
return CollectionTools.sortedSet(result);
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/xpath/java/XPath.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/xpath/java/XPath.java
index 18e581d9f3..37ea63fe52 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/xpath/java/XPath.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/xpath/java/XPath.java
@@ -495,7 +495,7 @@ public class XPath {
final String prefix, int pos) {
if (getTextRange(context).includes(pos) || getNextStep() == null) {
- return StringTools.convertToJavaStringLiterals(
+ return StringTools.convertToJavaStringLiteralContents(
new TransformationIterable<String, String>(
new CompositeIterable<String>(
getTextProposals(context, previousType),
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 85ca7bd50e..35a3a7a773 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);
+ }
+ }
}

Back to the top