Skip to content

Commit

Permalink
Address early review
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed May 13, 2024
1 parent 82695a7 commit 67f0100
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public enum ElementKind {
STATIC_INIT,
/** An instance initializer. */
INSTANCE_INIT,
/** A pattern declaration. */
PATTERN_DECLARATION,

/** A type parameter. */
TYPE_PARAMETER,
Expand Down Expand Up @@ -125,9 +123,15 @@ public enum ElementKind {
* A binding variable in a pattern.
* @since 16
*
* todo: think about reusing it for bindings of pattern declarations
*/
BINDING_VARIABLE;
BINDING_VARIABLE,

/**
* A pattern declaration.
* @since 23
*
*/
PATTERN_DECLARATION;

// Maintenance note: check if the default implementation of
// Elements.getOutermostTypeElement needs updating when new kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ default R visitRecordComponent(RecordComponentElement e, P p) {
* @param e the element to visit
* @param p a visitor-specified parameter
* @return a visitor-specified result
* @since 16
* @since 23
*/
default R visitPatternDeclaration(PatternDeclarationElement e, P p) {
default R visitPatternDeclaration(ExecutableElement e, P p) {
return visitUnknown(e, p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ public interface ExecutableElement extends Element, Parameterizable {
*/
@Override
Name getSimpleName();

/**
* Returns the binding parameters of this executable.
* They are returned in declaration order.
*
* @return the binding parameters,
* or an empty list if there are none or is not a pattern declaration.
*/
List<? extends VariableElement> getBindings();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.PatternDeclarationElement;
import javax.lang.model.element.RecordComponentElement;
import static javax.lang.model.SourceVersion.*;
Expand Down Expand Up @@ -78,5 +79,5 @@ protected AbstractElementVisitorPreview(){
* @return {@inheritDoc ElementVisitor}
*/
@Override
public abstract R visitPatternDeclaration(PatternDeclarationElement e, P p);
public abstract R visitPatternDeclaration(ExecutableElement e, P p);
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public R visitExecutable(ExecutableElement e, P p) {
return visitExecutableAsStaticInit(e, p);

case PATTERN_DECLARATION:
return visitPatternDeclaration((PatternDeclarationElement) e, p);
return visitPatternDeclaration(e, p);

default:
throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected ElementKindVisitorPreview(R defaultValue) {
* @param p a visitor-specified parameter
* @return the result of {@code defaultAction}
*/
public R visitPatternDeclaration(PatternDeclarationElement e, P p) {
public R visitPatternDeclaration(ExecutableElement e, P p) {
return defaultAction(e, p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ protected ElementScannerPreview(R defaultValue){
* @since N
*/
@Override
public R visitPatternDeclaration(PatternDeclarationElement e, P p) {
public R visitPatternDeclaration(ExecutableElement e, P p) {
return scan(createScanningList(e, e.getBindings()), p);
}

private List<? extends Element> createScanningList(PatternDeclarationElement element,
private List<? extends Element> createScanningList(ExecutableElement element,
List<? extends Element> toBeScanned) {
var typeParameters = element.getTypeParameters();
if (typeParameters.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ public boolean isPreserved() {

/** A class for method symbols.
*/
public static class MethodSymbol extends Symbol implements PatternDeclarationElement, ExecutableElement {
public static class MethodSymbol extends Symbol implements ExecutableElement {

/** The code of the method. */
public Code code = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BindingProcessor extends JavacTestingAbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(Bindings.class)) {
if (element instanceof PatternDeclarationElement exec) {
if (element instanceof ExecutableElement exec) {
String message = String.format("%s.%s(%s)",
exec.getEnclosingElement(),
exec.getSimpleName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void main(String... args) {
(ElementKind k) -> k.isDeclaredType(), "isDeclaredType");

// isExecutable: Returns true if this is a kind of executable: one of
// METHOD, CONSTRUCTOR, STATIC_INIT, INSTANCE_INIT
// METHOD, CONSTRUCTOR, STATIC_INIT, INSTANCE_INIT, PATTERN_DECLARATION
test(ALL_KINDS,
(ElementKind k) -> Set.of(ElementKind.METHOD,
ElementKind.CONSTRUCTOR,
Expand Down

0 comments on commit 67f0100

Please sign in to comment.