List of usage examples for com.google.common.io CharStreams nullWriter
public static Writer nullWriter()
From source file:eu.itesla_project.iidm.import_.JavaScriptPostProcessor.java
@Override public void process(Network network, ComputationManager computationManager) throws Exception { Path js = PlatformConfig.CONFIG_DIR.resolve("import-post-processor.js"); if (Files.exists(js)) { LOGGER.debug("Execute JS post processor {}", js); try (Reader reader = Files.newBufferedReader(js)) { Networks.runScript(network, reader, printToStdOut ? null : CharStreams.nullWriter()); }/*w w w .java2s . c o m*/ } }
From source file:com.google.errorprone.refaster.CodeTransformerTestHelper.java
public JavaFileObject transform(JavaFileObject original) { JavaCompiler compiler = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, Locale.ENGLISH, UTF_8);//w w w. j ava 2 s . c o m JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, ImmutableList.<String>of(), null, ImmutableList.of(original)); try { SourceFile sourceFile = SourceFile.create(original); Iterable<? extends CompilationUnitTree> trees = task.parse(); task.analyze(); JCCompilationUnit tree = Iterables.getOnlyElement(Iterables.filter(trees, JCCompilationUnit.class)); DescriptionBasedDiff diff = DescriptionBasedDiff.create(tree); transformer().apply(new TreePath(tree), task.getContext(), diff); diff.applyDifferences(sourceFile); return JavaFileObjects.forSourceString( Iterables.getOnlyElement(Iterables.filter(tree.getTypeDecls(), JCClassDecl.class)).sym .getQualifiedName().toString(), sourceFile.getSourceText()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.google.gerrit.server.project.Index.java
@Override public Response.Accepted apply(ProjectResource resource, ProjectInput input) { Project.NameKey project = resource.getNameKey(); Task mpt = new MultiProgressMonitor(ByteStreams.nullOutputStream(), "Reindexing project").beginSubTask("", MultiProgressMonitor.UNKNOWN); PrintWriter pw = new PrintWriter(CharStreams.nullWriter()); executor.submit(allChangesIndexer.reindexProject(indexer, project, mpt, mpt, pw)); return Response.accepted("Project " + project + " submitted for reindexing"); }
From source file:com.google.errorprone.analysis.RecompilingTopLevelAnalysis.java
private static boolean compiles(Fix fix, JCCompilationUnit compilationUnit, Context context) { final NavigableSet<Replacement> replacements = new TreeSet<>(ByStartPosition.INSTANCE); replacements.addAll(fix.getReplacements(compilationUnit.endPositions)); JavaFileObject modifiedFile = compilationUnit.getSourceFile(); if (replacements.isEmpty()) { return true; }/*w ww .ja va 2 s . c om*/ JavacTaskImpl javacTask = (JavacTaskImpl) context.get(JavacTask.class); if (javacTask == null) { throw new IllegalArgumentException("No JavacTask in context."); } List<JavaFileObject> fileObjects = new ArrayList<>(fileObjectsForTask(javacTask)); for (int i = 0; i < fileObjects.size(); i++) { final JavaFileObject oldFile = fileObjects.get(i); if (modifiedFile.toUri().equals(oldFile.toUri())) { fileObjects.set(i, new SimpleJavaFileObject(modifiedFile.toUri(), Kind.SOURCE) { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { StringBuilder builder = new StringBuilder(oldFile.getCharContent(ignoreEncodingErrors)); for (Replacement replacement : replacements.descendingSet()) { builder.replace(replacement.startPosition(), replacement.endPosition(), replacement.replaceWith()); } return builder; } }); break; } } JavaCompiler compiler = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticListener = new DiagnosticCollector<>(); JavacTask newTask = (JavacTask) compiler.getTask(CharStreams.nullWriter(), context.get(JavaFileManager.class), diagnosticListener, asListOrNull(argsForTask(javacTask)), asListOrNull(classesForTask(javacTask)), fileObjects); try { newTask.analyze(); } catch (Throwable e) { return false; } return countErrors(diagnosticListener) == 0; }
From source file:com.pressassociation.pr.filter.json.jackson.JacksonMatcherFilter.java
private void processFirstPass(Node parentNode, Object pojo, SerializerProvider provider, PropertyWriter writer, JsonGenerator generator) throws Exception { State state = this.state.get(); Leaf leaf = Leaf.copyOf(state.propertyPath); // if this property _can_ contribute towards the path leading to a matching leaf then we have to check boolean matches = matcher.matches(leaf); if (matches || matcher.matchesParent(leaf)) { if (parentNode.isRoot()) { // make sure we don't actually write anything to the output, only replace if we are the root node, it will // be passed to other nodes as needed via recursive calls generator = new JsonFactory().createGenerator(CharStreams.nullWriter()); }//from w w w. j av a2 s . c o m // prepare a node for this property so child branches can add to it as needed state.currentNode = new Node(parentNode, writer.getName()); writer.serializeAsField(pojo, generator, provider); // check the results of processing the children if (state.currentNode.isEmpty()) { // either we don't have any children or none of them are matching leaves. // in any case if (matches) { // it turns out we match anyway so add this node parentNode.addChild(state.currentNode); } } else { // child leafs match so we need to include this node as a parent of them parentNode.addChild(state.currentNode); } } }
From source file:com.google.errorprone.BugCheckerRefactoringTestHelper.java
private JCCompilationUnit doCompile(final JavaFileObject input, Iterable<JavaFileObject> files, Context context) throws IOException { JavacTool tool = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>(); context.put(ErrorProneOptions.class, ErrorProneOptions.empty()); JavacTaskImpl task = (JavacTaskImpl) tool.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, options, /*classes=*/ null, files, context); Iterable<? extends CompilationUnitTree> trees = task.parse(); task.analyze();/*from w w w . j a v a2 s.c o m*/ JCCompilationUnit tree = Iterables .getOnlyElement(Iterables.filter(Iterables.filter(trees, JCCompilationUnit.class), compilationUnit -> compilationUnit.getSourceFile() == input)); Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables .filter(diagnosticsCollector.getDiagnostics(), d -> d.getKind() == Diagnostic.Kind.ERROR); if (!Iterables.isEmpty(errorDiagnostics)) { fail("compilation failed unexpectedly: " + errorDiagnostics); } return tree; }