use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GebContentDeclarationSearcher method findDeclarationsAt.
@Override
public void findDeclarationsAt(@NotNull PsiElement element, int offsetInElement, Consumer<PomTarget> consumer) {
PsiElement grCall = element.getParent();
if (!(grCall instanceof GrMethodCall))
return;
PsiElement grClosure = grCall.getParent();
if (!(grClosure instanceof GrClosableBlock))
return;
PsiElement contentField = grClosure.getParent();
if (!(contentField instanceof GrField))
return;
GrField field = (GrField) contentField;
if (!"content".equals(field.getName()) || !field.hasModifierProperty(PsiModifier.STATIC))
return;
PsiClass containingClass = field.getContainingClass();
if (!InheritanceUtil.isInheritor(containingClass, "geb.Page") && !InheritanceUtil.isInheritor(containingClass, "geb.Module"))
return;
Map<String, PsiField> elements = GebUtil.getContentElements(containingClass);
for (PsiField f : elements.values()) {
if (f.getNavigationElement() == element) {
consumer.consume(f);
return;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class CustomMembersGenerator method methodCall.
public void methodCall(Closure<Map<Object, Object>> generator) {
PsiElement place = myDescriptor.getPlace();
PsiElement parent = place.getParent();
if (isMethodCall(place, parent)) {
assert parent instanceof GrMethodCall && place instanceof GrReferenceExpression;
GrReferenceExpression ref = (GrReferenceExpression) place;
PsiType[] argTypes = PsiUtil.getArgumentTypes(ref, false);
if (argTypes == null)
return;
String[] types = ContainerUtil.map(argTypes, PsiType::getCanonicalText, new String[argTypes.length]);
generator.setDelegate(this);
HashMap<String, Object> args = new HashMap<>();
args.put("name", ref.getReferenceName());
args.put("argumentTypes", types);
generator.call(args);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class PsiElementCategory method bind.
@Nullable
public static PsiElement bind(PsiElement element) {
PsiElement elem = element instanceof GrMethodCall ? ((GrMethodCall) element).getInvokedExpression() : element;
final PsiReference ref = elem.getReference();
return ref == null ? null : ref.resolve();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class GradleScriptContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, @Nullable PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
if (!UtilKt.isResolvedInGradleScript(aClass))
return;
List<String> methodInfo = ContainerUtilRt.newArrayList();
for (GrMethodCall current = PsiTreeUtil.getParentOfType(place, GrMethodCall.class); current != null; current = PsiTreeUtil.getParentOfType(current, GrMethodCall.class)) {
GrExpression expression = current.getInvokedExpression();
String text = expression.getText();
if (text != null) {
methodInfo.add(text);
}
}
final String methodCall = ContainerUtil.getLastItem(methodInfo);
if (methodInfo.size() > 1 && BUILD_PROJECT_SCRIPT_BLOCKS.contains(methodCall)) {
methodInfo.remove(methodInfo.size() - 1);
}
for (GradleMethodContextContributor contributor : GradleMethodContextContributor.EP_NAME.getExtensions()) {
if (!contributor.process(methodInfo, processor, state, place))
return;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.
the class NamedDomainObjectCollectionTypeEnhancer method getReferenceType.
@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
if (resolved != null)
return null;
GrExpression qualifierExpression = ref.getQualifierExpression();
if (qualifierExpression == null)
return null;
PsiType namedDomainCollectionType = GradleResolverUtil.getTypeOf(qualifierExpression);
if (!InheritanceUtil.isInheritor(namedDomainCollectionType, GradleCommonClassNames.GRADLE_API_NAMED_DOMAIN_OBJECT_COLLECTION)) {
return null;
}
PsiElement qResolved;
if (qualifierExpression instanceof GrReferenceExpression) {
qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
} else if (qualifierExpression instanceof GrMethodCall) {
qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
} else {
return null;
}
String key = ref.getReferenceName();
if (key == null)
return null;
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
if (type != null) {
return type;
}
}
if (namedDomainCollectionType instanceof PsiClassReferenceType) {
final PsiClassReferenceType referenceType = (PsiClassReferenceType) namedDomainCollectionType;
final String fqName = TypesUtil.getQualifiedName(referenceType);
if (GradleCommonClassNames.GRADLE_API_SOURCE_SET_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_SOURCE_SET, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_CONFIGURATION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_CONFIGURATION, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_TASK_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_TASK, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_DISTRIBUTION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_DISTRIBUTION, ref.getResolveScope());
} else {
GradleExtensionsSettings.GradleExtensionsData extensionsData = GradleExtensionsContributor.Companion.getExtensionsFor(ref);
if (extensionsData != null) {
for (GradleExtensionsSettings.GradleExtension extension : extensionsData.extensions) {
if (StringUtil.isNotEmpty(extension.namedObjectTypeFqn) && extension.rootTypeFqn.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(extension.namedObjectTypeFqn, ref.getResolveScope());
}
}
}
}
}
return null;
}
Aggregations