private Type mergeClasses(Type type) throws NotFoundException { CtClass superClass = findCommonSuperClass(this.clazz, type.clazz); // If its Object, then try and find a common interface(s) if (superClass.getSuperclass() == null) { Map interfaces = findCommonInterfaces(type); if (interfaces.size() == 1) return new Type((CtClass) interfaces.values().iterator().next()); if (interfaces.size() > 1) return new MultiType(interfaces); // Only Object is in common return new Type(superClass); } // Check for a common interface that is not on the found supertype Map commonDeclared = findExclusiveDeclaredInterfaces(type, superClass); if (commonDeclared.size() > 0) { return new MultiType(commonDeclared, new Type(superClass)); } return new Type(superClass); }
public boolean equals(Object o) { if (! (o instanceof MultiArrayType)) return false; MultiArrayType multi = (MultiArrayType)o; return component.equals(multi.component) && dims == multi.dims; }
private Map mergeMultiAndSingle(MultiType multi, Type single) { Map map1 = getAllMultiInterfaces(multi); Map map2 = getAllInterfaces(single.getCtClass(), null); return findCommonInterfaces(map1, map2); }
private Map mergeMultiInterfaces(MultiType type1, MultiType type2) { Map map1 = getAllMultiInterfaces(type1); Map map2 = getAllMultiInterfaces(type2); return findCommonInterfaces(map1, map2); }
public boolean isAssignableTo(Type type) { if (resolved != null) return type.isAssignableFrom(resolved); if (Type.OBJECT.equals(type)) return true; if (potentialClass != null && !type.isAssignableFrom(potentialClass)) potentialClass = null; Map map = mergeMultiAndSingle(this, type); if (map.size() == 1 && potentialClass == null) { // Update previous merge paths to the same resolved type resolved = Type.get((CtClass)map.values().iterator().next()); propogateResolved(); return true; } // Keep all previous merge paths up to date if (map.size() >= 1) { interfaces = map; propogateState(); return true; } if (potentialClass != null) { resolved = potentialClass; propogateResolved(); return true; } return false; }
merged = mergeMultiAndSingle(this, multi.resolved); } else { merged = mergeMultiInterfaces(multi, this); if (! inMergeSource(multi)) mergeSource = multi; merged = mergeMultiAndSingle(this, type); propogateState(); propogateResolved();
/** * Determines whether this type is assignable, to the passed type. * A type is assignable to another if it is either the same type, or * a sub-type. * * @param type the type to test assignability to * @return true if this is assignable to type, otherwise false */ public boolean isAssignableFrom(Type type) { if (this == type) return true; if ((type == UNINIT && isReference()) || this == UNINIT && type.isReference()) return true; if (type instanceof MultiType) return ((MultiType)type).isAssignableTo(this); if (type instanceof MultiArrayType) return ((MultiArrayType)type).isAssignableTo(this); // Primitives and Special types must be identical if (clazz == null || clazz.isPrimitive()) return false; try { return type.clazz.subtypeOf(clazz); } catch (Exception e) { throw new RuntimeException(e); } }
private Map getAllMultiInterfaces(MultiType type) { Map map = new HashMap(); Iterator iter = type.interfaces.values().iterator(); while (iter.hasNext()) { CtClass intf = (CtClass)iter.next(); map.put(intf.getName(), intf); getAllInterfaces(intf, map); } return map; }
public CtClass getCtClass() { CtClass clazz = component.getCtClass(); if (clazz == null) return null; ClassPool pool = clazz.getClassPool(); if (pool == null) pool = ClassPool.getDefault(); String name = arrayName(clazz.getName(), dims); try { return pool.get(name); } catch (NotFoundException e) { throw new RuntimeException(e); } }
merged = mergeMultiAndSingle(this, multi.resolved); } else { merged = mergeMultiInterfaces(multi, this); if (! inMergeSource(multi)) mergeSource = multi; merged = mergeMultiAndSingle(this, type); propogateState(); resolved = OBJECT; propogateResolved();
public boolean isAssignableTo(Type type) { if (resolved != null) return type.isAssignableFrom(resolved); if (Type.OBJECT.equals(type)) return true; if (potentialClass != null && !type.isAssignableFrom(potentialClass)) potentialClass = null; Map<String,CtClass> map = mergeMultiAndSingle(this, type); if (map.size() == 1 && potentialClass == null) { // Update previous merge paths to the same resolved type resolved = Type.get(map.values().iterator().next()); propogateResolved(); return true; } // Keep all previous merge paths up to date if (map.size() >= 1) { interfaces = map; propogateState(); return true; } if (potentialClass != null) { resolved = potentialClass; propogateResolved(); return true; } return false; }
private Map<String,CtClass> mergeMultiInterfaces(MultiType type1, MultiType type2) { Map<String,CtClass> map1 = getAllMultiInterfaces(type1); Map<String,CtClass> map2 = getAllMultiInterfaces(type2); return findCommonInterfaces(map1, map2); }
/** * Determines whether this type is assignable, to the passed type. * A type is assignable to another if it is either the same type, or * a sub-type. * * @param type the type to test assignability to * @return true if this is assignable to type, otherwise false */ public boolean isAssignableFrom(Type type) { if (this == type) return true; if ((type == UNINIT && isReference()) || this == UNINIT && type.isReference()) return true; if (type instanceof MultiType) return ((MultiType)type).isAssignableTo(this); if (type instanceof MultiArrayType) return ((MultiArrayType)type).isAssignableTo(this); // Primitives and Special types must be identical if (clazz == null || clazz.isPrimitive()) return false; try { return type.clazz.subtypeOf(clazz); } catch (Exception e) { throw new RuntimeException(e); } }
private Map<String,CtClass> getAllMultiInterfaces(MultiType type) { Map<String,CtClass> map = new HashMap<String,CtClass>(); for (CtClass intf:type.interfaces.values()) { map.put(intf.getName(), intf); getAllInterfaces(intf, map); } return map; }
@Override public CtClass getCtClass() { CtClass clazz = component.getCtClass(); if (clazz == null) return null; ClassPool pool = clazz.getClassPool(); if (pool == null) pool = ClassPool.getDefault(); String name = arrayName(clazz.getName(), dims); try { return pool.get(name); } catch (NotFoundException e) { throw new RuntimeException(e); } }
merged = mergeMultiAndSingle(this, multi.resolved); } else { merged = mergeMultiInterfaces(multi, this); if (! inMergeSource(multi)) mergeSource = multi; merged = mergeMultiAndSingle(this, type); propogateState(); propogateResolved();
private Map<String,CtClass> mergeMultiAndSingle(MultiType multi, Type single) { Map<String,CtClass> map1 = getAllMultiInterfaces(multi); Map<String,CtClass> map2 = getAllInterfaces(single.getCtClass(), null); return findCommonInterfaces(map1, map2); }
public boolean isAssignableTo(Type type) { if (resolved != null) return type.isAssignableFrom(resolved); if (Type.OBJECT.equals(type)) return true; if (potentialClass != null && !type.isAssignableFrom(potentialClass)) potentialClass = null; Map map = mergeMultiAndSingle(this, type); if (map.size() == 1 && potentialClass == null) { // Update previous merge paths to the same resolved type resolved = Type.get((CtClass)map.values().iterator().next()); propogateResolved(); return true; } // Keep all previous merge paths up to date if (map.size() >= 1) { interfaces = map; propogateState(); return true; } if (potentialClass != null) { resolved = potentialClass; propogateResolved(); return true; } return false; }
private Map mergeMultiInterfaces(MultiType type1, MultiType type2) { Map map1 = getAllMultiInterfaces(type1); Map map2 = getAllMultiInterfaces(type2); return findCommonInterfaces(map1, map2); }
public boolean isAssignableTo(Type type) { if (eq(type.getCtClass(), Type.OBJECT.getCtClass())) return true; if (eq(type.getCtClass(), Type.CLONEABLE.getCtClass())) return true; if (eq(type.getCtClass(), Type.SERIALIZABLE.getCtClass())) return true; if (! type.isArray()) return false; Type typeRoot = getRootComponent(type); int typeDims = type.getDimensions(); if (typeDims > dims) return false; if (typeDims < dims) { if (eq(typeRoot.getCtClass(), Type.OBJECT.getCtClass())) return true; if (eq(typeRoot.getCtClass(), Type.CLONEABLE.getCtClass())) return true; if (eq(typeRoot.getCtClass(), Type.SERIALIZABLE.getCtClass())) return true; return false; } return component.isAssignableTo(typeRoot); }