use of com.jetbrains.python.psi.resolve.RatedResolveResult in project intellij-community by JetBrains.
the class ResolveResultList method poke.
// Allows to add non-null elements and discard nulls in a hassle-free way.
public boolean poke(final PsiElement what, final int rate) {
PyPsiUtils.assertValid(what);
if (what == null)
return false;
if (!(what instanceof LightElement) && !what.isValid()) {
throw new PsiInvalidElementAccessException(what, "Trying to resolve a reference to an invalid element");
}
super.add(new RatedResolveResult(rate, what));
return true;
}
use of com.jetbrains.python.psi.resolve.RatedResolveResult in project intellij-community by JetBrains.
the class PyClassTypeImpl method resolveInner.
@NotNull
private static List<? extends RatedResolveResult> resolveInner(@NotNull PyClass cls, boolean isDefinition, @NotNull String name, @Nullable PyExpression location) {
final PyResolveProcessor processor = new PyResolveProcessor(name);
final Collection<PsiElement> result;
if (!isDefinition && !cls.processInstanceLevelDeclarations(processor, location)) {
result = processor.getElements();
} else {
cls.processClassLevelDeclarations(processor);
result = processor.getElements();
}
return ContainerUtil.map(result, element -> new RatedResolveResult(RatedResolveResult.RATE_NORMAL, element));
}
use of com.jetbrains.python.psi.resolve.RatedResolveResult in project intellij-community by JetBrains.
the class PyClassTypeImpl method resolveMetaClassMember.
@Nullable
private List<? extends RatedResolveResult> resolveMetaClassMember(@NotNull String name, @Nullable PyExpression location, @NotNull AccessDirection direction, @NotNull PyResolveContext resolveContext) {
final TypeEvalContext context = resolveContext.getTypeEvalContext();
if (!myClass.isNewStyleClass(context)) {
return null;
}
final PyClassLikeType typeType = getMetaClassType(context, true);
if (typeType == null) {
return null;
}
if (isDefinition()) {
final List<? extends RatedResolveResult> typeMembers = typeType.resolveMember(name, location, direction, resolveContext);
if (!ContainerUtil.isEmpty(typeMembers)) {
return typeMembers;
}
final List<? extends RatedResolveResult> typeInstanceMembers = typeType.toInstance().resolveMember(name, location, direction, resolveContext);
if (!ContainerUtil.isEmpty(typeInstanceMembers)) {
return typeInstanceMembers;
}
} else if (typeType instanceof PyClassType) {
final List<PyTargetExpression> typeInstanceAttributes = ((PyClassType) typeType).getPyClass().getInstanceAttributes();
if (!ContainerUtil.isEmpty(typeInstanceAttributes)) {
final List<RatedResolveResult> typeInstanceAttributesWithSpecifiedName = typeInstanceAttributes.stream().filter(member -> name.equals(member.getName())).map(member -> new RatedResolveResult(PyReferenceImpl.getRate(member, context), member)).collect(Collectors.toList());
if (!typeInstanceAttributesWithSpecifiedName.isEmpty()) {
return typeInstanceAttributesWithSpecifiedName;
}
}
}
return null;
}
Aggregations