KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > type > WildcardTypeImpl


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
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  * tyeung@bea.com - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.apt.core.internal.type;
13
14 import com.sun.mirror.type.ReferenceType;
15 import com.sun.mirror.type.WildcardType;
16 import com.sun.mirror.util.TypeVisitor;
17 import java.util.Collection JavaDoc;
18 import java.util.Collections JavaDoc;
19
20 import org.eclipse.jdt.apt.core.internal.declaration.EclipseMirrorType;
21 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
22 import org.eclipse.jdt.apt.core.internal.util.Factory;
23 import org.eclipse.jdt.core.dom.ITypeBinding;
24
25 public class WildcardTypeImpl implements WildcardType, EclipseMirrorType
26 {
27     private final ITypeBinding _binding;
28     private final BaseProcessorEnv _env;
29
30     public WildcardTypeImpl(ITypeBinding binding, BaseProcessorEnv env)
31     {
32         _binding = binding;
33         _env = env;
34         assert _binding != null && _binding.isWildcardType();
35         assert env != null : "missing environment"; //$NON-NLS-1$
36
}
37     
38     public void accept(TypeVisitor visitor)
39     {
40         visitor.visitWildcardType(this);
41     }
42
43     public Collection JavaDoc<ReferenceType> getLowerBounds()
44     {
45         final ITypeBinding bound = _binding.getBound();
46         // no bound or has an upper bound.
47
if( bound == null || _binding.isUpperbound() )
48             return Collections.emptyList();
49         ReferenceType mirror = Factory.createReferenceType(bound, _env);
50         if( mirror == null )
51             mirror = Factory.createErrorClassType(bound);
52         return Collections.singletonList(mirror);
53     }
54
55     public Collection JavaDoc<ReferenceType> getUpperBounds()
56     {
57         final ITypeBinding bound = _binding.getBound();
58         // no bound or has a lower bound.
59
if( bound == null || !_binding.isUpperbound() )
60             return Collections.emptyList();
61         ReferenceType mirror = Factory.createReferenceType(bound, _env);
62         if( mirror == null )
63             mirror = Factory.createErrorClassType(bound);
64         return Collections.singletonList(mirror);
65     }
66
67     public String JavaDoc toString(){ return _binding.toString(); }
68     public int hashCode(){ return _binding.hashCode(); }
69     public boolean equals(Object JavaDoc obj)
70     {
71         if(obj instanceof WildcardTypeImpl )
72             return ((WildcardTypeImpl)obj)._binding.isEqualTo(_binding);
73         return false;
74     }
75
76     public MirrorKind kind(){ return MirrorKind.TYPE_WILDCARD; }
77
78     public ITypeBinding getTypeBinding(){ return _binding; }
79     
80     public BaseProcessorEnv getEnvironment(){ return _env; }
81
82     public boolean isAssignmentCompatible(EclipseMirrorType left) {
83         return false;
84     }
85
86     public boolean isSubTypeCompatible(EclipseMirrorType type) {
87         return false;
88     }
89
90 }
91
Popular Tags