Commit 1d81cab4 authored by Skylot's avatar Skylot

core: change anonymous class marking

parent 2815cef1
......@@ -18,7 +18,7 @@ public class Consts {
public static final String DALVIK_ANNOTATION_DEFAULT = "dalvik.annotation.AnnotationDefault";
public static final String DEFAULT_PACKAGE_NAME = "defpackage";
public static final String ANONYMOUS_CLASS_PREFIX = "AnonymousClass_";
public static final String ANONYMOUS_CLASS_PREFIX = "AnonymousClass";
public static final String MTH_TOSTRING_SIGNATURE = "toString()Ljava/lang/String;";
}
......@@ -231,7 +231,7 @@ public class ClassGen {
private void addInnerClasses(CodeWriter code, ClassNode cls) throws CodegenException {
for (ClassNode innerCls : cls.getInnerClasses()) {
if (innerCls.contains(AFlag.DONT_GENERATE)
|| innerCls.isAnonymous()) {
|| innerCls.contains(AFlag.ANONYMOUS_CLASS)) {
continue;
}
ClassGen inClGen = new ClassGen(innerCls, getParentGen());
......@@ -243,7 +243,7 @@ public class ClassGen {
private boolean isInnerClassesPresents() {
for (ClassNode innerCls : cls.getInnerClasses()) {
if (!innerCls.isAnonymous()) {
if (!innerCls.contains(AFlag.ANONYMOUS_CLASS)) {
return true;
}
}
......
......@@ -530,7 +530,7 @@ public class InsnGen {
private void makeConstructor(ConstructorInsn insn, CodeWriter code)
throws CodegenException {
ClassNode cls = mth.dex().resolveClass(insn.getClassType());
if (cls != null && cls.isAnonymous() && !fallback) {
if (cls != null && cls.contains(AFlag.ANONYMOUS_CLASS) && !fallback) {
// anonymous class construction
ArgType parent;
if (cls.getInterfaces().size() == 1) {
......
......@@ -23,6 +23,7 @@ public enum AFlag {
SKIP_FIRST_ARG,
ANONYMOUS_CONSTRUCTOR,
ANONYMOUS_CLASS,
ELSE_IF_CHAIN,
......
......@@ -138,6 +138,14 @@ public final class ClassInfo {
return parentClass;
}
public ClassInfo getTopParentClass() {
if (parentClass != null) {
ClassInfo topCls = parentClass.getTopParentClass();
return topCls != null ? topCls : parentClass;
}
return null;
}
public boolean isInner() {
return parentClass != null;
}
......
......@@ -240,6 +240,10 @@ public class ClassNode extends LineAttrNode implements ILoadable {
&& fileName.endsWith("$" + name)) {
return;
}
ClassInfo parentClass = clsInfo.getTopParentClass();
if (parentClass != null && fileName.equals(parentClass.getShortName())) {
return;
}
}
this.addAttr(new SourceFileAttr(fileName));
LOG.debug("Class '{}' compiled from '{}'", this, fileName);
......@@ -434,7 +438,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
public boolean isAnonymous() {
return clsInfo.isInner()
&& clsInfo.getShortName().startsWith(Consts.ANONYMOUS_CLASS_PREFIX)
&& clsInfo.getAlias().getShortName().startsWith(Consts.ANONYMOUS_CLASS_PREFIX)
&& getDefaultConstructor() != null;
}
......
......@@ -40,9 +40,17 @@ public class ClassModifier extends AbstractVisitor {
removeEmptyMethods(cls);
checkFieldsInit(cls);
markAnonymousClass(cls);
return false;
}
private void markAnonymousClass(ClassNode cls) {
if (cls.isAnonymous()) {
cls.add(AFlag.ANONYMOUS_CLASS);
}
}
private static void removeSyntheticFields(ClassNode cls) {
if (!cls.getClassInfo().isInner() || cls.getAccessFlags().isStatic()) {
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment