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

The following examples show how to use org.eclipse.jdt.internal.corext.util.JavaModelUtil#getExecutionEnvironmentCompliance() . 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: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void fillExecutionEnvironments(ComboDialogField comboField) {
	String selectedItem= getLastSelectedEE();
	int selectionIndex= -1;
	if (fUseEEJRE.isSelected()) {
		selectionIndex= comboField.getSelectionIndex();
		if (selectionIndex != -1) {// paranoia
			selectedItem= comboField.getItems()[selectionIndex];
		}
	}

	fInstalledEEs= JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	Arrays.sort(fInstalledEEs, new Comparator<IExecutionEnvironment>() {
		public int compare(IExecutionEnvironment arg0, IExecutionEnvironment arg1) {
			return Policy.getComparator().compare(arg0.getId(), arg1.getId());
		}
	});
	selectionIndex= -1;//find new index
	String[] eeLabels= new String[fInstalledEEs.length];
	fEECompliance= new String[fInstalledEEs.length];
	for (int i= 0; i < fInstalledEEs.length; i++) {
		eeLabels[i]= fInstalledEEs[i].getId();
		if (selectedItem != null && eeLabels[i].equals(selectedItem)) {
			selectionIndex= i;
		}
		fEECompliance[i]= JavaModelUtil.getExecutionEnvironmentCompliance(fInstalledEEs[i]);
	}
	comboField.setItems(eeLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultEEName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example 3
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IExecutionEnvironment findBestMatchingEE() {
	IExecutionEnvironmentsManager eeManager= JavaRuntime.getExecutionEnvironmentsManager();
	IExecutionEnvironment[] ees= eeManager.getExecutionEnvironments();
	IExecutionEnvironment bestEE= null;
	String bestEECompliance= null;
	
	for (int i= 0; i < ees.length; i++) {
		IExecutionEnvironment ee= ees[i];
		String eeCompliance= JavaModelUtil.getExecutionEnvironmentCompliance(ee);
		String eeId= ee.getId();
		
		if (fRequiredVersion.equals(eeCompliance)) {
			if (eeId.startsWith("J") && eeId.endsWith(fRequiredVersion)) { //$NON-NLS-1$
				bestEE= ee;
				break; // perfect match
			}
			
		} else if (JavaModelUtil.isVersionLessThan(eeCompliance, fRequiredVersion)) {
			continue; // no match
			
		} else { // possible match
			if (bestEE != null) {
				if (! eeId.startsWith("J")) { //$NON-NLS-1$
					continue; // avoid taking e.g. OSGi profile if a Java profile is available
				}
				if (JavaModelUtil.isVersionLessThan(bestEECompliance, eeCompliance)) {
					continue; // the other one is the least matching
				}
			}
		}
		// found a new best
		bestEE= ee;
		bestEECompliance= eeCompliance;
	}
	return bestEE;
}
 
Example 4
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void fillExecutionEnvironments(ComboDialogField comboField) {
	String selectedItem = getLastSelectedEE();
	int selectionIndex = comboField.getSelectionIndex();
	if (this.useEEJRE.isSelected()) {
		if (selectionIndex != -1) {
			// paranoia
			selectedItem = comboField.getItems()[selectionIndex];
		}
	}

	this.installedEEs = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	Arrays.sort(this.installedEEs, new Comparator<IExecutionEnvironment>() {
		@Override
		public int compare(IExecutionEnvironment arg0, IExecutionEnvironment arg1) {
			return Policy.getComparator().compare(arg0.getId(), arg1.getId());
		}
	});
	// find new index
	selectionIndex = -1;
	final String[] eeLabels = new String[this.installedEEs.length];
	this.eeCompliance = new String[this.installedEEs.length];
	for (int i = 0; i < this.installedEEs.length; i++) {
		eeLabels[i] = this.installedEEs[i].getId();
		if (selectedItem != null && eeLabels[i].equals(selectedItem)) {
			selectionIndex = i;
		}
		this.eeCompliance[i] = JavaModelUtil.getExecutionEnvironmentCompliance(this.installedEEs[i]);
	}
	comboField.setItems(eeLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultEEName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example 5
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;
}