Java Code Examples for org.eclipse.jdt.internal.compiler.impl.CompilerOptions#versionFromJdkLevel()

The following examples show how to use org.eclipse.jdt.internal.compiler.impl.CompilerOptions#versionFromJdkLevel() . 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: JVMConfigurator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static void configureJVMSettings(IJavaProject javaProject, IVMInstall vmInstall) {
	if (javaProject == null) {
		return;
	}
	String version = "";
	if (vmInstall instanceof AbstractVMInstall) {
		AbstractVMInstall jvm = (AbstractVMInstall) vmInstall;
		version = jvm.getJavaVersion();
		long jdkLevel = CompilerOptions.versionToJdkLevel(jvm.getJavaVersion());
		String compliance = CompilerOptions.versionFromJdkLevel(jdkLevel);
		Map<String, String> options = javaProject.getOptions(false);
		JavaCore.setComplianceOptions(compliance, options);
	}
	;
	if (JavaCore.compareJavaVersions(version, JavaCore.latestSupportedJavaVersion()) >= 0) {
		//Enable Java preview features for the latest JDK release by default and stfu about it
		javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
		javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
	} else {
		javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.DISABLED);
	}

}
 
Example 2
Source File: JVMConfigurator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
	if (Objects.equals(previous, current)) {
		return;
	}
	String prev = (previous == null) ? null : previous.getId() + "-" + previous.getInstallLocation();
	String curr = (current == null) ? null : current.getId() + "-" + current.getInstallLocation();

	JavaLanguageServerPlugin.logInfo("Default VM Install changed from  " + prev + " to " + curr);

	//Reset global compliance settings
	AbstractVMInstall jvm = (AbstractVMInstall) current;
	long jdkLevel = CompilerOptions.versionToJdkLevel(jvm.getJavaVersion());
	String compliance = CompilerOptions.versionFromJdkLevel(jdkLevel);
	Hashtable<String, String> options = JavaCore.getOptions();
	JavaCore.setComplianceOptions(compliance, options);
	JavaCore.setOptions(options);

	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (IProject project : projects) {
		if (!ProjectUtils.isVisibleProject(project) && ProjectUtils.isJavaProject(project)) {
			IJavaProject javaProject = JavaCore.create(project);
			configureJVMSettings(javaProject, current);
		}
		ProjectsManager projectsManager = JavaLanguageServerPlugin.getProjectsManager();
		if (projectsManager != null) {
			//TODO Only trigger update if the project uses the default JVM
			JavaLanguageServerPlugin.logInfo("defaultVMInstallChanged -> force update of " + project.getName());
			projectsManager.updateProject(project, true);
		}
	}
}
 
Example 3
Source File: JarPackageFragmentRoot.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs a package fragment root which is the root of the Java package directory hierarchy
 * based on a JAR file that is not contained in a <code>IJavaProject</code> and
 * does not have an associated <code>IResource</code>.
 */
protected JarPackageFragmentRoot(IPath externalJarPath, JavaProject project) {
	super(null, project);
	this.jarPath = externalJarPath;
	Object file = JavaModel.getTarget(getPath(), true);
	long level = Util.getJdkLevel(file);
	this.complianceLevel = CompilerOptions.versionFromJdkLevel(level);
}
 
Example 4
Source File: JarPackageFragmentRoot.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs a package fragment root which is the root of the Java package directory hierarchy
 * based on a JAR file.
 */
protected JarPackageFragmentRoot(IResource resource, JavaProject project) {
	super(resource, project);
	this.jarPath = resource.getFullPath();
	Object file = JavaModel.getTarget(getPath(), true);
	long level = Util.getJdkLevel(file);
	this.complianceLevel = CompilerOptions.versionFromJdkLevel(level);
}