mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 09:59:25 +00:00
resolve new object contructors
This commit is contained in:
@@ -1598,8 +1598,8 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
||||
const new_token = tokens.current;
|
||||
tokens.expectValue('new');
|
||||
const ctr_type = typeIdent(tokens, scope, imports, typemap, {no_array_qualifiers:true, type_vars:[]});
|
||||
let match = new ResolvedIdent(`new ${ctr_type.resolved.simpleTypeName}`, [], [], [ctr_type.resolved]);
|
||||
let ctr_args = [], type_body = null, newtokens;
|
||||
let match = new ResolvedIdent(`new ${ctr_type.resolved.simpleTypeName}`, [], [], []);
|
||||
let newtokens;
|
||||
switch(tokens.current.value) {
|
||||
case '[':
|
||||
match = arrayQualifiers(match, tokens, mdecls, scope, imports, typemap);
|
||||
@@ -1611,9 +1611,10 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
||||
}
|
||||
return new ResolvedIdent(match.source, [new NewArray(new_token, ctr_type, match)], [], [], '', newtokens);
|
||||
case '(':
|
||||
tokens.inc();
|
||||
let ctr_args = [], commas = [], type_body = null;
|
||||
let open_bracket = tokens.consume();
|
||||
if (!tokens.isValue(')')) {
|
||||
({ expressions: ctr_args } = expressionList(tokens, mdecls, scope, imports, typemap));
|
||||
({ expressions: ctr_args, commas } = expressionList(tokens, mdecls, scope, imports, typemap));
|
||||
tokens.expectValue(')');
|
||||
}
|
||||
newtokens = tokens.markEnd();
|
||||
@@ -1622,13 +1623,11 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
||||
// anonymous type - just skip for now
|
||||
type_body = skipBody(tokens);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return new ResolvedIdent(match.source, [new NewObject(new_token, ctr_type, open_bracket, ctr_args, commas, type_body)], [], [], '', newtokens);
|
||||
}
|
||||
newtokens = tokens.markEnd();
|
||||
addproblem(tokens, ParseProblem.Error(tokens.current, 'Constructor expression expected'));
|
||||
break;
|
||||
}
|
||||
return new ResolvedIdent(match.source, [new NewObject(new_token, ctr_type, ctr_args, type_body)], [], [], '', newtokens);
|
||||
return match;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -317,3 +317,4 @@ function isCallCompatible(m, arg_types) {
|
||||
}
|
||||
|
||||
exports.MethodCallExpression = MethodCallExpression;
|
||||
exports.resolveConstructorCall = resolveConstructorCall;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
const { Expression } = require("./Expression");
|
||||
const { ArrayType } = require('java-mti');
|
||||
const { FixedLengthArrayType, SourceArrayType } = require('../source-types');
|
||||
const ParseProblem = require('../parsetypes/parse-problem');
|
||||
const { checkArrayIndex } = require('../expression-resolver');
|
||||
const { resolveConstructorCall } = require('./MethodCallExpression');
|
||||
|
||||
class NewArray extends Expression {
|
||||
/**
|
||||
@@ -61,14 +61,18 @@ class NewObject extends Expression {
|
||||
/**
|
||||
* @param {Token} new_token
|
||||
* @param {SourceTypeIdent} object_type
|
||||
* @param {Token} open_bracket
|
||||
* @param {ResolvedIdent[]} ctr_args
|
||||
* @param {Token[]} commas
|
||||
* @param {Token[]} type_body
|
||||
*/
|
||||
constructor(new_token, object_type, ctr_args, type_body) {
|
||||
constructor(new_token, object_type, open_bracket, ctr_args, commas, type_body) {
|
||||
super();
|
||||
this.new_token = new_token;
|
||||
this.object_type = object_type;
|
||||
this.open_bracket = open_bracket;
|
||||
this.ctr_args = ctr_args;
|
||||
this.commas = commas;
|
||||
this.type_body = type_body;
|
||||
}
|
||||
|
||||
@@ -76,6 +80,7 @@ class NewObject extends Expression {
|
||||
* @param {ResolveInfo} ri
|
||||
*/
|
||||
resolveExpression(ri) {
|
||||
resolveConstructorCall(ri, this.object_type.resolved.constructors, this.open_bracket, this.ctr_args, this.commas, () => this.tokens());
|
||||
return this.object_type.resolved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user