Java Code Examples for org.benf.cfr.reader.entities.Method#getCodeAttribute()

The following examples show how to use org.benf.cfr.reader.entities.Method#getCodeAttribute() . 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: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static StructuredStatement getSingleCodeLine(Method method) {
    if (method == null) return null;
    if (method.getCodeAttribute() == null) return null;
    Op04StructuredStatement code = method.getAnalysis();
    StructuredStatement topCode = code.getStatement();
    if (!(topCode instanceof Block)) return null;
    Block block = (Block)topCode;
    Optional<Op04StructuredStatement> content = block.getMaybeJustOneStatement();
    if (!content.isSet()) return null;
    return content.getValue().getStatement();
}
 
Example 2
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void hideConstructorIfEmpty(Method canonicalCons) {
    if (canonicalCons.getCodeAttribute() == null) return;
    Op04StructuredStatement code = canonicalCons.getAnalysis();
    if (code.getStatement().isEffectivelyNOP()) {
        canonicalCons.hideDead();
    }
}
 
Example 3
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void removeImplicitAssignments(Method canonicalCons, List<ClassFileField> instances, JavaRefTypeInstance thisType) {
    if (canonicalCons.getCodeAttribute() == null) return;
    Op04StructuredStatement code = canonicalCons.getAnalysis();

    instances = ListFactory.newList(instances);

    List<LocalVariable> args = canonicalCons.getMethodPrototype().getComputedParameters();
    // We expect a block.  The last N statements should be assignments
    StructuredStatement topCode = code.getStatement();
    if (!(topCode instanceof Block)) return;
    Block block = (Block)topCode;

    List<Op04StructuredStatement> statements = block.getBlockStatements();
    for (int x=statements.size()-1;x>=0;x--) {
        Op04StructuredStatement stm = statements.get(x);
        StructuredStatement statement = stm.getStatement();
        // this is very messy - refactor using wildcardmatch.
        if (statement.isEffectivelyNOP()) continue;
        if (!(statement instanceof StructuredAssignment)) return;
        LValue lhs = ((StructuredAssignment) statement).getLvalue();
        ClassFileField field = getCFF(lhs, thisType);
        if (field == null) return;
        int idx = instances.indexOf(field);
        if (idx == -1) return;
        instances.set(idx, null);

        Expression rhs = ((StructuredAssignment) statement).getRvalue();
        if (!(rhs instanceof LValueExpression)) return;
        LValue rlv = ((LValueExpression) rhs).getLValue();
        LocalVariable expected = args.get(idx);
        if (rlv != expected) return;
        stm.nopOut();
    }
}