@Nullable private StructureViewComposite.StructureViewDescriptor createBaseLanguageStructureView(final FileEditor fileEditor, final Language language) { if (!myVirtualFile.isValid()) return null; final FileViewProvider viewProvider = getViewProvider(); if (viewProvider == null) return null; final PsiFile dataFile = viewProvider.getPsi(language); if (dataFile == null || !isAcceptableBaseLanguageFile(dataFile)) return null; final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if (factory == null) return null; final StructureViewBuilder builder = factory.getStructureViewBuilder(dataFile); if (builder == null) return null; StructureView structureView = builder.createStructureView(fileEditor, myProject); return new StructureViewComposite.StructureViewDescriptor(IdeBundle.message("tab.structureview.baselanguage.view", language.getDisplayName()), structureView, findFileType(language).getIcon()); }
@Nullable private StructureViewComposite.StructureViewDescriptor createBaseLanguageStructureView(final FileEditor fileEditor, final Language language) { if (!myVirtualFile.isValid()) return null; final TemplateLanguageFileViewProvider viewProvider = getViewProvider(); if (viewProvider == null) return null; final PsiFile dataFile = viewProvider.getPsi(language); if (dataFile == null || !isAcceptableBaseLanguageFile(dataFile)) return null; final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if (factory == null) return null; final StructureViewBuilder builder = factory.getStructureViewBuilder(dataFile); if (builder == null) return null; StructureView structureView = builder.createStructureView(fileEditor, myProject); return new StructureViewComposite.StructureViewDescriptor(IdeBundle.message("tab.structureview.baselanguage.view", language.getDisplayName()), structureView, findFileType(language).getIcon()); }
@Nullable private static StructureViewBuilder getStructureViewBuilderForExtensions(final PsiFile psiFile) { for(Language language : XMLLanguage.INSTANCE.getLanguageExtensionsForFile(psiFile)) { PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if(factory == null) { continue; } final StructureViewBuilder builder = factory.getStructureViewBuilder(psiFile); if(builder != null) { return builder; } } return null; }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(@NotNull FileType fileType, @NotNull VirtualFile file, @NotNull Project project) { if(fileType == JavaClassFileType.INSTANCE) { PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if(psiFile instanceof PsiCompiledFile) { psiFile = ((PsiCompiledFile) psiFile).getDecompiledPsiFile(); } if(psiFile != null) { PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage()); if(factory != null) { return factory.getStructureViewBuilder(psiFile); } } } return null; }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(@NotNull FileType fileType, @NotNull VirtualFile file, @NotNull Project project) { final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (fileType == JavaClassFileType.INSTANCE && psiFile != null) { Language language = psiFile.getLanguage(); if (language != JavaLanguage.INSTANCE) { PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if (factory != null) { return factory.getStructureViewBuilder(psiFile); } } } if (psiFile instanceof PsiClassOwner) { return new TreeBasedStructureViewBuilder() { @Override @NotNull public StructureViewModel createStructureViewModel(@Nullable Editor editor) { return new JavaFileTreeModel((PsiClassOwner)psiFile, editor); } }; } return null; }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(@NotNull final FileType fileType, @NotNull final VirtualFile file, @NotNull final Project project) { if (!(fileType instanceof LanguageFileType)) return null; final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile == null) return null; final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage()); return factory == null ? null : factory.getStructureViewBuilder(psiFile); }
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(); } } }
public String getQualifiedName() { String presentableUrl = myFile.getPresentableUrl(); if (myFile.isDirectory()) return presentableUrl; PsiDocumentManager.getInstance(myProject).commitAllDocuments(); 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); }
@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 = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); 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); } }
@Nullable private static StructureViewBuilder getStructureViewBuilderForExtensions(final PsiFile psiFile) { for (Language language : XMLLanguage.INSTANCE.getLanguageExtensionsForFile(psiFile)) { PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if (factory == null) continue; final StructureViewBuilder builder = factory.getStructureViewBuilder(psiFile); if (builder != null) { return builder; } } return null; }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(@NotNull final FileType fileType, @NotNull final VirtualFile file, @NotNull final Project project) { final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); final ContentBasedFileSubstitutor[] processors = Extensions.getExtensions(ContentBasedFileSubstitutor.EP_NAME); for (ContentBasedFileSubstitutor processor : processors) { if (processor.isApplicable(project, file)) { final Language language = processor.obtainLanguageForFile(file); if (language != null) { final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(language); if (factory != null) return factory.getStructureViewBuilder(psiFile); } } } final PsiJavaFile javaFile = (PsiJavaFile)psiFile; if (javaFile == null) return null; return new TreeBasedStructureViewBuilder() { @Override @NotNull public StructureViewModel createStructureViewModel(@Nullable Editor editor) { return new JavaFileTreeModel(javaFile, editor); } }; }
@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 = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); int max = Integer.MIN_VALUE; Object target = null; for (TreeElement treeElement : element.getChildren()) { if (treeElement instanceof StructureViewTreeElement) { final ItemPresentation presentation = treeElement.getPresentation(); String presentableText = presentation == null ? null : presentation.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); } }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(@Nonnull final FileType fileType, @Nonnull final VirtualFile file, @Nonnull final Project project) { if (!(fileType instanceof LanguageFileType)) return null; final PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile == null) return null; final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiFile.getLanguage()); return factory == null ? null : factory.getStructureViewBuilder(psiFile); }
@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); } }
@Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) { return LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file) instanceof TreeBasedStructureViewBuilder; }
static boolean checkValidForFile(final PsiFile file) { final StructureViewBuilder structureViewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file); return structureViewBuilder instanceof TreeBasedStructureViewBuilder || structureViewBuilder instanceof TemplateLanguageStructureViewBuilder; }
protected boolean isShowRoot(final PsiFile psiFile) { StructureViewBuilder viewBuilder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile); return viewBuilder instanceof TreeBasedStructureViewBuilder && ((TreeBasedStructureViewBuilder)viewBuilder).isRootNodeShown(); }
@Override protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull final PsiFile file) { return LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file) instanceof TreeBasedStructureViewBuilder; }
@RequiredDispatchThread @Override public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull PsiFile file) { PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiElement container = null; WeakReference<LightweightHint> ref = editor.getUserData(MY_LAST_HINT_KEY); LightweightHint hint = SoftReference.dereference(ref); if (hint != null && hint.isVisible()){ hint.hide(); container = hint.getUserData(CONTAINER_KEY); if (container != null && !container.isValid()){ container = null; } } StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file); if (builder instanceof TreeBasedStructureViewBuilder) { StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(editor); boolean goOneLevelUp = true; try { if (container == null) { goOneLevelUp = false; Object element = model.getCurrentEditorElement(); if (element instanceof PsiElement) { container = (PsiElement) element; } } } finally { model.dispose(); } while(true) { if (container == null || container instanceof PsiFile) { return; } if (goOneLevelUp) { goOneLevelUp = false; } else { if (!isDeclarationVisible(container, editor)) { break; } } container = container.getParent(); while(container != null && DeclarationRangeUtil.getPossibleDeclarationAtRange(container) == null) { container = container.getParent(); if (container instanceof PsiFile) return; } } } if (container == null) { return; } final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container); if (range == null) { return; } final PsiElement _container = container; ApplicationManager.getApplication().invokeLater(() -> { LightweightHint hint1 = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true); if (hint1 != null) { hint1.putUserData(CONTAINER_KEY, _container); editor.putUserData(MY_LAST_HINT_KEY, new WeakReference<>(hint1)); } }); }