Search in sources :

Example 1 with ObjectLiteral

use of org.eclipse.wst.jsdt.core.dom.ObjectLiteral in project webtools.sourceediting by eclipse.

the class RunCodeHandler method getObjectLiteralField.

static ObjectLiteralField getObjectLiteralField(String source) {
    String js = "x.prototype = {" + source + "}";
    JavaScriptUnit jsu = getAST(js);
    ExpressionStatement stmt = (ExpressionStatement) jsu.statements().get(0);
    ObjectLiteral lit = (ObjectLiteral) ((Assignment) stmt.getExpression()).getRightHandSide();
    ObjectLiteralField field = (ObjectLiteralField) lit.fields().get(0);
    ASTNode node = ASTNode.copySubtree(jsu.getAST(), field);
    return (ObjectLiteralField) node;
}
Also used : IJavaScriptUnit(org.eclipse.wst.jsdt.core.IJavaScriptUnit) JavaScriptUnit(org.eclipse.wst.jsdt.core.dom.JavaScriptUnit) ObjectLiteral(org.eclipse.wst.jsdt.core.dom.ObjectLiteral) ExpressionStatement(org.eclipse.wst.jsdt.core.dom.ExpressionStatement) ASTNode(org.eclipse.wst.jsdt.core.dom.ASTNode) ObjectLiteralField(org.eclipse.wst.jsdt.core.dom.ObjectLiteralField)

Aggregations

IJavaScriptUnit (org.eclipse.wst.jsdt.core.IJavaScriptUnit)1 ASTNode (org.eclipse.wst.jsdt.core.dom.ASTNode)1 ExpressionStatement (org.eclipse.wst.jsdt.core.dom.ExpressionStatement)1 JavaScriptUnit (org.eclipse.wst.jsdt.core.dom.JavaScriptUnit)1 ObjectLiteral (org.eclipse.wst.jsdt.core.dom.ObjectLiteral)1 ObjectLiteralField (org.eclipse.wst.jsdt.core.dom.ObjectLiteralField)1