use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class MethodGen method addMethodArguments.
private void addMethodArguments(CodeWriter argsCode, List<RegisterArg> args) {
MethodParameters paramsAnnotation = mth.get(AType.ANNOTATION_MTH_PARAMETERS);
int i = 0;
for (Iterator<RegisterArg> it = args.iterator(); it.hasNext(); ) {
RegisterArg arg = it.next();
// add argument annotation
if (paramsAnnotation != null) {
annotationGen.addForParameter(argsCode, paramsAnnotation, i);
}
SSAVar argSVar = arg.getSVar();
if (argSVar != null && argSVar.contains(AFlag.FINAL)) {
argsCode.add("final ");
}
if (!it.hasNext() && mth.getAccessFlags().isVarArgs()) {
// change last array argument to varargs
ArgType type = arg.getType();
if (type.isArray()) {
ArgType elType = type.getArrayElement();
classGen.useType(argsCode, elType);
argsCode.add("...");
} else {
LOG.warn(ErrorsCounter.formatErrorMsg(mth, "Last argument in varargs method not array"));
classGen.useType(argsCode, arg.getType());
}
} else {
classGen.useType(argsCode, arg.getType());
}
argsCode.add(' ');
argsCode.add(nameGen.assignArg(arg));
i++;
if (it.hasNext()) {
argsCode.add(", ");
}
}
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class ClassGen method useClass.
public void useClass(CodeWriter code, ArgType type) {
useClass(code, ClassInfo.extCls(cls.dex(), type));
ArgType[] generics = type.getGenericTypes();
if (generics != null) {
code.add('<');
int len = generics.length;
for (int i = 0; i < len; i++) {
if (i != 0) {
code.add(", ");
}
ArgType gt = generics[i];
ArgType wt = gt.getWildcardType();
if (wt != null) {
code.add('?');
int bounds = gt.getWildcardBounds();
if (bounds != 0) {
code.add(bounds == -1 ? " super " : " extends ");
useType(code, wt);
}
} else {
useType(code, gt);
}
}
code.add('>');
}
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class ClassGen method addClassDeclaration.
public void addClassDeclaration(CodeWriter clsCode) {
AccessInfo af = cls.getAccessFlags();
if (af.isInterface()) {
af = af.remove(AccessFlags.ACC_ABSTRACT).remove(AccessFlags.ACC_STATIC);
} else if (af.isEnum()) {
af = af.remove(AccessFlags.ACC_FINAL).remove(AccessFlags.ACC_ABSTRACT).remove(AccessFlags.ACC_STATIC);
}
// 'static' and 'private' modifier not allowed for top classes (not inner)
if (!cls.getAlias().isInner()) {
af = af.remove(AccessFlags.ACC_STATIC).remove(AccessFlags.ACC_PRIVATE);
}
annotationGen.addForClass(clsCode);
insertSourceFileInfo(clsCode, cls);
insertRenameInfo(clsCode, cls);
clsCode.startLine(af.makeString());
if (af.isInterface()) {
if (af.isAnnotation()) {
clsCode.add('@');
}
clsCode.add("interface ");
} else if (af.isEnum()) {
clsCode.add("enum ");
} else {
clsCode.add("class ");
}
clsCode.attachDefinition(cls);
clsCode.add(cls.getShortName());
addGenericMap(clsCode, cls.getGenericMap());
clsCode.add(' ');
ArgType sup = cls.getSuperClass();
if (sup != null && !sup.equals(ArgType.OBJECT) && !sup.getObject().equals(ArgType.ENUM.getObject())) {
clsCode.add("extends ");
useClass(clsCode, sup);
clsCode.add(' ');
}
if (!cls.getInterfaces().isEmpty() && !af.isAnnotation()) {
if (cls.getAccessFlags().isInterface()) {
clsCode.add("extends ");
} else {
clsCode.add("implements ");
}
for (Iterator<ArgType> it = cls.getInterfaces().iterator(); it.hasNext(); ) {
ArgType interf = it.next();
useClass(clsCode, interf);
if (it.hasNext()) {
clsCode.add(", ");
}
}
if (!cls.getInterfaces().isEmpty()) {
clsCode.add(' ');
}
}
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class ClassGen method addGenericMap.
public boolean addGenericMap(CodeWriter code, Map<ArgType, List<ArgType>> gmap) {
if (gmap == null || gmap.isEmpty()) {
return false;
}
code.add('<');
int i = 0;
for (Entry<ArgType, List<ArgType>> e : gmap.entrySet()) {
ArgType type = e.getKey();
List<ArgType> list = e.getValue();
if (i != 0) {
code.add(", ");
}
if (type.isGenericType()) {
code.add(type.getObject());
} else {
useClass(code, type);
}
if (list != null && !list.isEmpty()) {
code.add(" extends ");
for (Iterator<ArgType> it = list.iterator(); it.hasNext(); ) {
ArgType g = it.next();
if (g.isGenericType()) {
code.add(g.getObject());
} else {
useClass(code, g);
}
if (it.hasNext()) {
code.add(" & ");
}
}
}
i++;
}
code.add('>');
return true;
}
use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.
the class ClsSet method makeParentsArray.
public static NClass[] makeParentsArray(ClassNode cls, Map<String, NClass> names) {
List<NClass> parents = new ArrayList<NClass>(1 + cls.getInterfaces().size());
ArgType superClass = cls.getSuperClass();
if (superClass != null) {
NClass c = getCls(superClass.getObject(), names);
if (c != null) {
parents.add(c);
}
}
for (ArgType iface : cls.getInterfaces()) {
NClass c = getCls(iface.getObject(), names);
if (c != null) {
parents.add(c);
}
}
return parents.toArray(new NClass[parents.size()]);
}
Aggregations