Search in sources :

Example 21 with ProperTextRange

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

the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.

public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
    String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
    ((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
    assertTrue(visibleRange.getLength() > 0);
    final Document document = myEditor.getDocument();
    assertTrue(visibleRange.getLength() < document.getTextLength());
    List<HighlightInfo> err1 = highlightErrors();
    HighlightInfo info = assertOneElement(err1);
    final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
    assertEquals(errorDescription, info.getDescription());
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
    final boolean[] errorRemoved = { false };
    model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            Object tt = highlighter.getErrorStripeTooltip();
            if (!(tt instanceof HighlightInfo))
                return;
            String description = ((HighlightInfo) tt).getDescription();
            if (errorDescription.equals(description)) {
                errorRemoved[0] = true;
                List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
                GeneralHighlightingPass ghp = null;
                for (TextEditorHighlightingPass pass : passes) {
                    if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
                        assert ghp == null : ghp;
                        ghp = (GeneralHighlightingPass) pass;
                    }
                }
                assertNotNull(ghp);
                boolean finished = ghp.isFinished();
                assertFalse(finished);
            }
        }
    });
    type("1");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    assertTrue(errorRemoved[0]);
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) ProperTextRange(com.intellij.openapi.util.ProperTextRange) MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 22 with ProperTextRange

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

the class InjectedSelfElementInfo method restoreElement.

@Override
public PsiElement restoreElement() {
    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;
    PsiFile injectedPsi = getInjectedFileIn(hostContext, hostFile, TextRange.create(segment));
    ProperTextRange rangeInInjected = hostToInjected(true, segment, injectedPsi, myAffixOffsets);
    if (rangeInInjected == null)
        return null;
    return myType.findPsiElement(injectedPsi, rangeInInjected.getStartOffset(), rangeInInjected.getEndOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) Segment(com.intellij.openapi.util.Segment)

Example 23 with ProperTextRange

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

the class UsageSerializable method serializeMe.

@Override
public void serializeMe(UsageInfo info, StringBuilder os) throws IOException {
    //final SmartPsiElementPointer<?> pointer = info.getSmartPointer();
    final GenericElementSignatureProvider provider = new GenericElementSignatureProvider();
    final String signature = provider.getSignature(info.getElement());
    append(os, info.getFile().getVirtualFile().getPath());
    os.append(separator);
    append(os, signature);
    os.append(separator);
    final ProperTextRange rangeInElement = info.getRangeInElement();
    if (rangeInElement == null) {
        append(os, "-1");
        os.append(separator);
        append(os, "-1");
        os.append(separator);
    } else {
        append(os, String.valueOf(rangeInElement.getStartOffset()));
        os.append(separator);
        append(os, String.valueOf(rangeInElement.getEndOffset()));
        os.append(separator);
    }
    append(os, String.valueOf(info.isNonCodeUsage()));
    os.append(separator);
    append(os, String.valueOf(info.isDynamicUsage()));
    os.append(separator);
    final String text = new UsageInfo2UsageAdapter(info).getPlainText();
    append(os, text);
    os.append(separator);
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) GenericElementSignatureProvider(com.intellij.codeInsight.folding.impl.GenericElementSignatureProvider)

Example 24 with ProperTextRange

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

the class ShredImpl method getRangeInsideHost.

@Override
@NotNull
public TextRange getRangeInsideHost() {
    PsiLanguageInjectionHost host = getHost();
    Segment psiRange = relevantRangeInHost.getPsiRange();
    TextRange textRange = psiRange == null ? null : TextRange.create(psiRange);
    if (host == null) {
        if (textRange != null)
            return textRange;
        Segment fromSP = hostElementPointer.getPsiRange();
        if (fromSP != null)
            return TextRange.create(fromSP);
        return new TextRange(0, 0);
    }
    TextRange hostTextRange = host.getTextRange();
    textRange = textRange == null ? null : textRange.intersection(hostTextRange);
    if (textRange == null)
        return new ProperTextRange(0, hostTextRange.getLength());
    return textRange.shiftRight(-hostTextRange.getStartOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) Segment(com.intellij.openapi.util.Segment) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with ProperTextRange

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

the class SelectionModelWindow method setSelection.

@Override
public void setSelection(@Nullable VisualPosition startPosition, int startOffset, @Nullable VisualPosition endPosition, int endOffset) {
    TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset));
    myHostModel.setSelection(startPosition, hostRange.getStartOffset(), endPosition, hostRange.getEndOffset());
}
Also used : ProperTextRange(com.intellij.openapi.util.ProperTextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

ProperTextRange (com.intellij.openapi.util.ProperTextRange)31 TextRange (com.intellij.openapi.util.TextRange)14 com.intellij.codeInsight.hint (com.intellij.codeInsight.hint)4 PsiElement (com.intellij.psi.PsiElement)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 Document (com.intellij.openapi.editor.Document)2 Segment (com.intellij.openapi.util.Segment)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 DefaultHighlightInfoProcessor (com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor)1 GeneralHighlightingPass (com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass)1 LocalInspectionsPass (com.intellij.codeInsight.daemon.impl.LocalInspectionsPass)1 EmptyPass (com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.EmptyPass)1 GenericElementSignatureProvider (com.intellij.codeInsight.folding.impl.GenericElementSignatureProvider)1 InspectionManager (com.intellij.codeInspection.InspectionManager)1