Example usage for org.eclipse.jdt.core.util IFieldInfo getConstantValueAttribute

List of usage examples for org.eclipse.jdt.core.util IFieldInfo getConstantValueAttribute

Introduction

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

Prototype

IConstantValueAttribute getConstantValueAttribute();

Source Link

Document

Answer back the constant value attribute of this field info if specified, null otherwise.

Usage

From source file:org.eclipse.jpt.common.eclipselink.core.internal.libval.EclipseLinkLibraryValidatorTools.java

License:Open Source License

private static IStatus validateEclipseLinkVersion(Iterable<IClasspathEntry> libraryEntries,
        VersionRange versionRange) {//from  w  w  w . ja va  2  s .c  o m
    Version version = null;
    for (IClasspathEntry libraryEntry : libraryEntries) {
        if (libraryEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            String versionString = null;
            IClassFileReader classReader = buildClassFileReader(libraryEntry);
            if (classReader != null) {
                for (IFieldInfo field : classReader.getFieldInfos()) {
                    if (Arrays.equals(field.getName(), VERSION_FIELD_NAME_CHAR_ARRAY)) {
                        try {
                            versionString = field.getConstantValueAttribute().getConstantValue()
                                    .getStringValue();
                        } catch (RuntimeException ex) {
                            // assume the field has no value
                        }
                        break;
                    }
                }
            }
            if (versionString != null) {
                if (version != null) {
                    return buildErrorStatus(
                            JptCommonEclipseLinkCoreMessages.ECLIPSELINK_LIBRARY_VALIDATOR__MULTIPLE_ECLIPSELINK_VERSIONS);
                }
                version = new Version(versionString);
            }
        }
    }

    if (version == null) {
        return buildErrorStatus(
                JptCommonEclipseLinkCoreMessages.ECLIPSELINK_LIBRARY_VALIDATOR__NO_ECLIPSELINK_VERSION);
    }

    if (!versionRange.isIncluded(version)) {
        return buildErrorStatus(
                JptCommonEclipseLinkCoreMessages.ECLIPSELINK_LIBRARY_VALIDATOR__IMPROPER_ECLIPSELINK_VERSION);
    }

    return Status.OK_STATUS;
}