Java Code Examples for org.eclipse.jdt.core.JavaCore#VERSION_1_4

The following examples show how to use org.eclipse.jdt.core.JavaCore#VERSION_1_4 . 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: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static String getCompilerCompliance(IVMInstall2 vMInstall, String defaultCompliance) {
	String version= vMInstall.getJavaVersion();
	if (version == null) {
		return defaultCompliance;
	} else if (version.startsWith(JavaCore.VERSION_1_8)) {
		return JavaCore.VERSION_1_8;
	} else if (version.startsWith(JavaCore.VERSION_1_7)) {
		return JavaCore.VERSION_1_7;
	} else if (version.startsWith(JavaCore.VERSION_1_6)) {
		return JavaCore.VERSION_1_6;
	} else if (version.startsWith(JavaCore.VERSION_1_5)) {
		return JavaCore.VERSION_1_5;
	} else if (version.startsWith(JavaCore.VERSION_1_4)) {
		return JavaCore.VERSION_1_4;
	} else if (version.startsWith(JavaCore.VERSION_1_3)) {
		return JavaCore.VERSION_1_3;
	} else if (version.startsWith(JavaCore.VERSION_1_2)) {
		return JavaCore.VERSION_1_3;
	} else if (version.startsWith(JavaCore.VERSION_1_1)) {
		return JavaCore.VERSION_1_3;
	}
	return defaultCompliance;
}
 
Example 2
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static String getExecutionEnvironmentCompliance(IExecutionEnvironment executionEnvironment) {
	Map<String, String> complianceOptions= executionEnvironment.getComplianceOptions();
	if (complianceOptions != null) {
		Object compliance= complianceOptions.get(JavaCore.COMPILER_COMPLIANCE);
		if (compliance instanceof String)
			return (String)compliance;
	}
	
	// fallback:
	String desc= executionEnvironment.getId();
	if (desc.indexOf(JavaCore.VERSION_1_8) != -1) {
		return JavaCore.VERSION_1_8;
	} else if (desc.indexOf(JavaCore.VERSION_1_7) != -1) {
		return JavaCore.VERSION_1_7;
	} else if (desc.indexOf(JavaCore.VERSION_1_6) != -1) {
		return JavaCore.VERSION_1_6;
	} else if (desc.indexOf(JavaCore.VERSION_1_5) != -1) {
		return JavaCore.VERSION_1_5;
	} else if (desc.indexOf(JavaCore.VERSION_1_4) != -1) {
		return JavaCore.VERSION_1_4;
	}
	return JavaCore.VERSION_1_3;
}
 
Example 3
Source File: JavaASTUtil.java    From compiler with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static ASTParser buildParser(FileKind fileKind) {
	int astLevel = -1;
	String compliance = null;
	switch (fileKind) {
	case SOURCE_JAVA_JLS2:
		astLevel = AST.JLS2;
		compliance = JavaCore.VERSION_1_4;
		break;
	case SOURCE_JAVA_JLS3:
		astLevel = AST.JLS3;
		compliance = JavaCore.VERSION_1_5;
		break;
	case SOURCE_JAVA_JLS4:
		astLevel = AST.JLS4;
		compliance = JavaCore.VERSION_1_7;
		break;
	case SOURCE_JAVA_JLS8:
		astLevel = AST.JLS8;
		compliance = JavaCore.VERSION_1_8;
		break;
	default:
		break;
	}
	if (compliance != null) {
		ASTParser parser = ASTParser.newParser(astLevel);
		parser.setKind(ASTParser.K_COMPILATION_UNIT);

		final Map<?, ?> options = JavaCore.getOptions();
		JavaCore.setComplianceOptions(compliance, options);
		parser.setCompilerOptions(options);
		return parser;
	}
	return null;
}
 
Example 4
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 5
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 6
Source File: JavadocSpecificsWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createExtraOptionsGroup(Composite composite) {
	Composite c= new Composite(composite, SWT.NONE);
	c.setLayout(createGridLayout(3));
	c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 3, 0));
	((GridLayout) c.getLayout()).marginWidth= 0;

	fOverViewButton= createButton(c, SWT.CHECK, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbutton_label, createGridData(1));
	fOverViewText= createText(c, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
	SWTUtil.setAccessibilityText(fOverViewText, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbutton_description);
	//there really aught to be a way to specify this
	 ((GridData) fOverViewText.getLayoutData()).widthHint= 200;
	fOverViewBrowseButton= createButton(c, SWT.PUSH, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbrowse_label, createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 0));
	SWTUtil.setButtonDimensionHint(fOverViewBrowseButton);

	String str= fStore.getOverview();
	if (str.length() == 0) {
		//default
		fOverViewText.setEnabled(false);
		fOverViewBrowseButton.setEnabled(false);
	} else {
		fOverViewButton.setSelection(true);
		fOverViewText.setText(str);
	}

	createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_vmoptionsfield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 3, 0));
	fVMOptionsText= createText(composite, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 3, 0));
	fVMOptionsText.setText(fStore.getVMParams());


	createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_extraoptionsfield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 3, 0));
	fExtraOptionsText= createText(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL, 3, 0));
	//fExtraOptionsText.setSize(convertWidthInCharsToPixels(60), convertHeightInCharsToPixels(10));

	fExtraOptionsText.setText(fStore.getAdditionalParams());

	Composite inner= new Composite(composite, SWT.NONE);
	inner.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false, 3, 1));
	GridLayout layout= new GridLayout(2, false);
	layout.marginHeight= 0;
	layout.marginWidth= 0;
	inner.setLayout(layout);

	createLabel(inner, SWT.NONE, JavadocExportMessages.JavadocSpecificsWizardPage_sourcecompatibility_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 0));

	fSourceCombo= createCombo(inner, SWT.NONE, fStore.getSource(), createGridData(1));
	String[] versions= { "-", //$NON-NLS-1$
			JavaCore.VERSION_1_3, JavaCore.VERSION_1_4, JavaCore.VERSION_1_5, JavaCore.VERSION_1_6, JavaCore.VERSION_1_7, JavaCore.VERSION_1_8 };
	fSourceCombo.setItems(versions);
	fSourceCombo.setText(fStore.getSource());


	//Listeners
	fOverViewButton.addSelectionListener(new ToggleSelectionAdapter(new Control[] { fOverViewBrowseButton, fOverViewText }) {
		@Override
		public void validate() {
			doValidation(OVERVIEWSTATUS);
		}
	});

	fOverViewText.addModifyListener(new ModifyListener() {
		public void modifyText(ModifyEvent e) {
			doValidation(OVERVIEWSTATUS);
		}
	});

	fOverViewBrowseButton.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent event) {
			handleFileBrowseButtonPressed(fOverViewText, new String[] { "*.html" }, JavadocExportMessages.JavadocSpecificsWizardPage_overviewbrowsedialog_title);  //$NON-NLS-1$
		}
	});

}
 
Example 7
Source File: JavaCodeScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected List<IRule> createRules() {

	List<IRule> rules= new ArrayList<IRule>();

	// Add rule for character constants.
	Token token= getToken(IJavaColorConstants.JAVA_STRING);
	rules.add(new SingleLineRule("'", "'", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$


	Token defaultToken= getToken(IJavaColorConstants.JAVA_DEFAULT);
	
	// Add generic whitespace rule.
	rules.add(new WhitespaceRule(new JavaWhitespaceDetector(), defaultToken));

	String version= getPreferenceStore().getString(SOURCE_VERSION);

	// Add JLS3 rule for /@\s*interface/ and /@\s*\w+/
	token= getToken(ANNOTATION_COLOR_KEY);
	AnnotationRule atInterfaceRule= new AnnotationRule(getToken(IJavaColorConstants.JAVA_KEYWORD), token, JavaCore.VERSION_1_5, version);
	rules.add(atInterfaceRule);
	fVersionDependentRules.add(atInterfaceRule);

	// Add word rule for new keywords, see bug 4077
	JavaWordDetector wordDetector= new JavaWordDetector();
	CombinedWordRule combinedWordRule= new CombinedWordRule(wordDetector, defaultToken);

	VersionedWordMatcher j14Matcher= new VersionedWordMatcher(defaultToken, JavaCore.VERSION_1_4, version);

	token= getToken(IJavaColorConstants.JAVA_KEYWORD);
	for (int i=0; i<fgJava14Keywords.length; i++)
		j14Matcher.addWord(fgJava14Keywords[i], token);

	combinedWordRule.addWordMatcher(j14Matcher);
	fVersionDependentRules.add(j14Matcher);

	VersionedWordMatcher j15Matcher= new VersionedWordMatcher(defaultToken, JavaCore.VERSION_1_5, version);
	
	token= getToken(IJavaColorConstants.JAVA_KEYWORD);
	for (int i=0; i<fgJava15Keywords.length; i++)
		j15Matcher.addWord(fgJava15Keywords[i], token);

	combinedWordRule.addWordMatcher(j15Matcher);
	fVersionDependentRules.add(j15Matcher);

	// Add rule for operators
	token= getToken(IJavaColorConstants.JAVA_OPERATOR);
	rules.add(new OperatorRule(token));

	// Add rule for brackets
	token= getToken(IJavaColorConstants.JAVA_BRACKET);
	rules.add(new BracketRule(token));

	// Add word rule for keyword 'return'.
	CombinedWordRule.WordMatcher returnWordRule= new CombinedWordRule.WordMatcher();
	token= getToken(IJavaColorConstants.JAVA_KEYWORD_RETURN);
	returnWordRule.addWord(RETURN, token);
	combinedWordRule.addWordMatcher(returnWordRule);

	// Add word rule for keywords, types, and constants.
	CombinedWordRule.WordMatcher wordRule= new CombinedWordRule.WordMatcher();
	token= getToken(IJavaColorConstants.JAVA_KEYWORD);
	for (int i=0; i<fgKeywords.length; i++)
		wordRule.addWord(fgKeywords[i], token);
	for (int i=0; i<fgTypes.length; i++)
		wordRule.addWord(fgTypes[i], token);
	for (int i=0; i<fgConstants.length; i++)
		wordRule.addWord(fgConstants[i], token);

	combinedWordRule.addWordMatcher(wordRule);

	rules.add(combinedWordRule);

	setDefaultReturnToken(defaultToken);
	return rules;
}