List of usage examples for org.eclipse.jdt.core JavaCore COMPILER_CODEGEN_TARGET_PLATFORM
String COMPILER_CODEGEN_TARGET_PLATFORM
To view the source code for org.eclipse.jdt.core JavaCore COMPILER_CODEGEN_TARGET_PLATFORM.
Click Source Link
From source file:br.uff.ic.gems.resources.ast.ASTExtractor.java
public void parser() throws IOException { ASTParser parser = ASTParser.newParser(AST.JLS3); File file = new File(filePath); String stringFile = FileUtils.readFileToString(file); parser.setSource(stringFile.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); //Setting options Map options;/* w w w.j av a 2 s .c om*/ options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); parser.setCompilerOptions(options); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); Visitor visitor = new Visitor(cu); cu.accept(visitor); List<Comment> commentList = cu.getCommentList(); for (Comment comment : commentList) { comment.accept(visitor); } languageConstructs = visitor.getLanguageConstructs(); }
From source file:br.uff.ic.mergeguider.javaparser.JavaParser.java
private Storage generateASTs(String path) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setResolveBindings(true);/*from w w w . j ava 2 s . co m*/ parser.setBindingsRecovery(true); Map options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8); parser.setCompilerOptions(options); String[] srcDirs = FileUtils.getAllDirs(path); String[] javaFiles = FileUtils.getAllJavaFiles(path); parser.setEnvironment(null, srcDirs, null, true); Storage storage = new Storage(); parser.createASTs(javaFiles, null, new String[0], storage, null); return storage; }
From source file:ch.acanda.eclipse.pmd.java.resolution.ASTQuickFixTestCase.java
License:Open Source License
private CompilationUnit createAST(final org.eclipse.jface.text.Document document, final ASTQuickFix<ASTNode> quickFix) { final ASTParser astParser = ASTParser.newParser(AST.JLS4); astParser.setSource(document.get().toCharArray()); astParser.setKind(ASTParser.K_COMPILATION_UNIT); astParser.setResolveBindings(quickFix.needsTypeResolution()); astParser.setEnvironment(new String[0], new String[0], new String[0], true); final String name = last(params.pmdReferenceId.or("QuickFixTest").split("/")); astParser.setUnitName(format("{0}.java", name)); final String version = last(params.language.or("java 1.7").split("\\s+")); astParser.setCompilerOptions(ImmutableMap.<String, String>builder().put(JavaCore.COMPILER_SOURCE, version) .put(JavaCore.COMPILER_COMPLIANCE, version).put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, version) .build());// w w w . ja va2 s . c o m final CompilationUnit ast = (CompilationUnit) astParser.createAST(null); ast.recordModifications(); return ast; }
From source file:chibi.gumtreediff.gen.jdt.AbstractJdtTreeGenerator.java
License:Open Source License
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public TreeContext generate(Reader r) throws IOException { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setKind(ASTParser.K_COMPILATION_UNIT); Map pOptions = JavaCore.getOptions(); pOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8); pOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8); pOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8); pOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(pOptions); parser.setSource(readerToCharArray(r)); AbstractJdtVisitor v = createVisitor(); CompilationUnit c = (CompilationUnit) parser.createAST(null); v.setTreeRoot(c);// ww w. j a va2 s. com c.accept(v); return v.getTreeContext(); }
From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java
License:Open Source License
/** * Checks the project compiler compliance level is supported. * @param javaProject The project to check * @return A pair with the first integer being an error code, and the second value * being the invalid value found or null. The error code can be: <ul> * <li><code>COMPILER_COMPLIANCE_OK</code> if the project is properly configured</li> * <li><code>COMPILER_COMPLIANCE_LEVEL</code> for unsupported compiler level</li> * <li><code>COMPILER_COMPLIANCE_SOURCE</code> for unsupported source compatibility</li> * <li><code>COMPILER_COMPLIANCE_CODEGEN_TARGET</code> for unsupported .class format</li> * </ul>/* w ww.j a va2 s . c o m*/ */ public static final Pair<Integer, String> checkCompilerCompliance(IJavaProject javaProject) { // get the project compliance level option String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); // check it against a list of valid compliance level strings. if (!checkCompliance(javaProject, compliance)) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_LEVEL, compliance); } // otherwise we check source compatibility String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); // check it against a list of valid compliance level strings. if (!checkCompliance(javaProject, source)) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_SOURCE, source); } // otherwise check codegen level String codeGen = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); // check it against a list of valid compliance level strings. if (!checkCompliance(javaProject, codeGen)) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_CODEGEN_TARGET, codeGen); } return Pair.of(COMPILER_COMPLIANCE_OK, null); }
From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java
License:Open Source License
/** * Checks, and fixes if needed, the compiler compliance level, and the source compatibility * level//from ww w. j a v a 2 s. c om * @param javaProject The Java project to check and fix. */ public static final void checkAndFixCompilerCompliance(IJavaProject javaProject) { Pair<Integer, String> result = checkCompilerCompliance(javaProject); if (result.getFirst().intValue() != COMPILER_COMPLIANCE_OK) { // setup the preferred compiler compliance level. javaProject.setOption(JavaCore.COMPILER_COMPLIANCE, AdtConstants.COMPILER_COMPLIANCE_PREFERRED); javaProject.setOption(JavaCore.COMPILER_SOURCE, AdtConstants.COMPILER_COMPLIANCE_PREFERRED); javaProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, AdtConstants.COMPILER_COMPLIANCE_PREFERRED); // clean the project to make sure we recompile try { javaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); } catch (CoreException e) { AdtPlugin.printErrorToConsole(javaProject.getProject(), "Project compiler settings changed. Clean your project."); } } }
From source file:com.android.ide.eclipse.adt.project.ProjectHelper.java
License:Open Source License
/** * Checks the project compiler compliance level is supported. * @param javaProject The project to check * @return <ul>// ww w .j a va 2 s .com * <li><code>COMPILER_COMPLIANCE_OK</code> if the project is properly configured</li> * <li><code>COMPILER_COMPLIANCE_LEVEL</code> for unsupported compiler level</li> * <li><code>COMPILER_COMPLIANCE_SOURCE</code> for unsupported source compatibility</li> * <li><code>COMPILER_COMPLIANCE_CODEGEN_TARGET</code> for unsupported .class format</li> * </ul> */ public static final int checkCompilerCompliance(IJavaProject javaProject) { // get the project compliance level option String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); // check it against a list of valid compliance level strings. if (checkCompliance(compliance) == false) { // if we didn't find the proper compliance level, we return an error return COMPILER_COMPLIANCE_LEVEL; } // otherwise we check source compatibility String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); // check it against a list of valid compliance level strings. if (checkCompliance(source) == false) { // if we didn't find the proper compliance level, we return an error return COMPILER_COMPLIANCE_SOURCE; } // otherwise check codegen level String codeGen = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); // check it against a list of valid compliance level strings. if (checkCompliance(codeGen) == false) { // if we didn't find the proper compliance level, we return an error return COMPILER_COMPLIANCE_CODEGEN_TARGET; } return COMPILER_COMPLIANCE_OK; }
From source file:com.android.ide.eclipse.adt.project.ProjectHelper.java
License:Open Source License
/** * Checks, and fixes if needed, the compiler compliance level, and the source compatibility * level//from w w w . j a va 2s . c o m * @param javaProject The Java project to check and fix. */ public static final void checkAndFixCompilerCompliance(IJavaProject javaProject) { if (checkCompilerCompliance(javaProject) != COMPILER_COMPLIANCE_OK) { // setup the preferred compiler compliance level. javaProject.setOption(JavaCore.COMPILER_COMPLIANCE, AndroidConstants.COMPILER_COMPLIANCE_PREFERRED); javaProject.setOption(JavaCore.COMPILER_SOURCE, AndroidConstants.COMPILER_COMPLIANCE_PREFERRED); javaProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, AndroidConstants.COMPILER_COMPLIANCE_PREFERRED); // clean the project to make sure we recompile try { javaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); } catch (CoreException e) { AdtPlugin.printErrorToConsole(javaProject.getProject(), "Project compiler settings changed. Clean your project."); } } }
From source file:com.android.ide.eclipse.auidt.internal.project.ProjectHelper.java
License:Open Source License
/** * Checks the project compiler compliance level is supported. * @param javaProject The project to check * @return A pair with the first integer being an error code, and the second value * being the invalid value found or null. The error code can be: <ul> * <li><code>COMPILER_COMPLIANCE_OK</code> if the project is properly configured</li> * <li><code>COMPILER_COMPLIANCE_LEVEL</code> for unsupported compiler level</li> * <li><code>COMPILER_COMPLIANCE_SOURCE</code> for unsupported source compatibility</li> * <li><code>COMPILER_COMPLIANCE_CODEGEN_TARGET</code> for unsupported .class format</li> * </ul>/*from w w w .j av a 2 s .c om*/ */ public static final Pair<Integer, String> checkCompilerCompliance(IJavaProject javaProject) { // get the project compliance level option String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); // check it against a list of valid compliance level strings. if (checkCompliance(compliance) == false) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_LEVEL, compliance); } // otherwise we check source compatibility String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); // check it against a list of valid compliance level strings. if (checkCompliance(source) == false) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_SOURCE, source); } // otherwise check codegen level String codeGen = javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); // check it against a list of valid compliance level strings. if (checkCompliance(codeGen) == false) { // if we didn't find the proper compliance level, we return an error return Pair.of(COMPILER_COMPLIANCE_CODEGEN_TARGET, codeGen); } return Pair.of(COMPILER_COMPLIANCE_OK, null); }
From source file:com.android.ide.eclipse.mock.JavaProjectMock.java
License:Open Source License
public String getOption(String optionName, boolean inheritJavaCoreOptions) { if (optionName.equals(JavaCore.COMPILER_COMPLIANCE)) { return mCompilerCompliance; } else if (optionName.equals(JavaCore.COMPILER_SOURCE)) { return mCompilerSource; } else if (optionName.equals(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM)) { return mCompilerTarget; }/* w ww .j a v a2 s. co m*/ return null; }