Skip to content

Commit

Permalink
Adds contains() method to TypeAndElementSource
Browse files Browse the repository at this point in the history
Signed-off-by: Laird Nelson <[email protected]>
  • Loading branch information
ljnelson committed Oct 16, 2024
1 parent 846bee1 commit c6eb71b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Maven dependency:
<groupId>org.microbean</groupId>
<artifactId>microbean-lang</artifactId>
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-lang for up-to-date available versions. -->
<version>0.0.20</version>
<version>0.0.21</version>
</dependency>
```

Expand Down
5 changes: 5 additions & 0 deletions lang/src/main/java/org/microbean/lang/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,11 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return Lang.boxedClass(t);
}

@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return Lang.contains(t, s);
}

@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... typeArguments) {
return Lang.declaredType(typeElement, typeArguments);
Expand Down
16 changes: 15 additions & 1 deletion lang/src/main/java/org/microbean/lang/TypeAndElementSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ public interface TypeAndElementSource {
// Note the strange positioning of payload and receiver.
public boolean assignable(final TypeMirror payload, final TypeMirror receiver);

public TypeElement boxedClass(final PrimitiveType t);
public default TypeElement boxedClass(final PrimitiveType t) {
return switch (t.getKind()) { // won't cause symbol completion
case BOOLEAN -> this.typeElement("java.lang.Boolean");
case BYTE -> this.typeElement("java.lang.Byte");
case CHAR -> this.typeElement("java.lang.Character");
case DOUBLE -> this.typeElement("java.lang.Double");
case FLOAT -> this.typeElement("java.lang.Float");
case INT -> this.typeElement("java.lang.Integer");
case LONG -> this.typeElement("java.lang.Long");
case SHORT -> this.typeElement("java.lang.Short");
default -> throw new IllegalArgumentException("t: " + t);
};
}

public boolean contains(final TypeMirror t, final TypeMirror s);

public DeclaredType declaredType(final DeclaredType enclosingType,
final TypeElement typeElement,
Expand Down
4 changes: 4 additions & 0 deletions lang/src/test/java/org/microbean/lang/TestErase.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return javacModelTypes.boxedClass(t);
}
@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return javacModelTypes.contains(t, s);
}
@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... arguments) {
return javacModelTypes.getDeclaredType(typeElement, arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return javacModelTypes.boxedClass(t);
}
@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return javacModelTypes.contains(t, s);
}
@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... arguments) {
return javacModelTypes.getDeclaredType(typeElement, arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return javacModelTypes.boxedClass(t);
}
@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return javacModelTypes.contains(t, s);
}
@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... arguments) {
return javacModelTypes.getDeclaredType(typeElement, arguments);
}
Expand Down
8 changes: 8 additions & 0 deletions lang/src/test/java/org/microbean/lang/TestTypeClosure.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return javacModelTypes.boxedClass(t);
}
@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return javacModelTypes.contains(t, s);
}
@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... arguments) {
return javacModelTypes.getDeclaredType(typeElement, arguments);
}
Expand Down Expand Up @@ -210,6 +214,10 @@ public final TypeElement boxedClass(final PrimitiveType t) {
return javacModelTypes.boxedClass(t);
}
@Override
public final boolean contains(final TypeMirror t, final TypeMirror s) {
return javacModelTypes.contains(t, s);
}
@Override
public final DeclaredType declaredType(final TypeElement typeElement, final TypeMirror... arguments) {
return javacModelTypes.getDeclaredType(typeElement, arguments);
}
Expand Down

0 comments on commit c6eb71b

Please sign in to comment.