private InstructionPrinter(final ITextOutput output, final MethodDefinition method, final DecompilerSettings settings, final int[] lineNumbers) { _settings = settings; _output = VerifyArgument.notNull(output, "output"); _body = VerifyArgument.notNull(method, "method").getBody(); _lineNumbers = lineNumbers; }
private InstructionPrinter(final ITextOutput output, final MethodDefinition method, final DecompilerSettings settings, final int[] lineNumbers) { _settings = settings; _output = VerifyArgument.notNull(output, "output"); _body = VerifyArgument.notNull(method, "method").getBody(); _lineNumbers = lineNumbers; }
private InstructionPrinter(final ITextOutput output, final MethodDefinition method, final DecompilerSettings settings, final int[] lineNumbers) { _settings = settings; _output = VerifyArgument.notNull(output, "output"); _body = VerifyArgument.notNull(method, "method").getBody(); _lineNumbers = lineNumbers; }
Frame(FrameContext fc, Frame closure) { this.sources = new IdentityHashMap<>(); this.fieldValues = fc.getInitialFields(); this.fc = fc; this.initial = new IdentityHashMap<>(); for(ParameterDefinition pd : fc.md.getParameters()) { putInitial(pd); } ParameterDefinition thisParam = fc.md.getBody().getThisParameter(); if(thisParam != null) { putInitial(thisParam); } if(closure != null) { initial.putAll(closure.initial); sources.putAll(closure.sources); } }
private void visitMethod(MethodData mdata, MethodDefinition md) { MethodBody body = md.getBody(); if (Flags.testAny(md.getFlags(), Flags.NATIVE)) { mdata.flags |= METHOD_MAY_HAVE_SIDE_EFFECT | METHOD_MAY_RETURN_NORMALLY | METHOD_MAY_THROW | METHOD_NON_TRIVIAL | METHOD_SUPPORTED; } if (body != null) { visitBody(mdata, body); } }
Map<MethodDefinition, MethodDefinition> deps = new HashMap<>(); for(MethodDefinition ctor : ctors) { MethodBody body = ctor.getBody(); if(body != null) { for(Instruction instr : body.getInstructions()) {
static void extractCalls(MethodDefinition md, Predicate<MethodReference> action) { MethodBody body = md.getBody(); if(body == null) return; for(Instruction inst : body.getInstructions()) { for(int i=0; i<inst.getOperandCount(); i++) { Object operand = inst.getOperand(i); if(operand instanceof MethodReference) { if(!action.test((MethodReference)operand)) return; } if(operand instanceof DynamicCallSite) { MethodHandle mh = Nodes.getMethodHandle((DynamicCallSite) operand); if(mh != null) { if(!action.test(mh.getMethod())) return; } } } } }
public static boolean isThrower(MethodDefinition md) { MethodBody body = md.getBody(); if(body == null) return false; for(Instruction inst : body.getInstructions()) { if(inst.hasLabel() || inst.getOpCode() == OpCode.RETURN || inst.getOpCode() == OpCode.ARETURN) return false; if(inst.getOpCode() == OpCode.ATHROW) return true; } // Actually should not go here for valid bytecode return false; }
Location getLocation(Node node) { NodeChain nc = parents; while(true) { int offset = getOffset(node); if(offset != Expression.MYSTERY_OFFSET) return new Location(offset, getLineNumber(offset)); if(nc == null || nc.getNode() instanceof Lambda) return new Location(0, getLineNumber(0)); // TODO: better support of catch blocks while(true) { Node parentNode = nc.getNode(); nc = nc.getParent(); List<Node> children = parentNode.getChildren(); int idx = children.indexOf(node); if(idx < children.size() - 1) { node = children.get(idx+1); break; } node = parentNode; if(nc == null || nc.getNode() instanceof Lambda) { offset = Math.max(realMethod.getBody().getCodeSize()-1, 0); return new Location(offset, getLineNumber(offset)); } } } }
public static MethodDefinition resolveToBridge(MethodDefinition md) { if (md.isBridgeMethod()) { return md; } for (MethodDefinition candidate : md.getDeclaringType().getDeclaredMethods()) { if (candidate.getName().equals(md.getName()) && candidate.isBridgeMethod()) { List<ParameterDefinition> params = candidate.getParameters(); if (params.size() == md.getParameters().size()) { MethodBody body = candidate.getBody(); if (body != null) { for (Instruction instr : body.getInstructions()) { if (instr.getOperandCount() == 1) { Object operand = instr.getOperand(0); if (operand instanceof MethodReference) { MethodReference mr = (MethodReference) operand; if (mr.getName().equals(md.getName()) && mr.getErasedSignature().equals(md .getErasedSignature()) && mr.getDeclaringType().isEquivalentTo(md .getDeclaringType())) { return candidate; } } } } } } } } return md; }
@Nullable private MethodDefinition tryLocateClassMethodOutOfScope(final TypeDefinition currentType) { final TypeDefinition enclosingType = MetadataHelper.getOutermostEnclosingType(currentType); if (enclosingType == null) { return null; } final AstBuilder builder = _context.getUserData(Keys.AST_BUILDER); for (final MethodDefinition m : enclosingType.getDeclaredMethods()) { if (ClassMethodLocator.isClassMethodCandidate(m)) { final MethodBody body = m.getBody(); if (body != null && body.getCodeSize() <= CANDIDATE_MAX_CODE_SIZE) { final MethodDeclaration method = builder.createMethod(m); if (ClassMethodLocator.PATTERN.matches(method)) { return m; } } } } return null; }
private boolean shouldInferVariableType(final Variable variable) { final VariableDefinition variableDefinition = variable.getOriginalVariable(); if (variable.isGenerated() || variable.isLambdaParameter()) { return true; } final ParameterDefinition parameter = variable.getOriginalParameter(); if (parameter != null) { if (parameter == _context.getCurrentMethod().getBody().getThisParameter()) { return false; } final TypeReference parameterType = parameter.getParameterType(); return !_preserveMetadataGenericTypes && (parameterType.isGenericType() || MetadataHelper.isRawType(parameterType)); } //noinspection RedundantIfStatement if (variableDefinition != null && variableDefinition.isFromMetadata() && (variableDefinition.getVariableType().isGenericType() ? _preserveMetadataGenericTypes : _preserveMetadataTypes)) { return false; } return true; }
private boolean shouldInferVariableType(final Variable variable) { final VariableDefinition variableDefinition = variable.getOriginalVariable(); if (variable.isGenerated() || variable.isLambdaParameter()) { return true; } if (variable.isParameter()) { final ParameterDefinition parameter = variable.getOriginalParameter(); if (parameter == _context.getCurrentMethod().getBody().getThisParameter()) { return false; } final TypeReference parameterType = parameter.getParameterType(); return !_preserveMetadataGenericTypes && (parameterType.isGenericType() || MetadataHelper.isRawType(parameterType)); } //noinspection RedundantIfStatement if (variableDefinition != null && variableDefinition.isFromMetadata() && (variableDefinition.getVariableType().isGenericType() ? _preserveMetadataGenericTypes : _preserveMetadataTypes)) { return false; } return true; }
private boolean shouldInferVariableType(final Variable variable) { final VariableDefinition variableDefinition = variable.getOriginalVariable(); if (variable.isGenerated() || variable.isLambdaParameter()) { return true; } if (variable.isParameter()) { final ParameterDefinition parameter = variable.getOriginalParameter(); if (parameter == _context.getCurrentMethod().getBody().getThisParameter()) { return false; } final TypeReference parameterType = parameter.getParameterType(); return !_preserveMetadataGenericTypes && (parameterType.isGenericType() || MetadataHelper.isRawType(parameterType)); } //noinspection RedundantIfStatement if (variableDefinition != null && variableDefinition.isFromMetadata() && (variableDefinition.getVariableType().isGenericType() ? _preserveMetadataGenericTypes : _preserveMetadataTypes)) { return false; } return true; }
final MethodBody body = method.getBody();
final MethodBody body = method.getBody();
private void writeMethodBody(final ITextOutput output, final MethodDefinition method, final DecompilationOptions options) { final MethodBody body = method.getBody();
final MethodBody body = method.getBody();
final MethodBody body = method.getBody();
final MethodBody body = method.getBody();