use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method getInnerClassesForResolve.
@NotNull
private static List<PsiClass> getInnerClassesForResolve(@NotNull final GrTypeDefinition grType, @Nullable final PsiElement lastParent, @NotNull final PsiElement place) {
if (lastParent instanceof GrReferenceList || PsiTreeUtil.getParentOfType(place, GrReferenceList.class) != null) {
return Arrays.asList(grType.getCodeInnerClasses());
}
boolean includeSynthetic = !PsiTreeUtil.isContextAncestor(grType, place, true);
Object key = Trinity.create(grType, lastParent, place);
List<PsiClass> classes = RecursionManager.doPreventingRecursion(key, false, () -> {
List<PsiClass> result = new ArrayList<>();
for (CandidateInfo info : CollectClassMembersUtil.getAllInnerClasses(grType, includeSynthetic).values()) {
final PsiClass inner = (PsiClass) info.getElement();
final PsiClass containingClass = inner.getContainingClass();
assert containingClass != null;
if (lastParent == null || !containingClass.isInterface() || PsiTreeUtil.isAncestor(containingClass, place, false)) {
ContainerUtil.addIfNotNull(result, inner);
}
}
return result;
});
if (classes == null) {
return Arrays.asList(grType.getCodeInnerClasses());
}
return classes;
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method findInnerClassByName.
@Nullable
public static PsiClass findInnerClassByName(GrTypeDefinition grType, String name, boolean checkBases) {
if (!checkBases) {
for (PsiClass inner : grType.getInnerClasses()) {
if (name.equals(inner.getName()))
return inner;
}
return null;
} else {
Map<String, CandidateInfo> innerClasses = CollectClassMembersUtil.getAllInnerClasses(grType, true);
final CandidateInfo info = innerClasses.get(name);
return info == null ? null : (PsiClass) info.getElement();
}
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class CollectClassMembersUtil method addMethod.
private static void addMethod(@NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
String name = method.getName();
List<CandidateInfo> methods = allMethods.get(name);
if (methods == null) {
methods = new ArrayList<>();
allMethods.put(name, methods);
}
methods.add(new CandidateInfo(method, substitutor));
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class CollectClassMembersUtil method processClass.
private static void processClass(@NotNull PsiClass aClass, @NotNull Map<String, CandidateInfo> allFields, @NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull Map<String, CandidateInfo> allInnerClasses, @NotNull Set<PsiClass> visitedClasses, @NotNull PsiSubstitutor substitutor, boolean includeSynthetic) {
PsiUtilCore.ensureValid(aClass);
if (!visitedClasses.add(aClass))
return;
if (visitedClasses.size() == 1 || !GrTraitUtil.isTrait(aClass)) {
for (PsiField field : getFields(aClass, includeSynthetic)) {
String name = field.getName();
if (!allFields.containsKey(name)) {
allFields.put(name, new CandidateInfo(field, substitutor));
} else if (hasExplicitVisibilityModifiers(field)) {
final CandidateInfo candidateInfo = allFields.get(name);
final PsiElement element = candidateInfo.getElement();
if (element instanceof GrField) {
final GrModifierList modifierList = ((GrField) element).getModifierList();
if ((modifierList == null || !modifierList.hasExplicitVisibilityModifiers()) && aClass == ((GrField) element).getContainingClass()) {
//replace property-field with field with explicit visibilityModifier
allFields.put(name, new CandidateInfo(field, substitutor));
}
}
}
}
}
for (PsiMethod method : getMethods(aClass, includeSynthetic)) {
addMethod(allMethods, method, substitutor);
}
for (final PsiClass inner : getInnerClasses(aClass, includeSynthetic)) {
final String name = inner.getName();
if (name != null && !allInnerClasses.containsKey(name)) {
allInnerClasses.put(name, new CandidateInfo(inner, substitutor));
}
}
for (PsiClass superClass : getSupers(aClass, includeSynthetic)) {
final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, substitutor);
processClass(superClass, allFields, allMethods, allInnerClasses, visitedClasses, superSubstitutor, includeSynthetic);
}
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class ReferenceExpressionCompletionContributor method completeFinalReference.
static Set<LookupElement> completeFinalReference(final PsiElement element, PsiJavaCodeReferenceElement reference, ElementFilter filter, final JavaSmartCompletionParameters parameters) {
final Set<PsiField> used = parameters.getParameters().getInvocationCount() < 2 ? findConstantsUsedInSwitch(element) : Collections.<PsiField>emptySet();
final Set<LookupElement> elements = JavaSmartCompletionContributor.completeReference(element, reference, new AndFilter(filter, new ElementFilter() {
@Override
public boolean isAcceptable(Object o, PsiElement context) {
if (o instanceof CandidateInfo) {
final CandidateInfo info = (CandidateInfo) o;
final PsiElement member = info.getElement();
final PsiType expectedType = parameters.getExpectedType();
if (expectedType.equals(PsiType.VOID)) {
return member instanceof PsiMethod;
}
//noinspection SuspiciousMethodCalls
if (member instanceof PsiEnumConstant && used.contains(CompletionUtil.getOriginalOrSelf(member))) {
return false;
}
return AssignableFromFilter.isAcceptable(member, element, expectedType, info.getSubstitutor());
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}), false, true, parameters.getParameters(), PrefixMatcher.ALWAYS_TRUE);
for (LookupElement lookupElement : elements) {
if (lookupElement.getObject() instanceof PsiMethod) {
final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
if (item != null) {
final PsiMethod method = (PsiMethod) lookupElement.getObject();
if (SmartCompletionDecorator.hasUnboundTypeParams(method, parameters.getExpectedType())) {
item.setInferenceSubstitutor(SmartCompletionDecorator.calculateMethodReturnTypeSubstitutor(method, parameters.getExpectedType()), element);
}
}
}
}
return elements;
}
Aggregations