use of java.lang.reflect.InvocationTargetException in project atlas by alibaba.
the class ExternalComponentIntentResolver method addComponent.
/**
* 将Activity信息添加入索引表
* @param activityObj android.content.pm.PackageParser.Activity信息
*/
public final void addComponent(Object activityObj) {
//反射获取component变量
ComponentName component = null;
try {
component = (ComponentName) AtlasHacks.PackageParser$Component_getComponentName.invoke(activityObj);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//加入componnt表
if (component != null) {
mComponents.put(component, activityObj);
}
ArrayList<?> intents = (ArrayList<?>) AtlasHacks.PackageParser$Activity_intents.get(activityObj);
int NI = intents.size();
for (int j = 0; j < NI; j++) {
addFilter((IntentFilter) intents.get(j));
}
}
use of java.lang.reflect.InvocationTargetException in project atlas by alibaba.
the class MtlTaskFactoryImpl method createTask.
@Override
public Task createTask(VariantContext variantContext, BaseVariantOutputData vod, Class<? extends MtlBaseTaskAction> baseTaskAction) {
if (null == baseTaskAction) {
return null;
}
try {
MtlBaseTaskAction mtlBaseTaskAction = getConstructor(baseTaskAction, variantContext.getClass()).newInstance(variantContext, vod);
Task task = variantContext.getProject().getTasks().create(mtlBaseTaskAction.getName(), mtlBaseTaskAction.getType());
mtlBaseTaskAction.execute(task);
return task;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ParanoidAndroid.
the class DelegateClassAdapterTest method testNoOp.
/**
* Tests that a class not being modified still works.
*/
@SuppressWarnings("unchecked")
@Test
public void testNoOp() throws Throwable {
// create an instance of the class that will be modified
// (load the class in a distinct class loader so that we can trash its definition later)
ClassLoader cl1 = new ClassLoader(this.getClass().getClassLoader()) {
};
Class<ClassWithNative> clazz1 = (Class<ClassWithNative>) cl1.loadClass(NATIVE_CLASS_NAME);
ClassWithNative instance1 = clazz1.newInstance();
assertEquals(42, instance1.add(20, 22));
try {
instance1.callNativeInstance(10, 3.1415, new Object[0]);
fail("Test should have failed to invoke callTheNativeMethod [1]");
} catch (UnsatisfiedLinkError e) {
// This is expected to fail since the native method is not implemented.
}
// Now process it but tell the delegate to not modify any method
ClassWriter cw = new ClassWriter(0);
HashSet<String> delegateMethods = new HashSet<String>();
String internalClassName = NATIVE_CLASS_NAME.replace('.', '/');
DelegateClassAdapter cv = new DelegateClassAdapter(mLog, cw, internalClassName, delegateMethods);
ClassReader cr = new ClassReader(NATIVE_CLASS_NAME);
cr.accept(cv, 0);
// Load the generated class in a different class loader and try it again
ClassLoader2 cl2 = null;
try {
cl2 = new ClassLoader2() {
@Override
public void testModifiedInstance() throws Exception {
Class<?> clazz2 = loadClass(NATIVE_CLASS_NAME);
Object i2 = clazz2.newInstance();
assertNotNull(i2);
assertEquals(42, callAdd(i2, 20, 22));
try {
callCallNativeInstance(i2, 10, 3.1415, new Object[0]);
fail("Test should have failed to invoke callTheNativeMethod [2]");
} catch (InvocationTargetException e) {
// This is expected to fail since the native method has NOT been
// overridden here.
assertEquals(UnsatisfiedLinkError.class, e.getCause().getClass());
}
// 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();
assertEquals(0, a.length);
}
};
cl2.add(NATIVE_CLASS_NAME, cw);
cl2.testModifiedInstance();
} catch (Throwable t) {
throw dumpGeneratedClass(t, cl2);
}
}
use of java.lang.reflect.InvocationTargetException in project RoboBinding by RoboBinding.
the class BeanCursor method getColumnValue.
private Object getColumnValue(int column) {
Preconditions.checkArgument(column < getNumColumns(), "column '" + column + "' is out of bound");
PropertyDescriptor descriptor = mapColumnToPropertyDescriptor(column);
try {
return descriptor.getReadMethod().invoke(getBean(), new Object[0]);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of java.lang.reflect.InvocationTargetException in project RoboBinding by RoboBinding.
the class PresentationModelObjectLoader method load.
public AbstractPresentationModelObject load(Object presentationModel) {
if (presentationModel instanceof HasPresentationModelChangeSupport) {
Preconditions.checkNotNull(((HasPresentationModelChangeSupport) presentationModel).getPresentationModelChangeSupport(), "The PresentationModelChangeSupport from presentationModel.getPresentationModelChangeSupport() must not be null");
}
String presentationModelObjectClassName = getObjectClassName(presentationModel.getClass().getName());
Class<?> presentationModelObjectType;
try {
presentationModelObjectType = Class.forName(presentationModelObjectClassName);
} catch (ClassNotFoundException e) {
throw new RuntimeException(MessageFormat.format("The source code for ''{0}'' is not generated. Is Java annotation processing(source code generation) correctly configured?", presentationModelObjectClassName));
}
try {
return (AbstractPresentationModelObject) ConstructorUtils.invokeConstructor(presentationModelObjectType, presentationModel);
} catch (NoSuchMethodException e) {
throw new Bug("This is a bug of constructor code generation", e);
} catch (IllegalAccessException e) {
throw new Bug("This is a bug of constructor code generation", e);
} catch (InvocationTargetException e) {
throw new Bug("This is a bug of constructor code generation", e);
} catch (InstantiationException e) {
throw new Bug("This is a bug of constructor code generation", e);
}
}
Aggregations