use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-elixir by KronicDeth.
the class Factory method structureViewBuilder.
@Nullable
public static StructureViewBuilder structureViewBuilder(@NotNull final PsiFile psiFile) {
StructureViewBuilder structureViewBuilder = null;
if (psiFile instanceof ElixirFile) {
final ElixirFile elixirFile = (ElixirFile) psiFile;
structureViewBuilder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new Model(elixirFile, editor);
}
@Override
public boolean isRootNodeShown() {
return false;
}
};
}
return structureViewBuilder;
}
use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.
the class Bookmark method getQualifiedName.
public String getQualifiedName() {
String presentableUrl = myFile.getPresentableUrl();
if (myFile.isDirectory())
return presentableUrl;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
if (psiFile == null)
return presentableUrl;
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(null);
Object element;
try {
element = model.getCurrentEditorElement();
} finally {
model.dispose();
}
if (element instanceof NavigationItem) {
ItemPresentation presentation = ((NavigationItem) element).getPresentation();
if (presentation != null) {
presentableUrl = ((NavigationItem) element).getName() + " " + presentation.getLocationString();
}
}
}
return IdeBundle.message("bookmark.file.X.line.Y", presentableUrl, getLine() + 1);
}
use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.
the class GotoClassAction method findMember.
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
if (builder == null || editors.length == 0) {
return null;
}
final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
try {
final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
if (element == null) {
return null;
}
final MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build();
int max = Integer.MIN_VALUE;
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
max = degree;
target = ((StructureViewTreeElement) treeElement).getValue();
}
}
}
}
return target instanceof Navigatable ? (Navigatable) target : null;
} finally {
Disposer.dispose(view);
}
}
use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.
the class SelectInContextImpl method doCreateEditorContext.
private static SelectInContext doCreateEditorContext(Project project, FileEditor editor, @Nullable DataContext dataContext) {
if (project == null || editor == null) {
return null;
}
VirtualFile file = FileEditorManagerEx.getInstanceEx(project).getFile(editor);
if (file == null) {
file = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (file == null) {
return null;
}
}
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile == null) {
return null;
}
if (editor instanceof TextEditor) {
return new TextEditorContext((TextEditor) editor, psiFile);
} else {
StructureViewBuilder builder = editor.getStructureViewBuilder();
StructureView structureView = builder != null ? builder.createStructureView(editor, project) : null;
Object selectorInFile = structureView != null ? structureView.getTreeModel().getCurrentEditorElement() : null;
if (structureView != null)
Disposer.dispose(structureView);
return new SimpleSelectInContext(psiFile, ObjectUtils.chooseNotNull(selectorInFile, psiFile));
}
}
use of com.intellij.ide.structureView.StructureViewBuilder 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);
}
}
}
Aggregations