
var BaseTranspiler = require('./BaseTranspiler.js');
var util = require('util');

function ExpressionTranspiler(parent) {
	BaseTranspiler.call(this, parent);
	return this;
}

util.inherits(ExpressionTranspiler, BaseTranspiler);

BaseTranspiler.prototype.visitLiteral = function(ctx) {
	// BUG: We assume, that Java and Javascript have the same literals.
	// This is potentional unsafe.
	var result = {
		type: 'Literal',
		value: eval(ctx.getText()),
		raw: ctx.getText()
	};
	if(ctx.StringLiteral()) {
		result = {
				"type": "CallExpression",
				"callee": {
					"type": "Identifier",
					"name": "j$"
				},
				"arguments": [
					result
				]
		};
	}
	return result;
}

BaseTranspiler.prototype.visitIdentifier = function(ctx) {
	return {
		"type": "Identifier",
		"name": ctx.getText()
	};
}

ExpressionTranspiler.prototype.visitPrimary = function(ctx) {
	if(ctx.Identifier())
		return this.visitIdentifier(ctx.Identifier());
	switch(ctx.getText()) {
	case 'this':
		return {
			"type": "ThisExpression"
		};
	case 'super':
		return {
			"type": "MemberExpression",
			"computed": false,
			"object": {
				"type": "ThisExpression"
			},
			"property": {
				"type": "Identifier",
				"name": "super_"
			}
		};
	default:
		return this.visitChildren(ctx)[0];
	}
}

ExpressionTranspiler.prototype.visitExpression = function(ctx) {
	if(ctx.primary())
		return this.visitPrimary(ctx);
	if(ctx.getChild(1).getText() === '.') {
		if(ctx.Identifier())
			return {
					"type": "MemberExpression",
					"computed": false,
					"object": this.visitExpression(ctx.expression()[0]),
					"property": {
						"type": "Identifier",
						"name": ctx.Identifier().getText()
					}
				};
		else if(ctx.getChild(2).getText() === 'new')
			return; // TODO
		else if(ctx.getChild(2).getText() === 'super')
			return this.visitChildren(ctx.superSuffix())
	}
	else if(ctx.getChild(1).getText() === '(')
		return {
			"type": "CallExpression",
			"callee": this.visitExpression(ctx.expression()[0]),
			"arguments": this.visitChildren(ctx.expressionList())
		}
	else if(ctx.getChild(1).getText() === '[')
			return {
				"type": "MemberExpression",
				"computed": true,
				"object": this.visitExpression(ctx.expression()[0]),
				"property": this.visitExpression(ctx.expression()[1]),
			};
	else
		return this.visitChildren(ctx)[0];
}


module.exports = ExpressionTranspiler;

@@ -447,30 +447,8 @@
 t())
-,%0A%09%09raw: ctx.getText()
 %0A%09%7D;
@@ -1721,16 +1721,61 @@
  // TODO
+: no idea what foo.new ... is actually doing.
 %0A%09%09else 
@@ -2110,16 +2110,53 @@
  === '%5B'
+ && ctx.getChild(3).getText() === '%5D'
 )%0A%09%09%09ret
@@ -2343,16 +2343,34 @@
 ;%0A%09else%0A
+%09%09// TODO: Unkown%0A
 %09%09return

Clean up ExpressionTranspiler.js