PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/orc/error/compiletime/PrintWriterCompileLogger.java

https://github.com/laurenyew/cOrcS
Java | 113 lines | 50 code | 16 blank | 47 comment | 7 complexity | 64fe1a6de684fc5e764774bab37db955 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. //
  2. // PrintWriterCompileLogger.java -- Java class PrintWriterCompileLogger
  3. // Project OrcScala
  4. //
  5. // $Id: PrintWriterCompileLogger.java 2235 2010-12-08 05:48:20Z jthywissen $
  6. //
  7. // Created by jthywiss on Aug 19, 2009.
  8. //
  9. // Copyright (c) 2010 The University of Texas at Austin. All rights reserved.
  10. //
  11. // Use and redistribution of this file is governed by the license terms in
  12. // the LICENSE file found in the project's top-level directory and also found at
  13. // URL: http://orc.csres.utexas.edu/license.shtml .
  14. //
  15. package orc.error.compiletime;
  16. import java.io.PrintWriter;
  17. import orc.ast.AST;
  18. import scala.util.parsing.input.Position;
  19. /**
  20. * A CompileMessageRecorder that writes messages to a PrintWriter (such
  21. * as one for stderr).
  22. *
  23. * @author jthywiss
  24. */
  25. public class PrintWriterCompileLogger implements CompileLogger {
  26. private PrintWriter outWriter;
  27. private Severity maxSeverity = Severity.UNKNOWN;
  28. /**
  29. * Constructs an object of class PrintWriterCompileLogger.
  30. *
  31. * @param logToWriter the Writer configuration in use.
  32. */
  33. public PrintWriterCompileLogger(final PrintWriter logToWriter) {
  34. if (logToWriter == null) {
  35. throw new NullPointerException("Cannot construct PrintWriterCompileLogger with a null PrintWriter");
  36. }
  37. outWriter = logToWriter;
  38. }
  39. /* (non-Javadoc)
  40. * @see orc.error.compiletime.CompileLogger#beginProcessing(java.lang.String)
  41. */
  42. @Override
  43. public void beginProcessing(final String filename) {
  44. if (outWriter == null) {
  45. throw new NullPointerException("Cannot use a options with a null stderr");
  46. }
  47. maxSeverity = Severity.UNKNOWN;
  48. }
  49. /* (non-Javadoc)
  50. * @see orc.error.compiletime.CompileLogger#endProcessing(java.lang.String)
  51. */
  52. @Override
  53. public void endProcessing(final String filename) {
  54. // Nothing needed
  55. }
  56. /* (non-Javadoc)
  57. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, AST, Throwable)
  58. */
  59. @Override
  60. public void recordMessage(final Severity severity, final int code, final String message, Position location, final AST astNode, final Throwable exception) {
  61. maxSeverity = severity.ordinal() > maxSeverity.ordinal() ? severity : maxSeverity;
  62. if (location != null) {
  63. outWriter.println(location.toString() + ": " + message + (exception instanceof CompilationException ? " [[OrcWiki:"+exception.getClass().getSimpleName()+"]]" : ""));
  64. outWriter.println(location.longString());
  65. } else {
  66. outWriter.println("<undefined position>: " + message);
  67. }
  68. }
  69. /* (non-Javadoc)
  70. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, Throwable)
  71. */
  72. @Override
  73. public void recordMessage(final Severity severity, final int code, final String message, final Position location, final Throwable exception) {
  74. recordMessage(severity, code, message, location, null, exception);
  75. }
  76. /* (non-Javadoc)
  77. * @see orc.error.compiletime.CompileLogger#recordMessage(Severity, int, String, Position, AST)
  78. */
  79. @Override
  80. public void recordMessage(final Severity severity, final int code, final String message, final Position location, final AST astNode) {
  81. recordMessage(severity, code, message, location, astNode, null);
  82. }
  83. /* (non-Javadoc)
  84. * @see orc.error.compiletime.CompileLogger#recordMessage(orc.error.compiletime.CompileLogger.Severity, int, java.lang.String)
  85. */
  86. @Override
  87. public void recordMessage(final Severity severity, final int code, final String message) {
  88. recordMessage(severity, code, message, null, null, null);
  89. }
  90. /* (non-Javadoc)
  91. * @see orc.error.compiletime.CompileLogger#getMaxSeverity()
  92. */
  93. @Override
  94. public Severity getMaxSeverity() {
  95. return maxSeverity;
  96. }
  97. }