Skip to content

Commit 83c4db0

Browse files
authored
Moves certain classes and interfaces to the microbean-producer project; cleans up documentation (#23)
Signed-off-by: Laird Nelson <[email protected]>
1 parent 1d27dad commit 83c4db0

16 files changed

+81
-576
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ microBean™ Bean requires a Java runtime of version 21 or higher.
1919

2020
# Installation
2121

22-
microBean™ Bean is available on [Maven Central](https://search.maven.org/). Include microBean™ Bean as a Maven
22+
microBean™ Bean is available on [Maven
23+
Central](https://central.sonatype.com/artifact/org.microbean/microbean-bean). Include microBean™ Bean as a Maven
2324
dependency:
2425

2526
```xml
2627
<dependency>
2728
<groupId>org.microbean</groupId>
2829
<artifactId>microbean-bean</artifactId>
29-
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
30-
<version>0.0.15</version>
30+
<!-- Always check https://central.sonatype.com/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
31+
<version>0.0.16</version>
3132
</dependency>
3233
```
3334

pom.xml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
<java.util.logging.config.file>${project.basedir}/src/test/java/logging.properties</java.util.logging.config.file>
7474

7575
<!-- maven-compiler-plugin properties -->
76-
<maven.compiler.release>23</maven.compiler.release>
76+
<maven.compiler.release>21</maven.compiler.release>
7777
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
7878
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
7979

8080
<!-- maven-javadoc-plugin properties -->
8181
<bottom><![CDATA[Copyright &copy; ${project.inceptionYear}&ndash;{currentYear}, <a href="${project.organization.url}" target="_top">${project.organization.name}</a>. All rights reserved.]]></bottom>
8282
<doctitle>&lt;a href="${project.url}" target="_top"&gt;&lt;span style="font-family:Lobster, cursive;"&gt;µb&lt;/span&gt; ${project.artifactId}&lt;/a&gt; ${project.version}</doctitle>
83-
<links>https://microbean.github.io/microbean-assign/apidocs/,https://microbean.github.io/microbean-attributes/apidocs/,https://microbean.github.io/microbean-construct/apidocs/,,https://microbean.github.io/microbean-scope/apidocs/</links>
83+
<links>https://microbean.github.io/microbean-assign/apidocs/,https://microbean.github.io/microbean-attributes/apidocs/,https://microbean.github.io/microbean-construct/apidocs/</links>
8484
<sourcetab>2</sourcetab>
8585

8686
<!-- maven-release-plugin properties -->
@@ -165,12 +165,6 @@
165165
<version>0.0.10</version>
166166
</dependency>
167167

168-
<dependency>
169-
<groupId>org.microbean</groupId>
170-
<artifactId>microbean-interceptor</artifactId>
171-
<version>0.4.0</version>
172-
</dependency>
173-
174168
</dependencies>
175169
</dependencyManagement>
176170

@@ -200,12 +194,6 @@
200194
<scope>compile</scope>
201195
</dependency>
202196

203-
<dependency>
204-
<groupId>org.microbean</groupId>
205-
<artifactId>microbean-interceptor</artifactId>
206-
<scope>compile</scope>
207-
</dependency>
208-
209197
<!-- Test-scoped dependencies. -->
210198

211199
<dependency>

src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@
2626
requires transitive org.microbean.attributes;
2727
requires org.microbean.constant;
2828
requires transitive org.microbean.construct;
29-
requires transitive org.microbean.interceptor;
3029

3130
}

src/main/java/org/microbean/bean/AbstractFactory.java renamed to src/main/java/org/microbean/bean/AbstractFactory.java.bak

File renamed without changes.

src/main/java/org/microbean/bean/Aggregate.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
* Copyright © 2024–2025 microBean™.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6-
* the License. You may obtain a copy of the License at
6+
* the License. You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1212
* specific language governing permissions and limitations under the License.
1313
*/
1414
package org.microbean.bean;
1515

1616
import java.util.Collection;
1717
import java.util.Collections;
18-
import java.util.LinkedHashSet;
19-
import java.util.List;
2018
import java.util.SequencedSet;
2119

20+
import java.util.function.Function;
21+
22+
import static java.util.Collections.unmodifiableSequencedSet;
23+
24+
import static java.util.LinkedHashSet.newLinkedHashSet;
25+
2226
/**
2327
* An object with {@linkplain AttributedElement dependencies}.
2428
*
25-
* <p>By default, {@link Aggregate}s have no dependencies.</p>
29+
* <p>By default, {@link Aggregate}s have {@linkplain #EMPTY_DEPENDENCIES no dependencies}.</p>
2630
*
2731
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
2832
*
@@ -39,12 +43,12 @@ public interface Aggregate {
3943
/**
4044
* An immutable, empty {@link SequencedSet} of {@link Assignment}s.
4145
*/
42-
public static final SequencedSet<Assignment<?>> EMPTY_ASSIGNMENTS = Collections.unmodifiableSequencedSet(new LinkedHashSet<>(0));
46+
public static final SequencedSet<Assignment<?>> EMPTY_ASSIGNMENTS = unmodifiableSequencedSet(newLinkedHashSet(0));
4347

4448
/**
4549
* An immutable, empty {@link SequencedSet} of {@link AttributedElement}s.
4650
*/
47-
public static final SequencedSet<AttributedElement> EMPTY_DEPENDENCIES = Collections.unmodifiableSequencedSet(new LinkedHashSet<>(0));
51+
public static final SequencedSet<AttributedElement> EMPTY_DEPENDENCIES = unmodifiableSequencedSet(newLinkedHashSet(0));
4852

4953

5054
/*
@@ -53,9 +57,9 @@ public interface Aggregate {
5357

5458

5559
/**
56-
* Returns an unmodifiable {@link SequencedSet} of {@link AttributedElement} instances.
60+
* Returns an immutable {@link SequencedSet} of {@link AttributedElement} instances.
5761
*
58-
* @return an unmodifiable {@link SequencedSet} of {@link AttributedElement} instances; never {@code null}
62+
* @return an immutable {@link SequencedSet} of {@link AttributedElement} instances; never {@code null}
5963
*
6064
* @see AttributedElement
6165
*/
@@ -64,24 +68,26 @@ public default SequencedSet<AttributedElement> dependencies() {
6468
}
6569

6670
/**
67-
* Assigns a contextual reference to each of this {@link Aggregate}'s {@link AttributedElement} instances and returns the
68-
* resulting {@link List} of {@link Assignment}s.
71+
* A convenience method that assigns a contextual reference to each of this {@link Aggregate}'s {@link
72+
* AttributedElement} instances and returns the resulting {@link SequencedSet} of {@link Assignment}s.
6973
*
70-
* @param r a {@link Request}; must not be {@code null}
74+
* <p>Typically there is no need to override this method.</p>
7175
*
72-
* @return a {@link List} of {@link Assignment} instances; never {@code null}
76+
* @param r a {@link Function} that retrieves a contextual reference suitable for an {@link AttributedType}; if {@link
77+
* #dependencies()} returns a non-empty {@link SequencedSet} then this argument must not be {@code null}; normally a
78+
* reference to the {@link Request#reference(AttributedType)} method
79+
*
80+
* @return an immutable {@link SequencedSet} of {@link Assignment} instances; never {@code null}
7381
*
7482
* @exception NullPointerException if {@code r} is {@code null}
7583
*/
76-
public default SequencedSet<? extends Assignment<?>> assign(final Request<?> r) {
84+
public default SequencedSet<? extends Assignment<?>> assign(final Function<? super AttributedType, ?> r) {
7785
final Collection<? extends AttributedElement> ds = this.dependencies();
7886
if (ds == null || ds.isEmpty()) {
7987
return EMPTY_ASSIGNMENTS;
8088
}
81-
final SequencedSet<Assignment<?>> assignments = new LinkedHashSet<>();
82-
for (final AttributedElement d : ds) {
83-
assignments.add(new Assignment<>(d, r.reference(d.attributedType())));
84-
}
89+
final SequencedSet<Assignment<?>> assignments = newLinkedHashSet(ds.size());
90+
ds.forEach(d -> assignments.add(new Assignment<>(d, r.apply(d.attributedType()))));
8591
return Collections.unmodifiableSequencedSet(assignments);
8692
}
8793

src/main/java/org/microbean/bean/AttributedElement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import javax.lang.model.type.TypeMirror;
2929

30+
import org.microbean.attributes.Attributed;
3031
import org.microbean.attributes.Attributes;
3132

3233
import org.microbean.constant.Constables;
@@ -43,9 +44,7 @@
4344
*
4445
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
4546
*/
46-
public final record AttributedElement(Element element, List<Attributes> attributes) implements Constable {
47-
48-
private static final ClassDesc CD_Element = ClassDesc.of("javax.lang.model.element.Element");
47+
public final record AttributedElement(Element element, List<Attributes> attributes) implements Attributed, Constable {
4948

5049
/**
5150
* Creates a new {@link AttributedElement}.
@@ -94,7 +93,7 @@ public Optional<? extends ConstantDesc> describeConstable() {
9493
.flatMap(elementDesc -> Constables.describeConstable(this.attributes())
9594
.map(attributesDesc -> DynamicConstantDesc.of(BSM_INVOKE,
9695
MethodHandleDesc.ofConstructor(ClassDesc.of(this.getClass().getName()),
97-
CD_Element,
96+
ClassDesc.of("javax.lang.model.element.Element"),
9897
CD_List),
9998
elementDesc,
10099
attributesDesc)));

src/main/java/org/microbean/bean/Bean.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
22
*
3-
* Copyright © 2023–2024 microBean™.
3+
* Copyright © 2023–2025 microBean™.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6-
* the License. You may obtain a copy of the License at
6+
* the License. You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1212
* specific language governing permissions and limitations under the License.
1313
*/
1414
package org.microbean.bean;
1515

16+
import java.lang.constant.ClassDesc;
1617
import java.lang.constant.Constable;
1718
import java.lang.constant.ConstantDesc;
1819
import java.lang.constant.DynamicConstantDesc;
@@ -22,11 +23,9 @@
2223
import java.util.Optional;
2324
import java.util.SequencedSet;
2425

25-
import static java.lang.constant.ConstantDescs.BSM_INVOKE;
26+
import java.util.function.Function;
2627

27-
import static org.microbean.bean.ConstantDescs.CD_Bean;
28-
import static org.microbean.bean.ConstantDescs.CD_Factory;
29-
import static org.microbean.bean.ConstantDescs.CD_Id;
28+
import static java.lang.constant.ConstantDescs.BSM_INVOKE;
3029

3130
/**
3231
* A ({@link Constable}) pairing of an {@link Id} with a {@link Factory}.
@@ -59,17 +58,24 @@ public final record Bean<I>(Id id, Factory<I> factory) implements Aggregate, Con
5958
Objects.requireNonNull(factory, "factory");
6059
}
6160

62-
@Override // Alternate
61+
@Override // Ranked
6362
public final boolean alternate() {
6463
return this.id().alternate();
6564
}
6665

66+
@Override // Aggregate
67+
public final SequencedSet<? extends Assignment<?>> assign(final Function<? super AttributedType, ?> r) {
68+
return this.factory().assign(r);
69+
}
70+
6771
/**
6872
* Returns this {@link Bean}, forcibly cast appropriately.
6973
*
7074
* @param <X> the type of contextual instances this {@link Bean} creates
7175
*
7276
* @return this {@link Bean}
77+
*
78+
* @exception ClassCastException if the cast is inappropriate
7379
*/
7480
@SuppressWarnings("unchecked")
7581
public final <X> Bean<X> cast() {
@@ -86,30 +92,24 @@ public final Optional<DynamicConstantDesc<Bean<I>>> describeConstable() {
8692
return (this.factory() instanceof Constable c ? c.describeConstable() : Optional.<ConstantDesc>empty())
8793
.flatMap(factoryDesc -> this.id().describeConstable()
8894
.map(idDesc -> DynamicConstantDesc.of(BSM_INVOKE,
89-
MethodHandleDesc.ofConstructor(CD_Bean,
90-
CD_Id,
91-
CD_Factory),
95+
MethodHandleDesc.ofConstructor(ClassDesc.of(Bean.class.getName()),
96+
ClassDesc.of(Id.class.getName()),
97+
ClassDesc.of(Factory.class.getName())),
9298
idDesc,
9399
factoryDesc)));
94100
}
95101

96-
@Override // Object
102+
@Override // Record (Object)
97103
public final boolean equals(final Object other) {
98-
if (other == this) {
99-
return true;
100-
} else if (other != null && other.getClass() == this.getClass()) {
101-
return Objects.equals(this.id(), ((Bean<?>)other).id());
102-
} else {
103-
return false;
104-
}
104+
return this == other || other != null && this.getClass() == other.getClass() && this.id().equals(((Bean<?>)other).id());
105105
}
106106

107-
@Override // Object
108-
public int hashCode() {
107+
@Override // Record (Object)
108+
public final int hashCode() {
109109
return this.id().hashCode();
110110
}
111111

112-
@Override // Alternate (Ranked)
112+
@Override // Ranked
113113
public final int rank() {
114114
return this.id().rank();
115115
}

src/main/java/org/microbean/bean/Beans.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*
4242
* @see #Beans(Selectable, Reducible)
4343
*
44+
* @see #cachingSelectableOf(Collection, Matcher, Map)
45+
*
4446
* @see Selectable
4547
*
4648
* @see Reducible
@@ -129,37 +131,47 @@ public Beans(final Domain domain, final Collection<? extends Bean<?>> beans) {
129131
/**
130132
* Creates a new {@link Beans}.
131133
*
132-
* <p>{@link Bean} instances selected by the supplied {@link Selectable} will be reduced using a {@link
133-
* RankedReducer}.</p>
134-
*
135134
* @param s a {@link Selectable}; must not be {@code null}
136135
*
137136
* @exception NullPointerException if {@code s} is {@code null}
138137
*
139-
* @see RankedReducer
138+
* @see #Beans(Selectable, Reducer)
139+
*
140+
* @see RankedReducer#of()
140141
*/
141142
public Beans(final Selectable<AttributedType, Bean<?>> s) {
142-
this(s, Reducible.of(s, RankedReducer.of()));
143+
this(s, (Reducer<AttributedType, Bean<?>>)null);
143144
}
144145

145146
/**
146147
* Creates a new {@link Beans}.
147148
*
148149
* @param s a {@link Selectable}; must not be {@code null}
149150
*
150-
* @param r a {@link Reducible} to apply to elements selected by the supplied {@link Selectable}; must not be {@code
151-
* null}
151+
* @param r a {@link Reducer}; may be {@code null} in which case a {@link RankedReducer#of() RankedReducer} will be
152+
* used instead
152153
*
153-
* @exception NullPointerException if any argument is {@code null}
154+
* @exception NullPointerException if {@code s} is {@code null}
154155
*
155-
* @see #cachingSelectableOf(Collection, Matcher, Map)
156+
* @see #Beans(Selectable, Reducible)
156157
*
157158
* @see Reducible#of(Selectable, Reducer)
159+
*/
160+
public Beans(final Selectable<AttributedType, Bean<?>> s, final Reducer<AttributedType, Bean<?>> r) {
161+
this(s, Reducible.of(s, r == null ? RankedReducer.of() : r));
162+
}
163+
164+
/**
165+
* Creates a new {@link Beans}.
166+
*
167+
* @param s a {@link Selectable}; must not be {@code null}
158168
*
159-
* @see RankedReducer
169+
* @param r a {@link Reducible} to apply to elements selected by the supplied {@link Selectable}; must not be {@code
170+
* null}
171+
*
172+
* @exception NullPointerException if any argument is {@code null}
160173
*/
161-
public Beans(final Selectable<AttributedType, Bean<?>> s,
162-
final Reducible<AttributedType, Bean<?>> r) {
174+
public Beans(final Selectable<AttributedType, Bean<?>> s, final Reducible<AttributedType, Bean<?>> r) {
163175
this.s = Objects.requireNonNull(s, "s");
164176
this.r = Objects.requireNonNull(r, "r");
165177
}

0 commit comments

Comments
 (0)