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