KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrimitiveType;
15 import com.sun.mirror.util.TypeVisitor;
16
17 import org.eclipse.jdt.apt.core.internal.declaration.EclipseMirrorType;
18 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
19 import org.eclipse.jdt.core.dom.ITypeBinding;
20
21 public class PrimitiveTypeImpl implements PrimitiveType, EclipseMirrorType
22 {
23     private final ITypeBinding _binding;
24     
25     public PrimitiveTypeImpl(ITypeBinding binding)
26     {
27         assert binding != null;
28         _binding = binding;
29     }
30     public void accept(TypeVisitor visitor)
31     {
32         visitor.visitPrimitiveType(this);
33     }
34
35     public PrimitiveType.Kind getKind()
36     {
37         final String JavaDoc name = getTypeBinding().getName();
38         if( "int".equals(name) ) //$NON-NLS-1$
39
return PrimitiveType.Kind.INT;
40         else if( "byte".equals(name) ) //$NON-NLS-1$
41
return PrimitiveType.Kind.BYTE;
42         else if( "short".equals(name) ) //$NON-NLS-1$
43
return PrimitiveType.Kind.SHORT;
44         else if( "char".equals(name) ) //$NON-NLS-1$
45
return PrimitiveType.Kind.CHAR;
46         else if( "long".equals(name) ) //$NON-NLS-1$
47
return PrimitiveType.Kind.LONG;
48         else if( "float".equals(name) ) //$NON-NLS-1$
49
return PrimitiveType.Kind.FLOAT;
50         else if( "double".equals(name) ) //$NON-NLS-1$
51
return PrimitiveType.Kind.DOUBLE;
52         else if( "boolean".equals(name)) //$NON-NLS-1$
53
return PrimitiveType.Kind.BOOLEAN;
54         else
55             throw new IllegalStateException JavaDoc("unrecognized primitive type " + _binding); //$NON-NLS-1$
56
}
57     
58     public String JavaDoc toString(){ return _binding.getName(); }
59
60     public ITypeBinding getTypeBinding(){ return _binding; }
61
62     public MirrorKind kind(){ return MirrorKind.TYPE_PRIMITIVE; }
63     
64     public boolean equals(final Object JavaDoc obj)
65     {
66         try{
67             return this._binding.isEqualTo( ((PrimitiveTypeImpl)obj)._binding );
68         }
69         catch(ClassCastException JavaDoc e){
70             return false;
71         }
72     }
73     
74     public BaseProcessorEnv getEnvironment(){ return null; }
75     
76     public boolean isAssignmentCompatible(EclipseMirrorType left) {
77         return getTypeBinding().isAssignmentCompatible(left.getTypeBinding());
78     }
79     public boolean isSubTypeCompatible(EclipseMirrorType type) {
80         return getTypeBinding().isSubTypeCompatible(type.getTypeBinding());
81     }
82 }
83
Popular Tags