use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion 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;
}
use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.
the class DartResolver method processRegionsInRange.
public static void processRegionsInRange(@NotNull final List<DartServerData.DartNavigationRegion> regions, @NotNull final TextRange range, @NotNull final Consumer<DartNavigationRegion> processor) {
if (regions.isEmpty())
return;
// first find the first region that has minimal allowed offset
int low = 0;
int high = regions.size() - 1;
while (low < high) {
int mid = (low + high) >>> 1;
DartServerData.DartNavigationRegion midVal = regions.get(mid);
int cmp = midVal.getOffset() - range.getStartOffset();
if (cmp < 0) {
low = Math.min(high, mid + 1);
} else {
high = Math.max(low, mid - 1);
}
}
assert low == high : regions.size() + "," + low + "," + high;
int i = low;
DartNavigationRegion region = regions.get(i);
if (region.getOffset() < range.getStartOffset()) {
i++;
if (i < regions.size()) {
region = regions.get(i);
} else {
return;
}
}
while (region.getOffset() + region.getLength() <= range.getEndOffset()) {
processor.consume(region);
i++;
if (i < regions.size()) {
region = regions.get(i);
} else {
return;
}
}
}
use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.
the class DartResolver method findRegion.
/**
* Find the region with the given offset in the given list of sorted regions.
* Returns the found region or null.
*/
@Nullable
public static DartNavigationRegion findRegion(@NotNull final List<DartServerData.DartNavigationRegion> regions, final int offset, final int length) {
int low = 0;
int high = regions.size() - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
DartServerData.DartNavigationRegion midVal = regions.get(mid);
int cmp = midVal.getOffset() - offset;
if (cmp < 0) {
low = mid + 1;
} else if (cmp > 0) {
high = mid - 1;
} else {
if (midVal.getLength() == length) {
return midVal;
}
return null;
}
}
return null;
}
use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.
the class DartServerHighlightingTest method testNavigationTargetOffsetUpdated.
public void testNavigationTargetOffsetUpdated() {
myFixture.configureByText(DartFileType.INSTANCE, "var a = 1; var b = a;");
myFixture.doHighlighting();
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(getProject());
final VirtualFile file = getFile().getVirtualFile();
final List<DartNavigationRegion> regions = service.getNavigation(file);
checkRegions(regions, TextRange.create(0, 3), TextRange.create(4, 5), TextRange.create(15, 16), TextRange.create(19, 20));
assertEquals(4, regions.get(3).getTargets().get(0).getOffset(getProject(), file));
getEditor().getCaretModel().moveToOffset(0);
myFixture.type("foo \b");
checkRegions(regions, TextRange.create(0 + 3, 3 + 3), TextRange.create(4 + 3, 5 + 3), TextRange.create(15 + 3, 16 + 3), TextRange.create(19 + 3, 20 + 3));
assertEquals(4 + 3, regions.get(3).getTargets().get(0).getOffset(getProject(), file));
}
use of com.jetbrains.lang.dart.analyzer.DartServerData.DartNavigationRegion in project intellij-plugins by JetBrains.
the class DartCalleeTreeStructure method getCallees.
private static void getCallees(@NotNull PsiElement element, @NotNull List<PsiElement> results) {
DartComponentName name = (DartComponentName) element;
DartComponent decl = (DartComponent) name.getParent();
PsiFile file = decl.getContainingFile();
if (file == null)
return;
VirtualFile vFile = file.getVirtualFile();
List<DartNavigationRegion> navRegions = DartAnalysisServerService.getInstance(element.getProject()).analysis_getNavigation(vFile, decl.getTextOffset(), decl.getTextLength());
if (navRegions == null)
return;
resolveReferences(decl, navRegions, results);
}
Aggregations