Search in sources :

Example 1 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 2 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 3 with Segment

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

the class InjectedSelfElementInfo method getInjectedRange.

@Nullable
private ProperTextRange getInjectedRange(boolean psi) {
    PsiElement hostContext = myHostContext.getElement();
    if (hostContext == null)
        return null;
    Segment hostElementRange = psi ? myInjectedFileRangeInHostFile.getPsiRange() : myInjectedFileRangeInHostFile.getRange();
    if (hostElementRange == null)
        return null;
    return hostToInjected(psi, hostElementRange, restoreFile(), myAffixOffsets);
}
Also used : Segment(com.intellij.openapi.util.Segment) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Segment

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

the class InjectedSelfElementInfo method restoreFile.

@Override
public PsiFile restoreFile() {
    PsiFile hostFile = myHostContext.getContainingFile();
    if (hostFile == null || !hostFile.isValid())
        return null;
    PsiElement hostContext = myHostContext.getElement();
    if (hostContext == null)
        return null;
    Segment segment = myInjectedFileRangeInHostFile.getPsiRange();
    if (segment == null)
        return null;
    final TextRange rangeInHostFile = TextRange.create(segment);
    return getInjectedFileIn(hostContext, hostFile, rangeInHostFile);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Segment(com.intellij.openapi.util.Segment)

Example 5 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)

Aggregations

Segment (com.intellij.openapi.util.Segment)23 NotNull (org.jetbrains.annotations.NotNull)7 TextRange (com.intellij.openapi.util.TextRange)5 Document (com.intellij.openapi.editor.Document)4 DocumentWindow (com.intellij.injected.editor.DocumentWindow)3 Project (com.intellij.openapi.project.Project)3 ProperTextRange (com.intellij.openapi.util.ProperTextRange)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 List (java.util.List)3 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)2 Editor (com.intellij.openapi.editor.Editor)2 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 UsageInfo (com.intellij.usageView.UsageInfo)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 Issue (com.android.tools.lint.detector.api.Issue)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)1