Search in sources :

Example 6 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class JsonDelegateContributor method processDynamicMethods.

@Override
boolean processDynamicMethods(@NotNull PsiType qualifierType, @NotNull PsiClass clazz, @NotNull String name, @NotNull PsiElement place, @NotNull Processor<PsiElement> processor) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(place.getProject());
    GrLightMethodBuilder method;
    PsiClassType genericType;
    // T (T)
    method = createMethod(name, clazz, place);
    genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
    method.addParameter("value", genericType, false);
    method.setReturnType(genericType);
    if (!processor.process(method))
        return false;
    // List<T> (T[], Closure)
    method = createMethod(name, clazz, place);
    genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
    method.addParameter("values", genericType.createArrayType(), false);
    method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
    method.setReturnType(TypesUtil.createListType(place, genericType));
    if (!processor.process(method))
        return false;
    // List<T> (Iterable<T>, Closure)
    method = createMethod(name, clazz, place);
    genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
    method.addParameter("values", TypesUtil.createIterableType(place, genericType), false);
    method.addAndGetParameter("c", GROOVY_LANG_CLOSURE, false).putUserData(DELEGATES_TO_KEY, DELEGATE_FQN);
    method.setReturnType(TypesUtil.createListType(place, genericType));
    if (!processor.process(method))
        return false;
    // List<T> (T...)
    method = createMethod(name, clazz, place);
    genericType = facade.getElementFactory().createType(method.addTypeParameter("T"));
    method.addAndGetParameter("values", new PsiEllipsisType(genericType), false);
    method.setReturnType(TypesUtil.createListType(place, genericType));
    return processor.process(method);
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 7 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class StreamingJsonBuilderContributor method createMethod.

@NotNull
private static GrLightMethodBuilder createMethod(@NotNull String name, @NotNull PsiElement place, @NotNull PsiType returnType, @NotNull PsiClass clazz) {
    GrLightMethodBuilder method = new GrLightMethodBuilder(place.getManager(), name);
    method.setModifiers(GrModifierFlags.PUBLIC_MASK);
    method.setReturnType(returnType);
    UtilsKt.setContainingClass(method, clazz);
    method.setOriginInfo(ORIGIN_INFO);
    return method;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class SpockMemberContributor method processDynamicElements.

@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (ResolveUtil.shouldProcessProperties(classHint)) {
        GrMethod method = PsiTreeUtil.getParentOfType(place, GrMethod.class);
        if (method == null)
            return;
        if (aClass != method.getContainingClass())
            return;
        Map<String, SpockVariableDescriptor> cachedValue = SpockUtils.getVariableMap(method);
        String nameHint = ResolveUtil.getNameHint(processor);
        if (nameHint == null) {
            for (SpockVariableDescriptor spockVar : cachedValue.values()) {
                if (!processor.execute(spockVar.getVariable(), state))
                    return;
            }
        } else {
            SpockVariableDescriptor spockVar = cachedValue.get(nameHint);
            if (spockVar != null && spockVar.getNavigationElement() != place) {
                if (!processor.execute(spockVar.getVariable(), state))
                    return;
            }
        }
    }
    if (ResolveUtil.shouldProcessMethods(classHint)) {
        String nameHint = ResolveUtil.getNameHint(processor);
        if (nameHint == null) {
            nameHint = place instanceof GrReferenceExpression ? ((GrReferenceExpression) place).getReferenceName() : null;
            if (nameHint != null)
                nameHint = GroovyPropertyUtils.getGetterNameNonBoolean(nameHint);
        }
        if ("get_".equals(nameHint)) {
            GrLightMethodBuilder m = new GrLightMethodBuilder(aClass.getManager(), "get_");
            m.setReturnType(null);
            if (!processor.execute(m, state))
                return;
        }
    }
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 9 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class GrTraitUtil method createTraitMethodFromCompiledHelperMethod.

private static PsiMethod createTraitMethodFromCompiledHelperMethod(PsiMethod compiledMethod, ClsClassImpl trait) {
    final GrLightMethodBuilder result = new GrLightMethodBuilder(trait.getManager(), compiledMethod.getName());
    result.setOriginInfo("via @Trait");
    result.addModifier(PsiModifier.STATIC);
    for (PsiTypeParameter parameter : compiledMethod.getTypeParameters()) {
        result.getTypeParameterList().addParameter(parameter);
    }
    final PsiTypeVisitor<PsiType> corrector = createCorrector(compiledMethod, trait);
    final PsiParameter[] methodParameters = compiledMethod.getParameterList().getParameters();
    for (int i = 1; i < methodParameters.length; i++) {
        final PsiParameter originalParameter = methodParameters[i];
        final PsiType correctedType = originalParameter.getType().accept(corrector);
        final String name = originalParameter.getName();
        assert name != null : compiledMethod;
        result.addParameter(name, correctedType, false);
    }
    for (PsiClassType type : compiledMethod.getThrowsList().getReferencedTypes()) {
        final PsiType correctedType = type.accept(corrector);
        result.getThrowsList().addReference(correctedType instanceof PsiClassType ? (PsiClassType) correctedType : type);
    }
    final PsiType originalType = compiledMethod.getReturnType();
    result.setReturnType(originalType == null ? null : originalType.accept(corrector));
    final PsiClass traitSource = trait.getSourceMirrorClass();
    final PsiMethod sourceMethod = traitSource == null ? null : traitSource.findMethodBySignature(result, false);
    result.setNavigationElement(sourceMethod != null ? sourceMethod : compiledMethod);
    return result;
}
Also used : GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)

Example 10 with GrLightMethodBuilder

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder in project intellij-community by JetBrains.

the class GdkMethodUtil method createMethod.

@NotNull
private static GrMethod createMethod(@NotNull GrClosureSignature signature, @NotNull String name, @NotNull GrAssignmentExpression statement, @NotNull PsiClass closure) {
    final GrLightMethodBuilder builder = new GrLightMethodBuilder(statement.getManager(), name);
    GrClosureParameter[] parameters = signature.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        GrClosureParameter parameter = parameters[i];
        final String parameterName = parameter.getName() != null ? parameter.getName() : "p" + i;
        final PsiType type = parameter.getType() != null ? parameter.getType() : TypesUtil.getJavaLangObject(statement);
        builder.addParameter(parameterName, type, parameter.isOptional());
    }
    builder.setNavigationElement(statement.getLValue());
    builder.setReturnType(signature.getReturnType());
    builder.setContainingClass(closure);
    return builder;
}
Also used : GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter) GrLightMethodBuilder(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder) ElementClassHint(com.intellij.psi.scope.ElementClassHint) ClassHint(org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrLightMethodBuilder (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder)22 NotNull (org.jetbrains.annotations.NotNull)6 ElementClassHint (com.intellij.psi.scope.ElementClassHint)2 Nullable (org.jetbrains.annotations.Nullable)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 GrLightParameter (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter)2 PsiEllipsisType (com.intellij.psi.PsiEllipsisType)1 LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 CustomMembersGenerator (org.jetbrains.plugins.groovy.dsl.CustomMembersGenerator)1 NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)1 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 GrReflectedMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod)1 GrClosureParameter (org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter)1