Skip to content

Commit

Permalink
impr: Support for annotation values of special numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Feb 24, 2024
1 parent 238c838 commit 1a4a7df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.annotation TestAnnotation {
number: 15,
bogusNumber: NaN,
charValue: 'c',
subWithString: .annotation org/jetbrains/annotations/NotNull {
value: "Hello, world!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.darknet.assembler.instructions.Instructions;
import me.darknet.assembler.parser.BytecodeFormat;
import me.darknet.assembler.parser.Stateful;
import me.darknet.assembler.util.DescriptorUtil;
import me.darknet.assembler.util.ElementMap;
import me.darknet.assembler.util.Location;
import me.darknet.assembler.visitor.Modifiers;
Expand Down Expand Up @@ -236,9 +237,19 @@ static ASTElement validateElementValue(ParserContext ctx, ASTElement value) {
}
case IDENTIFIER -> {
ASTIdentifier identifier = (ASTIdentifier) value;
if (identifier.content().equals("true") || identifier.content().equals("false")) {
value = new ASTBool(identifier.value());
}
value = switch (identifier.content().toLowerCase()) {
case "true", "false" -> new ASTBool(identifier.value());
case "nan", "nand", "nanf",
"+infinity", "+infinityd", "infinity", "infinityd",
"+infinityf", "infinityf", "-infinity", "-infinityd", "-infinityf" -> new ASTNumber(identifier.value());
default -> {
if (!DescriptorUtil.isValidFieldDescriptor('L' + identifier.literal() + ';')) {
ctx.throwUnexpectedElementError("Expected class type, boolean, or special number", value);
yield null;
}
yield value;
}
};
}
case EMPTY -> value = ASTEmpty.EMPTY_ARRAY;
case DECLARATION -> {
Expand Down

0 comments on commit 1a4a7df

Please sign in to comment.