org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences Java Examples
The following examples show how to use
org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.
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: ClassWriter.java From javaide with GNU General Public License v3.0 | 6 votes |
private static void invokeProcessors(ClassNode node) { ClassWrapper wrapper = node.getWrapper(); StructClass cl = wrapper.getClassStruct(); InitializerProcessor.extractInitializers(wrapper); if (node.type == ClassNode.CLASS_ROOT && !cl.isVersionGE_1_5() && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_CLASS_1_4)) { ClassReference14Processor.processClassReferences(node); } if (cl.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM)) { EnumProcessor.clearEnum(wrapper); } if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ASSERTIONS)) { AssertProcessor.buildAssertions(node); } }
Example #2
Source File: ClassWriter.java From javaide with GNU General Public License v3.0 | 6 votes |
private static boolean hideConstructor(ClassWrapper wrapper, boolean init, boolean throwsExceptions, int paramCount) { if (!init || throwsExceptions || paramCount > 0 || !DecompilerContext.getOption(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR)) { return false; } int count = 0; for (StructMethod mt : wrapper.getClassStruct().getMethods()) { if (CodeConstants.INIT_NAME.equals(mt.getName())) { if (++count > 1) { return false; } } } return true; }
Example #3
Source File: ClassWriter.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
private static void invokeProcessors(ClassNode node) { ClassWrapper wrapper = node.getWrapper(); StructClass cl = wrapper.getClassStruct(); InitializerProcessor.extractInitializers(wrapper); if (node.type == ClassNode.CLASS_ROOT && !cl.isVersionGE_1_5() && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_CLASS_1_4)) { ClassReference14Processor.processClassReferences(node); } if (cl.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM)) { EnumProcessor.clearEnum(wrapper); } if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ASSERTIONS)) { AssertProcessor.buildAssertions(node); } }
Example #4
Source File: ClassWriter.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
private static boolean hideConstructor(ClassWrapper wrapper, boolean init, boolean throwsExceptions, int paramCount) { if (!init || throwsExceptions || paramCount > 0 || !DecompilerContext.getOption(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR)) { return false; } int count = 0; for (StructMethod mt : wrapper.getClassStruct().getMethods()) { if (CodeConstants.INIT_NAME.equals(mt.getName())) { if (++count > 1) { return false; } } } return true; }
Example #5
Source File: InitializerProcessor.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
public static void extractInitializers(ClassWrapper wrapper) { MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V"); if (method != null && method.root != null) { // successfully decompiled static constructor extractStaticInitializers(wrapper, method); } extractDynamicInitializers(wrapper); // required e.g. if anonymous class is being decompiled as a standard one. // This can happen if InnerClasses attributes are erased liftConstructor(wrapper); if (DecompilerContext.getOption(IFernflowerPreferences.HIDE_EMPTY_SUPER)) { hideEmptySuper(wrapper); } }
Example #6
Source File: InitializerProcessor.java From javaide with GNU General Public License v3.0 | 6 votes |
public static void extractInitializers(ClassWrapper wrapper) { MethodWrapper method = wrapper.getMethodWrapper(CodeConstants.CLINIT_NAME, "()V"); if (method != null && method.root != null) { // successfully decompiled static constructor extractStaticInitializers(wrapper, method); } extractDynamicInitializers(wrapper); // required e.g. if anonymous class is being decompiled as a standard one. // This can happen if InnerClasses attributes are erased liftConstructor(wrapper); if (DecompilerContext.getOption(IFernflowerPreferences.HIDE_EMPTY_SUPER)) { hideEmptySuper(wrapper); } }
Example #7
Source File: FernFlowerDecompiler.java From Recaf with MIT License | 5 votes |
@Override protected Map<String, Object> generateDefaultOptions() { Map<String, Object> map = new HashMap<>(IFernflowerPreferences.getDefaults()); map.put("ind", " "); ConfDecompile config = getController().config().decompile(); if (config.showSynthetic) { // FernFlower doesn't have options against intentional marking of ACC_SYNTHETIC by obfuscators :/ // This will only show ACC_BRIDGE but not ACC_SYNTHETIC map.put("rbr", "0"); // hide bridge methods map.put("rsy", "0"); // hide synthetic class members } return map; }
Example #8
Source File: ConstExprent.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public boolean hasBooleanValue() { switch (constType.type) { case CodeConstants.TYPE_BOOLEAN: case CodeConstants.TYPE_CHAR: case CodeConstants.TYPE_BYTE: case CodeConstants.TYPE_BYTECHAR: case CodeConstants.TYPE_SHORT: case CodeConstants.TYPE_SHORTCHAR: case CodeConstants.TYPE_INT: int value = ((Integer) this.value).intValue(); return value == 0 || (DecompilerContext.getOption(IFernflowerPreferences.BOOLEAN_TRUE_ONE) && value == 1); } return false; }
Example #9
Source File: IdentifierConverter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public void rename(StructContext context) { try { this.context = context; String user_class = (String) DecompilerContext.getProperty(IFernflowerPreferences.USER_RENAMER_CLASS); if (user_class != null) { try { helper = (IIdentifierRenamer) IdentifierConverter.class.getClassLoader().loadClass(user_class).newInstance(); } catch (Exception ignored) { } } if (helper == null) { helper = new ConverterHelper(); } interceptor = new PoolInterceptor(helper); buildInheritanceTree(); renameAllClasses(); renameInterfaces(); renameClasses(); DecompilerContext.setPoolInterceptor(interceptor); context.reloadContext(); } catch (IOException ex) { throw new RuntimeException("Renaming failed!"); } }
Example #10
Source File: ClassWriter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
private static String getTypePrintOut(VarType type) { String typeText = ExprProcessor.getCastTypeName(type, false); if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeText) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) { typeText = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT, false); } return typeText; }
Example #11
Source File: Fernflower.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public void decompileContext() { if (DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) { new IdentifierConverter().rename(structContext); } classesProcessor = new ClassesProcessor(structContext); DecompilerContext.setClassProcessor(classesProcessor); DecompilerContext.setStructContext(structContext); structContext.saveContext(); }
Example #12
Source File: Fernflower.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public String getClassEntryName(StructClass cl, String entryName) { ClassNode node = classesProcessor.getMapRootClasses().get(cl.qualifiedName); if (node.type != ClassNode.CLASS_ROOT) { return null; } else { if (DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) { String simple_classname = cl.qualifiedName.substring(cl.qualifiedName.lastIndexOf('/') + 1); return entryName.substring(0, entryName.lastIndexOf('/') + 1) + simple_classname + ".java"; } else { return entryName.substring(0, entryName.lastIndexOf(".class")) + ".java"; } } }
Example #13
Source File: Fernflower.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
@Override public String getClassContent(StructClass cl) { try { TextBuffer buffer = new TextBuffer(ClassesProcessor.AVERAGE_CLASS_SIZE); buffer.append(DecompilerContext.getProperty(IFernflowerPreferences.BANNER).toString()); classesProcessor.writeClass(cl, buffer); return buffer.toString(); } catch (Throwable ex) { DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", ex); return null; } }
Example #14
Source File: ClassReference14Processor.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
private static void mapClassMethods(ClassNode node, Map<ClassWrapper, MethodWrapper> map) { boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); ClassWrapper wrapper = node.getWrapper(); for (MethodWrapper method : wrapper.getMethods()) { StructMethod mt = method.methodStruct; if ((noSynthFlag || mt.isSynthetic()) && mt.getDescriptor().equals("(Ljava/lang/String;)Ljava/lang/Class;") && mt.hasModifier(CodeConstants.ACC_STATIC)) { RootStatement root = method.root; if (root != null && root.getFirst().type == Statement.TYPE_TRYCATCH) { CatchStatement cst = (CatchStatement) root.getFirst(); if (cst.getStats().size() == 2 && cst.getFirst().type == Statement.TYPE_BASICBLOCK && cst.getStats().get(1).type == Statement.TYPE_BASICBLOCK && cst.getVars().get(0).getVarType().equals(new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/ClassNotFoundException"))) { BasicBlockStatement body = (BasicBlockStatement) cst.getFirst(); BasicBlockStatement handler = (BasicBlockStatement) cst.getStats().get(1); if (body.getExprents().size() == 1 && handler.getExprents().size() == 1) { if (BODY_EXPR.equals(body.getExprents().get(0)) && HANDLER_EXPR.equals(handler.getExprents().get(0))) { map.put(wrapper, method); break; } } } } } } // iterate nested classes for (ClassNode nd : node.nested) { mapClassMethods(nd, map); } }
Example #15
Source File: NestedMemberAccess.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public void propagateMemberAccess(ClassNode root) { if (root.nested.isEmpty()) { return; } noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); computeMethodTypes(root); eliminateStaticAccess(root); }
Example #16
Source File: NestedClassProcessor.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
private static String getEnclosingVarField(StructClass cl, MethodWrapper method, DirectGraph graph, int index) { String field = ""; // parameter variable final if (method.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarTypeProcessor.VAR_NON_FINAL) { return null; } boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); // no loop at the begin DirectNode firstNode = graph.first; if (firstNode.preds.isEmpty()) { // assignment to a synthetic field? for (Exprent exprent : firstNode.exprents) { if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) { AssignmentExprent assignExpr = (AssignmentExprent) exprent; if (assignExpr.getRight().type == Exprent.EXPRENT_VAR && ((VarExprent) assignExpr.getRight()).getIndex() == index && assignExpr.getLeft().type == Exprent.EXPRENT_FIELD) { FieldExprent left = (FieldExprent) assignExpr.getLeft(); StructField fd = cl.getField(left.getName(), left.getDescriptor().descriptorString); if (fd != null && cl.qualifiedName.equals(left.getClassname()) && fd.hasModifier(CodeConstants.ACC_FINAL) && (fd.isSynthetic() || (noSynthFlag && fd.hasModifier(CodeConstants.ACC_PRIVATE)))) { // local (== not inherited) field field = InterpreterUtil.makeUniqueKey(left.getName(), left.getDescriptor().descriptorString); break; } } } } } return field; }
Example #17
Source File: DecompilerContext.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public static void initContext(Map<String, Object> propertiesCustom) { Map<String, Object> properties = new HashMap<>(IFernflowerPreferences.DEFAULTS); if (propertiesCustom != null) { properties.putAll(propertiesCustom); } currentContext.set(new DecompilerContext(properties)); }
Example #18
Source File: DecompilerContext.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public static void setLogger(IFernflowerLogger logger) { if (logger != null) { String level = (String) getProperty(IFernflowerPreferences.LOG_LEVEL); if (level != null) { try { logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US))); } catch (IllegalArgumentException ignore) { } } } getCurrentContext().logger = logger; }
Example #19
Source File: TextUtil.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public static String getIndentString(int length) { if (length == 0) return ""; StringBuilder buf = new StringBuilder(); String indent = (String) DecompilerContext.getProperty(IFernflowerPreferences.INDENT_STRING); while (length-- > 0) { buf.append(indent); } return buf.toString(); }
Example #20
Source File: FernflowerDecompiler.java From windup with Eclipse Public License 1.0 | 5 votes |
private Map<String, Object> getOptions() { Map<String, Object> options = new HashMap<>(); options.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 30); options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); return options; }
Example #21
Source File: ClassWriter.java From javaide with GNU General Public License v3.0 | 5 votes |
private static String getTypePrintOut(VarType type) { String typeText = ExprProcessor.getCastTypeName(type, false); if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeText) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) { typeText = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT, false); } return typeText; }
Example #22
Source File: NestedClassProcessor.java From javaide with GNU General Public License v3.0 | 5 votes |
private static String getEnclosingVarField(StructClass cl, MethodWrapper method, DirectGraph graph, int index) { String field = ""; // parameter variable final if (method.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarTypeProcessor.VAR_NON_FINAL) { return null; } boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); // no loop at the begin DirectNode firstNode = graph.first; if (firstNode.preds.isEmpty()) { // assignment to a synthetic field? for (Exprent exprent : firstNode.exprents) { if (exprent.type == Exprent.EXPRENT_ASSIGNMENT) { AssignmentExprent assignExpr = (AssignmentExprent) exprent; if (assignExpr.getRight().type == Exprent.EXPRENT_VAR && ((VarExprent) assignExpr.getRight()).getIndex() == index && assignExpr.getLeft().type == Exprent.EXPRENT_FIELD) { FieldExprent left = (FieldExprent) assignExpr.getLeft(); StructField fd = cl.getField(left.getName(), left.getDescriptor().descriptorString); if (fd != null && cl.qualifiedName.equals(left.getClassname()) && (fd.isSynthetic() || noSynthFlag && possiblySyntheticField(fd))) { // local (== not inherited) field field = InterpreterUtil.makeUniqueKey(left.getName(), left.getDescriptor().descriptorString); break; } } } } } return field; }
Example #23
Source File: ClassWriter.java From javaide with GNU General Public License v3.0 | 5 votes |
public static GenericClassDescriptor getGenericClassDescriptor(StructClass cl) { if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES)) { StructGenericSignatureAttribute attr = (StructGenericSignatureAttribute) cl.getAttribute("Signature"); if (attr != null) { return GenericMain.parseClassSignature(attr.getSignature()); } } return null; }
Example #24
Source File: NestedMemberAccess.java From javaide with GNU General Public License v3.0 | 5 votes |
public void propagateMemberAccess(ClassNode root) { if (root.nested.isEmpty()) { return; } noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); computeMethodTypes(root); eliminateStaticAccess(root); }
Example #25
Source File: ClassReference14Processor.java From javaide with GNU General Public License v3.0 | 5 votes |
private static void mapClassMethods(ClassNode node, Map<ClassWrapper, MethodWrapper> map) { boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); ClassWrapper wrapper = node.getWrapper(); for (MethodWrapper method : wrapper.getMethods()) { StructMethod mt = method.methodStruct; if ((noSynthFlag || mt.isSynthetic()) && mt.getDescriptor().equals("(Ljava/lang/String;)Ljava/lang/Class;") && mt.hasModifier(CodeConstants.ACC_STATIC)) { RootStatement root = method.root; if (root != null && root.getFirst().type == Statement.TYPE_TRYCATCH) { CatchStatement cst = (CatchStatement) root.getFirst(); if (cst.getStats().size() == 2 && cst.getFirst().type == Statement.TYPE_BASICBLOCK && cst.getStats().get(1).type == Statement.TYPE_BASICBLOCK && cst.getVars().get(0).getVarType().equals(new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/ClassNotFoundException"))) { BasicBlockStatement body = (BasicBlockStatement) cst.getFirst(); BasicBlockStatement handler = (BasicBlockStatement) cst.getStats().get(1); if (body.getExprents().size() == 1 && handler.getExprents().size() == 1) { if (BODY_EXPR.equals(body.getExprents().get(0)) && HANDLER_EXPR.equals(handler.getExprents().get(0))) { map.put(wrapper, method); break; } } } } } } // iterate nested classes for (ClassNode nd : node.nested) { mapClassMethods(nd, map); } }
Example #26
Source File: Fernflower.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public String getClassContent(StructClass cl) { try { TextBuffer buffer = new TextBuffer(ClassesProcessor.AVERAGE_CLASS_SIZE); buffer.append(DecompilerContext.getProperty(IFernflowerPreferences.BANNER).toString()); classProcessor.writeClass(cl, buffer); return buffer.toString(); } catch (Throwable t) { DecompilerContext.getLogger().writeMessage("Class " + cl.qualifiedName + " couldn't be fully decompiled.", t); return null; } }
Example #27
Source File: Fernflower.java From javaide with GNU General Public License v3.0 | 5 votes |
public Fernflower(IBytecodeProvider provider, IResultSaver saver, Map<String, Object> customProperties, IFernflowerLogger logger) { Map<String, Object> properties = new HashMap<>(IFernflowerPreferences.DEFAULTS); if (customProperties != null) { properties.putAll(customProperties); } String level = (String) properties.get(IFernflowerPreferences.LOG_LEVEL); if (level != null) { try { logger.setSeverity(IFernflowerLogger.Severity.valueOf(level.toUpperCase(Locale.US))); } catch (IllegalArgumentException ignore) { } } structContext = new StructContext(saver, this, new LazyLoader(provider)); classProcessor = new ClassesProcessor(structContext); PoolInterceptor interceptor = null; if ("1".equals(properties.get(IFernflowerPreferences.RENAME_ENTITIES))) { helper = loadHelper((String) properties.get(IFernflowerPreferences.USER_RENAMER_CLASS), logger); interceptor = new PoolInterceptor(); converter = new IdentifierConverter(structContext, helper, interceptor); } else { helper = null; converter = null; } DecompilerContext context = new DecompilerContext(properties, logger, structContext, classProcessor, interceptor); DecompilerContext.setCurrentContext(context); }
Example #28
Source File: AssertProcessor.java From javaide with GNU General Public License v3.0 | 4 votes |
private static StructField findAssertionField(ClassNode node) { ClassWrapper wrapper = node.getWrapper(); boolean noSynthFlag = DecompilerContext.getOption(IFernflowerPreferences.SYNTHETIC_NOT_SET); for (StructField fd : wrapper.getClassStruct().getFields()) { String keyField = InterpreterUtil.makeUniqueKey(fd.getName(), fd.getDescriptor()); // initializer exists if (wrapper.getStaticFieldInitializers().containsKey(keyField)) { // access flags set if (fd.hasModifier(CodeConstants.ACC_STATIC) && fd.hasModifier(CodeConstants.ACC_FINAL) && (noSynthFlag || fd.isSynthetic())) { // field type boolean FieldDescriptor fdescr = FieldDescriptor.parseDescriptor(fd.getDescriptor()); if (VarType.VARTYPE_BOOLEAN.equals(fdescr.type)) { Exprent initializer = wrapper.getStaticFieldInitializers().getWithKey(keyField); if (initializer.type == Exprent.EXPRENT_FUNCTION) { FunctionExprent fexpr = (FunctionExprent) initializer; if (fexpr.getFuncType() == FunctionExprent.FUNCTION_BOOL_NOT && fexpr.getLstOperands().get(0).type == Exprent.EXPRENT_INVOCATION) { InvocationExprent invexpr = (InvocationExprent) fexpr.getLstOperands().get(0); if (invexpr.getInstance() != null && invexpr.getInstance().type == Exprent.EXPRENT_CONST && "desiredAssertionStatus".equals(invexpr.getName()) && "java/lang/Class".equals(invexpr.getClassname()) && invexpr.getLstParameters().isEmpty()) { ConstExprent cexpr = (ConstExprent) invexpr.getInstance(); if (VarType.VARTYPE_CLASS.equals(cexpr.getConstType())) { ClassNode nd = node; while (nd != null) { if (nd.getWrapper().getClassStruct().qualifiedName.equals(cexpr.getValue())) { break; } nd = nd.parent; } if (nd != null) { // found enclosing class with the same name return fd; } } } } } } } } } return null; }
Example #29
Source File: FinallyProcessor.java From javaide with GNU General Public License v3.0 | 4 votes |
private boolean processStatementEx(StructMethod mt, RootStatement root, ControlFlowGraph graph) { int bytecode_version = mt.getClassStruct().getBytecodeVersion(); LinkedList<Statement> stack = new LinkedList<>(); stack.add(root); while (!stack.isEmpty()) { Statement stat = stack.removeLast(); Statement parent = stat.getParent(); if (parent != null && parent.type == Statement.TYPE_CATCHALL && stat == parent.getFirst() && !parent.isCopied()) { CatchAllStatement fin = (CatchAllStatement) parent; BasicBlock head = fin.getBasichead().getBlock(); BasicBlock handler = fin.getHandler().getBasichead().getBlock(); if (catchallBlockIDs.containsKey(handler.id)) { // do nothing } else if (finallyBlockIDs.containsKey(handler.id)) { fin.setFinally(true); Integer var = finallyBlockIDs.get(handler.id); fin.setMonitor(var == null ? null : new VarExprent(var, VarType.VARTYPE_INT, varProcessor)); } else { Record inf = getFinallyInformation(mt, root, fin); if (inf == null) { // inconsistent finally catchallBlockIDs.put(handler.id, null); } else { if (DecompilerContext.getOption(IFernflowerPreferences.FINALLY_DEINLINE) && verifyFinallyEx(graph, fin, inf)) { finallyBlockIDs.put(handler.id, null); } else { int varindex = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER); insertSemaphore(graph, getAllBasicBlocks(fin.getFirst()), head, handler, varindex, inf, bytecode_version); finallyBlockIDs.put(handler.id, varindex); } DeadCodeHelper.removeDeadBlocks(graph); // e.g. multiple return blocks after a nested finally DeadCodeHelper.removeEmptyBlocks(graph); DeadCodeHelper.mergeBasicBlocks(graph); } return true; } } stack.addAll(stat.getStats()); } return false; }
Example #30
Source File: ClassWriter.java From javaide with GNU General Public License v3.0 | 4 votes |
private static void methodLambdaToJava(ClassNode lambdaNode, ClassWrapper classWrapper, StructMethod mt, TextBuffer buffer, int indent, boolean codeOnly, BytecodeMappingTracer tracer) { MethodWrapper methodWrapper = classWrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()); MethodWrapper outerWrapper = (MethodWrapper) DecompilerContext.getProperty(DecompilerContext.CURRENT_METHOD_WRAPPER); DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_WRAPPER, methodWrapper); try { String method_name = lambdaNode.lambdaInformation.method_name; MethodDescriptor md_content = MethodDescriptor.parseDescriptor(lambdaNode.lambdaInformation.content_method_descriptor); MethodDescriptor md_lambda = MethodDescriptor.parseDescriptor(lambdaNode.lambdaInformation.method_descriptor); if (!codeOnly) { buffer.appendIndent(indent); buffer.append("public "); buffer.append(method_name); buffer.append("("); boolean firstParameter = true; int index = lambdaNode.lambdaInformation.is_content_method_static ? 0 : 1; int start_index = md_content.params.length - md_lambda.params.length; for (int i = 0; i < md_content.params.length; i++) { if (i >= start_index) { if (!firstParameter) { buffer.append(", "); } String typeName = ExprProcessor.getCastTypeName(md_content.params[i].copy()); if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) && DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) { typeName = ExprProcessor.getCastTypeName(VarType.VARTYPE_OBJECT); } buffer.append(typeName); buffer.append(" "); String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0)); buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors firstParameter = false; } index += md_content.params[i].stackSize; } buffer.append(") {").appendLineSeparator(); indent += 1; } RootStatement root = classWrapper.getMethodWrapper(mt.getName(), mt.getDescriptor()).root; if (!methodWrapper.decompiledWithErrors) { if (root != null) { // check for existence try { buffer.append(root.toJava(indent, tracer)); } catch (Throwable t) { String message = "Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be written."; DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.WARN, t); methodWrapper.decompiledWithErrors = true; } } } if (methodWrapper.decompiledWithErrors) { buffer.appendIndent(indent); buffer.append("// $FF: Couldn't be decompiled"); buffer.appendLineSeparator(); } if (root != null) { tracer.addMapping(root.getDummyExit().bytecode); } if (!codeOnly) { indent -= 1; buffer.appendIndent(indent).append('}').appendLineSeparator(); } } finally { DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_WRAPPER, outerWrapper); } }