aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/ast/MethodSignature.java
blob: 715dadee2b3540f85b63dd48810f9112b3b4eb21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.zwobble.couscous.ast;

import org.zwobble.couscous.types.Type;
import org.zwobble.couscous.types.Types;

import java.util.List;

import static org.zwobble.couscous.util.ExtraLists.eagerMap;

public class MethodSignature {
    public static MethodSignature signature(String name, List<Type> arguments, Type returnType) {
        return new MethodSignature(name, arguments, returnType);
    }

    private final String name;
    private final List<Type> arguments;
    private final Type returnType;

    public MethodSignature(String name, List<Type> arguments, Type returnType) {
        this.name = name;
        this.arguments = arguments;
        this.returnType = returnType;
    }

    public String getName() {
        return name;
    }

    public List<Type> getArguments() {
        return arguments;
    }

    public Type getReturnType() {
        return returnType;
    }

    public MethodSignature generic() {
        return new MethodSignature(
            name,
            eagerMap(arguments, Types::generic),
            Types.generic(returnType));
    }

    @Override
    public String toString() {
        return "MethodSignature(" +
            "name='" + name + '\'' +
            ", arguments=" + arguments +
            ", returnType=" + returnType +
            ')';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MethodSignature that = (MethodSignature) o;

        if (!name.equals(that.name)) return false;
        if (!arguments.equals(that.arguments)) return false;
        return returnType.equals(that.returnType);

    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + arguments.hashCode();
        result = 31 * result + returnType.hashCode();
        return result;
    }
}