use of com.intellij.ide.structureView.newStructureView.StructureViewComponent in project intellij-community by JetBrains.
the class JavaTreeStructureTest method dotest.
private void dotest(CheckAction checkAction) throws Exception {
final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
final FileEditor fileEditor = fileEditors[0];
try {
final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
checkAction.testClassStructure(structureViewComponent);
Disposer.dispose(structureViewComponent);
} finally {
fileEditorManager.closeFile(virtualFile);
}
}
use of com.intellij.ide.structureView.newStructureView.StructureViewComponent in project intellij-community by JetBrains.
the class JsonStructureViewTest method testSimpleStructure.
// Moved from JavaScript
public void testSimpleStructure() {
myFixture.configureByFile("structureView/" + getTestName(false) + ".json");
final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(myFixture.getFile());
assertNotNull(builder);
StructureViewComponent component = null;
try {
final FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFixture.getFile().getVirtualFile());
component = (StructureViewComponent) builder.createStructureView(editor, myFixture.getProject());
final StructureViewModel model = component.getTreeModel();
TreeElement[] children = model.getRoot().getChildren();
assertEquals(2, children.length);
assertEquals("aaa", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
assertEquals("bbb", children[1].getPresentation().getPresentableText());
assertEquals(AllIcons.Json.Property_braces, children[1].getPresentation().getIcon(false));
children = children[1].getChildren();
assertEquals(1, children.length);
assertEquals("ccc", children[0].getPresentation().getPresentableText());
assertEquals(PlatformIcons.PROPERTY_ICON, children[0].getPresentation().getIcon(false));
} finally {
if (component != null) {
Disposer.dispose(component);
}
}
}
use of com.intellij.ide.structureView.newStructureView.StructureViewComponent in project intellij-community by JetBrains.
the class StructureViewUpdatingTest method testJavaClassStructure.
public void testJavaClassStructure() throws Exception {
final PsiClass psiClass = JavaDirectoryService.getInstance().getClasses(getPackageDirectory("com/package1"))[0];
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
FileEditor[] fileEditors = fileEditorManager.openFile(virtualFile, false);
final FileEditor fileEditor = fileEditors[0];
try {
final StructureViewComponent structureViewComponent = (StructureViewComponent) fileEditor.getStructureViewBuilder().createStructureView(fileEditor, myProject);
final Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile());
structureViewComponent.setActionActive(InheritedMembersNodeProvider.ID, true);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + " getValue(): int\n" + " getClass(): Class<? extends Object>\n" + " hashCode(): int\n" + " equals(Object): boolean\n" + " clone(): Object\n" + " toString(): String\n" + " notify(): void\n" + " notifyAll(): void\n" + " wait(long): void\n" + " wait(long, int): void\n" + " wait(): void\n" + " finalize(): void\n" + " myField1: boolean\n" + " myField2: boolean\n");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final int offset = document.getLineStartOffset(5);
document.insertString(offset, " boolean myNewField = false;\n");
}
}.execute().throwException();
PsiDocumentManager.getInstance(myProject).commitDocument(document);
PlatformTestUtil.waitForAlarm(600);
//TreeUtil.expand(structureViewComponent.getTree(), 3);
PlatformTestUtil.assertTreeEqual(structureViewComponent.getTree(), "-Class1.java\n" + " -Class1\n" + " getValue(): int\n" + " getClass(): Class<? extends Object>\n" + " hashCode(): int\n" + " equals(Object): boolean\n" + " clone(): Object\n" + " toString(): String\n" + " notify(): void\n" + " notifyAll(): void\n" + " wait(long): void\n" + " wait(long, int): void\n" + " wait(): void\n" + " finalize(): void\n" + " myField1: boolean\n" + " myField2: boolean\n" + " myNewField: boolean = false\n");
Disposer.dispose(structureViewComponent);
} finally {
fileEditorManager.closeFile(virtualFile);
}
}
use of com.intellij.ide.structureView.newStructureView.StructureViewComponent in project intellij-community by JetBrains.
the class TemplateLanguageStructureViewBuilder method updateBaseLanguageView.
private void updateBaseLanguageView() {
if (myBaseStructureViewDescriptor == null || !myProject.isOpen())
return;
final StructureViewComponent view = (StructureViewComponent) myBaseStructureViewDescriptor.structureView;
if (view.isDisposed())
return;
StructureViewState state = view.getState();
List<PsiAnchor> expanded = collectAnchors(state.getExpandedElements());
List<PsiAnchor> selected = collectAnchors(state.getSelectedElements());
updateTemplateDataFileView();
if (view.isDisposed())
return;
for (PsiAnchor pointer : expanded) {
PsiElement element = pointer.retrieve();
if (element != null) {
view.expandPathToElement(element);
}
}
for (PsiAnchor pointer : selected) {
PsiElement element = pointer.retrieve();
if (element != null) {
view.addSelectionPathTo(element);
}
}
}
use of com.intellij.ide.structureView.newStructureView.StructureViewComponent in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method testStructureView.
@Override
public void testStructureView(@NotNull Consumer<StructureViewComponent> consumer) {
assertNotNull("configure first", myFile);
final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(myFile);
assertNotNull("editor not opened for " + myFile, myFile);
final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(getFile());
assertNotNull("no builder for " + myFile, builder);
StructureViewComponent component = null;
try {
component = (StructureViewComponent) builder.createStructureView(fileEditor, getProject());
consumer.consume(component);
} finally {
if (component != null)
Disposer.dispose(component);
}
}
Aggregations