private static void AppendClassName(GenericType type, StringBuilder buffer) { List <GenericType> enclosingClasses = type.GetEnclosingClasses(); if ((enclosingClasses.Count == 0)) { string name = type.value.Replace('/', '.'); buffer.Append(DecompilerContext.GetImportCollector().GetShortName(name)); } else { foreach (GenericType tp in enclosingClasses) { if (buffer.Length == 0) { buffer.Append(DecompilerContext.GetImportCollector().GetShortName(tp.value.Replace ('/', '.'))); } else { buffer.Append(tp.value); } AppendTypeArguments(tp, buffer); buffer.Append('.'); } buffer.Append(type.value); } AppendTypeArguments(type, 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"); }
public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buffer = new TextBuffer(); buffer.AppendIndent(indent); buffer.Append('@'); buffer.Append(DecompilerContext.GetImportCollector().GetShortName(ExprProcessor.BuildJavaClassName (className))); int type = GetAnnotationType(); if (type != Annotation_Marker) { buffer.Append('('); bool oneLiner = type == Annotation_Single_Element || indent < 0; for (int i = 0; i < parNames.Count; i++) { if (!oneLiner) { buffer.AppendLineSeparator().AppendIndent(indent + 1); } if (type != Annotation_Single_Element) { buffer.Append(parNames[i]); buffer.Append(" = "); } buffer.Append(parValues[i].ToJava(0, tracer)); if (i < parNames.Count - 1) { buffer.Append(','); } } if (!oneLiner) { buffer.AppendLineSeparator().AppendIndent(indent); } buffer.Append(')'); } return(buffer); }
public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); if (isStatic__) { ClassesProcessor.ClassNode node = (ClassesProcessor.ClassNode)DecompilerContext.GetProperty (DecompilerContext.Current_Class_Node); if (node == null || !classname.Equals(node.classStruct.qualifiedName) || IsAmbiguous ()) { buf.Append(DecompilerContext.GetImportCollector().GetShortNameInClassContext(ExprProcessor .BuildJavaClassName(classname))); buf.Append("."); } } else { string super_qualifier = null; if (instance != null && instance.type == Exprent.Exprent_Var) { VarExprent instVar = (VarExprent)instance; VarVersionPair pair = new VarVersionPair(instVar); MethodWrapper currentMethod = (MethodWrapper)DecompilerContext.GetProperty(DecompilerContext .Current_Method_Wrapper); if (currentMethod != null) { // FIXME: remove string this_classname = currentMethod.varproc.GetThisVars().GetOrNull(pair); if (this_classname != null) { if (!classname.Equals(this_classname)) { // TODO: direct comparison to the super class? super_qualifier = this_classname; } } } } if (super_qualifier != null) { TextUtil.WriteQualifiedSuper(buf, super_qualifier); } else { TextBuffer buff = new TextBuffer(); bool casted = ExprProcessor.GetCastedExprent(instance, new VarType(ICodeConstants .Type_Object, 0, classname), buff, indent, true, tracer); string res = buff.ToString(); if (casted || instance.GetPrecedence() > GetPrecedence()) { res = "(" + res + ")"; } buf.Append(res); } if (buf.ToString().Equals(VarExprent.Var_Nameless_Enclosure)) { // FIXME: workaround for field access of an anonymous enclosing class. Find a better way. buf.SetLength(0); } else { buf.Append("."); } } buf.Append(name); tracer.AddMapping(bytecode); return(buf); }
public override TextBuffer ToJava(int indent, BytecodeMappingTracer tracer) { TextBuffer buf = new TextBuffer(); string super_qualifier = null; bool isInstanceThis = false; tracer.AddMapping(bytecode); if (instance is InvocationExprent) { ((InvocationExprent)instance).MarkUsingBoxingResult(); } if (isStatic__) { if (IsBoxingCall() && canIgnoreBoxing) { // process general "boxing" calls, e.g. 'Object[] data = { true }' or 'Byte b = 123' // here 'byte' and 'short' values do not need an explicit narrowing type cast ExprProcessor.GetCastedExprent(lstParameters[0], descriptor.@params[0], buf, indent , false, false, false, false, tracer); return(buf); } ClassesProcessor.ClassNode node = (ClassesProcessor.ClassNode)DecompilerContext.GetProperty (DecompilerContext.Current_Class_Node); if (node == null || !classname.Equals(node.classStruct.qualifiedName)) { buf.Append(DecompilerContext.GetImportCollector().GetShortNameInClassContext(ExprProcessor .BuildJavaClassName(classname))); } } else { if (instance != null && instance.type == Exprent.Exprent_Var) { VarExprent instVar = (VarExprent)instance; VarVersionPair varPair = new VarVersionPair(instVar); VarProcessor varProc = instVar.GetProcessor(); if (varProc == null) { MethodWrapper currentMethod = (MethodWrapper)DecompilerContext.GetProperty(DecompilerContext .Current_Method_Wrapper); if (currentMethod != null) { varProc = currentMethod.varproc; } } string this_classname = null; if (varProc != null) { this_classname = varProc.GetThisVars().GetOrNull(varPair); } if (this_classname != null) { isInstanceThis = true; if (invocationTyp == Invoke_Special) { if (!classname.Equals(this_classname)) { // TODO: direct comparison to the super class? StructClass cl = DecompilerContext.GetStructContext().GetClass(classname); bool isInterface = cl != null && cl.HasModifier(ICodeConstants.Acc_Interface); super_qualifier = !isInterface ? this_classname : classname; } } } } if (functype == Typ_General) { if (super_qualifier != null) { TextUtil.WriteQualifiedSuper(buf, super_qualifier); } else if (instance != null) { TextBuffer res = instance.ToJava(indent, tracer); if (IsUnboxingCall()) { // we don't print the unboxing call - no need to bother with the instance wrapping / casting buf.Append(res); return(buf); } VarType rightType = instance.GetExprType(); VarType leftType = new VarType(ICodeConstants.Type_Object, 0, classname); if (rightType.Equals(VarType.Vartype_Object) && !leftType.Equals(rightType)) { buf.Append("((").Append(ExprProcessor.GetCastTypeName(leftType)).Append(")"); if (instance.GetPrecedence() >= FunctionExprent.GetPrecedence(FunctionExprent.Function_Cast )) { res.Enclose("(", ")"); } buf.Append(res).Append(")"); } else if (instance.GetPrecedence() > GetPrecedence()) { buf.Append("(").Append(res).Append(")"); } else { buf.Append(res); } } } } switch (functype) { case Typ_General: { 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("("); break; } case Typ_Clinit: { throw new Exception("Explicit invocation of " + ICodeConstants.Clinit_Name); } case Typ_Init: { if (super_qualifier != null) { buf.Append("super("); } else if (isInstanceThis) { buf.Append("this("); } else if (instance != null) { buf.Append(instance.ToJava(indent, tracer)).Append(".<init>("); } else { throw new Exception("Unrecognized invocation of " + ICodeConstants.Init_Name); } break; } } List <VarVersionPair> mask = null; bool isEnum = false; if (functype == Typ_Init) { ClassesProcessor.ClassNode newNode = DecompilerContext.GetClassProcessor().GetMapRootClasses ().GetOrNull(classname); if (newNode != null) { mask = ExprUtil.GetSyntheticParametersMask(newNode, stringDescriptor, lstParameters .Count); isEnum = newNode.classStruct.HasModifier(ICodeConstants.Acc_Enum) && DecompilerContext .GetOption(IFernflowerPreferences.Decompile_Enum); } } BitSet setAmbiguousParameters = GetAmbiguousParameters(); // omit 'new Type[] {}' for the last parameter of a vararg method call if (lstParameters.Count == [email protected] && IsVarArgCall()) { Exprent lastParam = lstParameters[lstParameters.Count - 1]; if (lastParam.type == Exprent_New && lastParam.GetExprType().arrayDim >= 1) { ((NewExprent)lastParam).SetVarArgParam(true); } } bool firstParameter = true; int start = isEnum ? 2 : 0; for (int i = start; i < lstParameters.Count; i++) { if (mask == null || mask[i] == null) { TextBuffer buff = new TextBuffer(); bool ambiguous = setAmbiguousParameters.Get(i); // 'byte' and 'short' literals need an explicit narrowing type cast when used as a parameter ExprProcessor.GetCastedExprent(lstParameters[i], descriptor.@params[i], buff, indent , true, ambiguous, true, true, tracer); // the last "new Object[0]" in the vararg call is not printed if (buff.Length() > 0) { if (!firstParameter) { buf.Append(", "); } buf.Append(buff); } firstParameter = false; } } buf.Append(')'); return(buf); }