use of com.jetbrains.lang.dart.psi.DartClass 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.DartClass in project intellij-plugins by JetBrains.
the class DartNameSuggesterUtil method getSuggestedNames.
public static Collection<String> getSuggestedNames(final DartExpression expression, @Nullable Collection<String> additionalUsedNames) {
Collection<String> candidates = new LinkedHashSet<>();
String text = expression.getText();
if (expression instanceof DartReference) {
DartClass dartClass = ((DartReference) expression).resolveDartClass().getDartClass();
String dartClassName = dartClass == null ? null : dartClass.getName();
if (dartClassName != null && !dartClassName.equals(StringUtil.decapitalize(dartClassName))) {
candidates.add(StringUtil.decapitalize(dartClassName));
}
}
if (expression instanceof DartCallExpression) {
final DartExpression callee = ((DartCallExpression) expression).getExpression();
text = callee.getText();
}
if (text != null) {
candidates.addAll(generateNames(text));
}
final Set<String> usedNames = DartRefactoringUtil.collectUsedNames(expression);
if (additionalUsedNames != null && !additionalUsedNames.isEmpty()) {
usedNames.addAll(additionalUsedNames);
}
final Collection<String> result = new ArrayList<>();
for (String candidate : candidates) {
int index = 0;
String suffix = "";
while (usedNames.contains(candidate + suffix)) {
suffix = Integer.toString(++index);
}
result.add(candidate + suffix);
}
if (result.isEmpty()) {
// never empty
result.add("o");
}
return result;
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartGotoImplementationTest method testIterableSubclasses.
public void testIterableSubclasses() throws Throwable {
myFixture.configureByText("foo.dart", "");
myFixture.doHighlighting();
final DartSdk sdk = DartSdk.getDartSdk(getProject());
assertNotNull(sdk);
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "set.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "string.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "list.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
final DartClass iterableClass = PsiTreeUtil.findChildOfType(getFile(), DartClass.class);
assertNotNull(iterableClass);
assertEquals("Iterable", iterableClass.getName());
getEditor().getCaretModel().moveToOffset(iterableClass.getTextOffset());
final GotoTargetHandler.GotoData data = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), myFixture.getFile());
final List<String> actual = ContainerUtil.map(data.targets, psiElement -> psiElement instanceof PsiNamedElement ? ((PsiNamedElement) psiElement).getName() : psiElement.toString());
// only subclasses from dart:core are known to analyzer at this point
assertSameElements(actual, "List", "Set", "Runes");
}
use of com.jetbrains.lang.dart.psi.DartClass 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.DartClass in project intellij-plugins by JetBrains.
the class DartHierarchyNodeDescriptor method update.
@Override
public boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
if (element == null) {
return invalidElement();
}
final ItemPresentation presentation = element.getPresentation();
if (presentation != null) {
if (element instanceof DartMethodDeclaration) {
if (DartComponentType.typeOf(element) != DartComponentType.CONSTRUCTOR) {
// Do not print constructors as Class.Class.Class(args) Class
final DartClass cls = PsiTreeUtil.getParentOfType(element, DartClass.class);
if (cls != null) {
myHighlightedText.getEnding().addText(cls.getName() + ".");
}
}
}
myHighlightedText.getEnding().addText(presentation.getPresentableText());
PsiFile file = element.getContainingFile();
if (file != null) {
myHighlightedText.getEnding().addText(" (" + file.getName() + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
}
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
Aggregations