src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Diagnostic.java
author sundar
Thu, 28 Jun 2018 18:04:19 +0530
changeset 50878 fb7800b66c92
parent 47216 71c04702a3d5
permissions -rw-r--r--
8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs Reviewed-by: jlaskey, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     1
/*
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     4
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    10
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    15
 * accompanied this code).
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    16
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    20
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    23
 * questions.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    24
 */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    25
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    26
package jdk.nashorn.api.tree;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    27
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    28
/**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    29
 * Interface for diagnostics from tools.  A diagnostic usually reports
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    30
 * a problem at a specific position in a source file.  However, not
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    31
 * all diagnostics are associated with a position or a file.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    32
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    33
 * <p>A position is a zero-based character offset from the beginning of
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    34
 * a file.  Negative values (except {@link #NOPOS}) are not valid
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    35
 * positions.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    36
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    37
 * <p>Line and column numbers begin at 1.  Negative values (except
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    38
 * {@link #NOPOS}) and 0 are not valid line or column numbers.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    39
 *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    40
 * <p>Line terminator is as defined in ECMAScript specification which is one
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    41
 * of { &#92;u000A, &#92;u000B, &#92;u2028, &#92;u2029 }.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    42
 *
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    43
 * @deprecated Nashorn JavaScript script engine and APIs, and the jjs tool
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    44
 * are deprecated with the intent to remove them in a future release.
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    45
 *
35325
7624a7d7e661 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34903
diff changeset
    46
 * @since 9
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    47
 */
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    48
@Deprecated(since="11", forRemoval=true)
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    49
public interface Diagnostic {
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    50
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    51
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    52
     * Kinds of diagnostics, for example, error or warning.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    53
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    54
     * The kind of a diagnostic can be used to determine how the
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    55
     * diagnostic should be presented to the user. For example,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    56
     * errors might be colored red or prefixed with the word "Error",
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    57
     * while warnings might be colored yellow or prefixed with the
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    58
     * word "Warning". There is no requirement that the Kind
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    59
     * should imply any inherent semantic meaning to the message
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    60
     * of the diagnostic: for example, a tool might provide an
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    61
     * option to report all warnings as errors.
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    62
     *
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    63
     * @deprecated Nashorn JavaScript script engine and APIs, and the jjs tool
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    64
     * are deprecated with the intent to remove them in a future release.
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    65
     */
50878
fb7800b66c92 8204492: Add deprecation annotation to Nashorn APIs and warning to nashorn, jjs
sundar
parents: 47216
diff changeset
    66
    @Deprecated(since="11", forRemoval=true)
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    67
    enum Kind {
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    68
        /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    69
         * Problem which prevents the tool's normal completion.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    70
         */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    71
        ERROR,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    72
        /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    73
         * Problem which does not usually prevent the tool from
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    74
         * completing normally.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    75
         */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    76
        WARNING,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    77
        /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    78
         * Problem similar to a warning, but is mandated by the tool's
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    79
         * specification.  For example, the Java&trade; Language
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    80
         * Specification mandates warnings on certain
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    81
         * unchecked operations and the use of deprecated methods.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    82
         */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    83
        MANDATORY_WARNING,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    84
        /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    85
         * Informative message from the tool.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    86
         */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    87
        NOTE,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    88
        /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    89
         * Diagnostic which does not fit within the other kinds.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    90
         */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    91
        OTHER,
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    92
    }
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    93
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    94
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    95
     * Used to signal that no position is available.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    96
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    97
    public final static long NOPOS = -1;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    98
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
    99
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   100
     * Gets the kind of this diagnostic, for example, error or
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   101
     * warning.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   102
     * @return the kind of this diagnostic
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   103
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   104
    Kind getKind();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   105
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   106
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   107
     * Gets a character offset from the beginning of the source object
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   108
     * associated with this diagnostic that indicates the location of
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   109
     * the problem.  In addition, the following must be true:
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   110
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   111
     * <p>{@code getStartPostion() <= getPosition()}
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   112
     * <p>{@code getPosition() <= getEndPosition()}
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   113
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   114
     * @return character offset from beginning of source; {@link
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   115
     * #NOPOS} if no location is suitable
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   116
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   117
    long getPosition();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   118
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   119
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   120
     * Gets the source file name.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   121
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   122
     * @return the file name or null if not available
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   123
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   124
    String getFileName();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   125
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   126
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   127
     * Gets the line number of the character offset returned by
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   128
     * {@linkplain #getPosition()}.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   129
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   130
     * @return a line number or {@link #NOPOS} if and only if {@link
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   131
     * #getPosition()} returns {@link #NOPOS}
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   132
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   133
    long getLineNumber();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   134
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   135
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   136
     * Gets the column number of the character offset returned by
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   137
     * {@linkplain #getPosition()}.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   138
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   139
     * @return a column number or {@link #NOPOS} if and only if {@link
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   140
     * #getPosition()} returns {@link #NOPOS}
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   141
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   142
    long getColumnNumber();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   143
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   144
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   145
     * Gets a diagnostic code indicating the type of diagnostic.  The
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   146
     * code is implementation-dependent and might be {@code null}.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   147
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   148
     * @return a diagnostic code
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   149
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   150
    String getCode();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   151
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   152
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   153
     * Gets a message for this diagnostic.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   154
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   155
     * @return a message
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   156
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   157
    String getMessage();
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents:
diff changeset
   158
}