Java Code Examples for org.benf.cfr.reader.entities.ClassFile#getMethods()

The following examples show how to use org.benf.cfr.reader.entities.ClassFile#getMethods() . 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: MemberNameResolver.java    From cfr with MIT License 5 votes vote down vote up
public static boolean verifySingleClassNames(ClassFile oneClassFile) {
    MemberInfo memberInfo = new MemberInfo(oneClassFile);

    for (Method method : oneClassFile.getMethods()) {
        // Visibility also captures information about bridge / synthetic, but we still want to skip them
        // here, even if that's been altered.
        if (method.hiddenState() != Method.Visibility.Visible ||
            method.testAccessFlag(AccessFlagMethod.ACC_BRIDGE) ||
            method.testAccessFlag(AccessFlagMethod.ACC_SYNTHETIC)) {
            continue;
        }
        memberInfo.add(method);
    }
    return memberInfo.hasClashes();
}
 
Example 2
Source File: FakeMethodRewriter.java    From cfr with MIT License 5 votes vote down vote up
public static void rewrite(ClassFile classFile, TypeUsageCollectingDumper typeUsage) {
    ExpressionRewriterTransformer trans = new ExpressionRewriterTransformer(new Rewriter(classFile, typeUsage));
    for (Method method : classFile.getMethods()) {
        if (method.hasCodeAttribute()) {
            Op04StructuredStatement code = method.getAnalysis();
            trans.transform(code);
        }
    }
}
 
Example 3
Source File: UnreachableStaticRewriter.java    From cfr with MIT License 4 votes vote down vote up
public static void rewrite(ClassFile classFile, TypeUsageCollectingDumper typeUsage) {
    // It is worth considering this, if we have made use of a class that also exists
    // as an inner class, AND as a 'synthetic full package' class.
    // (see https://github.com/leibnitz27/cfr/issues/102 )
    TypeUsageInformation info = typeUsage.getRealTypeUsageInformation();
    final JavaRefTypeInstance thisType = classFile.getRefClassType();
    if (thisType == null) return;

    Pair<List<JavaRefTypeInstance>, List<JavaRefTypeInstance>> split = Functional.partition(info.getUsedClassTypes(), new Predicate<JavaRefTypeInstance>() {
        @Override
        public boolean test(JavaRefTypeInstance in) {
            return in.getInnerClassHereInfo().isTransitiveInnerClassOf(thisType);
        }
    });
    List<JavaRefTypeInstance> inners = split.getFirst();
    /*
     * We are interested in inner classes where we clash with the fqn.
     * (What monster would do that? See test).
     */
    Map<String, JavaRefTypeInstance> potentialClashes = MapFactory.newMap();
    for (JavaRefTypeInstance inner : inners) {
        StringBuilder sb = new StringBuilder();
        inner.getInnerClassHereInfo().getFullInnerPath(sb);
        sb.append(inner.getRawShortName());
        String name = sb.toString();
        potentialClashes.put(name, inner);
    }

    List<JavaRefTypeInstance> others = split.getSecond();

    Map<JavaTypeInstance, Inaccessible> inaccessibles = MapFactory.newMap();
    for (JavaRefTypeInstance type : others) {
        JavaRefTypeInstance clashFqn = potentialClashes.get(type.getRawName());
        JavaRefTypeInstance clashShort = potentialClashes.get(type.getRawShortName());
        // Strictly speaking, if EITHER of these is true we have a problem,
        // that's a todo.
        if (clashFqn == null || clashShort == null) continue;
        // Ok, we can't import this guy.  We could import static if it's just used as a method,
        // but even then, only if we don't collide with any *LOCAL* methods.
        inaccessibles.put(type, new Inaccessible(type, clashShort, clashFqn));
    }

    if (inaccessibles.isEmpty()) return;

    Rewriter usr = new Rewriter(thisType, typeUsage, inaccessibles);
    ExpressionRewriterTransformer trans = new ExpressionRewriterTransformer(usr);

    for (Method method : classFile.getMethods()) {
        if (method.hasCodeAttribute()) {
            Op04StructuredStatement code = method.getAnalysis();
            trans.transform(code);
        }
    }
}