use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyBlockGenerator method calculateAlignments.
private void calculateAlignments(List<ASTNode> children, boolean classLevel) {
List<GrStatement> currentGroup = null;
boolean spock = true;
for (ASTNode child : children) {
PsiElement psi = child.getPsi();
if (psi instanceof GrLabeledStatement) {
alignGroup(currentGroup, spock, classLevel);
currentGroup = ContainerUtil.newArrayList();
spock = true;
} else if (currentGroup != null && spock && isTablePart(psi)) {
currentGroup.add((GrStatement) psi);
} else if (psi instanceof GrVariableDeclaration) {
GrVariable[] variables = ((GrVariableDeclaration) psi).getVariables();
if (variables.length > 0) {
if (!classLevel || currentGroup == null || fieldGroupEnded(psi) || spock) {
alignGroup(currentGroup, spock, classLevel);
currentGroup = ContainerUtil.newArrayList();
spock = false;
}
currentGroup.add((GrStatement) psi);
}
} else {
if (shouldSkip(classLevel, psi))
continue;
alignGroup(currentGroup, spock, classLevel);
currentGroup = null;
}
}
if (currentGroup != null) {
alignGroup(currentGroup, spock, classLevel);
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovyIndentProcessor method getChildIndent.
/**
* Calculates indent, based on code style, between parent block and child node
*
* @param parentBlock parent block
* @param child child node
* @return indent
*/
@NotNull
public Indent getChildIndent(@NotNull final GroovyBlock parentBlock, @NotNull final ASTNode child) {
myChildType = child.getElementType();
if (parentBlock instanceof ClosureBodyBlock) {
if (myChildType == GroovyElementTypes.PARAMETERS_LIST) {
return Indent.getNoneIndent();
} else if (myChildType != GroovyTokenTypes.mLCURLY && myChildType != GroovyTokenTypes.mRCURLY) {
return Indent.getNormalIndent();
}
}
if (parentBlock instanceof GrLabelBlock) {
ASTNode first = parentBlock.getNode().getFirstChildNode();
return child == first ? Indent.getNoneIndent() : Indent.getLabelIndent();
}
if (GSTRING_TOKENS_INNER.contains(myChildType)) {
return Indent.getAbsoluteNoneIndent();
}
final PsiElement parent = parentBlock.getNode().getPsi();
if (parent instanceof GroovyPsiElement) {
myBlock = parentBlock;
myChild = child.getPsi();
((GroovyPsiElement) parent).accept(this);
if (myResult != null)
return myResult;
}
return Indent.getNoneIndent();
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class GroovySpacingProcessor method processParentheses.
private boolean processParentheses(@NotNull IElementType left, @NotNull IElementType right, @NotNull Boolean spaceWithin, @Nullable Boolean spaceWithinEmpty, @Nullable Boolean leftLF, @Nullable Boolean rightLF) {
if (myType1 == left && myType2 == right && spaceWithinEmpty != null) {
createSpaceInCode(spaceWithinEmpty);
return true;
} else if (myType1 == left) {
final ASTNode rparenth = findFrom(myChild1, right, true);
if (rparenth == null || leftLF == null) {
createSpaceInCode(spaceWithin);
} else {
final TextRange range = new TextRange(myChild1.getStartOffset(), rparenth.getTextRange().getEndOffset());
createDependentLFSpacing(leftLF, spaceWithin, range);
}
return true;
} else if (myType2 == right) {
final ASTNode lparenth = findFrom(myChild1, left, false);
if (lparenth == null || rightLF == null) {
createSpaceInCode(spaceWithin);
} else {
final TextRange range = new TextRange(lparenth.getStartOffset(), myChild2.getTextRange().getEndOffset());
createDependentLFSpacing(rightLF, spaceWithin, range);
}
return true;
} else {
return false;
}
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class XsltBreakpointHandler method getActualLineNumber.
public static int getActualLineNumber(Project project, @Nullable XSourcePosition position) {
if (position == null) {
return -1;
}
final PsiElement element = findContextElement(project, position);
if (element == null) {
return -1;
}
if (element instanceof XmlToken) {
final IElementType tokenType = ((XmlToken) element).getTokenType();
if (tokenType == XmlTokenType.XML_START_TAG_START || tokenType == XmlTokenType.XML_NAME) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = psiManager.findFile(position.getFile());
if (psiFile == null) {
return -1;
}
final Document document = documentManager.getDocument(psiFile);
if (document == null) {
return -1;
}
if (document.getLineNumber(element.getTextRange().getStartOffset()) == position.getLine()) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
if (tag != null) {
final ASTNode node = tag.getNode();
assert node != null;
// TODO: re-check if/when Xalan is supported
final ASTNode end = XmlChildRole.START_TAG_END_FINDER.findChild(node);
if (end != null) {
return document.getLineNumber(end.getTextRange().getEndOffset()) + 1;
} else {
final ASTNode end2 = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(node);
if (end2 != null) {
return document.getLineNumber(end2.getTextRange().getEndOffset()) + 1;
}
}
}
}
}
}
return -1;
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class YAMLQuotedTextImpl method getContentRanges.
@NotNull
@Override
public List<TextRange> getContentRanges() {
final ASTNode firstContentNode = getFirstContentNode();
if (firstContentNode == null) {
return Collections.emptyList();
}
List<TextRange> result = new ArrayList<>();
TextRange contentRange = TextRange.create(firstContentNode.getStartOffset(), getTextRange().getEndOffset()).shiftRight(-getTextRange().getStartOffset());
final List<String> lines = StringUtil.split(contentRange.substring(getText()), "\n", true, false);
// First line has opening quote
int cumulativeOffset = contentRange.getStartOffset();
for (int i = 0; i < lines.size(); ++i) {
final String line = lines.get(i);
int lineStart = 0;
int lineEnd = line.length();
if (i == 0) {
lineStart++;
} else {
while (lineStart < line.length() && YAMLGrammarCharUtil.isSpaceLike(line.charAt(lineStart))) {
lineStart++;
}
}
if (i == lines.size() - 1) {
// Last line has closing quote
lineEnd--;
} else {
while (lineEnd > lineStart && YAMLGrammarCharUtil.isSpaceLike(line.charAt(lineEnd - 1))) {
lineEnd--;
}
}
result.add(TextRange.create(lineStart, lineEnd).shiftRight(cumulativeOffset));
cumulativeOffset += line.length() + 1;
}
return result;
}
Aggregations