use of com.intellij.psi.PsiElement 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.psi.PsiElement 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.psi.PsiElement in project intellij-community by JetBrains.
the class GroovySpacingProcessor method init.
private boolean init(ASTNode node) {
_init(node);
if (myChild1 == null || myChild2 == null) {
return true;
}
PsiElement psi1 = myChild1.getPsi();
PsiElement psi2 = myChild2.getPsi();
if (psi1 == null || psi2 == null) {
return true;
}
if (psi1.getLanguage() != GroovyLanguage.INSTANCE || psi2.getLanguage() != GroovyLanguage.INSTANCE) {
return true;
}
return false;
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class DemorgansLawIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
GrBinaryExpression exp = (GrBinaryExpression) element;
final IElementType tokenType = exp.getOperationTokenType();
PsiElement parent = exp.getParent();
while (isConjunctionExpression(parent, tokenType)) {
exp = (GrBinaryExpression) parent;
assert exp != null;
parent = exp.getParent();
}
final String newExpression = convertConjunctionExpression(exp, tokenType);
replaceExpressionWithNegatedExpressionString(newExpression, exp);
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class CStyleCommentPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiComment)) {
return false;
}
if (element instanceof PsiDocComment) {
return false;
}
final PsiComment comment = (PsiComment) element;
final IElementType type = comment.getTokenType();
if (!GroovyTokenTypes.mML_COMMENT.equals(type)) {
return false;
}
final PsiElement sibling = PsiTreeUtil.nextLeaf(comment);
if (sibling == null) {
return true;
}
if (!(isWhitespace(sibling))) {
return false;
}
final String whitespaceText = sibling.getText();
return whitespaceText.indexOf((int) '\n') >= 0 || whitespaceText.indexOf((int) '\r') >= 0;
}
Aggregations