< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Messager.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 107             case WARNING:
 108             case MANDATORY_WARNING:
 109                 printWarning(path, msg);
 110                 return;
 111             default:
 112                 printWarning(path, msg);
 113                 return;
 114         }
 115     }
 116 
 117     @Override
 118     public void print(Kind kind, Element e, String msg) {
 119                 switch (kind) {
 120             case ERROR:
 121                 printError(e, msg);
 122                 return;
 123             case WARNING:
 124             case MANDATORY_WARNING:
 125                 printWarning(e, msg);
 126                 return;
 127             case NOTE:
 128                 printNotice(e, msg);
 129                 return;
 130             default:
 131                 throw new IllegalArgumentException(String.format("unexpected option %s", kind));

 132         }
 133     }
 134 
 135     final String programName;
 136 
 137     private Locale locale;
 138     private final JavacMessages messages;
 139     private final JCDiagnostic.Factory javadocDiags;
 140 
 141     /** The default writer for diagnostics
 142      */
 143     static final PrintWriter defaultOutWriter = new PrintWriter(System.out);
 144     static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
 145 
 146     /**
 147      * Constructor
 148      * @param programName  Name of the program (for error messages).
 149      */
 150     public Messager(Context context, String programName) {
 151         this(context, programName, defaultOutWriter, defaultErrWriter);


 186     private String getDiagSource(DocTreePath path) {
 187         if (path == null || path.getTreePath() == null) {
 188             return programName;
 189         }
 190         JavacTrees trees = JavacTrees.instance(context);
 191         DocSourcePositions sourcePositions = trees.getSourcePositions();
 192         CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
 193         long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
 194         long lineNumber = cu.getLineMap().getLineNumber(spos);
 195         String fname = cu.getSourceFile().getName();
 196         String posString = fname + ":" + lineNumber;
 197         return posString;
 198     }
 199 
 200     private String getDiagSource(Element e) {
 201         if (e == null) {
 202             return programName;
 203         }
 204         JavacTrees trees = JavacTrees.instance(context);
 205         TreePath path = trees.getPath(e);
 206         if (path == null) {
 207             return programName;
 208         }
 209         DocSourcePositions sourcePositions = trees.getSourcePositions();
 210         JCTree tree = trees.getTree(e);
 211         CompilationUnitTree cu = path.getCompilationUnit();
 212         long spos = sourcePositions.getStartPosition(cu, tree);
 213         long lineNumber = cu.getLineMap().getLineNumber(spos);
 214         String fname = cu.getSourceFile().getName();
 215         String posString = fname + ":" + lineNumber;
 216         return posString;
 217     }
 218 
 219     /**
 220      * Print error message, increment error count.
 221      * Part of DocErrorReporter.
 222      *
 223      * @param msg message to print
 224      */
 225     public void printError(String msg) {
 226         printError((DocTreePath)null, msg);
 227     }
 228 


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 107             case WARNING:
 108             case MANDATORY_WARNING:
 109                 printWarning(path, msg);
 110                 return;
 111             default:
 112                 printWarning(path, msg);
 113                 return;
 114         }
 115     }
 116 
 117     @Override
 118     public void print(Kind kind, Element e, String msg) {
 119                 switch (kind) {
 120             case ERROR:
 121                 printError(e, msg);
 122                 return;
 123             case WARNING:
 124             case MANDATORY_WARNING:
 125                 printWarning(e, msg);
 126                 return;



 127             default:
 128                 printWarning(e, msg);
 129                 return;
 130         }
 131     }
 132 
 133     final String programName;
 134 
 135     private Locale locale;
 136     private final JavacMessages messages;
 137     private final JCDiagnostic.Factory javadocDiags;
 138 
 139     /** The default writer for diagnostics
 140      */
 141     static final PrintWriter defaultOutWriter = new PrintWriter(System.out);
 142     static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
 143 
 144     /**
 145      * Constructor
 146      * @param programName  Name of the program (for error messages).
 147      */
 148     public Messager(Context context, String programName) {
 149         this(context, programName, defaultOutWriter, defaultErrWriter);


 184     private String getDiagSource(DocTreePath path) {
 185         if (path == null || path.getTreePath() == null) {
 186             return programName;
 187         }
 188         JavacTrees trees = JavacTrees.instance(context);
 189         DocSourcePositions sourcePositions = trees.getSourcePositions();
 190         CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
 191         long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
 192         long lineNumber = cu.getLineMap().getLineNumber(spos);
 193         String fname = cu.getSourceFile().getName();
 194         String posString = fname + ":" + lineNumber;
 195         return posString;
 196     }
 197 
 198     private String getDiagSource(Element e) {
 199         if (e == null) {
 200             return programName;
 201         }
 202         JavacTrees trees = JavacTrees.instance(context);
 203         TreePath path = trees.getPath(e);



 204         DocSourcePositions sourcePositions = trees.getSourcePositions();
 205         JCTree tree = trees.getTree(e);
 206         CompilationUnitTree cu = path.getCompilationUnit();
 207         long spos = sourcePositions.getStartPosition(cu, tree);
 208         long lineNumber = cu.getLineMap().getLineNumber(spos);
 209         String fname = cu.getSourceFile().getName();
 210         String posString = fname + ":" + lineNumber;
 211         return posString;
 212     }
 213 
 214     /**
 215      * Print error message, increment error count.
 216      * Part of DocErrorReporter.
 217      *
 218      * @param msg message to print
 219      */
 220     public void printError(String msg) {
 221         printError((DocTreePath)null, msg);
 222     }
 223 


< prev index next >