use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class FormatterBasedLineIndentInfoBuilder method getBlocksStartingNewLine.
@NotNull
private List<Block> getBlocksStartingNewLine() {
NewLineBlocksIterator newLineBlocksIterator = new NewLineBlocksIterator(myRootBlock, myDocument, myProgressIndicator);
List<Block> newLineBlocks = new ArrayList<>();
int currentLine = 0;
while (newLineBlocksIterator.hasNext() && currentLine < MAX_NEW_LINE_BLOCKS_TO_PROCESS) {
Block next = newLineBlocksIterator.next();
if (next instanceof ASTBlock && ((ASTBlock) next).getNode() instanceof PsiComment) {
continue;
}
newLineBlocks.add(next);
currentLine++;
}
return newLineBlocks;
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class UpdateJavaScriptFileCopyright method scanFile.
protected void scanFile() {
PsiElement first = getFile().getFirstChild();
if (first != null) {
final PsiElement child = first.getFirstChild();
if (child instanceof PsiComment) {
first = child;
}
}
PsiElement last = first;
PsiElement next = first;
while (next != null) {
if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
next = getNextSibling(next);
} else {
break;
}
last = next;
}
if (first != null) {
checkComments(first, last, true);
} else {
checkComments(null, null, true);
}
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class UpdateJspxFileCopyright method scanFile.
protected void scanFile() {
logger.debug("updating " + getFile().getVirtualFile());
XmlDocument doc = ((XmlFile) getFile()).getDocument();
XmlProlog xmlProlog = doc.getProlog();
if (xmlProlog == null) {
return;
}
PsiElement elem = xmlProlog.getFirstChild();
PsiElement docTypeStart = null;
while (elem != null) {
if (elem instanceof XmlDoctype) {
docTypeStart = elem;
break;
}
elem = getNextSibling(elem);
}
PsiElement first = xmlProlog.getFirstChild();
int location = getLanguageOptions().getFileLocation();
if (docTypeStart != null) {
final ArrayList<PsiComment> comments = new ArrayList<>();
collectComments(doc.getFirstChild(), xmlProlog, comments);
collectComments(first, docTypeStart, comments);
checkComments(first, location == XmlOptions.LOCATION_BEFORE_DOCTYPE, comments);
checkComments(docTypeStart, doc.getRootTag(), location == XmlOptions.LOCATION_BEFORE_ROOTTAG);
return;
} else if (location == XmlOptions.LOCATION_BEFORE_DOCTYPE) {
location = XmlOptions.LOCATION_BEFORE_ROOTTAG;
}
final ArrayList<PsiComment> comments = new ArrayList<>();
collectComments(doc.getFirstChild(), xmlProlog, comments);
collectComments(first, doc.getRootTag(), comments);
checkComments(doc.getRootTag(), location == XmlOptions.LOCATION_BEFORE_ROOTTAG, comments);
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class TopLevelMatchingHandler method match.
@Override
public boolean match(final PsiElement patternNode, final PsiElement matchedNode, final MatchContext matchContext) {
final boolean matched = delegate.match(patternNode, matchedNode, matchContext);
if (matched) {
List<PsiElement> matchedNodes = matchContext.getMatchedNodes();
if (matchedNodes == null) {
matchedNodes = new ArrayList<>();
matchContext.setMatchedNodes(matchedNodes);
}
PsiElement elementToAdd = matchedNode;
if (patternNode instanceof PsiComment && StructuralSearchUtil.isDocCommentOwner(matchedNode)) {
// psicomment and psidoccomment are placed inside the psimember next to them so
// simple topdown matching should do additional "dances" to cover this case.
elementToAdd = matchedNode.getFirstChild();
assert elementToAdd instanceof PsiComment;
}
matchedNodes.add(elementToAdd);
}
if ((!matched || matchContext.getOptions().isRecursiveSearch()) && matchContext.getPattern().getStrategy().continueMatching(matchedNode) && matchContext.shouldRecursivelyMatch()) {
matchContext.getMatcher().matchContext(new SsrFilteringNodeIterator(new SiblingNodeIterator(matchedNode.getFirstChild())));
}
return matched;
}
use of com.intellij.psi.PsiComment in project intellij-community by JetBrains.
the class JsonLineMover method checkAvailable.
@Override
public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) {
myShouldAddComma = false;
if (!(file instanceof JsonFile) || !super.checkAvailable(editor, file, info, down)) {
return false;
}
Pair<PsiElement, PsiElement> movedElementRange = getElementRange(editor, file, info.toMove);
if (!isValidElementRange(movedElementRange)) {
return false;
}
// Tweak range to move if it's necessary
movedElementRange = expandCommentsInRange(movedElementRange);
info.toMove = new LineRange(movedElementRange.getFirst(), movedElementRange.getSecond());
// Adjust destination range to prevent illegal offsets
final int lineCount = editor.getDocument().getLineCount();
if (down) {
info.toMove2 = new LineRange(info.toMove.endLine, Math.min(info.toMove.endLine + 1, lineCount));
} else {
info.toMove2 = new LineRange(Math.max(info.toMove.startLine - 1, 0), info.toMove.startLine);
}
if (movedElementRange.getFirst() instanceof PsiComment && movedElementRange.getSecond() instanceof PsiComment) {
return true;
}
// Check whether additional comma is needed
final Pair<PsiElement, PsiElement> destElementRange = getElementRange(editor, file, info.toMove2);
if (isValidElementRange(destElementRange) && movedElementRange.getFirst().getParent() == destElementRange.getSecond().getParent()) {
final PsiElement commonParent = movedElementRange.getFirst().getParent();
final PsiElement lowerRightElement = down ? destElementRange.getSecond() : movedElementRange.getSecond();
// Destination rightmost element is not closing brace or bracket
if (lowerRightElement instanceof JsonElement) {
if (commonParent instanceof JsonArray && notFollowedByNextElementOrComma(lowerRightElement, JsonValue.class) || commonParent instanceof JsonObject && notFollowedByNextElementOrComma(lowerRightElement, JsonProperty.class)) {
myShouldAddComma = true;
}
}
}
return true;
}
Aggregations