private ReferenceType computeFirstCommonSuperclassOfDifferentDimensionArrays ( ArrayType aArrType , ArrayType bArrType ) { assert aArrType . getDimensions ( ) != bArrType . getDimensions ( ) ; boolean aBaseTypeIsPrimitive = ( aArrType . getBasicType ( ) instanceof BasicType ) ; boolean bBaseTypeIsPrimitive = ( bArrType . getBasicType ( ) instanceof BasicType ) ; if ( aBaseTypeIsPrimitive || bBaseTypeIsPrimitive ) { int minDimensions , maxDimensions ; if ( aArrType . getDimensions ( ) < bArrType . getDimensions ( ) ) { minDimensions = aArrType . getDimensions ( ) ; maxDimensions = bArrType . getDimensions ( ) ; } else { minDimensions = bArrType . getDimensions ( ) ; maxDimensions = aArrType . getDimensions ( ) ; } if ( minDimensions == 1 ) { // One of the types was something like int[]. // The only possible common supertype is Object. return Type . OBJECT ; } else { // Weird case: e.g., // - first common supertype of int[][] and char[][][] is // Object[] // because f.c.s. of int[] and char[][] is Object // - first common supertype of int[][][] and char[][][][][] is // Object[][] // because f.c.s. of int[] and char[][][] is Object return new ArrayType ( Type . OBJECT , maxDimensions - minDimensions ) ; } } else { // Both a and b have base types which are ObjectTypes. // Since the arrays have different numbers of dimensions, the // f.c.s. will have Object as its base type. // E.g., f.c.s. of Cat[] and Dog[][] is Object[] return new ArrayType ( Type . OBJECT , Math . min ( aArrType . getDimensions ( ) , bArrType . getDimensions ( ) ) ) ; } }
Get the first common superclass of arrays with different numbers of dimensions .