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

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

Introduction

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

Prototype

int getKind();

Source Link

Document

Returns the type of this entry.

Usage

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

License:Eclipse Public License

/**
 * kind = 1, String/*from   w  ww . java 2 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;

}

From source file:org.fusesource.ide.imports.sap.IDoc3Archive.java

License:Open Source License

private void readVersion() throws IOException {
    Map<String, byte[]> idoc3Contents = new HashMap<String, byte[]>();
    readJARFile(sapidoc3jar, idoc3Contents);
    byte[] jco3IdocContents = idoc3Contents.get(JCOIDOC_CLASSFILE_ENTRY);
    ByteArrayInputStream bais = new ByteArrayInputStream(jco3IdocContents);
    IClassFileReader classfileReader = ToolFactory.createDefaultClassFileReader(bais, IClassFileReader.ALL);
    IFieldInfo[] fieldInfos = classfileReader.getFieldInfos();
    for (int i = 0; i < fieldInfos.length; i++) {
        if (Arrays.equals(fieldInfos[i].getName(), VERSION_NAME)) {
            IConstantValueAttribute constantValueAttribute = fieldInfos[i].getConstantValueAttribute();
            if (constantValueAttribute != null) {
                IConstantPoolEntry constantPoolEntry = constantValueAttribute.getConstantValue();
                if (constantPoolEntry.getKind() == IConstantPoolConstant.CONSTANT_String) {
                    version = constantPoolEntry.getStringValue();
                    if (version != null) {
                        version = version.split(JCOIDOC_VERSION_STRING_DELIMITER)[0];
                    }/*  w  w  w  .j  a v  a 2 s. c  o  m*/
                    break;
                }
            }
        }
    }
}