use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleDslExpressionList method createNamedArgumentList.
@Nullable
private GroovyPsiElement createNamedArgumentList() {
assert myParent instanceof GradleDslExpressionMap;
GroovyPsiElement parentPsiElement = myParent.create();
if (parentPsiElement == null) {
return null;
}
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(parentPsiElement.getProject());
GrExpression expressionFromText = factory.createExpressionFromText("[]");
if (expressionFromText instanceof GrListOrMap) {
// Elements need to be added to the list before adding the list to the named argument.
GrListOrMap list = (GrListOrMap) expressionFromText;
for (GradleDslExpression expression : myToBeAddedExpressions) {
expression.setPsiElement(list);
expression.applyChanges();
myExpressions.add(expression);
}
myToBeAddedExpressions.clear();
}
GrNamedArgument namedArgument = factory.createNamedArgument(myName, expressionFromText);
PsiElement added;
if (parentPsiElement instanceof GrArgumentList) {
added = ((GrArgumentList) parentPsiElement).addNamedArgument(namedArgument);
} else {
added = parentPsiElement.addAfter(namedArgument, parentPsiElement.getLastChild());
}
if (added instanceof GrNamedArgument) {
GrNamedArgument addedNameArgument = (GrNamedArgument) added;
setPsiElement(addedNameArgument.getExpression());
return getPsiElement();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleDslExpressionMap method create.
@Override
@Nullable
public GroovyPsiElement create() {
GroovyPsiElement psiElement = super.create();
if (psiElement == null) {
return null;
}
if (psiElement instanceof GrListOrMap || psiElement instanceof GrArgumentList) {
return psiElement;
}
if (psiElement instanceof GrApplicationStatement) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(psiElement.getProject());
GrArgumentList argumentList = factory.createArgumentListFromText("xyz");
// Workaround to get an empty argument list.
argumentList.getFirstChild().delete();
PsiElement added = psiElement.addAfter(argumentList, psiElement.getLastChild());
if (added instanceof GrArgumentList) {
GrArgumentList addedArgumentList = (GrArgumentList) added;
setPsiElement(addedArgumentList);
return addedArgumentList;
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleDslLiteral method getPsiElementFactory.
private GroovyPsiElementFactory getPsiElementFactory() {
GroovyPsiElement psiElement = getPsiElement();
if (psiElement == null) {
return null;
}
Project project = psiElement.getProject();
return GroovyPsiElementFactory.getInstance(project);
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.
the class GradleDslLiteral method addConfigBlock.
private void addConfigBlock() {
if (myUnsavedConfigBlock == null) {
return;
}
GroovyPsiElement psiElement = getPsiElement();
if (psiElement == null) {
return;
}
GroovyPsiElementFactory factory = getPsiElementFactory();
if (factory == null) {
return;
}
// For now, this is only reachable for newly added dependencies, which means psiElement is an application statement with three children:
// the configuration name, whitespace, dependency in compact notation. Let's add some more: comma, whitespace and finally the config
// block.
GrApplicationStatement methodCallStatement = (GrApplicationStatement) factory.createStatementFromText("foo 1, 2");
PsiElement comma = methodCallStatement.getArgumentList().getFirstChild().getNextSibling();
psiElement.addAfter(comma, psiElement.getLastChild());
psiElement.addAfter(factory.createWhiteSpace(), psiElement.getLastChild());
psiElement.addAfter(myUnsavedConfigBlock, psiElement.getLastChild());
myUnsavedConfigBlock = null;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement 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