make default a modifer keyword for interface default method support

This commit is contained in:
Dave Holoway
2020-06-07 16:22:38 +01:00
parent 4750212484
commit 6ef64b1d9c
2 changed files with 9 additions and 2 deletions

View File

@@ -241,8 +241,8 @@ function tokenize(source) {
}
if (m[4]) {
// ident or keyword
const KEYWORDS = /^(assert|break|case|catch|class|const|continue|default|do|else|enum|extends|finally|for|goto|if|implements|import|interface|new|package|return|super|switch|throw|throws|try|while)$/;
const MODIFIER_KEYWORDS = /^(abstract|final|native|private|protected|public|static|strictfp|synchronized|transient|volatile)$/;
const KEYWORDS = /^(assert|break|case|catch|class|const|continue|do|else|enum|extends|finally|for|goto|if|implements|import|interface|new|package|return|super|switch|throw|throws|try|while)$/;
const MODIFIER_KEYWORDS = /^(abstract|final|native|private|protected|public|static|strictfp|synchronized|transient|volatile|default)$/;
const PRIMITIVE_TYPE_KEYWORDS = /^(int|boolean|byte|char|double|float|long|short|void)$/
const LITERAL_VALUE_KEYWORDS = /^(this|true|false|null)$/;
const OPERATOR_KEYWORDS = /^(instanceof)$/;

View File

@@ -96,6 +96,13 @@ function checkMethodModifiers(type, ownertypemods, method, probs) {
if (allmods.has('native') && method.body().simplified.startsWith('B')) {
probs.push(ParseProblem.Error(allmods.get('native'), 'Method declarations marked as native cannot have a method body'));
}
// JLS8
if (type.kind() !== 'interface' && allmods.has('default')) {
probs.push(ParseProblem.Error(method, `Default method declarations are only allowed inside interfaces`));
}
if (allmods.has('default') && !method.body().simplified.startsWith('B')) {
probs.push(ParseProblem.Error(method, `Default method declarations must have an implementation`));
}
}
/**