Skip to content

Commit

Permalink
Merge pull request #112 from dmlloyd/jdk-17-1.5
Browse files Browse the repository at this point in the history
Start 1.5.x, requiring Java 17
  • Loading branch information
dmlloyd authored Apr 9, 2024
2 parents 5ffc8c9 + f733262 commit 8b5407d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 109 deletions.
Empty file added build-release-17
Empty file.
Empty file added container/build-release-17
Empty file.
2 changes: 1 addition & 1 deletion container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye.beanbag</groupId>
<artifactId>smallrye-beanbag-parent</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-beanbag</artifactId>
Expand Down
20 changes: 8 additions & 12 deletions container/src/main/java/io/smallrye/beanbag/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,18 @@ public static <R, T> List<R> mapList(List<T> input, Function<T, R> mapper, IntFu
Assert.checkNotNullParam("input", input);
Assert.checkNotNullParam("mapper", mapper);
final int size = input.size();
switch (size) {
case 0:
return List.of();
case 1:
return List.of(mapper.apply(input.get(0)));
case 2:
return List.of(mapper.apply(input.get(0)), mapper.apply(input.get(1)));
case 3:
return List.of(mapper.apply(input.get(0)), mapper.apply(input.get(1)), mapper.apply(input.get(2)));
default: {
return switch (size) {
case 0 -> List.of();
case 1 -> List.of(mapper.apply(input.get(0)));
case 2 -> List.of(mapper.apply(input.get(0)), mapper.apply(input.get(1)));
case 3 -> List.of(mapper.apply(input.get(0)), mapper.apply(input.get(1)), mapper.apply(input.get(2)));
default -> {
final R[] array = generator.apply(size);
for (int i = 0; i < size; i++) {
array[i] = mapper.apply(input.get(i));
}
return List.of(array);
yield List.of(array);
}
}
};
}
}
Empty file added maven/build-release-17
Empty file.
2 changes: 1 addition & 1 deletion maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye.beanbag</groupId>
<artifactId>smallrye-beanbag-parent</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-beanbag-maven</artifactId>
Expand Down
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.smallrye.beanbag</groupId>
<artifactId>smallrye-beanbag-parent</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>

<parent>
<groupId>io.smallrye</groupId>
Expand All @@ -17,8 +17,6 @@
<description>A trivial programmatic bean container implementation</description>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- versions -->
Expand Down
Empty file added sisu/build-release-17
Empty file.
2 changes: 1 addition & 1 deletion sisu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye.beanbag</groupId>
<artifactId>smallrye-beanbag-parent</artifactId>
<version>1.4.2-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-beanbag-sisu</artifactId>
Expand Down
133 changes: 42 additions & 91 deletions sisu/src/main/java/io/smallrye/beanbag/sisu/Sisu.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,10 @@ interface XMLCloser extends AutoCloseable {
private void consume(final XMLStreamReader xr) throws XMLStreamException {
while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
return;
}
case XMLStreamReader.START_ELEMENT: {
consume(xr);
break;
}
case XMLStreamReader.START_ELEMENT -> consume(xr);
}
}
}
Expand All @@ -152,16 +149,15 @@ private void parseComponentSet(final XMLStreamReader xr, final Map<Class<?>, Com
throws XMLStreamException {
while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
return;
}
case XMLStreamReader.START_ELEMENT: {
case XMLStreamReader.START_ELEMENT -> {
if (xr.getLocalName().equals("components")) {
parseComponents(xr, map, classLoader, filter);
} else {
consume(xr);
}
break;
}
}
}
Expand All @@ -172,16 +168,15 @@ private void parseComponents(final XMLStreamReader xr, final Map<Class<?>, Compo
throws XMLStreamException {
while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
return;
}
case XMLStreamReader.START_ELEMENT: {
case XMLStreamReader.START_ELEMENT -> {
if (xr.getLocalName().equals("component")) {
parseComponent(xr, map, classLoader, filter);
} else {
consume(xr);
}
break;
}
}
}
Expand All @@ -199,13 +194,13 @@ private void parseComponent(final XMLStreamReader xr, final Map<Class<?>, Compon

loop: while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
// all done
break loop;
}
case XMLStreamReader.START_ELEMENT: {
case XMLStreamReader.START_ELEMENT -> {
switch (xr.getLocalName()) {
case "implementation": {
case "implementation" -> {
if (clazz == null) {
// try to load it up
final String className = xr.getElementText();
Expand All @@ -227,9 +222,8 @@ private void parseComponent(final XMLStreamReader xr, final Map<Class<?>, Compon
} else {
consume(xr);
}
break;
}
case "role": {
case "role" -> {
if (type == null) {
final String className = xr.getElementText();
if (builder.isTypeFilteredOut(className)) {
Expand All @@ -244,9 +238,8 @@ private void parseComponent(final XMLStreamReader xr, final Map<Class<?>, Compon
} else {
consume(xr);
}
break;
}
case "role-hint": {
case "role-hint" -> {
if (name == null) {
name = xr.getElementText();
if (name.equals("default")) {
Expand All @@ -255,33 +248,16 @@ private void parseComponent(final XMLStreamReader xr, final Map<Class<?>, Compon
} else {
consume(xr);
}
break;
}
case "instantiation-strategy": {
case "instantiation-strategy" -> {
switch (xr.getElementText()) {
case "per-lookup": {
singleton = false;
break;
}
case "poolable":
case "keep-alive":
case "singleton": {
singleton = true;
break;
}
case "per-lookup" -> singleton = false;
case "poolable", "keep-alive", "singleton" -> singleton = true;
}
break;
}
case "requirements": {
requirements = parseRequirements(xr, classLoader, filter);
break;
}
default: {
consume(xr);
break;
}
case "requirements" -> requirements = parseRequirements(xr, classLoader, filter);
default -> consume(xr);
}
break;
}
}
}
Expand Down Expand Up @@ -339,22 +315,18 @@ private List<Requirement> parseRequirements(final XMLStreamReader xr, final Clas
List<Requirement> list = null;
loop: while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
break loop;
}
case XMLStreamReader.START_ELEMENT: {
case XMLStreamReader.START_ELEMENT -> {
switch (xr.getLocalName()) {
case "requirement": {
case "requirement" -> {
if (list == null) {
list = new ArrayList<>();
}
list.add(parseRequirement(xr, classLoader, filter));
break;
}
default: {
consume(xr);
break;
}
default -> consume(xr);
}
}
}
Expand All @@ -367,34 +339,23 @@ private Requirement parseRequirement(final XMLStreamReader xr, final ClassLoader
final Requirement requirement = new Requirement();
while (xr.hasNext()) {
switch (xr.next()) {
case XMLStreamReader.END_ELEMENT: {
case XMLStreamReader.END_ELEMENT -> {
return requirement;
}
case XMLStreamReader.START_ELEMENT: {
case XMLStreamReader.START_ELEMENT -> {
switch (xr.getLocalName()) {
case "role": {
requirement.injectType = xr.getElementText();
break;
}
case "role-hint": {
case "role" -> requirement.injectType = xr.getElementText();
case "role-hint" -> {
requirement.injectName = xr.getElementText();
if (requirement.injectName.equals("default")) {
requirement.injectName = "";
}
break;
}
case "field":
case "field-name": {
requirement.fieldName = xr.getElementText();
break;
}
case "field", "field-name" -> requirement.fieldName = xr.getElementText();

// todo: configuration
default: {
consume(xr);
break;
}
default -> consume(xr);
}
break;
}
}
}
Expand Down Expand Up @@ -745,8 +706,7 @@ private static void doExprPart(final StringBuilder b, final StringItr itr, final
}

private static Type getTypeArgument(Type type, int position) {
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
if (type instanceof final ParameterizedType pt) {
return pt.getActualTypeArguments()[position];
} else {
throw new IllegalArgumentException("No type argument given for " + type);
Expand All @@ -756,19 +716,15 @@ private static Type getTypeArgument(Type type, int position) {
private static Class<?> getRawType(Type type) {
if (type instanceof Class<?>) {
return (Class<?>) type;
} else if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
} else if (type instanceof final ParameterizedType pt) {
return getRawType(pt.getRawType());
} else if (type instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType) type;
} else if (type instanceof final GenericArrayType gat) {
// Class.arrayType() is JDK 12+
return getArrayType(getRawType(gat.getGenericComponentType()));
} else if (type instanceof WildcardType) {
WildcardType wt = (WildcardType) type;
} else if (type instanceof final WildcardType wt) {
final Type[] ub = wt.getUpperBounds();
return ub.length >= 1 ? getRawType(ub[0]) : Object.class;
} else if (type instanceof TypeVariable<?>) {
TypeVariable<?> tv = (TypeVariable<?>) type;
} else if (type instanceof final TypeVariable<?> tv) {
final Type[] bounds = tv.getBounds();
return bounds.length >= 1 ? getRawType(bounds[0]) : Object.class;
} else {
Expand Down Expand Up @@ -959,28 +915,23 @@ private Annotations(AnnotatedElement element) {
final Class<? extends Annotation> annoType = annotation.annotationType();
final String annoName = annoType.getName();
switch (annoName) {
case "javax.inject.Inject":
case "javax.inject.Inject" -> {
inject = true;
break;
case "javax.inject.Singleton":
case "org.eclipse.sisu.EagerSingleton":
case "org.sonatype.inject.EagerSingleton":
}
case "javax.inject.Singleton", "org.eclipse.sisu.EagerSingleton", "org.sonatype.inject.EagerSingleton" -> {
singleton = true;
break;
case "javax.inject.Named":
}
case "javax.inject.Named" -> {
named = GET_NAMED_VALUE_FN.get(annoType).apply(annotation);
break;
case "org.eclipse.sisu.Nullable":
case "org.sonatype.inject.Nullable":
}
case "org.eclipse.sisu.Nullable", "org.sonatype.inject.Nullable" -> {
nullable = true;
break;
case "org.eclipse.sisu.Priority": {
}
case "org.eclipse.sisu.Priority" -> {
priority = GET_PRIORITY_VALUE_FN.get(annoType).apply(annotation).intValue();
break;
}
case "org.eclipse.sisu.Typed": {
case "org.eclipse.sisu.Typed" -> {
typed = List.of(GET_TYPED_VALUE_FN.get(annoType).apply(annotation));
break;
}
}
}
Expand Down

0 comments on commit 8b5407d

Please sign in to comment.