JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/ImportDeclaration.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;
22
23import com.github.javaparser.ast.expr.Name;
24import com.github.javaparser.ast.nodeTypes.NodeWithName;
25import com.github.javaparser.ast.observer.ObservableProperty;
26import com.github.javaparser.ast.visitor.GenericVisitor;
27import com.github.javaparser.ast.visitor.VoidVisitor;
28import static com.github.javaparser.StaticJavaParser.parseName;
29import static com.github.javaparser.utils.Utils.assertNotNull;
30import com.github.javaparser.ast.visitor.CloneVisitor;
31import com.github.javaparser.metamodel.ImportDeclarationMetaModel;
32import com.github.javaparser.metamodel.JavaParserMetaModel;
33import com.github.javaparser.TokenRange;
34import com.github.javaparser.ast.Node;
35import com.github.javaparser.ast.Generated;
36
37/**
38 * An import declaration.
39 * <br>{@code import com.github.javaparser.JavaParser;}
40 * <br>{@code import com.github.javaparser.*;}
41 * <br>{@code import com.github.javaparser.JavaParser.*; }
42 * <br>{@code import static com.github.javaparser.JavaParser.*;}
43 * <br>{@code import static com.github.javaparser.JavaParser.parse;}
44 *
45 * <p>The name does not include the asterisk or the static keyword.</p>
46 * @author Julio Vilmar Gesser
47 */
48public class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration> {
49
50    private Name name;
51
52    private boolean isStatic;
53
54    private boolean isAsterisk;
55
56    private ImportDeclaration() {
57        this(null, new Name(), falsefalse);
58    }
59
60    public ImportDeclaration(String nameboolean isStaticboolean isAsterisk) {
61        this(nullparseName(name), isStaticisAsterisk);
62    }
63
64    @AllFieldsConstructor
65    public ImportDeclaration(Name nameboolean isStaticboolean isAsterisk) {
66        this(nullnameisStaticisAsterisk);
67    }
68
69    /**
70     * This constructor is used by the parser and is considered private.
71     */
72    @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
73    public ImportDeclaration(TokenRange tokenRangeName nameboolean isStaticboolean isAsterisk) {
74        super(tokenRange);
75        setName(name);
76        setStatic(isStatic);
77        setAsterisk(isAsterisk);
78        customInitialization();
79    }
80
81    @Override
82    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
83    public <RAR accept(final GenericVisitor<RAvfinal A arg) {
84        return v.visit(this, arg);
85    }
86
87    @Override
88    @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
89    public <Avoid accept(final VoidVisitor<Avfinal A arg) {
90        v.visit(this, arg);
91    }
92
93    /**
94     * Retrieves the name of the import (.* is not included.)
95     */
96    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
97    public Name getName() {
98        return name;
99    }
100
101    /**
102     * Return if the import ends with "*".
103     */
104    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
105    public boolean isAsterisk() {
106        return isAsterisk;
107    }
108
109    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
110    public boolean isStatic() {
111        return isStatic;
112    }
113
114    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
115    public ImportDeclaration setAsterisk(final boolean isAsterisk) {
116        if (isAsterisk == this.isAsterisk) {
117            return (ImportDeclaration) this;
118        }
119        notifyPropertyChange(ObservableProperty.ASTERISK, this.isAsteriskisAsterisk);
120        this.isAsterisk = isAsterisk;
121        return this;
122    }
123
124    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
125    public ImportDeclaration setName(final Name name) {
126        assertNotNull(name);
127        if (name == this.name) {
128            return (ImportDeclaration) this;
129        }
130        notifyPropertyChange(ObservableProperty.NAME, this.namename);
131        if (this.name != null)
132            this.name.setParentNode(null);
133        this.name = name;
134        setAsParentNodeOf(name);
135        return this;
136    }
137
138    @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
139    public ImportDeclaration setStatic(final boolean isStatic) {
140        if (isStatic == this.isStatic) {
141            return (ImportDeclaration) this;
142        }
143        notifyPropertyChange(ObservableProperty.STATIC, this.isStaticisStatic);
144        this.isStatic = isStatic;
145        return this;
146    }
147
148    @Override
149    @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
150    public boolean remove(Node node) {
151        if (node == null)
152            return false;
153        return super.remove(node);
154    }
155
156    @Override
157    @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
158    public ImportDeclaration clone() {
159        return (ImportDeclarationaccept(new CloneVisitor(), null);
160    }
161
162    @Override
163    @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
164    public ImportDeclarationMetaModel getMetaModel() {
165        return JavaParserMetaModel.importDeclarationMetaModel;
166    }
167
168    @Override
169    @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
170    public boolean replace(Node nodeNode replacementNode) {
171        if (node == null)
172            return false;
173        if (node == name) {
174            setName((NamereplacementNode);
175            return true;
176        }
177        return super.replace(nodereplacementNode);
178    }
179}
180
MembersX
ImportDeclaration:ImportDeclaration
ImportDeclaration:isAsterisk
ImportDeclaration:accept
ImportDeclaration:setName
ImportDeclaration:setStatic
ImportDeclaration:isStatic
ImportDeclaration:clone
ImportDeclaration:getMetaModel
ImportDeclaration:setAsterisk
ImportDeclaration:replace
ImportDeclaration:name
ImportDeclaration:remove
ImportDeclaration:getName
Members
X