Commit 13538ba9 authored by Nico Mack's avatar Nico Mack

Added ScriptedProperty Annotation. Not functional yet!

parent 9907c170
......@@ -21,10 +21,16 @@ import com.jgoodies.common.base.Preconditions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -133,14 +139,46 @@ public class ScriptUtils {
}
// ---------------------------------------------------------------------------
/**
*
* @param clazz
* @return
*/
// ---------------------------------------------------------------------------
private static Map<String, Method> getScriptableSetters(Class<?> clazz) {
Map<String, Method> setters = new HashMap<>();
try {
BeanInfo classDetails = Introspector.getBeanInfo(clazz);
PropertyDescriptor[] properties = classDetails.getPropertyDescriptors();
for (Method method : clazz.getDeclaredMethods()) {
ScriptedProperty scripted = method.getAnnotation(ScriptedProperty.class);
if (scripted != null) {
String property = scripted.property();
for (PropertyDescriptor descriptor : properties) {
if (method.equals(descriptor.getWriteMethod())) {
setters.put(property, method);
}
}
}
}
} catch (IntrospectionException e) {
LOGGER.error("Failed to lookup animation Setters for corona {}!", clazz.getSimpleName()); //$NON-NLS-1$
}
return setters;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param object
* @param root
* @param property
* @param propertyType
* @return
*/
// ---------------------------------------------------------------------------
......@@ -148,7 +186,7 @@ public class ScriptUtils {
public static ScriptableProperty findProperty(Object root, String property, Class<?> propertyType) {
Preconditions.checkArgument(root != null, "Object to find property of CAN'T be NULL!"); //$NON-NLS-1$
Preconditions.checkArgument(property != null && (!property.isEmpty()), "Property to look for CAN'T be NULL or empty!"); //$NON-NLS-1$
Preconditions.checkArgument(property != null && !property.isEmpty(), "Property to look for CAN'T be NULL or empty!"); //$NON-NLS-1$
Class<?> candidate = root.getClass();
ScriptableProperty scriptable = null;
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.scripting;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
@Retention(RUNTIME)
@Target(METHOD)
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public @interface ScriptedProperty {
String property() default "";
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment