Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoopur Gupta2016-02-25 13:46:49 +0000
committerNoopur Gupta2016-02-26 05:41:05 +0000
commit2e96c2b8506f407b3220551a72308ec19956b26d (patch)
treec09b1279daf6b0a605988abe24c77be5a0dde8e2
parent44be58ff209190498eb7ab23a1f3138a56efc6ba (diff)
downloadeclipse.jdt.ui-2e96c2b8506f407b3220551a72308ec19956b26d.tar.gz
eclipse.jdt.ui-2e96c2b8506f407b3220551a72308ec19956b26d.tar.xz
eclipse.jdt.ui-2e96c2b8506f407b3220551a72308ec19956b26d.zip
Fixed bug 487668 - [content assist] Substring completion still breaks
proposal sorting Change-Id: I0865fc42dc119dca586c7fd2ed6828ca6bea3a7b Signed-off-by: Noopur Gupta <noopur_gupta@in.ibm.com>
-rw-r--r--org.eclipse.jdt.ui/plugin.xml6
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java2
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractTemplateCompletionProposalComputer.java4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java35
4 files changed, 32 insertions, 15 deletions
diff --git a/org.eclipse.jdt.ui/plugin.xml b/org.eclipse.jdt.ui/plugin.xml
index 72471b6f2e..1f68bdf55d 100644
--- a/org.eclipse.jdt.ui/plugin.xml
+++ b/org.eclipse.jdt.ui/plugin.xml
@@ -367,7 +367,8 @@
id="TemplateProposalComputer">
<javaCompletionProposalComputer
class="org.eclipse.jdt.internal.ui.text.java.TemplateCompletionProposalComputer"
- categoryId="org.eclipse.jdt.ui.templateProposalCategory">
+ categoryId="org.eclipse.jdt.ui.templateProposalCategory"
+ needsSortingAfterFiltering="true">
<partition type="__dftl_partition_content_type"/>
<partition type="__java_singleline_comment"/> <!-- to get NLS templates -->
<partition type="__java_javadoc"/>
@@ -378,7 +379,8 @@
id="swtBuilderCompletionProposalComputer">
<javaCompletionProposalComputer
class="org.eclipse.jdt.internal.ui.text.java.SWTTemplateCompletionProposalComputer"
- categoryId="org.eclipse.jdt.ui.swtProposalCategory">
+ categoryId="org.eclipse.jdt.ui.swtProposalCategory"
+ needsSortingAfterFiltering="true">
<partition type="__dftl_partition_content_type"/>
</javaCompletionProposalComputer>
</extension>
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
index 44b2bdf06e..c3e8ad8bfd 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
@@ -845,7 +845,7 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
@Override
public int getRelevance() {
if (fPatternMatchRule == SearchPattern.R_SUBSTRING_MATCH) {
- return fRelevance - 1;
+ return fRelevance - 400;
}
return fRelevance;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractTemplateCompletionProposalComputer.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractTemplateCompletionProposalComputer.java
index fac4bc8429..24f1232c4c 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractTemplateCompletionProposalComputer.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractTemplateCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 2016 IBM Corporation and others.
* 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
@@ -79,7 +79,7 @@ public abstract class AbstractTemplateCompletionProposalComputer implements IJav
*/
for (int k= 0; k < templateProposals.length; k++) {
TemplateProposal curr= templateProposals[k];
- String name= curr.getTemplate().getPattern();
+ String name= curr.getTemplate().getName();
for (int i= 0; i < keyWordResults.length; i++) {
String keyword= keyWordResults[i].getDisplayString();
if (name.startsWith(keyword)) {
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java
index 2ac07cc4c6..5fe0502b02 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/template/contentassist/TemplateProposal.java
@@ -96,6 +96,7 @@ public class TemplateProposal
private final Image fImage;
private final IRegion fRegion;
private int fRelevance;
+ private boolean fIsSubstringMatch;
private IRegion fSelectedRegion; // initialized by apply()
private StyledString fDisplayString;
@@ -140,19 +141,24 @@ public class TemplateProposal
final int R_INLINE_TAG = 31;
int base= R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED;
-
+ boolean isSubstring= false;
try {
if (fContext instanceof DocumentTemplateContext) {
DocumentTemplateContext templateContext= (DocumentTemplateContext) fContext;
IDocument document= templateContext.getDocument();
String content= document.get(fRegion.getOffset(), fRegion.getLength());
- if (content.length() > 0 && fTemplate.getName().startsWith(content))
+ String templateName= fTemplate.getName();
+ if (content.length() > 0 && templateName.startsWith(content))
base += R_CASE;
- if (fTemplate.getName().equalsIgnoreCase(content))
+ if (templateName.equalsIgnoreCase(content))
base += R_EXACT_NAME;
if (fContext instanceof JavaDocContext)
base += R_INLINE_TAG;
+
+ String templateNameLC= templateName.toLowerCase();
+ String contentLC= content.toLowerCase();
+ isSubstring= content.length() > 0 && !templateNameLC.startsWith(contentLC) && templateNameLC.contains(contentLC);
}
} catch (BadLocationException e) {
// ignore - not a case sensitive match then
@@ -161,7 +167,8 @@ public class TemplateProposal
// see CompletionProposalCollector.computeRelevance
// just under keywords, but better than packages
final int TEMPLATE_RELEVANCE= 1;
- return base * 16 + TEMPLATE_RELEVANCE;
+ int rel= base * 16 + TEMPLATE_RELEVANCE;
+ return isSubstring ? rel - 400 : rel;
}
/**
@@ -556,7 +563,7 @@ public class TemplateProposal
*/
@Override
public int getRelevance() {
- return fRelevance;
+ return fIsSubstringMatch ? fRelevance - 400 : fRelevance;
}
public void setRelevance(int relevance) {
@@ -602,12 +609,20 @@ public class TemplateProposal
String content= document.get(replaceOffset, offset - replaceOffset).toLowerCase();
String templateName= fTemplate.getName().toLowerCase();
boolean isSubstringEnabled= JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_SUBSTRING_MATCH));
- boolean valid= isSubstringEnabled ? templateName.contains(content) : templateName.startsWith(content);
+ boolean valid= false;
+ fIsSubstringMatch= false;
+ if (templateName.startsWith(content)) {
+ valid= true;
+ } else if (isSubstringEnabled && templateName.contains(content)) {
+ valid= true;
+ fIsSubstringMatch= true;
+ }
if (!valid && fContext instanceof JavaDocContext && templateName.startsWith("<")) { //$NON-NLS-1$
- if (isSubstringEnabled) {
- valid= CharOperation.substringMatch(content.indexOf('<') == 0 ? content.substring(1) : content, templateName.substring(1));
- } else {
- valid= templateName.startsWith(content, 1);
+ if (templateName.startsWith(content, 1)) {
+ valid= true;
+ } else if (isSubstringEnabled && CharOperation.substringMatch(content.indexOf('<') == 0 ? content.substring(1) : content, templateName.substring(1))) {
+ valid= true;
+ fIsSubstringMatch= true;
}
}
return valid;

Back to the top