use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList 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.arguments.GrArgumentList 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.arguments.GrArgumentList in project intellij-community by JetBrains.
the class MyPredicate method getParameterByArgument.
@Nullable
private static GrParameter getParameterByArgument(GrExpression arg) {
PsiElement parent = PsiUtil.skipParentheses(arg.getParent(), true);
if (!(parent instanceof GrArgumentList))
return null;
final GrArgumentList argList = (GrArgumentList) parent;
parent = parent.getParent();
if (!(parent instanceof GrMethodCall))
return null;
final GrMethodCall methodCall = (GrMethodCall) parent;
final GrExpression expression = methodCall.getInvokedExpression();
if (!(expression instanceof GrReferenceExpression))
return null;
final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
if (resolveResult == null)
return null;
GrClosableBlock[] closures = methodCall.getClosureArguments();
final Map<GrExpression, Pair<PsiParameter, PsiType>> mapToParams = GrClosureSignatureUtil.mapArgumentsToParameters(resolveResult, arg, false, false, argList.getNamedArguments(), argList.getExpressionArguments(), closures);
if (mapToParams == null)
return null;
final Pair<PsiParameter, PsiType> parameterPair = mapToParams.get(arg);
final PsiParameter parameter = parameterPair == null ? null : parameterPair.getFirst();
return parameter instanceof GrParameter ? ((GrParameter) parameter) : null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class ConvertJunitAssertionToAssertStatementIntention method getReplacementStatement.
@Nullable
private static String getReplacementStatement(@NotNull PsiMethod method, @NotNull GrMethodCall methodCall) {
PsiClass containingClass = method.getContainingClass();
if (containingClass == null)
return null;
String qualifiedName = containingClass.getQualifiedName();
if (!"junit.framework.Assert".equals(qualifiedName) && !"groovy.util.GroovyTestCase".equals(qualifiedName))
return null;
String[] replacementStatements = ourStatementMap.get(method.getName());
if (replacementStatements == null)
return null;
GrArgumentList argumentList = methodCall.getArgumentList();
if (argumentList.getNamedArguments().length > 0)
return null;
GrExpression[] arguments = argumentList.getExpressionArguments();
if (arguments.length >= replacementStatements.length)
return null;
return replacementStatements[arguments.length];
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class IndexingMethodConversionPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final GrMethodCallExpression callExpression = (GrMethodCallExpression) element;
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
final GrExpression invokedExpression = callExpression.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression)) {
return false;
}
final GrReferenceExpression referenceExpression = (GrReferenceExpression) invokedExpression;
final GrExpression qualifier = referenceExpression.getQualifierExpression();
if (qualifier == null) {
return false;
}
final IElementType referenceType = referenceExpression.getDotTokenType();
if (!GroovyTokenTypes.mDOT.equals(referenceType)) {
return false;
}
final String methodName = referenceExpression.getReferenceName();
if ("getAt".equals(methodName)) {
return arguments.length == 1;
}
if ("get".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 1;
} else if ("setAt".equals(methodName)) {
return arguments.length == 2;
} else if ("put".equals(methodName)) {
final PsiType qualifierType = qualifier.getType();
if (!isMap(qualifierType)) {
return false;
}
return arguments.length == 2;
}
return false;
}
Aggregations