MCPcopy Create free account
hub / github.com/airlift/bytecode / MethodDefinition

Class MethodDefinition

src/main/java/io/airlift/bytecode/MethodDefinition.java:41–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39import static org.objectweb.asm.Opcodes.RETURN;
40
41@SuppressWarnings("UnusedDeclaration")
42@NotThreadSafe
43public class MethodDefinition
44{
45 private final Scope scope;
46 private final ClassDefinition declaringClass;
47 private final EnumSet<Access> access;
48 private final String name;
49 private final List<AnnotationDefinition> annotations = new ArrayList<>();
50 private final ParameterizedType returnType;
51 private final List<Parameter> parameters;
52 private final List<ParameterizedType> parameterTypes;
53 private final List<List<AnnotationDefinition>> parameterAnnotations;
54 private final List<ParameterizedType> exceptions = new ArrayList<>();
55
56 private final BytecodeBlock body;
57 private String comment;
58
59 public MethodDefinition(
60 ClassDefinition declaringClass,
61 EnumSet<Access> access,
62 String name,
63 ParameterizedType returnType,
64 Parameter... parameters)
65 {
66 this(declaringClass, access, name, returnType, ImmutableList.copyOf(parameters));
67 }
68
69 public MethodDefinition(
70 ClassDefinition declaringClass,
71 EnumSet<Access> access,
72 String name,
73 ParameterizedType returnType,
74 Iterable<Parameter> parameters)
75 {
76 checkArgument(Iterables.size(parameters) <= 254, "Too many parameters for method");
77
78 this.declaringClass = declaringClass;
79 body = new BytecodeBlock();
80
81 this.access = access;
82 this.name = name;
83 this.returnType = requireNonNullElseGet(returnType, () -> type(void.class));
84 this.parameters = ImmutableList.copyOf(parameters);
85 this.parameterTypes = Lists.transform(this.parameters, Parameter::getType);
86 this.parameterAnnotations = Streams.stream(parameters)
87 .map(input -> new ArrayList<AnnotationDefinition>())
88 .collect(toImmutableList());
89 Optional<ParameterizedType> thisType = Optional.empty();
90 if (!declaringClass.isInterface() && !access.contains(STATIC)) {
91 thisType = Optional.of(declaringClass.getType());
92 }
93 scope = new Scope(thisType, parameters);
94 }
95
96 public ClassDefinition getDeclaringClass()
97 {
98 return declaringClass;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected