use of com.intellij.psi.PsiComment 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.PsiComment in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method addFoldingDescriptors.
private static void addFoldingDescriptors(final List<FoldingDescriptor> descriptors, final PsiElement tag, @NotNull Document document) {
TextRange elementRange = tag.getTextRange();
final int start = elementRange.getStartOffset();
final int end = elementRange.getEndOffset();
if (start + 1 < end) {
TextRange range = null;
ASTNode astNode = tag.getNode();
IElementType astType = astNode.getElementType();
if (tag instanceof CfmlTag) {
//if (tag instanceof CfmlTagFunctionImpl || tag instanceof CfmlTagComponentImpl || tag instanceof CfmlTagScriptImpl) {
range = buildRangeForBraces(range, astNode, CfmlTokenTypes.R_ANGLEBRACKET, CfmlTokenTypes.LSLASH_ANGLEBRACKET);
//}
} else if (astType == CfmlElementTypes.FUNCTIONBODY || astType == CfmlElementTypes.BLOCK_OF_STATEMENTS) {
range = buildRange(range, start, end);
} else if (astType == CfmlElementTypes.SWITCHEXPRESSION) {
ASTNode lparen = astNode.findChildByType(CfscriptTokenTypes.L_CURLYBRACKET);
ASTNode rparen = astNode.findChildByType(CfscriptTokenTypes.R_CURLYBRACKET);
if (lparen != null && rparen != null) {
range = buildRange(range, lparen.getStartOffset(), rparen.getTextRange().getEndOffset());
}
} else if (tag instanceof PsiComment) {
boolean isColdFusionComment = astNode.getElementType() == CfmlTokenTypes.COMMENT;
int endIndex = astNode.getText().lastIndexOf(isColdFusionComment ? "--->" : "*/");
if (endIndex != -1) {
String commentText = astNode.getText().substring(0, endIndex);
if (commentText.contains("\n")) {
int startOffset = tag.getTextRange().getStartOffset();
range = buildRange(range, startOffset + (isColdFusionComment ? "<!---" : "/*").length(), startOffset + commentText.length());
}
}
}
if (range != null) {
descriptors.add(new FoldingDescriptor(astNode, range));
}
// TODO: insert condition
addFoldingDescriptorsFromChildren(descriptors, tag, document);
}
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class CfmlFoldingBuilder method isCollapsedByDefault.
public boolean isCollapsedByDefault(@NotNull ASTNode node) {
CodeFoldingSettings settings = CodeFoldingSettings.getInstance();
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
if (element instanceof PsiComment) {
// find out if file header
final ASTNode parent = node.getTreeParent();
ASTNode treePrev = node.getTreePrev();
if (parent.getElementType() == CfmlElementTypes.CFML_FILE && treePrev == null) {
return CodeFoldingSettings.getInstance().COLLAPSE_FILE_HEADER;
} else {
return CodeFoldingSettings.getInstance().COLLAPSE_DOC_COMMENTS;
}
} else if (element instanceof CfmlFunction || node.getElementType() == CfmlElementTypes.FUNCTIONBODY) {
return settings.COLLAPSE_METHODS;
}
return false;
}
use of com.intellij.psi.PsiComment 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;
}
use of com.intellij.psi.PsiComment in project intellij-plugins by JetBrains.
the class DartDocUtil method getDocumentationText.
@Nullable
private static String getDocumentationText(final DartComponent dartComponent) {
// PSI is not perfect currently, doc comment may be not part of the corresponding DartComponent element, so docs are searched for in several places:
// - direct child of this DartComponent
// - previous sibling (or previous sibling of parent element if this element is first child of its parent DartClassMembers)
// Consequent line doc comments (///) are joined
// 1. Look for multiline doc comment as direct child
final DartDocComment multilineComment = PsiTreeUtil.getChildOfType(dartComponent, DartDocComment.class);
if (multilineComment != null)
return getMultilineDocCommentText(multilineComment);
// 2. Look for single line doc comments as direct children
final PsiComment[] childComments = PsiTreeUtil.getChildrenOfType(dartComponent, PsiComment.class);
if (childComments != null) {
//
final String docText = getSingleLineDocCommentsText(childComments);
if (docText != null)
return docText;
}
PsiElement anchorElement = dartComponent;
final PsiElement parent = dartComponent.getParent();
if (parent instanceof DartClassMembers && parent.getFirstChild() == dartComponent || dartComponent instanceof DartVarAccessDeclaration) {
anchorElement = parent;
}
// 3. Look for multiline doc comment or line doc comments as previous siblings
final List<PsiComment> siblingComments = new ArrayList<>();
PsiElement previous = anchorElement;
while ((previous = UsefulPsiTreeUtil.getPrevSiblingSkipWhiteSpaces(previous, true)) instanceof PsiComment) {
if (previous instanceof DartDocComment) {
return getMultilineDocCommentText((DartDocComment) previous);
}
siblingComments.add(0, (PsiComment) previous);
}
if (!siblingComments.isEmpty()) {
return getSingleLineDocCommentsText(siblingComments.toArray(new PsiComment[siblingComments.size()]));
}
return null;
}
Aggregations