Example usage for org.objectweb.asm ClassReader getClassName

List of usage examples for org.objectweb.asm ClassReader getClassName

Introduction

In this page you can find the example usage for org.objectweb.asm ClassReader getClassName.

Prototype

public String getClassName() 

Source Link

Document

Returns the internal name of the class (see Type#getInternalName() ).

Usage

From source file:asmlib.DuplicateMethodChecker.java

License:Open Source License

public static void verify(ClassReader cr, PrintWriter pw) {
    InfoClass info = new InfoClass(cr.getClassName(), cr.getSuperName());
    cr.accept(new InfoClassAdapter(info), 0);

    List<InfoMethod> methodList = info.methods();
    NavigableSet<InfoMethod> methodSet = new TreeSet<InfoMethod>(methodList);

    if (methodList.size() == methodSet.size())
        return;/*from  w w  w.ja  v a 2s  .  co m*/

    while (!methodSet.isEmpty() && (methodList.size() != methodSet.size())) {
        InfoMethod current = methodSet.pollFirst();
        methodList.remove(current);

        boolean duplicate = false;
        while (methodList.contains(current)) {
            duplicate = true;
            methodList.remove(current);
        }

        if (duplicate)
            pw.println("DUPLICATE METHOD DETECTED: " + current.name() + current.desc());
    }
}

From source file:asmlib.InfoClass.java

License:Open Source License

public static InfoClass fromType(Type t) throws IOException {
    org.objectweb.asm.ClassReader cr = new org.objectweb.asm.ClassReader(t.commonName());
    InfoClass infoClass = new InfoClass(cr.getClassName(), cr.getSuperName());
    cr.accept(new InfoClassAdapter(infoClass), 0);
    return infoClass;
}

From source file:asmlib.UninitializedCallChecker.java

License:Open Source License

public static void verify(ClassReader cr, PrintWriter pw) {
    // O AnalyzerAdapter
    // precisa que as frames estejam delimitadas no cdigo para funcionar correctamente.
    // Frames parecem ser obrigatrias a partir do Java 6, mas muitas classes no as tm
    // por isso fazemos mais um pass com um ClassWriter, para obtermos uma classe com
    // as frames calculadas.
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cr.accept(cw, 0);//from  w  w  w  .  j a  v a  2  s. c o m
    cr = new ClassReader(cw.toByteArray());

    try {
        cr.accept(new GenericMethodVisitorAdapter(new EmptyClassVisitor(), UninitializedCallChecker.class,
                cr.getClassName(), pw), ClassReader.EXPAND_FRAMES);
    } catch (ArrayIndexOutOfBoundsException e) {
    }
}

From source file:asmlib.Util.java

License:Open Source License

public static void populateSuperclasses(InfoClass infoClass) throws IOException {
    if ((infoClass.superclass() != null) || infoClass.type().equals(Type.OBJECT))
        return;//  w w w  .j a v a2  s.  co  m

    ClassReader cr = new ClassReader(infoClass.superclassType().commonName());

    InfoClass superclass = new InfoClass(cr.getClassName(), cr.getSuperName());
    cr.accept(new InfoClassAdapter(superclass), 0);

    infoClass.setSuperclass(superclass);

    populateSuperclasses(superclass);
}

From source file:asmlib.Util.java

License:Open Source License

public static void populateSuperinterfaces(InfoClass infoClass) throws IOException {
    for (Type superInterfaceName : infoClass.interfaceTypes()) {
        ClassReader cr = new ClassReader(superInterfaceName.commonName());
        InfoClass superiface = new InfoClass(cr.getClassName(), cr.getSuperName());
        cr.accept(new InfoClassAdapter(superiface), 0);
        infoClass.addInterface(superiface);
        populateSuperinterfaces(superiface);
    }//  w  w w .  jav a  2  s .c om
}

From source file:blue.lapis.methodremapper.Remapper.java

License:Open Source License

/**
 * Remaps the given class file using the mappings of this {@link Remapper}.
 * This will scan the class hierarchy of the given class for matching
 * mappings and finally remap the method names to their new names. If one of
 * the super classes was not scanned for matching mappings yet it will be
 * queried from the provided {@link ClassProvider}.
 *
 * @param reader The class reader to read the class from
 * @return The remapped class//from w  w  w .  jav  a2  s. c om
 * @throws IOException If loading classes from the provider fails
 */
public byte[] remap(ClassReader reader) throws IOException {
    String name = reader.getClassName();

    // Make sure the mappings for this class are loaded
    Map<String, String> mappings = getMappings(name, reader);

    ClassWriter writer = new ClassWriter(reader, 0);
    ClassVisitor visitor;

    if (mappings != null) {
        logger.debug("Remapping {} with {}", name, mappings);
        visitor = new RemapClassVisitor(writer, this, mappings);
    } else {
        logger.trace("Remapping {}", name);
        visitor = new RemapInvokeClassVisitor(writer, this);
    }

    reader.accept(visitor, 0);
    return writer.toByteArray();
}

From source file:com.android.mkstubs.AsmAnalyzer.java

License:Apache License

/**
 * Utility that returns the fully qualified ASM class name for a ClassReader.
 * E.g. it returns something like android/view/View.
 *//*from  w  w w. ja  v a 2  s . c  o  m*/
static String classReaderToAsmName(ClassReader classReader) {
    if (classReader == null) {
        return null;
    } else {
        return classReader.getClassName();
    }
}

From source file:com.android.mkstubs.SourceGenerator.java

License:Apache License

/**
 * Generate source for the stubbed classes, mostly for debug purposes.
 * @throws IOException//  ww  w. ja v a2 s .  com
 */
public void generateSource(File baseDir, Map<String, ClassReader> classes, Filter filter) throws IOException {

    for (Entry<String, ClassReader> entry : classes.entrySet()) {
        ClassReader cr = entry.getValue();

        String name = classNameToJavaPath(cr.getClassName());

        try (FileWriter fw = createWriter(baseDir, name)) {
            visitClassSource(fw, cr, filter);
        }
    }
}

From source file:com.android.mkstubs.SourceGenerator.java

License:Apache License

/**
 * Generate a source equivalent to the stubbed version of the class reader,
 * minus all exclusions/*from w w  w.j  a  v  a2  s  .  co  m*/
 */
void visitClassSource(Writer fw, ClassReader cr, Filter filter) {
    mLog.debug("Dump " + cr.getClassName());

    ClassVisitor javaWriter = new ClassSourcer(new Output(fw));
    ClassVisitor classFilter = new FilterClassAdapter(javaWriter, filter, mLog);
    cr.accept(classFilter, 0 /*flags*/);
}

From source file:com.android.mkstubs.StubGenerator.java

License:Apache License

/**
 * Generate source for the stubbed classes, mostly for debug purposes.
 * @throws IOException//  w w w  . j ava 2 s.c  om
 */
public void generateStubbedJar(File destJar, Map<String, ClassReader> classes, Filter filter)
        throws IOException {

    TreeMap<String, byte[]> all = new TreeMap<>();

    for (Entry<String, ClassReader> entry : classes.entrySet()) {
        ClassReader cr = entry.getValue();

        byte[] b = visitClassStubber(cr, filter);
        String name = classNameToEntryPath(cr.getClassName());
        all.put(name, b);
    }

    createJar(new FileOutputStream(destJar), all);

    mLog.debug("Wrote %s", destJar.getPath());
}