use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartServerOverrideMarkerProvider method createOverrideMarker.
@Nullable
private static LineMarkerInfo createOverrideMarker(DartComponentName componentName) {
final VirtualFile virtualFile = componentName.getContainingFile().getVirtualFile();
if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
return null;
}
final List<DartServerData.DartOverrideMember> overrideMembers = DartAnalysisServerService.getInstance(componentName.getProject()).getOverrideMembers(virtualFile);
final Project project = componentName.getProject();
final int nameOffset = componentName.getTextRange().getStartOffset();
DartComponent superclassComponent = null;
List<DartComponent> interfaceComponents = Lists.newArrayList();
for (DartServerData.DartOverrideMember overrideMember : overrideMembers) {
if (overrideMember.getOffset() == nameOffset) {
final OverriddenMember member = overrideMember.getSuperclassMember();
superclassComponent = member == null ? null : DartHierarchyUtil.findDartComponent(project, member.getElement().getLocation());
if (overrideMember.getInterfaceMembers() != null) {
for (OverriddenMember overriddenMember : overrideMember.getInterfaceMembers()) {
addDartComponent(interfaceComponents, project, overriddenMember);
}
}
}
}
return tryCreateOverrideMarker(componentName, superclassComponent, interfaceComponents);
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.
@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
if (superclassComponent == null && interfaceComponents.isEmpty()) {
return null;
}
final String name = componentName.getName();
final boolean overrides;
final DartComponent superComponent;
if (superclassComponent != null) {
overrides = true;
superComponent = superclassComponent;
} else {
overrides = false;
superComponent = interfaceComponents.iterator().next();
}
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
if (superClass == null)
return "null";
if (overrides) {
return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
}
return DartBundle.message("implements.method.in", name, superClass.getName());
}, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
List<DartComponent> superComponents = Lists.newArrayList();
if (superclassComponent != null) {
superComponents.add(superclassComponent);
}
superComponents.addAll(interfaceComponents);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.LEFT);
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class BaseCreateMethodsFix method getElementsToProcess.
@NotNull
public Set<T> getElementsToProcess() {
//noinspection unchecked,SuspiciousToArrayCall
final T[] objects = (T[]) elementsToProcess.toArray(new DartComponent[elementsToProcess.size()]);
final Comparator<T> tComparator = Comparator.comparingInt(o -> o.getTextRange().getStartOffset());
final int size = elementsToProcess.size();
final LinkedHashSet<T> result = new LinkedHashSet<>(size);
final List<T> objectsFromSameFile = new ArrayList<>();
PsiFile containingFile = null;
for (int i = 0; i < size; ++i) {
final T object = objects[i];
final PsiFile currentContainingFile = object.getContainingFile();
if (currentContainingFile != containingFile) {
if (containingFile != null) {
Collections.sort(objectsFromSameFile, tComparator);
result.addAll(objectsFromSameFile);
objectsFromSameFile.clear();
}
containingFile = currentContainingFile;
}
objectsFromSameFile.add(object);
}
Collections.sort(objectsFromSameFile, tComparator);
result.addAll(objectsFromSameFile);
elementsToProcess.clear();
elementsToProcess.addAll(result);
return elementsToProcess;
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class BaseDartGenerateHandler method invoke.
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file, final int offset) {
final DartClass dartClass = PsiTreeUtil.getParentOfType(file.findElementAt(offset), DartClassDefinition.class);
if (dartClass == null)
return;
final List<DartComponent> candidates = new ArrayList<>();
collectCandidates(dartClass, candidates);
List<DartNamedElementNode> selectedElements = Collections.emptyList();
if (ApplicationManager.getApplication().isUnitTestMode()) {
selectedElements = ContainerUtil.map(candidates, DartNamedElementNode::new);
} else if (!candidates.isEmpty()) {
final MemberChooser<DartNamedElementNode> chooser = createMemberChooserDialog(project, dartClass, candidates, getTitle());
chooser.show();
if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return;
selectedElements = chooser.getSelectedElements();
}
doInvoke(project, editor, file, selectedElements, createFix(dartClass));
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartCalleeTreeStructure method getCallees.
private static void getCallees(@NotNull PsiElement element, @NotNull List<PsiElement> results) {
DartComponentName name = (DartComponentName) element;
DartComponent decl = (DartComponent) name.getParent();
PsiFile file = decl.getContainingFile();
if (file == null)
return;
VirtualFile vFile = file.getVirtualFile();
List<DartNavigationRegion> navRegions = DartAnalysisServerService.getInstance(element.getProject()).analysis_getNavigation(vFile, decl.getTextOffset(), decl.getTextLength());
if (navRegions == null)
return;
resolveReferences(decl, navRegions, results);
}
Aggregations