Search in sources :

Example 1 with DartNavigationTarget

use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationTarget in project intellij-plugins by JetBrains.

the class InlineMethodDialog method findContext.

@Nullable
private static InlineRefactoringContext findContext(@Nullable Editor editor) {
    if (editor == null) {
        return null;
    }
    // prepare project
    final Project project = editor.getProject();
    if (project == null) {
        return null;
    }
    // prepare files
    final Document document = editor.getDocument();
    final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (psiFile == null) {
        return null;
    }
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    // prepare navigation regions
    final int offset = editor.getCaretModel().getOffset();
    final List<DartNavigationRegion> navigationRegions = DartAnalysisServerService.getInstance(project).getNavigation(virtualFile);
    // find the navigation region
    for (DartNavigationRegion region : navigationRegions) {
        if (region.getOffset() <= offset && offset <= region.getOffset() + region.getLength()) {
            final List<DartNavigationTarget> targets = region.getTargets();
            final String kind = targets.get(0).getKind();
            return new InlineRefactoringContext(virtualFile, offset, kind);
        }
    }
    // fail
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartNavigationTarget(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationTarget) DartNavigationRegion(com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 DartNavigationRegion (com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion)1 DartNavigationTarget (com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationTarget)1 Nullable (org.jetbrains.annotations.Nullable)1