Search in sources :

Example 91 with TextRange

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

the class XmlEncodingReferenceProvider method xmlAttributeValueRange.

protected static TextRange xmlAttributeValueRange(final XmlAttributeValue xmlAttributeValue) {
    ASTNode valueNode = XmlChildRole.ATTRIBUTE_VALUE_VALUE_FINDER.findChild(xmlAttributeValue.getNode());
    PsiElement toHighlight = valueNode == null ? xmlAttributeValue : valueNode.getPsi();
    TextRange childRange = toHighlight.getTextRange();
    TextRange range = xmlAttributeValue.getTextRange();
    return childRange.shiftRight(-range.getStartOffset());
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 92 with TextRange

use of com.intellij.openapi.util.TextRange in project kotlin by JetBrains.

the class DiagnosticUtils method sortedDiagnostics.

@NotNull
public static List<Diagnostic> sortedDiagnostics(@NotNull Collection<Diagnostic> diagnostics) {
    Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {

        @Override
        public int compare(@NotNull Diagnostic d1, @NotNull Diagnostic d2) {
            String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
            String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
            if (!path1.equals(path2))
                return path1.compareTo(path2);
            TextRange range1 = firstRange(d1.getTextRanges());
            TextRange range2 = firstRange(d2.getTextRanges());
            if (!range1.equals(range2)) {
                return TEXT_RANGE_COMPARATOR.compare(range1, range2);
            }
            return d1.getFactory().getName().compareTo(d2.getFactory().getName());
        }
    };
    List<Diagnostic> result = Lists.newArrayList(diagnostics);
    Collections.sort(result, diagnosticComparator);
    return result;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with TextRange

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

the class GroovyMethodInliner method inlineUsage.

@Override
public void inlineUsage(@NotNull UsageInfo usage, @NotNull PsiElement referenced) {
    PsiElement element = usage.getElement();
    if (!(element instanceof GrExpression && element.getParent() instanceof GrCallExpression))
        return;
    final Editor editor = getCurrentEditorIfApplicable(element);
    GrCallExpression call = (GrCallExpression) element.getParent();
    RangeMarker marker = inlineReferenceImpl(call, myMethod, isOnExpressionOrReturnPlace(call), GroovyInlineMethodUtil.isTailMethodCall(call), editor);
    // highlight replaced result
    if (marker != null) {
        Project project = referenced.getProject();
        TextRange range = TextRange.create(marker);
        GroovyRefactoringUtil.highlightOccurrencesByRanges(project, editor, new TextRange[] { range });
        WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting"));
        if (editor != null) {
            editor.getCaretModel().moveToOffset(marker.getEndOffset());
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GrCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) TextRange(com.intellij.openapi.util.TextRange) RangeMarker(com.intellij.openapi.editor.RangeMarker) Editor(com.intellij.openapi.editor.Editor)

Example 94 with TextRange

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

the class GrInplaceParameterIntroducer method updateTitle.

@Override
protected void updateTitle(@Nullable GrVariable variable, String value) {
    if (getPreviewEditor() == null || variable == null)
        return;
    final PsiElement declarationScope = ((PsiParameter) variable).getDeclarationScope();
    if (declarationScope instanceof PsiMethod) {
        final PsiMethod psiMethod = (PsiMethod) declarationScope;
        final StringBuilder buf = new StringBuilder();
        buf.append(psiMethod.getName()).append(" (");
        boolean frst = true;
        final List<TextRange> ranges2Remove = new ArrayList<>();
        TextRange addedRange = null;
        int i = 0;
        for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
            if (frst) {
                frst = false;
            } else {
                buf.append(", ");
            }
            int startOffset = buf.length();
            /*if (myMustBeFinal || myPanel.isGenerateFinal()) {
          buf.append("final ");
        }*/
            buf.append(parameter.getType().getPresentableText()).append(" ").append(variable == parameter ? value : parameter.getName());
            int endOffset = buf.length();
            if (variable == parameter) {
                addedRange = new TextRange(startOffset, endOffset);
            } else if (myParametersToRemove.contains(i)) {
                ranges2Remove.add(new TextRange(startOffset, endOffset));
            }
            i++;
        }
        assert addedRange != null;
        buf.append(")");
        setPreviewText(buf.toString());
        final MarkupModel markupModel = DocumentMarkupModel.forDocument(getPreviewEditor().getDocument(), myProject, true);
        markupModel.removeAllHighlighters();
        for (TextRange textRange : ranges2Remove) {
            markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), 0, getTestAttributesForRemoval(), HighlighterTargetArea.EXACT_RANGE);
        }
        markupModel.addRangeHighlighter(addedRange.getStartOffset(), addedRange.getEndOffset(), 0, getTextAttributesForAdd(), HighlighterTargetArea.EXACT_RANGE);
    //revalidate();
    }
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) TextRange(com.intellij.openapi.util.TextRange) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) PsiElement(com.intellij.psi.PsiElement)

Example 95 with TextRange

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

the class ExtractUtil method getRangeOfRefactoring.

public static TextRange getRangeOfRefactoring(ExtractInfoHelper helper) {
    final StringPartInfo stringPartInfo = helper.getStringPartInfo();
    if (stringPartInfo != null) {
        return stringPartInfo.getRange();
    } else {
        final GrStatement[] statements = helper.getStatements();
        int start = statements[0].getTextRange().getStartOffset();
        int end = statements[statements.length - 1].getTextRange().getEndOffset();
        return new TextRange(start, end);
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1314 PsiElement (com.intellij.psi.PsiElement)261 NotNull (org.jetbrains.annotations.NotNull)237 Nullable (org.jetbrains.annotations.Nullable)167 Document (com.intellij.openapi.editor.Document)132 ArrayList (java.util.ArrayList)117 Project (com.intellij.openapi.project.Project)96 PsiFile (com.intellij.psi.PsiFile)96 ASTNode (com.intellij.lang.ASTNode)95 Editor (com.intellij.openapi.editor.Editor)75 PsiReference (com.intellij.psi.PsiReference)54 VirtualFile (com.intellij.openapi.vfs.VirtualFile)51 IElementType (com.intellij.psi.tree.IElementType)48 IncorrectOperationException (com.intellij.util.IncorrectOperationException)48 Pair (com.intellij.openapi.util.Pair)47 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)33 ProperTextRange (com.intellij.openapi.util.ProperTextRange)32 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)31 XmlTag (com.intellij.psi.xml.XmlTag)31 List (java.util.List)31