Search in sources :

Example 21 with PsiWhiteSpace

use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.

the class PsiEquivalenceUtil method getFilteredChildren.

@NotNull
public static PsiElement[] getFilteredChildren(@NotNull final PsiElement element, @Nullable Condition<PsiElement> isElementSignificantCondition, boolean areCommentsSignificant) {
    ASTNode[] children1 = element.getNode().getChildren(null);
    ArrayList<PsiElement> array = new ArrayList<>();
    for (ASTNode node : children1) {
        final PsiElement child = node.getPsi();
        if (!(child instanceof PsiWhiteSpace) && (areCommentsSignificant || !(child instanceof PsiComment)) && (isElementSignificantCondition == null || isElementSignificantCondition.value(child))) {
            array.add(child);
        }
    }
    return PsiUtilCore.toPsiElementArray(array);
}
Also used : PsiComment(com.intellij.psi.PsiComment) ASTNode(com.intellij.lang.ASTNode) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with PsiWhiteSpace

use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.

the class ConvertAbsolutePathToRelativeIntentionAction method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement element = file.findElementAt(offset);
    if (element == null || element instanceof PsiWhiteSpace) {
        return false;
    }
    final PsiReference reference = file.findReferenceAt(offset);
    final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);
    if (fileReference != null) {
        final FileReferenceSet set = fileReference.getFileReferenceSet();
        final FileReference lastReference = set.getLastReference();
        return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null && (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) && lastReference.resolve() != null;
    }
    return false;
}
Also used : PsiReference(com.intellij.psi.PsiReference) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 23 with PsiWhiteSpace

use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.

the class JavaImplementationTextSelectioner method getTextStartOffset.

@Override
public int getTextStartOffset(@NotNull final PsiElement parent) {
    PsiElement element = parent;
    if (element instanceof PsiDocCommentOwner) {
        PsiDocComment comment = ((PsiDocCommentOwner) element).getDocComment();
        if (comment != null) {
            element = comment.getNextSibling();
            while (element instanceof PsiWhiteSpace) {
                element = element.getNextSibling();
            }
        }
    }
    if (element != null) {
        TextRange range = element.getTextRange();
        if (range != null) {
            return range.getStartOffset();
        }
        LOG.error("Range should not be null: " + element + "; " + element.getClass());
    }
    LOG.error("Element should not be null: " + parent.getText());
    return parent.getTextRange().getStartOffset();
}
Also used : PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) PsiDocCommentOwner(com.intellij.psi.PsiDocCommentOwner) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 24 with PsiWhiteSpace

use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.

the class XmlSurroundWithRangeAdjuster method adjustSurroundWithRange.

@Override
public TextRange adjustSurroundWithRange(final PsiFile file, final TextRange selectedRange) {
    if (!(file instanceof XmlFile))
        return selectedRange;
    int startOffset = selectedRange.getStartOffset();
    int endOffset = selectedRange.getEndOffset();
    PsiElement element1 = file.findElementAt(startOffset);
    PsiElement element2 = file.findElementAt(endOffset - 1);
    Language lang1 = getLanguage(element1);
    Language lang2 = getLanguage(element2);
    if (element1 instanceof PsiWhiteSpace && isLanguageWithWSSignificant(lang1)) {
        startOffset = element1.getTextRange().getEndOffset();
        element1 = file.findElementAt(startOffset);
    }
    if (element2 instanceof PsiWhiteSpace && isLanguageWithWSSignificant(lang2)) {
        endOffset = element2.getTextRange().getStartOffset();
        element2 = file.findElementAt(endOffset);
    }
    lang1 = getLanguage(element1);
    lang2 = getLanguage(element2);
    if (lang1 != lang2)
        return null;
    TextRange.assertProperRange(startOffset, endOffset, "Wrong offsets for " + selectedRange.substring(file.getText()));
    return new TextRange(startOffset, endOffset);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 25 with PsiWhiteSpace

use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.

the class DartMethodLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    if (!myDaemonSettings.SHOW_METHOD_SEPARATORS) {
        return null;
    }
    // only continue if element is one of the markable elements (such as methods)
    if (isMarkableElement(element)) {
        // the method line markers are not nestable, aka, methods inside of methods, are not marked
        if (PsiTreeUtil.findFirstParent(element, true, DartMethodLineMarkerProvider::isMarkableElement) != null) {
            return null;
        }
        // move the marker to previous siblings until comments have been included
        PsiElement markerLocation = element;
        while (markerLocation.getPrevSibling() != null && (markerLocation.getPrevSibling() instanceof PsiComment || (markerLocation.getPrevSibling() instanceof PsiWhiteSpace && markerLocation.getPrevSibling().getPrevSibling() != null && markerLocation.getPrevSibling().getPrevSibling() instanceof PsiComment))) {
            markerLocation = markerLocation.getPrevSibling();
        }
        // if the markerLocation element doesn't have a previous sibling (not whitespace), do not mark
        PsiElement prevElement = markerLocation;
        while (prevElement.getPrevSibling() != null && prevElement.getPrevSibling() instanceof PsiWhiteSpace) {
            prevElement = prevElement.getPrevSibling();
        }
        if (prevElement.getPrevSibling() == null) {
            return null;
        }
        // finally, create the marker
        LineMarkerInfo info = new LineMarkerInfo<>(markerLocation, markerLocation.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
        EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
        info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
        info.separatorPlacement = SeparatorPlacement.TOP;
        return info;
    }
    return null;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PsiComment(com.intellij.psi.PsiComment) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)90 PsiElement (com.intellij.psi.PsiElement)82 TextRange (com.intellij.openapi.util.TextRange)23 ASTNode (com.intellij.lang.ASTNode)15 PsiFile (com.intellij.psi.PsiFile)15 NotNull (org.jetbrains.annotations.NotNull)15 Nullable (org.jetbrains.annotations.Nullable)14 PsiComment (com.intellij.psi.PsiComment)13 IElementType (com.intellij.psi.tree.IElementType)13 Document (com.intellij.openapi.editor.Document)12 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)6 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)5 Editor (com.intellij.openapi.editor.Editor)5 Language (com.intellij.lang.Language)4 UnfairTextRange (com.intellij.openapi.util.UnfairTextRange)4 XmlTag (com.intellij.psi.xml.XmlTag)4 XMLLanguage (com.intellij.lang.xml.XMLLanguage)3 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)3 XmlFile (com.intellij.psi.xml.XmlFile)3