aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/ast/InterfaceNode.java
blob: 09d2d3a39e5175bff2118541657c99d89d40ca96 (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
74
75
76
77
78
79
80
81
package org.zwobble.couscous.ast;

import org.zwobble.couscous.ast.visitors.NodeMapper;

import java.util.List;
import java.util.Set;

public class InterfaceNode implements TypeNode {
    public static InterfaceNode declareInterface(
        TypeName name,
        Set<TypeName> superTypes,
        List<MethodNode> methods)
    {
        return new InterfaceNode(name, superTypes, methods);
    }

    private final TypeName name;
    private final Set<TypeName> superTypes;
    private final List<MethodNode> methods;

    private InterfaceNode(
        TypeName name,
        Set<TypeName> superTypes,
        List<MethodNode> methodNodes)
    {
        this.name = name;
        this.superTypes = superTypes;
        methods = methodNodes;
    }

    @Override
    public TypeName getName() {
        return name;
    }

    @Override
    public Set<TypeName> getSuperTypes() {
        return superTypes;
    }

    @Override
    public List<MethodNode> getMethods() {
        return methods;
    }

    @Override
    public <T> T accept(NodeMapper<T> visitor) {
        // TODO: implement this
        return null;
    }

    @Override
    public String toString() {
        return "InterfaceNode(" +
            "name=" + name +
            ", superTypes=" + superTypes +
            ", methods=" + methods +
            ')';
    }

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

        InterfaceNode that = (InterfaceNode) o;

        if (!name.equals(that.name)) return false;
        if (!superTypes.equals(that.superTypes)) return false;
        return methods.equals(that.methods);

    }

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