List of usage examples for org.eclipse.jdt.core JavaCore VERSION_1_8
String VERSION_1_8
To view the source code for org.eclipse.jdt.core JavaCore VERSION_1_8.
Click Source Link
From source file:boa.test.datagen.Java8BaseTest.java
License:Apache License
private static void setJava8() { astLevel = AST.JLS8;// w w w .j av a2s . c om javaVersion = JavaCore.VERSION_1_8; visitor = new Java8Visitor("", new HashMap<String, Integer>()); }
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 .java 2 s . c o 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: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);// www.j av a2 s .com c.accept(v); return v.getTreeContext(); }
From source file:com.facebook.nuclide.debugger.EvaluationManager.java
License:Open Source License
private CompilationUnit compileSource(String source, String sourceFilePath, String unitName, StringBuilder errors) throws Exception { if (!unitName.endsWith(".java")) { // The AST compiler is surprisingly insistent about this. unitName += ".java"; }/* ww w.j a va2s .c om*/ final File sourceFile = new File(sourceFilePath); final String directoryPath = sourceFile.getAbsoluteFile().getParent(); Utils.logVerbose("compiling source for: " + directoryPath); final String[] sources = _contextManager.getSourceLocator().getSourceSearchPaths(); final String[] classpath = _contextManager.getSourceLocator().getBinaryJarPaths(); final ASTParser parser = ASTParser.newParser(AST.JLS8); final Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); parser.setUnitName(unitName); parser.setResolveBindings(true); parser.setStatementsRecovery(true); parser.setBindingsRecovery(true); parser.setEnvironment(classpath, sources, null, true); parser.setSource(source.toCharArray()); CompilationUnit unit = (CompilationUnit) parser.createAST(null); String errorMsg = checkUnitForProblems(unit); if (errorMsg != null) { errors.append(errorMsg); } return unit; }
From source file:com.facebook.nuclide.shim.EclipseJavaElementShim.java
License:Open Source License
@Override public ISourceRange getNameRange() throws JavaModelException { if (_sourceRange != null) { return _sourceRange; }//from www. jav a 2 s .c o m // We need to determine the location in the source at which this type // is declared. Compute an AST from the source file, and fine the declaring // node. ICompilationUnit unit = getCompilationUnit(); ASTParser parser = ASTParser.newParser(AST.JLS8); Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); try { parser.setSource(unit.getSource().toCharArray()); } catch (Exception ex) { return new SourceRange(0, 0); } final String targetName = fixTargetName(_refType.name()); CompilationUnit ast = (CompilationUnit) parser.createAST(null); ast.accept(new ASTVisitor(false) { public boolean visit(TypeDeclaration node) { SimpleName name = getNodeDeclName(node); if (name.getFullyQualifiedName().equals(targetName)) { _sourceRange = new SourceRange(name.getStartPosition(), name.getLength()); // No need to continue processing, we've found what we're looking for. return false; } return true; } }); if (_sourceRange != null) { return _sourceRange; } // Can't return null or the source generator will die. return new SourceRange(0, 1); }
From source file:com.facebook.nuclide.shim.EclipseJavaProjectShim.java
License:Open Source License
@Override public Map getOptions(boolean inheritJavaCoreOptions) { final Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); return options; }
From source file:com.github.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); parser.setCompilerOptions(pOptions); parser.setSource(readerToCharArray(r)); AbstractJdtVisitor v = createVisitor(); parser.createAST(null).accept(v);//from w w w .j a v a 2 s . co m return v.getTreeContext(); }
From source file:com.google.googlejavaformat.java.Formatter.java
License:Apache License
/** * Construct a {@code Formatter} given Java compilation unit. Parses the code; builds a * {@link JavaInput} and the corresponding {@link JavaOutput}. * @param javaInput the input, a Java compilation unit * @param javaOutput the {@link JavaOutput} * @param maxWidth the maximum formatted width * @param errors mutable list to receive errors * @param indentationMultiplier the multiplier for the unit of indent; the default is 1 *//*from ww w. ja v a 2 s. c om*/ static void format(JavaInput javaInput, JavaOutput javaOutput, int maxWidth, List<FormatterDiagnostic> errors, int indentationMultiplier) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(javaInput.getText().toCharArray()); @SuppressWarnings("unchecked") // safe by specification Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options); CompilationUnit unit = (CompilationUnit) parser.createAST(null); javaInput.setCompilationUnit(unit); if (unit.getMessages().length > 0) { for (Message message : unit.getMessages()) { errors.add(javaInput.createDiagnostic(message.getStartPosition(), message.getMessage())); } return; } OpsBuilder builder = new OpsBuilder(javaInput, javaOutput, errors); // Output compilation unit. new JavaInputAstVisitor(builder, indentationMultiplier).visit(unit); builder.sync(javaInput.getText().length()); builder.drain(); Doc doc = new DocBuilder().withOps(builder.build()).build(); doc.computeBreaks(javaOutput.getCommentsHelper(), maxWidth, new Doc.State(+0, 0, 0)); doc.write(javaOutput); javaOutput.flush(); }
From source file:com.google.googlejavaformat.java.RemoveUnusedImports.java
License:Open Source License
private static CompilationUnit parse(String source) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(source.toCharArray()); Map<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); parser.setCompilerOptions(options);/*from w w w . ja v a2 s . c o m*/ CompilationUnit unit = (CompilationUnit) parser.createAST(null); if (unit.getMessages().length > 0) { // error handling is done during formatting return null; } return unit; }
From source file:com.jaxio.celerio.output.EclipseCodeFormatter.java
License:Apache License
@SuppressWarnings({ "unchecked", "deprecation" }) public void setFormatterSettings(List<Setting> settings) { // // change the option to wrap each enum constant on a new line // options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, // DefaultCodeFormatterConstants.createAlignmentValue(true, // DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, // DefaultCodeFormatterConstants.INDENT_ON_COLUMN)); ////from www.j av a 2 s. com if (settings != null) { options = newHashMap(); for (Setting s : settings) { options.put(s.getId(), s.getValue()); } } else { options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); 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); options.put(JavaCore.FORMATTER_LINE_SPLIT, "160"); options.put(JavaCore.FORMATTER_TAB_CHAR, JavaCore.SPACE); options.put(JavaCore.FORMATTER_TAB_SIZE, "4"); } // instanciate the default code formatter with the given options codeFormatter = ToolFactory.createCodeFormatter(options); }