updated validation to use new JavaTypes module instead of MTIs

This commit is contained in:
Dave Holoway
2020-05-26 18:41:35 +01:00
parent a46474c3c2
commit ff8cf5b91a
22 changed files with 994 additions and 1455 deletions

View File

@@ -1,7 +1,5 @@
const Declaration = require('./declaration');
const ParseProblem = require('./parse-problem');
const Token = require('./token');
const TypeParameters = require('./type-parameters');
/**
* @typedef {import('./modifier')} Modifier
@@ -34,35 +32,6 @@ class ImportDeclaration extends Declaration {
lastToken() {
return this.semicolon || this.asterisk || this.nameparts.slice(-1)[0];
}
validate() {
const checkModifierIsStatic = () => {
if (this.static_ && this.static_.text !== 'static') {
return ParseProblem.syntaxError(this.static_);
}
}
const checkNoInvalidModifiers = () => {
return this.modifiers.map(modifier => {
if (modifier instanceof Token) {
return ParseProblem.syntaxError(modifier);
}
if (modifier instanceof TypeParameters) {
return ParseProblem.syntaxError(modifier.open);
}
})
}
/** @type {ParseProblem[]} */
const problems = [
checkModifierIsStatic(),
...ParseProblem.checkNonKeywordIdents(this.nameparts),
ParseProblem.checkSemicolon(this),
...checkNoInvalidModifiers(),
];
return problems;
}
}
module.exports = ImportDeclaration;

View File

@@ -1,17 +1,20 @@
/**
* @typedef {import('java-mti').JavaType} JavaType
*/
const { ImportBlock } = require('../parser9');
/**
* Class representing a resolved import.
*
* Each instance holds an array of types that would be resolved by the specified import.
* Each type is mapped to an MTI which lists the implementation details of the type (fields, methods, etc).
* Each type is mapped to a JavaType which lists the implementation details of the type (fields, methods, etc).
*
*/
class ResolvedImport {
/**
* @param {ImportBlock} import_decl
* @param {RegExpMatchArray} matches
* @param {Map<string,import('../mti').Type>} typemap
* @param {Map<string,JavaType>} typemap
* @param {'owner-package'|'import'|'implicit-import'} import_kind
*/
constructor(import_decl, matches, typemap, import_kind) {
@@ -27,7 +30,7 @@ const { ImportBlock } = require('../parser9');
this.fullyQualifiedNames = Array.from(matches);
/**
* THe map of fully-qualified type names to MTIs
* THe map of fully-qualified type names to JavaTypes
*/
this.types = new Map(matches.map(name => [name, typemap.get(name)]));

View File

@@ -1,6 +1,7 @@
/**
* @typedef {import('./token')} Token
* @typedef {import('./type')} TypeDeclaration
* @typedef {import('java-mti').JavaType} JavaType
*/
/**
@@ -78,8 +79,8 @@ class ResolvedType {
error = '';
/**
* The resolved MTIs that match this type. This will be an empty array if the type cannot be found.
* @type {import('../mti').Type[]}
* The resolved JavaTypes that match this type. This will be an empty array if the type cannot be found.
* @type {JavaType[]}
*/
mtis = [];