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


Java CompilerOptions.versionToJdkLevel方法代码示例

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


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

示例1: ASTConverter

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
public ASTConverter(Map options, boolean resolveBindings, IProgressMonitor monitor) {
	this.resolveBindings = resolveBindings;
	Object sourceModeSetting = options.get(JavaCore.COMPILER_SOURCE);
	long sourceLevel = CompilerOptions.versionToJdkLevel(sourceModeSetting);
	if (sourceLevel == 0) {
		// unknown sourceModeSetting
		sourceLevel = ClassFileConstants.JDK1_3;
	}
	this.scanner = new Scanner(
		true /*comment*/,
		false /*whitespace*/,
		false /*nls*/,
		sourceLevel /*sourceLevel*/,
		null /*taskTags*/,
		null/*taskPriorities*/,
		true/*taskCaseSensitive*/);
	this.monitor = monitor;
	this.insideComments = JavaCore.ENABLED.equals(options.get(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:20,代码来源:ASTConverter.java

示例2: filterEnum

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private boolean filterEnum(SearchMatch match) {
	
	// filter org.apache.commons.lang.enum package for projects above 1.5 
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317264	
	IJavaElement element = (IJavaElement)match.getElement();
	PackageFragment pkg = (PackageFragment)element.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
	if (pkg != null) {
		// enum was found in org.apache.commons.lang.enum at index 5
		if (pkg.names.length == 5 && pkg.names[4].equals("enum")) {  //$NON-NLS-1$
			if (this.options == null) {
				IJavaProject proj = (IJavaProject)pkg.getAncestor(IJavaElement.JAVA_PROJECT);
				String complianceStr = proj.getOption(CompilerOptions.OPTION_Source, true);
				if (CompilerOptions.versionToJdkLevel(complianceStr) >= ClassFileConstants.JDK1_5)
					return true;
			} else if (this.options.sourceLevel >= ClassFileConstants.JDK1_5) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:MatchLocator.java

示例3: indexForSourceLevel

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private int indexForSourceLevel(String sourceLevel) {
	if (sourceLevel == null) return 0;
	int majVersion = (int) (CompilerOptions.versionToJdkLevel(sourceLevel) >>> 16);
	switch (majVersion) {
		case ClassFileConstants.MAJOR_VERSION_1_2:
			return 1;
		case ClassFileConstants.MAJOR_VERSION_1_3:
			return 2;
		case ClassFileConstants.MAJOR_VERSION_1_4:
			return 3;
		case ClassFileConstants.MAJOR_VERSION_1_5:
			return 4;
		case ClassFileConstants.MAJOR_VERSION_1_6:
			return 5;
		case ClassFileConstants.MAJOR_VERSION_1_7:
			return 6;
		case ClassFileConstants.MAJOR_VERSION_1_8:
			return 7;
		default:
			// all other cases including ClassFileConstants.MAJOR_VERSION_1_1
			return 0;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:24,代码来源:JavaModelManager.java

示例4: ASTConverter

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
public ASTConverter(Map options, boolean resolveBindings, IProgressMonitor monitor) {
	this.resolveBindings = resolveBindings;
	this.referenceContext = null;
	Object sourceModeSetting = options.get(JavaCore.COMPILER_SOURCE);
	long sourceLevel = CompilerOptions.versionToJdkLevel(sourceModeSetting);
	if (sourceLevel == 0) {
		// unknown sourceModeSetting
		sourceLevel = ClassFileConstants.JDK1_3;
	}
	this.scanner = new Scanner(
		true /*comment*/,
		false /*whitespace*/,
		false /*nls*/,
		sourceLevel /*sourceLevel*/,
		null /*taskTags*/,
		null/*taskPriorities*/,
		true/*taskCaseSensitive*/);
	this.monitor = monitor;
	this.insideComments = JavaCore.ENABLED.equals(options.get(JavaCore.COMPILER_DOC_COMMENT_SUPPORT));
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ASTConverter.java

示例5: indexForSourceLevel

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private int indexForSourceLevel(String sourceLevel) {
	if (sourceLevel == null) return 0;
	int majVersion = (int) (CompilerOptions.versionToJdkLevel(sourceLevel) >>> 16);
	switch (majVersion) {
		case ClassFileConstants.MAJOR_VERSION_1_2:
			return 1;
		case ClassFileConstants.MAJOR_VERSION_1_3:
			return 2;
		case ClassFileConstants.MAJOR_VERSION_1_4:
			return 3;
		case ClassFileConstants.MAJOR_VERSION_1_5:
			return 4;
		case ClassFileConstants.MAJOR_VERSION_1_6:
			return 5;
		case ClassFileConstants.MAJOR_VERSION_1_7:
			return 6;
		default:
			// all other cases including ClassFileConstants.MAJOR_VERSION_1_1
			return 0;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:22,代码来源:JavaModelManager.java

示例6: getDefaultBootclasspath

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
Iterable<? extends File> getDefaultBootclasspath() {
	ArrayList<File> files = new ArrayList<File>();
	String javaversion = System.getProperty("java.version");//$NON-NLS-1$
	if(javaversion.length() > 3)
		javaversion = javaversion.substring(0, 3);
	long jdkLevel = CompilerOptions.versionToJdkLevel(javaversion);
	if (jdkLevel < ClassFileConstants.JDK1_6) {
		// wrong jdk - 1.6 or above is required
		return null;
	}

	/*
	 * Handle >= JDK 1.6
	 */
	String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
	File javaHomeFile = null;
	if (javaHome != null) {
		javaHomeFile = new File(javaHome);
		if (!javaHomeFile.exists())
			javaHomeFile = null;
	}

	addFilesFrom(javaHomeFile, "java.endorsed.dirs", "/lib/endorsed", files);//$NON-NLS-1$//$NON-NLS-2$
	if (javaHomeFile != null) {
		File[] directoriesToCheck = null;
		if (System.getProperty("os.name").startsWith("Mac")) {//$NON-NLS-1$//$NON-NLS-2$
			directoriesToCheck = new File[] { new File(javaHomeFile, "../Classes"), //$NON-NLS-1$
			};
		} else {
			directoriesToCheck = new File[] { new File(javaHomeFile, "lib") //$NON-NLS-1$
			};
		}
		File[][] jars = Main.getLibrariesFiles(directoriesToCheck);
		addFiles(jars, files);
	}
	addFilesFrom(javaHomeFile, "java.ext.dirs", "/lib/ext", files);//$NON-NLS-1$//$NON-NLS-2$
	return files;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:EclipseFileManager.java

示例7: accept

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Add additional source types
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	// ensure to jump back to toplevel type for first one (could be a member)
	while (sourceTypes[0].getEnclosingType() != null) {
		sourceTypes[0] = sourceTypes[0].getEnclosingType();
	}

	CompilationResult result =
		new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit);
	
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box.
	final long savedComplianceLevel = this.options.complianceLevel;
	final long savedSourceLevel = this.options.sourceLevel;
	
	try {
		IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject();
		this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true));
		this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true));

		// need to hold onto this
		CompilationUnitDeclaration unit =
			SourceTypeConverter.buildCompilationUnit(
					sourceTypes,//sourceTypes[0] is always toplevel here
					SourceTypeConverter.FIELD_AND_METHOD // need field and methods
					| SourceTypeConverter.MEMBER_TYPE // need member types
					| SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization
					this.lookupEnvironment.problemReporter,
					result);

		if (unit != null) {
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);
			this.lookupEnvironment.completeTypeBindings(unit);
		}
	} finally {
		this.options.complianceLevel = savedComplianceLevel;
		this.options.sourceLevel = savedSourceLevel;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:CompilationUnitProblemFinder.java

示例8: getMapper

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
private CodeSnippetToCuMapper getMapper() {
	if (this.mapper == null) {
		char[] varClassName = null;
		VariablesInfo installedVars = this.context.installedVars;
		if (installedVars != null) {
			char[] superPackageName = installedVars.packageName;
			if (superPackageName != null && superPackageName.length != 0) {
				varClassName = CharOperation.concat(superPackageName, installedVars.className, '.');
			} else {
				varClassName = installedVars.className;
			}

		}
		this.mapper = new CodeSnippetToCuMapper(
			this.codeSnippet,
			this.context.packageName,
			this.context.imports,
			getClassName(),
			varClassName,
			this.context.localVariableNames,
			this.context.localVariableTypeNames,
			this.context.localVariableModifiers,
			this.context.declaringTypeName,
			this.context.lineSeparator,
			CompilerOptions.versionToJdkLevel(this.options.get(JavaCore.COMPILER_COMPLIANCE))
		);

	}
	return this.mapper;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:CodeSnippetEvaluator.java

示例9: CodeFormatterVisitor

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
public CodeFormatterVisitor(DefaultCodeFormatterOptions preferences, Map settings, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) {
	long sourceLevel = settings == null
		? ClassFileConstants.JDK1_3
		: CompilerOptions.versionToJdkLevel(settings.get(JavaCore.COMPILER_SOURCE));
	this.localScanner = new Scanner(true, false, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);

	this.preferences = preferences;
	this.scribe = new Scribe(this, sourceLevel, regions, codeSnippetParsingUtil, includeComments);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:10,代码来源:CodeFormatterVisitor.java

示例10: setComplianceOptions

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Sets the default compiler options inside the given options map according
 * to the given compliance.
 *
 * <p>The given compliance must be one of those supported by the compiler,
 * that is one of the acceptable values for option {@link #COMPILER_COMPLIANCE}.</p>
 *
 * <p>The list of modified options is currently:</p>
 * <ul>
 * <li>{@link #COMPILER_COMPLIANCE}</li>
 * <li>{@link #COMPILER_SOURCE}</li>
 * <li>{@link #COMPILER_CODEGEN_TARGET_PLATFORM}</li>
 * <li>{@link #COMPILER_PB_ASSERT_IDENTIFIER}</li>
 * <li>{@link #COMPILER_PB_ENUM_IDENTIFIER}</li>
 * <li>{@link #COMPILER_CODEGEN_INLINE_JSR_BYTECODE} for compliance levels 1.5 and greater</li>
 * </ul>
 *
 * <p>If the given compliance is unknown, the given map is unmodified.</p>
 *
 * @param compliance the given compliance
 * @param options the given options map
 * @since 3.3
 */
public static void setComplianceOptions(String compliance, Map options) {
	switch((int) (CompilerOptions.versionToJdkLevel(compliance) >>> 16)) {
		case ClassFileConstants.MAJOR_VERSION_1_3:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_4:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_5:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_6:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_7:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_8:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:74,代码来源:JavaCore.java

示例11: select

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Computes the selection at the specified positions of the given code snippet.
 * (Note that this evaluation context's VM doesn't need to be running.)
 *  @param codeSnippet char[]
 * 		The code snipper source
 *
 *  @param selectionSourceStart int
 *
 *  @param selectionSourceEnd int
 *
 *  @param environment org.eclipse.jdt.internal.core.SearchableEnvironment
 *      used to resolve type/package references and search for types/packages
 *      based on partial names.
 *
 *  @param requestor org.eclipse.jdt.internal.codeassist.ISelectionRequestor
 *      since the engine might produce answers of various forms, the engine
 *      is associated with a requestor able to accept all possible selections.
 *
 *  @param options java.util.Map
 *		set of options used to configure the code assist engine.
 */
public void select(
	char[] codeSnippet,
	int selectionSourceStart,
	int selectionSourceEnd,
	SearchableEnvironment environment,
	ISelectionRequestor requestor,
	Map options,
	WorkingCopyOwner owner) {

	final char[] className = "CodeSnippetSelection".toCharArray(); //$NON-NLS-1$
	final long complianceVersion = CompilerOptions.versionToJdkLevel(options.get(JavaCore.COMPILER_COMPLIANCE));
	final CodeSnippetToCuMapper mapper = new CodeSnippetToCuMapper(
		codeSnippet,
		this.packageName,
		this.imports,
		className,
		this.installedVars == null ? null : this.installedVars.className,
		this.localVariableNames,
		this.localVariableTypeNames,
		this.localVariableModifiers,
		this.declaringTypeName,
		this.lineSeparator,
		complianceVersion
	);
	ICompilationUnit sourceUnit = new ICompilationUnit() {
		public char[] getFileName() {
			return CharOperation.concat(className, Util.defaultJavaExtension().toCharArray());
		}
		public char[] getContents() {
			return mapper.getCUSource(EvaluationContext.this.lineSeparator);
		}
		public char[] getMainTypeName() {
			return className;
		}
		public char[][] getPackageName() {
			return null;
		}
		public boolean ignoreOptionalProblems() {
			return false;
		}
	};
	SelectionEngine engine = new SelectionEngine(environment, mapper.getSelectionRequestor(requestor), options, owner);
	engine.select(sourceUnit, mapper.startPosOffset + selectionSourceStart, mapper.startPosOffset + selectionSourceEnd);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:66,代码来源:EvaluationContext.java

示例12: createScanner

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be
 * used to tokenize some source in a Java aware way.
 * Here is a typical scanning loop:
 *
 * <code>
 * <pre>
 *   IScanner scanner = ToolFactory.createScanner(false, false, false, false);
 *   scanner.setSource("int i = 0;".toCharArray());
 *   while (true) {
 *     int token = scanner.getNextToken();
 *     if (token == ITerminalSymbols.TokenNameEOF) break;
 *     System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
 *   }
 * </pre>
 * </code>
 *
 * <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE
 * or 1.4 if running from outside of a headless eclipse.
 * </p>
 *
 * @param tokenizeComments if set to <code>false</code>, comments will be silently consumed
 * @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed,
 * @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line
 * separator ends. In case of multi-character line separators, the last character position is considered. These positions
 * can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are
 * considered as valid line separators.
 * @param sourceLevel if set to <code>&quot;1.3&quot;</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers
 * ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>&quot;1.4&quot;</code>, it
 * would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced
 * a new 'assert' keyword.
 * @return a scanner
 * @see org.eclipse.jdt.core.compiler.IScanner
 * @see #createScanner(boolean, boolean, boolean, String, String)
 * @since 3.0
 */
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel) {
	// use default workspace compliance
	long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
	if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance
	long sourceLevelValue = CompilerOptions.versionToJdkLevel(sourceLevel);
	if (sourceLevelValue == 0) sourceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance
	PublicScanner scanner =
		new PublicScanner(
			tokenizeComments,
			tokenizeWhiteSpace,
			false/*nls*/,
			sourceLevelValue /*sourceLevel*/,
			complianceLevelValue,
			null/*taskTags*/,
			null/*taskPriorities*/,
			true/*taskCaseSensitive*/);
	scanner.recordLineSeparator = recordLineSeparator;
	return scanner;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:56,代码来源:ToolFactory.java

示例13: setComplianceOptions

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Sets the default compiler options inside the given options map according
 * to the given compliance.
 *
 * <p>The given compliance must be one of those supported by the compiler,
 * that is one of the acceptable values for option {@link #COMPILER_COMPLIANCE}.
 *
 * <p>The list of modified options is currently:</p>
 * <ul>
 * <li>{@link #COMPILER_COMPLIANCE}</li>
 * <li>{@link #COMPILER_SOURCE}</li>
 * <li>{@link #COMPILER_CODEGEN_TARGET_PLATFORM}</li>
 * <li>{@link #COMPILER_PB_ASSERT_IDENTIFIER}</li>
 * <li>{@link #COMPILER_PB_ENUM_IDENTIFIER}</li>
 * <li>{@link #COMPILER_CODEGEN_INLINE_JSR_BYTECODE} for compliance levels 1.5 and greater</li>
 * </ul>
 *
 * <p>If the given compliance is unknown, the given map is unmodified.</p>
 *
 * @param compliance the given compliance
 * @param options the given options map
 * @since 3.3
 */
public static void setComplianceOptions(String compliance, Map options) {
	switch((int) (CompilerOptions.versionToJdkLevel(compliance) >>> 16)) {
		case ClassFileConstants.MAJOR_VERSION_1_3:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.IGNORE);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.IGNORE);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_4:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.WARNING);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.WARNING);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_5:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_6:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
			break;
		case ClassFileConstants.MAJOR_VERSION_1_7:
			options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
			options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
			options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:65,代码来源:JavaCore.java

示例14: createScanner

import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; //导入方法依赖的package包/类
/**
 * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be
 * used to tokenize some source in a Java aware way.
 * Here is a typical scanning loop:
 *
 * <code>
 * <pre>
 *   IScanner scanner = ToolFactory.createScanner(false, false, false, false);
 *   scanner.setSource("int i = 0;".toCharArray());
 *   while (true) {
 *     int token = scanner.getNextToken();
 *     if (token == ITerminalSymbols.TokenNameEOF) break;
 *     System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
 *   }
 * </pre>
 * </code>
 *
 * <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE
 * or 1.4 if running from outside of a headless eclipse.
 * </p>
 *
 * @param tokenizeComments if set to <code>false</code>, comments will be silently consumed
 * @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed,
 * @param assertMode if set to <code>false</code>, occurrences of 'assert' will be reported as identifiers
 * ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>true</code>, it
 * would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced
 * a new 'assert' keyword.
 * @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line
 * separator ends. In case of multi-character line separators, the last character position is considered. These positions
 * can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are
 * considered as valid line separators.
 	 * @return a scanner
 * @see org.eclipse.jdt.core.compiler.IScanner
 * @see #createScanner(boolean, boolean, boolean, String, String)
 */
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator){
	// use default workspace compliance
	long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE));
	if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance
	PublicScanner scanner =
		new PublicScanner(
			tokenizeComments,
			tokenizeWhiteSpace,
			false/*nls*/,
			assertMode ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3/*sourceLevel*/,
			complianceLevelValue,
			null/*taskTags*/,
			null/*taskPriorities*/,
			true/*taskCaseSensitive*/);
	scanner.recordLineSeparator = recordLineSeparator;
	return scanner;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:53,代码来源:ToolFactory.java


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