author | rfield |
Fri, 10 Feb 2017 13:49:42 -0800 | |
changeset 43770 | a321bed02000 |
parent 38908 | f0c186d76c8a |
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. |
|
43770 | 33 |
* |
34 |
* @since 9 |
|
33362 | 35 |
* @see jdk.jshell.JShell#diagnostics(jdk.jshell.Snippet) |
36 |
*/ |
|
37 |
public abstract class Diag { |
|
38 |
// Simplified view on compiler Diagnostic. |
|
39 |
||
40 |
/** |
|
37756
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
41 |
* In-package creation only. |
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
42 |
*/ |
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
43 |
Diag() { |
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
44 |
} |
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
45 |
|
87dff934a38a
8139832: JShell API: Diag constructor should not be exposed and fix typo
rfield
parents:
37644
diff
changeset
|
46 |
/** |
33362 | 47 |
* Used to signal that no position is available. |
48 |
*/ |
|
49 |
public final static long NOPOS = Diagnostic.NOPOS; |
|
50 |
||
51 |
/** |
|
38908
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
37756
diff
changeset
|
52 |
* Indicates whether this diagnostic is an error (as opposed to a warning or |
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
37756
diff
changeset
|
53 |
* note). |
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
37756
diff
changeset
|
54 |
* |
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
37756
diff
changeset
|
55 |
* @return {@code true} if this diagnostic is an error; otherwise {@code false} |
33362 | 56 |
*/ |
57 |
public abstract boolean isError(); |
|
58 |
||
59 |
/** |
|
60 |
* Returns a character offset from the beginning of the source object |
|
61 |
* associated with this diagnostic that indicates the location of |
|
62 |
* the problem. In addition, the following must be true: |
|
63 |
* |
|
64 |
* <p>{@code getStartPostion() <= getPosition()} |
|
65 |
* <p>{@code getPosition() <= getEndPosition()} |
|
66 |
* |
|
67 |
* @return character offset from beginning of source; {@link |
|
37004
ff77b7986967
8153243: make docs should generate JShell API docs
jlahoda
parents:
33362
diff
changeset
|
68 |
* #NOPOS} if the position is not available. |
33362 | 69 |
*/ |
70 |
public abstract long getPosition(); |
|
71 |
||
72 |
/** |
|
73 |
* Returns the character offset from the beginning of the file |
|
74 |
* associated with this diagnostic that indicates the start 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 getStartPosition(); |
|
81 |
||
82 |
/** |
|
83 |
* Returns the character offset from the beginning of the file |
|
84 |
* associated with this diagnostic that indicates the end of the |
|
85 |
* problem. |
|
86 |
* |
|
87 |
* @return offset from beginning of file; {@link #NOPOS} if and |
|
88 |
* only if {@link #getPosition()} returns {@link #NOPOS} |
|
89 |
*/ |
|
90 |
public abstract long getEndPosition(); |
|
91 |
||
92 |
/** |
|
93 |
* Returns a diagnostic code indicating the type of diagnostic. The |
|
94 |
* code is implementation-dependent and might be {@code null}. |
|
95 |
* |
|
96 |
* @return a diagnostic code |
|
97 |
*/ |
|
98 |
public abstract String getCode(); |
|
99 |
||
100 |
/** |
|
101 |
* Returns a localized message for the given locale. The actual |
|
102 |
* message is implementation-dependent. If the locale is {@code |
|
103 |
* null} use the default locale. |
|
104 |
* |
|
105 |
* @param locale a locale; might be {@code null} |
|
106 |
* @return a localized message |
|
107 |
*/ |
|
108 |
public abstract String getMessage(Locale locale); |
|
109 |
||
110 |
// *** Internal support *** |
|
111 |
||
112 |
/** |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
113 |
* Internal: If this is from a compile/analyze wrapped in an outer class, extract the snippet. |
33362 | 114 |
* Otherwise null. |
115 |
*/ |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
116 |
Snippet snippetOrNull() { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
117 |
return null; |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
118 |
} |
33362 | 119 |
|
120 |
/** |
|
121 |
* This is an unreachable-statement error |
|
122 |
*/ |
|
123 |
boolean isUnreachableError() { |
|
124 |
return getCode().equals("compiler.err.unreachable.stmt"); |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* This is a not-a-statement error |
|
129 |
*/ |
|
130 |
boolean isNotAStatementError() { |
|
131 |
return getCode().equals("compiler.err.not.stmt"); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* This is a resolution error. |
|
136 |
*/ |
|
137 |
boolean isResolutionError() { |
|
138 |
//TODO: try javac RESOLVE_ERROR flag |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
139 |
return getCode().startsWith("compiler.err.cant.resolve") |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
37004
diff
changeset
|
140 |
|| getCode().equals("compiler.err.cant.apply.symbol"); |
33362 | 141 |
} |
142 |
} |