1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.annotationvisitor; 18 19 import java.util.Locale; 20 21 public class Status { 22 23 // Highlight "Error:" in red. 24 private static final String ERROR = "\u001B[31mError: \u001B[0m"; 25 26 // Highlight "Warning:" in yellow. 27 private static final String WARNING = "\u001B[33mWarning: \u001B[0m"; 28 29 private final boolean mDebug; 30 private boolean mHasErrors; 31 Status(boolean debug)32 public Status(boolean debug) { 33 mDebug = debug; 34 } 35 debug(String msg, Object... args)36 public void debug(String msg, Object... args) { 37 if (mDebug) { 38 System.err.println(String.format(Locale.US, msg, args)); 39 } 40 } 41 error(Throwable t)42 public void error(Throwable t) { 43 System.err.print(ERROR); 44 t.printStackTrace(System.err); 45 mHasErrors = true; 46 } 47 error(String message, Object... args)48 public void error(String message, Object... args) { 49 System.err.print(ERROR); 50 System.err.println(String.format(Locale.US, message, args)); 51 mHasErrors = true; 52 } 53 warning(String message, Object... args)54 public void warning(String message, Object... args) { 55 System.err.print(WARNING); 56 System.err.println(String.format(Locale.US, message, args)); 57 } 58 ok()59 public boolean ok() { 60 return !mHasErrors; 61 } 62 } 63