Fix LayoutLib Create tests.
Change-Id: Ica3efe417d54da7dc74b21d28215199d37600744
This commit is contained in:
@@ -97,7 +97,7 @@ public abstract class AbstractClassAdapter extends ClassVisitor {
|
||||
if (type.getSort() == Type.OBJECT) {
|
||||
String in = type.getInternalName();
|
||||
String newIn = renameInternalType(in);
|
||||
if (newIn != in) {
|
||||
if (!newIn.equals(in)) {
|
||||
return Type.getType("L" + newIn + ";");
|
||||
}
|
||||
} else if (type.getSort() == Type.ARRAY) {
|
||||
|
||||
@@ -316,9 +316,7 @@ public class DependencyFinder {
|
||||
|
||||
// Add it to the dependency set for the currently visited class, as needed.
|
||||
assert mCurrentDepSet != null;
|
||||
if (mCurrentDepSet != null) {
|
||||
mCurrentDepSet.add(className);
|
||||
}
|
||||
mCurrentDepSet.add(className);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Main {
|
||||
String[] osDestJar = { null };
|
||||
|
||||
if (!processArgs(log, args, osJarPath, osDestJar)) {
|
||||
log.error("Usage: layoutlib_create [-v] [-p] output.jar input.jar ...");
|
||||
log.error("Usage: layoutlib_create [-v] output.jar input.jar ...");
|
||||
log.error("Usage: layoutlib_create [-v] [--list-deps|--missing-deps] input.jar ...");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public final class OverrideMethod {
|
||||
* Sets the default listener for all methods not specifically handled.
|
||||
* Null means to do nothing.
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration") // Used by Bridge by reflection for debug purposes.
|
||||
public static void setDefaultListener(MethodListener listener) {
|
||||
sDefaultListener = listener;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class RenameClassAdapter extends AbstractClassAdapter {
|
||||
return mNewName;
|
||||
}
|
||||
|
||||
if (mOldBase != mOldName && type.equals(mOldBase)) {
|
||||
if (!mOldBase.equals(mOldName) && type.equals(mOldBase)) {
|
||||
return mNewBase;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import org.objectweb.asm.Type;
|
||||
*/
|
||||
class StubMethodAdapter extends MethodVisitor {
|
||||
|
||||
private static String CONSTRUCTOR = "<init>";
|
||||
private static String CLASS_INIT = "<clinit>";
|
||||
private static final String CONSTRUCTOR = "<init>";
|
||||
private static final String CLASS_INIT = "<clinit>";
|
||||
|
||||
/** The parent method writer */
|
||||
private MethodVisitor mParentVisitor;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.tools.layoutlib.create;
|
||||
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -136,13 +135,6 @@ class TransformClassAdapter extends ClassVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
/* Visits a field. Makes it public. */
|
||||
@Override
|
||||
public FieldVisitor visitField(int access, String name, String desc, String signature,
|
||||
Object value) {
|
||||
return super.visitField(access, name, desc, signature, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the return {@link Type} of this descriptor.
|
||||
*/
|
||||
|
||||
@@ -116,9 +116,16 @@ public class DelegateClassAdapterTest {
|
||||
|
||||
// Check that the native method does NOT have the new annotation
|
||||
Method[] m = clazz2.getDeclaredMethods();
|
||||
assertEquals("native_instance", m[2].getName());
|
||||
assertTrue(Modifier.isNative(m[2].getModifiers()));
|
||||
Annotation[] a = m[2].getAnnotations();
|
||||
Method nativeInstanceMethod = null;
|
||||
for (Method method : m) {
|
||||
if ("native_instance".equals(method.getName())) {
|
||||
nativeInstanceMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(nativeInstanceMethod);
|
||||
assertTrue(Modifier.isNative(nativeInstanceMethod.getModifiers()));
|
||||
Annotation[] a = nativeInstanceMethod.getAnnotations();
|
||||
assertEquals(0, a.length);
|
||||
}
|
||||
};
|
||||
@@ -184,9 +191,16 @@ public class DelegateClassAdapterTest {
|
||||
|
||||
// Check that the native method now has the new annotation and is not native
|
||||
Method[] m = clazz2.getDeclaredMethods();
|
||||
assertEquals("native_instance", m[2].getName());
|
||||
assertFalse(Modifier.isNative(m[2].getModifiers()));
|
||||
Annotation[] a = m[2].getAnnotations();
|
||||
Method nativeInstanceMethod = null;
|
||||
for (Method method : m) {
|
||||
if ("native_instance".equals(method.getName())) {
|
||||
nativeInstanceMethod = method;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(nativeInstanceMethod);
|
||||
assertFalse(Modifier.isNative(nativeInstanceMethod.getModifiers()));
|
||||
Annotation[] a = nativeInstanceMethod.getAnnotations();
|
||||
assertEquals("LayoutlibDelegate", a[0].annotationType().getSimpleName());
|
||||
}
|
||||
};
|
||||
@@ -237,13 +251,8 @@ public class DelegateClassAdapterTest {
|
||||
assertEquals(4+10+20, callGet(o2, 10, 20));
|
||||
assertEquals(1+10+20, callGet_Original(o2, 10, 20));
|
||||
|
||||
// The original Outer has a private method that is
|
||||
// delegated. We should be able to call both the delegate
|
||||
// and the original (which is now public).
|
||||
assertEquals("outerPrivateMethod",
|
||||
callMethod(o2, "privateMethod_Original", false /*makePublic*/));
|
||||
|
||||
// The original method is private, so by default we can't access it
|
||||
// The original Outer has a private method,
|
||||
// so by default we can't access it.
|
||||
boolean gotIllegalAccessException = false;
|
||||
try {
|
||||
callMethod(o2, "privateMethod", false /*makePublic*/);
|
||||
@@ -251,9 +260,18 @@ public class DelegateClassAdapterTest {
|
||||
gotIllegalAccessException = true;
|
||||
}
|
||||
assertTrue(gotIllegalAccessException);
|
||||
// Try again, but now making it accessible
|
||||
assertEquals("outerPrivate_Delegate",
|
||||
callMethod(o2, "privateMethod", true /*makePublic*/));
|
||||
|
||||
// The private method from original Outer has been
|
||||
// delegated. The delegate generated should have the
|
||||
// same access.
|
||||
gotIllegalAccessException = false;
|
||||
try {
|
||||
assertEquals("outerPrivateMethod",
|
||||
callMethod(o2, "privateMethod_Original", false /*makePublic*/));
|
||||
} catch (IllegalAccessException e) {
|
||||
gotIllegalAccessException = true;
|
||||
}
|
||||
assertTrue(gotIllegalAccessException);
|
||||
|
||||
// Check the inner class. Since it's not a static inner class, we need
|
||||
// to use the hidden constructor that takes the outer class as first parameter.
|
||||
|
||||
Reference in New Issue
Block a user