Search in sources :

Example 56 with InvocationTargetException

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));
    }
}
Also used : ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 57 with InvocationTargetException

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;
}
Also used : Task(org.gradle.api.Task) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 58 with InvocationTargetException

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);
    }
}
Also used : ClassWriter(org.objectweb.asm.ClassWriter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClassReader(org.objectweb.asm.ClassReader) OuterClass(com.android.tools.layoutlib.create.dataclass.OuterClass) InnerClass(com.android.tools.layoutlib.create.dataclass.OuterClass.InnerClass) ClassWithNative(com.android.tools.layoutlib.create.dataclass.ClassWithNative) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with InvocationTargetException

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);
    }
}
Also used : PropertyDescriptor(org.robobinding.internal.java_beans.PropertyDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 60 with InvocationTargetException

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);
    }
}
Also used : Bug(org.robobinding.Bug) AbstractPresentationModelObject(org.robobinding.presentationmodel.AbstractPresentationModelObject) HasPresentationModelChangeSupport(org.robobinding.presentationmodel.HasPresentationModelChangeSupport) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)4781 Method (java.lang.reflect.Method)2031 IOException (java.io.IOException)550 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)492 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)407 ArrayList (java.util.ArrayList)402 List (java.util.List)248 CoreException (org.eclipse.core.runtime.CoreException)247 File (java.io.File)238 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)236 Constructor (java.lang.reflect.Constructor)233 Field (java.lang.reflect.Field)220 Test (org.junit.Test)209 Map (java.util.Map)205 HashMap (java.util.HashMap)202 DBException (org.jkiss.dbeaver.DBException)169 IStatus (org.eclipse.core.runtime.IStatus)136 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)97 Arrays (java.util.Arrays)96 Status (org.eclipse.core.runtime.Status)94