Search in sources :

Example 6 with Segment

use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.

the class RangeBlinker method startBlinking.

public void startBlinking() {
    Project project = myEditor.getProject();
    if (ApplicationManager.getApplication().isDisposed() || myEditor.isDisposed() || project != null && project.isDisposed()) {
        return;
    }
    MarkupModel markupModel = myEditor.getMarkupModel();
    if (show) {
        for (Segment segment : myMarkers) {
            if (segment.getEndOffset() > myEditor.getDocument().getTextLength())
                continue;
            RangeHighlighter highlighter = markupModel.addRangeHighlighter(segment.getStartOffset(), segment.getEndOffset(), HighlighterLayer.ADDITIONAL_SYNTAX, myAttributes, HighlighterTargetArea.EXACT_RANGE);
            myAddedHighlighters.add(highlighter);
        }
    } else {
        removeHighlights();
    }
    stopBlinking();
    myBlinkingAlarm.addRequest(() -> {
        if (myTimeToLive > 0 || show) {
            myTimeToLive--;
            show = !show;
            startBlinking();
        }
    }, 400);
}
Also used : Project(com.intellij.openapi.project.Project) Segment(com.intellij.openapi.util.Segment)

Example 7 with Segment

use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.

the class SoftWrapApplianceManager method recalculate.

public void recalculate(List<? extends Segment> ranges) {
    if (myIsDirty) {
        return;
    }
    if (myVisibleAreaWidth <= 0) {
        myIsDirty = true;
        return;
    }
    Collections.sort(ranges, (o1, o2) -> {
        int startDiff = o1.getStartOffset() - o2.getStartOffset();
        return startDiff == 0 ? o2.getEndOffset() - o1.getEndOffset() : startDiff;
    });
    final int[] lastRecalculatedOffset = new int[] { 0 };
    SoftWrapAwareDocumentParsingListenerAdapter listener = new SoftWrapAwareDocumentParsingListenerAdapter() {

        @Override
        public void onRecalculationEnd(@NotNull IncrementalCacheUpdateEvent event) {
            lastRecalculatedOffset[0] = event.getActualEndOffset();
        }
    };
    myListeners.add(listener);
    try {
        for (Segment range : ranges) {
            int lastOffset = lastRecalculatedOffset[0];
            if (range.getEndOffset() > lastOffset) {
                recalculateSoftWraps(new IncrementalCacheUpdateEvent(Math.max(range.getStartOffset(), lastOffset), range.getEndOffset(), myEditor));
            }
        }
    } finally {
        myListeners.remove(listener);
    }
    onRecalculationEnd();
}
Also used : NotNull(org.jetbrains.annotations.NotNull) Segment(com.intellij.openapi.util.Segment)

Example 8 with Segment

use of com.intellij.openapi.util.Segment in project android by JetBrains.

the class UnusedResourcesProcessor method findUsages.

@Override
@NotNull
protected UsageInfo[] findUsages() {
    Map<Issue, Map<File, List<ProblemData>>> map = computeUnusedMap();
    List<PsiElement> elements = computeUnusedDeclarationElements(map);
    myElements = elements.toArray(new PsiElement[elements.size()]);
    UsageInfo[] result = new UsageInfo[myElements.length];
    for (int i = 0, n = myElements.length; i < n; i++) {
        PsiElement element = myElements[i];
        if (element instanceof PsiBinaryFile) {
            // The usage view doesn't handle binaries at all. Work around this (for example,
            // the UsageInfo class asserts in the constructor if the element doesn't have
            // a text range.)
            SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject);
            SmartPsiElementPointer<PsiElement> smartPointer = smartPointerManager.createSmartPsiElementPointer(element);
            SmartPsiFileRange smartFileRange = smartPointerManager.createSmartPsiFileRangePointer((PsiBinaryFile) element, TextRange.EMPTY_RANGE);
            result[i] = new UsageInfo(smartPointer, smartFileRange, false, false) {

                @Override
                public boolean isValid() {
                    return true;
                }

                @Override
                @Nullable
                public Segment getSegment() {
                    return null;
                }
            };
        } else {
            result[i] = new UsageInfo(element);
        }
    }
    return UsageViewUtil.removeDuplicatedUsages(result);
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) Segment(com.intellij.openapi.util.Segment) ProblemData(org.jetbrains.android.inspections.lint.ProblemData) Map(java.util.Map) UsageInfo(com.intellij.usageView.UsageInfo) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Segment

use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testAnchorInfoHasRange.

public void testAnchorInfoHasRange() throws Exception {
    PsiJavaFile file = (PsiJavaFile) createFile("a.java", "class C1{}");
    assertNotNull(((PsiFileImpl) file).getStubTree());
    PsiClass psiClass = file.getClasses()[0];
    Segment range = createPointer(psiClass).getRange();
    assertNotNull(range);
    assertEquals(psiClass.getNameIdentifier().getTextRange(), TextRange.create(range));
    file = (PsiJavaFile) createFile("b.java", "class C2{}");
    assertNotNull(((PsiFileImpl) file).getStubTree());
    psiClass = file.getClasses()[0];
    range = createPointer(psiClass).getPsiRange();
    assertNotNull(range);
    assertEquals(psiClass.getNameIdentifier().getTextRange(), TextRange.create(range));
}
Also used : Segment(com.intellij.openapi.util.Segment)

Example 10 with Segment

use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testEqualPointerRangesWhenCreatedFromStubAndAST.

public void testEqualPointerRangesWhenCreatedFromStubAndAST() {
    final PsiFile file = configureByText(JavaFileType.INSTANCE, "class S {\n" + "}");
    PsiClass aClass = ((PsiJavaFile) file).getClasses()[0];
    assertNotNull(((PsiFileImpl) file).getStubTree());
    final SmartPointerManager manager = getPointerManager();
    final SmartPsiElementPointer<PsiClass> pointer1 = createPointer(aClass);
    Segment range1 = pointer1.getRange();
    manager.removePointer(pointer1);
    final FileASTNode node = file.getNode();
    final SmartPsiElementPointer<PsiClass> pointer2 = createPointer(aClass);
    assertEquals(range1, pointer2.getRange());
    assertNotNull(node);
}
Also used : FileASTNode(com.intellij.lang.FileASTNode) Segment(com.intellij.openapi.util.Segment)

Aggregations

Segment (com.intellij.openapi.util.Segment)21 NotNull (org.jetbrains.annotations.NotNull)7 TextRange (com.intellij.openapi.util.TextRange)5 DocumentWindow (com.intellij.injected.editor.DocumentWindow)3 Document (com.intellij.openapi.editor.Document)3 ProperTextRange (com.intellij.openapi.util.ProperTextRange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)2 UsageInfo (com.intellij.usageView.UsageInfo)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 Issue (com.android.tools.lint.detector.api.Issue)1 RefManagerExtension (com.intellij.codeInspection.lang.RefManagerExtension)1 FindResult (com.intellij.find.FindResult)1 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 FileASTNode (com.intellij.lang.FileASTNode)1 Language (com.intellij.lang.Language)1 Editor (com.intellij.openapi.editor.Editor)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1