mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
initial test of context-dependant code completion
This commit is contained in:
@@ -205,7 +205,7 @@ function parse(source, typemap) {
|
||||
const timeEnd = name => (timers.delete(name), console.timeEnd(name));
|
||||
try {
|
||||
time('tokenize');
|
||||
tokens = new TokenList(tokenize(source));
|
||||
tokens = new TokenList(unit.tokens = tokenize(source));
|
||||
problems = tokens.problems;
|
||||
timeEnd('tokenize');
|
||||
|
||||
@@ -318,16 +318,22 @@ function parseUnit(tokens, unit, typemap) {
|
||||
*/
|
||||
function packageDeclaration(tokens) {
|
||||
tokens.mark();
|
||||
const package_token = tokens.current;
|
||||
package_token.loc = 'pkgname:';
|
||||
tokens.expectValue('package');
|
||||
const pkg_name_parts = [];
|
||||
let pkg_name_parts = [], dot;
|
||||
for (;;) {
|
||||
let name = tokens.current;
|
||||
if (!tokens.isKind('ident')) {
|
||||
name = null;
|
||||
addproblem(tokens, ParseProblem.Error(tokens.current, `Package identifier expected`));
|
||||
}
|
||||
if (name) pkg_name_parts.push(name.value);
|
||||
if (tokens.isValue('.')) {
|
||||
if (name) {
|
||||
name.loc = `pkgname:${pkg_name_parts.join('/')}`;
|
||||
pkg_name_parts.push(name.value);
|
||||
}
|
||||
if (dot = tokens.getIfValue('.')) {
|
||||
dot.loc = `pkgname:${pkg_name_parts.join('/')}`;
|
||||
continue;
|
||||
}
|
||||
const decl_tokens = tokens.markEnd();
|
||||
|
||||
@@ -366,6 +366,7 @@ class SourceConstructor extends Constructor {
|
||||
this.sourceParameters = parameters;
|
||||
this.throws = throws;
|
||||
this.body = body;
|
||||
this.parsed = null;
|
||||
}
|
||||
|
||||
get hasImplementation() {
|
||||
@@ -411,6 +412,7 @@ class SourceMethod extends Method {
|
||||
this.sourceParameters = parameters;
|
||||
this.throws = throws;
|
||||
this.body = body;
|
||||
this.parsed = null;
|
||||
}
|
||||
|
||||
get hasImplementation() {
|
||||
@@ -449,6 +451,7 @@ class SourceInitialiser extends MethodBase {
|
||||
this.owner = owner;
|
||||
this.modifierTokens = modifiers;
|
||||
this.body = body;
|
||||
this.parsed = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,12 +538,38 @@ class SourceImport {
|
||||
}
|
||||
|
||||
class SourceUnit {
|
||||
/** @type {Token[]} */
|
||||
tokens = [];
|
||||
/** @type {SourcePackage} */
|
||||
package_ = null;
|
||||
/** @type {SourceImport[]} */
|
||||
imports = [];
|
||||
/** @type {SourceType[]} */
|
||||
types = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} char_index
|
||||
*/
|
||||
getCompletionOptionsAt(char_index) {
|
||||
let i = 0;
|
||||
let loc = '';
|
||||
for (let tok of this.tokens) {
|
||||
if (char_index > tok.range.start + tok.range.length) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
while (i > 0 && tok.kind === 'wsc') {
|
||||
tok = this.tokens[--i];
|
||||
}
|
||||
loc = tok.loc;
|
||||
break;
|
||||
}
|
||||
return {
|
||||
index: char_index,
|
||||
loc: loc,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class SourceArrayType extends ArrayType {
|
||||
|
||||
@@ -49,6 +49,7 @@ class Token extends TextBlock {
|
||||
constructor(text, start, length, kind) {
|
||||
super(new BlockRange(text, start, length), tokenKindToSimplified(text, start, length, kind));
|
||||
this.kind = kind;
|
||||
this.loc = '';
|
||||
}
|
||||
|
||||
get value() {
|
||||
|
||||
@@ -3,6 +3,28 @@ const { resolveImports } = require('../java/import-resolver');
|
||||
const { SourceUnit } = require('./source-types');
|
||||
const { parseBody } = require('./body-parser3');
|
||||
|
||||
/**
|
||||
* @param {SourceUnit} unit
|
||||
* @param {Map<string, CEIType>} androidLibrary
|
||||
*/
|
||||
function parseMethodBodies(unit, androidLibrary) {
|
||||
const resolved_types = [
|
||||
...resolveImports(androidLibrary, [], [], null).resolved,
|
||||
...unit.imports.filter(i => i.resolved).map(i => i.resolved),
|
||||
]
|
||||
unit.types.forEach(t => {
|
||||
t.initers.forEach(i => {
|
||||
i.parsed = parseBody(i, resolved_types, androidLibrary);
|
||||
})
|
||||
t.constructors.forEach(c => {
|
||||
c.parsed = parseBody(c, resolved_types, androidLibrary);
|
||||
})
|
||||
t.sourceMethods.forEach(m => {
|
||||
m.parsed = parseBody(m, resolved_types, androidLibrary);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {SourceUnit} unit
|
||||
* @param {Map<string, CEIType>} androidLibrary
|
||||
@@ -12,41 +34,20 @@ function validate(unit, androidLibrary) {
|
||||
console.time('validation');
|
||||
|
||||
let probs = [];
|
||||
const resolved_types = [
|
||||
...resolveImports(androidLibrary, [], [], null).resolved,
|
||||
...unit.imports.filter(i => i.resolved).map(i => i.resolved),
|
||||
]
|
||||
unit.types.forEach(t => {
|
||||
t.initers.forEach(i => {
|
||||
const parsed = parseBody(i, resolved_types, androidLibrary);
|
||||
if (parsed)
|
||||
probs = probs.concat(parsed.problems)
|
||||
})
|
||||
t.constructors.forEach(c => {
|
||||
const parsed = parseBody(c, resolved_types, androidLibrary);
|
||||
if (parsed)
|
||||
probs = probs.concat(parsed.problems)
|
||||
})
|
||||
t.sourceMethods.forEach(m => {
|
||||
const parsed = parseBody(m, resolved_types, androidLibrary);
|
||||
if (parsed)
|
||||
probs = probs.concat(parsed.problems)
|
||||
})
|
||||
})
|
||||
|
||||
const module_validaters = [
|
||||
// require('./validation/multiple-package-decls'),
|
||||
// require('./validation/unit-decl-order'),
|
||||
// require('./validation/duplicate-members'),
|
||||
// require('./validation/parse-errors'),
|
||||
require('./validation/modifier-errors'),
|
||||
require('./validation/unresolved-imports'),
|
||||
require('./validation/invalid-types'),
|
||||
require('./validation/bad-extends'),
|
||||
require('./validation/bad-implements'),
|
||||
require('./validation/non-implemented-interfaces'),
|
||||
require('./validation/bad-overrides'),
|
||||
require('./validation/missing-constructor'),
|
||||
// require('./validation/modifier-errors'),
|
||||
// require('./validation/unresolved-imports'),
|
||||
// require('./validation/invalid-types'),
|
||||
// require('./validation/bad-extends'),
|
||||
// require('./validation/bad-implements'),
|
||||
// require('./validation/non-implemented-interfaces'),
|
||||
// require('./validation/bad-overrides'),
|
||||
// require('./validation/missing-constructor'),
|
||||
//require('./validation/expression-compatibility'),
|
||||
];
|
||||
let problems = [
|
||||
@@ -73,4 +74,5 @@ function validate(unit, androidLibrary) {
|
||||
|
||||
module.exports = {
|
||||
validate,
|
||||
parseMethodBodies,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user