Skip to content

Commit 681627d

Browse files
authored
Merge pull request #306 from eclipse-rcptt/merge/master/release/2.8
Merge release/2.8 into master
2 parents 0a6d2d9 + 96df8fc commit 681627d

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

core/org.eclipse.rcptt.util/src/org/eclipse/rcptt/util/ReflectionUtil.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public static Field findField(Class<?> clazz, String name) {
133133
} catch (NoSuchFieldException e) {
134134
// check superclass
135135
}
136+
for (Class<?> clazz1 : clazz.getInterfaces()) {
137+
Field result = findField(clazz1, name);
138+
if (result != null) {
139+
return result;
140+
}
141+
}
136142
return findField(clazz.getSuperclass(), name);
137143
}
138144

@@ -157,6 +163,12 @@ public static Method findMethod(Class<?> clazz, String name,
157163
} catch (NoSuchMethodException e) {
158164
// check superclass
159165
}
166+
for (Class<?> clazz1 : clazz.getInterfaces()) {
167+
Method result = findMethod(clazz1, name);
168+
if (result != null) {
169+
return result;
170+
}
171+
}
160172
return findMethod(clazz.getSuperclass(), name, params);
161173
}
162174

runtime/tesla/org.eclipse.rcptt.tesla.swt/src/org/eclipse/rcptt/tesla/swt/reflection/JavaMembersHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.eclipse.rcptt.tesla.swt.reflection;
1212

1313
import static org.eclipse.rcptt.tesla.core.TeslaFeatures.isProtectedEnabled;
14+
import static java.lang.String.format;
1415
import static java.lang.reflect.Modifier.PROTECTED;
1516
import static java.lang.reflect.Modifier.PUBLIC;
1617
import static java.lang.reflect.Modifier.STATIC;
@@ -525,6 +526,10 @@ PropertyValue getValue(Object object) throws IllegalArgumentException,
525526
}
526527
Field field = ReflectionUtil.findField(object.getClass(),
527528
memberName);
529+
if (field == null) {
530+
throw new IllegalArgumentException(format("Class: %s, field: %s",
531+
object.getClass(), memberName));
532+
}
528533
Object value = field.get(object);
529534
return new PropertyValue(object, value, memberName, field.getType());
530535
}
@@ -546,6 +551,10 @@ PropertyValue getValue(Object object) throws IllegalArgumentException,
546551

547552
Method method = ReflectionUtil.findMethod(object.getClass(),
548553
memberName);
554+
if (method == null) {
555+
throw new IllegalArgumentException(format("Class: %s, method: %s",
556+
object.getClass(), memberName));
557+
}
549558
Object value = method.invoke(object);
550559
return new PropertyValue(object, value, memberName,
551560
method.getReturnType());
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 DSA GmbH, Aachen and others.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-v20.html
8+
*
9+
* Contributors:
10+
* DSA GmbH, Aachen - initial API and implementation and/or initial documentation
11+
*******************************************************************************/
12+
package org.eclipse.rcptt.core.tests.util;
13+
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotNull;
16+
17+
import java.util.Collections;
18+
import java.util.List;
19+
20+
import org.eclipse.core.resources.IFile;
21+
import org.eclipse.core.runtime.IPath;
22+
import org.eclipse.core.runtime.Path;
23+
import org.eclipse.rcptt.util.ReflectionUtil;
24+
import org.junit.Test;
25+
26+
public class ReflectionUtilTest {
27+
@Test
28+
public void testCallMethod1() {
29+
List<String> test = List.of("value");
30+
assertEquals(1, ReflectionUtil.callMethod(test, "size"));
31+
}
32+
33+
@Test
34+
public void testCallMethod2() {
35+
List<String> test = Collections.unmodifiableList(List.of("value"));
36+
assertEquals(1, ReflectionUtil.callMethod(test, "size"));
37+
}
38+
39+
@Test
40+
public void testFindMethod1() {
41+
assertNotNull(ReflectionUtil.findMethod(List.class, "size"));
42+
}
43+
44+
@Test
45+
public void testFindMethod2() {
46+
List<String> test = Collections.unmodifiableList(List.of("value"));
47+
assertNotNull(ReflectionUtil.findMethod(test.getClass(), "size"));
48+
}
49+
50+
@Test
51+
public void testGetField() {
52+
Path p = new Path("");
53+
assertEquals(IPath.SEPARATOR, ReflectionUtil.getField(p, "SEPARATOR"));
54+
}
55+
56+
@Test
57+
public void testFindField() {
58+
assertNotNull(ReflectionUtil.findField(IFile.class, "DEPTH_INFINITE"));
59+
}
60+
}

0 commit comments

Comments
 (0)