diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java b/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java index 92613ecd4baa..1b7b2dcfc05e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/CastingLookupElementDecorator.java @@ -9,7 +9,6 @@ import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiType; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -18,14 +17,6 @@ import org.jetbrains.annotations.Nullable; public class CastingLookupElementDecorator extends LookupElementDecorator implements TypedLookupItem { private final LookupElement myCastItem; private final PsiType myCastType; - private static final LookupElementVisagiste CASTING_VISAGISTE = new LookupElementVisagiste() { - @Override - public void applyCosmetics(@NotNull CastingLookupElementDecorator item, @NotNull LookupElementPresentation base) { - final String castType = getItemText(base, item.getCastItem()); - base.setItemText("(" + castType + ")" + base.getItemText()); - base.setTypeText(castType); - } - }; @Nullable private static String getItemText(LookupElementPresentation base, LookupElement castItem) { @@ -49,6 +40,13 @@ public class CastingLookupElementDecorator extends LookupElementDecorator implements TypedLookupItem { private final LookupElement myQualifier; - private static final LookupElementVisagiste CHAINING_VISAGISTE = new LookupElementVisagiste() { - @Override - public void applyCosmetics(@NotNull JavaChainLookupElement item, @NotNull LookupElementPresentation base) { - final LookupElementPresentation qualifierPresentation = new LookupElementPresentation(base.isReal()); - item.myQualifier.renderElement(qualifierPresentation); - String name = item.maybeAddParentheses(qualifierPresentation.getItemText()); - final String qualifierText = item.myQualifier.as(CastingLookupElementDecorator.class) != null ? "(" + name + ")" : name; - base.setItemText(qualifierText + "." + base.getItemText()); - } - }; private JavaChainLookupElement(LookupElement qualifier, LookupElement main) { super(main); @@ -65,6 +55,16 @@ public class JavaChainLookupElement extends LookupElementDecorator highlight(LookupElement decorator) { - return LookupElementDecorator.decorate(decorator, new LookupElementVisagiste() { + return LookupElementDecorator.withRenderer(decorator, new LookupElementRenderer>() { @Override - public void applyCosmetics(@NotNull LookupElement item, @NotNull LookupElementPresentation base) { - base.setItemTextBold(true); + public void renderElement(LookupElementDecorator element, LookupElementPresentation presentation) { + element.getDelegate().renderElement(presentation); + presentation.setItemTextBold(true); } }); } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java index 18c831dc8d5b..d8bbf47a6a8e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaSmartCompletionContributor.java @@ -313,7 +313,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor { for (PsiClassType ref : method.getThrowsList().getReferencedTypes()) { final PsiClass exception = ref.resolve(); if (exception != null && throwsSet.add(exception)) { - result.addElement(TailTypeDecorator.createDecorator(new JavaPsiClassReferenceElement(exception).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE)); + result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE)); } } } @@ -331,7 +331,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor { if (tryBlock == null) return; for (final PsiClassType type : ExceptionUtil.getThrownExceptions(tryBlock.getStatements())) { - result.addElement(TailTypeDecorator.createDecorator(PsiTypeLookupItem.createLookupItem(type).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE)); + result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type).setInsertHandler(new DefaultInsertHandler()), TailType.SPACE)); } } }); @@ -377,7 +377,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor { PsiUtil.getLanguageLevel(context)); if (substitution != null && substitution != PsiType.NULL) { final LookupItem item = PsiTypeLookupItem.createLookupItem(substitution); - resultSet.addElement(TailTypeDecorator.createDecorator(item.setInsertHandler(new DefaultInsertHandler()), tail)); + resultSet.addElement(TailTypeDecorator.withTail(item.setInsertHandler(new DefaultInsertHandler()), tail)); } } } @@ -393,7 +393,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor { final PsiClass psiClass = PsiUtil.resolveClassInType(type); if (psiClass == null) return; - resultSet.addElement(TailTypeDecorator.createDecorator(new JavaPsiClassReferenceElement(psiClass).setInsertHandler(new DefaultInsertHandler()), tail)); + resultSet.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(psiClass).setInsertHandler(new DefaultInsertHandler()), tail)); } }, resultSet.getPrefixMatcher()); diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/SameSignatureCallParametersProvider.java b/java/java-impl/src/com/intellij/codeInsight/completion/SameSignatureCallParametersProvider.java index aee9a2917e84..8d401f2f880a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/SameSignatureCallParametersProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/SameSignatureCallParametersProvider.java @@ -66,7 +66,7 @@ class SameSignatureCallParametersProvider extends CompletionProvider> getSuperMethodCandidates(PsiReferenceExpression expression) { diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java index f6187e21cdce..615542341c36 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java @@ -108,7 +108,7 @@ public abstract class LookupElementDecorator extends Lo } @NotNull - public static LookupElementDecorator decorate(@NotNull final T element, @NotNull final LookupElementVisagiste visagiste) { + public static LookupElementDecorator withRenderer(@NotNull final T element, @NotNull final LookupElementRenderer> visagiste) { return new VisagisteDecorator(element, visagiste); } @@ -153,19 +153,16 @@ public abstract class LookupElementDecorator extends Lo } private static class VisagisteDecorator extends LookupElementDecorator { - private final T myElement; - private final LookupElementVisagiste myVisagiste; + private final LookupElementRenderer> myVisagiste; - public VisagisteDecorator(T element, LookupElementVisagiste visagiste) { + public VisagisteDecorator(T element, LookupElementRenderer> visagiste) { super(element); - myElement = element; myVisagiste = visagiste; } @Override public void renderElement(final LookupElementPresentation presentation) { - getDelegate().renderElement(presentation); - myVisagiste.applyCosmetics(getDelegate(), presentation); + myVisagiste.renderElement(this, presentation); } @Override @@ -176,7 +173,6 @@ public abstract class LookupElementDecorator extends Lo VisagisteDecorator that = (VisagisteDecorator)o; - if (!myElement.equals(that.myElement)) return false; if (!myVisagiste.getClass().equals(that.myVisagiste.getClass())) return false; return true; @@ -185,7 +181,6 @@ public abstract class LookupElementDecorator extends Lo @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + myElement.hashCode(); result = 31 * result + myVisagiste.getClass().hashCode(); return result; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java index 5067658d56f8..e5a06c62fe6c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/WordCompletionContributor.java @@ -46,7 +46,7 @@ public class WordCompletionContributor extends CompletionContributor implements character().javaIdentifierPart().andNot(character().equalTo('$')), character().javaIdentifierStart())); for (final String word : AllWordsGetter.getAllWords(insertedElement, startOffset)) { - final LookupElement item = TailTypeDecorator.createDecorator(LookupElementBuilder.create(word), TailType.SPACE); + final LookupElement item = TailTypeDecorator.withTail(LookupElementBuilder.create(word), TailType.SPACE); javaResultSet.addElement(item); plainResultSet.addElement(item); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/TailTypeDecorator.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/TailTypeDecorator.java index eb9fdb136fca..8cbff0df9f49 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/TailTypeDecorator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/TailTypeDecorator.java @@ -29,7 +29,7 @@ public abstract class TailTypeDecorator extends LookupE super(delegate); } - public static TailTypeDecorator createDecorator(T element, final TailType type) { + public static TailTypeDecorator withTail(T element, final TailType type) { return new TailTypeDecorator(element) { @Override protected TailType computeTailType(InsertionContext context) { diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java index 116cf39769b2..39387dbbff53 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/TagNameReference.java @@ -166,7 +166,7 @@ public class TagNameReference implements PsiReference { } protected static LookupElement createClosingTagLookupElement(XmlTag tag) { - return TailTypeDecorator.createDecorator(LookupElementBuilder.create(tag.getName()).setAutoCompletionPolicy( + return TailTypeDecorator.withTail(LookupElementBuilder.create(tag.getName()).setAutoCompletionPolicy( AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE), TailType.createSimpleTailType('>')); }