本文整理汇总了Java中org.eclipse.jdt.internal.corext.util.JavaModelUtil.setComplianceOptions方法的典型用法代码示例。如果您正苦于以下问题:Java JavaModelUtil.setComplianceOptions方法的具体用法?Java JavaModelUtil.setComplianceOptions怎么用?Java JavaModelUtil.setComplianceOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.util.JavaModelUtil
的用法示例。
在下文中一共展示了JavaModelUtil.setComplianceOptions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEEOptions
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Returns the compliance options from the given EE. If the result is not <code>null</code>,
* it contains at least these core options:
* <ul>
* <li>{@link JavaCore#COMPILER_COMPLIANCE}</li>
* <li>{@link JavaCore#COMPILER_SOURCE}</li>
* <li>{@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}</li>
* <li>{@link JavaCore#COMPILER_PB_ASSERT_IDENTIFIER}</li>
* <li>{@link JavaCore#COMPILER_PB_ENUM_IDENTIFIER}</li>
* <li>{@link JavaCore#COMPILER_CODEGEN_INLINE_JSR_BYTECODE} for compliance levels 1.5 and greater</li>
* </ul>
*
* @param ee the EE, can be <code>null</code>
* @return the options, or <code>null</code> if none
* @since 3.5
*/
public static Map<String, String> getEEOptions(IExecutionEnvironment ee) {
if (ee == null)
return null;
Map<String, String> eeOptions= ee.getComplianceOptions();
if (eeOptions == null)
return null;
Object complianceOption= eeOptions.get(JavaCore.COMPILER_COMPLIANCE);
if (!(complianceOption instanceof String))
return null;
// eeOptions can miss some options, make sure they are complete:
HashMap<String, String> options= new HashMap<String, String>();
JavaModelUtil.setComplianceOptions(options, (String)complianceOption);
options.putAll(eeOptions);
return options;
}
示例2: testMismatchingReturnTypeOnGenericMethod14
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
@Test
public void testMismatchingReturnTypeOnGenericMethod14() throws Exception {
Map<String, String> options14 = new HashMap<>(fJProject1.getOptions(false));
JavaModelUtil.setComplianceOptions(options14, JavaCore.VERSION_1_4);
fJProject1.setOptions(options14);
IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("import java.lang.reflect.AccessibleObject;\n");
buf.append("public class E {\n");
buf.append(" void m() {\n");
buf.append(" new AccessibleObject() {\n");
buf.append(" public void getAnnotation(Class annotationClass) {\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("import java.lang.annotation.Annotation;\n");
buf.append("import java.lang.reflect.AccessibleObject;\n");
buf.append("public class E {\n");
buf.append(" void m() {\n");
buf.append(" new AccessibleObject() {\n");
buf.append(" public Annotation getAnnotation(Class annotationClass) {\n");
buf.append(" }\n");
buf.append(" };\n");
buf.append(" }\n");
buf.append("}\n");
Expected e1 = new Expected("Change return type of 'getAnnotation(..)' to 'Annotation'", buf.toString());
assertCodeActions(cu, e1);
}
示例3: parseSuperType
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private static Type parseSuperType(String superType, boolean isInterface) {
if (! superType.trim().equals(superType)) {
return null;
}
StringBuffer cuBuff= new StringBuffer();
if (isInterface)
cuBuff.append("class __X__ implements "); //$NON-NLS-1$
else
cuBuff.append("class __X__ extends "); //$NON-NLS-1$
int offset= cuBuff.length();
cuBuff.append(superType).append(" {}"); //$NON-NLS-1$
ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
p.setSource(cuBuff.toString().toCharArray());
Map<String, String> options= new HashMap<String, String>();
JavaModelUtil.setComplianceOptions(options, JavaModelUtil.VERSION_LATEST);
p.setCompilerOptions(options);
CompilationUnit cu= (CompilationUnit) p.createAST(null);
ASTNode selected= NodeFinder.perform(cu, offset, superType.length());
if (selected instanceof Name)
selected= selected.getParent();
if (selected.getStartPosition() != offset
|| selected.getLength() != superType.length()
|| ! (selected instanceof Type)
|| selected instanceof PrimitiveType) {
return null;
}
Type type= (Type) selected;
String typeNodeRange= cuBuff.substring(type.getStartPosition(), ASTNodes.getExclusiveEnd(type));
if (! superType.equals(typeNodeRange)){
return null;
}
return type;
}
示例4: parseCus
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public static List<ParsedCu> parseCus(IJavaProject javaProject, String compilerCompliance, String text) {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
if (javaProject != null) {
parser.setProject(javaProject);
} else if (compilerCompliance != null) {
Map<String, String> options= JavaCore.getOptions();
JavaModelUtil.setComplianceOptions(options, compilerCompliance);
parser.setCompilerOptions(options);
}
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
CompilationUnit unit= (CompilationUnit) parser.createAST(null);
if (unit.types().size() > 0)
return parseAsTypes(text, unit);
parser.setProject(javaProject);
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
ASTNode root= parser.createAST(null);
if (root instanceof TypeDeclaration) {
List<BodyDeclaration> bodyDeclarations= ((TypeDeclaration) root).bodyDeclarations();
if (bodyDeclarations.size() > 0)
return Collections.singletonList(new ParsedCu(text, ASTParser.K_CLASS_BODY_DECLARATIONS, null, null));
}
parser.setProject(javaProject);
parser.setSource(text.toCharArray());
parser.setStatementsRecovery(true);
parser.setKind(ASTParser.K_STATEMENTS);
root= parser.createAST(null);
if (root instanceof Block) {
List<Statement> statements= ((Block) root).statements();
if (statements.size() > 0)
return Collections.singletonList(new ParsedCu(text, ASTParser.K_STATEMENTS, null, null));
}
return Collections.emptyList();
}
示例5: JavaPreview
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
public JavaPreview(Map<String, String> workingValues, Composite parent) {
JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
fPreviewDocument= new Document();
fWorkingValues= workingValues;
tools.setupJavaDocumentPartitioner( fPreviewDocument, IJavaPartitions.JAVA_PARTITIONING);
PreferenceStore prioritizedSettings= new PreferenceStore();
HashMap<String, String> complianceOptions= new HashMap<String, String>();
JavaModelUtil.setComplianceOptions(complianceOptions, JavaModelUtil.VERSION_LATEST);
for (Entry<String, String> complianceOption : complianceOptions.entrySet()) {
prioritizedSettings.setValue(complianceOption.getKey(), complianceOption.getValue());
}
IPreferenceStore[] chain= { prioritizedSettings, JavaPlugin.getDefault().getCombinedPreferenceStore() };
fPreferenceStore= new ChainedPreferenceStore(chain);
fSourceViewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore);
fSourceViewer.setEditable(false);
Cursor arrowCursor= fSourceViewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
fSourceViewer.getTextWidget().setCursor(arrowCursor);
// Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263
// fSourceViewer.getTextWidget().setCaret(null);
fViewerConfiguration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, IJavaPartitions.JAVA_PARTITIONING, true);
fSourceViewer.configure(fViewerConfiguration);
fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
fMarginPainter= new MarginPainter(fSourceViewer);
final RGB rgb= PreferenceConverter.getColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb));
fSourceViewer.addPainter(fMarginPainter);
new JavaSourcePreviewerUpdater();
fSourceViewer.setDocument(fPreviewDocument);
}
示例6: setDefaultCompilerComplianceValues
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* 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()));
}
}
示例7: setLatestCompliance
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
private static void setLatestCompliance(Map<String, String> map) {
JavaModelUtil.setComplianceOptions(map, JavaModelUtil.VERSION_LATEST);
}
示例8: setLatestCompliance
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; //导入方法依赖的package包/类
/**
* Updates the map to use the latest the source compliance
* @param map The map to update
*/
public static void setLatestCompliance(Map<String, String> map) {
JavaModelUtil.setComplianceOptions(map, JavaModelUtil.VERSION_LATEST);
}