1 4 package com.puppycrawl.tools.checkstyle.bcel.generic; 5 6 import org.apache.bcel.generic.ReferenceType; 7 import org.apache.bcel.generic.Type; 8 9 14 public class Utils 15 { 16 25 public static boolean isCompatible(Type aSubType, Type aSuperType) 26 { 27 boolean result = false; 28 29 if (aSubType.equals(aSuperType)) { 30 result = true; 32 } 33 else if ((aSubType instanceof ReferenceType) 34 && (aSuperType instanceof ReferenceType)) 35 { 36 final ReferenceType aSubRefType = (ReferenceType) aSubType; 38 result = aSubRefType.isAssignmentCompatibleWith(aSuperType); 39 } 40 else if (aSubType.equals(Type.BYTE)) { 42 result = 43 aSuperType.equals(Type.SHORT) 44 || aSuperType.equals(Type.INT) 45 || aSuperType.equals(Type.LONG) 46 || aSuperType.equals(Type.FLOAT) 47 || aSuperType.equals(Type.DOUBLE); 48 } 49 else if (aSubType.equals(Type.SHORT)) { 50 result = 51 aSuperType.equals(Type.INT) 52 || aSuperType.equals(Type.LONG) 53 || aSuperType.equals(Type.FLOAT) 54 || aSuperType.equals(Type.DOUBLE); 55 } 56 else if (aSubType.equals(Type.INT)) { 57 result = 58 aSuperType.equals(Type.LONG) 59 || aSuperType.equals(Type.FLOAT) 60 || aSuperType.equals(Type.DOUBLE); 61 } 62 else if (aSubType.equals(Type.LONG)) { 63 result = 64 aSuperType.equals(Type.FLOAT) || aSuperType.equals(Type.DOUBLE); 65 } 66 else if (aSubType.equals(Type.DOUBLE)) { 67 result = aSuperType.equals(Type.DOUBLE); 68 } 69 return result; 70 } 71 } 72 | Popular Tags |