blob: 0f897c3854c0e7f5792f67e1aa1cee312c72e48a (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package com.github.javaparser.ast.imports;
import com.github.javaparser.Range;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;
import static com.github.javaparser.ast.expr.NameExpr.*;
import static com.github.javaparser.utils.Utils.assertNotNull;
/**
* Examples:
* <code>
* import com.github.javaparser.*;
* import com.github.javaparser.JavaParser.*;
* </code>
* Since a parser cannot differentiate between a type name and a package name, we simply store a NameExpr.
* <p><a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-7.html#jls-7.5.2">JLS 7.5.2. Type-Import-on-Demand Declarations</a></p>
*/
public class TypeImportOnDemandDeclaration extends ImportDeclaration {
private NameExpr name;
public TypeImportOnDemandDeclaration() {
this(Range.UNKNOWN, name(""));
}
public TypeImportOnDemandDeclaration(Range range, NameExpr name) {
super(range);
setName(name);
}
@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
return v.visit(this, arg);
}
@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
v.visit(this, arg);
}
/**
* Retrieves the name of the import.
*
* @return the name of the import
* @throws UnsupportedOperationException when invoked on an empty import declaration
*/
public NameExpr getName() {
return name;
}
/**
* Sets the name this import.
*
* @param name
* the name to set
*/
public ImportDeclaration setName(NameExpr name) {
this.name = assertNotNull(name);
setAsParentNodeOf(this.name);
return this;
}
}
|