Skip to content

Commit 382a241

Browse files
authored
Hoists some constructs from microbean-bean into this project. Refreshes dependencies. (#7)
Signed-off-by: Laird Nelson <[email protected]>
1 parent a2c5971 commit 382a241

File tree

10 files changed

+621
-19
lines changed

10 files changed

+621
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ changes, regardless of project version and without notice.**
1515

1616
# Requirements
1717

18-
microBean™ Assign requires a Java runtime of version 23 or higher.
18+
microBean™ Assign requires a Java runtime of version 21 or higher.
1919

2020
# Installation
2121

@@ -27,7 +27,7 @@ dependency:
2727
<groupId>org.microbean</groupId>
2828
<artifactId>microbean-assign</artifactId>
2929
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-bean for up-to-date available versions. -->
30-
<version>0.0.5</version>
30+
<version>0.0.6</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
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

@@ -125,7 +125,7 @@
125125
<dependency>
126126
<groupId>org.junit</groupId>
127127
<artifactId>junit-bom</artifactId>
128-
<version>5.11.3</version>
128+
<version>5.13.1</version>
129129
<type>pom</type>
130130
<scope>import</scope>
131131
</dependency>
@@ -135,13 +135,19 @@
135135
<dependency>
136136
<groupId>org.microbean</groupId>
137137
<artifactId>microbean-attributes</artifactId>
138-
<version>0.0.2</version>
138+
<version>0.0.3</version>
139+
</dependency>
140+
141+
<dependency>
142+
<groupId>org.microbean</groupId>
143+
<artifactId>microbean-constant</artifactId>
144+
<version>0.0.7</version>
139145
</dependency>
140146

141147
<dependency>
142148
<groupId>org.microbean</groupId>
143149
<artifactId>microbean-construct</artifactId>
144-
<version>0.0.10</version>
150+
<version>0.0.11</version>
145151
</dependency>
146152

147153
</dependencies>
@@ -154,7 +160,13 @@
154160
<artifactId>microbean-attributes</artifactId>
155161
<scope>compile</scope>
156162
</dependency>
157-
163+
164+
<dependency>
165+
<groupId>org.microbean</groupId>
166+
<artifactId>microbean-constant</artifactId>
167+
<scope>compile</scope>
168+
</dependency>
169+
158170
<dependency>
159171
<groupId>org.microbean</groupId>
160172
<artifactId>microbean-construct</artifactId>
@@ -308,7 +320,7 @@
308320
</plugin>
309321
<plugin>
310322
<artifactId>maven-clean-plugin</artifactId>
311-
<version>3.4.1</version>
323+
<version>3.5.0</version>
312324
<configuration>
313325
<filesets>
314326
<fileset>
@@ -423,14 +435,7 @@
423435
</plugin>
424436
<plugin>
425437
<artifactId>maven-surefire-plugin</artifactId>
426-
<version>3.5.2</version>
427-
<dependencies>
428-
<dependency>
429-
<groupId>org.apache.maven.surefire</groupId>
430-
<artifactId>surefire-junit-platform</artifactId>
431-
<version>3.5.2</version>
432-
</dependency>
433-
</dependencies>
438+
<version>3.5.3</version>
434439
</plugin>
435440
<plugin>
436441
<artifactId>maven-toolchains-plugin</artifactId>
@@ -439,7 +444,7 @@
439444
<plugin>
440445
<groupId>com.github.spotbugs</groupId>
441446
<artifactId>spotbugs-maven-plugin</artifactId>
442-
<version>4.9.1.0</version>
447+
<version>4.9.3.0</version>
443448
</plugin>
444449
<plugin>
445450
<groupId>org.codehaus.mojo</groupId>
@@ -449,7 +454,7 @@
449454
<plugin>
450455
<groupId>io.smallrye</groupId>
451456
<artifactId>jandex-maven-plugin</artifactId>
452-
<version>3.2.7</version>
457+
<version>3.3.1</version>
453458
</plugin>
454459
<plugin>
455460
<groupId>org.sonatype.plugins</groupId>

src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
requires transitive java.compiler;
2525
requires transitive org.microbean.attributes;
26+
requires org.microbean.constant;
2627
requires transitive org.microbean.construct;
2728

2829
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
2+
*
3+
* Copyright © 2025 microBean™.
4+
*
5+
* 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
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* 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
12+
* specific language governing permissions and limitations under the License.
13+
*/
14+
package org.microbean.assign;
15+
16+
import java.util.Collection;
17+
import java.util.Collections;
18+
import java.util.SequencedSet;
19+
20+
import java.util.function.Function;
21+
22+
import static java.util.Collections.unmodifiableSequencedSet;
23+
24+
import static java.util.LinkedHashSet.newLinkedHashSet;
25+
26+
/**
27+
* An object with {@linkplain AttributedElement dependencies}.
28+
*
29+
* <p>By default, {@link Aggregate}s have {@linkplain #EMPTY_DEPENDENCIES no dependencies}.</p>
30+
*
31+
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
32+
*
33+
* @see #dependencies()
34+
*/
35+
public interface Aggregate {
36+
37+
38+
/*
39+
* Static fields.
40+
*/
41+
42+
43+
/**
44+
* An immutable, empty {@link SequencedSet} of {@link Assignment}s.
45+
*/
46+
public static final SequencedSet<Assignment<?>> EMPTY_ASSIGNMENTS = unmodifiableSequencedSet(newLinkedHashSet(0));
47+
48+
/**
49+
* An immutable, empty {@link SequencedSet} of {@link AttributedElement}s.
50+
*/
51+
public static final SequencedSet<AttributedElement> EMPTY_DEPENDENCIES = unmodifiableSequencedSet(newLinkedHashSet(0));
52+
53+
54+
/*
55+
* Default instance methods.
56+
*/
57+
58+
59+
/**
60+
* Returns an immutable {@link SequencedSet} of {@link AttributedElement} instances.
61+
*
62+
* @return an immutable {@link SequencedSet} of {@link AttributedElement} instances; never {@code null}
63+
*
64+
* @see AttributedElement
65+
*/
66+
public default SequencedSet<AttributedElement> dependencies() {
67+
return EMPTY_DEPENDENCIES;
68+
}
69+
70+
/**
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.
73+
*
74+
* <p>Typically there is no need to override this method.</p>
75+
*
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}
78+
*
79+
* @return an immutable {@link SequencedSet} of {@link Assignment} instances; never {@code null}
80+
*
81+
* @exception NullPointerException if {@code r} is {@code null}
82+
*/
83+
public default SequencedSet<? extends Assignment<?>> assign(final Function<? super AttributedType, ?> r) {
84+
final Collection<? extends AttributedElement> ds = this.dependencies();
85+
if (ds == null || ds.isEmpty()) {
86+
return EMPTY_ASSIGNMENTS;
87+
}
88+
final SequencedSet<Assignment<?>> assignments = newLinkedHashSet(ds.size());
89+
ds.forEach(d -> assignments.add(new Assignment<>(d, r.apply(d.attributedType()))));
90+
return Collections.unmodifiableSequencedSet(assignments);
91+
}
92+
93+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
2+
*
3+
* Copyright © 2025 microBean™.
4+
*
5+
* 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
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* 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
12+
* specific language governing permissions and limitations under the License.
13+
*/
14+
package org.microbean.assign;
15+
16+
import java.util.Objects;
17+
18+
/**
19+
* An assignment of a value to an {@link AttributedElement}.
20+
*
21+
* @param <R> the value type
22+
*
23+
* @param assignee the {@link AttributedElement}; must not be {@code null}
24+
*
25+
* @param value the value; may be {@code null}
26+
*
27+
* @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
28+
*/
29+
// You're going to be tempted to replace the value component with a Supplier component. Don't do it. An assignment is a
30+
// value that belongs to, e.g., a field, so even if the value "came from" none/dependent/prototype scope, it was already
31+
// sourced and "belongs to" the field.
32+
public final record Assignment<R>(AttributedElement assignee, R value) {
33+
34+
/**
35+
* Creates a new {@link Assignment}.
36+
*
37+
* @param assignee the {@link AttributedElement}; must not be {@code null}
38+
*
39+
* @param value the contextual reference; may be {@code null}
40+
*/
41+
public Assignment {
42+
Objects.requireNonNull(assignee, "assignee");
43+
}
44+
45+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
2+
*
3+
* Copyright © 2025 microBean™.
4+
*
5+
* 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
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* 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
12+
* specific language governing permissions and limitations under the License.
13+
*/
14+
package org.microbean.assign;
15+
16+
import java.lang.constant.ClassDesc;
17+
import java.lang.constant.Constable;
18+
import java.lang.constant.ConstantDesc;
19+
import java.lang.constant.DynamicConstantDesc;
20+
import java.lang.constant.MethodHandleDesc;
21+
22+
import java.util.List;
23+
import java.util.Objects;
24+
import java.util.Optional;
25+
26+
import javax.lang.model.element.Element;
27+
28+
import javax.lang.model.type.TypeMirror;
29+
30+
import org.microbean.attributes.Attributed;
31+
import org.microbean.attributes.Attributes;
32+
33+
import org.microbean.constant.Constables;
34+
35+
import static java.lang.constant.ConstantDescs.BSM_INVOKE;
36+
import static java.lang.constant.ConstantDescs.CD_List;
37+
38+
/**
39+
* A pairing of an {@link Element} with a {@link List} of {@link Attributes}s.
40+
*
41+
* @param element an {@link Element}
42+
*
43+
* @param attributes a {@link List} of {@link Attributes}s
44+
*
45+
* @author <a href="https://about.me/lairdnelson/" target="_top">Laird Nelson</a>
46+
*/
47+
public final record AttributedElement(Element element, List<Attributes> attributes) implements Attributed, Constable {
48+
49+
/**
50+
* Creates a new {@link AttributedElement}.
51+
*
52+
* @param element a {@link Element}; must not be {@code null}
53+
*
54+
* @param attributes a {@link List} of {@link Attributes}; must not be {@code null}
55+
*
56+
* @exception NullPointerException if either argument is {@code null}
57+
*/
58+
public AttributedElement {
59+
Objects.requireNonNull(element, "element");
60+
attributes = List.copyOf(attributes);
61+
}
62+
63+
/**
64+
* Returns this {@link AttributedElement}'s {@linkplain Element#asType() type}.
65+
*
66+
* @return this {@link AttributedElement}'s {@linkplain Element#asType() type}; never {@code null}
67+
*/
68+
public final TypeMirror type() {
69+
return this.element().asType();
70+
}
71+
72+
/**
73+
* Returns this {@link AttributedElement}'s {@link AttributedType}.
74+
*
75+
* @return this {@link AttributedElement}'s {@link AttributedType}; never {@code null}
76+
*
77+
* @see AttributedType
78+
*/
79+
public final AttributedType attributedType() {
80+
return new AttributedType(this.type(), this.attributes());
81+
}
82+
83+
/**
84+
* Returns an {@link Optional} containing a {@link ConstantDesc} describing this {@link AttributedType}, or an
85+
* {@linkplain Optional#isEmpty() empty <code>Optional</code>} if it could not be described.
86+
*
87+
* @return an {@link Optional} containing a {@link ConstantDesc} describing this {@link AttributedType}, or an
88+
* {@linkplain Optional#isEmpty() empty <code>Optional</code>} if it could not be describe; never {@code null}
89+
*/
90+
@Override // Constable
91+
public Optional<? extends ConstantDesc> describeConstable() {
92+
return this.element() instanceof Constable e ? e.describeConstable() : Optional.<ConstantDesc>empty()
93+
.flatMap(elementDesc -> Constables.describeConstable(this.attributes())
94+
.map(attributesDesc -> DynamicConstantDesc.of(BSM_INVOKE,
95+
MethodHandleDesc.ofConstructor(ClassDesc.of(this.getClass().getName()),
96+
ClassDesc.of("javax.lang.model.element.Element"),
97+
CD_List),
98+
elementDesc,
99+
attributesDesc)));
100+
}
101+
102+
}

0 commit comments

Comments
 (0)