use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class ImportMavenRepositoriesTask method findMavenRemoteRepositories.
@NotNull
private Collection<? extends MavenRemoteRepository> findMavenRemoteRepositories(@Nullable GrClosableBlock repositoriesBlock) {
Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
for (GrMethodCall repo : PsiTreeUtil.getChildrenOfTypeAsList(repositoriesBlock, GrMethodCall.class)) {
final String expressionText = repo.getInvokedExpression().getText();
if ("mavenCentral".equals(expressionText)) {
myRemoteRepositories.add(mavenCentralRemoteRepository);
} else if ("mavenRepo".equals(expressionText)) {
for (GrNamedArgument namedArgument : repo.getNamedArguments()) {
if ("url".equals(namedArgument.getLabelName())) {
URI urlArgumentValue = resolveUriFromSimpleExpression(namedArgument.getExpression());
if (urlArgumentValue != null) {
String textUri = urlArgumentValue.toString();
myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
}
break;
}
}
} else if ("maven".equals(expressionText) && repo.getClosureArguments().length > 0) {
List<GrApplicationStatement> applicationStatementList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrApplicationStatement.class);
if (!applicationStatementList.isEmpty()) {
GrApplicationStatement statement = applicationStatementList.get(0);
if (statement == null)
continue;
GrExpression expression = statement.getInvokedExpression();
if ("url".equals(expression.getText())) {
URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getExpressionArguments()[0]);
if (urlArgumentValue != null) {
String textUri = urlArgumentValue.toString();
myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
}
}
}
List<GrAssignmentExpression> assignmentExpressionList = PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrAssignmentExpression.class);
if (!assignmentExpressionList.isEmpty()) {
GrAssignmentExpression statement = assignmentExpressionList.get(0);
if (statement == null)
continue;
GrExpression expression = statement.getLValue();
if ("url".equals(expression.getText())) {
URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getRValue());
if (urlArgumentValue != null) {
String textUri = urlArgumentValue.toString();
myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
}
}
}
}
}
return myRemoteRepositories;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.
the class GradleGroovyFile method getValueStatic.
/**
* Returns the value in the file for the given key, or null if not present.
*/
@Nullable
static Object getValueStatic(@NotNull GrStatementOwner root, @NotNull BuildFileKey key) {
GrMethodCall method = getMethodCallByPath(root, key.getPath());
if (method == null) {
return null;
}
GroovyPsiElement arg = key.getType() == BuildFileKeyType.CLOSURE ? getMethodClosureArgument(method) : getFirstArgument(method);
if (arg == null) {
return null;
}
return key.getValue(arg);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.
the class GradleBuildFile method getPlugins.
/**
* Returns a list of all the plugins used by the given build file.
*/
@NotNull
public static List<String> getPlugins(GroovyFile buildScript) {
List<String> plugins = Lists.newArrayListWithExpectedSize(1);
for (GrMethodCall methodCall : getMethodCalls(buildScript, "apply")) {
Map<String, Object> values = getNamedArgumentValues(methodCall);
Object plugin = values.get("plugin");
if (plugin != null) {
plugins.add(plugin.toString());
}
}
return plugins;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project android by JetBrains.
the class GradleGroovyFile method setValueStatic.
/**
* Sets the value for the given key
*/
static void setValueStatic(@NotNull GrStatementOwner root, @NotNull BuildFileKey key, @NotNull Object value, boolean reformatClosure, @Nullable ValueFactory.KeyFilter filter) {
if (value == GradleBuildFile.UNRECOGNIZED_VALUE) {
return;
}
GrMethodCall method = getMethodCallByPath(root, key.getPath());
if (method == null) {
method = createNewValue(root, key, value, reformatClosure);
if (key.getType() != BuildFileKeyType.CLOSURE) {
return;
}
}
if (method != null) {
GroovyPsiElement arg = key.getType() == BuildFileKeyType.CLOSURE ? getMethodClosureArgument(method) : getFirstArgument(method);
if (arg == null) {
return;
}
key.setValue(arg, value, filter);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall 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