KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > apt > model > TypeVariableImpl


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.compiler.apt.model;
13
14 import javax.lang.model.element.Element;
15 import javax.lang.model.type.TypeKind;
16 import javax.lang.model.type.TypeMirror;
17 import javax.lang.model.type.TypeVariable;
18 import javax.lang.model.type.TypeVisitor;
19
20 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
21 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
22 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
23 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;
24
25 /**
26  * @author OThomann
27  *
28  */

29 public class TypeVariableImpl extends TypeMirrorImpl implements TypeVariable {
30     
31     public TypeVariableImpl(BaseProcessingEnvImpl env, TypeVariableBinding binding) {
32         super(env, binding);
33     }
34     /* (non-Javadoc)
35      * @see javax.lang.model.type.TypeVariable#asElement()
36      */

37     @Override JavaDoc
38     public Element asElement() {
39         return _env.getFactory().newElement(this._binding);
40     }
41
42     /* (non-Javadoc)
43      * @see javax.lang.model.type.TypeVariable#getLowerBound()
44      */

45     @Override JavaDoc
46     public TypeMirror getLowerBound() {
47         // TODO might be more complex than this
48
return this._env.getFactory().getNullType();
49     }
50
51     /* (non-Javadoc)
52      * @see javax.lang.model.type.TypeVariable#getUpperBound()
53      */

54     @Override JavaDoc
55     public TypeMirror getUpperBound() {
56         TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this._binding;
57         TypeBinding firstBound = typeVariableBinding.firstBound;
58         ReferenceBinding[] superInterfaces = typeVariableBinding.superInterfaces;
59         if (firstBound == null || superInterfaces.length == 0) {
60             // no explicit bound
61
return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound());
62         }
63         if (firstBound != null && superInterfaces.length == 1 && superInterfaces[0] == firstBound) {
64             // only one bound that is an interface
65
return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound());
66         }
67         return this._env.getFactory().newDeclaredType((TypeVariableBinding) this._binding);
68     }
69
70     /* (non-Javadoc)
71      * @see javax.lang.model.type.TypeMirror#accept(javax.lang.model.type.TypeVisitor, java.lang.Object)
72      */

73     @Override JavaDoc
74     public <R, P> R accept(TypeVisitor<R, P> v, P p) {
75         return v.visitTypeVariable(this, p);
76     }
77     
78     @Override JavaDoc
79     public TypeKind getKind()
80     {
81         return TypeKind.TYPEVAR;
82     }
83     
84     
85 }
86
Popular Tags