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 intellij-community by JetBrains.
the class MissingReturnInspection method getExpectedClosureReturnType.
@Nullable
public static PsiType getExpectedClosureReturnType(GrClosableBlock closure) {
List<PsiType> expectedReturnTypes = new ArrayList<>();
PsiElement parent = closure.getParent();
if (parent instanceof GrArgumentList && parent.getParent() instanceof GrMethodCall || parent instanceof GrMethodCall) {
GrMethodCall call = (GrMethodCall) (parent instanceof GrArgumentList ? parent.getParent() : parent);
GroovyResolveResult[] variants = call.getCallVariants(null);
for (GroovyResolveResult variant : variants) {
Map<GrExpression, Pair<PsiParameter, PsiType>> map = GrClosureSignatureUtil.mapArgumentsToParameters(variant, closure, true, true, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments());
if (map != null) {
Pair<PsiParameter, PsiType> pair = map.get(closure);
if (pair == null)
continue;
PsiParameter parameter = pair.getFirst();
PsiType type = parameter.getType();
if (TypesUtil.isPsiClassTypeToClosure(type)) {
PsiType[] parameters = ((PsiClassType) type).getParameters();
if (parameters.length == 1) {
expectedReturnTypes.add(parameters[0]);
}
}
}
}
} else {
for (PsiType expectedType : GroovyExpectedTypesProvider.getDefaultExpectedTypes(closure)) {
if (TypesUtil.isPsiClassTypeToClosure(expectedType)) {
PsiType[] parameters = ((PsiClassType) expectedType).getParameters();
if (parameters.length == 1) {
expectedReturnTypes.add(parameters[0]);
}
}
}
}
for (PsiType type : expectedReturnTypes) {
if (PsiType.VOID.equals(type))
return PsiType.VOID;
}
return TypesUtil.getLeastUpperBoundNullable(expectedReturnTypes, closure.getManager());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class UnnecessaryQualifiedReferenceInspection method isQualifiedStaticMethodWithUnnecessaryQualifier.
private static boolean isQualifiedStaticMethodWithUnnecessaryQualifier(GrReferenceExpression ref) {
if (ref.getQualifier() == null)
return false;
final PsiElement resolved = ref.resolve();
if (!(resolved instanceof PsiMember))
return false;
if (!((PsiMember) resolved).hasModifierProperty(PsiModifier.STATIC))
return false;
PsiElement copyResolved;
final PsiElement parent = ref.getParent();
if (parent instanceof GrMethodCall) {
final GrMethodCall copy = (GrMethodCall) parent.copy();
GrReferenceExpression invoked = (GrReferenceExpression) copy.getInvokedExpression();
assert invoked != null;
invoked.setQualifier(null);
copyResolved = ((GrReferenceExpression) copy.getInvokedExpression()).resolve();
} else {
final GrReferenceExpression copy = (GrReferenceExpression) ref.copy();
copy.setQualifier(null);
copyResolved = copy.resolve();
}
return ref.getManager().areElementsEquivalent(copyResolved, resolved);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GebUtil method calculateContentElements.
private static Map<String, PsiField> calculateContentElements(@NotNull PsiClass pageOrModuleClass) {
PsiField contentField = pageOrModuleClass.findFieldByName("content", false);
if (!(contentField instanceof GrField))
return Collections.emptyMap();
GrExpression initializer = ((GrField) contentField).getInitializerGroovy();
if (!(initializer instanceof GrClosableBlock))
return Collections.emptyMap();
Map<String, PsiField> res = new HashMap<>();
PsiType objectType = PsiType.getJavaLangObject(pageOrModuleClass.getManager(), pageOrModuleClass.getResolveScope());
for (PsiElement e = initializer.getFirstChild(); e != null; e = e.getNextSibling()) {
if (e instanceof GrMethodCall) {
GrMethodCall methodCall = (GrMethodCall) e;
GrExpression invokedExpression = methodCall.getInvokedExpression();
if (!(invokedExpression instanceof GrReferenceExpression))
continue;
if (((GrReferenceExpression) invokedExpression).isQualified())
continue;
GrExpression[] arguments = PsiUtil.getAllArguments((GrCall) e);
if (arguments.length == 0)
continue;
final GrClosableBlock block;
if (arguments.length == 1 && arguments[0] instanceof GrClosableBlock) {
block = (GrClosableBlock) arguments[0];
} else if (arguments.length == 2 && arguments[0] == null && arguments[1] instanceof GrClosableBlock) {
block = (GrClosableBlock) arguments[1];
} else {
continue;
}
GrLightField field = new GrLightField(pageOrModuleClass, ((GrReferenceExpression) invokedExpression).getReferenceName(), objectType, invokedExpression) {
@Override
public PsiType getTypeGroovy() {
return block.getReturnType();
}
@Override
public PsiType getDeclaredType() {
return null;
}
};
field.getModifierList().addModifier(GrModifierFlags.STATIC_MASK);
res.put(field.getName(), field);
}
}
return res;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class ConfigSlurperMapContentProvider method getInfo.
@Nullable
private static Pair<ConfigSlurperSupport.PropertiesProvider, List<String>> getInfo(@NotNull GrExpression qualifier, @Nullable PsiElement resolve) {
if (!InheritanceUtil.isInheritor(qualifier.getType(), GroovyCommonClassNames.GROOVY_UTIL_CONFIG_OBJECT)) {
return null;
}
GrExpression resolvedQualifier = qualifier;
PsiElement resolveResult = resolve;
List<String> path = new ArrayList<>();
while (resolveResult == null) {
if (!(resolvedQualifier instanceof GrReferenceExpression))
return null;
GrReferenceExpression expr = (GrReferenceExpression) resolvedQualifier;
path.add(expr.getReferenceName());
resolvedQualifier = expr.getQualifierExpression();
if (resolvedQualifier instanceof GrReferenceExpression) {
resolveResult = ((GrReferenceExpression) resolvedQualifier).resolve();
} else if (resolvedQualifier instanceof GrMethodCall) {
resolveResult = ((GrMethodCall) resolvedQualifier).resolveMethod();
} else {
return null;
}
}
Collections.reverse(path);
ConfigSlurperSupport.PropertiesProvider propertiesProvider = null;
for (ConfigSlurperSupport slurperSupport : ConfigSlurperSupport.EP_NAME.getExtensions()) {
propertiesProvider = slurperSupport.getConfigSlurperInfo(resolvedQualifier, resolveResult);
if (propertiesProvider != null)
break;
}
if (propertiesProvider == null)
return null;
return Pair.create(propertiesProvider, path);
}
Aggregations