package io.trygvis.container.compiler.model; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; import static java.util.Arrays.asList; import static java.util.Collections.addAll; import static java.util.Collections.singletonList; public class MethodRef { public final TypeRef returnType; public final String name; public final int modifiers; public final Parameters parameters; public final Set exceptions = new TreeSet<>(); public final List typeArgs = new ArrayList<>(); public final List annotations = new ArrayList<>(); public final List body; public MethodRef(int modifiers, TypeRef returnType, String name, String body) { this(modifiers, returnType, name, new Parameters(), singletonList(body)); } public MethodRef(int modifiers, TypeRef returnType, String name, Parameters p, String... body) { this(modifiers, returnType, name, p, asList(body)); } public MethodRef(int modifiers, TypeRef returnType, String name, Parameters parameters, List body) { this.modifiers = modifiers; this.returnType = returnType; this.name = name; this.parameters = parameters; this.body = body; if ((Modifier.methodModifiers() & modifiers) != modifiers) { throw new RuntimeException("Invalid modifiers for method: " + Modifier.toString(modifiers)); } } public MethodRef exception(TypeRef... exceptions) { addAll(this.exceptions, exceptions); return this; } public MethodRef typeArgs(String... args) { addAll(typeArgs, args); return this; } public MethodRef annotation(AnnotationG annotation) { this.annotations.add(annotation); return this; } }