KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrimitiveType;
16 import javax.lang.model.type.TypeKind;
17 import javax.lang.model.type.TypeVisitor;
18
19 import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
20 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
21 import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
22
23 /**
24  *
25  * @since 3.3
26  */

27 public class PrimitiveTypeImpl extends TypeMirrorImpl implements PrimitiveType {
28     
29     public final static PrimitiveTypeImpl BOOLEAN = new PrimitiveTypeImpl(TypeBinding.BOOLEAN);
30     public final static PrimitiveTypeImpl BYTE = new PrimitiveTypeImpl(TypeBinding.BYTE);
31     public final static PrimitiveTypeImpl CHAR = new PrimitiveTypeImpl(TypeBinding.CHAR);
32     public final static PrimitiveTypeImpl DOUBLE = new PrimitiveTypeImpl(TypeBinding.DOUBLE);
33     public final static PrimitiveTypeImpl FLOAT = new PrimitiveTypeImpl(TypeBinding.FLOAT);
34     public final static PrimitiveTypeImpl INT = new PrimitiveTypeImpl(TypeBinding.INT);
35     public final static PrimitiveTypeImpl LONG = new PrimitiveTypeImpl(TypeBinding.LONG);
36     public final static PrimitiveTypeImpl SHORT = new PrimitiveTypeImpl(TypeBinding.SHORT);
37     
38     /**
39      * Clients should call {@link Factory#getPrimitiveType(TypeKind)},
40      * rather than creating new objects.
41      */

42     private PrimitiveTypeImpl(BaseTypeBinding binding) {
43         // Primitive types do not need an environment!
44
super(null, binding);
45     }
46     
47     @Override JavaDoc
48     public <R, P> R accept(TypeVisitor<R, P> v, P p)
49     {
50         return v.visitPrimitive(this, p);
51     }
52
53     /* (non-Javadoc)
54      * @see org.eclipse.jdt.internal.compiler.apt.model.TypeMirrorImpl#getKind()
55      */

56     @Override JavaDoc
57     public TypeKind getKind() {
58         return getKind((BaseTypeBinding)_binding);
59     }
60
61     public static TypeKind getKind(BaseTypeBinding binding) {
62         switch (binding.id) {
63         case TypeIds.T_boolean:
64             return TypeKind.BOOLEAN;
65         case TypeIds.T_byte:
66             return TypeKind.BYTE;
67         case TypeIds.T_char:
68             return TypeKind.CHAR;
69         case TypeIds.T_double:
70             return TypeKind.DOUBLE;
71         case TypeIds.T_float:
72             return TypeKind.FLOAT;
73         case TypeIds.T_int:
74             return TypeKind.INT;
75         case TypeIds.T_long:
76             return TypeKind.LONG;
77         case TypeIds.T_short:
78             return TypeKind.SHORT;
79         default:
80             throw new IllegalArgumentException JavaDoc("BaseTypeBinding of unexpected id " + binding.id); //$NON-NLS-1$
81
}
82     }
83     
84 }
85
Popular Tags