use of com.jetbrains.lang.dart.psi.DartComponent 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.DartComponent in project intellij-plugins by JetBrains.
the class DartMethodHierarchyTreeStructure method addAllVisibleSubclasses.
private void addAllVisibleSubclasses(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final TypeHierarchyItem item, @NotNull final DartMethodHierarchyNodeDescriptor descriptor) {
if (!stackItems.add(item)) {
descriptor.setCachedChildren(ArrayUtil.EMPTY_OBJECT_ARRAY);
return;
}
HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
if (state == null)
throw new NullPointerException();
List<DartMethodHierarchyNodeDescriptor> subDescriptors = Lists.newArrayList();
try {
for (int index : item.getSubclasses()) {
final TypeHierarchyItem subItem = items.get(index);
final DartClass subclass = findDartClass(project, subItem);
if (subclass != null) {
final DartMethodHierarchyNodeDescriptor subDescriptor = new DartMethodHierarchyNodeDescriptor(project, descriptor, subclass, false, this);
subDescriptors.add(subDescriptor);
addAllVisibleSubclasses(stackItems, project, items, subItem, subDescriptor);
}
}
DartClass dartClass = findDartClass(project, item);
assert dartClass != null;
String methodName = getBaseMethod().getName();
if (methodName != null) {
DartComponent method = dartClass.findMethodByName(methodName);
if (method != null) {
DartClass definingClass = PsiTreeUtil.getParentOfType(method, DartClass.class);
if (definingClass == dartClass) {
descriptor.myIsImplementor = true;
} else {
descriptor.myShouldImplement = method.isAbstract() && !dartClass.isAbstract();
}
}
}
for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
if (subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor) {
descriptor.myIsSuperclassOfImplementor = true;
break;
}
}
if (state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED) {
List<DartMethodHierarchyNodeDescriptor> toRemove = Lists.newArrayList();
for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
if (!(subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor)) {
toRemove.add(subDescriptor);
}
}
subDescriptors.removeAll(toRemove);
}
} finally {
stackItems.remove(item);
}
descriptor.setCachedChildren(subDescriptors.toArray(new HierarchyNodeDescriptor[subDescriptors.size()]));
}
use of com.jetbrains.lang.dart.psi.DartComponent 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();
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartGenericSpecialization method getGenericKey.
public static String getGenericKey(@Nullable PsiElement element, @NotNull String genericName) {
final StringBuilder result = new StringBuilder();
final DartComponent dartComponent = PsiTreeUtil.getParentOfType(element, DartComponent.class, false);
if (dartComponent instanceof DartClass) {
result.append(dartComponent.getName());
} else if (dartComponent != null) {
DartClass dartClass = PsiTreeUtil.getParentOfType(dartComponent, DartClass.class);
if (dartClass != null) {
result.append(dartClass.getName());
}
if (PsiTreeUtil.getChildOfType(dartComponent, DartTypeArguments.class) != null) {
// generic method
result.append(":");
result.append(dartComponent.getName());
}
}
if (result.length() > 0) {
result.append("-");
}
result.append(genericName);
return result.toString();
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class CreateNamedConstructorFix method buildFunctionsText.
protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
template.setToReformat(true);
//noinspection ConstantConditions
template.addTextSegment(myDartClass.getName());
template.addTextSegment(".");
template.addVariable(new TextExpression("name"), true);
template.addTextSegment("(");
for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
DartComponent component = iterator.next();
template.addTextSegment("this.");
//noinspection ConstantConditions
template.addTextSegment(component.getName());
if (iterator.hasNext()) {
template.addTextSegment(",");
}
}
template.addTextSegment(");");
template.addEndVariable();
// trailing space is removed when auto-reformatting, but it helps to enter line break if needed
template.addTextSegment(" ");
return template;
}
Aggregations