use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class XsltResolveTest method testResolveIncludedTemplateParam.
public void testResolveIncludedTemplateParam() throws Throwable {
final String name = getTestFileName();
final PsiReference reference = myFixture.getReferenceAtCaretPositionWithAssertion(name + ".xsl", "included.xsl");
final PsiElement element = resolveXsltReference(reference);
assertNotNull("reference did not resolve to XsltElement: " + reference, element);
assertTrue(element instanceof XsltParameter);
assertEquals("foo", ((XsltParameter) element).getName());
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class DeclarationConflictChecker method findDefinitions.
/**
* For each reference in the collection, finds a definition of name visible from the point of the reference. Returns a list of
* such definitions.
* @param name what to look for.
* @param references references to check.
* @param ignored if an element defining the name is also listed here, ignore it.
* @return a list of pairs (referring element, element that defines name).
*/
@NotNull
public static List<Pair<PsiElement, PsiElement>> findDefinitions(@NotNull String name, @NotNull Collection<PsiReference> references, @NotNull Set<PsiElement> ignored) {
final List<Pair<PsiElement, PsiElement>> conflicts = new ArrayList<>();
for (PsiReference ref : references) {
final PsiElement refElement = ref.getElement();
final ScopeOwner owner = ScopeUtil.getScopeOwner(refElement);
if (owner != null) {
for (PsiElement element : PyResolveUtil.resolveLocally(owner, name)) {
if (!ignored.contains(element)) {
conflicts.add(Pair.create(refElement, element));
}
}
}
}
return conflicts;
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class SpecifyTypeInDocstringIntention method doInvoke.
@Override
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
final PyExpression problemElement = getProblemElement(elementAt);
final PsiReference reference = problemElement == null ? null : problemElement.getReference();
final PsiElement resolved = reference != null ? reference.resolve() : null;
final PyNamedParameter parameter = getParameter(problemElement, resolved);
if (parameter != null) {
final PyFunction parentFunction = PsiTreeUtil.getParentOfType(parameter, PyFunction.class);
if (parentFunction != null) {
generateDocstring(parameter, parentFunction);
}
} else {
StreamEx.of(getMultiCallable(elementAt)).select(PyFunction.class).forEach(function -> generateDocstring(null, function));
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class SpecifyTypeInPy3AnnotationsIntention method doInvoke.
@Override
public void doInvoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
final PyExpression problemElement = getProblemElement(elementAt);
final PsiReference reference = problemElement == null ? null : problemElement.getReference();
final PsiElement resolved = reference != null ? reference.resolve() : null;
final PyNamedParameter parameter = getParameter(problemElement, resolved);
if (parameter != null) {
annotateParameter(project, editor, parameter, true);
} else {
StreamEx.of(getMultiCallable(elementAt)).select(PyFunction.class).forEach(function -> annotateReturnType(project, function, true));
}
}
use of com.intellij.psi.PsiReference in project intellij-community by JetBrains.
the class TypeAssertionIntention method isAvailable.
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!(file instanceof PyFile)) {
return false;
}
PsiElement elementAt = PyUtil.findNonWhitespaceAtOffset(file, editor.getCaretModel().getOffset());
PyExpression problemElement = PsiTreeUtil.getParentOfType(elementAt, PyReferenceExpression.class);
if (problemElement == null)
return false;
if (problemElement.getParent() instanceof PyWithItem)
return false;
final PyExpression qualifier = ((PyQualifiedExpression) problemElement).getQualifier();
if (qualifier != null && !qualifier.getText().equals(PyNames.CANONICAL_SELF)) {
problemElement = qualifier;
}
final PsiReference reference = problemElement.getReference();
if (problemElement.getParent() instanceof PyCallExpression || PsiTreeUtil.getParentOfType(problemElement, PyComprehensionElement.class) != null || PsiTreeUtil.getParentOfType(problemElement, PyLambdaExpression.class) != null || PsiTreeUtil.getParentOfType(problemElement, PyGeneratorExpression.class) != null || (reference != null && reference.resolve() == null)) {
return false;
}
final PyType type = TypeEvalContext.codeAnalysis(file.getProject(), file).getType(problemElement);
return type == null;
}
Aggregations