use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class JavaConstructorCallElement method markClassItemWrapped.
private void markClassItemWrapped(@NotNull LookupElement classItem) {
LookupElement delegate = classItem;
while (true) {
delegate.putUserData(WRAPPING_CONSTRUCTOR_CALL, this);
if (!(delegate instanceof LookupElementDecorator))
break;
delegate = ((LookupElementDecorator) delegate).getDelegate();
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class JavaGenerateMemberCompletionContributor method addGetterSetterElements.
private static void addGetterSetterElements(CompletionResultSet result, PsiClass parent, Set<MethodSignature> addedSignatures) {
int count = 0;
for (PsiField field : parent.getFields()) {
if (field instanceof PsiEnumConstant)
continue;
List<PsiMethod> prototypes = ContainerUtil.newSmartList();
Collections.addAll(prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, true));
Collections.addAll(prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, false));
for (final PsiMethod prototype : prototypes) {
if (parent.findMethodBySignature(prototype, false) == null && addedSignatures.add(prototype.getSignature(PsiSubstitutor.EMPTY))) {
Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY);
result.addElement(createGenerateMethodElement(prototype, PsiSubstitutor.EMPTY, icon, "", new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
removeLookupString(context);
insertGenerationInfos(context, Collections.singletonList(new PsiGenerationInfo<>(prototype)));
}
}));
if (count++ > 100)
return;
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class SmartCompletionDecorator method computeTailType.
@Override
protected TailType computeTailType(InsertionContext context) {
if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
return TailType.NONE;
}
if (LookupItem.getDefaultTailType(context.getCompletionChar()) != null) {
return null;
}
LookupElement delegate = getDelegate();
LookupItem item = as(LookupItem.CLASS_CONDITION_KEY);
Object object = delegate.getObject();
if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && (object instanceof PsiMethod || object instanceof PsiClass)) {
return TailType.NONE;
}
final PsiExpression enclosing = PsiTreeUtil.getContextOfType(myPosition, PsiExpression.class, true);
if (enclosing != null) {
final PsiType type = JavaCompletionUtil.getLookupElementType(delegate);
final TailType itemType = item != null ? item.getTailType() : TailType.NONE;
if (type != null && type.isValid()) {
Set<TailType> voidTyped = new HashSet<>();
Set<TailType> sameTyped = new HashSet<>();
Set<TailType> assignableTyped = new HashSet<>();
for (ExpectedTypeInfo info : myExpectedTypeInfos) {
final PsiType infoType = info.getType();
final PsiType originalInfoType = JavaCompletionUtil.originalize(infoType);
if (PsiType.VOID.equals(infoType)) {
voidTyped.add(info.getTailType());
} else if (infoType.equals(type) || originalInfoType.equals(type)) {
sameTyped.add(info.getTailType());
} else if ((info.getKind() == ExpectedTypeInfo.TYPE_OR_SUBTYPE && (infoType.isAssignableFrom(type) || originalInfoType.isAssignableFrom(type))) || (info.getKind() == ExpectedTypeInfo.TYPE_OR_SUPERTYPE && (type.isAssignableFrom(infoType) || type.isAssignableFrom(originalInfoType)))) {
assignableTyped.add(info.getTailType());
}
}
if (!sameTyped.isEmpty()) {
return sameTyped.size() == 1 ? sameTyped.iterator().next() : itemType;
}
if (!assignableTyped.isEmpty()) {
return assignableTyped.size() == 1 ? assignableTyped.iterator().next() : itemType;
}
if (!voidTyped.isEmpty()) {
return voidTyped.size() == 1 ? voidTyped.iterator().next() : itemType;
}
} else {
if (myExpectedTypeInfos.size() == 1) {
return myExpectedTypeInfos.iterator().next().getTailType();
}
}
return itemType;
}
return null;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class SuperCalls method suggestQualifyingSuperCalls.
static Set<LookupElement> suggestQualifyingSuperCalls(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter, JavaCompletionProcessor.Options options, Condition<String> nameCondition) {
Set<LookupElement> set = ContainerUtil.newLinkedHashSet();
for (final String className : getContainingClassNames(element)) {
PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element);
PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement());
JavaCompletionProcessor superProcessor = new JavaCompletionProcessor(leaf, elementFilter, options, nameCondition);
fakeSuper.processVariants(superProcessor);
for (CompletionElement completionElement : superProcessor.getResults()) {
for (LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference)) {
set.add(withQualifiedSuper(className, item));
}
}
}
return set;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class XmlBasicToClassNameDelegator method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiFile file = position.getContainingFile();
if (parameters.getCompletionType() != CompletionType.BASIC || !JavaCompletionContributor.mayStartClassName(result) || !file.getLanguage().isKindOf(StdLanguages.XML)) {
return;
}
final boolean empty = result.runRemainingContributors(parameters, true).isEmpty();
if (!empty && parameters.getInvocationCount() == 0) {
result.restartCompletionWhenNothingMatches();
}
if (empty && JavaClassReferenceCompletionContributor.findJavaClassReference(file, parameters.getOffset()) != null || parameters.isExtendedCompletion()) {
CompletionService.getCompletionService().getVariantsFromContributors(parameters.delegateToClassName(), null, completionResult -> {
LookupElement lookupElement = completionResult.getLookupElement();
JavaPsiClassReferenceElement classElement = lookupElement.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
if (classElement != null) {
classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
}
lookupElement.putUserData(XmlCompletionContributor.WORD_COMPLETION_COMPATIBLE, Boolean.TRUE);
result.passResult(completionResult);
});
}
}
Aggregations