langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
changeset 26266 2d24bda701dc
parent 25874 83c19f00452c
child 28334 1633de6070ae
equal deleted inserted replaced
26265:46aacfffd3b5 26266:2d24bda701dc
    34 
    34 
    35 import com.sun.tools.javac.api.DiagnosticFormatter;
    35 import com.sun.tools.javac.api.DiagnosticFormatter;
    36 import com.sun.tools.javac.code.Lint.LintCategory;
    36 import com.sun.tools.javac.code.Lint.LintCategory;
    37 import com.sun.tools.javac.tree.EndPosTable;
    37 import com.sun.tools.javac.tree.EndPosTable;
    38 import com.sun.tools.javac.tree.JCTree;
    38 import com.sun.tools.javac.tree.JCTree;
       
    39 import com.sun.tools.javac.util.DefinedBy.Api;
    39 
    40 
    40 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
    41 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
    41 
    42 
    42 /** An abstraction of a diagnostic message generated by the compiler.
    43 /** An abstraction of a diagnostic message generated by the compiler.
    43  *
    44  *
   464 
   465 
   465     /**
   466     /**
   466      * Get the name of the source file referred to by this diagnostic.
   467      * Get the name of the source file referred to by this diagnostic.
   467      * @return the name of the source referred to with this diagnostic, or null if none
   468      * @return the name of the source referred to with this diagnostic, or null if none
   468      */
   469      */
       
   470     @DefinedBy(Api.COMPILER)
   469     public JavaFileObject getSource() {
   471     public JavaFileObject getSource() {
   470         if (source == null)
   472         if (source == null)
   471             return null;
   473             return null;
   472         else
   474         else
   473             return source.getFile();
   475             return source.getFile();
   491 
   493 
   492     protected int getIntEndPosition() {
   494     protected int getIntEndPosition() {
   493         return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
   495         return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable()));
   494     }
   496     }
   495 
   497 
       
   498     @DefinedBy(Api.COMPILER)
   496     public long getStartPosition() {
   499     public long getStartPosition() {
   497         return getIntStartPosition();
   500         return getIntStartPosition();
   498     }
   501     }
   499 
   502 
       
   503     @DefinedBy(Api.COMPILER)
   500     public long getPosition() {
   504     public long getPosition() {
   501         return getIntPosition();
   505         return getIntPosition();
   502     }
   506     }
   503 
   507 
       
   508     @DefinedBy(Api.COMPILER)
   504     public long getEndPosition() {
   509     public long getEndPosition() {
   505         return getIntEndPosition();
   510         return getIntEndPosition();
   506     }
   511     }
   507 
   512 
   508     public DiagnosticPosition getDiagnosticPosition() {
   513     public DiagnosticPosition getDiagnosticPosition() {
   511 
   516 
   512     /**
   517     /**
   513      * Get the line number within the source referred to by this diagnostic.
   518      * Get the line number within the source referred to by this diagnostic.
   514      * @return  the line number within the source referred to by this diagnostic
   519      * @return  the line number within the source referred to by this diagnostic
   515      */
   520      */
       
   521     @DefinedBy(Api.COMPILER)
   516     public long getLineNumber() {
   522     public long getLineNumber() {
   517         if (sourcePosition == null) {
   523         if (sourcePosition == null) {
   518             sourcePosition = new SourcePosition();
   524             sourcePosition = new SourcePosition();
   519         }
   525         }
   520         return sourcePosition.getLineNumber();
   526         return sourcePosition.getLineNumber();
   522 
   528 
   523     /**
   529     /**
   524      * Get the column number within the line of source referred to by this diagnostic.
   530      * Get the column number within the line of source referred to by this diagnostic.
   525      * @return  the column number within the line of source referred to by this diagnostic
   531      * @return  the column number within the line of source referred to by this diagnostic
   526      */
   532      */
       
   533     @DefinedBy(Api.COMPILER)
   527     public long getColumnNumber() {
   534     public long getColumnNumber() {
   528         if (sourcePosition == null) {
   535         if (sourcePosition == null) {
   529             sourcePosition = new SourcePosition();
   536             sourcePosition = new SourcePosition();
   530         }
   537         }
   531         return sourcePosition.getColumnNumber();
   538         return sourcePosition.getColumnNumber();
   567     @Deprecated
   574     @Deprecated
   568     private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
   575     private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
   569 
   576 
   570     // Methods for javax.tools.Diagnostic
   577     // Methods for javax.tools.Diagnostic
   571 
   578 
       
   579     @DefinedBy(Api.COMPILER)
   572     public Diagnostic.Kind getKind() {
   580     public Diagnostic.Kind getKind() {
   573         switch (type) {
   581         switch (type) {
   574         case NOTE:
   582         case NOTE:
   575             return Diagnostic.Kind.NOTE;
   583             return Diagnostic.Kind.NOTE;
   576         case WARNING:
   584         case WARNING:
   582         default:
   590         default:
   583             return Diagnostic.Kind.OTHER;
   591             return Diagnostic.Kind.OTHER;
   584         }
   592         }
   585     }
   593     }
   586 
   594 
       
   595     @DefinedBy(Api.COMPILER)
   587     public String getCode() {
   596     public String getCode() {
   588         return key;
   597         return key;
   589     }
   598     }
   590 
   599 
       
   600     @DefinedBy(Api.COMPILER)
   591     public String getMessage(Locale locale) {
   601     public String getMessage(Locale locale) {
   592         return defaultFormatter.formatMessage(this, locale);
   602         return defaultFormatter.formatMessage(this, locale);
   593     }
   603     }
   594 
   604 
   595     public void setFlag(DiagnosticFlag flag) {
   605     public void setFlag(DiagnosticFlag flag) {