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: * * import com.github.javaparser.*; * import com.github.javaparser.JavaParser.*; * * Since a parser cannot differentiate between a type name and a package name, we can only store a Name. *

JLS 7.5.2. Type-Import-on-Demand Declarations

*/ public class TypeImportOnDemandDeclaration extends NonEmptyImportDeclaration implements NodeWithName { private Name name; public TypeImportOnDemandDeclaration() { this(null, new Name()); } public TypeImportOnDemandDeclaration(Range range, Name name) { super(range); setName(name); } @Override public R accept(GenericVisitor v, A arg) { return v.visit(this, arg); } @Override public void accept(VoidVisitor 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; } }