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-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;
}
Aggregations