use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method addSubClasses.
private static void addSubClasses(@NotNull final Project project, @NotNull final SearchScope scope, @NotNull final Set<TypeHierarchyItem> visited, @NotNull final List<TypeHierarchyItem> hierarchyItems, @NotNull final List<DartComponent> components, @NotNull final TypeHierarchyItem currentItem, final boolean addItem) {
if (!visited.add(currentItem)) {
return;
}
if (addItem) {
final Element element = currentItem.getClassElement();
final Location location = element.getLocation();
final DartComponent component = DartHierarchyUtil.findDartComponent(project, location);
if (component != null && isInScope(scope, component)) {
components.add(component);
}
}
for (int subIndex : currentItem.getSubclasses()) {
final TypeHierarchyItem subItem = hierarchyItems.get(subIndex);
addSubClasses(project, scope, visited, hierarchyItems, components, subItem, true);
}
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartDocUtilTest method doTest.
private void doTest(String expectedDoc, String fileContents) {
final int caretOffset = fileContents.indexOf("<caret>");
assertTrue(caretOffset != -1);
final String realContents = fileContents.substring(0, caretOffset) + fileContents.substring(caretOffset + "<caret>".length());
final PsiFile psiFile = myFixture.addFileToProject("test.dart", realContents);
final DartComponent dartComponent = PsiTreeUtil.getParentOfType(psiFile.findElementAt(caretOffset), DartComponent.class);
assertNotNull("target element not found at offset " + caretOffset, dartComponent);
assertEquals(expectedDoc, DartDocUtil.generateDoc(dartComponent));
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method prepare.
private static void prepare(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Ref<VirtualFile> fileRef, @NotNull final Ref<Integer> offsetRef, @NotNull final Ref<DartComponentType> componentTypeRef) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = parameters.getElement();
if (element.getLanguage() != DartLanguage.INSTANCE)
return;
final DartComponentType componentType = DartComponentType.typeOf(element);
if (componentType != DartComponentType.CLASS && componentType != DartComponentType.METHOD && componentType != DartComponentType.OPERATOR) {
return;
}
final DartComponentName componentName = element instanceof DartComponentName ? (DartComponentName) element : element instanceof DartComponent ? ((DartComponent) element).getComponentName() : null;
final VirtualFile file = componentName == null ? null : DartResolveUtil.getRealVirtualFile(componentName.getContainingFile());
if (file != null) {
fileRef.set(file);
offsetRef.set(componentName.getTextRange().getStartOffset());
componentTypeRef.set(componentType);
}
});
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method addSubMembers.
private static void addSubMembers(@NotNull final Project project, @NotNull final SearchScope scope, @NotNull final Set<TypeHierarchyItem> visited, @NotNull final List<TypeHierarchyItem> hierarchyItems, @NotNull final List<DartComponent> components, @NotNull final TypeHierarchyItem currentItem, final boolean addItem) {
if (!visited.add(currentItem)) {
return;
}
if (addItem) {
final Element element = currentItem.getMemberElement();
if (element != null) {
final Location location = element.getLocation();
final DartComponent component = DartHierarchyUtil.findDartComponent(project, location);
if (component != null && isInScope(scope, component)) {
components.add(component);
}
}
}
for (int subIndex : currentItem.getSubclasses()) {
final TypeHierarchyItem subItem = hierarchyItems.get(subIndex);
addSubMembers(project, scope, visited, hierarchyItems, components, subItem, true);
}
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartServerImplementationsMarkerProvider method createMarkerMember.
@NotNull
private static LineMarkerInfo createMarkerMember(@NotNull final DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
final int nameOffset = name.getTextRange().getStartOffset();
return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("method.is.overridden.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
if (items.isEmpty()) {
return;
}
final List<DartComponent> components = DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size()), "Overriding methods of " + name.getName(), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
Aggregations