use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class LookupUi method addListeners.
private void addListeners() {
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (myLookup.isLookupDisposed())
return;
myHintAlarm.cancelAllRequests();
final LookupElement item = myLookup.getCurrentItem();
if (item != null) {
updateHint(item);
}
}
});
final Alarm alarm = new Alarm(myLookup);
myScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
if (myLookup.myUpdating || myLookup.isLookupDisposed())
return;
alarm.addRequest(() -> myLookup.refreshUi(false, false), 300, myModalityState);
}
});
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class EncodingReference method getVariants.
@Override
@NotNull
public Object[] getVariants() {
Charset[] charsets = CharsetToolkit.getAvailableCharsets();
List<LookupElement> suggestions = new ArrayList<>(charsets.length);
for (Charset charset : charsets) {
suggestions.add(LookupElementBuilder.create(charset.name()).withCaseSensitivity(false));
}
return suggestions.toArray(new LookupElement[suggestions.size()]);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class ComponentTypeOfMacro method calculateLookupItems.
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
if (params.length != 1)
return null;
LookupElement[] lookupItems = params[0].calculateLookupItems(context);
if (lookupItems == null)
return null;
List<LookupElement> result = ContainerUtil.newArrayList();
for (LookupElement element : lookupItems) {
PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
if (lookupItem != null) {
PsiType psiType = lookupItem.getType();
if (psiType instanceof PsiArrayType) {
result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType) psiType).getComponentType(), null));
}
}
}
return lookupItems;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class ComponentTypeOfMacro method calculateResult.
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
if (params.length != 1)
return null;
final Result result = params[0].calculateResult(context);
if (result == null)
return null;
if (result instanceof PsiTypeResult) {
PsiType type = ((PsiTypeResult) result).getType();
if (type instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
}
}
PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
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.getType();
if (psiType instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) psiType).getComponentType(), context.getProject());
}
}
}
}
return new PsiElementResult(null);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class SubtypesMacro method calculateLookupItems.
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
if (params.length == 0)
return LookupElement.EMPTY_ARRAY;
Result paramResult = params[0].calculateQuickResult(context);
if (paramResult instanceof PsiTypeResult) {
final PsiType type = ((PsiTypeResult) paramResult).getType();
final PsiFile file = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(context.getEditor().getDocument());
final PsiElement element = file.findElementAt(context.getStartOffset());
final Set<LookupElement> set = new LinkedHashSet<>();
JavaTemplateUtil.addTypeLookupItem(set, type);
CodeInsightUtil.processSubTypes(type, element, false, PrefixMatcher.ALWAYS_TRUE, psiType -> JavaTemplateUtil.addTypeLookupItem(set, psiType));
return set.toArray(new LookupElement[set.size()]);
}
return LookupElement.EMPTY_ARRAY;
}
Aggregations