use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project android by JetBrains.
the class AndroidDslContributor method resolveToMethodWithClosure.
private static void resolveToMethodWithClosure(PsiElement place, PsiElement resolveToElement, String closureTypeFqcn, PsiScopeProcessor processor, ResolveState state) {
if (place.getParent() instanceof GrMethodCallExpression) {
GrLightMethodBuilder methodWithClosure = GradleResolverUtil.createMethodWithClosure(place.getText(), closureTypeFqcn, null, place);
if (methodWithClosure != null) {
processor.execute(methodWithClosure, state);
methodWithClosure.setNavigationElement(resolveToElement);
}
} else if (place.getParent() instanceof GrReferenceExpression) {
GrLightVariable variable = new GrLightVariable(place.getManager(), place.getText(), closureTypeFqcn, place);
processor.execute(variable, state);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project android by JetBrains.
the class GradleDslElement method deleteIfEmpty.
protected static void deleteIfEmpty(@Nullable PsiElement element) {
if (element == null || !element.isValid()) {
return;
}
PsiElement parent = element.getParent();
if (element instanceof GrAssignmentExpression) {
if (((GrAssignmentExpression) element).getRValue() == null) {
element.delete();
}
} else if (element instanceof GrApplicationStatement) {
if (((GrApplicationStatement) element).getArgumentList() == null) {
element.delete();
}
} else if (element instanceof GrClosableBlock) {
final Boolean[] isEmpty = new Boolean[] { true };
((GrClosableBlock) element).acceptChildren(new GroovyElementVisitor() {
@Override
public void visitElement(GroovyPsiElement child) {
if (child instanceof GrParameterList) {
if (((GrParameterList) child).getParameters().length == 0) {
// Ignore the empty parameter list.
return;
}
}
isEmpty[0] = false;
}
});
if (isEmpty[0]) {
element.delete();
}
} else if (element instanceof GrMethodCallExpression) {
GrMethodCallExpression call = ((GrMethodCallExpression) element);
GrArgumentList argumentList;
try {
argumentList = call.getArgumentList();
} catch (AssertionError e) {
// We will get this exception if the argument list is already deleted.
argumentList = null;
}
GrClosableBlock[] closureArguments = call.getClosureArguments();
if ((argumentList == null || argumentList.getAllArguments().length == 0) && closureArguments.length == 0) {
element.delete();
}
} else if (element instanceof GrCommandArgumentList) {
GrCommandArgumentList commandArgumentList = (GrCommandArgumentList) element;
if (commandArgumentList.getAllArguments().length == 0) {
commandArgumentList.delete();
}
} else if (element instanceof GrListOrMap) {
GrListOrMap listOrMap = (GrListOrMap) element;
if ((listOrMap.isMap() && listOrMap.getNamedArguments().length == 0) || (!listOrMap.isMap() && listOrMap.getInitializers().length == 0)) {
listOrMap.delete();
}
}
if (!element.isValid()) {
// If this element is deleted, also delete the parent if it is empty.
deleteIfEmpty(parent);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression in project android by JetBrains.
the class GradleDslMethodCall method apply.
@Override
protected void apply() {
for (GradleDslElement argument : myToBeRemovedArguments) {
if (myArguments.remove(argument)) {
argument.delete();
}
}
GroovyPsiElement psiElement = getPsiElement();
if (psiElement instanceof GrMethodCallExpression) {
GrMethodCallExpression methodCall = (GrMethodCallExpression) psiElement;
if (myToBeAddedArgument != null) {
myToBeAddedArgument.setPsiElement(methodCall.getArgumentList());
myToBeAddedArgument.applyChanges();
myArguments.add(myToBeAddedArgument);
}
}
for (GradleDslElement argument : myArguments) {
if (argument.isModified()) {
argument.applyChanges();
}
}
}
Aggregations