OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.errorprone; |
| 6 |
| 7 import com.google.errorprone.BugPattern; |
| 8 import com.google.errorprone.ErrorProneOptions; |
| 9 import com.google.errorprone.ErrorProneScanner; |
| 10 import com.google.errorprone.ErrorReportingJavaCompiler; |
| 11 import com.google.errorprone.JDKCompatible; |
| 12 import com.google.errorprone.Scanner; |
| 13 import com.google.errorprone.bugpatterns.BugChecker; |
| 14 |
| 15 import com.sun.tools.javac.file.JavacFileManager; |
| 16 import com.sun.tools.javac.main.Main; |
| 17 import com.sun.tools.javac.util.Context; |
| 18 import com.sun.tools.javac.util.List; |
| 19 |
| 20 import java.io.PrintWriter; |
| 21 import java.util.HashSet; |
| 22 import java.util.Set; |
| 23 |
| 24 import javax.tools.JavaFileObject; |
| 25 |
| 26 /** |
| 27 * Configures (and compiles with) the error-prone java compiler. |
| 28 */ |
| 29 public class ChromiumErrorProneCompiler { |
| 30 |
| 31 public static void main(String[] args) { |
| 32 System.exit(compile(args)); |
| 33 } |
| 34 |
| 35 private static int compile(String[] args) { |
| 36 PrintWriter printWriter = new PrintWriter(System.err, true); |
| 37 Main main = new Main("javac (chromium-error-prone)", printWriter); |
| 38 Context context = new Context(); |
| 39 JavacFileManager.preRegister(context); |
| 40 |
| 41 ErrorProneOptions epOptions = ErrorProneOptions.processArgs(args); |
| 42 final Set<String> disabledChecks = new HashSet<String>(epOptions.getDisa
bledChecks()); |
| 43 |
| 44 Scanner scannerInContext = new ErrorProneScanner(new ErrorProneScanner.E
nabledPredicate() { |
| 45 @Override |
| 46 public boolean isEnabled(Class<? extends BugChecker> check, BugPatte
rn annotation) { |
| 47 return !disabledChecks.contains(check.getCanonicalName()); |
| 48 } |
| 49 }); |
| 50 context.put(Scanner.class, scannerInContext); |
| 51 |
| 52 ErrorReportingJavaCompiler.preRegister(context); |
| 53 return JDKCompatible.runCompile( |
| 54 main, epOptions.getRemainingArgs(), context, List.<JavaFileObjec
t>nil(), null); |
| 55 } |
| 56 |
| 57 } |
OLD | NEW |