Skip to content

Commit

Permalink
Fix record ctor with throws
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Mar 2, 2020
1 parent f49a6db commit fc0b437
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pmd-java/etc/grammar/Java.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -1165,6 +1171,7 @@ void RecordConstructorDeclaration():
modifiers = Modifiers() { jjtThis.setModifiers(modifiers); }
[TypeParameters()]
<IDENTIFIER> { jjtThis.setImage(token.image); }
[ "throws" NameList() ]
"{" ( BlockStatement() )* "}"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.io.IOException;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

Expand Down Expand Up @@ -54,5 +55,10 @@ public interface Person {
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();
}
}
}

0 comments on commit fc0b437

Please sign in to comment.