Search in sources :

Example 61 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project RoboBinding by RoboBinding.

the class ReflectionUtils method tryToInvokeMethod.

@SuppressWarnings("unchecked")
public static <T> T tryToInvokeMethod(Object target, String name, Object... args) {
    final Class<?>[] parameterTypes = ClassUtils.toClass(args);
    Method method = findMethod(target.getClass(), name, parameterTypes);
    if (method != null) {
        makeAccessible(method);
        try {
            return (T) method.invoke(target, args);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 62 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project RoboBinding by RoboBinding.

the class ViewBindingLoader method load.

@SuppressWarnings("unchecked")
public <ViewType> ViewBinding<ViewType> load(CustomViewBinding<ViewType> customViewBinding) {
    String viewBindingClassName = getViewBindingClassName(customViewBinding.getClass().getName());
    Class<?> viewBindingType;
    try {
        viewBindingType = Class.forName(viewBindingClassName);
    } 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?", viewBindingClassName));
    }
    try {
        return (ViewBinding<ViewType>) ConstructorUtils.invokeConstructor(viewBindingType, customViewBinding);
    } 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 : ViewBinding(org.robobinding.viewbinding.ViewBinding) Bug(org.robobinding.Bug) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 63 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project che by eclipse.

the class RenameSupport method perform.

//	/**
//	 * Opens the refactoring dialog for this rename support.
//	 *
//	 * @param parent a shell used as a parent for the refactoring dialog.
//	 * @throws CoreException if an unexpected exception occurs while opening the
//	 * dialog.
//	 *
//	 * @see #openDialog(Shell, boolean)
//	 */
//	public void openDialog(Shell parent) throws CoreException {
//		openDialog(parent, false);
//	}
//
//	/**
//	 * Opens the refactoring dialog for this rename support.
//	 *
//	 * <p>
//	 * This method has to be called from within the UI thread.
//	 * </p>
//	 *
//	 * @param parent a shell used as a parent for the refactoring, preview, or error dialog
//	 * @param showPreviewOnly if <code>true</code>, the dialog skips all user input pages and
//	 * directly shows the preview or error page. Otherwise, shows all pages.
//	 * @return <code>true</code> if the refactoring has been executed successfully,
//	 * <code>false</code> if it has been canceled or if an error has happened during
//	 * initial conditions checking.
//	 *
//	 * @throws CoreException if an error occurred while executing the
//	 * operation.
//	 *
//	 * @see #openDialog(Shell)
//	 * @since 3.3
//	 */
//	public boolean openDialog(Shell parent, boolean showPreviewOnly) throws CoreException {
//		ensureChecked();
//		if (fPreCheckStatus.hasFatalError()) {
//			showInformation(parent, fPreCheckStatus);
//			return false;
//		}
//
//		UserInterfaceStarter starter;
//		if (!showPreviewOnly) {
//			starter = RenameUserInterfaceManager.getDefault().getStarter(fRefactoring);
//		} else {
//			starter = new RenameUserInterfaceStarter();
//			RenameRefactoringWizard wizard = new RenameRefactoringWizard(fRefactoring, fRefactoring.getName(), null, null, null) {
//				@Override
//				protected void addUserInputPages() {
//					// nothing to add
//				}
//			};
//			wizard.setForcePreviewReview(showPreviewOnly);
//			starter.initialize(wizard);
//		}
//		return starter.activate(fRefactoring, parent, getJavaRenameProcessor().getSaveMode());
//	}
//
/**
	 * Executes the rename refactoring without showing a dialog to gather
	 * additional user input (for example the new name of the <tt>IJavaElement</tt>).
	 * Only an error dialog is shown (if necessary) to present the result
	 * of the refactoring's full precondition checking.
	 * <p>
	 * The method has to be called from within the UI thread.
	 * </p>
	 *
	 *
	 * @throws InterruptedException if the operation has been canceled by the
	 * user.
	 * @throws InvocationTargetException if an error occurred while executing the
	 * operation.
	 */
public RefactoringStatus perform() throws InterruptedException, InvocationTargetException {
    try {
        ensureChecked();
        if (fPreCheckStatus.hasFatalError()) {
            return fPreCheckStatus;
        }
        RefactoringExecutionHelper helper = new RefactoringExecutionHelper(fRefactoring, RefactoringCore.getConditionCheckingFailedSeverity(), getJavaRenameProcessor().getSaveMode());
        RefactoringStatus status = helper.perform(true, true);
        fPerformChangeOperation = helper.getfPerformChangeOperation();
        return status;
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : RefactoringExecutionHelper(org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper) CoreException(org.eclipse.core.runtime.CoreException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 64 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ParanoidAndroid.

the class InstrumentationTestCase method runMethod.

private void runMethod(Method runMethod, int tolerance, boolean isRepetitive) throws Throwable {
    Throwable exception = null;
    int runCount = 0;
    do {
        try {
            runMethod.invoke(this, (Object[]) null);
            exception = null;
        } catch (InvocationTargetException e) {
            e.fillInStackTrace();
            exception = e.getTargetException();
        } catch (IllegalAccessException e) {
            e.fillInStackTrace();
            exception = e;
        } finally {
            runCount++;
            // Report current iteration number, if test is repetitive
            if (isRepetitive) {
                Bundle iterations = new Bundle();
                iterations.putInt("currentiterations", runCount);
                getInstrumentation().sendStatus(2, iterations);
            }
        }
    } while ((runCount < tolerance) && (isRepetitive || exception != null));
    if (exception != null) {
        throw exception;
    }
}
Also used : Bundle(android.os.Bundle) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 65 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project android_frameworks_base by ParanoidAndroid.

the class DebugUtils method isObjectSelected.

/**
     * <p>Filters objects against the <code>ANDROID_OBJECT_FILTER</code>
     * environment variable. This environment variable can filter objects
     * based on their class name and attribute values.</p>
     *
     * <p>Here is the syntax for <code>ANDROID_OBJECT_FILTER</code>:</p>
     *
     * <p><code>ClassName@attribute1=value1@attribute2=value2...</code></p>
     *
     * <p>Examples:</p>
     * <ul>
     * <li>Select TextView instances: <code>TextView</code></li>
     * <li>Select TextView instances of text "Loading" and bottom offset of 22:
     * <code>TextView@text=Loading.*@bottom=22</code></li>
     * </ul>
     *
     * <p>The class name and the values are regular expressions.</p>
     *
     * <p>This class is useful for debugging and logging purpose:</p>
     * <pre>
     * if (DEBUG) {
     *   if (DebugUtils.isObjectSelected(childView) && LOGV_ENABLED) {
     *     Log.v(TAG, "Object " + childView + " logged!");
     *   }
     * }
     * </pre>
     *
     * <p><strong>NOTE</strong>: This method is very expensive as it relies
     * heavily on regular expressions and reflection. Calls to this method
     * should always be stripped out of the release binaries and avoided
     * as much as possible in debug mode.</p>
     *
     * @param object any object to match against the ANDROID_OBJECT_FILTER
     *        environement variable
     * @return true if object is selected by the ANDROID_OBJECT_FILTER
     *         environment variable, false otherwise
     */
public static boolean isObjectSelected(Object object) {
    boolean match = false;
    String s = System.getenv("ANDROID_OBJECT_FILTER");
    if (s != null && s.length() > 0) {
        String[] selectors = s.split("@");
        // first selector == class name
        if (object.getClass().getSimpleName().matches(selectors[0])) {
            // check potential attributes
            for (int i = 1; i < selectors.length; i++) {
                String[] pair = selectors[i].split("=");
                Class<?> klass = object.getClass();
                try {
                    Method declaredMethod = null;
                    Class<?> parent = klass;
                    do {
                        declaredMethod = parent.getDeclaredMethod("get" + pair[0].substring(0, 1).toUpperCase() + pair[0].substring(1), (Class[]) null);
                    } while ((parent = klass.getSuperclass()) != null && declaredMethod == null);
                    if (declaredMethod != null) {
                        Object value = declaredMethod.invoke(object, (Object[]) null);
                        match |= (value != null ? value.toString() : "null").matches(pair[1]);
                    }
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return match;
}
Also used : Method(java.lang.reflect.Method) 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