use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ImplicitClosureCallPredicate method satisfiedBy.
@Override
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof GrMethodCallExpression)) {
return false;
}
final GrMethodCallExpression call = (GrMethodCallExpression) element;
final GrExpression invokedExpression = call.getInvokedExpression();
if (invokedExpression == null) {
return false;
}
final PsiType type = invokedExpression.getType();
if (type == null) {
return false;
}
if (!type.equalsToText(GroovyCommonClassNames.GROOVY_LANG_CLOSURE)) {
return false;
}
return !ErrorUtil.containsError(element);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class MakeClosureCallImplicitIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrMethodCallExpression expression = (GrMethodCallExpression) element;
final GrReferenceExpression invokedExpression = (GrReferenceExpression) expression.getInvokedExpression();
final GrExpression qualifier = invokedExpression.getQualifierExpression();
final GrArgumentList argList = expression.getArgumentList();
final GrClosableBlock[] closureArgs = expression.getClosureArguments();
final StringBuilder newExpression = new StringBuilder();
newExpression.append(qualifier.getText());
newExpression.append(argList.getText());
for (GrClosableBlock closureArg : closureArgs) {
newExpression.append(closureArg.getText());
}
PsiImplUtil.replaceExpression(newExpression.toString(), expression);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class NewGantScriptAction method doCreate.
@Override
@NotNull
protected PsiElement[] doCreate(String newName, PsiDirectory directory) throws Exception {
PsiFile file = createGantScriptFromTemplate(directory, newName, GroovyTemplates.GANT_SCRIPT);
PsiElement lastChild = file.getLastChild();
PsiElement child = null;
if (lastChild instanceof GrMethodCallExpression) {
child = lastChild;
}
if (child == null && file.getChildren().length > 0) {
child = file.getLastChild();
}
return child != null ? new PsiElement[] { file, child } : new PsiElement[] { file };
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class OldReferencesResolver method canRemoveQualifier.
private static boolean canRemoveQualifier(GrReferenceExpression refExpr) {
try {
GrExpression qualifier = refExpr.getQualifier();
if (!(qualifier instanceof GrReferenceExpression))
return false;
PsiElement qualifierRefElement = ((GrReferenceExpression) qualifier).resolve();
if (!(qualifierRefElement instanceof PsiClass))
return false;
PsiElement refElement = refExpr.resolve();
if (refElement == null)
return false;
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(refExpr.getProject());
if (refExpr.getParent() instanceof GrMethodCallExpression) {
GrMethodCallExpression methodCall = (GrMethodCallExpression) refExpr.getParent();
GrMethodCallExpression newMethodCall = (GrMethodCallExpression) factory.createExpressionFromText(refExpr.getReferenceName() + "()", refExpr);
newMethodCall.getArgumentList().replace(methodCall.getArgumentList());
PsiElement newRefElement = ((GrReferenceExpression) newMethodCall.getInvokedExpression()).resolve();
return refElement.equals(newRefElement);
} else {
GrReferenceExpression newRefExpr = (GrReferenceExpression) factory.createExpressionFromText(refExpr.getReferenceName(), refExpr);
PsiElement newRefElement = newRefExpr.resolve();
return refElement.equals(newRefElement);
}
} catch (IncorrectOperationException e) {
return false;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project intellij-community by JetBrains.
the class ConvertConcatenationToGstringIntention method isToStringMethod.
/**
* append text to builder if the operand is 'something'.toString()
*/
private static boolean isToStringMethod(GrExpression operand, StringBuilder builder) {
if (!(operand instanceof GrMethodCallExpression))
return false;
final GrExpression expression = ((GrMethodCallExpression) operand).getInvokedExpression();
if (!(expression instanceof GrReferenceExpression))
return false;
final GrReferenceExpression refExpr = (GrReferenceExpression) expression;
final GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null)
return false;
final GroovyResolveResult[] results = refExpr.multiResolve(false);
if (results.length != 1)
return false;
final PsiElement element = results[0].getElement();
if (!(element instanceof PsiMethod))
return false;
final PsiMethod method = (PsiMethod) element;
final PsiClass objectClass = JavaPsiFacade.getInstance(operand.getProject()).findClass(CommonClassNames.JAVA_LANG_OBJECT, operand.getResolveScope());
if (objectClass == null)
return false;
final PsiMethod[] toStringMethod = objectClass.findMethodsByName("toString", true);
if (MethodSignatureUtil.isSubsignature(toStringMethod[0].getHierarchicalMethodSignature(), method.getHierarchicalMethodSignature())) {
builder.append(START_BRACE).append(qualifier.getText()).append(END_BRACE);
return true;
}
return false;
}
Aggregations