Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.compiler/share/classes/javax/lang/model/util/ElementScanner14.java
41161 views
1
/*
2
* Copyright (c) 2019, 2020, 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 javax.lang.model.util;
27
28
import java.util.List;
29
import java.util.ArrayList;
30
import javax.lang.model.element.*;
31
import javax.annotation.processing.SupportedSourceVersion;
32
import javax.lang.model.SourceVersion;
33
import static javax.lang.model.SourceVersion.*;
34
35
/**
36
* A scanning visitor of program elements with default behavior
37
* appropriate for the {@link SourceVersion#RELEASE_14 RELEASE_14}
38
* source version.
39
*
40
* The <code>visit<i>Xyz</i></code> methods in this
41
* class scan their component elements by calling {@code scan} on
42
* their {@linkplain Element#getEnclosedElements enclosed elements},
43
* {@linkplain ExecutableElement#getParameters parameters}, etc., as
44
* indicated in the individual method specifications. A subclass can
45
* control the order elements are visited by overriding the
46
* <code>visit<i>Xyz</i></code> methods. Note that clients of a scanner
47
* may get the desired behavior be invoking {@code v.scan(e, p)} rather
48
* than {@code v.visit(e, p)} on the root objects of interest.
49
*
50
* <p>When a subclass overrides a <code>visit<i>Xyz</i></code> method, the
51
* new method can cause the enclosed elements to be scanned in the
52
* default way by calling <code>super.visit<i>Xyz</i></code>. In this
53
* fashion, the concrete visitor can control the ordering of traversal
54
* over the component elements with respect to the additional
55
* processing; for example, consistently calling
56
* <code>super.visit<i>Xyz</i></code> at the start of the overridden
57
* methods will yield a preorder traversal, etc. If the component
58
* elements should be traversed in some other order, instead of
59
* calling <code>super.visit<i>Xyz</i></code>, an overriding visit method
60
* should call {@code scan} with the elements in the desired order.
61
*
62
* @apiNote
63
* Methods in this class may be overridden subject to their general
64
* contract.
65
*
66
* @param <R> the return type of this visitor's methods. Use {@link
67
* Void} for visitors that do not need to return results.
68
* @param <P> the type of the additional parameter to this visitor's
69
* methods. Use {@code Void} for visitors that do not need an
70
* additional parameter.
71
*
72
* @see <a href="ElementScanner6.html#note_for_subclasses"><strong>Compatibility note for subclasses</strong></a>
73
* @see ElementScanner6
74
* @see ElementScanner7
75
* @see ElementScanner8
76
* @see ElementScanner9
77
* @since 16
78
*/
79
@SupportedSourceVersion(RELEASE_17)
80
public class ElementScanner14<R, P> extends ElementScanner9<R, P> {
81
/**
82
* Constructor for concrete subclasses; uses {@code null} for the
83
* default value.
84
*/
85
protected ElementScanner14(){
86
super(null);
87
}
88
89
/**
90
* Constructor for concrete subclasses; uses the argument for the
91
* default value.
92
*
93
* @param defaultValue the default value
94
*/
95
protected ElementScanner14(R defaultValue){
96
super(defaultValue);
97
}
98
99
/**
100
* {@inheritDoc}
101
*
102
* @implSpec This implementation scans the type parameters, if
103
* any, and then the enclosed elements.
104
*
105
*
106
* @param e {@inheritDoc}
107
* @param p {@inheritDoc}
108
* @return the result of scanning
109
*/
110
@Override
111
public R visitType(TypeElement e, P p) {
112
return scan(createScanningList(e, e.getEnclosedElements()), p);
113
}
114
115
/**
116
* {@inheritDoc}
117
*
118
* @implSpec This implementation first scans the type parameters, if any, and then
119
* the parameters.
120
*
121
* @param e {@inheritDoc}
122
* @param p {@inheritDoc}
123
* @return the result of scanning
124
*/
125
public R visitExecutable(ExecutableElement e, P p) {
126
return scan(createScanningList(e, e.getParameters()), p);
127
}
128
129
private List<? extends Element> createScanningList(Parameterizable element,
130
List<? extends Element> toBeScanned) {
131
var typeParameters = element.getTypeParameters();
132
if (typeParameters.isEmpty()) {
133
return toBeScanned;
134
} else {
135
List<Element> scanningList = new ArrayList<>(typeParameters);
136
scanningList.addAll(toBeScanned);
137
return scanningList;
138
}
139
}
140
141
/**
142
* {@inheritDoc}
143
*
144
* @implSpec This implementation scans the enclosed elements.
145
*
146
* @param e the element to visit
147
* @param p a visitor-specified parameter
148
* @return the result of the scan
149
*/
150
@Override
151
public R visitRecordComponent(RecordComponentElement e, P p) {
152
return scan(e.getEnclosedElements(), p);
153
}
154
}
155
156