ListTemplate action: do not overwrite prefix-matched template with template

that was found by description
This commit is contained in:
Alexander Zolotov
2014-12-24 19:44:40 +03:00
parent 6eff2e784c
commit 30c60fff7a
4 changed files with 16 additions and 1 deletions
@@ -0,0 +1,5 @@
class A {
public static void main() {
template.with.desc<caret>
}
}
@@ -0,0 +1,5 @@
class A {
public static void main() {
template with description<caret>
}
}
@@ -33,6 +33,7 @@ public class ListTemplateActionTest extends LightCodeInsightFixtureTestCase {
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
addTemplate("simple", "simple template text", "description");
addTemplate("complex key", "complex template text", "");
addTemplate("template.with.desc", "template with description", "desc");
}
private void addTemplate(String key, String text, String description) {
@@ -92,6 +93,10 @@ public class ListTemplateActionTest extends LightCodeInsightFixtureTestCase {
public void testComplexKeyWithNotMatchedPrefixAfterNonJavaCharacter() {
doTest("complex key");
}
public void testTemplateShouldNotBeReplacedByOtherTemplateMatchedByDescription() {
doTest("template.with.desc");
}
private void doTest(@NotNull String lookupText) {
myFixture.configureByFile(getTestName(false) + ".java");
@@ -120,7 +120,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
}
}
if (searchInDescription) {
if (searchInDescription && !matchingTemplates.containsKey(template)) {
String templateDescription = template.getDescription();
if (!prefixWithoutDots.isEmpty() && templateDescription != null && prefixSearchPattern.matcher(templateDescription).matches()) {
matchingTemplates.put(template, prefixWithoutDots);