use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GroovyIntroduceParameterObjectDelegate method createNewParameterInitializerAtCallSite.
@Override
public PsiElement createNewParameterInitializerAtCallSite(PsiElement callExpression, IntroduceParameterObjectClassDescriptor descriptor, List<? extends ParameterInfo> oldMethodParameters, Object substitutor) {
if (callExpression instanceof GrCallExpression) {
final GrArgumentList list = ((GrCallExpression) callExpression).getArgumentList();
if (list == null) {
return null;
}
final GrExpression[] args = list.getExpressionArguments();
final String qualifiedName = StringUtil.getQualifiedName(descriptor.getPackageName(), descriptor.getClassName());
String newExpression = "new " + qualifiedName + '(' + JavaIntroduceParameterObjectDelegate.getMergedArgs(descriptor, oldMethodParameters, args) + ')';
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(callExpression.getProject());
return factory.createExpressionFromText(newExpression, callExpression);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class JavaStylePropertiesUtil method isSetterInvocation.
private static boolean isSetterInvocation(GrMethodCall call) {
GrExpression expr = call.getInvokedExpression();
if (!(expr instanceof GrReferenceExpression))
return false;
GrReferenceExpression refExpr = (GrReferenceExpression) expr;
PsiMethod method;
if (call instanceof GrApplicationStatement) {
PsiElement element = refExpr.resolve();
if (!(element instanceof PsiMethod) || !GroovyPropertyUtils.isSimplePropertySetter(((PsiMethod) element)))
return false;
method = (PsiMethod) element;
} else {
method = call.resolveMethod();
if (!GroovyPropertyUtils.isSimplePropertySetter(method))
return false;
LOG.assertTrue(method != null);
}
if (!GroovyNamesUtil.isValidReference(GroovyPropertyUtils.getPropertyNameBySetterName(method.getName()), ((GrReferenceExpression) expr).getQualifier() != null, call.getProject())) {
return false;
}
GrArgumentList args = call.getArgumentList();
if (args.getExpressionArguments().length != 1 || PsiImplUtil.hasNamedArguments(args)) {
return false;
}
GrAssignmentExpression assignment = genRefForSetter(call, refExpr.getReferenceName());
if (assignment != null) {
GrExpression value = assignment.getLValue();
if (value instanceof GrReferenceExpression && call.getManager().areElementsEquivalent(((GrReferenceExpression) value).resolve(), method)) {
return true;
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class GroovyTargetElementEvaluator method getElementByReference.
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
PsiElement sourceElement = ref.getElement();
if (sourceElement instanceof GrCodeReferenceElement) {
GrNewExpression newExpr;
if (sourceElement.getParent() instanceof GrNewExpression) {
newExpr = (GrNewExpression) sourceElement.getParent();
} else if (sourceElement.getParent().getParent() instanceof GrNewExpression) {
//anonymous class declaration
newExpr = (GrNewExpression) sourceElement.getParent().getParent();
} else {
return null;
}
final PsiMethod constructor = newExpr.resolveMethod();
final GrArgumentList argumentList = newExpr.getArgumentList();
if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
if (constructor.getParameterList().getParametersCount() == 0)
return constructor.getContainingClass();
}
return constructor;
}
if (sourceElement instanceof GrReferenceExpression) {
PsiElement resolved = ((GrReferenceExpression) sourceElement).resolve();
if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) {
return correctSearchTargets(resolved);
}
return resolved;
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class PsiImplUtil method getRuntimeQualifier.
@Nullable
public static GrExpression getRuntimeQualifier(@NotNull GrReferenceExpression refExpr) {
GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier != null)
return qualifier;
for (GrClosableBlock closure = PsiTreeUtil.getParentOfType(refExpr, GrClosableBlock.class); closure != null; closure = PsiTreeUtil.getParentOfType(closure, GrClosableBlock.class)) {
PsiElement parent = closure.getParent();
if (parent instanceof GrArgumentList)
parent = parent.getParent();
if (!(parent instanceof GrMethodCall))
continue;
GrExpression funExpr = ((GrMethodCall) parent).getInvokedExpression();
if (!(funExpr instanceof GrReferenceExpression))
return funExpr;
final PsiElement resolved = ((GrReferenceExpression) funExpr).resolve();
if (!(resolved instanceof PsiMethod))
return funExpr;
if (resolved instanceof GrGdkMethod && isFromDGM((GrGdkMethod) resolved) && !GdkMethodUtil.isWithName(((GrGdkMethod) resolved).getStaticMethod().getName())) {
continue;
}
qualifier = ((GrReferenceExpression) funExpr).getQualifierExpression();
if (qualifier != null)
return qualifier;
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList in project intellij-community by JetBrains.
the class IndexedExpressionConversionIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrIndexProperty arrayIndexExpression = (GrIndexProperty) element;
final GrArgumentList argList = (GrArgumentList) arrayIndexExpression.getLastChild();
assert argList != null;
final GrExpression[] arguments = argList.getExpressionArguments();
final PsiElement parent = element.getParent();
final GrExpression arrayExpression = arrayIndexExpression.getInvokedExpression();
if (!(parent instanceof GrAssignmentExpression)) {
rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
return;
}
final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) parent;
final GrExpression rhs = assignmentExpression.getRValue();
if (rhs.equals(element)) {
rewriteAsGetAt(arrayIndexExpression, arrayExpression, arguments[0]);
} else {
rewriteAsSetAt(assignmentExpression, arrayExpression, arguments[0], rhs);
}
}
Aggregations