KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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  * wharley@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.compiler.apt.model;
14
15 import javax.lang.model.type.TypeKind;
16 import javax.lang.model.type.TypeMirror;
17 import javax.lang.model.type.TypeVisitor;
18
19 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
20 import org.eclipse.jdt.internal.compiler.lookup.Binding;
21
22 /**
23  * Implementation of a TypeMirror. TypeMirror represents a type, including
24  * types that have no declaration, such as primitives (int, boolean) and
25  * types that are specializations of declarations (List<String>).
26  */

27 public class TypeMirrorImpl implements TypeMirror {
28
29     // Caution: _env will be NULL for PrimitiveTypeImpl.
30
protected final BaseProcessingEnvImpl _env;
31     protected final Binding _binding;
32     
33     /* package */ TypeMirrorImpl(BaseProcessingEnvImpl env, Binding binding) {
34         _env = env;
35         _binding = binding;
36     }
37     
38     /* package */ Binding binding() {
39         return _binding;
40     }
41
42     /* (non-Javadoc)
43      * @see javax.lang.model.type.TypeMirror#accept(javax.lang.model.type.TypeVisitor, java.lang.Object)
44      */

45     @Override JavaDoc
46     public <R, P> R accept(TypeVisitor<R, P> v, P p) {
47         return v.visit(this, p);
48     }
49
50     /* (non-Javadoc)
51      * @see javax.lang.model.type.TypeMirror#getKind()
52      */

53     @Override JavaDoc
54     public TypeKind getKind() {
55         switch (_binding.kind()) {
56         // case Binding.TYPE:
57
// case Binding.RAW_TYPE:
58
// case Binding.GENERIC_TYPE:
59
// case Binding.PARAMETERIZED_TYPE:
60
// handled by DeclaredTypeImpl, etc.
61
// case Binding.BASE_TYPE: handled by PrimitiveTypeImpl
62
// case Binding.METHOD: handled by ExecutableTypeImpl
63
// case Binding.PACKAGE: handled by NoTypeImpl
64
// case Binding.WILDCARD_TYPE: handled by WildcardTypeImpl
65
// case Binding.ARRAY_TYPE: handled by ArrayTypeImpl
66
// case Binding.TYPE_PARAMETER: handled by TypeVariableImpl
67
// TODO: fill in the rest of these
68
case Binding.FIELD:
69         case Binding.LOCAL:
70         case Binding.VARIABLE:
71         case Binding.IMPORT:
72             throw new IllegalArgumentException JavaDoc("Invalid binding kind: " + _binding.kind()); //$NON-NLS-1$
73
}
74         return null;
75     }
76
77     /* (non-Javadoc)
78      * @see java.lang.Object#toString()
79      */

80     @Override JavaDoc
81     public String JavaDoc toString() {
82         return new String JavaDoc(_binding.readableName());
83     }
84
85     /* (non-Javadoc)
86      * @see java.lang.Object#hashCode()
87      */

88     @Override JavaDoc
89     public int hashCode() {
90         final int prime = 31;
91         int result = 1;
92         result = prime * result + ((_binding == null) ? 0 : _binding.hashCode());
93         return result;
94     }
95
96     /* (non-Javadoc)
97      * @see java.lang.Object#equals(java.lang.Object)
98      */

99     @Override JavaDoc
100     public boolean equals(Object JavaDoc obj) {
101         if (this == obj)
102             return true;
103         if (!(obj instanceof TypeMirrorImpl))
104             return false;
105         final TypeMirrorImpl other = (TypeMirrorImpl) obj;
106         return _binding == other._binding;
107     }
108
109     
110 }
111
Popular Tags