use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList in project intellij-community by JetBrains.
the class GroovyBlock method getChildAttributes.
@Override
@NotNull
public ChildAttributes getChildAttributes(final int newChildIndex) {
ASTNode astNode = getNode();
final PsiElement psiParent = astNode.getPsi();
if (psiParent instanceof GroovyFileBase) {
return new ChildAttributes(Indent.getNoneIndent(), null);
}
if (psiParent instanceof GrSwitchStatement) {
List<Block> subBlocks = getSubBlocks();
if (newChildIndex > 0) {
Block block = subBlocks.get(newChildIndex - 1);
if (block instanceof GroovyBlock) {
PsiElement anchorPsi = ((GroovyBlock) block).getNode().getPsi();
if (anchorPsi instanceof GrCaseSection) {
for (GrStatement statement : ((GrCaseSection) anchorPsi).getStatements()) {
if (statement instanceof GrBreakStatement || statement instanceof GrContinueStatement || statement instanceof GrReturnStatement || statement instanceof GrThrowStatement) {
final Indent indent = GroovyIndentProcessor.getSwitchCaseIndent(myContext.getSettings());
return new ChildAttributes(indent, null);
}
}
int indentSize = myContext.getSettings().getIndentOptions().INDENT_SIZE;
final int spaces = myContext.getSettings().INDENT_CASE_FROM_SWITCH ? 2 * indentSize : indentSize;
return new ChildAttributes(Indent.getSpaceIndent(spaces), null);
}
}
}
}
if (psiParent instanceof GrCaseLabel) {
return new ChildAttributes(GroovyIndentProcessor.getSwitchCaseIndent(getContext().getSettings()), null);
}
if (psiParent instanceof GrCaseSection) {
return getSwitchIndent((GrCaseSection) psiParent, newChildIndex);
}
if (TokenSets.BLOCK_SET.contains(astNode.getElementType()) || GroovyElementTypes.SWITCH_STATEMENT.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (GroovyElementTypes.CASE_SECTION.equals(astNode.getElementType())) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrBinaryExpression || psiParent instanceof GrConditionalExpression || psiParent instanceof GrCommandArgumentList || psiParent instanceof GrArgumentList || psiParent instanceof GrParameterList || psiParent instanceof GrListOrMap || psiParent instanceof GrAnnotationArgumentList || psiParent instanceof GrVariable || psiParent instanceof GrAssignmentExpression) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
}
if (psiParent instanceof GrDocComment || psiParent instanceof GrDocTag) {
return new ChildAttributes(Indent.getSpaceIndent(GroovyIndentProcessor.GDOC_COMMENT_INDENT), null);
}
if (psiParent instanceof GrIfStatement || psiParent instanceof GrLoopStatement) {
return new ChildAttributes(Indent.getNormalIndent(), null);
}
if (psiParent instanceof GrLabeledStatement && newChildIndex == 2) {
final Indent indent = getContext().getGroovySettings().INDENT_LABEL_BLOCKS ? Indent.getLabelIndent() : Indent.getNoneIndent();
return new ChildAttributes(indent, null);
}
return new ChildAttributes(Indent.getNoneIndent(), null);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList in project intellij-community by JetBrains.
the class GrMethodCallFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement psiElement) {
final GrArgumentList argList = psiElement instanceof GrCall ? ((GrCall) psiElement).getArgumentList() : null;
if (argList == null || argList instanceof GrCommandArgumentList)
return;
GrCall call = (GrCall) psiElement;
PsiElement parenth = argList.getLastChild();
if (parenth != null && ")".equals(parenth.getText()) || PsiImplUtil.hasClosureArguments(call))
return;
int endOffset = -1;
for (PsiElement child = argList.getFirstChild(); child != null; child = child.getNextSibling()) {
if (!(child instanceof PsiErrorElement))
continue;
final PsiErrorElement errorElement = (PsiErrorElement) child;
if (errorElement.getErrorDescription().contains("')'")) {
endOffset = errorElement.getTextRange().getStartOffset();
break;
}
}
if (endOffset == -1) {
endOffset = argList.getTextRange().getEndOffset();
}
final GrExpression[] params = argList.getExpressionArguments();
if (params.length > 0 && GrForBodyFixer.startLine(editor.getDocument(), argList) != GrForBodyFixer.startLine(editor.getDocument(), params[0])) {
endOffset = argList.getTextRange().getStartOffset() + 1;
}
endOffset = CharArrayUtil.shiftBackward(editor.getDocument().getCharsSequence(), endOffset - 1, " \t\n") + 1;
editor.getDocument().insertString(endOffset, ")");
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList in project intellij-community by JetBrains.
the class GroovyShellCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
if (!(file instanceof GroovyShellCodeFragment))
return;
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (!(parent instanceof GrReferenceExpression && !((GrReferenceExpression) parent).isQualified()))
return;
if (PsiUtil.isExpressionStatement(parent)) {
addAllCommands(result);
} else if (parent.getParent() instanceof GrCommandArgumentList) {
PsiElement ppparent = parent.getParent().getParent();
if (ppparent instanceof GrMethodCall && isFirstArg((GrMethodCall) ppparent, parent)) {
GrExpression invokedExpression = ((GrMethodCall) ppparent).getInvokedExpression();
if (invokedExpression instanceof GrReferenceExpression && !((GrReferenceExpression) invokedExpression).isQualified()) {
String name = ((GrReferenceExpression) invokedExpression).getReferenceName();
if ("help".equals(name)) {
addAllCommands(result);
} else if ("show".equals(name)) {
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("purge".equals(name)) {
add(result, "variables");
add(result, "classes");
add(result, "imports");
add(result, "preferences");
add(result, "all");
} else if ("record".equals(name)) {
add(result, "start");
add(result, "stop");
add(result, "status");
} else if ("history".equals(name)) {
add(result, "show");
add(result, "recall");
add(result, "flush");
add(result, "clear");
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList in project android by JetBrains.
the class AndroidGradleSpellcheckingStrategy method isPrint.
private static boolean isPrint(PsiElement element) {
PsiElement parent0 = element.getParent();
if (parent0 == null) {
return false;
}
PsiElement parent1 = parent0.getParent();
if (parent1 == null) {
return false;
}
PsiElement parent2 = parent1.getParent();
if (parent2 == null) {
return false;
}
if (parent2 instanceof GrCommandArgumentList) {
parent2 = parent2.getParent();
}
if (parent2 instanceof GrApplicationStatement) {
GrApplicationStatement call = (GrApplicationStatement) parent2;
GrExpression propertyExpression = call.getInvokedExpression();
if (propertyExpression instanceof GrReferenceExpression) {
GrReferenceExpression propertyRef = (GrReferenceExpression) propertyExpression;
String property = propertyRef.getReferenceName();
if ("print".equals(property) || "println".equals(property)) {
return true;
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList in project android by JetBrains.
the class GradleDslLiteral method apply.
@Override
protected void apply() {
GroovyPsiElement psiElement = getPsiElement();
if (psiElement == null) {
return;
}
GrLiteral newLiteral = createLiteral();
if (newLiteral == null) {
return;
}
if (myExpression != null) {
PsiElement replace = myExpression.replace(newLiteral);
if (replace instanceof GrLiteral) {
myExpression = (GrLiteral) replace;
}
} else {
PsiElement added;
if (// Entries in [].
psiElement instanceof GrListOrMap || (psiElement instanceof GrArgumentList && !(psiElement instanceof GrCommandArgumentList))) {
// Method call arguments in ().
// add before ) or ]
added = psiElement.addBefore(newLiteral, psiElement.getLastChild());
} else {
added = psiElement.addAfter(newLiteral, psiElement.getLastChild());
}
if (added instanceof GrLiteral) {
myExpression = (GrLiteral) added;
}
if (myUnsavedConfigBlock != null) {
addConfigBlock();
}
}
}
Aggregations