author | rfield |
Mon, 25 Apr 2016 08:50:16 -0700 | |
changeset 37644 | 33cf53901cac |
parent 37004 | ff77b7986967 |
child 37756 | 87dff934a38a |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jshell; |
|
27 |
||
28 |
import java.util.Locale; |
|
29 |
import javax.tools.Diagnostic; |
|
30 |
||
31 |
/** |
|
32 |
* Diagnostic information for a Snippet. |
|
33 |
* @see jdk.jshell.JShell#diagnostics(jdk.jshell.Snippet) |
|
34 |
*/ |
|
35 |
public abstract class Diag { |
|
36 |
// Simplified view on compiler Diagnostic. |
|
37 |
||
38 |
/** |
|
39 |
* Used to signal that no position is available. |
|
40 |
*/ |
|
41 |
public final static long NOPOS = Diagnostic.NOPOS; |
|
42 |
||
43 |
/** |
|
44 |
* Is this diagnostic and error (as opposed to a warning or note) |
|
45 |
* @return true if this diagnostic is an error |
|
46 |
*/ |
|
47 |
public abstract boolean isError(); |
|
48 |
||
49 |
/** |
|
50 |
* Returns a character offset from the beginning of the source object |
|
51 |
* associated with this diagnostic that indicates the location of |
|
52 |
* the problem. In addition, the following must be true: |
|
53 |
* |
|
54 |
* <p>{@code getStartPostion() <= getPosition()} |
|
55 |
* <p>{@code getPosition() <= getEndPosition()} |
|
56 |
* |
|
57 |
* @return character offset from beginning of source; {@link |
|
37004
ff77b7986967
8153243: make docs should generate JShell API docs
jlahoda
parents:
33362
diff
changeset
|
58 |
* #NOPOS} if the position is not available. |
33362 | 59 |
*/ |
60 |
public abstract long getPosition(); |
|
61 |
||
62 |
/** |
|
63 |
* Returns the character offset from the beginning of the file |
|
64 |
* associated with this diagnostic that indicates the start of the |
|
65 |
* problem. |
|
66 |
* |
|
67 |
* @return offset from beginning of file; {@link #NOPOS} if and |
|
68 |
* only if {@link #getPosition()} returns {@link #NOPOS} |
|
69 |
*/ |
|
70 |
public abstract long getStartPosition(); |
|
71 |
||
72 |
/** |
|
73 |
* Returns the character offset from the beginning of the file |
|
74 |
* associated with this diagnostic that indicates the end of the |
|
75 |
* problem. |
|
76 |
* |
|
77 |
* @return offset from beginning of file; {@link #NOPOS} if and |
|
78 |
* only if {@link #getPosition()} returns {@link #NOPOS} |
|
79 |
*/ |
|
80 |
public abstract long getEndPosition(); |
|
81 |
||
82 |
/** |
|
83 |
* Returns a diagnostic code indicating the type of diagnostic. The |
|
84 |
* code is implementation-dependent and might be {@code null}. |
|
85 |
* |
|
86 |
* @return a diagnostic code |
|
87 |
*/ |
|
88 |
public abstract String getCode(); |
|
89 |
||
90 |
/** |
|
91 |
* Returns a localized message for the given locale. The actual |
|
92 |
* message is implementation-dependent. If the locale is {@code |
|
93 |
* null} use the default locale. |
|
94 |
* |
|
95 |
* @param locale a locale; might be {@code null} |
|
96 |
* @return a localized message |
|
97 |
*/ |
|
98 |
public abstract String getMessage(Locale locale); |
|
99 |
||
100 |
// *** Internal support *** |
|
101 |
||
102 |
/** |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
103 |
* Internal: If this is from a compile/analyze wrapped in an outer class, extract the snippet. |
33362 | 104 |
* Otherwise null. |
105 |
*/ |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
106 |
Snippet snippetOrNull() { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
107 |
return null; |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
108 |
} |
33362 | 109 |
|
110 |
/** |
|
111 |
* This is an unreachable-statement error |
|
112 |
*/ |
|
113 |
boolean isUnreachableError() { |
|
114 |
return getCode().equals("compiler.err.unreachable.stmt"); |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* This is a not-a-statement error |
|
119 |
*/ |
|
120 |
boolean isNotAStatementError() { |
|
121 |
return getCode().equals("compiler.err.not.stmt"); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* This is a resolution error. |
|
126 |
*/ |
|
127 |
boolean isResolutionError() { |
|
128 |
//TODO: try javac RESOLVE_ERROR flag |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
129 |
return getCode().startsWith("compiler.err.cant.resolve") |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
130 |
|| getCode().equals("compiler.err.cant.apply.symbol"); |
33362 | 131 |
} |
132 |
} |