Search in sources :

Example 26 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 27 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 28 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 29 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 30 with PsiWhiteSpace

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

the class ReplacerUtil method copySpacesAndCommentsBefore.

public static PsiElement copySpacesAndCommentsBefore(PsiElement elementToReplace, PsiElement[] patternElements, String replacementToMake, PsiElement elementParent) {
    int i = 0;
    while (true) {
        // if it goes out of bounds then deep error happens
        if (!(patternElements[i] instanceof PsiComment || patternElements[i] instanceof PsiWhiteSpace)) {
            break;
        }
        ++i;
        if (patternElements.length == i) {
            break;
        }
    }
    if (patternElements.length == i) {
        Logger logger = Logger.getInstance(StructuralSearchProfile.class.getName());
        logger.error("Unexpected replacement structure:" + replacementToMake);
    }
    if (i != 0) {
        elementParent.addRangeBefore(patternElements[0], patternElements[i - 1], elementToReplace);
    }
    return patternElements[i];
}
Also used : PsiComment(com.intellij.psi.PsiComment) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile) Logger(com.intellij.openapi.diagnostic.Logger) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

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