use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class ShredImpl method assertValid.
private void assertValid() {
Segment hostRange = getHostRangeMarker();
assert hostRange != null : "invalid host range: " + relevantRangeInHost;
PsiLanguageInjectionHost host = hostElementPointer.getElement();
assert host != null && host.isValid() : "no host: " + hostElementPointer;
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class ShredImpl method toString.
@Override
@SuppressWarnings({ "HardCodedStringLiteral" })
public String toString() {
PsiLanguageInjectionHost host = getHost();
Segment hostRange = getHostRangeMarker();
return "Shred " + (host == null ? null : host.getTextRange()) + ": " + host + " In host range: " + (hostRange != null ? "(" + hostRange.getStartOffset() + "," + hostRange.getEndOffset() + ");" : "invalid;") + " PSI range: " + this.range;
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class InjectedLanguageManagerImpl method getNonEditableFragments.
@NotNull
@Override
public List<TextRange> getNonEditableFragments(@NotNull DocumentWindow window) {
List<TextRange> result = ContainerUtil.newArrayList();
int offset = 0;
for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl) window).getShreds()) {
Segment hostRange = shred.getHostRangeMarker();
if (hostRange == null)
continue;
offset = appendRange(result, offset, shred.getPrefix().length());
offset += hostRange.getEndOffset() - hostRange.getStartOffset();
offset = appendRange(result, offset, shred.getSuffix().length());
}
return result;
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class SearchForUsagesRunnable method flashUsageScriptaculously.
private static void flashUsageScriptaculously(@NotNull final Usage usage) {
if (!(usage instanceof UsageInfo2UsageAdapter)) {
return;
}
UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter) usage;
Editor editor = usageInfo.openTextEditor(true);
if (editor == null)
return;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES);
RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6);
List<Segment> segments = new ArrayList<>();
Processor<Segment> processor = Processors.cancelableCollectProcessor(segments);
usageInfo.processRangeMarkers(processor);
rangeBlinker.resetMarkers(segments);
rangeBlinker.startBlinking();
}
use of com.intellij.openapi.util.Segment in project intellij-community by JetBrains.
the class ChunkExtractor method extractChunks.
@NotNull
private TextChunk[] extractChunks(@NotNull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @NotNull PsiFile file) {
int absoluteStartOffset = usageInfo2UsageAdapter.getNavigationOffset();
if (absoluteStartOffset == -1)
return TextChunk.EMPTY_ARRAY;
Document visibleDocument = myDocument instanceof DocumentWindow ? ((DocumentWindow) myDocument).getDelegate() : myDocument;
int visibleStartOffset = myDocument instanceof DocumentWindow ? ((DocumentWindow) myDocument).injectedToHost(absoluteStartOffset) : absoluteStartOffset;
int lineNumber = myDocument.getLineNumber(absoluteStartOffset);
int visibleLineNumber = visibleDocument.getLineNumber(visibleStartOffset);
List<TextChunk> result = new ArrayList<>();
appendPrefix(result, visibleLineNumber);
int fragmentToShowStart = myDocument.getLineStartOffset(lineNumber);
int fragmentToShowEnd = fragmentToShowStart < myDocument.getTextLength() ? myDocument.getLineEndOffset(lineNumber) : 0;
if (fragmentToShowStart > fragmentToShowEnd)
return TextChunk.EMPTY_ARRAY;
final CharSequence chars = myDocument.getCharsSequence();
if (fragmentToShowEnd - fragmentToShowStart > MAX_LINE_LENGTH_TO_SHOW) {
final int lineStartOffset = fragmentToShowStart;
fragmentToShowStart = Math.max(lineStartOffset, absoluteStartOffset - OFFSET_BEFORE_TO_SHOW_WHEN_LONG_LINE);
final int lineEndOffset = fragmentToShowEnd;
Segment segment = usageInfo2UsageAdapter.getUsageInfo().getSegment();
int usage_length = segment != null ? segment.getEndOffset() - segment.getStartOffset() : 0;
fragmentToShowEnd = Math.min(lineEndOffset, absoluteStartOffset + usage_length + OFFSET_AFTER_TO_SHOW_WHEN_LONG_LINE);
// this should not cause restarts of the lexer as the tokens are usually words
if (usage_length > 0 && StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset)) && StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset + usage_length - 1))) {
while (fragmentToShowEnd < lineEndOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowEnd - 1))) ++fragmentToShowEnd;
while (fragmentToShowStart > lineStartOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowStart))) --fragmentToShowStart;
if (fragmentToShowStart != lineStartOffset)
++fragmentToShowStart;
if (fragmentToShowEnd != lineEndOffset)
--fragmentToShowEnd;
}
}
if (myDocument instanceof DocumentWindow) {
List<TextRange> editable = InjectedLanguageManager.getInstance(file.getProject()).intersectWithAllEditableFragments(file, new TextRange(fragmentToShowStart, fragmentToShowEnd));
for (TextRange range : editable) {
createTextChunks(usageInfo2UsageAdapter, chars, range.getStartOffset(), range.getEndOffset(), true, result);
}
return result.toArray(new TextChunk[result.size()]);
}
return createTextChunks(usageInfo2UsageAdapter, chars, fragmentToShowStart, fragmentToShowEnd, true, result);
}
Aggregations