public TextBuffer appendIndent(int length) { while (length-- > 0) { append(myIndent); } return this; }
private static void appendDeprecation(TextBuffer buffer, int indent) { buffer.appendIndent(indent).append("/** @deprecated */").appendLineSeparator(); }
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); }
private static void appendModifiers(TextBuffer buffer, int flags, int allowed, boolean isInterface, int excluded) { flags &= allowed; if (!isInterface) excluded = 0; for (int modifier : MODIFIERS.keySet()) { if ((flags & modifier) == modifier && (modifier & excluded) == 0) { buffer.append(MODIFIERS.get(modifier)).append(' '); } } }
@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; } }
private static void appendTypeAnnotations(TextBuffer buffer, int indent, StructMember mb, int targetType, int index, Set<String> filter) { for (StructGeneralAttribute.Key<?> key : TYPE_ANNOTATION_ATTRIBUTES) { StructTypeAnnotationAttribute attribute = (StructTypeAnnotationAttribute)mb.getAttribute(key); if (attribute != null) { for (TypeAnnotation annotation : attribute.getAnnotations()) { if (annotation.isTopLevel() && annotation.getTargetType() == targetType && (index < 0 || annotation.getIndex() == index)) { String text = annotation.getAnnotation().toJava(indent, BytecodeMappingTracer.DUMMY).toString(); if (!filter.contains(text)) { buffer.append(text); if (indent < 0) { buffer.append(' '); } else { buffer.appendLineSeparator(); } } } } } } }
public static void appendTypeParameters(TextBuffer buffer, List<String> parameters, List<? extends List<GenericType>> bounds) { buffer.append('<'); for (int i = 0; i < parameters.size(); i++) { if (i > 0) { buffer.append(", "); } buffer.append(parameters.get(i)); List<GenericType> parameterBounds = bounds.get(i); if (parameterBounds.size() > 1 || !"java/lang/Object".equals(parameterBounds.get(0).value)) { buffer.append(" extends "); buffer.append(GenericMain.getGenericCastTypeName(parameterBounds.get(0))); for (int j = 1; j < parameterBounds.size(); j++) { buffer.append(" & "); buffer.append(GenericMain.getGenericCastTypeName(parameterBounds.get(j))); } } } buffer.append('>'); } }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); buf.append(first.toJava(indent, tracer)); if (isLabeled()) { buf.appendIndent(indent).append("label").append(this.id.toString()).append(":").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } buf.appendIndent(indent).append(headexprent.get(0).toJava(indent, tracer)).append(" {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); buf.append(ExprProcessor.jmpWrapper(body, indent + 1, true, tracer)); buf.appendIndent(indent).append("}").appendLineSeparator(); mapMonitorExitInstr(tracer); tracer.incrementCurrentSourceLine(); return buf; }
public TextBuffer enclose(String left, String right) { prepend(left); append(right); return this; }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); boolean islabeled = isLabeled(); buf.append(ExprProcessor.listToJava(varDefinitions, indent, tracer)); if (islabeled) { buf.appendIndent(indent++).append("label").append(this.id.toString()).append(": {").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } boolean notempty = false; for (int i = 0; i < stats.size(); i++) { Statement st = stats.get(i); if (i > 0 && notempty) { buf.appendLineSeparator(); tracer.incrementCurrentSourceLine(); } TextBuffer str = ExprProcessor.jmpWrapper(st, indent, false, tracer); buf.append(str); notempty = !str.containsOnlyWhitespaces(); } if (islabeled) { buf.appendIndent(indent-1).append("}").appendLineSeparator(); tracer.incrementCurrentSourceLine(); } return buf; }
@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; } }
public static void writeQualifiedSuper(TextBuffer buf, String qualifier) { ClassesProcessor.ClassNode classNode = (ClassesProcessor.ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE); if (!qualifier.equals(classNode.classStruct.qualifiedName)) { buf.append(DecompilerContext.getImportCollector().getShortName(ExprProcessor.buildJavaClassName(qualifier))).append('.'); } buf.append("super"); }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer tb = ExprProcessor.listToJava(varDefinitions, indent, tracer); tb.append(ExprProcessor.listToJava(exprents, indent, tracer)); return tb; }
private static void appendParameterAnnotations(TextBuffer buffer, StructMethod mt, int param) { Set<String> filter = new HashSet<>(); for (StructGeneralAttribute.Key<?> key : PARAMETER_ANNOTATION_ATTRIBUTES) { StructAnnotationParameterAttribute attribute = (StructAnnotationParameterAttribute)mt.getAttribute(key); if (attribute != null) { List<List<AnnotationExprent>> annotations = attribute.getParamAnnotations(); if (param < annotations.size()) { for (AnnotationExprent annotation : annotations.get(param)) { String text = annotation.toJava(-1, BytecodeMappingTracer.DUMMY).toString(); filter.add(text); buffer.append(text).append(' '); } } } } appendTypeAnnotations(buffer, -1, mt, TypeAnnotation.METHOD_PARAMETER, param, filter); }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { return ExprProcessor.listToJava(varDefinitions, indent, tracer).append(first.toJava(indent, tracer)); }
@Override public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) { TextBuffer res = array.toJava(indent, tracer); if (array.getPrecedence() > getPrecedence()) { // array precedence equals 0 res.enclose("(", ")"); } VarType arrType = array.getExprType(); if (arrType.arrayDim == 0) { VarType objArr = VarType.VARTYPE_OBJECT.resizeArrayDim(1); // type family does not change res.enclose("((" + ExprProcessor.getCastTypeName(objArr) + ")", ")"); } tracer.addMapping(bytecode); return res.append('[').append(index.toJava(indent, tracer)).append(']'); }
@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; } } }
@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; }