diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PropertyHelper.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PropertyHelper.java deleted file mode 100644 index b018a6beb84..00000000000 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/PropertyHelper.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2015 Tom Schindl and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Tom Schindl - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.ui.css.swt.helpers; - -import java.util.HashMap; - -import java.lang.reflect.Method; - -import java.util.Map; - -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; - -public class PropertyHelper { - private static final Map NOTNESTEDCACHE = new HashMap<>(); - - public static Object getProperty(Object bean, String attr) - throws Exception { - String key = bean.getClass().getName() + "#" + attr; - - if (attr.indexOf('.') == -1) { - Method readMethod = NOTNESTEDCACHE.get(key); - if (readMethod != null) { - return readMethod.invoke(bean); - } - } - - Method readMethod = null; - Object value = bean; - for (String part : attr.split("\\.")) { - PropertyDescriptor desc = getPropertyDescriptor(value.getClass(), - part); - if (desc != null) { - readMethod = desc.getReadMethod(); - } - - if (readMethod == null) { - throw new IllegalArgumentException("Attribute '" + part - + "' is not known in '" + value + "'"); - } else { - value = readMethod.invoke(value); - } - } - - if (attr.indexOf('.') == -1) { - NOTNESTEDCACHE.put(key,readMethod); - } - - return value; - } - - private static PropertyDescriptor getPropertyDescriptor(Class clazz, - String name) throws IntrospectionException { - PropertyDescriptor[] descs = getPropertyDescriptor(clazz); - for (PropertyDescriptor desc : descs) { - if (desc.getName().equals(name)) { - return desc; - } - } - return null; - } - - private static PropertyDescriptor[] getPropertyDescriptor(Class clazz) - throws IntrospectionException { - return Introspector.getBeanInfo(clazz).getPropertyDescriptors(); - } - -} \ No newline at end of file diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java deleted file mode 100644 index 2b40fc72ff3..00000000000 --- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/TestPropertyHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2014 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Thibault Le Ouay - Bug 443094 - *******************************************************************************/ -package org.eclipse.e4.ui.tests.css.swt; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.eclipse.e4.ui.css.swt.helpers.PropertyHelper; -import org.junit.jupiter.api.Test; - -public class TestPropertyHelper { - public static class Base { - private String a = "A"; - public String getA() { - return a; - } - public void setA(String a) { - this.a = a; - } - - public String getC() { - return "C"; - } - - public boolean isD() { - return true; - } - } - - public static class Impl extends Base { - private String b = "B"; - private Base nested = new Base(); - { - nested.a = "Nested"; - } - - public String getB() { - return b; - } - - public void setB(String b) { - this.b = b; - } - - public Base getNested() { - return nested; - } - - public void setNested(Base nested) { - this.nested = nested; - } - } - - @Test - void testReadWriteProperty() throws Exception { - Impl bean = new Impl(); - assertEquals("A",PropertyHelper.getProperty(bean, "a")); - assertEquals("B",PropertyHelper.getProperty(bean, "b")); - } - - @Test - void testReadOnlyProperty() throws Exception { - Impl bean = new Impl(); - assertEquals("C",PropertyHelper.getProperty(bean, "c")); - assertEquals(true,PropertyHelper.getProperty(bean, "d")); - } - - @Test - void testNestedProperty() throws Exception { - Impl bean = new Impl(); - assertEquals("Nested",PropertyHelper.getProperty(bean, "nested.a")); - } -}