aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-core/src/main/java/com/github/javaparser/ast/imports/TypeImportOnDemandDeclaration.java
blob: e0d552c91f57622392e87affb7bbbf845bfce175 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.github.javaparser.ast.imports;

import com.github.javaparser.Range;
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.ast.nodeTypes.NodeWithName;
import com.github.javaparser.ast.observing.ObservableProperty;
import com.github.javaparser.ast.visitor.GenericVisitor;
import com.github.javaparser.ast.visitor.VoidVisitor;

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 can only store a Name.
 * <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 NonEmptyImportDeclaration implements NodeWithName<TypeImportOnDemandDeclaration> {
    private Name name;

    public TypeImportOnDemandDeclaration() {
        this(null, new Name());
    }
    
    public TypeImportOnDemandDeclaration(Range range, Name 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
     */
    @Override
    public Name getName() {
        return name;
    }

    /**
     * Sets the name this import.
     *
     * @param name
     *            the name to set
     */
    @Override
    public TypeImportOnDemandDeclaration setName(Name name) {
        notifyPropertyChange(ObservableProperty.NAME, this.name, name);
        this.name = assertNotNull(name);
        setAsParentNodeOf(this.name);
        return this;
    }

    @Override
    boolean isAsterisk() {
        return true;
    }

    @Override
    boolean isStatic() {
        return false;
    }
}