Java Code Examples for org.eclipse.jdt.internal.corext.util.JavaModelUtil#getCompilerCompliance()

The following examples show how to use org.eclipse.jdt.internal.corext.util.JavaModelUtil#getCompilerCompliance() . 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: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getDefaultEEName() {
	IVMInstall defaultVM= JavaRuntime.getDefaultVMInstall();

	IExecutionEnvironment[] environments= JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	if (defaultVM != null) {
		for (int i= 0; i < environments.length; i++) {
			IVMInstall eeDefaultVM= environments[i].getDefaultVM();
			if (eeDefaultVM != null && defaultVM.getId().equals(eeDefaultVM.getId()))
				return environments[i].getId();
		}
	}

	String defaultCC=JavaModelUtil.VERSION_LATEST;
	if (defaultVM instanceof IVMInstall2)
		defaultCC= JavaModelUtil.getCompilerCompliance((IVMInstall2)defaultVM, defaultCC);

	for (int i= 0; i < environments.length; i++) {
		String eeCompliance= JavaModelUtil.getExecutionEnvironmentCompliance(environments[i]);
		if (defaultCC.endsWith(eeCompliance))
			return environments[i].getId();
	}

	return "JavaSE-1.7"; //$NON-NLS-1$
}
 
Example 2
Source File: PasteAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getVMVersion(IVMInstall vm) {
	if (vm instanceof IVMInstall2) {
		IVMInstall2 vm2= (IVMInstall2) vm;
		return JavaModelUtil.getCompilerCompliance(vm2, null);
	} else {
		return null;
	}
}
 
Example 3
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isRequiredOrGreaterVMInstall(IVMInstall install) {
	if (install instanceof IVMInstall2) {
		String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3);
		return !JavaModelUtil.isVersionLessThan(compliance, fRequiredVersion);
	}
	return false;
}
 
Example 4
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getVMInstallCompliance(IVMInstall install) {
	if (install instanceof IVMInstall2) {
		String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3);
		return compliance;
	}
	return JavaCore.VERSION_1_1;
}
 
Example 5
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void validateComplianceStatus() {
		if (fJRE50InfoText != null && !fJRE50InfoText.isDisposed()) {
			boolean isVisible= false;
			String compliance= getStoredValue(PREF_COMPLIANCE); // get actual value
			IVMInstall install= null;
			if (fProject != null) { // project specific settings: only test if a 50 JRE is installed
				try {
					install= JavaRuntime.getVMInstall(JavaCore.create(fProject));
				} catch (CoreException e) {
					JavaPlugin.log(e);
				}
			} else {
				install= JavaRuntime.getDefaultVMInstall();
			}
			if (install instanceof IVMInstall2) {
				String compilerCompliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, compliance);
				if (!compilerCompliance.equals(compliance)) { // Discourage using compiler with version other than compliance
					String[] args= { getVersionLabel(compliance), getVersionLabel(compilerCompliance) };
					if (fProject == null) {
						fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info, args));
					} else {
						fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info_project, args));
					}
					isVisible= true;
				}
			}
			
//			String source= getValue(PREF_SOURCE_COMPATIBILITY);
//			if (VERSION_1_8.equals(source)) {
//				fJRE50InfoText.setText("This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP."); //$NON-NLS-1$
//				isVisible= true;
//			}
			
			fJRE50InfoText.setVisible(isVisible);
			fJRE50InfoImage.setImage(isVisible ? JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING) : null);
			fJRE50InfoImage.getParent().layout();
		}
	}
 
Example 6
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the default compiler compliance options based on the current default JRE in the
 * workspace.
 * 
 * @since 3.5
 */
private void setDefaultCompilerComplianceValues() {
	IVMInstall defaultVMInstall= JavaRuntime.getDefaultVMInstall();
	if (defaultVMInstall instanceof IVMInstall2 && isOriginalDefaultCompliance()) {
		String complianceLevel= JavaModelUtil.getCompilerCompliance((IVMInstall2)defaultVMInstall, JavaCore.VERSION_1_4);
		Map<String, String> complianceOptions= new HashMap<String, String>();
		JavaModelUtil.setComplianceOptions(complianceOptions, complianceLevel);
		setDefaultValue(PREF_COMPLIANCE, complianceOptions.get(PREF_COMPLIANCE.getName()));
		setDefaultValue(PREF_PB_ASSERT_AS_IDENTIFIER, complianceOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName()));
		setDefaultValue(PREF_PB_ENUM_AS_IDENTIFIER, complianceOptions.get(PREF_PB_ENUM_AS_IDENTIFIER.getName()));
		setDefaultValue(PREF_SOURCE_COMPATIBILITY, complianceOptions.get(PREF_SOURCE_COMPATIBILITY.getName()));
		setDefaultValue(PREF_CODEGEN_TARGET_PLATFORM, complianceOptions.get(PREF_CODEGEN_TARGET_PLATFORM.getName()));
	}
}
 
Example 7
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private String getDefaultEEName() {
	final IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();

	final IExecutionEnvironment[] environments = JavaRuntime.getExecutionEnvironmentsManager()
			.getExecutionEnvironments();
	if (defaultVM != null) {
		for (int i = 0; i < environments.length; i++) {
			final IVMInstall eeDefaultVM = environments[i].getDefaultVM();
			if (eeDefaultVM != null && defaultVM.getId().equals(eeDefaultVM.getId())) {
				return environments[i].getId();
			}
		}
	}

	final String defaultCC;
	if (defaultVM instanceof IVMInstall2) {
		defaultCC = JavaModelUtil.getCompilerCompliance((IVMInstall2) defaultVM, SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
	} else {
		defaultCC = SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
	}

	for (int i = 0; i < environments.length; i++) {
		final String eeCompliance = JavaModelUtil.getExecutionEnvironmentCompliance(environments[i]);
		if (defaultCC.endsWith(eeCompliance)) {
			return environments[i].getId();
		}
	}

	return SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
}
 
Example 8
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void fillInstalledJREs(ComboDialogField comboField) {
	String selectedItem= getLastSelectedJRE();
	int selectionIndex= -1;
	if (fUseProjectJRE.isSelected()) {
		selectionIndex= comboField.getSelectionIndex();
		if (selectionIndex != -1) {//paranoia
			selectedItem= comboField.getItems()[selectionIndex];
		}
	}

	fInstalledJVMs= getWorkspaceJREs();
	Arrays.sort(fInstalledJVMs, new Comparator<IVMInstall>() {

		public int compare(IVMInstall i0, IVMInstall i1) {
			if (i1 instanceof IVMInstall2 && i0 instanceof IVMInstall2) {
				String cc0= JavaModelUtil.getCompilerCompliance((IVMInstall2) i0, JavaCore.VERSION_1_4);
				String cc1= JavaModelUtil.getCompilerCompliance((IVMInstall2) i1, JavaCore.VERSION_1_4);
				int result= cc1.compareTo(cc0);
				if (result != 0)
					return result;
			}
			return Policy.getComparator().compare(i0.getName(), i1.getName());
		}

	});
	selectionIndex= -1;//find new index
	String[] jreLabels= new String[fInstalledJVMs.length];
	fJRECompliance= new String[fInstalledJVMs.length];
	for (int i= 0; i < fInstalledJVMs.length; i++) {
		jreLabels[i]= fInstalledJVMs[i].getName();
		if (selectedItem != null && jreLabels[i].equals(selectedItem)) {
			selectionIndex= i;
		}
		if (fInstalledJVMs[i] instanceof IVMInstall2) {
			fJRECompliance[i]= JavaModelUtil.getCompilerCompliance((IVMInstall2) fInstalledJVMs[i], JavaCore.VERSION_1_4);
		} else {
			fJRECompliance[i]= JavaCore.VERSION_1_4;
		}
	}
	comboField.setItems(jreLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultJVMName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example 9
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void handlePossibleJVMChange() {

			if (JavaRuntime.getDefaultVMInstall() == null) {
				fHintText.setText(NewWizardMessages.NewJavaProjectWizardPageOne_NoJREFound_link);
				fHintText.setVisible(true);
				fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
				fIcon.setVisible(true);
				return;
			}

			String selectedCompliance= fJREGroup.getSelectedCompilerCompliance();
			if (selectedCompliance != null) {
				String defaultCompliance= JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
				if (selectedCompliance.equals(defaultCompliance)) {
					fHintText.setVisible(false);
					fIcon.setVisible(false);
				} else {
					fHintText.setText(Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_differendWorkspaceCC_message, new String[] {  BasicElementLabels.getVersionName(defaultCompliance), BasicElementLabels.getVersionName(selectedCompliance)}));
					fHintText.setVisible(true);
					fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
					fIcon.setVisible(true);
				}
				return;
			}

			selectedCompliance= JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
			IVMInstall selectedJVM= fJREGroup.getSelectedJVM();
			if (selectedJVM == null) {
				selectedJVM= JavaRuntime.getDefaultVMInstall();
			}
			String jvmCompliance= JavaCore.VERSION_1_4;
			if (selectedJVM instanceof IVMInstall2) {
				jvmCompliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) selectedJVM, JavaCore.VERSION_1_4);
			}
			if (!selectedCompliance.equals(jvmCompliance) && (JavaModelUtil.is50OrHigher(selectedCompliance) || JavaModelUtil.is50OrHigher(jvmCompliance))) {
				fHintText.setText(Messages.format(NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_jre_message, new String[] {BasicElementLabels.getVersionName(selectedCompliance), BasicElementLabels.getVersionName(jvmCompliance)}));
				fHintText.setVisible(true);
				fIcon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
				fIcon.setVisible(true);
			} else {
				fHintText.setVisible(false);
				fIcon.setVisible(false);
			}

		}
 
Example 10
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 4 votes vote down vote up
private void fillInstalledJREs(ComboDialogField comboField) {
	String selectedItem = getLastSelectedJRE();
	int selectionIndex = comboField.getSelectionIndex();
	if (this.useProjectJRE.isSelected()) {
		if (selectionIndex != -1) {
			// paranoia
			selectedItem = comboField.getItems()[selectionIndex];
		}
	}

	this.installedJVMs = getWorkspaceJREs();
	Arrays.sort(this.installedJVMs, new Comparator<IVMInstall>() {

		@Override
		public int compare(IVMInstall i0, IVMInstall i1) {
			if (i1 instanceof IVMInstall2 && i0 instanceof IVMInstall2) {
				final String cc0 = JavaModelUtil.getCompilerCompliance((IVMInstall2) i0,
						SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
				final String cc1 = JavaModelUtil.getCompilerCompliance((IVMInstall2) i1,
						SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
				final int result = cc1.compareTo(cc0);
				if (result != 0) {
					return result;
				}
			}
			return Policy.getComparator().compare(i0.getName(), i1.getName());
		}

	});
	// find new index
	selectionIndex = -1;
	final String[] jreLabels = new String[this.installedJVMs.length];
	this.jreCompliance = new String[this.installedJVMs.length];
	for (int i = 0; i < this.installedJVMs.length; i++) {
		jreLabels[i] = this.installedJVMs[i].getName();
		if (selectedItem != null && jreLabels[i].equals(selectedItem)) {
			selectionIndex = i;
		}
		if (this.installedJVMs[i] instanceof IVMInstall2) {
			this.jreCompliance[i] = JavaModelUtil.getCompilerCompliance(
					(IVMInstall2) this.installedJVMs[i],
					SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
		} else {
			this.jreCompliance[i] = SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
		}
	}
	comboField.setItems(jreLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultJVMName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example 11
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("synthetic-access")
public void handlePossibleJVMChange() {

	if (JavaRuntime.getDefaultVMInstall() == null) {
		this.fHintText.setText(NewWizardMessages.NewJavaProjectWizardPageOne_NoJREFound_link);
		this.fHintText.setVisible(true);
		this.icon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
		this.icon.setVisible(true);
		return;
	}

	String selectedCompliance = MainProjectWizardPage.this.jreGroup.getSelectedCompilerCompliance();
	if (selectedCompliance != null) {
		final String defaultCompliance = JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
		if (selectedCompliance.equals(defaultCompliance)) {
			this.fHintText.setVisible(false);
			this.icon.setVisible(false);
		} else {
			this.fHintText.setText(MessageFormat.format(
					NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_differendWorkspaceCC_message,
					TextProcessor.process(defaultCompliance),
					TextProcessor.process(selectedCompliance)));
			this.fHintText.setVisible(true);
			this.icon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
			this.icon.setVisible(true);
		}
		return;
	}

	selectedCompliance = JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
	IVMInstall selectedJVM = MainProjectWizardPage.this.jreGroup.getSelectedJVM();
	if (selectedJVM == null) {
		selectedJVM = JavaRuntime.getDefaultVMInstall();
	}
	String jvmCompliance = SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
	if (selectedJVM instanceof IVMInstall2) {
		jvmCompliance = JavaModelUtil.getCompilerCompliance((IVMInstall2) selectedJVM,
				SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
	}
	if (!selectedCompliance.equals(jvmCompliance)
			&& (JavaModelUtil.is50OrHigher(selectedCompliance)
			|| JavaModelUtil.is50OrHigher(jvmCompliance))) {
		this.fHintText.setText(MessageFormat.format(
				NewWizardMessages.NewJavaProjectWizardPageOne_DetectGroup_jre_message,
				TextProcessor.process(selectedCompliance),
				TextProcessor.process(jvmCompliance)));
		this.fHintText.setVisible(true);
		this.icon.setImage(Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
		this.icon.setVisible(true);
	} else {
		this.fHintText.setVisible(false);
		this.icon.setVisible(false);
	}

}