use of com.intellij.ide.structureView.StructureViewModel in project ideavim by JetBrains.
the class PsiHelper method findMethodOrClass.
private static int findMethodOrClass(@NotNull Editor editor, int offset, int count, boolean isStart) {
PsiFile file = getFile(editor);
if (file == null) {
return -1;
}
StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
if (!(structureViewBuilder instanceof TreeBasedStructureViewBuilder))
return -1;
TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
StructureViewModel model = builder.createStructureViewModel(editor);
TIntArrayList navigationOffsets = new TIntArrayList();
addNavigationElements(model.getRoot(), navigationOffsets, isStart);
if (navigationOffsets.isEmpty()) {
return -1;
}
navigationOffsets.sort();
int index = navigationOffsets.size();
for (int i = 0; i < navigationOffsets.size(); i++) {
if (navigationOffsets.get(i) > offset) {
index = i;
if (count > 0)
count--;
break;
} else if (navigationOffsets.get(i) == offset) {
index = i;
break;
}
}
int resultIndex = index + count;
if (resultIndex < 0) {
resultIndex = 0;
} else if (resultIndex >= navigationOffsets.size()) {
resultIndex = navigationOffsets.size() - 1;
}
return navigationOffsets.get(resultIndex);
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class FileStructureDialogTest method testFileStructureForClass.
public void testFileStructureForClass() throws Exception {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(getPackageDirectory());
assertNotNull(aPackage);
final PsiClass psiClass = aPackage.getClasses()[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
assertNotNull(virtualFile);
final StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(virtualFile.getFileType(), virtualFile, myProject);
assertNotNull(structureViewBuilder);
final StructureViewModel structureViewModel = ((TreeBasedStructureViewBuilder) structureViewBuilder).createStructureViewModel(null);
final EditorFactory factory = EditorFactory.getInstance();
assertNotNull(factory);
final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
assertNotNull(document);
final Editor editor = factory.createEditor(document, myProject);
try {
final FileStructureDialog dialog = new FileStructureDialog(structureViewModel, editor, myProject, psiClass, new Disposable() {
@Override
public void dispose() {
structureViewModel.dispose();
}
}, true);
try {
final CommanderPanel panel = dialog.getPanel();
assertListsEqual((ListModel) panel.getModel(), "Inner1\n" + "Inner2\n" + "__method(): void\n" + "_myField1: int\n" + "_myField2: String\n");
} finally {
dialog.close(0);
}
} finally {
factory.releaseEditor(editor);
}
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class MethodUpDownUtil method addNavigationElements.
private static void addNavigationElements(Collection<PsiElement> array, PsiFile element) {
StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(element);
if (structureViewBuilder instanceof TreeBasedStructureViewBuilder) {
TreeBasedStructureViewBuilder builder = (TreeBasedStructureViewBuilder) structureViewBuilder;
StructureViewModel model = builder.createStructureViewModel(null);
try {
addStructureViewElements(model.getRoot(), array, element);
} finally {
model.dispose();
}
}
}
use of com.intellij.ide.structureView.StructureViewModel in project intellij-community by JetBrains.
the class ViewStructureAction method createPopup.
@Nullable
public static FileStructurePopup createPopup(@NotNull Project project, @NotNull FileEditor fileEditor) {
StructureViewBuilder structureViewBuilder = fileEditor.getStructureViewBuilder();
if (structureViewBuilder == null)
return null;
StructureView structureView = structureViewBuilder.createStructureView(fileEditor, project);
StructureViewModel model = structureView.getTreeModel();
if (model instanceof PlaceHolder) {
//noinspection unchecked
((PlaceHolder) model).setPlace(TreeStructureUtil.PLACE);
}
return createStructureViewPopup(project, fileEditor, structureView);
}
use of com.intellij.ide.structureView.StructureViewModel in project android by JetBrains.
the class StructureViewTest method testLayoutStructureOrder2.
public void testLayoutStructureOrder2() throws Exception {
VirtualFile file = copyFileToProject("layout/structure_view_test_order_2.xml", "/res/layout/layout.xml");
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
assertInstanceOf(psiFile, XmlFile.class);
DomFileElement<LayoutViewElement> element = DomManager.getDomManager(getProject()).getFileElement(((XmlFile) psiFile), LayoutViewElement.class);
assertNotNull(element);
final StructureViewModel model = new LayoutStructureViewBuilder(element).createStructureViewModel(null);
String expected = "LinearLayout\n" + " Include\n" + " Fragment\n";
assertEquals(expected, model.getRoot().toString());
}
Aggregations