@Override protected ClassStructure initialValue() { final String superInternalClassName = classReader.getSuperName(); if (StringUtils.equals("java/lang/Object", superInternalClassName)) { return null; } return newInstance(toJavaClassName(superInternalClassName)); } };
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
/** * Returns the internal names of the ancestor classes of the given type. * * @param type the internal name of a class or interface. * @param info the ClassReader corresponding to 'type'. * @return a StringBuilder containing the ancestor classes of 'type', * separated by ';'. The returned string has the following format: * ";type1;type2 ... ;typeN", where type1 is 'type', and typeN is a * direct subclass of Object. If 'type' is Object, the returned * string is empty. * @throws IOException if the bytecode of 'type' or of some of its ancestor * class cannot be loaded. */ private StringBuffer typeAncestors(String type, ClassReader info) throws IOException { StringBuffer b = new StringBuffer(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
String superClassName = classReader.getSuperName(); if(superClassName == null) { return false;
/** * Returns true if the given type implements the given interface. * * @param type the internal name of a class or interface. * @param info the ClassReader corresponding to 'type'. * @param itf the internal name of a interface. * @return true if 'type' implements directly or indirectly 'itf' * @throws IOException if the bytecode of 'type' or of some of its ancestor * class cannot be loaded. */ private boolean typeImplements(String type, ClassReader info, String itf) throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (int i = 0; i < itfs.length; ++i) { if (itfs[i].equals(itf)) { return true; } } for (int i = 0; i < itfs.length; ++i) { if (typeImplements(itfs[i], typeInfo(itfs[i]), itf)) { return true; } } type = info.getSuperName(); info = typeInfo(type); } return false; } /**
public static boolean checkNeedRedirect(ClassReader classReader) { return SUPER_REDIRECT_MAP.keySet().contains(classReader.getSuperName()); }
private StringBuilder typeAncestors(String type, ClassReader info) throws IOException { StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
private static List<String> getFieldNames(final String internalName, String recurseToInternalName, ClassLoader classLoader, final List<String> ret) throws IOException { ClassReader r = new ClassReader(readByteCode(internalName, classLoader)); String p = r.getSuperName(); if (p != null && !p.equals("java/lang/Object") && !recurseToInternalName.equals(internalName)) { getFieldNames(p, recurseToInternalName, classLoader, ret); } r.accept(new EmptyVisitor() { @Override public FieldVisitor visitField(int i, String name, String string1, String string2, Object o) { ret.add(name); return null; } }, SKIP_DEBUG | SKIP_FRAMES | SKIP_CODE); return ret; }
private static List<String> getMethodNames(final String internalName, String recurseToInternalName, ClassLoader classLoader, final List<String> ret) throws IOException { ClassReader r = new ClassReader(readByteCode(internalName, classLoader)); String p = r.getSuperName(); if (p != null && !p.equals("java/lang/Object") && !recurseToInternalName.equals(internalName)) { getMethodNames(p, recurseToInternalName, classLoader, ret); } r.accept(new EmptyVisitor() { @Override public MethodVisitor visitMethod(int i, String name, String string1, String string2, String[] strings) { ret.add(name); return null; } }, SKIP_DEBUG | SKIP_FRAMES | SKIP_CODE); return ret; }
/** * Returns the internal names of the ancestor classes of the given type. * * @param type * the internal name of a class or interface. * @param info * the ClassReader corresponding to 'type'. * @return a StringBuilder containing the ancestor classes of 'type', * separated by ';'. The returned string has the following format: * ";type1;type2 ... ;typeN", where type1 is 'type', and typeN is a * direct subclass of Object. If 'type' is Object, the returned * string is empty. * @throws IOException * if the bytecode of 'type' or of some of its ancestor class * cannot be loaded. */ protected StringBuilder typeAncestors(String type, ClassReader info) throws IOException { StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
/** * Returns the internal names of the ancestor classes of the given type. * * @param type * the internal name of a class or interface. * @param info * the ClassReader corresponding to 'type'. * @return a StringBuilder containing the ancestor classes of 'type', * separated by ';'. The returned string has the following format: * ";type1;type2 ... ;typeN", where type1 is 'type', and typeN is a * direct subclass of Object. If 'type' is Object, the returned * string is empty. * @throws IOException * if the bytecode of 'type' or of some of its ancestor class * cannot be loaded. */ private StringBuilder typeAncestors(String type, ClassReader info) throws IOException { StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
/** * Returns the internal names of the ancestor classes of the given type. * * @param type * the internal name of a class or interface. * @param info * the ClassReader corresponding to 'type'. * @return a StringBuilder containing the ancestor classes of 'type', * separated by ';'. The returned string has the following format: * ";type1;type2 ... ;typeN", where type1 is 'type', and typeN is a * direct subclass of Object. If 'type' is Object, the returned * string is empty. * @throws IOException * if the bytecode of 'type' or of some of its ancestor class * cannot be loaded. */ protected StringBuilder typeAncestors(String type, ClassReader info) throws IOException { StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
private static List<String[]> getNativeMethodSignatures(final String internalName, ClassLoader classLoader, final List<String[]> ret) throws IOException { ClassReader r = new ClassReader(readByteCode(internalName, classLoader)); String p = r.getSuperName(); if (p != null && !p.equals("java/lang/Object")) { getNativeMethodSignatures(p, classLoader, ret); } r.accept(new EmptyVisitor() { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (Modifier.isNative(access)) { ret.add(new String[]{internalName, name, desc}); } return null; } }, SKIP_DEBUG | SKIP_FRAMES | SKIP_CODE); return ret; }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
private static List<String> classInterfaces(String name, ClassLoader classLoader) { ImmutableList.Builder<String> list = ImmutableList.builder(); ClassReader reader = readClass(name, classLoader); for (String binaryName : reader.getInterfaces()) { list.add(javaName(binaryName)); } if (reader.getSuperName() != null) { list.addAll(classInterfaces(javaName(reader.getSuperName()), classLoader)); } return list.build(); }
protected static final Set<String> getSuperClasses(String cname, URLClassLoader rcl) { Set<String> ret = new HashSet<String>(); try { InputStream is = rcl.getResourceAsStream(cname); ClassReader cr = new ClassReader(is); is.close(); String sname = cr.getSuperName(); if (sname != null) { ret.add(sname); ret.addAll(getSuperClasses(sname + ".class", rcl)); } } catch (Exception e) { } return ret; }
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { throw weavingException(wovenClass, e); } }
public boolean isSuperClassWoven(WovenClass wovenClass) { ClassReader cReader = new ClassReader(wovenClass.getBytes()); try { Class<?> superClass = Class.forName(cReader.getSuperName().replace('/', '.'), false, wovenClass.getBundleWiring().getClassLoader()); return WovenProxy.class.isAssignableFrom(superClass); } catch (ClassNotFoundException e) { String failureMessage = NLS.MESSAGES.getMessage("fatal.weaving.failure", wovenClass.getClassName()); //This is a failure that should stop the class loading! LOGGER.error(failureMessage, e); throw new WeavingException(failureMessage, e); } }
private boolean typeImplements(String type, ClassReader info, String itf) throws IOException { while (!"java/lang/Object".equals(type)) { String[] itfs = info.getInterfaces(); for (String itf2 : itfs) { if (itf2.equals(itf)) { return true; } } for (String itf1 : itfs) { if (typeImplements(itf1, typeInfo(itf1), itf)) { return true; } } type = info.getSuperName(); info = typeInfo(type); } return false; }