langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java
changeset 28455 41245007c074
parent 28334 1633de6070ae
child 29291 076c277565f7
equal deleted inserted replaced
28454:63c31d7de8f6 28455:41245007c074
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    36 
    36 
    37 import com.sun.tools.javac.api.DiagnosticFormatter;
    37 import com.sun.tools.javac.api.DiagnosticFormatter;
    38 import com.sun.tools.javac.main.Main;
    38 import com.sun.tools.javac.main.Main;
    39 import com.sun.tools.javac.main.Option;
    39 import com.sun.tools.javac.main.Option;
    40 import com.sun.tools.javac.tree.EndPosTable;
    40 import com.sun.tools.javac.tree.EndPosTable;
       
    41 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    41 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    42 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
    42 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
    43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
    43 
    44 
    44 import static com.sun.tools.javac.main.Option.*;
    45 import static com.sun.tools.javac.main.Option.*;
    45 
    46 
   189 
   190 
   190     /** Print stack trace on errors?
   191     /** Print stack trace on errors?
   191      */
   192      */
   192     public boolean dumpOnError;
   193     public boolean dumpOnError;
   193 
   194 
   194     /** Print multiple errors for same source locations.
       
   195      */
       
   196     public boolean multipleErrors;
       
   197 
       
   198     /**
   195     /**
   199      * Diagnostic listener, if provided through programmatic
   196      * Diagnostic listener, if provided through programmatic
   200      * interface to javac (JSR 199).
   197      * interface to javac (JSR 199).
   201      */
   198      */
   202     protected DiagnosticListener<? super JavaFileObject> diagListener;
   199     protected DiagnosticListener<? super JavaFileObject> diagListener;
   415 
   412 
   416     /** Returns true if an error needs to be reported for a given
   413     /** Returns true if an error needs to be reported for a given
   417      * source name and pos.
   414      * source name and pos.
   418      */
   415      */
   419     protected boolean shouldReport(JavaFileObject file, int pos) {
   416     protected boolean shouldReport(JavaFileObject file, int pos) {
   420         if (multipleErrors || file == null)
   417         if (file == null)
   421             return true;
   418             return true;
   422 
   419 
   423         Pair<JavaFileObject,Integer> coords = new Pair<>(file, pos);
   420         Pair<JavaFileObject,Integer> coords = new Pair<>(file, pos);
   424         boolean shouldReport = !recorded.contains(coords);
   421         boolean shouldReport = !recorded.contains(coords);
   425         if (shouldReport)
   422         if (shouldReport)
   578                     }
   575                     }
   579                 }
   576                 }
   580                 break;
   577                 break;
   581 
   578 
   582             case ERROR:
   579             case ERROR:
   583                 if (nerrors < MaxErrors
   580                 if (nerrors < MaxErrors &&
   584                     && shouldReport(diagnostic.getSource(), diagnostic.getIntPosition())) {
   581                     (diagnostic.isFlagSet(DiagnosticFlag.MULTIPLE) ||
       
   582                      shouldReport(diagnostic.getSource(), diagnostic.getIntPosition()))) {
   585                     writeDiagnostic(diagnostic);
   583                     writeDiagnostic(diagnostic);
   586                     nerrors++;
   584                     nerrors++;
   587                 }
   585                 }
   588                 break;
   586                 break;
   589             }
   587             }