use of javafx.beans.NamedArg in project intellij-community by JetBrains.
the class JavaFxGenerateDefaultPropertyValuesScript method constructorNamedArgValues.
@NotNull
private static Map<String, Object> constructorNamedArgValues(Class<?> aClass) {
if (aClass.isInterface() || aClass.isAnnotation() || WritableValue.class.isAssignableFrom(aClass) || Event.class.isAssignableFrom(aClass)) {
return Collections.emptyMap();
}
final Constructor<?>[] constructors = aClass.getConstructors();
final Args args = new Args();
for (Constructor<?> constructor : constructors) {
final Parameter[] parameters = constructor.getParameters();
for (Parameter parameter : parameters) {
final Class<?> type = parameter.getType();
if (type.isPrimitive() || type.isEnum() || type == String.class) {
final NamedArg namedArg = parameter.getAnnotation(NamedArg.class);
if (namedArg == null)
continue;
final String name = namedArg.value();
if (!name.isEmpty()) {
final String defaultValue = namedArg.defaultValue();
if ((type == String.class || type.isEnum()) && !defaultValue.isEmpty() && !"\"\"".equals(defaultValue)) {
args.add(name, type, defaultValue);
} else if (type == boolean.class) {
args.add(name, type, Boolean.valueOf(defaultValue));
} else if (type == int.class) {
try {
args.add(name, type, Integer.valueOf(defaultValue));
} catch (NumberFormatException e) {
args.add(name, type, Integer.valueOf(0));
}
} else if (type == long.class) {
try {
args.add(name, type, Long.valueOf(defaultValue));
} catch (NumberFormatException e) {
args.add(name, type, Long.valueOf(0));
}
} else if (type == double.class) {
try {
args.add(name, type, Double.valueOf(defaultValue));
} catch (NumberFormatException e) {
args.add(name, type, Double.valueOf(0));
}
} else if (type == float.class) {
try {
args.add(name, type, Float.valueOf(defaultValue));
} catch (NumberFormatException e) {
args.add(name, type, Float.valueOf(0));
}
} else if (!type.isEnum() && type != String.class) {
System.err.println("pri " + type);
}
}
}
}
}
if (args.isEmpty())
return Collections.emptyMap();
Map<String, Object> result = new TreeMap<>();
for (String name : args) {
final Type type = args.getType(name);
if (type != null) {
final Object value = args.getValue(name);
if (value != null) {
result.put(name, value);
}
}
}
return result;
}