Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMariot Chauvin2011-09-22 10:11:21 +0000
committerMariot Chauvin2011-09-22 10:11:21 +0000
commitbebc66fd5a9e4e4ebb957750e33702a9f1dd3117 (patch)
treefbf93f5dcf2c930b7b0b71199a4aa060b71ee9f5
parent0d3c2ab67d2a9574adf5ae687d7cb90ef4b3b1fa (diff)
downloadorg.eclipse.swtbot-bebc66fd5a9e4e4ebb957750e33702a9f1dd3117.tar.gz
org.eclipse.swtbot-bebc66fd5a9e4e4ebb957750e33702a9f1dd3117.tar.xz
org.eclipse.swtbot-bebc66fd5a9e4e4ebb957750e33702a9f1dd3117.zip
Add a static method to retrieve an attribute reflexively. This is
useful if the class field is not accessible.
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
index 768f023d..663f6336 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/utils/SWTUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2011 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
package org.eclipse.swtbot.swt.finder.utils;
import java.io.File;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
@@ -299,6 +300,22 @@ public abstract class SWTUtils {
}
/**
+ * Get the value of an attribute on the object even if the attribute is not accessible.
+ * @param object the object
+ * @param attributeName the attribute name
+ * @return the value the attribute value
+ * @throws SecurityException if the attribute accessibility may not be changed.
+ * @throws NoSuchFieldException if the attribute attributeName does not exist.
+ * @throws IllegalAccessException if the java access control does not allow access.
+ */
+ public static Object getAttribute(final Object object, final String attributeName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+ Field field = object.getClass().getDeclaredField(attributeName);
+ if (!field.isAccessible())
+ field.setAccessible(true);
+ return field.get(object);
+ }
+
+ /**
* This captures a screen shot and saves it to the given file.
*
* @param fileName the filename to save screenshot to.

Back to the top