JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/modules/ModuleDeclaration.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21package com.github.javaparser.ast.modules;
22
23import com.github.javaparser.ast.AllFieldsConstructor;
24import com.github.javaparser.ast.Node;
25import com.github.javaparser.ast.NodeList;
26import com.github.javaparser.ast.expr.AnnotationExpr;
27import com.github.javaparser.ast.expr.Name;
28import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
29import com.github.javaparser.ast.nodeTypes.NodeWithName;
30import com.github.javaparser.ast.observer.ObservableProperty;
31import com.github.javaparser.ast.visitor.CloneVisitor;
32import com.github.javaparser.ast.visitor.GenericVisitor;
33import com.github.javaparser.ast.visitor.VoidVisitor;
34import com.github.javaparser.metamodel.JavaParserMetaModel;
35import com.github.javaparser.metamodel.ModuleDeclarationMetaModel;
36import static com.github.javaparser.StaticJavaParser.parseModuleDirective;
37import static com.github.javaparser.utils.Utils.assertNotNull;
38import com.github.javaparser.TokenRange;
39import com.github.javaparser.ast.Generated;
40
41/**
42 * A Java 9 Jigsaw module declaration. {@code @Foo module com.github.abc { requires a.B; }}
43 */
44public class ModuleDeclaration extends Node implements NodeWithName<ModuleDeclaration>, NodeWithAnnotations<ModuleDeclaration> {
45
46    private Name name;
47
48    private NodeList<AnnotationExprannotations;
49
50    private boolean isOpen;
51
52    private NodeList<ModuleDirectivedirectives;
53
54    public ModuleDeclaration() {
55        this(null, new NodeList<>(), new Name(), false, new NodeList<>());
56    }
57
58    public ModuleDeclaration(Name nameboolean isOpen) {
59        this(null, new NodeList<>(), nameisOpen, new NodeList<>());
60    }
61
62    @AllFieldsConstructor
63    public ModuleDeclaration(NodeList<AnnotationExprannotationsName nameboolean isOpenNodeList<ModuleDirectivedirectives) {
64        this(nullannotationsnameisOpendirectives);
65    }
66
67    /**
68     * This constructor is used by the parser and is considered private.
69     */
70    @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
71    public ModuleDeclaration(TokenRange tokenRangeNodeList<AnnotationExprannotationsName nameboolean isOpenNodeList<ModuleDirectivedirectives) {
72        super(tokenRange);
73        setAnnotations(annotations);
74        setName(name);
75        setOpen(isOpen);
76        setDirectives(directives);
77        customInitialization();
78    }
79
80    @Override
81    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
82    public <RAR accept(final GenericVisitor<RAvfinal A arg) {
83        return v.visit(this, arg);
84    }
85
86    @Override
87    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
88    public <Avoid accept(final VoidVisitor<Avfinal A arg) {
89        v.visit(this, arg);
90    }
91
92    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
93    public Name getName() {
94        return name;
95    }
96
97    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
98    public ModuleDeclaration setName(final Name name) {
99        assertNotNull(name);
100        if (name == this.name) {
101            return (ModuleDeclaration) this;
102        }
103        notifyPropertyChange(ObservableProperty.NAME, this.namename);
104        if (this.name != null)
105            this.name.setParentNode(null);
106        this.name = name;
107        setAsParentNodeOf(name);
108        return this;
109    }
110
111    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
112    public NodeList<AnnotationExprgetAnnotations() {
113        return annotations;
114    }
115
116    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
117    public ModuleDeclaration setAnnotations(final NodeList<AnnotationExprannotations) {
118        assertNotNull(annotations);
119        if (annotations == this.annotations) {
120            return (ModuleDeclaration) this;
121        }
122        notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotationsannotations);
123        if (this.annotations != null)
124            this.annotations.setParentNode(null);
125        this.annotations = annotations;
126        setAsParentNodeOf(annotations);
127        return this;
128    }
129
130    @Override
131    @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
132    public boolean remove(Node node) {
133        if (node == null)
134            return false;
135        for (int i = 0i < annotations.size(); i++) {
136            if (annotations.get(i) == node) {
137                annotations.remove(i);
138                return true;
139            }
140        }
141        for (int i = 0i < directives.size(); i++) {
142            if (directives.get(i) == node) {
143                directives.remove(i);
144                return true;
145            }
146        }
147        return super.remove(node);
148    }
149
150    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
151    public boolean isOpen() {
152        return isOpen;
153    }
154
155    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
156    public ModuleDeclaration setOpen(final boolean isOpen) {
157        if (isOpen == this.isOpen) {
158            return (ModuleDeclaration) this;
159        }
160        notifyPropertyChange(ObservableProperty.OPEN, this.isOpenisOpen);
161        this.isOpen = isOpen;
162        return this;
163    }
164
165    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
166    public NodeList<ModuleDirectivegetDirectives() {
167        return directives;
168    }
169
170    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
171    public ModuleDeclaration setDirectives(final NodeList<ModuleDirectivedirectives) {
172        assertNotNull(directives);
173        if (directives == this.directives) {
174            return (ModuleDeclaration) this;
175        }
176        notifyPropertyChange(ObservableProperty.DIRECTIVES, this.directivesdirectives);
177        if (this.directives != null)
178            this.directives.setParentNode(null);
179        this.directives = directives;
180        setAsParentNodeOf(directives);
181        return this;
182    }
183
184    @Override
185    @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
186    public ModuleDeclaration clone() {
187        return (ModuleDeclarationaccept(new CloneVisitor(), null);
188    }
189
190    @Override
191    @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
192    public ModuleDeclarationMetaModel getMetaModel() {
193        return JavaParserMetaModel.moduleDeclarationMetaModel;
194    }
195
196    @Override
197    @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
198    public boolean replace(Node nodeNode replacementNode) {
199        if (node == null)
200            return false;
201        for (int i = 0i < annotations.size(); i++) {
202            if (annotations.get(i) == node) {
203                annotations.set(i, (AnnotationExprreplacementNode);
204                return true;
205            }
206        }
207        for (int i = 0i < directives.size(); i++) {
208            if (directives.get(i) == node) {
209                directives.set(i, (ModuleDirectivereplacementNode);
210                return true;
211            }
212        }
213        if (node == name) {
214            setName((NamereplacementNode);
215            return true;
216        }
217        return super.replace(nodereplacementNode);
218    }
219
220    /**
221     * Add a directive to the module, like "exports R.S to T1.U1, T2.U2;"
222     */
223    public ModuleDeclaration addDirective(String directive) {
224        return addDirective(parseModuleDirective(directive));
225    }
226
227    public ModuleDeclaration addDirective(ModuleDirective directive) {
228        getDirectives().add(directive);
229        return this;
230    }
231}
232
MembersX
ModuleDeclaration:setDirectives
ModuleDeclaration:isOpen
ModuleDeclaration:getMetaModel
ModuleDeclaration:setName
ModuleDeclaration:setAnnotations
ModuleDeclaration:getDirectives
ModuleDeclaration:setOpen
ModuleDeclaration:getAnnotations
ModuleDeclaration:clone
ModuleDeclaration:name
ModuleDeclaration:remove
ModuleDeclaration:accept
ModuleDeclaration:ModuleDeclaration
ModuleDeclaration:replace
ModuleDeclaration:directives
ModuleDeclaration:annotations
ModuleDeclaration:getName
ModuleDeclaration:addDirective
Members
X