Java Code Examples for org.objectweb.asm.ClassReader#getClassName()
The following examples show how to use
org.objectweb.asm.ClassReader#getClassName() .
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: Input.java From JRemapper with MIT License | 6 votes |
/** * Try to add the class contained in the given stream to the classes map. * * @param name * Entry name. * @param is * Stream of entry. * @throws IOException * Thrown if stream could not be read or if ClassNode could not be * derived from the streamed content. */ protected void addClass(String name, InputStream is) { try { byte[] value = Streams.from(is); ClassReader cr = new ClassReader(value); String className = cr.getClassName(); // Add missing debug information if needed ClassWriter cw = new ClassWriter(0); VariableFixer fixer = new VariableFixer(); cr.accept(fixer, 0); fixer.accept(cw); if (fixer.isDirty()) value = cw.toByteArray(); // Put value in map rawNodeMap.put(className, value); } catch (Exception e) { Logging.error("Could not parse class: " + name); e.printStackTrace(); } }
Example 2
Source File: Parser.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public static void parse(File sourceFile) throws Exception { if(ByteCodeTranslator.verbose) { System.out.println("Parsing: " + sourceFile.getAbsolutePath()); } ClassReader r = new ClassReader(new FileInputStream(sourceFile)); /*if(ByteCodeTranslator.verbose) { System.out.println("Class: " + r.getClassName() + " derives from: " + r.getSuperName() + " interfaces: " + Arrays.asList(r.getInterfaces())); }*/ Parser p = new Parser(); p.clsName = r.getClassName().replace('/', '_').replace('$', '_'); p.cls = new ByteCodeClass(p.clsName, r.getClassName()); r.accept(p, ClassReader.EXPAND_FRAMES); classes.add(p.cls); }
Example 3
Source File: ASMClassWriter.java From pinpoint with Apache License 2.0 | 6 votes |
private String getCommonInterface(final ClassReader classReader1, final ClassReader classReader2) { final Set<String> interfaceHierarchy = new HashSet<String>(); traversalInterfaceHierarchy(interfaceHierarchy, classReader1); if (isInterface(classReader2)) { if (interfaceHierarchy.contains(classReader2.getClassName())) { return classReader2.getClassName(); } } final String interfaceInternalName = getImplementedInterface(interfaceHierarchy, classReader2); if (interfaceInternalName != null) { return interfaceInternalName; } return OBJECT_CLASS_INTERNAL_NAME; }
Example 4
Source File: DefaultLambdaClassFileResolver.java From pinpoint with Apache License 2.0 | 6 votes |
@Override public String resolve(ClassLoader classLoader, String classInternalName, ProtectionDomain protectionDomain, byte[] classFileBuffer) { if (classInternalName != null) { return classInternalName; } if (classFileBuffer == null) { return classInternalName; } // proxy-like class specific for lambda expressions. // e.g. Example$$Lambda$1/1072591677 try { final ClassReader classReader = new ClassReader(classFileBuffer, 0, classFileBuffer.length); return classReader.getClassName(); } catch (Exception e) { if (logger.isInfoEnabled()) { logger.info("Failed to read metadata of lambda expressions. classLoader={}", classLoader, e); } return null; } }
Example 5
Source File: AsmUtils.java From Box with Apache License 2.0 | 5 votes |
public static String getNameFromClassFile(File file) throws IOException { String className; try (FileInputStream in = new FileInputStream(file)) { ClassReader classReader = new ClassReader(in); className = classReader.getClassName(); } return className; }
Example 6
Source File: AsmUtils.java From Box with Apache License 2.0 | 5 votes |
public static String getNameFromClassFile(File file) throws IOException { String className; try (FileInputStream in = new FileInputStream(file)) { ClassReader classReader = new ClassReader(in); className = classReader.getClassName(); } return className; }
Example 7
Source File: Mappings.java From Recaf with MIT License | 5 votes |
private void accept(Map<String, byte[]> updated, ClassReader cr, int readFlags, int writeFlags) { String name = cr.getClassName(); // Apply with mapper SimpleRecordingRemapper mapper = new SimpleRecordingRemapper(getMappings(), checkFieldHierarchy, checkMethodHierarchy, workspace); WorkspaceClassWriter cw = workspace.createWriter(writeFlags); cw.setMappings(getMappings(), reverseClassMappings); ClassRemapper adapter = new ClassRemapper(cw, mapper); if (clearDebugInfo) readFlags |= ClassReader.SKIP_DEBUG; cr.accept(adapter, readFlags); // Only return the modified class if any references to the mappings were found. if (mapper.isDirty()) updated.put(name, cw.toByteArray()); }
Example 8
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 9
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 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: 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)); } }