use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class JavaTemplateUtil method addTypeLookupItem.
public static LookupElement addTypeLookupItem(Set<LookupElement> items, PsiType type) {
final LookupElement item = PsiTypeLookupItem.createLookupItem(type, null);
items.add(item);
item.putUserData(TemplateLookupSelectionHandler.KEY_IN_LOOKUP_ITEM, new JavaTemplateLookupSelectionHandler());
return item;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class JavaReflectionCompletionContributor method addAnnotationClasses.
private static void addAnnotationClasses(@NotNull PsiClass psiClass, boolean isDeclared, @NotNull CompletionResultSet result) {
Set<PsiAnnotation> declaredAnnotations = isDeclared ? ContainerUtil.set(AnnotationUtil.getAllAnnotations(psiClass, false, null, false)) : null;
PsiAnnotation[] annotations = AnnotationUtil.getAllAnnotations(psiClass, true, null, false);
for (PsiAnnotation annotation : annotations) {
PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement != null) {
PsiElement resolved = referenceElement.resolve();
if (resolved instanceof PsiClass) {
PsiClass annotationClass = (PsiClass) resolved;
String className = annotationClass.getName();
if (className != null) {
LookupElement lookupElement = LookupElementBuilder.createWithIcon(annotationClass).withPresentableText(className + ".class").withInsertHandler(JavaReflectionCompletionContributor::handleAnnotationClassInsertion);
if (isDeclared) {
lookupElement = withPriority(lookupElement, declaredAnnotations.contains(annotation));
}
result.addElement(lookupElement);
}
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class JavaClassReference method processPackage.
@NotNull
private LookupElement[] processPackage(@NotNull PsiPackage aPackage) {
final ArrayList<LookupElement> list = ContainerUtil.newArrayList();
final int startOffset = StringUtil.isEmpty(aPackage.getName()) ? 0 : aPackage.getQualifiedName().length() + 1;
final GlobalSearchScope scope = getScope(getJavaContextFile());
for (final PsiPackage subPackage : aPackage.getSubPackages(scope)) {
final String shortName = subPackage.getQualifiedName().substring(startOffset);
if (PsiNameHelper.getInstance(subPackage.getProject()).isIdentifier(shortName)) {
list.add(LookupElementBuilder.create(subPackage).withIcon(subPackage.getIcon(Iconable.ICON_FLAG_VISIBILITY)));
}
}
final List<PsiClass> classes = ContainerUtil.filter(aPackage.getClasses(scope), psiClass -> StringUtil.isNotEmpty(psiClass.getName()));
final Map<CustomizableReferenceProvider.CustomizationKey, Object> options = getOptions();
if (options != null) {
final boolean instantiatable = JavaClassReferenceProvider.INSTANTIATABLE.getBooleanValue(options);
final boolean concrete = JavaClassReferenceProvider.CONCRETE.getBooleanValue(options);
final boolean notInterface = JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(options);
final boolean notEnum = JavaClassReferenceProvider.NOT_ENUM.getBooleanValue(options);
final ClassKind classKind = getClassKind();
for (PsiClass clazz : classes) {
if (isClassAccepted(clazz, classKind, instantiatable, concrete, notInterface, notEnum)) {
list.add(JavaClassNameCompletionContributor.createClassLookupItem(clazz, false));
}
}
} else {
for (PsiClass clazz : classes) {
list.add(JavaClassNameCompletionContributor.createClassLookupItem(clazz, false));
}
}
return list.toArray(new LookupElement[list.size()]);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class FileReferenceCompletionImpl method getFileReferenceCompletionVariants.
@NotNull
@Override
public Object[] getFileReferenceCompletionVariants(final FileReference reference) {
final String s = reference.getText();
if (s != null && s.equals("/")) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem> collector = new CommonProcessors.CollectUniquesProcessor<>();
final PsiElementProcessor<PsiFileSystemItem> processor = new PsiElementProcessor<PsiFileSystemItem>() {
@Override
public boolean execute(@NotNull PsiFileSystemItem fileSystemItem) {
return new FilteringProcessor<>(reference.getFileReferenceSet().getReferenceCompletionFilter(), collector).process(FileReference.getOriginalFile(fileSystemItem));
}
};
List<Object> additionalItems = ContainerUtil.newArrayList();
for (PsiFileSystemItem context : reference.getContexts()) {
for (final PsiElement child : context.getChildren()) {
if (child instanceof PsiFileSystemItem) {
processor.execute((PsiFileSystemItem) child);
}
}
if (context instanceof FileReferenceResolver) {
additionalItems.addAll(((FileReferenceResolver) context).getVariants(reference));
}
}
final FileType[] types = reference.getFileReferenceSet().getSuitableFileTypes();
final THashSet<PsiElement> set = new THashSet<>(collector.getResults(), VARIANTS_HASHING_STRATEGY);
final PsiElement[] candidates = PsiUtilCore.toPsiElementArray(set);
final Object[] variants = new Object[candidates.length + additionalItems.size()];
for (int i = 0; i < candidates.length; i++) {
PsiElement candidate = candidates[i];
Object item = reference.createLookupItem(candidate);
if (item == null) {
item = FileInfoManager.getFileLookupItem(candidate);
}
if (candidate instanceof PsiFile && item instanceof LookupElement && types.length > 0 && ArrayUtil.contains(((PsiFile) candidate).getFileType(), types)) {
item = PrioritizedLookupElement.withPriority((LookupElement) item, Double.MAX_VALUE);
}
variants[i] = item;
}
for (int i = 0; i < additionalItems.size(); i++) {
variants[i + candidates.length] = additionalItems.get(i);
}
if (!reference.getFileReferenceSet().isUrlEncoded()) {
return variants;
}
List<Object> encodedVariants = new ArrayList<>(variants.length + additionalItems.size());
for (int i = 0; i < candidates.length; i++) {
final PsiElement element = candidates[i];
if (element instanceof PsiNamedElement) {
final PsiNamedElement psiElement = (PsiNamedElement) element;
String name = psiElement.getName();
final String encoded = reference.encode(name, psiElement);
if (encoded == null)
continue;
if (!encoded.equals(name)) {
final Icon icon = psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
LookupElementBuilder item = FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
encodedVariants.add(item.withTailText(" (" + name + ")"));
} else {
encodedVariants.add(variants[i]);
}
}
}
encodedVariants.addAll(additionalItems);
return ArrayUtil.toObjectArray(encodedVariants);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class DefaultTextCompletionValueDescriptor method createLookupBuilder.
@NotNull
@Override
public LookupElementBuilder createLookupBuilder(@NotNull T item) {
LookupElementBuilder builder = LookupElementBuilder.create(item, getLookupString(item)).withIcon(getIcon(item));
InsertHandler<LookupElement> handler = createInsertHandler(item);
if (handler != null) {
builder = builder.withInsertHandler(handler);
}
String tailText = getTailText(item);
if (tailText != null) {
builder = builder.withTailText(tailText, true);
}
String typeText = getTypeText(item);
if (typeText != null) {
builder = builder.withTypeText(typeText);
}
return builder;
}
Aggregations