@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); if (isLabeled()) { buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator(); } buf.appendIndent(indent).append("abstract statement {").appendLineSeparator(); for (Statement stat : stats) { buf.append(stat.toJava(indent + 1, tracer)); } buf.appendIndent(indent).append("}"); return buf; } }
public TextBuffer append(TextBuffer buffer) { if (buffer.myLineToOffsetMapping != null && !buffer.myLineToOffsetMapping.isEmpty()) { checkMapCreated(); for (Map.Entry<Integer, Integer> entry : buffer.myLineToOffsetMapping.entrySet()) { myLineToOffsetMapping.put(entry.getKey(), entry.getValue() + myStringBuilder.length()); } } myStringBuilder.append(buffer.myStringBuilder); return this; }
private void appendLines(StringBuilder res, String[] srcLines, int from, int to, int requiredLineNumber) { if (to - from > requiredLineNumber) { List<String> strings = compactLines(Arrays.asList(srcLines).subList(from, to) ,requiredLineNumber); int separatorsRequired = requiredLineNumber - 1; for (String s : strings) { res.append(s); if (separatorsRequired-- > 0) { res.append(myLineSeparator); } } res.append(myLineSeparator); } else if (to - from <= requiredLineNumber) { for (int i = from; i < to; i++) { res.append(srcLines[i]).append(myLineSeparator); } for (int i = 0; i < requiredLineNumber - to + from; i++) { res.append(myLineSeparator); } } }
private static void appendDeprecation(TextBuffer buffer, int indent) { buffer.appendIndent(indent).append("/** @deprecated */").appendLineSeparator(); }
public int writeImports(TextBuffer buffer) { int importLinesWritten = 0; List<String> imports = packImports(); for (String s : imports) { buffer.append("import "); buffer.append(s); buffer.append(';'); buffer.appendLineSeparator(); importLinesWritten++; } return importLinesWritten; }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); enclosing = getQualifiedNewInstance(child.anonymousClassType.value, constructor.getLstParameters(), indent, tracer); if (enclosing != null) { buf.append(enclosing).append('.'); buf.append("new "); if (descriptor != null) { if (descriptor.superinterfaces.isEmpty()) { buf.append(GenericMain.getGenericCastTypeName(descriptor.superclass)); buf.append(GenericMain.getGenericCastTypeName(descriptor.superinterfaces.get(0))); buf.append(typename); buf.append('('); if (mask == null || mask.get(i) == null) { if (!firstParam) { buf.append(", "); buf.append(')'); if (enumConst && buf.length() == 2) { buf.setLength(0); buf.setLength(0); // remove the usual 'new <class>()', it will be replaced with lambda style '() ->'
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); buf.append(DecompilerContext.getImportCollector().getShortNameInClassContext(ExprProcessor.buildJavaClassName(classname))); buf.append(res); return buf; buf.append("((").append(ExprProcessor.getCastTypeName(leftType)).append(")"); res.enclose("(", ")"); buf.append(res).append(")"); buf.append("(").append(res).append(")"); buf.append(res); if (VarExprent.VAR_NAMELESS_ENCLOSURE.equals(buf.toString())) { buf = new TextBuffer(); if (buf.length() > 0) { buf.append("."); buf.append(name); if (invocationTyp == INVOKE_DYNAMIC) { buf.append("<invokedynamic>"); buf.append("(");
TextBuffer classBuffer = new TextBuffer(AVERAGE_CLASS_SIZE); new ClassWriter().classToJava(root, classBuffer, 0, null); String packageName = cl.qualifiedName.substring(0, index).replace('/', '.'); buffer.append("package "); buffer.append(packageName); buffer.append(";"); buffer.appendLineSeparator(); buffer.appendLineSeparator(); buffer.appendLineSeparator(); int offsetLines = buffer.countLines(); buffer.append(classBuffer); mapper.addTotalOffset(offsetLines); if (DecompilerContext.getOption(IFernflowerPreferences.DUMP_ORIGINAL_LINES)) { buffer.dumpOriginalLineNumbers(mapper.getOriginalLinesMapping()); buffer.appendLineSeparator(); mapper.dumpMapping(buffer, true);
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); buf.append(DecompilerContext.getImportCollector().getShortNameInClassContext(ExprProcessor.buildJavaClassName(classname))); buf.append("."); TextBuffer buff = new TextBuffer(); boolean casted = ExprProcessor.getCastedExprent(instance, new VarType(CodeConstants.TYPE_OBJECT, 0, classname), buff, indent, true, tracer); String res = buff.toString(); buf.append(res); if (buf.toString().equals( buf.setLength(0); buf.append("."); buf.append(name);
return new TextBuffer(); TextBuffer buffer = new TextBuffer(); buffer.append(((FieldExprent)left).getName()); buffer.append(left.toJava(indent, tracer)); (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT)) { if (right.getPrecedence() >= FunctionExprent.getPrecedence(FunctionExprent.FUNCTION_CAST)) { res.enclose("(", ")"); res.prepend("(" + ExprProcessor.getCastTypeName(leftType) + ")"); buffer.append(condType == CONDITION_NONE ? " = " : OPERATORS[condType]).append(res);
private static void appendAnnotations(TextBuffer buffer, int indent, StructMember mb, int targetType) { Set<String> filter = new HashSet<>(); for (StructGeneralAttribute.Key<?> key : ANNOTATION_ATTRIBUTES) { StructAnnotationAttribute attribute = (StructAnnotationAttribute)mb.getAttribute(key); if (attribute != null) { for (AnnotationExprent annotation : attribute.getAnnotations()) { String text = annotation.toJava(indent, BytecodeMappingTracer.DUMMY).toString(); filter.add(text); buffer.append(text).appendLineSeparator(); } } } appendTypeAnnotations(buffer, indent, mb, targetType, -1, filter); }
@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; } } }
.append(OPERATORS[funcType]) .append(wrapOperandString(lstOperands.get(1), true, indent, tracer)); .append(OPERATORS[funcType - FUNCTION_EQ + 11]) .append(wrapOperandString(lstOperands.get(1), true, indent, tracer)); return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("~"); case FUNCTION_BOOL_NOT: return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("!"); case FUNCTION_NEG: return wrapOperandString(lstOperands.get(0), true, indent, tracer).prepend("-"); case FUNCTION_CAST: return lstOperands.get(1).toJava(indent, tracer).enclose("(", ")").append(wrapOperandString(lstOperands.get(0), true, indent, tracer)); case FUNCTION_ARRAY_LENGTH: Exprent arr = lstOperands.get(0); if (arr.getExprType().arrayDim == 0) { VarType objArr = VarType.VARTYPE_OBJECT.resizeArrayDim(1); // type family does not change res.enclose("((" + ExprProcessor.getCastTypeName(objArr) + ")", ")"); return res.append(".length"); case FUNCTION_IIF: return wrapOperandString(lstOperands.get(0), true, indent, tracer) .append(" ? ") .append(wrapOperandString(lstOperands.get(1), true, indent, tracer)) .append(" : ") .append(wrapOperandString(lstOperands.get(2), true, indent, tracer)); case FUNCTION_IPP: return wrapOperandString(lstOperands.get(0), true, indent, tracer).append("++");
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buffer = new TextBuffer(); tracer.addMapping(bytecode); if (classDef) { ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(varType.value); new ClassWriter().classToJava(child, buffer, indent, tracer); tracer.incrementCurrentSourceLine(buffer.countLines()); } else { VarVersionPair varVersion = getVarVersionPair(); String name = null; if (processor != null) { name = processor.getVarName(varVersion); } if (definition) { if (processor != null && processor.getVarFinal(varVersion) == VarTypeProcessor.VAR_EXPLICIT_FINAL) { buffer.append("final "); } appendDefinitionType(buffer); buffer.append(" "); } buffer.append(name == null ? ("var" + index + (this.version == 0 ? "" : "_" + this.version)) : name); } return buffer; }
TextBuffer buffer = new TextBuffer("return"); buffer.append(' '); ExprProcessor.getCastedExprent(value, retType, buffer, indent, false, tracer); TextBuffer buffer = new TextBuffer("throw "); ExprProcessor.getCastedExprent(value, exType, buffer, indent, false, tracer); return buffer; return value.toJava(indent, tracer).prepend("throw ");
return new TextBuffer(ExprProcessor.getCastTypeName(constType)); return new TextBuffer(Boolean.toString((Integer)value != 0)); return new TextBuffer(ret).enclose("'", "'"); return new TextBuffer(value.toString()); return new TextBuffer(value.toString()).append('L'); return new TextBuffer("0.0F / 0.0"); return new TextBuffer("1.0F / 0.0"); return new TextBuffer("-1.0F / 0.0"); return new TextBuffer(value.toString()).append('F'); return new TextBuffer("0.0D / 0.0"); return new TextBuffer("1.0D / 0.0"); return new TextBuffer("-1.0D / 0.0"); return new TextBuffer(value.toString()).append('D'); return new TextBuffer("null"); return new TextBuffer(convertStringToJava(value.toString(), ascii)).enclose("\"", "\"");
public TextBuffer appendIndent(int length) { while (length-- > 0) { append(myIndent); } return this; }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buffer = new TextBuffer(); buffer.append("assert "); tracer.addMapping(bytecode); if (parameters.get(0) == null) { buffer.append("false"); } else { buffer.append(parameters.get(0).toJava(indent, tracer)); } if (parameters.size() > 1) { buffer.append(" : "); buffer.append(parameters.get(1).toJava(indent, tracer)); } return buffer; } }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { tracer.addMapping(bytecode); if (monType == MONITOR_ENTER) { return value.toJava(indent, tracer).enclose("synchronized(", ")"); } else { return new TextBuffer(); } }