Search in sources :

Example 16 with Segment

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;
}
Also used : Segment(com.intellij.openapi.util.Segment)

Example 17 with Segment

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;
}
Also used : Segment(com.intellij.openapi.util.Segment)

Example 18 with Segment

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;
}
Also used : DocumentWindowImpl(com.intellij.injected.editor.DocumentWindowImpl) TextRange(com.intellij.openapi.util.TextRange) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) Segment(com.intellij.openapi.util.Segment) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with Segment

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();
}
Also used : RangeBlinker(com.intellij.util.ui.RangeBlinker) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) Segment(com.intellij.openapi.util.Segment)

Example 20 with Segment

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);
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) Segment(com.intellij.openapi.util.Segment) NotNull(org.jetbrains.annotations.NotNull)

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