/** * Does the class implement Serializable? */ private static boolean isSerializable(CtClass clazz) throws NotFoundException { ClassPool pool = clazz.getClassPool(); return clazz.subtypeOf(pool.get("java.io.Serializable")); }
public boolean subtypeOf(CtClass clazz) throws NotFoundException { if (super.subtypeOf(clazz)) return true; String cname = clazz.getName(); if (cname.equals(javaLangObject)) return true; CtClass[] intfs = getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].subtypeOf(clazz)) return true; return clazz.isArray() && getComponentType().subtypeOf(clazz.getComponentType()); }
/** * Does the class implement Serializable? */ private static boolean isSerializable(CtClass clazz) throws NotFoundException { ClassPool pool = clazz.getClassPool(); return clazz.subtypeOf(pool.get("java.io.Serializable")); }
private CtClass fixByUppers(ArrayList users, ClassPool cp, HashSet visited, CtClass type) throws NotFoundException { if (users == null) return type; int size = users.size(); for (int i = 0; i < size; i++) { TypeVar t = (TypeVar)users.get(i); if (!visited.add(t)) return type; if (t.uppers != null) { int s = t.uppers.size(); for (int k = 0; k < s; k++) { CtClass cc = cp.get((String)t.uppers.get(k)); if (cc.subtypeOf(type)) type = cc; } } type = fixByUppers(t.usedBy, cp, visited, type); } return type; }
private boolean matchClass(String name, ClassPool pool) { if (classname.equals(name)) return true; try { CtClass clazz = pool.get(name); CtClass declClazz = pool.get(classname); if (clazz.subtypeOf(declClazz)) try { CtMethod m = clazz.getMethod(methodname, methodDescriptor); return m.getDeclaringClass().getName().equals(classname); } catch (NotFoundException e) { // maybe the original method has been removed. return true; } } catch (NotFoundException e) { return false; } return false; }
public boolean subtypeOf(CtClass clazz) throws NotFoundException { int i; String cname = clazz.getName(); if (this == clazz || getName().equals(cname)) return true; ClassFile file = getClassFile2(); String supername = file.getSuperclass(); if (supername != null && supername.equals(cname)) return true; String[] ifs = file.getInterfaces(); int num = ifs.length; for (i = 0; i < num; ++i) if (ifs[i].equals(cname)) return true; if (supername != null && classPool.get(supername).subtypeOf(clazz)) return true; for (i = 0; i < num; ++i) if (classPool.get(ifs[i]).subtypeOf(clazz)) return true; return false; }
@Override public boolean subtypeOf(CtClass clazz) throws NotFoundException { if (super.subtypeOf(clazz)) return true; String cname = clazz.getName(); if (cname.equals(javaLangObject)) return true; CtClass[] intfs = getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].subtypeOf(clazz)) return true; return clazz.isArray() && getComponentType().subtypeOf(clazz.getComponentType()); }
private int ftype( String sig, CtClass ct, CtField fld ) throws NotFoundException { switch( sig.charAt(0) ) { case 'Z': return 0; // Booleans: I could compress these more case 'B': return 1; // Primitives case 'C': return 2; case 'S': return 3; case 'I': return 4; case 'F': return 5; case 'J': return 6; case 'D': return 7; case 'L': // Handled classes if( sig.equals("Ljava/lang/String;") ) return 8; String clz = sig.substring(1,sig.length()-1).replace('/', '.'); CtClass argClass = _pool.get(clz); if( argClass.subtypeOf(_pool.get("water.Freezable")) ) return 9; if( argClass.subtypeOf(_pool.get("java.lang.Enum")) ) return 10; break; case '[': // Arrays return ftype(sig.substring(1), ct, fld)+20; // Same as prims, plus 20 } throw barf(ct, fld); }
private CtClass fixByUppers(List<TypeData> users, ClassPool cp, Set<TypeData> visited, CtClass type) throws NotFoundException { if (users == null) return type; int size = users.size(); for (int i = 0; i < size; i++) { TypeVar t = (TypeVar)users.get(i); if (!visited.add(t)) return type; if (t.uppers != null) { int s = t.uppers.size(); for (int k = 0; k < s; k++) { CtClass cc = cp.get(t.uppers.get(k)); if (cc.subtypeOf(type)) type = cc; } } type = fixByUppers(t.usedBy, cp, visited, type); } return type; }
private boolean matchClass(String name, ClassPool pool) { if (classname.equals(name)) return true; try { CtClass clazz = pool.get(name); CtClass declClazz = pool.get(classname); if (clazz.subtypeOf(declClazz)) try { CtMethod m = clazz.getMethod(methodname, methodDescriptor); return m.getDeclaringClass().getName().equals(classname); } catch (NotFoundException e) { // maybe the original method has been removed. return true; } } catch (NotFoundException e) { return false; } return false; }
@Override public boolean subtypeOf(CtClass clazz) throws NotFoundException { int i; String cname = clazz.getName(); if (this == clazz || getName().equals(cname)) return true; ClassFile file = getClassFile2(); String supername = file.getSuperclass(); if (supername != null && supername.equals(cname)) return true; String[] ifs = file.getInterfaces(); int num = ifs.length; for (i = 0; i < num; ++i) if (ifs[i].equals(cname)) return true; if (supername != null && classPool.get(supername).subtypeOf(clazz)) return true; for (i = 0; i < num; ++i) if (classPool.get(ifs[i]).subtypeOf(clazz)) return true; return false; }
CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else
CtClass clazz = lookupClassByJvmName(argClassNames[n]); try { if (clazz.subtypeOf(lookupClassByJvmName(cname))) result++; else
/** * 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); } }
boolean addMeta = !clazz.subtypeOf(mlevel); if (addMeta) clazz.addInterface(mlevel);
/** * 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 boolean modifyClassfile(CtClass clazz, CtClass metaobject, CtClass metaclass) throws CannotCompileException, NotFoundException { if (clazz.getAttribute("Reflective") != null) return false; // this is already reflective. clazz.setAttribute("Reflective", new byte[0]); CtClass mlevel = classPool.get("javassist.tools.reflect.Metalevel"); boolean addMeta = !clazz.subtypeOf(mlevel); if (addMeta) clazz.addInterface(mlevel); processMethods(clazz, addMeta); processFields(clazz); CtField f; if (addMeta) { f = new CtField(classPool.get("javassist.tools.reflect.Metaobject"), metaobjectField, clazz); f.setModifiers(Modifier.PROTECTED); clazz.addField(f, CtField.Initializer.byNewWithParams(metaobject)); clazz.addMethod(CtNewMethod.getter(metaobjectGetter, f)); clazz.addMethod(CtNewMethod.setter(metaobjectSetter, f)); } f = new CtField(classPool.get("javassist.tools.reflect.ClassMetaobject"), classobjectField, clazz); f.setModifiers(Modifier.PRIVATE | Modifier.STATIC); clazz.addField(f, CtField.Initializer.byNew(metaclass, new String[] { clazz.getName() })); clazz.addMethod(CtNewMethod.getter(classobjectAccessor, f)); return true; }
CtClass addSerializationMethods( CtClass cc ) throws CannotCompileException, NotFoundException { if( cc.subclassOf(_enum) ) exposeRawEnumArray(cc); if( cc.subclassOf(_iced) ) ensureAPImethods(cc); if( cc.subclassOf(_iced) || cc.subclassOf(_dtask)|| cc.subtypeOf(_freezable)) { cc.setModifiers(javassist.Modifier.setPublic(cc.getModifiers())); ensureSerMethods(cc); ensureNullaryCtor(cc); ensureNewInstance(cc); ensureType(cc); } return cc; }
/** * Does the class implement Serializable? */ private static boolean isSerializable(CtClass clazz) throws NotFoundException { ClassPool pool = clazz.getClassPool(); return clazz.subtypeOf(pool.get("java.io.Serializable")); }