use of com.jetbrains.python.psi.PyTypedElement in project intellij-community by JetBrains.
the class PyiTypeTest method doTest.
private void doTest(@NotNull String expectedType) {
myFixture.copyDirectoryToProject("pyi/type/" + getTestName(true), "");
myFixture.copyDirectoryToProject("typing", "");
PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments();
final String fileName = getTestName(false) + ".py";
myFixture.configureByFile(fileName);
final PsiElement element = myFixture.getElementAtCaret();
assertNotNull("Could not find element at caret in: " + myFixture.getFile());
assertInstanceOf(element, PyTypedElement.class);
final PyTypedElement typedElement = (PyTypedElement) element;
final Project project = element.getProject();
final PsiFile containingFile = element.getContainingFile();
assertType(expectedType, typedElement, TypeEvalContext.codeAnalysis(project, containingFile));
assertType(expectedType, typedElement, TypeEvalContext.userInitiated(project, containingFile));
}
use of com.jetbrains.python.psi.PyTypedElement in project intellij-community by JetBrains.
the class PyIterableVariableMacro method getIterableElements.
@NotNull
protected List<PsiNamedElement> getIterableElements(@NotNull PsiElement element) {
final TypeEvalContext typeEvalContext = TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile());
final List<PsiNamedElement> components = new ArrayList<>();
for (PsiNamedElement namedElement : getVisibleNamedElements(element)) {
if (namedElement instanceof PyTypedElement) {
final PyType type = typeEvalContext.getType((PyTypedElement) namedElement);
if (type != null && PyABCUtil.isSubtype(type, PyNames.ITERABLE, typeEvalContext)) {
components.add(namedElement);
}
}
}
return components;
}
Aggregations