| 1 11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types; 12 13 import org.eclipse.jdt.core.IJavaProject; 14 15 16 public final class PrimitiveType extends TType { 17 18 19 public static final int INT = 0; 20 21 public static final int CHAR = 1; 22 23 public static final int BOOLEAN = 2; 24 25 public static final int SHORT = 3; 26 27 public static final int LONG = 4; 28 29 public static final int FLOAT = 5; 30 31 public static final int DOUBLE = 6; 32 33 public static final int BYTE = 7; 34 35 static final String [] NAMES= { 36 "int", "char", "boolean", "short", "long", "float", "double", "byte"}; 45 private int fId; 46 47 protected PrimitiveType(TypeEnvironment environment, int id, String signature) { 48 super(environment, signature); 49 fId= id; 50 } 51 52 public int getId() { 53 return fId; 54 } 55 56 public int getKind() { 57 return PRIMITIVE_TYPE; 58 } 59 60 protected boolean doEquals(TType type) { 61 return fId == ((PrimitiveType)type).fId; 62 } 63 64 protected boolean doCanAssignTo(TType lhs) { 65 if (lhs.getKind() != PRIMITIVE_TYPE) { 66 if (lhs.getKind() == STANDARD_TYPE) { 67 IJavaProject javaProject= ((StandardType)lhs).getJavaElementType().getJavaProject(); 68 return getEnvironment().createBoxed(this, javaProject).canAssignTo(lhs); 69 } 70 return false; 71 } 72 73 switch (((PrimitiveType)lhs).fId) { 74 case BOOLEAN : 75 case BYTE : 76 case CHAR : 77 return false; 78 case DOUBLE : 79 switch (fId) { 80 case BYTE : 81 case CHAR : 82 case SHORT : 83 case INT : 84 case LONG : 85 case FLOAT : 86 return true; 87 default : 88 return false; 89 } 90 case FLOAT : 91 switch (fId) { 92 case BYTE : 93 case CHAR : 94 case SHORT : 95 case INT : 96 case LONG : 97 return true; 98 default : 99 return false; 100 } 101 case LONG : 102 switch (fId) { 103 case BYTE : 104 case CHAR : 105 case SHORT : 106 case INT : 107 return true; 108 default : 109 return false; 110 } 111 case INT : 112 switch (fId) { 113 case BYTE : 114 case CHAR : 115 case SHORT : 116 return true; 117 default : 118 return false; 119 } 120 case SHORT : 121 return (fId == BYTE); 122 } 123 return false; 124 } 125 126 public String getName() { 127 return NAMES[fId]; 128 } 129 130 protected String getPlainPrettySignature() { 131 return NAMES[fId]; 132 } 133 } 134 | Popular Tags |