use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class CreateConstructorFix 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("(");
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;
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class CreateEqualsAndHashcodeFix method buildFunctionsText.
protected Template buildFunctionsText(TemplateManager templateManager, @NotNull Set<DartComponent> elementsToProcess) {
final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
template.setToReformat(true);
final boolean doInsertOverrideAnnotation = CodeStyleSettingsManager.getSettings(myDartClass.getProject()).INSERT_OVERRIDE_ANNOTATION;
if (doInsertOverrideAnnotation) {
template.addTextSegment("@override\n");
}
template.addTextSegment("bool operator==(Object other) =>\nidentical(this, other) ||\n");
if (mySuperclassOverridesEqualEqualAndHashCode) {
template.addTextSegment("super == other &&\n");
}
template.addTextSegment("other is " + myDartClass.getName() + " &&\n");
template.addTextSegment("runtimeType == other.runtimeType");
for (DartComponent component : elementsToProcess) {
template.addTextSegment(" &&\n");
template.addTextSegment(component.getName() + " == other." + component.getName());
}
template.addTextSegment(";\n");
if (doInsertOverrideAnnotation) {
template.addTextSegment("@override\n");
}
template.addTextSegment("int get hashCode => ");
boolean firstItem = true;
if (mySuperclassOverridesEqualEqualAndHashCode) {
template.addTextSegment("\nsuper.hashCode");
firstItem = false;
}
for (DartComponent component : elementsToProcess) {
if (!firstItem) {
template.addTextSegment(" ^\n");
}
template.addTextSegment(component.getName() + ".hashCode");
firstItem = false;
}
if (!mySuperclassOverridesEqualEqualAndHashCode && elementsToProcess.isEmpty()) {
template.addTextSegment("0");
}
template.addTextSegment(";\n");
template.addEndVariable();
// trailing space is removed when auto-reformatting, but it helps to enter line break if needed
template.addTextSegment(" ");
return template;
}
use of com.jetbrains.lang.dart.psi.DartComponent in project intellij-plugins by JetBrains.
the class DartServerGotoSuperHandler method addSuperComponent.
private static void addSuperComponent(@NotNull Project project, List<DartComponent> supers, boolean isInClass, TypeHierarchyItem item) {
// prepare Element for the current item
final Element itemElement = isInClass ? item.getClassElement() : item.getMemberElement();
if (itemElement == null) {
return;
}
// ignore Object
if (ElementKind.CLASS.equals(itemElement.getKind()) && "Object".equals(itemElement.getName())) {
return;
}
// find the DartComponent
final Location itemLocation = itemElement.getLocation();
final DartComponent itemComponent = DartHierarchyUtil.findDartComponent(project, itemLocation);
if (itemComponent != null) {
supers.add(itemComponent);
}
}
use of com.jetbrains.lang.dart.psi.DartComponent 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.DartComponent in project intellij-plugins by JetBrains.
the class DartInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
final Ref<VirtualFile> fileRef = Ref.create();
final Ref<Integer> offsetRef = Ref.create();
final Ref<DartComponentType> componentTypeRef = Ref.create();
prepare(parameters, fileRef, offsetRef, componentTypeRef);
if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
return;
ApplicationManager.getApplication().runReadAction(() -> {
final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
});
final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
for (DartComponent component : components) {
consumer.process(component);
}
});
}
Aggregations