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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations