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));
}
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);
}
Aggregations