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 | */ |
21 | package com.github.javaparser.ast.expr; |
22 | |
23 | import com.github.javaparser.ast.AllFieldsConstructor; |
24 | import com.github.javaparser.ast.Node; |
25 | import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier; |
26 | import com.github.javaparser.ast.observer.ObservableProperty; |
27 | import com.github.javaparser.ast.visitor.GenericVisitor; |
28 | import com.github.javaparser.ast.visitor.VoidVisitor; |
29 | import static com.github.javaparser.utils.Utils.assertNonEmpty; |
30 | import com.github.javaparser.ast.visitor.CloneVisitor; |
31 | import com.github.javaparser.metamodel.NonEmptyProperty; |
32 | import com.github.javaparser.metamodel.SimpleNameMetaModel; |
33 | import com.github.javaparser.metamodel.JavaParserMetaModel; |
34 | import com.github.javaparser.TokenRange; |
35 | import com.github.javaparser.ast.Generated; |
36 | |
37 | /** |
38 | * A name that consists of a single identifier. |
39 | * In other words: it.does.NOT.contain.dots. |
40 | * |
41 | * @see Name |
42 | */ |
43 | public class SimpleName extends Node implements NodeWithIdentifier<SimpleName> { |
44 | |
45 | @NonEmptyProperty |
46 | private String identifier; |
47 | |
48 | public SimpleName() { |
49 | this(null, "empty"); |
50 | } |
51 | |
52 | @AllFieldsConstructor |
53 | public SimpleName(final String identifier) { |
54 | this(null, identifier); |
55 | } |
56 | |
57 | /** |
58 | * This constructor is used by the parser and is considered private. |
59 | */ |
60 | @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") |
61 | public SimpleName(TokenRange tokenRange, String identifier) { |
62 | super(tokenRange); |
63 | setIdentifier(identifier); |
64 | customInitialization(); |
65 | } |
66 | |
67 | @Override |
68 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
69 | public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { |
70 | return v.visit(this, arg); |
71 | } |
72 | |
73 | @Override |
74 | @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") |
75 | public <A> void accept(final VoidVisitor<A> v, final A arg) { |
76 | v.visit(this, arg); |
77 | } |
78 | |
79 | @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
80 | public String getIdentifier() { |
81 | return identifier; |
82 | } |
83 | |
84 | @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") |
85 | public SimpleName setIdentifier(final String identifier) { |
86 | assertNonEmpty(identifier); |
87 | if (identifier == this.identifier) { |
88 | return (SimpleName) this; |
89 | } |
90 | notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier); |
91 | this.identifier = identifier; |
92 | return this; |
93 | } |
94 | |
95 | @Override |
96 | @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") |
97 | public boolean remove(Node node) { |
98 | if (node == null) |
99 | return false; |
100 | return super.remove(node); |
101 | } |
102 | |
103 | public String asString() { |
104 | return identifier; |
105 | } |
106 | |
107 | @Override |
108 | @Generated("com.github.javaparser.generator.core.node.CloneGenerator") |
109 | public SimpleName clone() { |
110 | return (SimpleName) accept(new CloneVisitor(), null); |
111 | } |
112 | |
113 | @Override |
114 | @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") |
115 | public SimpleNameMetaModel getMetaModel() { |
116 | return JavaParserMetaModel.simpleNameMetaModel; |
117 | } |
118 | |
119 | @Override |
120 | @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") |
121 | public boolean replace(Node node, Node replacementNode) { |
122 | if (node == null) |
123 | return false; |
124 | return super.replace(node, replacementNode); |
125 | } |
126 | } |
127 |
Members