Java Code Examples for org.objectweb.asm.ClassReader#getInterfaces()
The following examples show how to use
org.objectweb.asm.ClassReader#getInterfaces() .
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: 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 4
Source File: JavaLanguageAdapter.java From fabric-loader with Apache License 2.0 | 6 votes |
public static Class<?> getClass(String className, Options options) throws ClassNotFoundException, IOException { String classFilename = className.replace('.', '/') + ".class"; InputStream stream = FabricLauncherBase.getLauncher().getResourceAsStream(classFilename); if (stream == null) { throw new ClassNotFoundException("Could not find or load class " + classFilename); } ClassReader reader = new ClassReader(stream); for (String s : reader.getInterfaces()) { if (!canApplyInterface(s)) { switch (options.getMissingSuperclassBehavior()) { case RETURN_NULL: stream.close(); return null; case CRASH: default: stream.close(); throw new ClassNotFoundException("Could not find or load class " + s); } } } stream.close(); return FabricLauncherBase.getClass(className); }
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: 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 7
Source File: HierarchyGraph.java From Recaf with MIT License | 5 votes |
/** * Populate {@link #descendents} map. */ public void refresh() { // TODO: Call this when the inheritance tree is modified. // - Already called by mappings // - But later if user changes a class name WITHOUT remappping this needs to be called too descendents.clear(); for (ClassReader reader : getWorkspace().getPrimaryClassReaders()) { descendents.computeIfAbsent(reader.getSuperName(), k -> new HashSet<>()).add(reader.getClassName()); for (String inter : reader.getInterfaces()) { descendents.computeIfAbsent(inter, k -> new HashSet<>()).add(reader.getClassName()); } } }
Example 8
Source File: JavaLanguageAdapter.java From fabric-loader with Apache License 2.0 | 5 votes |
private static boolean canApplyInterface(String itfString) throws IOException { String className = itfString + ".class"; // TODO: Be a bit more involved switch (itfString) { case "net/fabricmc/api/ClientModInitializer": if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { return false; } break; case "net/fabricmc/api/DedicatedServerModInitializer": if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { return false; } } InputStream stream = FabricLauncherBase.getLauncher().getResourceAsStream(className); if (stream == null) { return false; } ClassReader reader = new ClassReader(stream); for (String s : reader.getInterfaces()) { if (!canApplyInterface(s)) { stream.close(); return false; } } stream.close(); return true; }
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: ASMClassWriter.java From pinpoint with Apache License 2.0 | 5 votes |
private void traversalInterfaceHierarchy(final Set<String> interfaceHierarchy, final ClassReader classReader) { if (classReader != null && interfaceHierarchy.add(classReader.getClassName())) { for (String interfaceInternalName : classReader.getInterfaces()) { traversalInterfaceHierarchy(interfaceHierarchy, getClassReader(interfaceInternalName)); } } }
Example 14
Source File: DefaultMethodClassFixer.java From bazel with Apache License 2.0 | 5 votes |
private void collectOrderedCompanionsToTriggerInterfaceClinit( String anInterface, LinkedHashSet<String> visitedInterfaces, ImmutableList.Builder<String> companionCollector) { if (!visitedInterfaces.add(anInterface)) { return; } ClassReader bytecode = classpath.readIfKnown(anInterface); if (bytecode == null || bootclasspath.isKnown(anInterface)) { return; } String[] parentInterfaces = bytecode.getInterfaces(); if (parentInterfaces != null && parentInterfaces.length > 0) { for (String parentInterface : parentInterfaces) { collectOrderedCompanionsToTriggerInterfaceClinit( parentInterface, visitedInterfaces, companionCollector); } } InterfaceInitializationNecessityDetector necessityDetector = new InterfaceInitializationNecessityDetector(bytecode.getClassName()); bytecode.accept(necessityDetector, ClassReader.SKIP_DEBUG); if (necessityDetector.needsToInitialize()) { // If we need to initialize this interface, we initialize its companion class, and its // companion class will initialize the interface then. This desigin decision is made to avoid // access issue, e.g., package-private interfaces. companionCollector.add(InterfaceDesugaring.getCompanionClassName(anInterface)); } }