author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 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 |
*/ |
|
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
33362
diff
changeset
|
25 |
|
33362 | 26 |
package jdk.jshell; |
27 |
||
28 |
import java.util.Collection; |
|
29 |
import jdk.jshell.Key.DeclarationKey; |
|
30 |
||
31 |
/** |
|
32 |
* Grouping for all declaration Snippets: variable declarations |
|
33 |
* ({@link jdk.jshell.VarSnippet}), method declarations |
|
34 |
* ({@link jdk.jshell.MethodSnippet}), and type declarations |
|
35 |
* ({@link jdk.jshell.TypeDeclSnippet}). |
|
36 |
* <p> |
|
37 |
* Declaration snippets are unique in that they can be active |
|
38 |
* with unresolved references: |
|
39 |
* {@link jdk.jshell.Snippet.Status#RECOVERABLE_DEFINED RECOVERABLE_DEFINED} or |
|
40 |
* {@link jdk.jshell.Snippet.Status#RECOVERABLE_NOT_DEFINED RECOVERABLE_NOT_DEFINED}. |
|
41 |
* Unresolved references can be queried with |
|
42 |
* {@link jdk.jshell.JShell#unresolvedDependencies(jdk.jshell.DeclarationSnippet) |
|
43 |
* JShell.unresolvedDependencies(DeclarationSnippet)}. |
|
44 |
* <p> |
|
45 |
* <code>DeclarationSnippet</code> is immutable: an access to |
|
46 |
* any of its methods will always return the same result. |
|
47 |
* and thus is thread-safe. |
|
43770 | 48 |
* |
49 |
* @since 9 |
|
33362 | 50 |
*/ |
51 |
public abstract class DeclarationSnippet extends PersistentSnippet { |
|
52 |
||
53 |
private final Wrap corralled; |
|
54 |
private final Collection<String> declareReferences; |
|
55 |
private final Collection<String> bodyReferences; |
|
56 |
||
57 |
DeclarationSnippet(DeclarationKey key, String userSource, Wrap guts, |
|
58 |
String unitName, SubKind subkind, Wrap corralled, |
|
59 |
Collection<String> declareReferences, |
|
39370
437ba9bd2582
8159111: JShell API: Add access to wrappers and dependencies
rfield
parents:
37644
diff
changeset
|
60 |
Collection<String> bodyReferences, |
437ba9bd2582
8159111: JShell API: Add access to wrappers and dependencies
rfield
parents:
37644
diff
changeset
|
61 |
DiagList syntheticDiags) { |
437ba9bd2582
8159111: JShell API: Add access to wrappers and dependencies
rfield
parents:
37644
diff
changeset
|
62 |
super(key, userSource, guts, unitName, subkind, syntheticDiags); |
33362 | 63 |
this.corralled = corralled; |
64 |
this.declareReferences = declareReferences; |
|
65 |
this.bodyReferences = bodyReferences; |
|
66 |
} |
|
67 |
||
68 |
/**** internal access ****/ |
|
69 |
||
70 |
/** |
|
71 |
* @return the corralled guts |
|
72 |
*/ |
|
73 |
@Override |
|
74 |
Wrap corralled() { |
|
75 |
return corralled; |
|
76 |
} |
|
77 |
||
78 |
@Override |
|
79 |
Collection<String> declareReferences() { |
|
80 |
return declareReferences; |
|
81 |
} |
|
82 |
||
83 |
@Override |
|
84 |
Collection<String> bodyReferences() { |
|
85 |
return bodyReferences; |
|
86 |
} |
|
87 |
||
88 |
@Override |
|
89 |
String importLine(JShell state) { |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
34752
diff
changeset
|
90 |
return "import static " + classFullName() + "." + name() + ";\n"; |
33362 | 91 |
} |
92 |
} |