Search in sources :

Example 11 with GrClosureParameter

use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter in project intellij-community by JetBrains.

the class GrClosureSignatureUtil method checkAndAddSignature.

public static void checkAndAddSignature(List<GrClosureSignature> list, PsiType[] args, int position, List<GrClosureParameter> params, PsiType returnType, @NotNull PsiElement context) {
    final int last = position + args.length;
    if (last > params.size())
        return;
    for (int i = position; i < last; i++) {
        final GrClosureParameter p = params.get(i);
        final PsiType type = p.getType();
        if (!isAssignableByConversion(type, args[i - position], context))
            return;
    }
    GrClosureParameter[] _p = new GrClosureParameter[params.size() - args.length];
    int j = 0;
    for (int i = 0; i < position; i++) {
        _p[j++] = params.get(i);
    }
    for (int i = position + args.length; i < params.size(); i++) {
        _p[j++] = params.get(i);
    }
    list.add(new GrImmediateClosureSignatureImpl(_p, returnType, _p.length > 0 && _p[_p.length - 1].getType() instanceof PsiArrayType, true));
}
Also used : GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter)

Example 12 with GrClosureParameter

use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter in project intellij-community by JetBrains.

the class GroovyPsiElementFactoryImpl method createMethodFromSignature.

@NotNull
@Override
public GrMethod createMethodFromSignature(@NotNull String name, @NotNull GrClosureSignature signature) {
    StringBuilder builder = new StringBuilder("public");
    final PsiType returnType = signature.getReturnType();
    if (returnType != null && returnType != PsiType.NULL) {
        builder.append(' ');
        builder.append(returnType.getCanonicalText());
    }
    builder.append(' ').append(name).append('(');
    int i = 0;
    for (GrClosureParameter parameter : signature.getParameters()) {
        final PsiType type = parameter.getType();
        if (type != null) {
            builder.append(type.getCanonicalText());
            builder.append(' ');
        }
        builder.append('p').append(++i);
        final GrExpression initializer = parameter.getDefaultInitializer();
        if (initializer != null) {
            builder.append(" = ").append(initializer.getText());
            builder.append(", ");
        }
    }
    if (signature.getParameterCount() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    builder.append("){}");
    return createMethodFromText(builder);
}
Also used : GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrClosureParameter (org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter)12 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)6 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)3 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)3 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)3 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 GrRecursiveSignatureVisitor (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor)2 GrReflectedMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod)2 GrClosureSignatureUtil (org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil)2 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiType (com.intellij.psi.PsiType)1 ElementClassHint (com.intellij.psi.scope.ElementClassHint)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 GrSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)1 GrNewExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression)1