ChestShop-3/com/Acrobot/Breeze/Configuration/FieldParser.java

32 lines
836 B
Java
Raw Normal View History

2012-11-23 20:59:12 +01:00
package com.Acrobot.Breeze.Configuration;
2012-11-23 21:00:35 +01:00
import java.lang.reflect.Field;
2012-11-23 20:59:12 +01:00
/**
* @author Acrobot
*/
public class FieldParser {
2012-11-23 21:00:35 +01:00
/**
* Parses a field into a YAML-compatible string
*
* @param field Field to parse
* @return Parsed field
*/
public static String parse(Field field) {
StringBuilder builder = new StringBuilder(50);
try {
builder.append(field.getName()).append(": ").append(ValueParser.parseToYAML(field.get(null)));
} catch (IllegalAccessException e) {
e.printStackTrace();
return "";
}
if (field.isAnnotationPresent(ConfigurationComment.class)) {
builder.append('\n').append('#').append(field.getAnnotation(ConfigurationComment.class).value());
}
return builder.toString();
}
2012-11-23 20:59:12 +01:00
}