8335905: CompoundElement API cleanup

Reviewed-by: asotona
This commit is contained in:
Chen Liang 2024-07-14 15:01:51 +00:00
parent 6f325db493
commit a9f5e76a65
34 changed files with 73 additions and 82 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -89,7 +89,7 @@ public sealed interface ClassFileBuilder<E extends ClassFileElement, B extends C
B builder = (B) this;
var resolved = transform.resolve(builder);
resolved.startHandler().run();
model.forEachElement(resolved.consumer());
model.forEach(resolved.consumer());
resolved.endHandler().run();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,7 +37,7 @@ import jdk.internal.javac.PreviewFeature;
/**
* Models a classfile. The contents of the classfile can be traversed via
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
* a streaming view, or via random access (e.g.,
* {@link #flags()}), or by freely mixing the two.
*
* @since 22

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,8 +36,7 @@ import jdk.internal.javac.PreviewFeature;
/**
* Models the body of a method (the {@code Code} attribute). The instructions
* of the method body are accessed via a streaming view (e.g., {@link
* #elements()}).
* of the method body are accessed via a streaming view.
*
* @since 22
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ import jdk.internal.javac.PreviewFeature;
* class. When encountering a {@linkplain CompoundElement}, clients have the
* option to treat the element as a single entity (e.g., an entire method)
* or to traverse the contents of that element with the methods in this class
* (e.g., {@link #elements()}, {@link #forEachElement(Consumer)}, etc.)
* (e.g., {@link #forEach(Consumer)}, etc.)
* @param <E> the element type
*
* @sealedGraph
@ -55,15 +55,8 @@ public sealed interface CompoundElement<E extends ClassFileElement>
* compound element
* @param consumer the handler
*/
void forEachElement(Consumer<E> consumer);
/**
* {@return an {@link Iterable} describing all the elements contained in this
* compound element}
*/
default Iterable<E> elements() {
return elementList();
}
@Override
void forEach(Consumer<? super E> consumer);
/**
* {@return an {@link Iterator} describing all the elements contained in this
@ -71,7 +64,7 @@ public sealed interface CompoundElement<E extends ClassFileElement>
*/
@Override
default Iterator<E> iterator() {
return elements().iterator();
return elementList().iterator();
}
/**
@ -91,7 +84,7 @@ public sealed interface CompoundElement<E extends ClassFileElement>
*/
default List<E> elementList() {
List<E> list = new ArrayList<>();
forEachElement(new Consumer<>() {
forEach(new Consumer<>() {
@Override
public void accept(E e) {
list.add(e);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,7 @@ import jdk.internal.javac.PreviewFeature;
/**
* Models a field. The contents of the field can be traversed via
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
* a streaming view, or via random access (e.g.,
* {@link #flags()}), or by freely mixing the two.
*
* @since 22

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,7 @@ import jdk.internal.javac.PreviewFeature;
/**
* Models a method. The contents of the method can be traversed via
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
* a streaming view, or via random access (e.g.,
* {@link #flags()}), or by freely mixing the two.
*
* @since 22