aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/ast/identifiers/ExtendedIdentifier.java
blob: 407c6da2baaaf180072f89dd4403b988ce92209c (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
package org.zwobble.couscous.ast.identifiers;

import static org.zwobble.couscous.util.ExtraIterables.lazyAppend;

public class ExtendedIdentifier implements Identifier {
    private final Identifier parent;
    private final String part;
    private final IdentifierType type;

    ExtendedIdentifier(Identifier parent, String part, IdentifierType type) {
        this.parent = parent;
        this.part = part;
        this.type = type;
    }

    @Override
    public Iterable<IdentifierPart> getParts() {
        return lazyAppend(parent.getParts(), new IdentifierPart(part, type));
    }

    @Override
    public String toString() {
        return "ExtendedIdentifier(" +
            "parent=" + parent +
            ", part='" + part + '\'' +
            ", type=" + type +
            ')';
    }

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

        ExtendedIdentifier that = (ExtendedIdentifier) o;

        if (!parent.equals(that.parent)) return false;
        if (!part.equals(that.part)) return false;
        return type == that.type;

    }

    @Override
    public int hashCode() {
        int result = parent.hashCode();
        result = 31 * result + part.hashCode();
        result = 31 * result + type.hashCode();
        return result;
    }
}