Returns the common super type of the two given types. The default implementation of this method loads the two given classes and uses the java.lang.Class methods to find the common super class. It can be overridden to compute this common super type in other ways, in particular without actually
(final String type1, final String type2)
| 940 | * @return the internal name of the common super class of the two given classes. |
| 941 | */ |
| 942 | protected String getCommonSuperClass(final String type1, final String type2) { |
| 943 | ClassLoader classLoader = getClass().getClassLoader(); |
| 944 | Class<?> class1; |
| 945 | try { |
| 946 | class1 = Class.forName(type1.replace('/', '.'), false, classLoader); |
| 947 | } catch (Exception e) { |
| 948 | throw new TypeNotPresentException(type1, e); |
| 949 | } |
| 950 | Class<?> class2; |
| 951 | try { |
| 952 | class2 = Class.forName(type2.replace('/', '.'), false, classLoader); |
| 953 | } catch (Exception e) { |
| 954 | throw new TypeNotPresentException(type2, e); |
| 955 | } |
| 956 | if (class1.isAssignableFrom(class2)) { |
| 957 | return type1; |
| 958 | } |
| 959 | if (class2.isAssignableFrom(class1)) { |
| 960 | return type2; |
| 961 | } |
| 962 | if (class1.isInterface() || class2.isInterface()) { |
| 963 | return "java/lang/Object"; |
| 964 | } else { |
| 965 | do { |
| 966 | class1 = class1.getSuperclass(); |
| 967 | } while (!class1.isAssignableFrom(class2)); |
| 968 | return class1.getName().replace('.', '/'); |
| 969 | } |
| 970 | } |
| 971 | } |
no test coverage detected