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