Search in sources :

Example 41 with GrMethodCall

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;
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) PsiElement(com.intellij.psi.PsiElement)

Example 42 with GrMethodCall

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);
    }
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) FakePsiElement(com.intellij.psi.impl.FakePsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 43 with GrMethodCall

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();
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with GrMethodCall

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;
    }
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Example 45 with GrMethodCall

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;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GroovyPsiManager(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyMapContentProvider(org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider) PsiElement(com.intellij.psi.PsiElement) PsiClassReferenceType(com.intellij.psi.impl.source.PsiClassReferenceType) PsiType(com.intellij.psi.PsiType) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Aggregations

GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)51 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)23 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)22 Nullable (org.jetbrains.annotations.Nullable)18 PsiElement (com.intellij.psi.PsiElement)17 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)13 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)9 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 NotNull (org.jetbrains.annotations.NotNull)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 PsiMethod (com.intellij.psi.PsiMethod)3 PsiType (com.intellij.psi.PsiType)3 ArrayList (java.util.ArrayList)3 GroovyMapContentProvider (org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider)3 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)3 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)3