Skip to content

Commit

Permalink
Downgrade codegen and remaining subprojects to JDK 17
Browse files Browse the repository at this point in the history
  • Loading branch information
hpmellema committed Apr 26, 2024
1 parent 6a257f6 commit 5073dec
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Java ${{ matrix.java }} ${{ matrix.os }}
strategy:
matrix:
java: [21]
java: [17]
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
Expand Down
6 changes: 1 addition & 5 deletions buildSrc/src/main/groovy/smithy-java.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ plugins {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(17)
}
}

tasks.compileJava {
options.release = 17
}

/*
* Common test configuration
* ===============================
Expand Down
4 changes: 0 additions & 4 deletions codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ plugins {

description = "This module provides the codegen functionality for Smithy java"

tasks.compileJava {
options.release = 21
}

ext {
displayName = "Smithy :: Java :: Codegen"
moduleName = "software.amazon.smithy.smithy-java.codegen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SequencedSet;
import java.util.Set;
import java.util.SortedSet;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
Expand Down Expand Up @@ -48,6 +50,7 @@
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.model.traits.UniqueItemsTrait;
import software.amazon.smithy.utils.BuilderRef;
import software.amazon.smithy.utils.CaseUtils;

/**
Expand Down Expand Up @@ -112,11 +115,11 @@ public Symbol booleanShape(BooleanShape booleanShape) {
public Symbol listShape(ListShape listShape) {
// Lists with unique Items are treated as Sequenced Sets
if (listShape.hasTrait(UniqueItemsTrait.class)) {
return SymbolUtils.fromClass(SequencedSet.class)
return SymbolUtils.fromClass(Set.class)
.toBuilder()
.putProperty(SymbolProperties.COLLECTION_COPY_METHOD, "unmodifiableSequencedSet")
.putProperty(SymbolProperties.COLLECTION_COPY_METHOD, "unmodifiableSet")
.putProperty(SymbolProperties.COLLECTION_IMPLEMENTATION_CLASS, LinkedHashSet.class)
.putProperty(SymbolProperties.COLLECTION_EMPTY_METHOD, "emptySortedSet()")
.putProperty(SymbolProperties.COLLECTION_EMPTY_METHOD, "emptySet()")
.addReference(listShape.getMember().accept(this))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,22 @@ public void run() {
var iter = traitsToAdd.iterator();
while (iter.hasNext()) {
var traitId = iter.next();
switch (shape.getAllTraits().get(traitId)) {
case AnnotationTrait a -> writer.writeInline("new $T()", a.getClass());
case StringTrait st -> writer.writeInline("new $T($S)", st.getClass(), st.getValue());
case StringListTrait slt -> writer.writeInline(
"new $T($S, $T.NONE)",
slt.getClass(),
slt.getValues(),
SourceLocation.class
Trait trait = shape.getAllTraits().get(traitId);
if (trait instanceof AnnotationTrait) {
writer.writeInline("new $T()", trait.getClass());
} else if (trait instanceof StringTrait) {
writer.writeInline("new $T($S)", trait.getClass(), ((StringTrait) trait).getValue());
} else if (trait instanceof StringListTrait) {
writer.writeInline(
"new $T($S, $T.NONE)",
trait.getClass(),
((StringListTrait) trait).getValues(),
SourceLocation.class
);
case Trait t -> traitFactoryInitializer(writer, t);
} else {
traitFactoryInitializer(writer, trait);
}

if (iter.hasNext()) {
writer.writeInline(",").newLine();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ public boolean isIntercepted(CodeSection section) {

@Override
public void prepend(JavaWriter writer, CodeSection section) {
Shape shape = switch (section) {
case ClassSection s -> s.shape();
case GetterSection s -> s.memberShape();
default -> throw new IllegalArgumentException("Javadocs cannot be injected for section: " + section);
};
Shape shape;
if (section instanceof ClassSection) {
shape = ((ClassSection) section).shape();
} else if (section instanceof GetterSection) {
shape = ((GetterSection) section).memberShape();
} else {
throw new IllegalArgumentException("Javadocs cannot be injected for section: " + section);
}

writer.injectSection(new JavadocSection(shape));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ public JavaWriter apply(String filename, String namespace) {
private final class JavaTypeFormatter implements BiFunction<Object, String, String> {
@Override
public String apply(Object type, String indent) {
Symbol typeSymbol = switch (type) {
case Symbol s -> s;
case Class<?> c -> SymbolUtils.fromClass(c);
case SymbolReference r -> r.getSymbol();
default -> throw new IllegalArgumentException(
"Invalid type provided for $T. Expected a Symbol or Class"
+ " but found: `" + type + "`."
);
};

Symbol typeSymbol;
if (type instanceof Symbol) {
typeSymbol = (Symbol) type;
} else if (type instanceof Class<?>) {
typeSymbol = SymbolUtils.fromClass((Class<?>) type);
} else if (type instanceof SymbolReference) {
typeSymbol = ((SymbolReference) type).getSymbol();
} else {
throw new IllegalArgumentException(
"Invalid type provided for $T. Expected a Symbol or Class"
+ " but found: `" + type + "`.");
}

if (typeSymbol.getReferences().isEmpty()) {
return getPlaceholder(typeSymbol);
Expand Down Expand Up @@ -187,15 +191,18 @@ private final class BoxedTypeFormatter implements BiFunction<Object, String, Str

@Override
public String apply(Object type, String indent) {
Symbol typeSymbol = switch (type) {
case Symbol s -> s;
case Class<?> c -> SymbolUtils.fromClass(c);
case SymbolReference r -> r.getSymbol();
default -> throw new IllegalArgumentException(
"Invalid type provided for $B. Expected a Symbol or Class"
+ " but found: `" + type + "`."
);
};
Symbol typeSymbol;
if (type instanceof Symbol) {
typeSymbol = (Symbol) type;
} else if (type instanceof Class<?>) {
typeSymbol = SymbolUtils.fromClass((Class<?>) type);
} else if (type instanceof SymbolReference) {
typeSymbol = ((SymbolReference) type).getSymbol();
} else {
throw new IllegalArgumentException(
"Invalid type provided for $B. Expected a Symbol or Class"
+ " but found: `" + type + "`.");
}

if (typeSymbol.getProperty(SymbolProperties.BOXED_TYPE).isPresent()) {
typeSymbol = typeSymbol.expectProperty(SymbolProperties.BOXED_TYPE, Symbol.class);
Expand Down
4 changes: 2 additions & 2 deletions config/spotless/formatting.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<profiles version="21">
<profile kind="CodeFormatterProfile" name="Smithy Formatting" version="21">
<profiles version="17">
<profile kind="CodeFormatterProfile" name="Smithy Formatting" version="17">
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert"/>
Expand Down
4 changes: 0 additions & 4 deletions examples/restjson-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
alias(libs.plugins.jmh)
}

tasks.compileJava {
options.release = 21
}

dependencies {
api(project(":client-aws-rest-json1"))
api(libs.smithy.aws.traits)
Expand Down

0 comments on commit 5073dec

Please sign in to comment.