Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 444376cb94e9bca2259aea75713db0ff99b26c54 (plain) (blame)
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
78
79
80
81
82
83
/*******************************************************************************
 * Copyright (c) 2006, 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.internal.compiler.apt.model;

import javax.lang.model.element.Element;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.TypeVisitor;

import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding;

/**
 * Implementation of TypeVariable
 */
public class TypeVariableImpl extends TypeMirrorImpl implements TypeVariable {
	
	TypeVariableImpl(BaseProcessingEnvImpl env, TypeVariableBinding binding) {
		super(env, binding);
	}
	/* (non-Javadoc)
	 * @see javax.lang.model.type.TypeVariable#asElement()
	 */
	@Override
	public Element asElement() {
		return _env.getFactory().newElement(this._binding);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.type.TypeVariable#getLowerBound()
	 */
	@Override
	public TypeMirror getLowerBound() {
		// TODO might be more complex than this
		return this._env.getFactory().getNullType();
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.type.TypeVariable#getUpperBound()
	 */
	@Override
	public TypeMirror getUpperBound() {
		TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this._binding;
		TypeBinding firstBound = typeVariableBinding.firstBound;
		ReferenceBinding[] superInterfaces = typeVariableBinding.superInterfaces;
		if (firstBound == null || superInterfaces.length == 0) {
			// no explicit bound
			return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound());
		}
		if (firstBound != null && superInterfaces.length == 1 && TypeBinding.equalsEquals(superInterfaces[0], firstBound)) {
			// only one bound that is an interface
			return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound());
		}
		return this._env.getFactory().newTypeMirror((TypeVariableBinding) this._binding);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.type.TypeMirror#accept(javax.lang.model.type.TypeVisitor, java.lang.Object)
	 */
	@Override
	public <R, P> R accept(TypeVisitor<R, P> v, P p) {
		return v.visitTypeVariable(this, p);
	}
	
	@Override
	public TypeKind getKind() {
		return TypeKind.TYPEVAR;
	}
	
	
}

Back to the top