diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java index f8fbc82bedf4..fda74bc70fe6 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/ConstructorInsertHandler.java @@ -53,7 +53,6 @@ class ConstructorInsertHandler implements InsertHandler CLASS_CONDITION_KEY = ClassConditionKey.create(PsiTypeLookupItem.class); private final boolean myDiamond; + private final int myBracketsCount; private boolean myIndicateAnonymous; - private PsiTypeLookupItem(Object o, @NotNull @NonNls String lookupString, boolean diamond) { + private PsiTypeLookupItem(Object o, @NotNull @NonNls String lookupString, boolean diamond, int bracketsCount) { super(o, lookupString); myDiamond = diamond; + myBracketsCount = bracketsCount; + } + + public PsiType getPsiType() { + Object object = getObject(); + PsiType type = object instanceof PsiType ? (PsiType)object : JavaPsiFacade.getElementFactory(((PsiClass) object).getProject()).createType((PsiClass)object); + for (int i = 0; i < getBracketsCount(); i++) { + type = new PsiArrayType(type); + } + return type; } @@ -119,8 +130,7 @@ public class PsiTypeLookupItem extends LookupItem { } public int getBracketsCount() { - final Integer integer = (Integer)getUserData(BRACKETS_COUNT_ATTR); - return integer == null ? 0 : integer; + return myBracketsCount; } public static PsiTypeLookupItem createLookupItem(@NotNull PsiType type, @Nullable PsiElement context) { @@ -131,18 +141,17 @@ public class PsiTypeLookupItem extends LookupItem { dim++; } - PsiTypeLookupItem item = doCreateItem(type, context); + PsiTypeLookupItem item = doCreateItem(type, context, dim); if (dim > 0) { item.setAttribute(TAIL_TEXT_ATTR, " " + StringUtil.repeat("[]", dim)); item.setAttribute(TAIL_TEXT_SMALL_ATTR, ""); - item.putUserData(BRACKETS_COUNT_ATTR, dim); } item.setAttribute(TYPE, original); return item; } - private static PsiTypeLookupItem doCreateItem(final PsiType type, PsiElement context) { + private static PsiTypeLookupItem doCreateItem(final PsiType type, PsiElement context, int bracketsCount) { if (type instanceof PsiClassType) { PsiClassType.ClassResolveResult classResolveResult = ((PsiClassType)type).resolveGenerics(); final PsiClass psiClass = classResolveResult.getElement(); @@ -169,13 +178,13 @@ public class PsiTypeLookupItem extends LookupItem { } } - PsiTypeLookupItem item = new PsiTypeLookupItem(psiClass, lookupString, diamond); + PsiTypeLookupItem item = new PsiTypeLookupItem(psiClass, lookupString, diamond, bracketsCount); item.setAttribute(SUBSTITUTOR, substitutor); return item; } } - return new PsiTypeLookupItem(type, type.getPresentableText(), false); + return new PsiTypeLookupItem(type, type.getPresentableText(), false, bracketsCount); } @NotNull diff --git a/java/java-impl/src/com/intellij/codeInsight/template/macro/ComponentTypeOfMacro.java b/java/java-impl/src/com/intellij/codeInsight/template/macro/ComponentTypeOfMacro.java index d59cb8668be6..29208b4d579d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/macro/ComponentTypeOfMacro.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/macro/ComponentTypeOfMacro.java @@ -16,15 +16,18 @@ package com.intellij.codeInsight.template.macro; import com.intellij.codeInsight.CodeInsightBundle; -import com.intellij.codeInsight.lookup.LookupItem; import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.PsiTypeLookupItem; import com.intellij.codeInsight.template.*; import com.intellij.psi.PsiArrayType; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiType; +import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class ComponentTypeOfMacro extends Macro { public String getName() { return "componentTypeOf"; @@ -39,12 +42,14 @@ public class ComponentTypeOfMacro extends Macro { LookupElement[] lookupItems = params[0].calculateLookupItems(context); if (lookupItems == null) return null; + List result = CollectionFactory.arrayList(); for (LookupElement element : lookupItems) { - if (element instanceof LookupItem) { - final LookupItem item = (LookupItem)element; - Integer bracketsCount = (Integer)item.getUserData(LookupItem.BRACKETS_COUNT_ATTR); - if (bracketsCount == null) return null; - item.putUserData(LookupItem.BRACKETS_COUNT_ATTR, new Integer(bracketsCount.intValue() - 1)); + PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY); + if (lookupItem != null) { + PsiType psiType = lookupItem.getPsiType(); + if (psiType instanceof PsiArrayType) { + result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType)psiType).getComponentType(), null)); + } } } @@ -65,17 +70,24 @@ public class ComponentTypeOfMacro extends Macro { } PsiExpression expr = MacroUtil.resultToPsiExpression(result, context); - PsiType type; - if (expr == null) { - type = MacroUtil.resultToPsiType(result, context); - } - else{ - type = expr.getType(); - } + PsiType type = expr == null ? MacroUtil.resultToPsiType(result, context) : expr.getType(); if (type instanceof PsiArrayType) { return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject()); } + LookupElement[] elements = params[0].calculateLookupItems(context); + if (elements != null) { + for (LookupElement element : elements) { + PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY); + if (typeLookupItem != null) { + PsiType psiType = typeLookupItem.getPsiType(); + if (psiType instanceof PsiArrayType) { + return new PsiTypeResult(((PsiArrayType)psiType).getComponentType(), context.getProject()); + } + } + } + } + return new PsiElementResult(null); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java index 076428bd32a8..dd9c7ea5193e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java @@ -51,7 +51,6 @@ public class LookupItem extends MutableLookupElement implements Comparable public static final Object TAIL_TEXT_SMALL_ATTR = Key.create("tailTextSmall"); public static final Key FORCE_SHOW_SIGNATURE_ATTR = Key.create("forceShowSignature"); - public static final Key BRACKETS_COUNT_ATTR = Key.create("BRACKETS_COUNT_ATTR"); public static final Object FORCE_QUALIFY = Key.create("FORCE_QUALIFY"); public static final Object SUBSTITUTOR = Key.create("SUBSTITUTOR"); public static final Object TYPE = Key.create("TYPE");