aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/ast/ClassNode.java
blob: 5f08d385c9fa5e401d76c9a08d01f986c38eccc0 (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
package org.zwobble.couscous.ast;

import java.util.List;

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

import com.google.common.collect.ImmutableList;

import lombok.Singular;
import lombok.Value;

@Value
public class ClassNode implements Node {
    public static ClassNode.Builder builder(String name) {
        return new Builder(name);
    }
    
    public static class Builder {
        private final String name;
        private final ImmutableList.Builder<MethodNode> methods;
        
        public Builder(String name) {
            this.name = name;
            this.methods = ImmutableList.builder();
        }
        
        public Builder method(MethodNode method) {
            this.methods.add(method);
            return this;
        }
        
        public ClassNode build() {
            return new ClassNode(TypeName.of(name), methods.build());
        }
    }
    
    TypeName name;
    @Singular
    List<MethodNode> methods;
    
    public String getSimpleName() {
        return name.getSimpleName();
    }

    @Override
    public void accept(NodeVisitor visitor) {
        visitor.visit(this);
    }
}