use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartMethodHierarchyNodeDescriptor method update.
public final boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
DartClass dartClass = getType();
if (dartClass == null) {
if (!myHighlightedText.getText().startsWith(INVALID_PREFIX)) {
myHighlightedText.getBeginning().addText(INVALID_PREFIX, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
}
return true;
}
final ItemPresentation presentation = dartClass.getPresentation();
Icon baseIcon = null;
Icon stateIcon = null;
if (presentation != null) {
myHighlightedText.getEnding().addText(presentation.getPresentableText());
PsiFile file = dartClass.getContainingFile();
if (file != null) {
myHighlightedText.getEnding().addText(" (" + file.getName() + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
}
baseIcon = presentation.getIcon(false);
stateIcon = calculateStateIcon(dartClass);
}
if (changes || baseIcon != myRawIcon || stateIcon != myStateIcon) {
changes = true;
Icon newIcon = myRawIcon = baseIcon;
myStateIcon = stateIcon;
if (myIsBase) {
final LayeredIcon icon = new LayeredIcon(2);
icon.setIcon(newIcon, 0);
newIcon = icon;
icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
}
if (myStateIcon != null) {
newIcon = new RowIcon(myStateIcon, newIcon);
}
setIcon(newIcon);
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartTypeHierarchyNodeDescriptor method update.
public final boolean update() {
boolean changes = super.update();
final DartClass dartClass = getDartClass();
if (dartClass == null) {
final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
}
return true;
}
if (changes && myIsBase) {
final LayeredIcon icon = new LayeredIcon(2);
icon.setIcon(getIcon(), 0);
icon.setIcon(AllIcons.Hierarchy.Base, 1, -AllIcons.Hierarchy.Base.getIconWidth() / 2, 0);
setIcon(icon);
}
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
TextAttributes classNameAttributes = null;
if (myColor != null) {
classNameAttributes = new TextAttributes(myColor, null, null, null, Font.PLAIN);
}
final String libraryName = DartResolveUtil.getLibraryName(dartClass.getContainingFile());
myHighlightedText.getEnding().addText(dartClass.getName(), classNameAttributes);
myHighlightedText.getEnding().addText(" (" + libraryName + ")", HierarchyNodeDescriptor.getPackageNameAttributes());
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartFilterByClassMacro method calculateResult.
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
final PsiElement at = context.getPsiElementAtStartOffset();
final Set<DartComponentName> variables = DartRefactoringUtil.collectUsedComponents(at);
final List<DartComponentName> filtered = ContainerUtil.filter(variables, name -> {
final PsiElement nameParent = name.getParent();
if (nameParent instanceof DartClass) {
return false;
}
final DartClassResolveResult result = DartResolveUtil.getDartClassResolveResult(nameParent);
final DartClass dartClass = result.getDartClass();
return dartClass != null && filter(dartClass);
});
return filtered.isEmpty() ? null : new PsiElementResult(filtered.iterator().next());
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartServerGotoSuperHandler method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
return;
}
final boolean isInClass = inComponent instanceof DartClass;
// ask for the super type hierarchy
final VirtualFile virtualFile = file.getVirtualFile();
final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
// build list of DartComponent(s)
final List<DartComponent> supers = Lists.newArrayList();
if (!items.isEmpty()) {
TypeHierarchyItem seed = items.get(0);
{
final Integer superIndex = seed.getSuperclass();
if (superIndex != null) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
for (int superIndex : seed.getMixins()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
for (int superIndex : seed.getInterfaces()) {
final TypeHierarchyItem superItem = items.get(superIndex);
addSuperComponent(project, supers, isInClass, superItem);
}
}
// prepare the title
final String title;
if (isInClass) {
title = DartBundle.message("goto.super.class.chooser.title");
} else {
title = CodeInsightBundle.message("goto.super.method.chooser.title");
}
// open DartComponent(s)
final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.
the class DartNamedElementNode method buildPresentationText.
@Nullable
private static String buildPresentationText(DartComponent dartComponent) {
final ItemPresentation presentation = dartComponent.getPresentation();
if (presentation == null) {
return dartComponent.getName();
}
final StringBuilder result = new StringBuilder();
if (dartComponent instanceof DartClass) {
result.append(dartComponent.getName());
final String location = presentation.getLocationString();
if (location != null && !location.isEmpty()) {
result.append(" ").append(location);
}
} else {
result.append(presentation.getPresentableText());
}
return result.toString();
}
Aggregations