mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
remove Value class, add NewExpression and separate out Any classes
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
/**
|
||||
* @typedef {import('./expressiontypes/Expression').Expression} Expression
|
||||
*/
|
||||
const { JavaType, ArrayType, Method, Parameter, Field } = require('java-mti');
|
||||
const { Token } = require('./tokenizer');
|
||||
|
||||
class ResolvedIdent {
|
||||
/**
|
||||
* @param {string} ident
|
||||
* @param {(Local|Parameter|Field|ArrayElement|ValueBase)[]} variables
|
||||
* @param {(Local|Parameter|Field|Expression)[]} variables
|
||||
* @param {Method[]} methods
|
||||
* @param {JavaType[]} types
|
||||
* @param {string} package_name
|
||||
@@ -20,45 +23,6 @@ class ResolvedIdent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AnyType is a special type that's used to fill in types that are missing.
|
||||
* To prevent cascading errors, AnyType should be fully assign/cast/type-compatible
|
||||
* with any other type
|
||||
*/
|
||||
class AnyType extends JavaType {
|
||||
/**
|
||||
*
|
||||
* @param {String} label
|
||||
*/
|
||||
constructor(label) {
|
||||
super("class", [], '');
|
||||
super.simpleTypeName = label || '<unknown type>';
|
||||
}
|
||||
|
||||
static Instance = new AnyType('');
|
||||
|
||||
get rawTypeSignature() {
|
||||
return 'U';
|
||||
}
|
||||
|
||||
get typeSignature() {
|
||||
return 'U';
|
||||
}
|
||||
}
|
||||
|
||||
class AnyMethod extends Method {
|
||||
/**
|
||||
* @param {string} name
|
||||
*/
|
||||
constructor(name) {
|
||||
super(null, name, [], '');
|
||||
}
|
||||
|
||||
get returnType() {
|
||||
return AnyType.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
class Local {
|
||||
/**
|
||||
* @param {Token[]} modifiers
|
||||
@@ -115,91 +79,7 @@ class MethodDeclarations {
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayElement {
|
||||
/**
|
||||
*
|
||||
* @param {Local|Parameter|Field|ArrayElement|Value} array_variable
|
||||
* @param {ResolvedIdent} index
|
||||
*/
|
||||
constructor(array_variable, index) {
|
||||
this.array_variable = array_variable;
|
||||
this.index = index;
|
||||
if (!(this.array_variable.type instanceof ArrayType)) {
|
||||
throw new Error('Array element cannot be created from non-array type');
|
||||
}
|
||||
this.name = `${array_variable.name}[${index.source}]`;
|
||||
/** @type {JavaType} */
|
||||
this.type = this.array_variable.type.elementType;
|
||||
}
|
||||
}
|
||||
|
||||
class ValueBase {}
|
||||
|
||||
class Value extends ValueBase {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {JavaType} type
|
||||
*/
|
||||
constructor(name, type) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
class AnyValue extends Value {
|
||||
constructor(name) {
|
||||
super(name, AnyType.Instance);
|
||||
}
|
||||
}
|
||||
|
||||
class MethodCall extends Value {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {ResolvedIdent} instance
|
||||
* @param {Method} method
|
||||
*/
|
||||
constructor(name, instance, method) {
|
||||
super(name, method.returnType);
|
||||
this.instance = instance;
|
||||
this.method = method;
|
||||
}
|
||||
}
|
||||
|
||||
class ConstructorCall extends Value {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {JavaType} type
|
||||
*/
|
||||
constructor(name, type) {
|
||||
super(name, type);
|
||||
}
|
||||
}
|
||||
|
||||
class TernaryValue extends Value {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {JavaType} true_type
|
||||
* @param {Token} colon
|
||||
* @param {Value} false_value
|
||||
*/
|
||||
constructor(name, true_type, colon, false_value) {
|
||||
super(name, true_type);
|
||||
this.colon = colon;
|
||||
this.falseValue = false_value;
|
||||
}
|
||||
}
|
||||
|
||||
exports.AnyMethod = AnyMethod;
|
||||
exports.AnyType = AnyType;
|
||||
exports.AnyValue = AnyValue;
|
||||
exports.ArrayElement = ArrayElement;
|
||||
exports.ConstructorCall = ConstructorCall;
|
||||
exports.Label = Label;
|
||||
exports.Local = Local;
|
||||
exports.MethodCall = MethodCall;
|
||||
exports.MethodDeclarations = MethodDeclarations;
|
||||
exports.ResolvedIdent = ResolvedIdent;
|
||||
exports.TernaryValue = TernaryValue;
|
||||
exports.Value = Value;
|
||||
exports.ValueBase = ValueBase;
|
||||
|
||||
Reference in New Issue
Block a user