Java Code Examples for org.objectweb.asm.ClassReader#getSuperName()
The following examples show how to use
org.objectweb.asm.ClassReader#getSuperName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComputeClassWriter.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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; }
Example 2
Source File: SafeClassWriter.java From JQF with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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; }
Example 3
Source File: SpecifiedInterfaceImplementionChecked.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
/** * 判断是否实现了指定接口 * * @param reader class reader * @param interfaceSet interface collection * @return check result */ public static boolean hasImplSpecifiedInterfaces(ClassReader reader, Set<String> interfaceSet) { if (isObject(reader.getClassName())) { return false; } try { if (containedTargetInterface(reader.getInterfaces(), interfaceSet)) { return true; } else { ClassReader parent = new ClassReader(reader.getSuperName()); return hasImplSpecifiedInterfaces(parent, interfaceSet); } } catch (IOException e) { return false; } }
Example 4
Source File: ComputeClassWriter.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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; }
Example 5
Source File: ComputeClassWriter.java From tascalate-async-await with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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; }
Example 6
Source File: ASMClassWriter.java From pinpoint with Apache License 2.0 | 5 votes |
private String getSuperClassInternalName(final String classInternalName) { final ClassReader classReader = getClassReader(classInternalName); if (classReader == null) { return null; } return classReader.getSuperName(); }
Example 7
Source File: ASMClassWriter.java From pinpoint with Apache License 2.0 | 5 votes |
private String getCommonClass(final ClassReader classReader1, final ClassReader classReader2) { final Set<String> classHierarchy = new HashSet<String>(); classHierarchy.add(classReader1.getClassName()); classHierarchy.add(classReader2.getClassName()); String superClassInternalName1 = classReader1.getSuperName(); if (!classHierarchy.add(superClassInternalName1)) { // find common super class. return superClassInternalName1; } String superClassInternalName2 = classReader2.getSuperName(); if (!classHierarchy.add(superClassInternalName2)) { // find common super class. return superClassInternalName2; } while (superClassInternalName1 != null || superClassInternalName2 != null) { // for each. if (superClassInternalName1 != null) { superClassInternalName1 = getSuperClassInternalName(superClassInternalName1); if (superClassInternalName1 != null) { if (!classHierarchy.add(superClassInternalName1)) { return superClassInternalName1; } } } if (superClassInternalName2 != null) { superClassInternalName2 = getSuperClassInternalName(superClassInternalName2); if (superClassInternalName2 != null) { if (!classHierarchy.add(superClassInternalName2)) { return superClassInternalName2; } } } } return OBJECT_CLASS_INTERNAL_NAME; }
Example 8
Source File: PluginDiscovery.java From presto with Apache License 2.0 | 5 votes |
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(); }
Example 9
Source File: InternalUtils.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
static ClassInformation getClassInformation(final InputStream is) throws IOException { ClassReader classReader = new ClassReader(is); String name = classReader.getClassName(); String superName = classReader.getSuperName(); String[] interfaces = classReader.getInterfaces(); boolean interfaceMarker = (classReader.getAccess() & Opcodes.ACC_INTERFACE) != 0; return new ClassInformation(name, superName, Arrays.asList(interfaces), interfaceMarker); }
Example 10
Source File: ClassHierarchy.java From tascalate-javaflow with Apache License 2.0 | 5 votes |
/** * Returns a ClassReader corresponding to the given class or interface. * * @param type * the internal name of a class or interface. * @return the ClassReader corresponding to 'type'. * @throws IOException * if the bytecode of 'type' cannot be loaded. */ private TypeInfo loadTypeInfo(String type) throws IOException { InputStream is = loader.getResourceAsStream(type + ".class"); try { ClassReader info = new ClassReader(is); return new TypeInfo(info.getClassName(), info.getSuperName(), info.getInterfaces(), (info.getAccess() & Opcodes.ACC_INTERFACE) != 0); } finally { is.close(); } }
Example 11
Source File: ClassHierarchy.java From tascalate-javaflow with Apache License 2.0 | 5 votes |
/** * Returns a ClassReader corresponding to the given class or interface. * * @param type * the internal name of a class or interface. * @return the ClassReader corresponding to 'type'. * @throws IOException * if the bytecode of 'type' cannot be loaded. */ private TypeInfo loadTypeInfo(String type) throws IOException { InputStream is = loader.getResourceAsStream(type + ".class"); try { ClassReader info = new ClassReader(is); return new TypeInfo(info.getClassName(), info.getSuperName(), info.getInterfaces(), (info.getAccess() & Opcodes.ACC_INTERFACE) != 0); } finally { is.close(); } }
Example 12
Source File: ClassHierarchy.java From tascalate-javaflow with Apache License 2.0 | 5 votes |
/** * Returns a ClassReader corresponding to the given class or interface. * * @param type * the internal name of a class or interface. * @return the ClassReader corresponding to 'type'. * @throws IOException * if the bytecode of 'type' cannot be loaded. */ private TypeInfo loadTypeInfo(String type) throws IOException { InputStream is = loader.getResourceAsStream(type + ".class"); try { ClassReader info = new ClassReader(is); return new TypeInfo(info.getClassName(), info.getSuperName(), info.getInterfaces(), (info.getAccess() & Opcodes.ACC_INTERFACE) != 0); } finally { is.close(); } }
Example 13
Source File: DefaultMethodClassFixer.java From bazel with Apache License 2.0 | 4 votes |
private void recordInheritedMethods() { InstanceMethodRecorder recorder = new InstanceMethodRecorder(mayNeedInterfaceStubsForEmulatedSuperclass()); if (newSuperName != null) { checkState(useGeneratedBaseClasses); // If we're using a generated base class, walk the implemented interfaces and record default // methods we won't need to stub. That reflects the methods that will be in the generated // base class (and its superclasses, if applicable), without looking at the generated class. // We go through sub-interfaces before their super-interfaces (same order as when we stub) // to encounter overriding before overridden default methods. We don't record methods from // interfaces the chosen base class doesn't implement, even if those methods also appear in // interfaces we would normally record later. That ensures we generate a stub when a default // method is available in the base class but needs to be overridden due to an overriding // default method in a sub-interface not implemented by the base class. LinkedHashSet<String> allSeen = new LinkedHashSet<>(); for (Class<?> itf : interfacesToStub) { boolean willBeInBaseClass = itf.isAssignableFrom(newSuperName); for (Method m : itf.getDeclaredMethods()) { if (!m.isDefault()) { continue; } String desc = Type.getMethodDescriptor(m); if (coreLibrarySupport != null) { // Foreshadow any type renaming to avoid issues with double-desugaring (b/111447199) desc = coreLibrarySupport.getRemapper().mapMethodDesc(desc); } String methodKey = m.getName() + ":" + desc; if (allSeen.add(methodKey) && willBeInBaseClass) { // Only record never-seen methods, and only for super-types of newSuperName (see longer // explanation above) instanceMethods.add(methodKey); } } } // Fall through to the logic below to record j.l.Object's methods. checkState(superName.equals("java/lang/Object")); } // Walk superclasses String internalName = superName; while (internalName != null) { ClassReader bytecode = bootclasspath.readIfKnown(internalName); if (bytecode == null) { bytecode = checkNotNull( classpath.readIfKnown(internalName), "Superclass not found: %s", internalName); } bytecode.accept(recorder, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG); internalName = bytecode.getSuperName(); } }
Example 14
Source File: ASMHelper.java From TFC2 with GNU General Public License v3.0 | 4 votes |
/** * @return Whether or not the class read by the ClassReader has a valid super class. */ public static boolean classHasSuper(ClassReader classReader) { return classReader.getSuperName() != null && !classReader.getSuperName().equals("java/lang/Object"); }
Example 15
Source File: ComputeClassWriter.java From QuickTheories with Apache License 2.0 | 3 votes |
/** * 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. */ private StringBuilder typeAncestors(String type, ClassReader info) { final StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
Example 16
Source File: ComputeClassWriter.java From pitest with Apache License 2.0 | 3 votes |
/** * 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. */ private StringBuilder typeAncestors(String type, ClassReader info) { final StringBuilder b = new StringBuilder(); while (!"java/lang/Object".equals(type)) { b.append(';').append(type); type = info.getSuperName(); info = typeInfo(type); } return b; }
Example 17
Source File: ComputeClassWriter.java From tascalate-async-await with BSD 2-Clause "Simplified" License | 3 votes |
/** * 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; }
Example 18
Source File: ComputeClassWriter.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 3 votes |
/** * 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; }
Example 19
Source File: SafeClassWriter.java From JQF with BSD 2-Clause "Simplified" License | 3 votes |
/** * 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; }
Example 20
Source File: ComputeClassWriter.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 3 votes |
/** * 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; }