use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyiRelatedItemLineMarkerProvider method collectNavigationMarkers.
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
if (element instanceof PyFunction || element instanceof PyTargetExpression || element instanceof PyClass) {
final PsiElement pythonStub = PyiUtil.getPythonStub((PyElement) element);
if (pythonStub != null) {
result.add(createLineMarkerInfo(element, pythonStub, "Has stub item"));
}
final PsiElement originalElement = PyiUtil.getOriginalElement((PyElement) element);
if (originalElement != null) {
result.add(createLineMarkerInfo(element, originalElement, "Stub for item"));
}
}
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyPathEvaluatorTest method testConstants.
public void testConstants() {
myFixture.configureByText(PythonFileType.INSTANCE, "ROOT_PATH = '/foo'\nTEMPLATES_DIR = os.path.join(ROOT_PATH, 'templates')");
PyFile file = (PyFile) myFixture.getFile();
final PyTargetExpression expression = file.findTopLevelAttribute("TEMPLATES_DIR");
final PyExpression value = expression.findAssignedValue();
final String result = FileUtil.toSystemIndependentName((String) new PyPathEvaluator("").evaluate(value));
assertEquals(result, "/foo/templates");
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyTargetElementEvaluator method getElementByReference.
@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
if ((flags & TargetElementUtil.ELEMENT_NAME_ACCEPTED) == 0) {
return null;
}
final PsiElement element = ref.getElement();
PsiElement result = ref.resolve();
Set<PsiElement> visited = new HashSet<>();
visited.add(result);
while (result instanceof PyReferenceOwner && (result instanceof PyReferenceExpression || result instanceof PyTargetExpression)) {
PsiElement nextResult = ((PyReferenceOwner) result).getReference(PyResolveContext.noImplicits()).resolve();
if (nextResult != null && !visited.contains(nextResult) && PsiTreeUtil.getParentOfType(element, ScopeOwner.class) == PsiTreeUtil.getParentOfType(result, ScopeOwner.class) && (nextResult instanceof PyReferenceExpression || nextResult instanceof PyTargetExpression || nextResult instanceof PyParameter)) {
visited.add(nextResult);
result = nextResult;
} else {
break;
}
}
return result;
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testSubscribedSource.
public void testSubscribedSource() throws Exception {
Map<String, PsiElement> marks = loadTest();
Assert.assertEquals(2, marks.size());
// const -> ref foo -> subscr expr;
PsiElement src = marks.get("<src>").getParent().getParent();
// ident -> target expr
PsiElement dst = marks.get("<dst>").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
PyAssignmentStatement stmt = (PyAssignmentStatement) dst.getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(1, mapping.size());
Pair<PyExpression, PyExpression> pair = mapping.get(0);
Assert.assertEquals(dst, pair.getFirst());
Assert.assertEquals(src, pair.getSecond());
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testSimple.
public void testSimple() throws Exception {
Map<String, PsiElement> marks = loadTest();
Assert.assertEquals(2, marks.size());
// const -> expr;
PsiElement src = marks.get("<src>").getParent();
// ident -> target expr
PsiElement dst = marks.get("<dst>").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
PyAssignmentStatement stmt = (PyAssignmentStatement) dst.getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(1, mapping.size());
Pair<PyExpression, PyExpression> pair = mapping.get(0);
Assert.assertEquals(dst, pair.getFirst());
Assert.assertEquals(src, pair.getSecond());
}
Aggregations