/** Parse a single file and report the errors/warnings */ static DartUnit parse( AnalysisServer server, File libraryFile, LibrarySource librarySource, File sourceFile) { ErrorListener errorListener = new ErrorListener(server); DartSource source = new UrlDartSource(sourceFile, librarySource); String sourceCode = null; try { sourceCode = FileUtilities.getContents(sourceFile); } catch (IOException e) { errorListener.onError(newIoError(source, e)); } DartUnit dartUnit = null; if (sourceCode != null) { try { DartParser parser = new DartParser(source, sourceCode, errorListener); dartUnit = parser.parseUnit(source); } catch (Throwable e) { DartCore.logError("Exception while parsing " + sourceFile.getPath(), e); errorListener.onError(newParseFailure(source, e)); } } errorListener.notifyParsed(libraryFile, sourceFile, dartUnit); return dartUnit != null ? dartUnit : new DartUnit(source, false); }
private static void formatFile(IFile file, IProgressMonitor monitor) throws UnsupportedEncodingException, CoreException, IOException { Reader reader = new InputStreamReader(file.getContents(), file.getCharset()); String contents = FileUtilities.getContents(reader); if (contents != null) { FormattedSource result = format(contents, null, monitor); if (!contents.equals(result.source)) { InputStream stream = new ByteArrayInputStream(result.source.getBytes("UTF-8")); file.setContents(stream, IResource.KEEP_HISTORY, monitor); } } }