Example usage for org.eclipse.jdt.core.util IConstantPoolEntry getIntegerValue

List of usage examples for org.eclipse.jdt.core.util IConstantPoolEntry getIntegerValue

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.util IConstantPoolEntry getIntegerValue.

Prototype

int getIntegerValue();

Source Link

Document

Returns the integer value for a CONSTANT_Integer type entry.

Usage

From source file:com.inepex.classtemplater.plugin.logic.Annotation.java

License:Eclipse Public License

/**
 * kind = 1, String/*from   w ww. ja  v  a2  s.co  m*/
 * kind = 4, float
 * kind = 5, long
 * kind = 6, double
 * kind = 3, int
 * kind = 3, boolean
 */
private Object parseDefaultObjectValueFromAnnotationDefaultAttribute(AnnotationDefaultAttribute a,
        String type) {
    if (a.getMemberValue().getConstantValue() != null) {
        IConstantPoolEntry constant = a.getMemberValue().getConstantValue();
        switch (constant.getKind()) {
        case 1:
            return new String(constant.getUtf8Value());
        case 5:
            return constant.getLongValue();
        case 6:
            return constant.getDoubleValue();
        case 4:
            return constant.getFloatValue();
        case 3:
            if (type.contains("()Z")) {
                return constant.getIntegerValue() == 1;
            } else
                return constant.getIntegerValue();
        default:
            return null;
        }
    } else if (a.getMemberValue().getEnumConstantName() != null) {
        String[] typeSplitted = new String(a.getMemberValue().getEnumConstantTypeName()).split("/");
        String enumType = typeSplitted[typeSplitted.length - 1].substring(0,
                typeSplitted[typeSplitted.length - 1].length() - 1);
        return enumType + "." + new String(a.getMemberValue().getEnumConstantName());
    } else
        return null;

}