Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing java primitives to annotation constant params parsing #2610

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ class DefaultPsiToDocumentableTranslator(
}

private fun Any.toAnnotationLiteralValue() = when (this) {
is Byte -> IntValue(this.toInt())
is Short -> IntValue(this.toInt())
is Char -> StringValue(this.toString())
is Int -> IntValue(this)
is Long -> LongValue(this)
is Boolean -> BooleanValue(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
|import static test.JavaConstants.BOOLEAN;
|import static test.JavaConstants.DOUBLE;
|import static test.JavaConstants.FLOAT;
|import static test.JavaConstants.BYTE;
|import static test.JavaConstants.SHORT;
|import static test.JavaConstants.CHAR;
|
|@JavaAnnotation(
| stringValue = STRING, intValue = INTEGER, longValue = LONG,
| booleanValue = BOOLEAN, doubleValue = DOUBLE, floatValue = FLOAT
| byteValue = BYTE, shortValue = SHORT, intValue = INTEGER, longValue = LONG, booleanValue = BOOLEAN,
| doubleValue = DOUBLE, floatValue = FLOAT, stringValue = STRING, charValue = CHAR
|)
|public class JavaClassUsingAnnotation {
|}
Expand All @@ -223,23 +226,29 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
|package test;
|@Documented
|public @interface JavaAnnotation {
| String stringValue();
| byte byteValue();
| short shortValue();
| int intValue();
| long longValue();
| boolean booleanValue();
| double doubleValue();
| float floatValue();
| String stringValue();
| char charValue();
|}
|
|/src/main/java/test/JavaConstants.java
|package test;
|public class JavaConstants {
| public static final String STRING = "STRING_CONSTANT_VALUE";
| public static final byte BYTE = 3;
| public static final short SHORT = 4;
| public static final int INTEGER = 5;
| public static final long LONG = 6L;
| public static final boolean BOOLEAN = true;
| public static final double DOUBLE = 7.0d;
| public static final float FLOAT = 8.0f;
| public static final String STRING = "STRING_CONSTANT_VALUE";
| public static final char CHAR = 'c';
|}
""".trimIndent(),
configuration
Expand All @@ -251,13 +260,16 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
checkNotNull(annotation)

assertEquals("JavaAnnotation", annotation.dri.classNames)
assertEquals(StringValue("STRING_CONSTANT_VALUE"), annotation.params["stringValue"])

assertEquals(IntValue(3), annotation.params["byteValue"])
assertEquals(IntValue(4), annotation.params["shortValue"])
assertEquals(IntValue(5), annotation.params["intValue"])
assertEquals(LongValue(6), annotation.params["longValue"])
assertEquals(BooleanValue(true), annotation.params["booleanValue"])
assertEquals(DoubleValue(7.0), annotation.params["doubleValue"])
assertEquals(FloatValue(8.0f), annotation.params["floatValue"])
assertEquals(StringValue("STRING_CONSTANT_VALUE"), annotation.params["stringValue"])
assertEquals(StringValue("c"), annotation.params["charValue"])
}
}
}
Expand Down