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);
}
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;
}
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();
}
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);
}
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];
}
Aggregations