1 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 name = getTypeBinding().getName(); 38 if( "int".equals(name) ) return PrimitiveType.Kind.INT; 40 else if( "byte".equals(name) ) return PrimitiveType.Kind.BYTE; 42 else if( "short".equals(name) ) return PrimitiveType.Kind.SHORT; 44 else if( "char".equals(name) ) return PrimitiveType.Kind.CHAR; 46 else if( "long".equals(name) ) return PrimitiveType.Kind.LONG; 48 else if( "float".equals(name) ) return PrimitiveType.Kind.FLOAT; 50 else if( "double".equals(name) ) return PrimitiveType.Kind.DOUBLE; 52 else if( "boolean".equals(name)) return PrimitiveType.Kind.BOOLEAN; 54 else 55 throw new IllegalStateException ("unrecognized primitive type " + _binding); } 57 58 public String 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 obj) 65 { 66 try{ 67 return this._binding.isEqualTo( ((PrimitiveTypeImpl)obj)._binding ); 68 } 69 catch(ClassCastException 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 |