use of com.jetbrains.lang.dart.psi.DartComponentName in project intellij-plugins by JetBrains.
the class DartClassContributor method getItemsByName.
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
final Collection<DartComponentName> result = DartClassIndex.getItemsByName(name, project, scope);
if (result.size() == 0) {
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
}
return result.toArray(new NavigationItem[result.size()]);
}
use of com.jetbrains.lang.dart.psi.DartComponentName 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);
}
use of com.jetbrains.lang.dart.psi.DartComponentName in project intellij-plugins by JetBrains.
the class DartServerImplementationsMarkerProvider method createMarkerClass.
@NotNull
private static LineMarkerInfo createMarkerClass(@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("class.is.subclassed.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.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), ""), "Subclasses of " + name.getName(), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
use of com.jetbrains.lang.dart.psi.DartComponentName in project intellij-plugins by JetBrains.
the class DartClassIndex method getItemsByName.
public static List<DartComponentName> getItemsByName(String name, Project project, GlobalSearchScope searchScope) {
final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(DART_CLASS_INDEX, name, searchScope);
final Set<DartComponentName> result = new THashSet<>();
for (VirtualFile vFile : files) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
for (PsiElement root : DartResolveUtil.findDartRoots(psiFile)) {
for (DartClass component : DartResolveUtil.getClassDeclarations(root)) {
if (name.equals(component.getName())) {
result.add(component.getComponentName());
}
}
}
}
return new ArrayList<>(result);
}
use of com.jetbrains.lang.dart.psi.DartComponentName in project intellij-plugins by JetBrains.
the class DartServerResolverTest method getPresentableElementPosition.
@NotNull
private static String getPresentableElementPosition(@NotNull final CodeInsightTestFixture fixture, @Nullable final PsiElement element) {
if (element == null)
return "";
final StringBuilder buf = new StringBuilder(element.getText());
DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
while (component != null) {
final DartComponentName componentName = component.getComponentName();
if (componentName != null && componentName != element) {
buf.insert(0, component.getName() + " -> ");
}
component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
}
String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath();
final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
if (path.equals(contentRoot))
path = "[content root]";
final String contentRootWithSlash = contentRoot + "/";
path = StringUtil.trimStart(path, contentRootWithSlash);
final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
if (sdk != null && path.startsWith(sdk.getHomePath()))
path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());
if (buf.length() > 0)
buf.insert(0, " -> ");
buf.insert(0, path);
return buf.toString();
}
Aggregations