use of com.intellij.codeInsight.completion.scope.JavaCompletionProcessor in project intellij-community by JetBrains.
the class JavaDocCompletionContributor method completeJavadocReference.
@NotNull
private List<LookupElement> completeJavadocReference(PsiElement position, PsiJavaReference ref) {
JavaCompletionProcessor processor = new JavaCompletionProcessor(position, TrueFilter.INSTANCE, JavaCompletionProcessor.Options.CHECK_NOTHING, Conditions.alwaysTrue());
ref.processVariants(processor);
return ContainerUtil.map(processor.getResults(), (completionResult) -> {
LookupElement item = createReferenceLookupItem(completionResult.getElement());
item.putUserData(JavaCompletionUtil.FORCE_SHOW_SIGNATURE_ATTR, Boolean.TRUE);
return item;
});
}
use of com.intellij.codeInsight.completion.scope.JavaCompletionProcessor 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.completion.scope.JavaCompletionProcessor in project intellij-community by JetBrains.
the class CanonicalPsiTypeConverterImpl method getReferences.
public PsiReference[] getReferences(@Nullable PsiType type, String typeText, int startOffsetInText, @NotNull final PsiElement element) {
final ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
assert manipulator != null;
String trimmed = typeText.trim();
int offset = manipulator.getRangeInElement(element).getStartOffset() + startOffsetInText + typeText.indexOf(trimmed);
if (trimmed.startsWith(ARRAY_PREFIX)) {
offset += ARRAY_PREFIX.length();
if (trimmed.endsWith(";")) {
trimmed = trimmed.substring(ARRAY_PREFIX.length(), trimmed.length() - 1);
} else {
trimmed = trimmed.substring(ARRAY_PREFIX.length());
}
}
if (type != null) {
type = type.getDeepComponentType();
}
final boolean isPrimitiveType = type instanceof PsiPrimitiveType;
return new JavaClassReferenceSet(trimmed, element, offset, false, CLASS_REFERENCE_PROVIDER) {
@Override
@NotNull
protected JavaClassReference createReference(int refIndex, @NotNull String subRefText, @NotNull TextRange textRange, boolean staticImport) {
return new JavaClassReference(this, textRange, refIndex, subRefText, staticImport) {
@Override
public boolean isSoft() {
return true;
}
@Override
@NotNull
public JavaResolveResult advancedResolve(final boolean incompleteCode) {
if (isPrimitiveType) {
return new CandidateInfo(element, PsiSubstitutor.EMPTY, false, false, element);
}
return super.advancedResolve(incompleteCode);
}
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
if (processor instanceof JavaCompletionProcessor) {
((JavaCompletionProcessor) processor).setCompletionElements(getVariants());
} else {
super.processVariants(processor);
}
}
@Override
@NotNull
public Object[] getVariants() {
final Object[] variants = super.getVariants();
if (myIndex == 0) {
return ArrayUtil.mergeArrays(variants, PRIMITIVES, ArrayUtil.OBJECT_ARRAY_FACTORY);
}
return variants;
}
};
}
}.getAllReferences();
}
use of com.intellij.codeInsight.completion.scope.JavaCompletionProcessor in project intellij-community by JetBrains.
the class JavaClassReference method processVariants.
@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
if (processor instanceof JavaCompletionProcessor) {
final Map<CustomizableReferenceProvider.CustomizationKey, Object> options = getOptions();
if (options != null && (JavaClassReferenceProvider.EXTEND_CLASS_NAMES.getValue(options) != null || JavaClassReferenceProvider.NOT_INTERFACE.getBooleanValue(options) || JavaClassReferenceProvider.CONCRETE.getBooleanValue(options)) || JavaClassReferenceProvider.CLASS_KIND.getValue(options) != null) {
((JavaCompletionProcessor) processor).setCompletionElements(getVariants());
return;
}
}
PsiScopeProcessor processorToUse = processor;
if (myInStaticImport) {
// allows to complete members
processor.handleEvent(JavaScopeProcessorEvent.CHANGE_LEVEL, null);
} else {
if (isDefinitelyStatic()) {
processor.handleEvent(JavaScopeProcessorEvent.START_STATIC, null);
}
processorToUse = new PsiScopeProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
return !(element instanceof PsiClass || element instanceof PsiPackage) || processor.execute(element, state);
}
@Override
public <V> V getHint(@NotNull Key<V> hintKey) {
return processor.getHint(hintKey);
}
@Override
public void handleEvent(@NotNull Event event, Object associated) {
processor.handleEvent(event, associated);
}
};
}
super.processVariants(processorToUse);
}
use of com.intellij.codeInsight.completion.scope.JavaCompletionProcessor in project intellij-community by JetBrains.
the class JavaCompletionUtil method processJavaQualifiedReference.
private static Set<LookupElement> processJavaQualifiedReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter, JavaCompletionProcessor.Options options, final PrefixMatcher matcher, CompletionParameters parameters) {
final Set<LookupElement> set = new LinkedHashSet<>();
final Condition<String> nameCondition = matcher::prefixMatches;
final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, options, nameCondition);
final PsiType plainQualifier = processor.getQualifierType();
PsiType qualifierType = plainQualifier;
PsiType runtimeQualifier = getQualifierCastType(javaReference, parameters);
if (runtimeQualifier != null) {
PsiType composite = qualifierType == null ? runtimeQualifier : PsiIntersectionType.createIntersection(qualifierType, runtimeQualifier);
PsiElement ctx = createContextWithXxxVariable(element, composite);
javaReference = createReference("xxx.xxx", ctx);
qualifierType = runtimeQualifier;
processor.setQualifierType(qualifierType);
}
javaReference.processVariants(processor);
final PsiTypeLookupItem castItem = runtimeQualifier == null ? null : PsiTypeLookupItem.createLookupItem(runtimeQualifier, (PsiReferenceExpression) javaReference);
final boolean pkgContext = inSomePackage(element);
PsiClass qualifierClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
final boolean honorExcludes = qualifierClass == null || !isInExcludedPackage(qualifierClass, false);
final Set<PsiMember> mentioned = new THashSet<>();
for (CompletionElement completionElement : processor.getResults()) {
for (LookupElement item : createLookupElements(completionElement, javaReference)) {
item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
final Object o = item.getObject();
if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass) o, pkgContext)) {
continue;
}
if (o instanceof PsiMember) {
if (honorExcludes && isInExcludedPackage((PsiMember) o, true)) {
continue;
}
mentioned.add(CompletionUtil.getOriginalOrSelf((PsiMember) o));
}
set.add(highlightIfNeeded(qualifierType, castQualifier(item, castItem, plainQualifier, processor), o, element));
}
}
if (javaReference instanceof PsiJavaCodeReferenceElement) {
PsiElement refQualifier = ((PsiJavaCodeReferenceElement) javaReference).getQualifier();
if (refQualifier == null) {
final StaticMemberProcessor memberProcessor = new JavaStaticMemberProcessor(parameters);
memberProcessor.processMembersOfRegisteredClasses(matcher, (member, psiClass) -> {
if (!mentioned.contains(member) && processor.satisfies(member, ResolveState.initial())) {
set.add(memberProcessor.createLookupElement(member, psiClass, true));
}
});
} else if (refQualifier instanceof PsiSuperExpression && ((PsiSuperExpression) refQualifier).getQualifier() == null) {
set.addAll(SuperCalls.suggestQualifyingSuperCalls(element, javaReference, elementFilter, options, nameCondition));
}
}
return set;
}
Aggregations