Fix record ctor with throws

This commit is contained in:
Clément Fournier
2020-03-02 19:00:59 +01:00
parent f49a6dbc3d
commit fc0b437ad7
2 changed files with 16 additions and 3 deletions

View File

@ -1152,9 +1152,15 @@ void RecordBody():
void RecordBodyDeclaration() #void :
{}
{
LOOKAHEAD(ClassOrInterfaceBodyDeclaration()) ClassOrInterfaceBodyDeclaration()
LOOKAHEAD(RecordCtorLookahead()) RecordConstructorDeclaration()
|
RecordConstructorDeclaration()
ClassOrInterfaceBodyDeclaration()
}
private void RecordCtorLookahead() #void:
{}
{
Modifiers() [ TypeParameters() ] <IDENTIFIER> ("throws" | "{")
}
void RecordConstructorDeclaration():
@ -1165,6 +1171,7 @@ void RecordConstructorDeclaration():
modifiers = Modifiers() { jjtThis.setModifiers(modifiers); }
[TypeParameters()]
<IDENTIFIER> { jjtThis.setImage(token.image); }
[ "throws" NameList() ]
"{" ( BlockStatement() )* "}"
}

View File

@ -1,3 +1,4 @@
import java.io.IOException;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@ -54,5 +55,10 @@ public class Records {
String lastName();
}
public record PersonRecord(String firstName, String lastName)
implements Person, java.io.Serializable { }
implements Person, java.io.Serializable {
PersonRecord throws IOException { // compact ctor with throws list
throw new IOException();
}
}
}