summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-23 03:25:24 (EDT)
committer sefftinge2009-03-23 03:25:24 (EDT)
commit36304e6c3b12b877d8dd2ba1e51c46c29b52af0d (patch)
treeb4f738fc2f88f1b02ce7e7b3d961d14ad22cee69
parent60c7f9a6466a1c6daba09c58dfdda312e8da5a80 (diff)
downloadorg.eclipse.xtext-36304e6c3b12b877d8dd2ba1e51c46c29b52af0d.zip
org.eclipse.xtext-36304e6c3b12b877d8dd2ba1e51c46c29b52af0d.tar.gz
org.eclipse.xtext-36304e6c3b12b877d8dd2ba1e51c46c29b52af0d.tar.bz2
There is no need to store the previous accessibility state of method objects as they are only handles
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/JavaReflectiveMethodInvoker.java4
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ReflectionTest.java38
2 files changed, 38 insertions, 4 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/JavaReflectiveMethodInvoker.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/JavaReflectiveMethodInvoker.java
index c82b7b7..3d93bbd 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/JavaReflectiveMethodInvoker.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/JavaReflectiveMethodInvoker.java
@@ -71,7 +71,6 @@ public class JavaReflectiveMethodInvoker {
@SuppressWarnings("unchecked")
private final List<ICompletionProposal> invokeMethod(Method method, Object target, Object... args) {
- boolean wasAccessible = method.isAccessible();
try {
method.setAccessible(true);
return (List<ICompletionProposal>) method.invoke(target, args);
@@ -90,9 +89,6 @@ public class JavaReflectiveMethodInvoker {
throw (Error)targetEx;
throw new IllegalStateException("Unexpected exception thrown", targetEx);
}
- finally {
- method.setAccessible(wasAccessible);
- }
}
private boolean equalOrAssignableTypes(Class<?>[] a, Class<?>[] a2) {
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ReflectionTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ReflectionTest.java
new file mode 100644
index 0000000..dc4e675
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/util/ReflectionTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.util;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class ReflectionTest extends TestCase {
+
+ private static class MyClass {
+ @SuppressWarnings("unused")
+ private String getString() {
+ return "string";
+ }
+ }
+
+ public void testGetMethodGivesCopy() throws Exception {
+ Class<MyClass> clazz = MyClass.class;
+ Method declaredMethod = clazz.getDeclaredMethod("getString");
+ assertNotNull("declaredMethod", declaredMethod);
+ assertFalse("isAccessible", declaredMethod.isAccessible());
+ declaredMethod.setAccessible(true);
+ assertTrue("isAccessible", declaredMethod.isAccessible());
+ Method secondMethod = clazz.getDeclaredMethod("getString");
+ assertNotSame(declaredMethod, secondMethod);
+ assertFalse("isAccessible", secondMethod.isAccessible());
+ }
+
+}