use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-community by JetBrains.
the class ResolveUtil method getCallVariants.
public static GroovyResolveResult[] getCallVariants(GroovyPsiElement place) {
final PsiElement parent = place.getParent();
GroovyResolveResult[] variants = GroovyResolveResult.EMPTY_ARRAY;
if (parent instanceof GrCallExpression) {
variants = ((GrCallExpression) parent).getCallVariants(place instanceof GrExpression ? (GrExpression) place : null);
} else if (parent instanceof GrConstructorInvocation) {
final PsiClass clazz = ((GrConstructorInvocation) parent).getDelegatedClass();
if (clazz != null) {
final PsiMethod[] constructors = clazz.getConstructors();
variants = getConstructorResolveResult(constructors, place);
}
} else if (parent instanceof GrAnonymousClassDefinition) {
final PsiElement element = ((GrAnonymousClassDefinition) parent).getBaseClassReferenceGroovy().resolve();
if (element instanceof PsiClass) {
final PsiMethod[] constructors = ((PsiClass) element).getConstructors();
variants = getConstructorResolveResult(constructors, place);
}
} else if (place instanceof GrReferenceExpression) {
variants = ((GrReferenceExpression) place).getSameNameVariants();
}
return variants;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project android by JetBrains.
the class GradleFilePsiMerger method pullDependenciesIntoMap.
/**
* Looks for statements adding dependencies to different configurations (which look like 'configurationName "dependencyCoordinate"')
* and tries to parse them into Gradle coordinates. If successful, adds the new coordinate to the map and removes the corresponding
* PsiElement from the tree.
*
* @return true if new items were added to the map
*/
private static boolean pullDependenciesIntoMap(@NotNull PsiElement root, @NotNull Map<String, Multimap<String, GradleCoordinate>> allConfigurations, @Nullable List<String> unparsedDependencies) {
boolean wasMapUpdated = false;
for (PsiElement existingElem : root.getChildren()) {
if (existingElem instanceof GrCall) {
PsiElement reference = existingElem.getFirstChild();
if (reference instanceof GrReferenceExpression) {
final String configurationName = reference.getText();
boolean parsed = false;
GrCall call = (GrCall) existingElem;
GrArgumentList arguments = call.getArgumentList();
// Don't try merging dependencies if one of them has a closure block attached.
if (arguments != null && call.getClosureArguments().length == 0) {
GrExpression[] expressionArguments = arguments.getExpressionArguments();
if (expressionArguments.length == 1 && expressionArguments[0] instanceof GrLiteral) {
Object value = ((GrLiteral) expressionArguments[0]).getValue();
if (value instanceof String) {
String coordinateText = (String) value;
GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(coordinateText);
if (coordinate != null) {
parsed = true;
Multimap<String, GradleCoordinate> map = allConfigurations.get(configurationName);
if (map == null) {
map = LinkedListMultimap.create();
allConfigurations.put(configurationName, map);
}
if (!map.get(coordinate.getId()).contains(coordinate)) {
map.put(coordinate.getId(), coordinate);
existingElem.delete();
wasMapUpdated = true;
}
}
}
}
if (!parsed && unparsedDependencies != null) {
unparsedDependencies.add(existingElem.getText());
}
}
}
}
}
return wasMapUpdated;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression 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.GrReferenceExpression in project android by JetBrains.
the class GradleEditorValueExtractor method extractMethodName.
@Nullable
public static Pair<String, TextRange> extractMethodName(@NotNull PsiElement methodCall) {
GrReferenceExpression methodNameRef = PsiTreeUtil.findChildOfType(methodCall, GrReferenceExpression.class);
if (methodNameRef == null || methodNameRef.getParent() != methodCall) {
return null;
}
String methodName = methodNameRef.getReferenceName();
if (methodName == null) {
return null;
}
return Pair.create(methodName, methodNameRef.getTextRange());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression in project intellij-plugins by JetBrains.
the class CustomWorldContributor method isWorldDeclaration.
private static boolean isWorldDeclaration(@NotNull GrMethodCall methodCall) {
final GrExpression invoked = methodCall.getInvokedExpression();
if (invoked instanceof GrReferenceExpression) {
final PsiMethod method = methodCall.resolveMethod();
final PsiClass clazz = method == null ? null : method.getContainingClass();
final String qname = clazz == null ? null : clazz.getQualifiedName();
return method != null && "World".equals(method.getName()) && GrCucumberCommonClassNames.isHookClassName(qname);
}
return false;
}
Aggregations