Skip to content

Commit

Permalink
Use autocasting instanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
hpmellema committed Apr 26, 2024
1 parent dfad098 commit 4807502
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void run() {
while (iter.hasNext()) {
var traitId = iter.next();
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) {
if (trait instanceof AnnotationTrait at) {
writer.writeInline("new $T()", at.getClass());
} else if (trait instanceof StringTrait st) {
writer.writeInline("new $T($S)", st.getClass(), st.getValue());
} else if (trait instanceof StringListTrait slt) {
writer.writeInline(
"new $T($S, $T.NONE)",
trait.getClass(),
((StringListTrait) trait).getValues(),
slt.getValues(),
SourceLocation.class
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public boolean isIntercepted(CodeSection section) {
@Override
public void prepend(JavaWriter writer, CodeSection section) {
Shape shape;
if (section instanceof ClassSection) {
shape = ((ClassSection) section).shape();
} else if (section instanceof GetterSection) {
shape = ((GetterSection) section).memberShape();
if (section instanceof ClassSection cs) {
shape = cs.shape();
} else if (section instanceof GetterSection gs) {
shape = gs.memberShape();
} else {
throw new IllegalArgumentException("Javadocs cannot be injected for section: " + section);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ private final class JavaTypeFormatter implements BiFunction<Object, String, Stri
public String apply(Object type, String indent) {

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();
if (type instanceof Symbol s) {
typeSymbol = s;
} else if (type instanceof Class<?> c) {
typeSymbol = SymbolUtils.fromClass(c);
} else if (type instanceof SymbolReference r) {
typeSymbol = r.getSymbol();
} else {
throw new IllegalArgumentException(
"Invalid type provided for $T. Expected a Symbol or Class"
Expand Down Expand Up @@ -193,12 +193,12 @@ private final class BoxedTypeFormatter implements BiFunction<Object, String, Str
@Override
public String apply(Object type, String indent) {
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();
if (type instanceof Symbol s) {
typeSymbol = s;
} else if (type instanceof Class<?> c) {
typeSymbol = SymbolUtils.fromClass(c);
} else if (type instanceof SymbolReference r) {
typeSymbol = r.getSymbol();
} else {
throw new IllegalArgumentException(
"Invalid type provided for $B. Expected a Symbol or Class"
Expand Down

0 comments on commit 4807502

Please sign in to comment.