com.sun.codemodel.JTypeVar Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://jwsdp.dev.java.net/CDDLv1.0.html
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
* add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your
* own identifying information: Portions Copyright [yyyy]
* [name of copyright owner]
*/
package com.sun.codemodel;
import java.util.Iterator;
import java.util.List;
/**
* Type variable used to declare generics.
*
* @see JGenerifiable
* @author
* Kohsuke Kawaguchi ([email protected])
*/
public final class JTypeVar extends JClass implements JDeclaration {
private final String name;
private JClass bound;
JTypeVar(JCodeModel owner, String _name) {
super(owner);
this.name = _name;
}
public String name() {
return name;
}
public String fullName() {
return name;
}
public JPackage _package() {
return null;
}
/**
* Adds a bound to this variable.
*
* @return this
*/
public JTypeVar bound( JClass c ) {
if(bound!=null)
throw new IllegalArgumentException("type variable has an existing class bound "+bound);
bound = c;
return this;
}
/**
* Returns the class bound of this variable.
*
*
* If no bound is given, this method returns {@link Object}.
*/
public JClass _extends() {
if(bound!=null)
return bound;
else
return owner().ref(Object.class);
}
/**
* Returns the interface bounds of this variable.
*/
public Iterator _implements() {
return bound._implements();
}
public boolean isInterface() {
return false;
}
public boolean isAbstract() {
return false;
}
/**
* Prints out the declaration of the variable.
*/
public void declare(JFormatter f) {
f.id(name);
if(bound!=null)
f.p("extends").g(bound);
}
protected JClass substituteParams(JTypeVar[] variables, List bindings) {
for(int i=0;i