org.benf.cfr.reader.entities.Method Java Examples

The following examples show how to use org.benf.cfr.reader.entities.Method. 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: OperationFactoryDupX2.java    From cfr with MIT License 6 votes vote down vote up
@Override
public StackDelta getStackDelta(JVMInstr instr, byte[] data, ConstantPoolEntry[] cpEntries,
                                StackSim stackSim, Method method) {
    if (getCat(stackSim, 1) == 2) {
        checkCat(stackSim, 0, 1);
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0, 1),
                getStackTypes(stackSim, 0, 1, 0)
        );
    } else {
        checkCat(stackSim, 0, 1);
        checkCat(stackSim, 2, 1);
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0, 1, 2),
                getStackTypes(stackSim, 0, 1, 2, 0)
        );
    }
}
 
Example #2
Source File: FileSummaryDumper.java    From cfr with MIT License 6 votes vote down vote up
@Override
public void notifyError(JavaTypeInstance controllingType, Method method, String error) {
    try {
        if (lastControllingType != controllingType) {
            lastControllingType = controllingType;
            lastMethod = null;
            writer.write("\n\n" + controllingType.getRawName() + "\n----------------------------\n\n");
        }
        if (method != lastMethod) {
            if (method != null) {
                writer.write(method.getMethodPrototype().toString() + "\n");
            }
            lastMethod = method;
        }
        writer.write("  " + error + "\n");
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #3
Source File: RecordRewriter.java    From cfr with MIT License 6 votes vote down vote up
@Override
public boolean test(Method in) {
    MethodPrototype proto = in.getMethodPrototype();
    if (!proto.parametersComputed()) return false;
    List<JavaTypeInstance> protoArgs = proto.getArgs();
    if (protoArgs.size() != fields.size()) return false;
    List<LocalVariable> parameters = proto.getComputedParameters();
    // The names MIGHT not match, if we've been obfuscated.  That's ok, as long as the parameters are assigned,
    // at the top level, to the appropriate variable.
    if (parameters.size() != fields.size()) return false;
    // If they don't match, we have to rename, as implicit parameters are usable inside constructor.
    for (int x=0;x<fields.size();++x) {
        JavaTypeInstance fieldType = fields.get(x).getField().getJavaTypeInstance();
        JavaTypeInstance paramType = protoArgs.get(x);
        if (!fieldType.equals(paramType)) return false;
    }

    return true;
}
 
Example #4
Source File: OperationFactoryDup2X1.java    From cfr with MIT License 6 votes vote down vote up
@Override
public StackDelta getStackDelta(JVMInstr instr, byte[] data, ConstantPoolEntry[] cpEntries,
                                StackSim stackSim, Method method) {

    if (getCat(stackSim, 0) == 1) {
        checkCat(stackSim, 1, 1);
        checkCat(stackSim, 2, 1);
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0, 1, 2),
                getStackTypes(stackSim, 0, 1, 2, 0, 1)
        );
    } else {
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0, 1),
                getStackTypes(stackSim, 0, 1, 0)
        );
    }
}
 
Example #5
Source File: OperationFactoryDup2.java    From cfr with MIT License 6 votes vote down vote up
@Override
public StackDelta getStackDelta(JVMInstr instr, byte[] data, ConstantPoolEntry[] cpEntries,
                                StackSim stackSim, Method method) {
    if (getCat(stackSim, 0) == 1) {
        checkCat(stackSim, 1, 1);
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0, 1),
                getStackTypes(stackSim, 0, 1, 0, 1)
        );
    } else {
        return new StackDeltaImpl(
                getStackTypes(stackSim, 0),
                getStackTypes(stackSim, 0, 0)
        );
    }
}
 
Example #6
Source File: ResourceReleaseDetector.java    From cfr with MIT License 6 votes vote down vote up
public static boolean isResourceRelease(Method method, Op04StructuredStatement root) {
    if (!method.getAccessFlags().contains(AccessFlagMethod.ACC_STATIC)) return false;
    if (!method.getAccessFlags().contains(AccessFlagMethod.ACC_SYNTHETIC)) return false;
    List<JavaTypeInstance> argTypes = method.getMethodPrototype().getArgs();
    if (argTypes.size() != 2) return false;
    List<LocalVariable> computedParameters = method.getMethodPrototype().getComputedParameters();
    if (computedParameters.size() != 2) return false;

    List<StructuredStatement> structuredStatements = MiscStatementTools.linearise(root);
    if (structuredStatements == null) return false;

    LocalVariable throwable = computedParameters.get(0);
    LocalVariable autoclose = computedParameters.get(1);

    WildcardMatch wcm = new WildcardMatch();
    Matcher<StructuredStatement> m = getStructuredStatementMatcher(wcm, throwable, autoclose);

    MatchIterator<StructuredStatement> mi = new MatchIterator<StructuredStatement>(structuredStatements);

    MatchResultCollector collector = new EmptyMatchResultCollector();
    mi.advance();
    return m.match(mi, collector);
}
 
Example #7
Source File: ConstructorUtils.java    From cfr with MIT License 6 votes vote down vote up
public static MethodPrototype getDelegatingPrototype(Method constructor) {
    List<Op04StructuredStatement> statements = MiscStatementTools.getBlockStatements(constructor.getAnalysis());
    if (statements == null) return null;
    for (Op04StructuredStatement statement : statements) {
        StructuredStatement structuredStatement = statement.getStatement();
        if (structuredStatement instanceof StructuredComment) continue;
        if (!(structuredStatement instanceof StructuredExpressionStatement)) return null;
        StructuredExpressionStatement structuredExpressionStatement = (StructuredExpressionStatement) structuredStatement;

        WildcardMatch wcm1 = new WildcardMatch();
        StructuredStatement test = new StructuredExpressionStatement(wcm1.getMemberFunction("m", null, true /* this method */, new LValueExpression(wcm1.getLValueWildCard("o")), null), false);
        if (test.equals(structuredExpressionStatement)) {
            MemberFunctionInvokation m = wcm1.getMemberFunction("m").getMatch();
            MethodPrototype prototype = m.getMethodPrototype();
            return prototype;
        }
        return null;
    }
    return null;
}
 
Example #8
Source File: RemoveDeterministicJumps.java    From cfr with MIT License 6 votes vote down vote up
public static List<Op03SimpleStatement> apply(Method method, List<Op03SimpleStatement> statements) {
    boolean success = false;
    Set<BlockIdentifier> ignoreInThese = FinallyRewriter.getBlocksAffectedByFinally(statements);

    for (Op03SimpleStatement stm : statements) {
        if (!(stm.getStatement() instanceof AssignmentSimple)) continue;
        if (SetUtil.hasIntersection(ignoreInThese, stm.getBlockIdentifiers())) continue;
        Map<LValue, Literal> display = MapFactory.newMap();
        success |= propagateLiteralReturn(method, stm, display);
    }

    if (success) {
        statements = Cleaner.removeUnreachableCode(statements, true);
    }
    return statements;
}
 
Example #9
Source File: StaticInitReturnRewriter.java    From cfr with MIT License 6 votes vote down vote up
public static List<Op03SimpleStatement> rewrite(Options options, Method method, List<Op03SimpleStatement> statementList) {
    if (!method.getName().equals(MiscConstants.STATIC_INIT_METHOD)) return statementList;
    if (!options.getOption(OptionsImpl.STATIC_INIT_RETURN)) return statementList;
    /*
     * if the final statement is a return, then replace all other returns with a jump to that.
     */
    Op03SimpleStatement last = statementList.get(statementList.size()-1);
    if (last.getStatement().getClass() != ReturnNothingStatement.class) return statementList;
    for (int x =0, len=statementList.size()-1;x<len;++x) {
        Op03SimpleStatement stm = statementList.get(x);
        if (stm.getStatement().getClass() == ReturnNothingStatement.class) {
            stm.replaceStatement(new GotoStatement());
            stm.addTarget(last);
            last.addSource(stm);
        }
    }
    return statementList;
}
 
Example #10
Source File: MemberNameResolver.java    From cfr with MIT License 6 votes vote down vote up
void inheritFrom(MemberInfo base) {
    for (Map.Entry<MethodKey, Map<JavaTypeInstance, Collection<Method>>> entry : base.knownMethods.entrySet()) {
        MethodKey key = entry.getKey();
        for (Map.Entry<JavaTypeInstance, Collection<Method>> entry2 : entry.getValue().entrySet()) {
            JavaTypeInstance returnType = entry2.getKey();
            Collection<Method> methods = entry2.getValue();
            /*
             * Only add visible ones.
             */
            for (Method method : methods) {
                if (method.isVisibleTo(classFile.getRefClassType())) {
                    add(key, returnType, method, true);
                }
            }
        }
    }
}
 
Example #11
Source File: VariableFactory.java    From cfr with MIT License 6 votes vote down vote up
public VariableFactory(Method method, BytecodeMeta bytecodeMeta) {
    this.variableNamer = method.getVariableNamer();
    this.clashes = bytecodeMeta.getLivenessClashes();
    MethodPrototype methodPrototype = method.getMethodPrototype();
    List<JavaTypeInstance> args = methodPrototype.getArgs();
    this.typedArgs = MapFactory.newMap();
    int offset = 0;
    if (methodPrototype.isInstanceMethod()) {
        JavaTypeInstance thisType = method.getClassFile().getClassType();
        typedArgs.put(offset++, new InferredJavaType(thisType, InferredJavaType.Source.UNKNOWN, true));
    }
    for (JavaTypeInstance arg : args) {
        typedArgs.put(offset, new InferredJavaType(arg, InferredJavaType.Source.UNKNOWN, true));
        offset += arg.getStackType().getComputationCategory();
    }
    if (methodPrototype.parametersComputed()) {
        for (LocalVariable localVariable : methodPrototype.getComputedParameters()) {
            cache.put(localVariable, localVariable);
        }
    }
    this.method = method;
}
 
Example #12
Source File: MemberNameResolver.java    From cfr with MIT License 6 votes vote down vote up
private void add(MethodKey key1, JavaTypeInstance key2, Method method, boolean fromParent) {
    Map<JavaTypeInstance, Collection<Method>> methods = knownMethods.get(key1);
    if (method.hiddenState() != Method.Visibility.Visible) return;
    if (fromParent && !methods.containsKey(key2) && !methods.isEmpty()) {
        // This is ok if key2 is covariant to an existing key.
        if (methods.keySet().size() == 1) {
            JavaTypeInstance existing = methods.keySet().iterator().next();
            BindingSuperContainer supers = existing.getBindingSupers();
            if (supers != null && supers.containsBase(key2)) {
                key2 = existing;
            }
        }
    }
    methods.get(key2).add(method);
    if (methods.size() > 1) {
        clashes.add(key1);
    }
}
 
Example #13
Source File: MemberNameResolver.java    From cfr with MIT License 6 votes vote down vote up
public void add(Method method) {
    if (method.isConstructor()) return;

    MethodPrototype prototype = method.getMethodPrototype();
    String name = prototype.getName();
    List<JavaTypeInstance> args = Functional.map(prototype.getArgs(), new UnaryFunction<JavaTypeInstance, JavaTypeInstance>() {
        @Override
        public JavaTypeInstance invoke(JavaTypeInstance arg) {
            return arg.getDeGenerifiedType();
        }
    });
    MethodKey methodKey = new MethodKey(name, args);
    JavaTypeInstance type = prototype.getReturnType();
    if (type instanceof JavaGenericBaseInstance) return;
    add(methodKey, prototype.getReturnType(), method, false);
}
 
Example #14
Source File: LambdaUtils.java    From cfr with MIT License 6 votes vote down vote up
public static MethodPrototype getLiteralProto(Expression arg) {
    TypedLiteral.LiteralType flavour = getLiteralType(arg);

    switch (flavour) {
        case MethodHandle: {
            ConstantPoolEntryMethodHandle targetFnHandle = getHandle(arg);
            ConstantPoolEntryMethodRef targetMethRef = targetFnHandle.getMethodRef();
            return targetMethRef.getMethodPrototype();
        }
        case MethodType: {
            ConstantPoolEntryMethodType targetFnType = getType(arg);
            ConstantPoolEntryUTF8 descriptor = targetFnType.getDescriptor();
            return ConstantPoolUtils.parseJavaMethodPrototype(null,null, null, null, false, Method.MethodConstructor.NOT, descriptor, targetFnType.getCp(), false, false, null);
        }
        default:
            throw new ConfusedCFRException("Can't understand this lambda - disable lambdas.");
    }
}
 
Example #15
Source File: MemberNameResolver.java    From cfr with MIT License 6 votes vote down vote up
private void patchBadNames() {
    Collection<MemberInfo> memberInfos = infoMap.values();
    for (MemberInfo memberInfo : memberInfos) {
        if (!memberInfo.hasClashes()) continue;
        Set<MethodKey> clashes = memberInfo.getClashes();
        for (MethodKey clashKey : clashes) {
            Map<JavaTypeInstance, Collection<Method>> clashMap = memberInfo.getClashedMethodsFor(clashKey);
            for (Map.Entry<JavaTypeInstance, Collection<Method>> clashByType : clashMap.entrySet()) {
                String resolvedName = null;
                for (Method method : clashByType.getValue()) {
                    MethodPrototype methodPrototype = method.getMethodPrototype();
                    if (methodPrototype.hasNameBeenFixed()) {
                        if (resolvedName == null) resolvedName = methodPrototype.getFixedName();
                    } else {
                        // Need to fix.  If we've already seen fixed name don't generate, use.  If we haven't
                        // generate.
                        if (resolvedName == null) {
                            resolvedName = ClassNameUtils.getTypeFixPrefix(clashByType.getKey()) + methodPrototype.getName();
                        }
                        methodPrototype.setFixedName(resolvedName);
                    }
                }
            }
        }
    }
}
 
Example #16
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 #17
Source File: J14ClassObjectRewriter.java    From cfr with MIT License 5 votes vote down vote up
private boolean methodIsClassLookup(Method method) {
    if (method == null) return false;
    /*
     * Verify it matches expected pattern.
     */
    if (!method.getAccessFlags().contains(AccessFlagMethod.ACC_SYNTHETIC)) return false;
    if (!method.hasCodeAttribute()) return false;
    List<StructuredStatement> statements = MiscStatementTools.linearise(method.getAnalysis());
    if (statements == null) return false;
    MatchIterator<StructuredStatement> mi = new MatchIterator<StructuredStatement>(statements);
    WildcardMatch wcm1 = new WildcardMatch();

    List<LocalVariable> args = method.getMethodPrototype().getComputedParameters();
    if (args.size() != 1) return false;
    LocalVariable arg = args.get(0);
    if (!TypeConstants.STRING.equals(arg.getInferredJavaType().getJavaTypeInstance())) return false;

    Matcher<StructuredStatement> m =
            new MatchSequence(
                    new BeginBlock(null),
                    new StructuredTry(null, null),
                    new BeginBlock(null),
                    new StructuredReturn(wcm1.getStaticFunction("forName",TypeConstants.CLASS, null, "forName", new LValueExpression(arg)), TypeConstants.CLASS),
                    new EndBlock(null),
                    new StructuredCatch(null, null, null, null),
                    new BeginBlock(null),
                    new StructuredThrow(
                            wcm1.getMemberFunction("initCause", "initCause",
                                    wcm1.getConstructorSimpleWildcard("nocd", TypeConstants.NOCLASSDEFFOUND_ERROR),
                                    wcm1.getExpressionWildCard("throwable"))
                    ),
                    new EndBlock(null),
                    new EndBlock(null)
            );

    // start
    mi.advance();
    return m.match(mi, null);
}
 
Example #18
Source File: TryResourcesTransformerBase.java    From cfr with MIT License 5 votes vote down vote up
ResourceMatch(Method resourceMethod, LValue resource, LValue throwable, boolean reprocessException, List<Op04StructuredStatement> removeThese) {
    this.resourceMethod = resourceMethod;
    this.resource = resource;
    this.throwable = throwable;
    this.reprocessException = reprocessException;
    this.removeThese = removeThese;
}
 
Example #19
Source File: CondenseConstruction.java    From cfr with MIT License 5 votes vote down vote up
static void condenseConstruction(DCCommonState state, Method method, List<Op03SimpleStatement> statements, AnonymousClassUsage anonymousClassUsage) {
    CreationCollector creationCollector = new CreationCollector(anonymousClassUsage);
    for (Op03SimpleStatement statement : statements) {
        statement.findCreation(creationCollector);
    }
    creationCollector.condenseConstructions(method, state);
}
 
Example #20
Source File: RemoveDeterministicJumps.java    From cfr with MIT License 5 votes vote down vote up
public static void propagateToReturn(Method method, List<Op03SimpleStatement> statements) {
    boolean success = false;

    List<Op03SimpleStatement> assignmentSimples = Functional.filter(statements, new TypeFilter<AssignmentSimple>(AssignmentSimple.class));
    Set<BlockIdentifier> affectedByFinally = FinallyRewriter.getBlocksAffectedByFinally(statements);

    for (Op03SimpleStatement stm : assignmentSimples) {
        if (SetUtil.hasIntersection(affectedByFinally, stm.getBlockIdentifiers())) continue;
        Statement inner = stm.getStatement();
        /*
         * This pass helps with scala and dex2jar style output - find a remaining assignment to a stack
         * variable (or POSSIBLY a local), and follow it through.  If nothing intervenes, and we hit a return, we can
         * simply replace the entry point.
         *
         * We agressively attempt to follow through computable literals.
         *
         * Note that we pull this one out here, because it can handle a non-literal assignment -
         * inside PLReturn we can only handle subsequent literal assignments.
         */
        if (stm.getTargets().size() != 1)
            continue; // shouldn't be possible to be other, but a pruning might have removed.
        AssignmentSimple assignmentSimple = (AssignmentSimple) inner;
        LValue lValue = assignmentSimple.getCreatedLValue();
        Expression rValue = assignmentSimple.getRValue();
        if (!(lValue instanceof StackSSALabel || lValue instanceof LocalVariable)) continue;
        Map<LValue, Literal> display = MapFactory.newMap();
        if (rValue instanceof Literal) {
            display.put(lValue, (Literal) rValue);
        }
        Op03SimpleStatement next = stm.getTargets().get(0);
        success |= propagateLiteralReturn(method, stm, next, lValue, rValue, display);
        // Note - we can't have another go with return back yet, as it would break ternary discovery.
    }


    if (success) Op03Rewriters.replaceReturningIfs(statements, true);
}
 
Example #21
Source File: LocalClassScopeDiscoverImpl.java    From cfr with MIT License 5 votes vote down vote up
public LocalClassScopeDiscoverImpl(Options options, Method method, VariableFactory variableFactory) {
    super(options, method.getMethodPrototype(), variableFactory);
    scopeType = method.getMethodPrototype().getClassType();

    JavaTypeInstance thisClassType = method.getClassFile().getClassType();
    while (thisClassType != null) {
        if (null != localClassTypes.put(thisClassType, Boolean.FALSE)) break;
        InnerClassInfo innerClassInfo = thisClassType.getInnerClassHereInfo();
        if (!innerClassInfo.isInnerClass()) break;
        thisClassType = innerClassInfo.getOuterClass();
    }
}
 
Example #22
Source File: SinkSummaryDumper.java    From cfr with MIT License 5 votes vote down vote up
@Override
public void notifyError(JavaTypeInstance controllingType, Method method, String error) {
    if (lastControllingType != controllingType) {
        lastControllingType = controllingType;
        lastMethod = null;
        sink.write("\n\n" + controllingType.getRawName() + "\n----------------------------\n\n");
    }
    if (method != lastMethod) {
        sink.write(method.getMethodPrototype().toString() + "\n");
        lastMethod = method;
    }
    sink.write("  " + error + "\n");
}
 
Example #23
Source File: DeadMethodRemover.java    From cfr with MIT License 5 votes vote down vote up
public static void removeDeadMethod(ClassFile classFile, Method method) {
    Op04StructuredStatement code = method.getAnalysis();
    StructuredStatement statement = code.getStatement();
    if (!(statement instanceof Block)) return;

    Block block = (Block) statement;
    for (Op04StructuredStatement inner : block.getBlockStatements()) {
        StructuredStatement innerStatement = inner.getStatement();
        if (!(innerStatement instanceof StructuredComment)) {
            return;
        }
    }
    method.hideDead();
}
 
Example #24
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 #25
Source File: AnonymousClassConstructorRewriter.java    From cfr with MIT License 5 votes vote down vote up
@Override
public Expression rewriteExpression(Expression expression, SSAIdentifiers ssaIdentifiers, StatementContainer statementContainer, ExpressionRewriterFlags flags) {
    expression = super.rewriteExpression(expression, ssaIdentifiers, statementContainer, flags);
    if (expression instanceof ConstructorInvokationAnonymousInner) {
        ClassFile classFile = ((ConstructorInvokationAnonymousInner) expression).getClassFile();
        if (classFile != null) {
            for (Method constructor : classFile.getConstructors()) {
                Op04StructuredStatement analysis = constructor.getAnalysis();
                /*
                 * nop out initial super call, if present.
                 */
                if (!(analysis.getStatement() instanceof Block)) continue;
                Block block = (Block) analysis.getStatement();
                List<Op04StructuredStatement> statements = block.getBlockStatements();
                for (Op04StructuredStatement stmCont : statements) {
                    StructuredStatement stm = stmCont.getStatement();
                    if (stm instanceof StructuredComment) continue;
                    if (stm instanceof StructuredExpressionStatement) {
                        Expression e = ((StructuredExpressionStatement) stm).getExpression();
                        if (e instanceof SuperFunctionInvokation) {
                            stmCont.nopOut();
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }
    return expression;
}
 
Example #26
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static Method getMethod(ClassFile classFile, final List<JavaTypeInstance> args, String name) {
    List<Method> methods = classFile.getMethodsByNameOrNull(name);
    if (methods == null) return null;
    methods = Functional.filter(methods, new Predicate<Method>() {
        @Override
        public boolean test(Method in) {
            if (!in.testAccessFlag(AccessFlagMethod.ACC_PUBLIC)) return false;
            return in.getMethodPrototype().getArgs().equals(args);
        }
    });
    return methods.size() == 1 ? methods.get(0) : null;
}
 
Example #27
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void hideIfMatch(JavaTypeInstance thisType, List<ClassFileField> fields, Method method, WildcardMatch wcm, StructuredStatement stm) {
    StructuredStatement item = getSingleCodeLine(method);
    if (!stm.equals(item)) return;
    if (!cmpArgsEq(wcm.getExpressionWildCard("array").getMatch(), thisType, fields)) return;
    if (!isThis(wcm.getExpressionWildCard("this").getMatch(), thisType)) return;
    method.hideDead();
}
 
Example #28
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void hideHashCode(ClassFile classFile, JavaTypeInstance thisType, List<ClassFileField> fields) {
    Method method = getMethod(classFile, Collections.<JavaTypeInstance>emptyList(), MiscConstants.HASHCODE);
    if (method == null) return;

    WildcardMatch wcm = new WildcardMatch();
    StructuredStatement stm = new StructuredReturn(new CastExpression(new InferredJavaType(RawJavaType.INT, InferredJavaType.Source.TEST),
            wcm.getStaticFunction("func", TypeConstants.OBJECTMETHODS, TypeConstants.OBJECT, "bootstrap",
                    new Literal(TypedLiteral.getString(QuotingUtils.enquoteString(MiscConstants.HASHCODE))),
                    wcm.getExpressionWildCard("array"),
                    wcm.getExpressionWildCard("this"))), RawJavaType.INT);

    hideIfMatch(thisType, fields, method, wcm, stm);
}
 
Example #29
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void hideToString(ClassFile classFile, JavaTypeInstance thisType, List<ClassFileField> fields) {
    Method method = getMethod(classFile, Collections.<JavaTypeInstance>emptyList(), MiscConstants.TOSTRING);
    if (method == null) return;

    WildcardMatch wcm = new WildcardMatch();
    StructuredStatement stm = new StructuredReturn(
            wcm.getStaticFunction("func", TypeConstants.OBJECTMETHODS, TypeConstants.OBJECT, "bootstrap",
                    new Literal(TypedLiteral.getString(QuotingUtils.enquoteString(MiscConstants.TOSTRING))),
                    wcm.getExpressionWildCard("array"),
                    wcm.getExpressionWildCard("this")), TypeConstants.STRING);

    hideIfMatch(thisType, fields, method, wcm, stm);
}
 
Example #30
Source File: RecordRewriter.java    From cfr with MIT License 5 votes vote down vote up
private static void hideEquals(ClassFile classFile, JavaTypeInstance thisType, List<ClassFileField> fields) {
    Method method = getMethod(classFile, Collections.<JavaTypeInstance>singletonList(TypeConstants.OBJECT), MiscConstants.EQUALS);
    if (method == null) return;

    WildcardMatch wcm = new WildcardMatch();
    StructuredStatement stm = new StructuredReturn(new CastExpression(new InferredJavaType(RawJavaType.BOOLEAN, InferredJavaType.Source.TEST),
            wcm.getStaticFunction("func", TypeConstants.OBJECTMETHODS, TypeConstants.OBJECT, "bootstrap",
                    new Literal(TypedLiteral.getString(QuotingUtils.enquoteString(MiscConstants.EQUALS))),
                    wcm.getExpressionWildCard("array"),
                    wcm.getExpressionWildCard("this"),
                    new LValueExpression(method.getMethodPrototype().getComputedParameters().get(0)))), RawJavaType.BOOLEAN);

    hideIfMatch(thisType, fields, method, wcm, stm);
}