Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_1

The following examples show how to use org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_1 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompilerOptions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String versionFromJdkLevel(long jdkLevel) {
	switch ((int)(jdkLevel>>16)) {
		case ClassFileConstants.MAJOR_VERSION_1_1 :
			if (jdkLevel == ClassFileConstants.JDK1_1)
				return VERSION_1_1;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_2 :
			if (jdkLevel == ClassFileConstants.JDK1_2)
				return VERSION_1_2;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_3 :
			if (jdkLevel == ClassFileConstants.JDK1_3)
				return VERSION_1_3;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_4 :
			if (jdkLevel == ClassFileConstants.JDK1_4)
				return VERSION_1_4;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_5 :
			if (jdkLevel == ClassFileConstants.JDK1_5)
				return VERSION_1_5;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_6 :
			if (jdkLevel == ClassFileConstants.JDK1_6)
				return VERSION_1_6;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_7 :
			if (jdkLevel == ClassFileConstants.JDK1_7)
				return VERSION_1_7;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_8 :
			if (jdkLevel == ClassFileConstants.JDK1_8)
				return VERSION_1_8;
			break;
	}
	return Util.EMPTY_STRING; // unknown version
}
 
Example 2
Source File: CompilerOptions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static long versionToJdkLevel(Object versionID) {
	if (versionID instanceof String) {
		String version = (String) versionID;
		// verification is optimized for all versions with same length and same "1." prefix
		if (version.length() == 3 && version.charAt(0) == '1' && version.charAt(1) == '.') {
			switch (version.charAt(2)) {
				case '1':
					return ClassFileConstants.JDK1_1;
				case '2':
					return ClassFileConstants.JDK1_2;
				case '3':
					return ClassFileConstants.JDK1_3;
				case '4':
					return ClassFileConstants.JDK1_4;
				case '5':
					return ClassFileConstants.JDK1_5;
				case '6':
					return ClassFileConstants.JDK1_6;
				case '7':
					return ClassFileConstants.JDK1_7;
				case '8':
					return ClassFileConstants.JDK1_8;
				default:
					return 0; // unknown
			}
		}
		if (VERSION_JSR14.equals(versionID)) {
			return ClassFileConstants.JDK1_4;
		}
		if (VERSION_CLDC1_1.equals(versionID)) {
			return ClassFileConstants.CLDC_1_1;
		}
	}
	return 0; // unknown
}
 
Example 3
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Return true if and only if the running VM supports the given minimal version.
 *
 * <p>This only checks the major version, since the minor version is always 0 (at least for the useful cases).</p>
 * <p>The given minimalSupportedVersion is one of the constants:</p>
 * <ul>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_1</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_2</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_3</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_4</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_6</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_7</code></li>
 * </ul>
 * @param minimalSupportedVersion the given minimal version
 * @return true if and only if the running VM supports the given minimal version, false otherwise
 */
private boolean checkVMVersion(long minimalSupportedVersion) {
	// the format of this property is supposed to be xx.x where x are digits.
	String classFileVersion = System.getProperty("java.class.version"); //$NON-NLS-1$
	if (classFileVersion == null) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	int index = classFileVersion.indexOf('.');
	if (index == -1) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	int majorVersion;
	try {
		majorVersion = Integer.parseInt(classFileVersion.substring(0, index));
	} catch (NumberFormatException e) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	switch(majorVersion) {
		case ClassFileConstants.MAJOR_VERSION_1_1 : // 1.0 and 1.1
			return ClassFileConstants.JDK1_1 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_2 : // 1.2
			return ClassFileConstants.JDK1_2 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_3 : // 1.3
			return ClassFileConstants.JDK1_3 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_4 : // 1.4
			return ClassFileConstants.JDK1_4 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_5 : // 1.5
			return ClassFileConstants.JDK1_5 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_6 : // 1.6
			return ClassFileConstants.JDK1_6 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_7 : // 1.7
			return ClassFileConstants.JDK1_7 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_8: // 1.8
			return ClassFileConstants.JDK1_8 >= minimalSupportedVersion;
	}
	// unknown version
	return false;
}