当前位置: 首页>>代码示例>>Java>>正文


Java JavaModelUtil.isVersionLessThan方法代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.corext.util.JavaModelUtil.isVersionLessThan方法的典型用法代码示例。如果您正苦于以下问题:Java JavaModelUtil.isVersionLessThan方法的具体用法?Java JavaModelUtil.isVersionLessThan怎么用?Java JavaModelUtil.isVersionLessThan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.internal.corext.util.JavaModelUtil的用法示例。


在下文中一共展示了JavaModelUtil.isVersionLessThan方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addOverrideAnnotation

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
 * Adds <code>@Override</code> annotation to <code>methodDecl</code> if not already present and
 * if requested by code style settings or compiler errors/warnings settings.
 *
 * @param settings the code generation style settings, may be <code>null</code>
 * @param project the Java project used to access the compiler settings
 * @param rewrite the ASTRewrite
 * @param imports the ImportRewrite
 * @param methodDecl the method declaration to add the annotation to
 * @param isDeclaringTypeInterface <code>true</code> if the type declaring the method overridden
 *            by <code>methodDecl</code> is an interface
 * @param group the text edit group, may be <code>null</code>
 */
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
		boolean isDeclaringTypeInterface, TextEditGroup group) {
	if (!JavaModelUtil.is50OrHigher(project)) {
		return;
	}
	if (isDeclaringTypeInterface) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
		{
			return; // not allowed in 1.5
		}
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
		{
			return; // user doesn't want to use 1.6 style
		}
	}
	if ((settings != null && settings.overrideAnnotation) || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, true))) {
		createOverrideAnnotation(rewrite, imports, methodDecl, group);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:34,代码来源:StubUtility2.java

示例2: findRequiredOrGreaterVMInstall

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private IVMInstall findRequiredOrGreaterVMInstall() {
	String bestMatchingCompliance= null;
	IVMInstall bestMatchingVMInstall= null;
	IVMInstallType[] installTypes= JavaRuntime.getVMInstallTypes();
	for (int i= 0; i < installTypes.length; i++) {
		IVMInstall[] installs= installTypes[i].getVMInstalls();
		for (int k= 0; k < installs.length; k++) {
			String vmInstallCompliance= getVMInstallCompliance(installs[k]);
			
			if (fRequiredVersion.equals(vmInstallCompliance)) {
				return installs[k]; // perfect match
				
			} else if (JavaModelUtil.isVersionLessThan(vmInstallCompliance, fRequiredVersion)) {
				continue; // no match
				
			} else if (bestMatchingVMInstall != null) {
				if (JavaModelUtil.isVersionLessThan(bestMatchingCompliance, vmInstallCompliance)) {
					continue; // the other one is the least matching
				}
			}
			bestMatchingCompliance= vmInstallCompliance;
			bestMatchingVMInstall= installs[k];
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:ReorgCorrectionsSubProcessor.java

示例3: createMethodComments

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
 * Creates the method annotations and comments of the extracted methods in
 * the source type.
 *
 * @param sourceRewrite
 *            the source compilation unit rewrite
 * @param replacements
 *            the set of variable binding keys of formal parameters which
 *            must be replaced
 * @throws CoreException
 *             if an error occurs
 */
protected final void createMethodComments(final CompilationUnitRewrite sourceRewrite, final Set<String> replacements) throws CoreException {
	Assert.isNotNull(sourceRewrite);
	Assert.isNotNull(replacements);
	if (fMembers.length > 0 && (fAnnotations || fComments)) {
		IJavaProject project= fSubType.getJavaProject();
		boolean annotations= fAnnotations && !JavaModelUtil.isVersionLessThan(project.getOption(JavaCore.COMPILER_SOURCE, true), JavaCore.VERSION_1_6);
		boolean javadoc= project.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true).equals(JavaCore.ENABLED);
		IMember member= null;
		for (int index= 0; index < fMembers.length; index++) {
			member= fMembers[index];
			if (member instanceof IMethod) {
				MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, sourceRewrite.getRoot());
				if (annotations) {
					ASTRewrite rewrite= sourceRewrite.getASTRewrite();
					AST ast= rewrite.getAST();
					Annotation marker= ast.newMarkerAnnotation();
					marker.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$
					rewrite.getListRewrite(declaration, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
				}
				if (fComments)
					createMethodComment(sourceRewrite, declaration, replacements, javadoc);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:38,代码来源:ExtractInterfaceProcessor.java

示例4: enforcePreferredCompilerCompliance

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
 * Makes the given project use JDK 6 (or more specifically,
 * {@link AdtConstants#COMPILER_COMPLIANCE_PREFERRED} as the compilation
 * target, regardless of what the default IDE JDK level is, provided a JRE
 * of the given level is installed.
 *
 * @param javaProject the Java project
 * @throws CoreException if the IDE throws an exception setting the compiler
 *             level
 */
@SuppressWarnings("restriction") // JDT API for setting compliance options
public static void enforcePreferredCompilerCompliance(IJavaProject javaProject)
        throws CoreException {
    String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    if (compliance == null ||
            JavaModelUtil.isVersionLessThan(compliance, COMPILER_COMPLIANCE_PREFERRED)) {
        IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
        for (int i = 0; i < types.length; i++) {
            IVMInstallType type = types[i];
            IVMInstall[] installs = type.getVMInstalls();
            for (int j = 0; j < installs.length; j++) {
                IVMInstall install = installs[j];
                if (install instanceof IVMInstall2) {
                    IVMInstall2 install2 = (IVMInstall2) install;
                    // Java version can be 1.6.0, and preferred is 1.6
                    if (install2.getJavaVersion().startsWith(COMPILER_COMPLIANCE_PREFERRED)) {
                        Map<String, String> options = javaProject.getOptions(false);
                        JavaCore.setComplianceOptions(COMPILER_COMPLIANCE_PREFERRED, options);
                        JavaModelUtil.setDefaultClassfileOptions(options,
                                COMPILER_COMPLIANCE_PREFERRED);
                        javaProject.setOptions(options);
                        return;
                    }
                }
            }
        }
    }
}
 
开发者ID:thahn0720,项目名称:agui_eclipse_plugin,代码行数:39,代码来源:ProjectHelper.java

示例5: addOverrideAnnotation

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
	if (binding.getDeclaringClass().isInterface()) {
		String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
		if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
			return; // not allowed in 1.5
		if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
			return; // user doesn't want to use 1.6 style
	}
	
	Annotation marker= rewrite.getAST().newMarkerAnnotation();
	marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$
	rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:StubUtility2.java

示例6: createSettings

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
@Override
CodeGenerationSettings createSettings(IType type, SourceActionDialog dialog) {
	ToStringGenerationSettings settings= ((GenerateToStringDialog) dialog).getGenerationSettings();
	super.createSettings(type, dialog).setSettings(settings);
	settings.createComments= dialog.getGenerateComment();
	settings.useBlocks= useBlocks(type.getJavaProject());
	String version= fUnit.getJavaElement().getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true);
	settings.is50orHigher= !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_5);
	settings.is60orHigher= !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6);
	return settings;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:GenerateToStringAction.java

示例7: isRequiredOrGreaterVMInstall

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:ReorgCorrectionsSubProcessor.java

示例8: findBestMatchingEE

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:ReorgCorrectionsSubProcessor.java

示例9: matches

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private boolean matches(ICompilationUnit cunit) {
	if (fRequiredSourceLevel != null) {
		String current= cunit.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true);
		if (JavaModelUtil.isVersionLessThan(current, fRequiredSourceLevel)) {
			return false;
		}
	}

	if (fStatus != null) {
		return fStatus.booleanValue();
	}

	IConfigurationElement[] children= fConfigurationElement.getChildren(ExpressionTagNames.ENABLEMENT);
	if (children.length == 1) {
		try {
			ExpressionConverter parser= ExpressionConverter.getDefault();
			Expression expression= parser.perform(children[0]);
			EvaluationContext evalContext= new EvaluationContext(null, cunit);
			evalContext.addVariable("compilationUnit", cunit); //$NON-NLS-1$
			IJavaProject javaProject= cunit.getJavaProject();
			String[] natures= javaProject.getProject().getDescription().getNatureIds();
			evalContext.addVariable("projectNatures", Arrays.asList(natures)); //$NON-NLS-1$
			evalContext.addVariable("sourceLevel", javaProject.getOption(JavaCore.COMPILER_SOURCE, true)); //$NON-NLS-1$
			return expression.evaluate(evalContext) == EvaluationResult.TRUE;
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
		return false;
	}
	fStatus= Boolean.FALSE;
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:ContributedProcessorDescriptor.java

示例10: validateCompliance

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private IStatus validateCompliance() {
	StatusInfo status= new StatusInfo();
	String compliance= getValue(PREF_COMPLIANCE);
	String source= getValue(PREF_SOURCE_COMPATIBILITY);
	String target= getValue(PREF_CODEGEN_TARGET_PLATFORM);
	
	if (ComplianceConfigurationBlock.VERSION_JSR14.equals(target)) {
		target= source;
	}

	// compliance must not be smaller than source or target
	if (JavaModelUtil.isVersionLessThan(compliance, source)) {
		status.setError(PreferencesMessages.ComplianceConfigurationBlock_src_greater_compliance);
		return status;
	}

	if (JavaModelUtil.isVersionLessThan(compliance, target)) {
		status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_compliance);
		return status;
	}

	if (VERSION_CLDC_1_1.equals(target)) {
		if (!VERSION_1_3.equals(source) || !JavaModelUtil.isVersionLessThan(compliance, VERSION_1_5)) {
			status.setError(PreferencesMessages.ComplianceConfigurationBlock_cldc11_requires_source13_compliance_se14);
			return status;
		}
	}

	// target must not be smaller than source
	if (!VERSION_1_3.equals(source) && JavaModelUtil.isVersionLessThan(target, source)) {
		status.setError(PreferencesMessages.ComplianceConfigurationBlock_classfile_greater_source);
		return status;
	}

	return status;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:ComplianceConfigurationBlock.java

示例11: addOverrideAnnotation

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) {
	String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	if (!binding.getDeclaringClass().isInterface() || !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6)) {
		final Annotation marker= rewrite.getAST().newMarkerAnnotation();
		marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$
		rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:9,代码来源:StubUtility2.java

示例12: validateSettings

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
	if (!areSettingsEnabled()) {
		return;
	}
	if (changedKey != null) {
		if (INTR_DEFAULT_COMPLIANCE.equals(changedKey)) {
			updateComplianceEnableState();
			updateComplianceDefaultSettings(true, null);
			fComplianceStatus= validateCompliance();
		} else if (INTR_COMPLIANCE_FOLLOWS_EE.equals(changedKey)) {
			setValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF);
			updateComplianceEnableState();
			updateComplianceDefaultSettings(true, null);
			updateControls();
			fComplianceStatus= validateCompliance();
			validateComplianceStatus();
		} else if (PREF_COMPLIANCE.equals(changedKey)) {
		    // set compliance settings to default
		    Object oldDefault= getValue(INTR_DEFAULT_COMPLIANCE);
			boolean rememberOld= USER_CONF.equals(oldDefault);
			updateComplianceDefaultSettings(rememberOld, oldValue);
			fComplianceStatus= validateCompliance();
			validateComplianceStatus();
		} else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) {
			updateAssertEnumAsIdentifierEnableState();
			fComplianceStatus= validateCompliance();
		} else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) {
			if (VERSION_CLDC_1_1.equals(newValue) && !oldValue.equals(newValue)) {
				String compliance= getValue(PREF_COMPLIANCE);
				String source= getValue(PREF_SOURCE_COMPATIBILITY);
				if (!JavaModelUtil.isVersionLessThan(compliance, VERSION_1_5)) {
					setValue(PREF_COMPLIANCE, VERSION_1_4);
				}
				if (!VERSION_1_3.equals(source)) {
					setValue(PREF_SOURCE_COMPATIBILITY, VERSION_1_3);
				}
			}
			updateControls();
			updateInlineJSREnableState();
			updateStoreMethodParamNamesEnableState();
			updateAssertEnumAsIdentifierEnableState();
			fComplianceStatus= validateCompliance();
		} else if (PREF_PB_ENUM_AS_IDENTIFIER.equals(changedKey) ||
				PREF_PB_ASSERT_AS_IDENTIFIER.equals(changedKey)) {
			fComplianceStatus= validateCompliance();
		} else {
			return;
		}
	} else {
		updateComplianceFollowsEE();
		updateControls();
		updateComplianceEnableState();
		updateAssertEnumAsIdentifierEnableState();
		updateInlineJSREnableState();
		updateStoreMethodParamNamesEnableState();
		fComplianceStatus= validateCompliance();
		validateComplianceStatus();
	}
	fContext.statusChanged(fComplianceStatus);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:65,代码来源:ComplianceConfigurationBlock.java

示例13: validateSettings

import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void validateSettings(Key changedKey, String oldValue, String newValue) {
	if (!areSettingsEnabled()) {
		return;
	}
	if (changedKey != null) {
		if (INTR_DEFAULT_COMPLIANCE.equals(changedKey)) {
			updateComplianceEnableState();
			updateComplianceDefaultSettings(true, null);
			fComplianceStatus= validateCompliance();
		} else if (INTR_COMPLIANCE_FOLLOWS_EE.equals(changedKey)) {
			setValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF);
			updateComplianceEnableState();
			updateComplianceDefaultSettings(true, null);
			updateControls();
			fComplianceStatus= validateCompliance();
			validateComplianceStatus();
		} else if (PREF_COMPLIANCE.equals(changedKey)) {
		    // set compliance settings to default
		    Object oldDefault= getValue(INTR_DEFAULT_COMPLIANCE);
			boolean rememberOld= USER_CONF.equals(oldDefault);
			updateComplianceDefaultSettings(rememberOld, oldValue);
			fComplianceStatus= validateCompliance();
			validateComplianceStatus();
		} else if (PREF_SOURCE_COMPATIBILITY.equals(changedKey)) {
			updateAssertEnumAsIdentifierEnableState();
			fComplianceStatus= validateCompliance();
		} else if (PREF_CODEGEN_TARGET_PLATFORM.equals(changedKey)) {
			if (VERSION_CLDC_1_1.equals(newValue) && !oldValue.equals(newValue)) {
				String compliance= getValue(PREF_COMPLIANCE);
				String source= getValue(PREF_SOURCE_COMPATIBILITY);
				if (!JavaModelUtil.isVersionLessThan(compliance, VERSION_1_5)) {
					setValue(PREF_COMPLIANCE, VERSION_1_4);
				}
				if (!VERSION_1_3.equals(source)) {
					setValue(PREF_SOURCE_COMPATIBILITY, VERSION_1_3);
				}
			}
			updateControls();
			updateInlineJSREnableState();
			updateAssertEnumAsIdentifierEnableState();
			fComplianceStatus= validateCompliance();
		} else if (PREF_PB_ENUM_AS_IDENTIFIER.equals(changedKey) ||
				PREF_PB_ASSERT_AS_IDENTIFIER.equals(changedKey)) {
			fComplianceStatus= validateCompliance();
		} else {
			return;
		}
	} else {
		updateComplianceFollowsEE();
		updateControls();
		updateComplianceEnableState();
		updateAssertEnumAsIdentifierEnableState();
		updateInlineJSREnableState();
		fComplianceStatus= validateCompliance();
		validateComplianceStatus();
	}
	fContext.statusChanged(fComplianceStatus);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:63,代码来源:ComplianceConfigurationBlock.java


注:本文中的org.eclipse.jdt.internal.corext.util.JavaModelUtil.isVersionLessThan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。