use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyBlockGenerator method alignVariableDeclarations.
private void alignVariableDeclarations(List<GrStatement> group, boolean classLevel) {
AlignmentProvider.Aligner typeElement = myAlignmentProvider.createAligner(true);
AlignmentProvider.Aligner varName = myAlignmentProvider.createAligner(true);
AlignmentProvider.Aligner eq = myAlignmentProvider.createAligner(true);
for (GrStatement statement : group) {
GrVariableDeclaration varDeclaration = (GrVariableDeclaration) statement;
GrVariable[] variables = varDeclaration.getVariables();
for (GrVariable variable : variables) {
varName.append(variable.getNameIdentifierGroovy());
}
if (classLevel && myContext.getSettings().ALIGN_GROUP_FIELD_DECLARATIONS) {
typeElement.append(varDeclaration.getTypeElementGroovy());
ASTNode current_eq = variables[variables.length - 1].getNode().findChildByType(GroovyTokenTypes.mASSIGN);
if (current_eq != null) {
eq.append(current_eq.getPsi());
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyBlockGenerator method alignSpockTable.
private void alignSpockTable(List<GrStatement> group) {
if (group.size() < 2) {
return;
}
GrStatement inner = group.get(0);
boolean embedded = inner != null && isTablePart(inner);
GrStatement first = embedded ? inner : group.get(1);
List<AlignmentProvider.Aligner> alignments = ContainerUtil.map2List(getSpockTable(first), leaf -> myAlignmentProvider.createAligner(leaf, true, Alignment.Anchor.RIGHT));
int second = embedded ? 1 : 2;
for (int i = second; i < group.size(); i++) {
List<LeafPsiElement> table = getSpockTable(group.get(i));
for (int j = 0; j < Math.min(table.size(), alignments.size()); j++) {
alignments.get(j).append(table.get(j));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class UpdateGroovyCopyrightsProvider method createInstance.
@Override
public UpdateCopyright createInstance(Project project, Module module, VirtualFile file, FileType base, CopyrightProfile options) {
return new UpdateJavaFileCopyright(project, module, file, options) {
@Override
protected boolean accept() {
return getFile() instanceof GroovyFile;
}
@Override
protected PsiElement[] getImportsList() {
return ((GroovyFile) getFile()).getImportStatements();
}
@Override
protected PsiElement getPackageStatement() {
return ((GroovyFile) getFile()).getPackageDefinition();
}
@Override
protected void checkCommentsForTopClass(PsiClass topclass, int location, List<PsiComment> comments) {
if (!(topclass instanceof GroovyScriptClass)) {
super.checkCommentsForTopClass(topclass, location, comments);
return;
}
final GroovyFile containingFile = (GroovyFile) topclass.getContainingFile();
PsiElement last = containingFile.getFirstChild();
while (last != null && !(last instanceof GrStatement)) {
last = last.getNextSibling();
}
checkComments(last, location == JavaOptions.LOCATION_BEFORE_CLASS, comments);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GrJoinLinesHandlerBase method skipSemicolonsAndWhitespaces.
@Nullable
private static GrStatement skipSemicolonsAndWhitespaces(PsiElement child, boolean forward) {
while (child != null && !(child instanceof GrStatement)) {
final IElementType type = child.getNode().getElementType();
if (type != GroovyTokenTypes.mSEMI && !(type == TokenType.WHITE_SPACE && !child.getText().contains("\n")))
return null;
child = forward ? child.getNextSibling() : child.getPrevSibling();
}
return (GrStatement) child;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GrJoinLinesHandlerBase method tryJoinRawLines.
@Override
public int tryJoinRawLines(Document document, PsiFile file, int start, int end) {
if (!(file instanceof GroovyFileBase))
return CANNOT_JOIN;
final PsiElement element = file.findElementAt(end);
final GrStatementOwner statementOwner = PsiTreeUtil.getParentOfType(element, GrStatementOwner.class, true, GroovyFileBase.class);
if (statementOwner == null)
return CANNOT_JOIN;
GrStatement first = null;
GrStatement last = null;
for (PsiElement child = statementOwner.getFirstChild(); child != null; child = child.getNextSibling()) {
final TextRange range = child.getTextRange();
if (range.getEndOffset() == start) {
first = skipSemicolonsAndWhitespaces(child, BACK);
} else if (range.getStartOffset() == end) {
last = skipSemicolonsAndWhitespaces(child, FORWARD);
}
}
if (last == null || first == null)
return CANNOT_JOIN;
return tryJoinStatements(first, last);
}
Aggregations