use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory 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.GroovyPsiElementFactory 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.GroovyPsiElementFactory 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.GroovyPsiElementFactory in project android by JetBrains.
the class GradleDslLiteral method createLiteral.
@Nullable
private GrLiteral createLiteral() {
if (myUnsavedValue == null) {
return null;
}
CharSequence unsavedValueText = null;
if (myUnsavedValue instanceof String) {
unsavedValueText = GrStringUtil.getLiteralTextByValue((String) myUnsavedValue);
} else if (myUnsavedValue instanceof Integer || myUnsavedValue instanceof Boolean) {
unsavedValueText = myUnsavedValue.toString();
}
myUnsavedValue = null;
if (unsavedValueText == null) {
return null;
}
GroovyPsiElementFactory factory = getPsiElementFactory();
if (factory == null) {
return null;
}
GrExpression newExpression = factory.createExpressionFromText(unsavedValueText);
if (!(newExpression instanceof GrLiteral)) {
return null;
}
return (GrLiteral) newExpression;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-plugins by JetBrains.
the class GrStepDefinitionCreator method buildStepDefinitionByStep.
private static GrMethodCall buildStepDefinitionByStep(@NotNull final GherkinStep step) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(step.getProject());
final Step cucumberStep = new Step(Collections.emptyList(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
SnippetGenerator generator = new SnippetGenerator(new GroovySnippet());
final String fqnPendingException;
if (GrCucumberUtil.isCucumber_1_1_orAbove(step)) {
fqnPendingException = "cucumber.api.PendingException";
} else {
fqnPendingException = "cucumber.runtime.PendingException";
}
String snippet = generator.getSnippet(cucumberStep, null).replace("PendingException", fqnPendingException);
return (GrMethodCall) factory.createStatementFromText(snippet, step);
}
Aggregations