Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java

Issue 11362002: Option to disable syntax highlighter and use mostly semantic highlighter. Tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java
index 3760a44d51fec35042c2385d8d89b815d57968ac..21fac5c498a064c44aa494de5e49f9b71f729460 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/internal/corext/refactoring/util/ReflectionUtils.java
@@ -15,6 +15,7 @@ package com.google.dart.tools.internal.corext.refactoring.util;
import org.eclipse.core.runtime.Assert;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -29,10 +30,52 @@ public class ReflectionUtils {
* @return the name of the {@link Class} for signature.
*/
public static String getClassName(Class<?> clazz) {
+ if (clazz.isArray()) {
+ return getClassName(clazz.getComponentType()) + "[]";
+ }
return clazz.getName();
}
/**
+ * @return the declared {@link Field} with given name, may be private.
+ */
+ public static Field getField(Object target, String name) {
+ Assert.isNotNull(target);
+ Assert.isNotNull(name);
+ Class<?> targetClass = getTargetClass(target);
+ while (targetClass != null) {
+ Field[] declaredFields = targetClass.getDeclaredFields();
+ for (Field field : declaredFields) {
+ if (field.getName().equals(name)) {
+ field.setAccessible(true);
+ return field;
+ }
+ }
+ targetClass = targetClass.getSuperclass();
+ }
+ return null;
+ }
+
+ /**
+ * @return the value of the field with given name, may be even private.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T getFieldObject(Object target, String name) {
+ Assert.isNotNull(target);
+ Assert.isNotNull(name);
+ Field field = getField(target, name);
+ if (field == null) {
+ Class<?> targetClass = getTargetClass(target);
+ throw new IllegalArgumentException(name + " in " + targetClass);
+ }
+ try {
+ return (T) field.get(target);
+ } catch (Throwable e) {
+ throw ExecutionUtils.propagate(e);
+ }
+ }
+
+ /**
* @return the declared {@link Method} with given signature, may be private.
*/
public static Method getMethod(Object target, String signature) {
@@ -75,6 +118,24 @@ public class ReflectionUtils {
}
/**
+ * Sets the new for field with given name.
+ */
+ public static void setField(Object target, String name, Object value) {
+ Assert.isNotNull(target);
+ Assert.isNotNull(name);
+ Field field = getField(target, name);
+ if (field == null) {
+ Class<?> targetClass = getTargetClass(target);
+ throw new IllegalArgumentException(name + " in " + targetClass);
+ }
+ try {
+ field.set(target, value);
+ } catch (Throwable e) {
+ throw ExecutionUtils.propagate(e);
+ }
+ }
+
+ /**
* @return the signature of the given {@link Method}, not JVM signature however, just some
* reasonable signature to write manually.
*/

Powered by Google App Engine
This is Rietveld 408576698