use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyInheritorsSearchTest method testDotted.
public void testDotted() throws Exception {
setupProject();
final PyClass pyClass = findClass("A");
Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, true).findAll();
assertEquals(1, inheritors.size());
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyInheritorsSearchTest method findClass.
private PyClass findClass(final String name) {
final Project project = myFixture.getProject();
final Collection<PyClass> classes = PyClassNameIndex.find(name, project, false);
assertEquals(1, classes.size());
return classes.iterator().next();
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyDeclarationRangeHandler method getDeclarationRange.
@NotNull
@Override
public TextRange getDeclarationRange(@NotNull PsiElement container) {
int start = container.getTextRange().getStartOffset();
if (container instanceof PyFunction) {
PyParameterList parameterList = ((PyFunction) container).getParameterList();
return new TextRange(start, parameterList.getTextRange().getEndOffset());
}
if (container instanceof PyClass) {
PyArgumentList argumentList = ((PyClass) container).getSuperClassExpressionList();
if (argumentList != null) {
return new TextRange(start, argumentList.getTextRange().getEndOffset());
}
ASTNode nameNode = ((PyClass) container).getNameNode();
if (nameNode != null) {
return new TextRange(start, nameNode.getStartOffset() + nameNode.getTextLength());
}
}
return container.getTextRange();
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyLineMarkerProvider method collectSlowLineMarkers.
public void collectSlowLineMarkers(@NotNull final List<PsiElement> elements, @NotNull final Collection<LineMarkerInfo> result) {
Set<PyFunction> functions = new HashSet<PyFunction>();
for (PsiElement element : elements) {
if (element instanceof PyClass) {
collectInheritingClasses((PyClass) element, result);
} else if (element instanceof PyFunction) {
functions.add((PyFunction) element);
}
}
collectOverridingMethods(functions, result);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyLineMarkerProvider method collectOverridingMethods.
private static void collectOverridingMethods(final Set<PyFunction> functions, final Collection<LineMarkerInfo> result) {
Set<PyClass> classes = new HashSet<PyClass>();
final MultiMap<PyClass, PyFunction> candidates = new MultiMap<PyClass, PyFunction>();
for (PyFunction function : functions) {
PyClass pyClass = function.getContainingClass();
if (pyClass != null && function.getName() != null) {
classes.add(pyClass);
candidates.putValue(pyClass, function);
}
}
final Set<PyFunction> overridden = new HashSet<PyFunction>();
for (final PyClass pyClass : classes) {
PyClassInheritorsSearch.search(pyClass, true).forEach(inheritor -> {
for (Iterator<PyFunction> it = candidates.get(pyClass).iterator(); it.hasNext(); ) {
PyFunction func = it.next();
if (inheritor.findMethodByName(func.getName(), false, null) != null) {
overridden.add(func);
it.remove();
}
}
return !candidates.isEmpty();
});
if (candidates.isEmpty())
break;
}
for (PyFunction func : overridden) {
result.add(new LineMarkerInfo<PyFunction>(func, func.getTextOffset(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, ourOverridingMethodTooltipProvider, ourOverridingMethodNavigator));
}
}
Aggregations