diff --git a/qt/org.eclipse.cdt.qt.core/META-INF/MANIFEST.MF b/qt/org.eclipse.cdt.qt.core/META-INF/MANIFEST.MF index 1ed5ff29d85..9660440da67 100644 --- a/qt/org.eclipse.cdt.qt.core/META-INF/MANIFEST.MF +++ b/qt/org.eclipse.cdt.qt.core/META-INF/MANIFEST.MF @@ -29,6 +29,6 @@ Export-Package: org.eclipse.cdt.internal.qt.core;x-friends:="org.eclipse.cdt.qt. org.eclipse.cdt.internal.qt.core.parser;x-friends:="org.eclipse.cdt.qt.ui", org.eclipse.cdt.internal.qt.core.project;x-friends:="org.eclipse.cdt.qt.ui", org.eclipse.cdt.internal.qt.core.qmldir;x-friends:="org.eclipse.cdt.qt.core.tests", - org.eclipse.cdt.qt.core;x-friends:="org.eclipse.cdt.qt.core.tests", + org.eclipse.cdt.qt.core, org.eclipse.cdt.qt.core.location, org.eclipse.cdt.qt.core.qmldir diff --git a/qt/org.eclipse.cdt.qt.core/acorn-qml/inject.js b/qt/org.eclipse.cdt.qt.core/acorn-qml/inject.js index bd47ebc3651..1533e619851 100644 --- a/qt/org.eclipse.cdt.qt.core/acorn-qml/inject.js +++ b/qt/org.eclipse.cdt.qt.core/acorn-qml/inject.js @@ -56,6 +56,7 @@ kw("readonly", { isQMLContextual: true }); kw("signal", { isQMLContextual: true }); kw("as"); + kw("on", { isQMLContextual: true }); kw("boolean", { isPrimitive: true }); kw("double", { isPrimitive: true }); kw("int", { isPrimitive: true }); @@ -83,47 +84,46 @@ var pp = acorn.Parser.prototype; /* - * Parses a set of QML Header Statements which can either be of - * the type import or pragma + * Parses a set of QML Header Items (QMLImport or QMLPragma) */ - pp.qml_parseHeaderStatements = function () { + pp.qml_parseHeaderItemList = function () { var node = this.startNode(); - node.statements = []; + node.items = []; var loop = true; while (loop) { if (this.isContextual(qtt._import)) { - node.statements.push(this.qml_parseImportStatement()); + node.items.push(this.qml_parseImport()); } else if (this.isContextual(qtt._pragma)) { - node.statements.push(this.qml_parsePragmaStatement()); + node.items.push(this.qml_parsePragma()); } else { loop = false; } } - return this.finishNode(node, "QMLHeaderStatements"); + return this.finishNode(node, "QMLHeaderItemList"); }; /* * Parses a QML Pragma statement of the form: - * 'pragma' + * 'pragma' */ - pp.qml_parsePragmaStatement = function () { + pp.qml_parsePragma = function () { var node = this.startNode(); this.expectContextual(qtt._pragma); - node.id = this.parseIdent(false); + node.id = this.qml_parseQualifiedId(true); this.semicolon(); - return this.finishNode(node, "QMLPragmaStatement"); + return this.finishNode(node, "QMLPragma"); }; /* - * Parses a QML Import statement of the form: - * 'import' [as ] - * 'import' [as ] + * Parses a QML Import of the form: + * 'import' [as ] + * 'import' [as ] * * as specified by http://doc.qt.io/qt-5/qtqml-syntax-imports.html */ - pp.qml_parseImportStatement = function () { + pp.qml_parseImport = function () { var node = this.startNode(); if (!this.eatContextual(qtt._import)) { @@ -149,12 +149,12 @@ } this.semicolon(); - return this.finishNode(node, "QMLImportStatement"); + return this.finishNode(node, "QMLImport"); }; /* * Parses a QML Module of the form: - * ['as' ]? + * */ pp.qml_parseModule = function () { var node = this.startNode(); @@ -176,16 +176,12 @@ pp.qml_parseVersionLiteral = function () { var node = this.startNode(); - node.raw = this.input.slice(this.start, this.end); node.value = this.value; - var matches; - if ((matches = /(\d+)\.(\d+)/.exec(node.raw))) { - node.major = parseInt(matches[1]); - node.minor = parseInt(matches[2]); - this.next(); - } else { + node.raw = this.input.slice(this.start, this.end); + if (!(/(\d+)\.(\d+)/.exec(node.raw))) { this.raise(this.start, "QML module must specify major and minor version"); } + this.next(); return this.finishNode(node, "QMLVersionLiteral"); }; @@ -202,45 +198,47 @@ }; /* - * Parses a QML Object Literal of the form: - * { ()* } + * Parses a QML Object Definition of the form: + * { ()* } * * http://doc.qt.io/qt-5/qtqml-syntax-basics.html#object-declarations */ - pp.qml_parseObjectLiteral = function (node) { + pp.qml_parseObjectDefinition = function (node, isBinding) { if (!node) { node = this.startNode(); } if (!node.id) { node.id = this.qml_parseQualifiedId(false); } - node.body = this.qml_parseMemberBlock(); - return this.finishNode(node, "QMLObjectLiteral"); + node.body = this.qml_parseObjectInitializer(); + return this.finishNode(node, isBinding ? "QMLObjectBinding" : "QMLObjectDefinition"); }; /* - * Parses a QML Member Block of the form: - * { * } + * Parses a QML Object Initializer of the form: + * '{' * '}' */ - pp.qml_parseMemberBlock = function () { + pp.qml_parseObjectInitializer = function () { var node = this.startNode(); this.expect(tt.braceL); node.members = []; - while (!this.eat(tt.braceR)) { - node.members.push(this.qml_parseMember()); + while (this.type !== tt.braceR) { + node.members.push(this.qml_parseObjectMember()); } - return this.finishNode(node, "QMLMemberBlock"); + this.expect(tt.braceR); + return this.finishNode(node, "QMLObjectInitializer"); }; /* - * Parses a QML Member which can be one of the following: + * Parses a QML Object Member which can be one of the following: * - a QML Property Binding - * - a Property Declaration (or Alias) + * - a QML Property Declaration + * - a QML Property Modifier * - a QML Object Literal * - a JavaScript Function Declaration - * - a Signal Definition + * - a QML Signal Definition */ - pp.qml_parseMember = function () { + pp.qml_parseObjectMember = function () { if (this.type === tt._default || this.isContextual(qtt._readonly) || this.isContextual(qtt._property)) { return this.qml_parsePropertyDeclaration(); } else if (this.isContextual(qtt._signal)) { @@ -248,7 +246,7 @@ } else if (this.type === tt._function) { return this.qml_parseFunctionMember(); } - return this.qml_parseObjectLiteralOrPropertyBinding(); + return this.qml_parseObjectDefinitionOrPropertyBinding(); }; /* @@ -261,9 +259,9 @@ }; /* - * Parses a QML Object Literal or Property Binding depending on the tokens found. + * Parses a QML Object Definition or Property Binding depending on the tokens found. */ - pp.qml_parseObjectLiteralOrPropertyBinding = function (node) { + pp.qml_parseObjectDefinitionOrPropertyBinding = function (node) { if (!node) { node = this.startNode(); } @@ -272,7 +270,7 @@ } switch (this.type) { case tt.braceL: - return this.qml_parseObjectLiteral(node); + return this.qml_parseObjectDefinition(node); case tt.colon: return this.qml_parsePropertyBinding(node); } @@ -280,7 +278,26 @@ }; /* - * Parses a QML Property of the form: + * Parses a QML Property Modifier of the form: + * 'on' + + * TODO: Call this method in the normal parser once we can do lookahead + * Without lookahead, telling the difference between an Object Declaration, + * Property Binding, and Property Modifier would be too difficult. For now, + * we've implemented a workaround for Object Declarations and Property Bindings + * until Acorn gets lookahead. + */ + pp.qml_parsePropertyModifier = function () { + var node = this.startNode(); + node.kind = this.qml_parseQualifiedID(false); + this.expectContextual(qtt._on); + node.id = this.qml_parseQualifiedID(false); + node.body = this.qml_parseObjectInitializer(); + return this.finishNode(node, "QMLPropertyModifier"); + }; + + /* + * Parses a QML Property Binding of the form: * */ pp.qml_parsePropertyBinding = function (node) { @@ -297,7 +314,7 @@ /* * Parses a QML Signal Definition of the form: - * 'signal' [( [',' ]* )]? + * 'signal' [( [',' ]* )]? */ pp.qml_parseSignalDefinition = function () { var node = this.startNode(); @@ -312,12 +329,12 @@ if (this.type === tt.colon || this.type === tt.braceL) { // This is a property binding or object literal node.id = signal; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); } } else { // Signal keyword is a qualified ID. This is not a signal definition node.id = signal; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); } node.id = this.qml_parseIdent(false); @@ -328,7 +345,7 @@ /* * Parses QML Signal Parameters of the form: - * [( [',' ]* )]? + * [( [',' ]* )]? */ pp.qml_parseSignalParams = function (node) { node.params = []; @@ -336,7 +353,7 @@ if (!this.eat(tt.parenR)) { do { var param = this.startNode(); - param.kind = this.qml_parseIdent(true); + param.kind = this.qml_parsePropertyType(); param.id = this.qml_parseIdent(false); node.params.push(this.finishNode(param, "QMLParameter")); } while (this.eat(tt.comma)); @@ -346,7 +363,7 @@ }; /* - * Parses a QML Property Declaration (or Alias) of the form: + * Parses a QML Property Declaration of the form: * ['default'|'readonly'] 'property' [] */ pp.qml_parsePropertyDeclaration = function () { @@ -364,13 +381,13 @@ if (this.type === tt.colon || this.type === tt.braceL) { // This is a property binding or object literal. node.id = readonly; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); } node.readonly = true; } else { // Readonly keyword is a qualified ID. This is not a property declaration. node.id = readonly; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); } } @@ -386,17 +403,26 @@ node.default = undefined; node.readonly = undefined; node.id = property; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); } } else { // Property keyword is a qualified ID. This is not a property declaration. node.default = undefined; node.readonly = undefined; node.id = property; - return this.qml_parseObjectLiteralOrPropertyBinding(node); + return this.qml_parseObjectDefinitionOrPropertyBinding(node); + } + + node.kind = this.qml_parsePropertyType(); + if (this.value === "<") { + this.expect(tt.relational); // '<' + node.modifier = this.qml_parsePropertyType(); + if (this.value !== ">") { + this.unexpected(); + } + this.expect(tt.relational); // '>' } - node.kind = this.qml_parseKind(); node.id = this.qml_parseIdent(false); if (!this.eat(tt.colon)) { node.binding = null; @@ -408,9 +434,24 @@ return this.finishNode(node, "QMLPropertyDeclaration"); }; + /* + * Parses a QML Property Type of the form: + * + */ + pp.qml_parsePropertyType = function () { + var node = this.startNode(); + node.primitive = false; + if (this.qml_isPrimitiveType(this.type, this.value)) { + node.primitive = true; + } + node.id = this.qml_parseIdent(true); + return this.finishNode(node, "QMLPropertyType"); + }; + /* * Parses one of the following possibilities for a QML Property assignment: - * - QML Object Literal + * - QML Object Binding + * - QML Array Binding * - QML Script Binding */ pp.qml_parseBinding = function () { @@ -426,6 +467,23 @@ return this.qml_parseScriptBinding(true); }; + /* + * Parses a QML Array Binding of the form: + * '[' [ (',' )*] ']' + * + * TODO: call this in the parser once we can use lookahead to distinguish between + * a QML Array Binding and a JavaScript array. + */ + pp.qml_parseArrayBinding = function () { + var node = this.startNode(); + this.expect(tt.bracketL); + node.members = []; + while (!this.eat(tt.bracketR)) { + node.members.push(this.qml_parseObjectDefinition()); + } + return this.finishNode(node, "QMLArrayBinding"); + }; + /* * Parses one of the following Script Bindings: * - Single JavaScript Expression @@ -446,32 +504,18 @@ /* * Parses a QML Statement Block of the form: - * { * } + * { * } */ pp.qml_parseStatementBlock = function () { var node = this.startNode(); this.expect(tt.braceL); - node.statements = []; + node.body = []; while (!this.eat(tt.braceR)) { - node.statements.push(this.parseStatement(true, false)); + node.body.push(this.parseStatement(true, false)); } return this.finishNode(node, "QMLStatementBlock"); }; - /* - * Parses a QML Type which can be either a Qualified ID or a primitive type keyword. - * Returns a node of type qtt._alias if the type keyword parsed was "alias". - */ - pp.qml_parseKind = function () { - var value = this.value; - if (this.qml_eatPrimitiveType(this.type, value)) { - return value; - } else { - return this.qml_parseQualifiedId(false); - } - this.unexpected(); - }; - /* * Parses a Qualified ID of the form: * ('.' )* @@ -579,10 +623,10 @@ // replacing JavaScripts top-level. Here we are parsing such things // as the root object literal and header statements of QML. Eventually, // these rules will delegate down to JavaScript expressions. - node.headerStatements = this.qml_parseHeaderStatements(); + node.headerItemList = this.qml_parseHeaderItemList(); node.rootObject = null; if (this.type !== tt.eof) { - node.rootObject = this.qml_parseObjectLiteral(); + node.rootObject = this.qml_parseObjectDefinition(); } if (!this.eat(tt.eof)) { diff --git a/qt/org.eclipse.cdt.qt.core/acorn-qml/loose/inject.js b/qt/org.eclipse.cdt.qt.core/acorn-qml/loose/inject.js index 40cdf0405bb..ee3eff58b7f 100644 --- a/qt/org.eclipse.cdt.qt.core/acorn-qml/loose/inject.js +++ b/qt/org.eclipse.cdt.qt.core/acorn-qml/loose/inject.js @@ -34,47 +34,46 @@ var injectQMLLoose; var pp = acorn.Parser.prototype; /* - * Parses a set of QML Header Statements which can either be of - * the type import or pragma + * Parses a set of QML Header Items (QMLImport or QMLPragma) */ - lp.qml_parseHeaderStatements = function () { + lp.qml_parseHeaderItemList = function () { var node = this.startNode(); - node.statements = []; + node.items = []; var loop = true; while (loop) { if (this.isContextual(qtt._import)) { - node.statements.push(this.qml_parseImportStatement()); + node.items.push(this.qml_parseImport()); } else if (this.isContextual(qtt._pragma)) { - node.statements.push(this.qml_parsePragmaStatement()); + node.items.push(this.qml_parsePragma()); } else { loop = false; } } - return this.finishNode(node, "QMLHeaderStatements"); + return this.finishNode(node, "QMLHeaderItemList"); }; /* * Parses a QML Pragma statement of the form: - * 'pragma' + * 'pragma' */ - lp.qml_parsePragmaStatement = function () { + lp.qml_parsePragma = function () { var node = this.startNode(); this.expectContextual(qtt._pragma); - node.id = this.parseIdent(false); + node.id = this.qml_parseQualifiedId(true); this.semicolon(); - return this.finishNode(node, "QMLPragmaStatement"); + return this.finishNode(node, "QMLPragma"); }; /* - * Parses a QML Import statement of the form: - * 'import' [as ] - * 'import' [as ] + * Parses a QML Import of the form: + * 'import' [as ] + * 'import' [as ] * * as specified by http://doc.qt.io/qt-5/qtqml-syntax-imports.html */ - lp.qml_parseImportStatement = function () { + lp.qml_parseImport = function () { var node = this.startNode(); this.expectContextual(qtt._import); @@ -95,12 +94,12 @@ var injectQMLLoose; } this.semicolon(); - return this.finishNode(node, "QMLImportStatement"); + return this.finishNode(node, "QMLImport"); }; /* * Parses a QML Module of the form: - * ['as' ]? + * */ lp.qml_parseModule = function () { var node = this.startNode(); @@ -118,22 +117,12 @@ var injectQMLLoose; lp.qml_parseVersionLiteral = function () { var node = this.startNode(); - node.raw = this.input.slice(this.tok.start, this.tok.end); - node.value = this.tok.value; var matches; if (this.tok.type === tt.num) { - if ((matches = /(\d+)\.(\d+)/.exec(node.raw))) { - node.major = parseInt(matches[1]); - node.minor = parseInt(matches[2]); - this.next(); - } else { - node.major = parseInt(node.raw); - node.minor = 0; - this.next(); - } + node.raw = this.input.slice(this.tok.start, this.tok.end); + node.value = this.tok.value; + this.next(); } else { - node.major = 0; - node.minor = 0; node.value = 0; node.raw = "0.0"; } @@ -153,48 +142,50 @@ var injectQMLLoose; }; /* - * Parses a QML Object Literal of the form: - * { ()* } + * Parses a QML Object Definition of the form: + * { ()* } * * http://doc.qt.io/qt-5/qtqml-syntax-basics.html#object-declarations */ - lp.qml_parseObjectLiteral = function () { + lp.qml_parseObjectDefinition = function (isBinding) { var node = this.startNode(); node.id = this.qml_parseQualifiedId(false); - node.body = this.qml_parseMemberBlock(); - return this.finishNode(node, "QMLObjectLiteral"); + node.body = this.qml_parseObjectInitializer(); + return this.finishNode(node, isBinding ? "QMLObjectBinding" : "QMLObjectDefinition"); }; /* - * Parses a QML Member Block of the form: - * { * } + * Parses a QML Object Initializer of the form: + * '{' * '}' */ - lp.qml_parseMemberBlock = function () { + lp.qml_parseObjectInitializer = function () { var node = this.startNode(); this.pushCx(); this.expect(tt.braceL); - var blockIndent = this.curIndent, line = this.curLineStart; + var blockIndent = this.curIndent, + line = this.curLineStart; node.members = []; while (!this.closes(tt.braceR, blockIndent, line, true)) { - var member = this.qml_parseMember(); + var member = this.qml_parseObjectMember(); if (member) { node.members.push(member); } } this.popCx(); this.eat(tt.braceR); - return this.finishNode(node, "QMLMemberBlock"); + return this.finishNode(node, "QMLObjectInitializer"); }; /* - * Parses a QML Member which can be one of the following: + * Parses a QML Object Member which can be one of the following: * - a QML Property Binding - * - a Property Declaration (or Alias) + * - a QML Property Declaration + * - a QML Property Modifier * - a QML Object Literal * - a JavaScript Function Declaration - * - a Signal Definition + * - a QML Signal Definition */ - lp.qml_parseMember = function () { + lp.qml_parseObjectMember = function () { if (this.tok.type === tt._default || this.isContextual(qtt._readonly) || this.isContextual(qtt._property) || this.qml_isPrimitiveType(this.tok.type, this.tok.value)) { return this.qml_parsePropertyDeclaration(); } else if (this.isContextual(qtt._signal)) { @@ -203,27 +194,57 @@ var injectQMLLoose; return this.qml_parseFunctionMember(); } else if (this.qml_isIdent(this.tok.type, this.tok.value) || this.tok.type === tt.dot) { var la = this.lookAhead(1); - if (this.qml_isIdent(la.type, la.value)) { + if (this.qml_isIdent(la.type, la.value) && la.value !== qtt._on) { // Two identifiers in a row means this is most likely a property declaration - // with the 'property' token missing + // with the 'property' token missing. return this.qml_parsePropertyDeclaration(); } else { - var node = this.qml_parseObjectLiteralOrPropertyBinding(); - if (node) { - return node; - } else { - return this.qml_parsePropertyBinding(); - } + return this.qml_parseMemberStartsWithIdentifier() || this.qml_parsePropertyBinding(); } } else if (this.tok.type === tt.colon) { return this.qml_parsePropertyBinding(); } else if (this.tok.type === tt.braceL) { - return this.qml_parseObjectLiteral(); + return this.qml_parseObjectDefinition(); } // ignore the current token if it didn't pass the previous tests this.next(); }; + /* + * Parses a QML Object Member that starts with an identifier. This method solves the + * ambiguities that arise from QML having multiple Object Members that start with + * Qualified IDs as well as the fact that several of its keywords can be used as part + * of these Qualified IDs. + */ + lp.qml_parseMemberStartsWithIdentifier = function () { + // Jump past the potential Qualified ID + var i = 1, + la = this.tok; + if (this.qml_isIdent(la.type, la.value)) { + la = this.lookAhead(i++); + } + while (la.type === tt.dot) { + la = this.lookAhead(i++); + if (this.qml_isIdent(la.type, la.value)) { + la = this.lookAhead(i++); + } + } + + // Check the last lookahead token + switch (la.type) { + case tt.braceL: + return this.qml_parseObjectDefinition(); + case tt.colon: + return this.qml_parsePropertyBinding(); + case tt.name: + if (la.value === qtt._on) { + return this.qml_parsePropertyModifier(); + } + break; + } + return null; + }; + /* * Parses a JavaScript function as a member of a QML Object Literal */ @@ -234,14 +255,14 @@ var injectQMLLoose; }; /* - * QML version of 'parseFunction' needed to have proper error tolerant parsing - * for QML member functions versus their JavaScript counterparts. The main - * difference between the two functions is that this implementation will not - * forcefully insert '(' and '{' tokens for the body and parameters. Instead, - * it will silently create an empty parameter list or body and let parsing - * continue normally. - */ - lp.qml_parseFunction = function(node, isStatement) { + * QML version of 'parseFunction' needed to have proper error tolerant parsing + * for QML member functions versus their JavaScript counterparts. The main + * difference between the two functions is that this implementation will not + * forcefully insert '(' and '{' tokens for the body and parameters. Instead, + * it will silently create an empty parameter list or body and let parsing + * continue normally. + */ + lp.qml_parseFunction = function (node, isStatement) { this.initFunction(node); if (this.tok.type === tt.name) node.id = this.parseIdent(); else if (isStatement) node.id = this.dummyIdent(); @@ -250,7 +271,7 @@ var injectQMLLoose; node.body = this.parseBlock(); } else { if (this.options.locations) { - node.body = this.startNodeAt([ this.last.end, this.last.loc.end ]); + node.body = this.startNodeAt([this.last.end, this.last.loc.end]); } else { node.body = this.startNodeAt(this.last.end); } @@ -261,27 +282,16 @@ var injectQMLLoose; }; /* - * Parses a QML Object Literal or Property Binding depending on the tokens found. + * Parses a QML Property Modifier of the form: + * 'on' */ - lp.qml_parseObjectLiteralOrPropertyBinding = function () { - var i = 1, la = this.tok; - if (this.qml_isIdent(la.type, la.value)) { - la = this.lookAhead(i++); - } - while (la.type === tt.dot) { - la = this.lookAhead(i++); - if (this.qml_isIdent(la.type, la.value)) { - la = this.lookAhead(i++); - } - } - - switch (la.type) { - case tt.braceL: - return this.qml_parseObjectLiteral(); - case tt.colon: - return this.qml_parsePropertyBinding(); - } - return null; + lp.qml_parsePropertyModifier = function () { + var node = this.startNode(); + node.kind = this.qml_parseQualifiedId(false); + this.expectContextual(qtt._on); + node.id = this.qml_parseQualifiedId(false); + node.body = this.qml_parseObjectInitializer(); + return this.finishNode(node, "QMLPropertyModifier"); }; /* @@ -299,13 +309,13 @@ var injectQMLLoose; /* * Parses a QML Signal Definition of the form: - * 'signal' [( [',' ]* )]? + * 'signal' [( [',' ]* )]? */ lp.qml_parseSignalDefinition = function () { var node = this.startNode(); // Check if this is an object literal or property binding first - var objOrBind = this.qml_parseObjectLiteralOrPropertyBinding(); + var objOrBind = this.qml_parseMemberStartsWithIdentifier(); if (objOrBind) { return objOrBind; } @@ -318,28 +328,28 @@ var injectQMLLoose; }; /* - * Checks if the given node is a dummy identifier - */ + * Checks if the given node is a dummy identifier + */ function isDummy(node) { return node.name === "✖"; } /* * Parses QML Signal Parameters of the form: - * [( [',' ]* )]? + * [( [',' ]* )]? */ lp.qml_parseSignalParams = function (node) { this.pushCx(); - var indent = this.curIndent, line = this.curLineStart; + var indent = this.curIndent, + line = this.curLineStart; node.params = []; if (this.eat(tt.parenL)) { - while (!this.closes(tt.parenR, indent + 1, line)) { + while (!this.closes(tt.parenR, indent + 1, line) && this.tok.type !== tt.braceR) { var param = this.startNode(); - - param.kind = this.qml_parseIdent(true); + param.kind = this.qml_parsePropertyType(); // Break out of an infinite loop where we continously consume dummy ids - if (isDummy(param.kind) && this.tok.type !== tt.comma) { + if (isDummy(param.kind.id) && this.tok.type !== tt.comma) { break; } @@ -363,7 +373,7 @@ var injectQMLLoose; }; /* - * Parses a QML Property Declaration (or Alias) of the form: + * Parses a QML Property Declaration of the form: * ['default'|'readonly'] 'property' [] */ lp.qml_parsePropertyDeclaration = function () { @@ -376,7 +386,7 @@ var injectQMLLoose; if (this.eat(tt._default)) { node.default = true; } else if (this.isContextual(qtt._readonly)) { - objOrBind = this.qml_parseObjectLiteralOrPropertyBinding(); + objOrBind = this.qml_parseMemberStartsWithIdentifier(); if (objOrBind) { objOrBind.default = undefined; objOrBind.readonly = undefined; @@ -387,7 +397,7 @@ var injectQMLLoose; } if (!node.default && !node.readonly) { - objOrBind = this.qml_parseObjectLiteralOrPropertyBinding(); + objOrBind = this.qml_parseMemberStartsWithIdentifier(); if (objOrBind) { return objOrBind; } @@ -397,7 +407,13 @@ var injectQMLLoose; } - node.kind = this.qml_parseKind(); + node.kind = this.qml_parsePropertyType(); + if (this.tok.value === "<") { + this.expect(tt.relational); // '<' + node.modifier = this.qml_parsePropertyType(); + this.expect(tt.relational); // '>' + } + node.id = this.qml_parseIdent(false); var start = this.storeCurrentPos(); @@ -411,22 +427,53 @@ var injectQMLLoose; return this.finishNode(node, "QMLPropertyDeclaration"); }; + /* + * Parses a QML Property Type of the form: + * + */ + lp.qml_parsePropertyType = function () { + var node = this.startNode(); + node.primitive = false; + if (this.qml_isPrimitiveType(this.tok.type, this.tok.value)) { + node.primitive = true; + } + node.id = this.qml_parseIdent(true); + return this.finishNode(node, "QMLPropertyType"); + }; + /* * Parses one of the following possibilities for a QML Property assignment: - * - QML Object Literal + * - QML Object Binding + * - QML Array Binding * - QML Script Binding */ lp.qml_parseBinding = function (start) { + var i, la; if (this.options.mode === "qmltypes") { return this.qml_parseScriptBinding(start, false); } if (this.tok.type === tt.braceL) { return this.qml_parseScriptBinding(start, true); + } else if (this.tok.type === tt.bracketL) { + // Perform look ahead to determine whether this is an expression or + // a QML Array Binding + i = 1; + la = this.lookAhead(i++); + if (la.type === tt.name) { + while (la.type === tt.dot || la.type === tt.name) { + la = this.lookAhead(i++); + } + if (la.type === tt.braceL) { + return this.qml_parseArrayBinding(); + } + } + return this.qml_parseScriptBinding(start, true); } // Perform look ahead to determine whether this is an expression or // a QML Object Literal - var i = 1, la = this.tok; + i = 1; + la = this.tok; if (this.qml_isIdent(la.type, la.value)) { la = this.lookAhead(i++); } @@ -438,12 +485,44 @@ var injectQMLLoose; } if (la.type === tt.braceL) { - return this.qml_parseObjectLiteral(); + return this.qml_parseObjectDefinition(true); } else { return this.qml_parseScriptBinding(start, true); } }; + /* + * Parses a QML Array Binding of the form: + * '[' [ (',' )*] ']' + */ + lp.qml_parseArrayBinding = function () { + var node = this.startNode(); + var indent = this.curIndent, + line = this.curLineStart; + this.pushCx(); + this.expect(tt.bracketL); + node.elements = []; + while (!this.closes(tt.bracketR, indent + 1, line) && this.tok.type !== tt.braceR) { + var obj = this.qml_parseObjectDefinition(); + node.elements.push(obj); + + // Break out of an infinite loop where we continously consume dummy ids + if (isDummy(obj.id) && this.tok.type !== tt.comma) { + break; + } + + this.eat(tt.comma); + } + this.popCx(); + if (!this.eat(tt.bracketR)) { + // If there is no closing brace, make the node span to the start + // of the next token (this is useful for Tern) + this.last.end = this.tok.start; + if (this.options.locations) this.last.loc.end = this.tok.loc.start; + } + return this.finishNode(node, "QMLArrayBinding"); + }; + /* * Parses one of the following Script Bindings: * - Single JavaScript Expression @@ -479,7 +558,7 @@ var injectQMLLoose; /* * Parses a QML Statement Block of the form: - * { * } + * { * } */ lp.qml_parseStatementBlock = function () { var node = this.startNode(); @@ -487,27 +566,15 @@ var injectQMLLoose; this.expect(tt.braceL); var blockIndent = this.curIndent, line = this.curLineStart; - node.statements = []; + node.body = []; while (!this.closes(tt.braceR, blockIndent, line, true)) { - node.statements.push(this.parseStatement(true, false)); + node.body.push(this.parseStatement(true, false)); } this.popCx(); this.eat(tt.braceR); return this.finishNode(node, "QMLStatementBlock"); }; - /* - * Parses a QML Type which can be either a Qualified ID or a primitive type keyword. - */ - lp.qml_parseKind = function () { - var value = this.tok.value; - if (this.qml_eatPrimitiveType(this.tok.type, value)) { - return value; - } else { - return this.qml_parseQualifiedId(false); - } - }; - /* * Parses a Qualified ID of the form: * ('.' )* @@ -552,11 +619,11 @@ var injectQMLLoose; }; /* - * Checks the next token to see if it matches the given contextual keyword. If the - * contextual keyword was not found, this function looks ahead at the next two tokens - * and jumps ahead if it was found there. Returns whether or not the keyword was found. - */ - lp.expectContextual = function(name) { + * Checks the next token to see if it matches the given contextual keyword. If the + * contextual keyword was not found, this function looks ahead at the next two tokens + * and jumps ahead if it was found there. Returns whether or not the keyword was found. + */ + lp.expectContextual = function (name) { if (this.eatContextual(name)) return true; for (var i = 1; i <= 2; i++) { if (this.lookAhead(i).type == tt.name && this.lookAhead(i).value === name) { @@ -589,15 +656,15 @@ var injectQMLLoose; // as the root object literal and header statements of QML. Eventually, // these rules will delegate down to JavaScript expressions. var node = this.startNode(); - node.headerStatements = this.qml_parseHeaderStatements(); + node.headerItemList = this.qml_parseHeaderItemList(); node.rootObject = null; if (this.tok.type !== tt.eof) { - node.rootObject = this.qml_parseObjectLiteral(); + node.rootObject = this.qml_parseObjectDefinition(); } return this.finishNode(node, "QMLProgram"); } else if (this.options.mode === "js") { - return nextMethod.call(this, node); + return nextMethod.call(this); } else { throw new Error("Unknown mode '" + this.options.mode + "'"); } diff --git a/qt/org.eclipse.cdt.qt.core/acorn-qml/test/tests-qml.js b/qt/org.eclipse.cdt.qt.core/acorn-qml/test/tests-qml.js index f8470162483..4610eb23362 100644 --- a/qt/org.eclipse.cdt.qt.core/acorn-qml/test/tests-qml.js +++ b/qt/org.eclipse.cdt.qt.core/acorn-qml/test/tests-qml.js @@ -18,17 +18,17 @@ var tokTypes = driver.tokTypes; testFail('', "QML only supports ECMA Script Language Specification 5 or older", { locations: true, ecmaVersion: 6, allowReserved: false }); -test('import QtQuick 2.2', headerStatements([{ - type: "QMLImportStatement", +test('import QtQuick 2.02', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, - end: { line: 1, column: 18 } + end: { line: 1, column: 19 } }, module: { type: "QMLModule", loc: { start: { line: 1, column: 7 }, - end: { line: 1, column: 18 } + end: { line: 1, column: 19 } }, id: { type: "QMLQualifiedID", @@ -43,18 +43,16 @@ test('import QtQuick 2.2', headerStatements([{ type: "QMLVersionLiteral", loc: { start: { line: 1, column: 15 }, - end: { line: 1, column: 18 } + end: { line: 1, column: 19 } }, - value: 2.2, - major: 2, - minor: 2, - raw: "2.2" + value: 2.02, + raw: "2.02" } } }])); -test('import "./file.js"', headerStatements([{ - type: "QMLImportStatement", +test('import "./file.js"', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 18 } @@ -70,8 +68,8 @@ test('import "./file.js"', headerStatements([{ } }])); -test('import "./file.js" as MyModule', headerStatements([{ - type: "QMLImportStatement", +test('import "./file.js" as MyModule', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 30 } @@ -114,9 +112,9 @@ testFail('import QtQuick 1', "QML module must specify major and minor version (1:15)", { locations: true, loose: false }); -test('import QtQuick 2.2\nimport "./file.js"', headerStatements([ +test('import QtQuick 2.2\nimport "./file.js"', headerItemList([ { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 18 } @@ -143,14 +141,12 @@ test('import QtQuick 2.2\nimport "./file.js"', headerStatements([ end: { line: 1, column: 18 } }, value: 2.2, - major: 2, - minor: 2, raw: "2.2" } } }, { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 18 } @@ -167,9 +163,9 @@ test('import QtQuick 2.2\nimport "./file.js"', headerStatements([ } ])); -test('import QtQuick 2.2;import "./file.js"', headerStatements([ +test('import QtQuick 2.2;import "./file.js"', headerItemList([ { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 19 } @@ -196,14 +192,12 @@ test('import QtQuick 2.2;import "./file.js"', headerStatements([ end: { line: 1, column: 18 } }, value: 2.2, - major: 2, - minor: 2, raw: "2.2" } } }, { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 19 }, end: { line: 1, column: 37 } @@ -220,9 +214,9 @@ test('import QtQuick 2.2;import "./file.js"', headerStatements([ } ])); -test('import Module 1.0 as MyModule', headerStatements([ +test('import Module 1.0 as MyModule', headerItemList([ { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 29 } @@ -249,8 +243,6 @@ test('import Module 1.0 as MyModule', headerStatements([ end: { line: 1, column: 17 } }, value: 1, - major: 1, - minor: 0, raw: "1.0" } }, @@ -272,9 +264,9 @@ test('import Module 1.0 as MyModule', headerStatements([ } ])); -test('import Qualified.Id.Test 1.0', headerStatements([ +test('import Qualified.Id.Test 1.0', headerItemList([ { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 28 } @@ -305,100 +297,103 @@ test('import Qualified.Id.Test 1.0', headerStatements([ end: { line: 1, column: 28 } }, value: 1, - major: 1, - minor: 0, raw: "1.0" } } } ])); -test('pragma Singleton', headerStatements([ +test('pragma Singleton', headerItemList([ { - type: "QMLPragmaStatement", + type: "QMLPragma", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 16 } }, id: { - type: "Identifier", + type: "QMLQualifiedID", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 16 } }, + parts: [{ type: "Identifier", name: "Singleton" }], name: "Singleton" } } ])); -test('pragma Singleton\npragma Other', headerStatements([ +test('pragma Singleton\npragma Other', headerItemList([ { - type: "QMLPragmaStatement", + type: "QMLPragma", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 16 } }, id: { - type: "Identifier", + type: "QMLQualifiedID", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 16 } }, + parts: [{ type: "Identifier", name: "Singleton" }], name: "Singleton" } }, { - type: "QMLPragmaStatement", + type: "QMLPragma", loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 12 } }, id: { - type: "Identifier", + type: "QMLQualifiedID", loc: { start: { line: 2, column: 7 }, end: { line: 2, column: 12 } }, + parts: [{ type: "Identifier", name: "Other" }], name: "Other" } } ])); -test('pragma Singleton;pragma Other', headerStatements([ +test('pragma Singleton;pragma Other', headerItemList([ { - type: "QMLPragmaStatement", + type: "QMLPragma", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 17 } }, id: { - type: "Identifier", + type: "QMLQualifiedID", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 16 } }, + parts: [{ type: "Identifier", name: "Singleton" }], name: "Singleton" } }, { - type: "QMLPragmaStatement", + type: "QMLPragma", loc: { start: { line: 1, column: 17 }, end: { line: 1, column: 29 } }, id: { - type: "Identifier", + type: "QMLQualifiedID", loc: { start: { line: 1, column: 24 }, end: { line: 1, column: 29 } }, + parts: [{ type: "Identifier", name: "Other" }], name: "Other" } } ])); test('Window {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 9 } @@ -413,7 +408,7 @@ test('Window {}', rootObject({ name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 9 } @@ -423,7 +418,7 @@ test('Window {}', rootObject({ })); test('QtQuick.Window {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 17 } @@ -441,7 +436,7 @@ test('QtQuick.Window {}', rootObject({ name: "QtQuick.Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 15 }, end: { line: 1, column: 17 } @@ -451,7 +446,7 @@ test('QtQuick.Window {}', rootObject({ })); test('property {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 11 } @@ -466,7 +461,7 @@ test('property {}', rootObject({ name: "property" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 9 }, end: { line: 1, column: 11 } @@ -476,7 +471,7 @@ test('property {}', rootObject({ })); test('readonly {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 11 } @@ -491,7 +486,7 @@ test('readonly {}', rootObject({ name: "readonly" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 9 }, end: { line: 1, column: 11 } @@ -501,7 +496,7 @@ test('readonly {}', rootObject({ })); test('signal {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 9 } @@ -516,7 +511,7 @@ test('signal {}', rootObject({ name: "signal" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 9 } @@ -526,7 +521,7 @@ test('signal {}', rootObject({ })); test('alias {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 8 } @@ -541,7 +536,7 @@ test('alias {}', rootObject({ name: "alias" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 6 }, end: { line: 1, column: 8 } @@ -551,7 +546,7 @@ test('alias {}', rootObject({ })); test('list {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 7 } @@ -566,7 +561,7 @@ test('list {}', rootObject({ name: "list" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 5 }, end: { line: 1, column: 7 } @@ -576,7 +571,7 @@ test('list {}', rootObject({ })); test('color {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 8 } @@ -591,7 +586,7 @@ test('color {}', rootObject({ name: "color" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 6 }, end: { line: 1, column: 8 } @@ -601,7 +596,7 @@ test('color {}', rootObject({ })); test('real {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 7 } @@ -616,7 +611,7 @@ test('real {}', rootObject({ name: "real" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 5 }, end: { line: 1, column: 7 } @@ -626,7 +621,7 @@ test('real {}', rootObject({ })); test('string {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 9 } @@ -641,7 +636,7 @@ test('string {}', rootObject({ name: "string" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 9 } @@ -651,7 +646,7 @@ test('string {}', rootObject({ })); test('url {}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 6 } @@ -666,7 +661,7 @@ test('url {}', rootObject({ name: "url" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 4 }, end: { line: 1, column: 6 } @@ -676,7 +671,7 @@ test('url {}', rootObject({ })); test('Window {Button {}}', rootObjectMembers([{ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 8 }, end: { line: 1, column: 17 } @@ -691,7 +686,7 @@ test('Window {Button {}}', rootObjectMembers([{ name: "Button" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 15 }, end: { line: 1, column: 17 } @@ -701,7 +696,7 @@ test('Window {Button {}}', rootObjectMembers([{ }])); test('a{ property {} }', rootObjectMembers([{ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 3 }, end: { line: 1, column: 14 } @@ -716,7 +711,7 @@ test('a{ property {} }', rootObjectMembers([{ name: "property" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 12 }, end: { line: 1, column: 14 } @@ -726,7 +721,7 @@ test('a{ property {} }', rootObjectMembers([{ }])); test('a{ readonly {} }', rootObjectMembers([{ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 3 }, end: { line: 1, column: 14 } @@ -741,7 +736,7 @@ test('a{ readonly {} }', rootObjectMembers([{ name: "readonly" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 12 }, end: { line: 1, column: 14 } @@ -751,7 +746,7 @@ test('a{ readonly {} }', rootObjectMembers([{ }])); test('a{ signal {} }', rootObjectMembers([{ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 3 }, end: { line: 1, column: 12 } @@ -766,7 +761,7 @@ test('a{ signal {} }', rootObjectMembers([{ name: "signal" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 10 }, end: { line: 1, column: 12 } @@ -787,7 +782,15 @@ test('a{ readonly property var w: 3 }', rootObjectMembers([{ }, default: false, readonly: true, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 24 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -818,7 +821,15 @@ test('a{ default property var w: 3 }', rootObjectMembers([{ }, default: true, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 20 }, + end: { line: 1, column: 23 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -857,7 +868,15 @@ test('a{ property var w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -888,7 +907,15 @@ test('a{ property boolean w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "boolean", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 19 } + }, + primitive: true, + id: { type: "Identifier", name: "boolean"} + }, id: { type: "Identifier", loc: { @@ -919,7 +946,15 @@ test('a{ property double w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "double", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 18 } + }, + primitive: true, + id: { type: "Identifier", name: "double"} + }, id: { type: "Identifier", loc: { @@ -950,7 +985,15 @@ test('a{ property int w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "int", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "int"} + }, id: { type: "Identifier", loc: { @@ -973,28 +1016,45 @@ test('a{ property int w: 3 }', rootObjectMembers([{ } }])); -test('a{ property list w: 3 }', rootObjectMembers([{ +test('a{ property list w: 3 }', rootObjectMembers([{ type: "QMLPropertyDeclaration", loc: { start: { line: 1, column: 3 }, - end: { line: 1, column: 21 } + end: { line: 1, column: 27 } }, default: false, readonly: false, - kind: "list", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 16 } + }, + primitive: true, + id: { type: "Identifier", name: "list"}, + }, + modifier: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 17 }, + end: { line: 1, column: 21 } + }, + primitive: false, + id: { type: "Identifier", name: "Type" } + }, id: { type: "Identifier", loc: { - start: { line: 1, column: 17 }, - end: { line: 1, column: 18 } + start: { line: 1, column: 23 }, + end: { line: 1, column: 24 } }, name: "w" }, binding: { type: "QMLScriptBinding", loc: { - start: { line: 1, column: 20 }, - end: { line: 1, column: 21 } + start: { line: 1, column: 26 }, + end: { line: 1, column: 27 } }, script: { type: "Literal", @@ -1012,7 +1072,15 @@ test('a{ property color w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "color", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 17 } + }, + primitive: true, + id: { type: "Identifier", name: "color"} + }, id: { type: "Identifier", loc: { @@ -1043,7 +1111,15 @@ test('a{ property real w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "real", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 16 } + }, + primitive: true, + id: { type: "Identifier", name: "real"} + }, id: { type: "Identifier", loc: { @@ -1074,7 +1150,15 @@ test('a{ property string w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "string", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 18 } + }, + primitive: true, + id: { type: "Identifier", name: "string"} + }, id: { type: "Identifier", loc: { @@ -1105,7 +1189,15 @@ test('a{ property url w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "url", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "url"} + }, id: { type: "Identifier", loc: { @@ -1138,13 +1230,13 @@ test('a{ property QtObject w: 3 }', rootObjectMembers([{ default: false, readonly: false, kind: { - type: "QMLQualifiedID", + type: "QMLPropertyType", loc: { start: { line: 1, column: 12 }, end: { line: 1, column: 20 } }, - parts: [{ type: "Identifier", name: "QtObject" }], - name: "QtObject" + primitive: false, + id: { type: "Identifier", name: "QtObject"} }, id: { type: "Identifier", @@ -1176,7 +1268,15 @@ test('a{ property alias w: 3 }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "alias", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 17 } + }, + primitive: true, + id: { type: "Identifier", name: "alias"} + }, id: { type: "Identifier", loc: { @@ -1696,6 +1796,30 @@ test('a{b:url}', javaScript({ name: "url" })); +test('a{b:[]}', javaScript({ + type: "ArrayExpression", + loc: { + start: { line: 1, column: 4 }, + end: { line: 1, column: 6 } + }, + elements: [] +})); + +test('a{b:[{}]}', javaScript({ + type: "ArrayExpression", + loc: { + start: { line: 1, column: 4 }, + end: { line: 1, column: 8 } + }, + elements: [{ + type: "ObjectExpression", + loc: { + start: { line: 1, column: 5 }, + end: { line: 1, column: 7 } + }, + }] +})); + test('a{ function fn() {} }', rootObjectMembers([{ type: "FunctionDeclaration", loc: { @@ -1812,12 +1936,13 @@ test('a{ signal b (type param)}', rootObjectMembers([{ end: { line: 1, column: 23 } }, kind: { - type: "Identifier", + type: "QMLPropertyType", loc: { start: { line: 1, column: 13 }, end: { line: 1, column: 17 } }, - name: "type" + primitive: false, + id: { type: "Identifier", name: "type" } }, id: { type: "Identifier", @@ -1852,12 +1977,13 @@ test('a{ signal b (type1 param1, type2 param2, type3 param3)}', rootObjectMember end: { line: 1, column: 25 } }, kind: { - type: "Identifier", + type: "QMLPropertyType", loc: { start: { line: 1, column: 13 }, end: { line: 1, column: 18 } }, - name: "type1" + primitive: false, + id: { type: "Identifier", name: "type1" } }, id: { type: "Identifier", @@ -1875,12 +2001,13 @@ test('a{ signal b (type1 param1, type2 param2, type3 param3)}', rootObjectMember end: { line: 1, column: 39 } }, kind: { - type: "Identifier", + type: "QMLPropertyType", loc: { start: { line: 1, column: 27 }, end: { line: 1, column: 32 } }, - name: "type2" + primitive: false, + id: { type: "Identifier", name: "type2" } }, id: { type: "Identifier", @@ -1898,12 +2025,13 @@ test('a{ signal b (type1 param1, type2 param2, type3 param3)}', rootObjectMember end: { line: 1, column: 53 } }, kind: { - type: "Identifier", + type: "QMLPropertyType", loc: { start: { line: 1, column: 41 }, end: { line: 1, column: 46 } }, - name: "type3" + primitive: false, + id: { type: "Identifier", name: "type3" } }, id: { type: "Identifier", @@ -1957,7 +2085,7 @@ test('a{ id: test }', rootObjectMembers([{ */ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n\n\tMouseArea {\n\t\tanchors.fill: parent\n\t\tonClicked: {\n\t\t\tQt.quit();\n\t\t}\n\t}\n\tText {\n\t\ttext: qsTr("Hello World")\n\t\tanchors.centerIn: parent\n\t}\n}', program([{ - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 1, column: 0 }, @@ -1985,14 +2113,11 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n end: { line: 1, column: 18 } }, raw: "2.3", - value: 2.3, - major: 2, - minor: 3 } } }, { - type: "QMLImportStatement", + type: "QMLImport", loc: { start: { line: 2, column: 0 }, end: { line: 2, column: 25 } @@ -2022,13 +2147,10 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n end: { line: 2, column: 25 } }, raw: "2.2", - value: 2.2, - major: 2, - minor: 2 } } }],{ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 3, column: 0 }, end: { line: 16, column: 1 } @@ -2043,7 +2165,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 3, column: 7 }, end: { line: 16, column: 1 } @@ -2078,7 +2200,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n } }, { - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 6, column: 1 }, end: { line: 11, column: 2 } @@ -2093,7 +2215,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n name: "MouseArea" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 6, column: 11 }, end: { line: 11, column: 2 } @@ -2152,7 +2274,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n }, script: { type: "QMLStatementBlock", - statements: [{ + body: [{ type: "ExpressionStatement", expression: { type: "CallExpression", @@ -2178,7 +2300,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n } }, { - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 12, column: 1 }, end: { line: 15, column: 2 } @@ -2193,7 +2315,7 @@ test('import QtQuick 2.3\nimport QtQuick.Window 2.2\nWindow {\n\tvisible: true\n name: "Text" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 12, column: 6 }, end: { line: 15, column: 2 } @@ -2279,8 +2401,8 @@ function testLoose(code, ast, options) { test(code, ast, opts); } -testLoose('import QtQuick', headerStatements([{ - type: "QMLImportStatement", +testLoose('import QtQuick', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 14 } @@ -2307,15 +2429,13 @@ testLoose('import QtQuick', headerStatements([{ end: { line: 1, column: 14 } }, value: 0, - major: 0, - minor: 0, raw: "0.0" } } }])); -testLoose('import ', headerStatements([{ - type: "QMLImportStatement", +testLoose('import ', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 7 } @@ -2342,15 +2462,13 @@ testLoose('import ', headerStatements([{ end: { line: 1, column: 7 } }, value: 0, - major: 0, - minor: 0, raw: "0.0" } } }])); -testLoose('import QtQuick 0x01', headerStatements([{ - type: "QMLImportStatement", +testLoose('import QtQuick 0x01', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 19 } @@ -2377,15 +2495,13 @@ testLoose('import QtQuick 0x01', headerStatements([{ end: { line: 1, column: 19 } }, value: 1, - major: 1, - minor: 0, raw: "0x01" } } }])); -testLoose('import QtQuick 1', headerStatements([{ - type: "QMLImportStatement", +testLoose('import QtQuick 1', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 16 } @@ -2412,15 +2528,13 @@ testLoose('import QtQuick 1', headerStatements([{ end: { line: 1, column: 16 } }, value: 1, - major: 1, - minor: 0, raw: "1" } } }])); -testLoose('import "./file.js', headerStatements([{ - type: "QMLImportStatement", +testLoose('import "./file.js', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 17 } @@ -2436,8 +2550,8 @@ testLoose('import "./file.js', headerStatements([{ } }])); -testLoose('import QtQuick 2.2 as ', headerStatements([{ - type: "QMLImportStatement", +testLoose('import QtQuick 2.2 as ', headerItemList([{ + type: "QMLImport", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 22 } @@ -2464,8 +2578,6 @@ testLoose('import QtQuick 2.2 as ', headerStatements([{ end: { line: 1, column: 18 } }, value: 2.2, - major: 2, - minor: 2, raw: "2.2" } }, @@ -2487,7 +2599,7 @@ testLoose('import QtQuick 2.2 as ', headerStatements([{ }])); testLoose('Window {', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 8 } @@ -2502,7 +2614,7 @@ testLoose('Window {', rootObject({ name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 8 } @@ -2512,7 +2624,7 @@ testLoose('Window {', rootObject({ })); testLoose('Window {\n\tprop: 3', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 2, column: 8 } @@ -2527,7 +2639,7 @@ testLoose('Window {\n\tprop: 3', rootObject({ name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 7 }, end: { line: 2, column: 8 } @@ -2564,7 +2676,7 @@ testLoose('Window {\n\tprop: 3', rootObject({ })); testLoose('a {\n\tb {\n\n\tc {\n}', rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", loc: { start: { line: 1, column: 0 }, end: { line: 5, column: 1 } @@ -2579,60 +2691,58 @@ testLoose('a {\n\tb {\n\n\tc {\n}', rootObject({ name: "a" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 2 }, end: { line: 5, column: 1 } }, - members: [ - { - type: "QMLObjectLiteral", + members: [{ + type: "QMLObjectDefinition", + loc: { + start: { line: 2, column: 1 }, + end: { line: 5, column: 1 } + }, + id: { + type: "QMLQualifiedID", loc: { start: { line: 2, column: 1 }, + end: { line: 2, column: 2 } + }, + parts: [{ type: "Identifier", name: "b" }], + name: "b" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 2, column: 3 }, end: { line: 5, column: 1 } }, - id: { - type: "QMLQualifiedID", + members: [{ + type: "QMLObjectDefinition", loc: { - start: { line: 2, column: 1 }, - end: { line: 2, column: 2 } - }, - parts: [{ type: "Identifier", name: "b" }], - name: "b" - }, - body: { - type: "QMLMemberBlock", - loc: { - start: { line: 2, column: 3 }, + start: { line: 4, column: 1 }, end: { line: 5, column: 1 } }, - members: [{ - type: "QMLObjectLiteral", + id: { + type: "QMLQualifiedID", loc: { start: { line: 4, column: 1 }, + end: { line: 4, column: 2 } + }, + parts: [{ type: "Identifier", name: "c" }], + name: "c" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 4, column: 3 }, end: { line: 5, column: 1 } }, - id: { - type: "QMLQualifiedID", - loc: { - start: { line: 4, column: 1 }, - end: { line: 4, column: 2 } - }, - parts: [{ type: "Identifier", name: "c" }], - name: "c" - }, - body: { - type: "QMLMemberBlock", - loc: { - start: { line: 4, column: 3 }, - end: { line: 5, column: 1 } - }, - members: [] - } - }] - } + members: [] + } + }] } - ] + }] } })); @@ -2644,7 +2754,15 @@ testLoose('a{ property var }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -2847,7 +2965,15 @@ testLoose('a{ var }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 6 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -2867,7 +2993,15 @@ testLoose('a{ var w }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 6 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -2888,13 +3022,13 @@ testLoose('a{ obj w }', rootObjectMembers([{ default: false, readonly: false, kind: { - type: "QMLQualifiedID", + type: "QMLPropertyType", loc: { start: { line: 1, column: 3 }, end: { line: 1, column: 6 } }, - parts: [{ type: "Identifier", name: "obj" }], - name: "obj" + primitive: false, + id: { type: "Identifier", name: "obj"} }, id: { type: "Identifier", @@ -2916,7 +3050,15 @@ testLoose('a{ property var b: Window {} }', rootObjectMembers([{ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -2926,7 +3068,7 @@ testLoose('a{ property var b: Window {} }', rootObjectMembers([{ name: "b" }, binding: { - type: "QMLObjectLiteral", + type: "QMLObjectBinding", loc: { start: { line: 1, column: 19 }, end: { line: 1, column: 28 } @@ -2941,7 +3083,7 @@ testLoose('a{ property var b: Window {} }', rootObjectMembers([{ name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 26 }, end: { line: 1, column: 28 } @@ -2968,7 +3110,7 @@ testLoose('a{ b: Window {} }', rootObjectMembers([{ name: "b" }, binding: { - type: "QMLObjectLiteral", + type: "QMLObjectBinding", loc: { start: { line: 1, column: 6 }, end: { line: 1, column: 15 } @@ -2983,7 +3125,7 @@ testLoose('a{ b: Window {} }', rootObjectMembers([{ name: "Window" }, body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", loc: { start: { line: 1, column: 13 }, end: { line: 1, column: 15 } @@ -3065,12 +3207,13 @@ testLoose('a{ signal test(int test }', rootObjectMembers([{ end: { line: 1, column: 23 } }, kind: { - type: "Identifier", + type: "QMLPropertyType", loc: { start: { line: 1, column: 15 }, end: { line: 1, column: 18 } }, - name: "int" + primitive: true, + id: { type: "Identifier", name: "int" } }, id: { type: "Identifier", @@ -3116,7 +3259,15 @@ testLoose('Window {\n\tfunction\n\tproperty var prop\n}', rootObjectMembers([ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 3, column: 10 }, + end: { line: 3, column: 13 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -3171,7 +3322,15 @@ testLoose('Window {\n\tfunction (something)\n\tproperty var prop\n}', rootObject }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 3, column: 10 }, + end: { line: 3, column: 13 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -3217,7 +3376,15 @@ testLoose('Window {\n\tfunction (\n\tproperty var prop\n}', rootObjectMembers([ }, default: false, readonly: false, - kind: "var", + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 3, column: 10 }, + end: { line: 3, column: 13 } + }, + primitive: true, + id: { type: "Identifier", name: "var"} + }, id: { type: "Identifier", loc: { @@ -3230,6 +3397,504 @@ testLoose('Window {\n\tfunction (\n\tproperty var prop\n}', rootObjectMembers([ } ])); +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ QtObject on test {} }", rootObjectMembers([{ + type: "QMLPropertyModifier", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 22 } + }, + kind: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 11 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 19 } + }, + parts: [{ type: "Identifier", name: "test" }], + name: "test" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 20 }, + end: { line: 1, column: 22 } + }, + members: [] + } +}])); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ QtObject on test {} }", rootObjectMembers([{ + type: "QMLPropertyModifier", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 22 } + }, + kind: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 11 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 15 }, + end: { line: 1, column: 19 } + }, + parts: [{ type: "Identifier", name: "test" }], + name: "test" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 20 }, + end: { line: 1, column: 22 } + }, + members: [] + } +}])); + +testLoose("a{ QtObject. on test {} }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 23 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 15 } + }, + parts: [ + { type: "Identifier", name: "QtObject" }, + { type: "Identifier", name: "on" } + ], + name: "QtObject.on" + }, + binding: { + type: "QMLObjectBinding", + loc: { + start: { line: 1, column: 16 }, + end: { line: 1, column: 23 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 16 }, + end: { line: 1, column: 20 } + }, + parts: [{ type: "Identifier", name: "test" }], + name: "test" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 23 } + }, + members: [] + } + } +}]), { locations: true, qmltypes: false } ); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ s: [ QtObject {} ] }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 21 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 4 } + }, + parts: [{ type: "Identifier", name: "s" }], + name: "s" + }, + binding: { + type: "QMLArrayBinding", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 21 } + }, + elements: [ + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 19 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 16 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 17 }, + end: { line: 1, column: 19 } + }, + members: [] + } + } + ] + } +}]), { locations: true, qmltypes: false }); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ s: [ QtObject {}, QtObject {} ] }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 34 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 4 } + }, + parts: [{ type: "Identifier", name: "s" }], + name: "s" + }, + binding: { + type: "QMLArrayBinding", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 34 } + }, + elements: [ + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 19 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 16 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 17 }, + end: { line: 1, column: 19 } + }, + members: [] + } + }, + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 32 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 29 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 30 }, + end: { line: 1, column: 32 } + }, + members: [] + } + } + ] + } +}]), { locations: true, qmltypes: false }); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ s: [ QtObject ] }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 18 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 4 } + }, + parts: [{ type: "Identifier", name: "s" }], + name: "s" + }, + binding: { + type: "QMLScriptBinding", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 18 } + }, + block: false, + script: { + type: "ArrayExpression", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 18 } + }, + elements: [ + { + type: "Identifier", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 16 } + }, + name: "QtObject" + } + ] + } + } +}] +), { locations: true, qmltypes: false }); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ property var s: [ QtObject {} ] }", rootObjectMembers([{ + type: "QMLPropertyDeclaration", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 34 } + }, + default: false, + readonly: false, + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "var" } + }, + id: { + type: "Identifier", + loc: { + start: { line: 1, column: 16 }, + end: { line: 1, column: 17 } + }, + name: "s" + }, + binding: { + type: "QMLArrayBinding", + loc: { + start: { line: 1, column: 19 }, + end: { line: 1, column: 34 } + }, + elements: [ + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 32 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 29 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 30 }, + end: { line: 1, column: 32 } + }, + members: [] + } + } + ] + } +}]), { locations: true, qmltypes: false }); + +// TODO: Allow this to run on the normal parser once the ambiguity is solved +testLoose("a{ property var s: [ QtObject ] }", rootObjectMembers([{ + type: "QMLPropertyDeclaration", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 31 } + }, + default: false, + readonly: false, + kind: { + type: "QMLPropertyType", + loc: { + start: { line: 1, column: 12 }, + end: { line: 1, column: 15 } + }, + primitive: true, + id: { type: "Identifier", name: "var" } + }, + id: { + type: "Identifier", + loc: { + start: { line: 1, column: 16 }, + end: { line: 1, column: 17 } + }, + name: "s" + }, + binding: { + type: "QMLScriptBinding", + loc: { + start: { line: 1, column: 19 }, + end: { line: 1, column: 31 } + }, + block: false, + script: { + type: "ArrayExpression", + loc: { + start: { line: 1, column: 19 }, + end: { line: 1, column: 31 } + }, + elements: [ + { + type: "Identifier", + loc: { + start: { line: 1, column: 21 }, + end: { line: 1, column: 29 } + }, + name: "QtObject" + } + ] + } + } +}]), { locations: true, qmltypes: false }); + +testLoose("a{ s: [ QtObject {} }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 20 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 4 } + }, + parts: [{ type: "Identifier", name: "s" }], + name: "s" + }, + binding: { + type: "QMLArrayBinding", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 20 } + }, + elements: [ + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 19 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 16 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 17 }, + end: { line: 1, column: 19 } + }, + members: [] + } + } + ] + } +}]), { locations: true, qmltypes: false }); + +testLoose("a{ s: [ QtObject { ] }", rootObjectMembers([{ + type: "QMLPropertyBinding", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 22 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 3 }, + end: { line: 1, column: 4 } + }, + parts: [{ type: "Identifier", name: "s" }], + name: "s" + }, + binding: { + type: "QMLArrayBinding", + loc: { + start: { line: 1, column: 6 }, + end: { line: 1, column: 22 } + }, + elements: [ + { + type: "QMLObjectDefinition", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 22 } + }, + id: { + type: "QMLQualifiedID", + loc: { + start: { line: 1, column: 8 }, + end: { line: 1, column: 16 } + }, + parts: [{ type: "Identifier", name: "QtObject" }], + name: "QtObject" + }, + body: { + type: "QMLObjectInitializer", + loc: { + start: { line: 1, column: 17 }, + end: { line: 1, column: 22 } + }, + members: [] + } + } + ] + } +}]), { locations: true, qmltypes: false }); + /*************************************************************************** * QMLTypes Parser Tests * ****************************************************************************/ @@ -3288,34 +3953,34 @@ testQMLTypes('a{ b: ["one", "two"] }', javaScript({ })); /* -* Creates a Program with 'headerStatements' and 'rootObject' as the program's expected +* Creates a Program with 'headerItemList' and 'rootObject' as the program's expected * body. */ -function program(headerStatements, rootObject) { +function program(headerItemList, rootObject) { return { type: "QMLProgram", - headerStatements: { - type: "QMLHeaderStatements", - statements: headerStatements || [] + headerItemList: { + type: "QMLHeaderItemList", + items: headerItemList || [] }, rootObject: rootObject || null }; } /* -* Creates a QMLHeaderStatements with 'stmts' as the expected statements and 'prog' as the -* parent Program. A value of null for 'prog' will append the QMLHeaderStatements AST to +* Creates a QMLHeaderItemList with 'stmts' as the expected statements and 'prog' as the +* parent Program. A value of null for 'prog' will append the QMLHeaderItemList AST to * the Program returned by program(). */ -function headerStatements(stmts, prog) { +function headerItemList(items, prog) { prog = prog || program(); - prog.headerStatements.statements = stmts; + prog.headerItemList.items = items; return prog; } /* -* Creates a QMLObjectLiteral with 'stmts' as the expected statements and 'prog' as the parent -* Program. A value of null for 'prog' will append the QMLObjectLiteral AST to the Program +* Creates a QMLObjectDefinition with 'stmts' as the expected statements and 'prog' as the parent +* Program. A value of null for 'prog' will append the QMLObjectDefinition AST to the Program * returned by program(). */ function rootObject(obj, prog) { @@ -3325,15 +3990,15 @@ function rootObject(obj, prog) { } /* -* Creates a QMLMemberBlock with 'members' as the expected members and 'obj' as the parent -* QMLObjectLiteral. A value of null for 'obj' will append the QMLMemberBlock AST to the -* QMLObjectLiteral returned by rootObject(). +* Creates a QMLObjectInitializer with 'members' as the expected members and 'obj' as the parent +* QMLObjectDefinition. A value of null for 'obj' will append the QMLObjectInitializer AST to the +* QMLObjectDefinition returned by rootObject(). */ function rootObjectMembers(members, obj) { var rootObj = obj || rootObject({ - type: "QMLObjectLiteral", + type: "QMLObjectDefinition", body: { - type: "QMLMemberBlock", + type: "QMLObjectInitializer", members: members } }); @@ -3342,8 +4007,8 @@ function rootObjectMembers(members, obj) { /* * Creates a JavaScript Expression with 'expr' as the expected expression and 'objMembers' as -* the parent QMLMemberBlock. A value of null for 'objMembers' will append the JavaScript -* Expression to the QMLMemberBlock returned by rootObjectMembers(). +* the parent QMLObjectInitializer. A value of null for 'objMembers' will append the JavaScript +* Expression to the QMLObjectInitializer returned by rootObjectMembers(). */ function javaScript(expr, objMembers) { objMembers = objMembers || rootObjectMembers([{ diff --git a/qt/org.eclipse.cdt.qt.core/acorn-qml/walk/index.js b/qt/org.eclipse.cdt.qt.core/acorn-qml/walk/index.js index 7678b13d403..a1883ac501f 100644 --- a/qt/org.eclipse.cdt.qt.core/acorn-qml/walk/index.js +++ b/qt/org.eclipse.cdt.qt.core/acorn-qml/walk/index.js @@ -31,45 +31,54 @@ extendWalk(walk.base, { QMLProgram: function (node, st, c) { - c(node.headerStatements, st); + c(node.headerItemList, st); if (node.rootObject) { c(node.rootObject, st, "QMLRootObject"); } }, - QMLHeaderStatements: function (node, st, c) { - for (var i = 0; i < node.statements.length; i++) { - c(node.statements[i], st, "QMLHeaderStatement"); + QMLHeaderItemList: function (node, st, c) { + for (var i = 0; i < node.items.length; i++) { + c(node.items[i], st, "QMLHeaderItem"); } }, - QMLHeaderStatement: skipThrough, - QMLImportStatement: ignore, - QMLPragmaStatement: ignore, + QMLHeaderItem: skipThrough, + QMLImport: ignore, + QMLPragma: ignore, QMLRootObject: skipThrough, - QMLObjectLiteral: function (node, st, c) { + QMLObjectDefinition: function (node, st, c) { c(node.body, st); }, - QMLMemberBlock: function (node, st, c) { + QMLObjectInitializer: function (node, st, c) { for (var i = 0; i < node.members.length; i++) { - c(node.members[i], st, "QMLMember"); + c(node.members[i], st, "QMLObjectMember"); } }, - QMLMember: skipThrough, + QMLObjectMember: skipThrough, QMLPropertyDeclaration: function (node, st, c) { if (node.binding) { - c(node.binding, st); + c(node.binding, st, "QMLBinding"); } }, QMLSignalDefinition: ignore, QMLPropertyBinding: function (node, st, c) { - c(node.binding, st); + c(node.binding, st, "QMLBinding"); + }, + QMLBinding: skipThrough, + QMLObjectBinding: function (node, st, c) { + c(node.body, st); + }, + QMLArrayBinding: function (node, st, c) { + for (var i = 0; i < node.elements.length; i++) { + c(node.elements[i], st); + } }, QMLScriptBinding: function (node, st, c) { c(node.script, st); }, QMLQualifiedID: ignore, QMLStatementBlock: function (node, st, c) { - for (var i = 0; i < node.statements.length; i++) { - c(node.statements[i], st, "Statement"); + for (var i = 0; i < node.body.length; i++) { + c(node.body[i], st, "Statement"); } } }); diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QMLAnalyzer.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QMLAnalyzer.java index 1764a2223c8..3aca52cfa9a 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QMLAnalyzer.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/QMLAnalyzer.java @@ -8,11 +8,14 @@ package org.eclipse.cdt.qt.core; import java.io.BufferedReader; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -25,12 +28,6 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import org.eclipse.cdt.internal.qt.core.Activator; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; @SuppressWarnings("nls") public class QMLAnalyzer { @@ -74,28 +71,16 @@ public class QMLAnalyzer { ResolveDirectory resolveDirectory = (file, pathString) -> { String filename = (String) file.get("name"); - int slash = filename.lastIndexOf('/'); - String fileDirectory = slash >= 0 ? filename.substring(0, slash + 1) : filename; + String fileDirectory = new File(filename).getParent(); if (pathString == null) { - return fileDirectory; + return fixPathString(fileDirectory); } - IPath path = Path.fromOSString(pathString); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + Path fileDirectoryPath = Paths.get(fileDirectory); + Path path = Paths.get(pathString); if (!path.isAbsolute()) { - IResource res = root.findMember(fileDirectory); - if (res instanceof IContainer) { - IContainer dir = (IContainer) res; - res = dir.findMember(path); - if (res != null) { - String p = res.getFullPath().toString().substring(1); - if (!p.isEmpty() && !p.endsWith("/")) { - p += "/"; - } - return p; - } - } + path = fileDirectoryPath.toAbsolutePath().resolve(path); } - return pathString; + return fixPathString(path.normalize().toString()); }; options.put("resolveDirectory", invoke.invokeFunction("resolveDirectory", resolveDirectory)); @@ -137,19 +122,28 @@ public class QMLAnalyzer { void callback(Object err, Object data); } + private String fixPathString(String fileName) { + fileName = fileName.replaceAll("\\\\", "/"); + if (fileName.startsWith("/")) { + fileName = fileName.substring(1); + } + return fileName; + } + public void addFile(String fileName, String code) throws NoSuchMethodException, ScriptException { waitUntilLoaded(); - invoke.invokeMethod(tern, "addFile", fileName, code); + invoke.invokeMethod(tern, "addFile", fixPathString(fileName), code); } public void deleteFile(String fileName) throws NoSuchMethodException, ScriptException { waitUntilLoaded(); - invoke.invokeMethod(tern, "delFile", fileName); + invoke.invokeMethod(tern, "delFile", fixPathString(fileName)); } public Collection getCompletions(String fileName, String text, int pos) throws NoSuchMethodException, ScriptException { waitUntilLoaded(); + fileName = fixPathString(fileName); Bindings file = engine.createBindings(); file.put("type", "full"); file.put("name", fileName); @@ -201,6 +195,7 @@ public class QMLAnalyzer { public List getDefinition(String identifier, String fileName, String text, int pos) throws NoSuchMethodException, ScriptException { waitUntilLoaded(); + fileName = fixPathString(fileName); Bindings file = engine.createBindings(); file.put("type", "full"); file.put("name", fileName); diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSArrayExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSArrayExpression.java new file mode 100644 index 00000000000..34251ab0882 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSArrayExpression.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript array expression from the ESTree + * Specification + */ +public interface IJSArrayExpression extends IJSExpression { + @Override + default String getType() { + return "ArrayExpression"; //$NON-NLS-1$ + } + + public List getElements(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSAssignmentExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSAssignmentExpression.java new file mode 100644 index 00000000000..d07c0ef80d2 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSAssignmentExpression.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript assignment expression from the + * ESTree Specification + */ +public interface IJSAssignmentExpression extends IJSExpression { + /** + * An Enumeration covering the 12 assignment operators in JavaScript + */ + enum AssignmentOperator { + Assign("="), //$NON-NLS-1$ + AssignAdd("+="), //$NON-NLS-1$ + AssignSubtract("-="), //$NON-NLS-1$ + AssignMultiply("*="), //$NON-NLS-1$ + AssignDivide("/="), //$NON-NLS-1$ + AssignModulus("%="), //$NON-NLS-1$ + AssignLeftShift("<<="), //$NON-NLS-1$ + AssignRightShift(">>="), //$NON-NLS-1$ + AssignUnsignedRightShift(">>>="), //$NON-NLS-1$ + AssignOr("|="), //$NON-NLS-1$ + AssignExclusiveOr("^"), //$NON-NLS-1$ + AssignAnd("&="); //$NON-NLS-1$ + + private final String op; + + private AssignmentOperator(String op) { + this.op = op; + } + + @Override + public String toString() { + return this.op; + } + } + + @Override + default String getType() { + return "AssignmentExpression"; //$NON-NLS-1$ + } + + public AssignmentOperator getOperator(); + + public IJSExpression getLeft(); + + public IJSExpression getRight(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBinaryExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBinaryExpression.java new file mode 100644 index 00000000000..43790d77d59 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBinaryExpression.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript binary expression from the ESTree + * Specification + */ +public interface IJSBinaryExpression extends IJSExpression { + /** + * An Enumeration covering the 21 binary operators in JavaScript + */ + enum BinaryOperator { + Equality("=="), //$NON-NLS-1$ + Inequality("!="), //$NON-NLS-1$ + StrictEquality("==="), //$NON-NLS-1$ + LessThan("<"), //$NON-NLS-1$ + LessThanOrEqual("<="), //$NON-NLS-1$ + GreaterThan(">"), //$NON-NLS-1$ + GreaterThanOrEqual(">="), //$NON-NLS-1$ + LeftShift("<<"), //$NON-NLS-1$ + RightShift(">>"), //$NON-NLS-1$ + UnsignedRightShift(">>>"), //$NON-NLS-1$ + Add("+"), //$NON-NLS-1$ + Subtract("-"), //$NON-NLS-1$ + Multiply("*"), //$NON-NLS-1$ + Divide("/"), //$NON-NLS-1$ + Modulus("%"), //$NON-NLS-1$ + Or("|"), //$NON-NLS-1$ + EclusiveOr("^"), //$NON-NLS-1$ + And("&"), //$NON-NLS-1$ + In("in"), //$NON-NLS-1$ + Instanceof("instanceof"); //$NON-NLS-1$ + + private final String op; + + private BinaryOperator(String op) { + this.op = op; + } + + @Override + public String toString() { + return this.op; + } + } + + @Override + default String getType() { + return "UnaryExpression"; //$NON-NLS-1$ + } + + public BinaryOperator getOperator(); + + public IJSExpression getLeft(); + + public IJSExpression getRight(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBlockStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBlockStatement.java new file mode 100644 index 00000000000..b055638f13c --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBlockStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript block statement from the ESTree + * Specification + */ +public interface IJSBlockStatement extends IJSStatement { + @Override + default String getType() { + return "BlockStatement"; //$NON-NLS-1$ + } + + public List getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBreakStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBreakStatement.java new file mode 100644 index 00000000000..4dbf9fbbfdf --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSBreakStatement.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript break statement from the ESTree + * Specification + */ +public interface IJSBreakStatement extends IJSStatement { + @Override + default String getType() { + return "BreakStatement"; //$NON-NLS-1$ + } + + public IJSIdentifier getLabel(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCallExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCallExpression.java new file mode 100644 index 00000000000..dc534d9a917 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCallExpression.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript call expression from the ESTree + * Specification + */ +public interface IJSCallExpression extends IJSExpression { + @Override + default String getType() { + return "CallExpression"; //$NON-NLS-1$ + } + + public IJSExpression getCallee(); + + public List getArguments(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCatchClause.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCatchClause.java new file mode 100644 index 00000000000..68d6076c6c4 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSCatchClause.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript catch clause from the ESTree + * Specification + */ +public interface IJSCatchClause extends IQmlASTNode { + @Override + default String getType() { + return "CatchClause"; //$NON-NLS-1$ + } + + public IJSPattern getParam(); + + public IJSBlockStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSConditionalExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSConditionalExpression.java new file mode 100644 index 00000000000..385f85404ac --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSConditionalExpression.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript conditional expression from the + * ESTree Specification + */ +public interface IJSConditionalExpression extends IJSExpression { + @Override + default String getType() { + return "ConditionalExpression"; //$NON-NLS-1$ + } + + public IJSExpression getTest(); + + public IJSExpression getAlternate(); + + public IJSExpression getConsequent(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSContinueStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSContinueStatement.java new file mode 100644 index 00000000000..3943169e5ab --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSContinueStatement.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript continue statement from the ESTree + * Specification + */ +public interface IJSContinueStatement extends IJSStatement { + @Override + default String getType() { + return "ContinueStatement"; //$NON-NLS-1$ + } + + public IJSIdentifier getLabel(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDebuggerStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDebuggerStatement.java new file mode 100644 index 00000000000..74ac14b6a0d --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDebuggerStatement.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript debugger statement from the ESTree + * Specification + */ +public interface IJSDebuggerStatement extends IJSStatement { + @Override + default String getType() { + return "DebuggerStatement"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDeclaration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDeclaration.java new file mode 100644 index 00000000000..8a03246a8dc --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDeclaration.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript declaration from the ESTree + * Specification + */ +public interface IJSDeclaration extends IJSStatement { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDoWhileStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDoWhileStatement.java new file mode 100644 index 00000000000..ac2a1cf916e --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSDoWhileStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript do while statement from the ESTree + * Specification + */ +public interface IJSDoWhileStatement extends IJSStatement { + @Override + default String getType() { + return "DoWhileStatement"; //$NON-NLS-1$ + } + + public IJSExpression getTest(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSEmptyStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSEmptyStatement.java new file mode 100644 index 00000000000..fa6b54597e9 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSEmptyStatement.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * An empty JavaScrit statement from the ESTree + * Specification + */ +public interface IJSEmptyStatement extends IJSStatement { + @Override + default String getType() { + return "EmptyStatement"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpression.java new file mode 100644 index 00000000000..8f1f70e5557 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpression.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript expression from the ESTree + * Specification + */ +public interface IJSExpression extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpressionStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpressionStatement.java new file mode 100644 index 00000000000..988dba7ef28 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSExpressionStatement.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript expression statement from the + * ESTree Specification + */ +public interface IJSExpressionStatement extends IJSStatement { + @Override + default String getType() { + return "ExpressionStatement"; //$NON-NLS-1$ + } + + public IJSExpression getExpression(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForInStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForInStatement.java new file mode 100644 index 00000000000..d113f2ae136 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForInStatement.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript for in statement from the ESTree + * Specification + */ +public interface IJSForInStatement extends IJSStatement { + @Override + default String getType() { + return "ForInStatement"; //$NON-NLS-1$ + } + + /** + * @return {@link IJSVariableDeclaration}, or {@link IJSExpression} + */ + public IQmlASTNode getRight(); + + public IJSExpression getLeft(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForStatement.java new file mode 100644 index 00000000000..7686b10bf03 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSForStatement.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript for statement from the ESTree + * Specification + */ +public interface IJSForStatement extends IJSStatement { + @Override + default String getType() { + return "ForStatement"; //$NON-NLS-1$ + } + + /** + * @return {@link IJSVariableDeclaration}, {@link IJSExpression}, or null + */ + public IQmlASTNode getInit(); + + public IJSExpression getTest(); + + public IJSExpression getUpdate(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunction.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunction.java new file mode 100644 index 00000000000..3cd8224bead --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunction.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript function from the ESTree Specification + */ +public interface IJSFunction extends IQmlASTNode { + public IJSIdentifier getIdentifier(); + + public List getParams(); + + public IJSBlockStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionDeclaration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionDeclaration.java new file mode 100644 index 00000000000..e0dae44c456 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionDeclaration.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript function declaration from the + * ESTree Specification + */ +public interface IJSFunctionDeclaration extends IJSFunction, IJSDeclaration, IQmlObjectMember { + @Override + default String getType() { + return "FunctionDeclaration"; //$NON-NLS-1$ + } + + @Override + public IJSIdentifier getIdentifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionExpression.java new file mode 100644 index 00000000000..0d196f2bdf6 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSFunctionExpression.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript function expression from the + * ESTree Specification + */ +public interface IJSFunctionExpression extends IJSExpression { + @Override + default String getType() { + return "FunctionExpression"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIdentifier.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIdentifier.java new file mode 100644 index 00000000000..9549c22000e --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIdentifier.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript identifier from the ESTree + * Specification + */ +public interface IJSIdentifier extends IJSExpression, IJSPattern { + @Override + default public String getType() { + return "Identifier"; //$NON-NLS-1$ + }; + + public String getName(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIfStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIfStatement.java new file mode 100644 index 00000000000..a0b58d0dd29 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSIfStatement.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript if statement from the + * ESTree Specification + */ +public interface IJSIfStatement extends IJSStatement { + @Override + default String getType() { + return "IfStatement"; //$NON-NLS-1$ + } + + public IJSExpression getTest(); + + public IJSStatement getConsequence(); + + public IJSStatement getAlternate(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLabeledStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLabeledStatement.java new file mode 100644 index 00000000000..ddde2ea014e --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLabeledStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript labeled statement from the ESTree + * Specification + */ +public interface IJSLabeledStatement extends IJSStatement { + @Override + default String getType() { + return "LabledStatement"; //$NON-NLS-1$ + } + + public IJSIdentifier getLabel(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLiteral.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLiteral.java new file mode 100644 index 00000000000..2e4e2fab37a --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLiteral.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript literal from the ESTree Specification + */ +public interface IJSLiteral extends IJSExpression { + @Override + default public String getType() { + return "Literal"; //$NON-NLS-1$ + }; + + /** + * @return String, Boolean, Integer, Double, or Regular Expression + */ + public Object getValue(); + + public String getRaw(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLogicalExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLogicalExpression.java new file mode 100644 index 00000000000..de224729607 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSLogicalExpression.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript logical expression from the ESTree + * Specification + */ +public interface IJSLogicalExpression extends IJSExpression { + /** + * An Enumeration covering the two logical operators in JavaScript + */ + enum LogicalOperator { + Or("||"), //$NON-NLS-1$ + And("&&"); //$NON-NLS-1$ + + private final String op; + + private LogicalOperator(String op) { + this.op = op; + } + + @Override + public String toString() { + return this.op; + } + } + + @Override + default String getType() { + return "LogicalExpression"; //$NON-NLS-1$ + } + + public LogicalOperator getOperator(); + + public IJSExpression getLeft(); + + public IJSExpression getRight(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSMemberExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSMemberExpression.java new file mode 100644 index 00000000000..bc7b4d1d859 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSMemberExpression.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript member expression from the ESTree + * Specification + */ +public interface IJSMemberExpression extends IJSExpression { + @Override + default String getType() { + return "MemberExpression"; //$NON-NLS-1$ + } + + public IJSExpression getOjbect(); + + public IJSExpression getProperty(); + + public boolean isComputed(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSNewExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSNewExpression.java new file mode 100644 index 00000000000..b23f20cac0a --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSNewExpression.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript new expression from the ESTree + * Specification + */ +public interface IJSNewExpression extends IJSCallExpression { + @Override + default String getType() { + return "NewExpression"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSObjectExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSObjectExpression.java new file mode 100644 index 00000000000..997c437e87a --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSObjectExpression.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript object expression from the ESTree + * Specification + */ +public interface IJSObjectExpression extends IJSExpression { + @Override + default String getType() { + return "ObjectExpression"; //$NON-NLS-1$ + } + + public List getProperties(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSPattern.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSPattern.java new file mode 100644 index 00000000000..83930954d54 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSPattern.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript pattern from the ESTree Specification + */ +public interface IJSPattern extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProgram.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProgram.java new file mode 100644 index 00000000000..105e69d331a --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProgram.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript program from the ESTree Specification + */ +public interface IJSProgram extends IQmlASTNode { + @Override + default String getType() { + return "Program"; //$NON-NLS-1$ + } + + public List getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProperty.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProperty.java new file mode 100644 index 00000000000..d8d20ba0028 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSProperty.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript object property from the ESTree + * Specification + */ +public interface IJSProperty extends IQmlASTNode { + @Override + default String getType() { + return "Property"; //$NON-NLS-1$ + } + + /** + * @return {@link IJSLiteral}, or {@link IJSIdentifier} + */ + public IQmlASTNode getKey(); + + public IJSExpression getValue(); + + public String getKind(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSRegExpLiteral.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSRegExpLiteral.java new file mode 100644 index 00000000000..304d7e2bb46 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSRegExpLiteral.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript regular expression literal from the + * ESTree Specification + */ +public interface IJSRegExpLiteral extends IJSLiteral { + /** + * A JavaScript regular expression that holds a pattern and a set of flags. Both are represented as plain Strings. + */ + public static class JSRegExp { + private final String pattern; + private final String flags; + + public JSRegExp(String pattern, String flags) { + this.pattern = pattern; + this.flags = flags; + } + + public String getPattern() { + return pattern; + } + + public String getFlags() { + return flags; + } + } + + public JSRegExp getRegex(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSReturnStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSReturnStatement.java new file mode 100644 index 00000000000..6b6c58e553c --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSReturnStatement.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript return statement from the ESTree + * Specification + */ +public interface IJSReturnStatement extends IJSStatement { + @Override + default String getType() { + return "ReturnStatement"; //$NON-NLS-1$ + } + + public IJSExpression getArgument(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSequenceExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSequenceExpression.java new file mode 100644 index 00000000000..4cdd2baa9e1 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSequenceExpression.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript sequence expression from the + * ESTree Specification + */ +public interface IJSSequenceExpression extends IJSExpression { + @Override + default String getType() { + return "SequenceExpression"; //$NON-NLS-1$ + } + + public List getExpressions(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSStatement.java new file mode 100644 index 00000000000..a2617e3c939 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSStatement.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript statement from the ESTree + * Specification + */ +public interface IJSStatement extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchCase.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchCase.java new file mode 100644 index 00000000000..6247a01d4e9 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchCase.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript switch case from the ESTree + * Specification + */ +public interface IJSSwitchCase extends IQmlASTNode { + @Override + default String getType() { + return "SwitchCase"; //$NON-NLS-1$ + } + + public IJSExpression getTest(); + + public List getConsequent(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchStatement.java new file mode 100644 index 00000000000..9c0ca91a98f --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSSwitchStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript switch statement from the ESTree + * Specification + */ +public interface IJSSwitchStatement extends IJSStatement { + @Override + default String getType() { + return "SwitchStatement"; //$NON-NLS-1$ + } + + public IJSExpression getDiscriminant(); + + public IJSSwitchCase getCases(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThisExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThisExpression.java new file mode 100644 index 00000000000..1cc3fbe1b6c --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThisExpression.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript this expression from the ESTree + * Specification + */ +public interface IJSThisExpression extends IJSExpression { + @Override + default String getType() { + return "ThisExpression"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThrowStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThrowStatement.java new file mode 100644 index 00000000000..f3ddf6e1022 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSThrowStatement.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript throw statement from the ESTree + * Specification + */ +public interface IJSThrowStatement extends IJSStatement { + @Override + default String getType() { + return "ThrowStatement"; //$NON-NLS-1$ + } + + public IJSExpression getArgument(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSTryStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSTryStatement.java new file mode 100644 index 00000000000..a89fede7b49 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSTryStatement.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript try statement from the ESTree + * Specification + */ +public interface IJSTryStatement extends IJSStatement { + @Override + default String getType() { + return "TryStatement"; //$NON-NLS-1$ + } + + public IJSBlockStatement getBlock(); + + public IJSCatchClause getHandler(); + + public IJSBlockStatement getFinalizer(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUnaryExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUnaryExpression.java new file mode 100644 index 00000000000..6fe2c021b12 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUnaryExpression.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript unary expression from the ESTree + * Specification + */ +public interface IJSUnaryExpression extends IJSExpression { + /** + * An Enumeration covering the 7 unary operators in JavaScript + */ + enum UnaryOperator { + Negation("-"), //$NON-NLS-1$ + Plus("+"), //$NON-NLS-1$ + Not("!"), //$NON-NLS-1$ + BitwiseNot("~"), //$NON-NLS-1$ + Typeof("typeof"), //$NON-NLS-1$ + Void("void"), //$NON-NLS-1$ + Delete("delete"); //$NON-NLS-1$ + + private final String op; + + private UnaryOperator(String op) { + this.op = op; + } + + @Override + public String toString() { + return this.op; + } + } + + @Override + default String getType() { + return "UnaryExpression"; //$NON-NLS-1$ + } + + public UnaryOperator getOperator(); + + public boolean isPrefix(); + + public IJSExpression getArgument(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUpdateExpression.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUpdateExpression.java new file mode 100644 index 00000000000..cddb8461a3e --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSUpdateExpression.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript update expression from the ESTree + * Specification + */ +public interface IJSUpdateExpression extends IQmlASTNode { + /** + * An Enumeration covering the two update operators in JavaScript + */ + enum UpdateOperator { + Decrement("--"), //$NON-NLS-1$ + Increment("++"); //$NON-NLS-1$ + + private final String op; + + private UpdateOperator(String op) { + this.op = op; + } + + @Override + public String toString() { + return this.op; + } + } + + @Override + default String getType() { + return "UpdateExpression"; //$NON-NLS-1$ + } + + public UpdateOperator getOperator(); + + public IJSExpression getArgument(); + + public boolean isPrefix(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclaration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclaration.java new file mode 100644 index 00000000000..ec35a257ce5 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclaration.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +/** + * A JavaScript variable declaration from the + * ESTree Specification + */ +public interface IJSVariableDeclaration extends IJSDeclaration { + @Override + default String getType() { + return "VariableDeclaration"; //$NON-NLS-1$ + } + + public List getDeclarations(); + + default public String getKind() { + return "var"; //$NON-NLS-1$ + } +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclarator.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclarator.java new file mode 100644 index 00000000000..93b81adbbdd --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSVariableDeclarator.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript variable declarator from the + * ESTree Specification + */ +public interface IJSVariableDeclarator extends IQmlASTNode { + @Override + default String getType() { + return "VariableDeclarator"; //$NON-NLS-1$ + } + + public IJSPattern getIdentifier(); + + public IJSExpression getInit(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWhileStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWhileStatement.java new file mode 100644 index 00000000000..4b1393aca3b --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWhileStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript while statement from the ESTree + * Specification + */ +public interface IJSWhileStatement extends IJSStatement { + @Override + default String getType() { + return "WhileStatement"; //$NON-NLS-1$ + } + + public IJSExpression getTest(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWithStatement.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWithStatement.java new file mode 100644 index 00000000000..1e1586b7b2c --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IJSWithStatement.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +/** + * A JavaScript with statement from the ESTree + * Specification + */ +public interface IJSWithStatement extends IJSStatement { + @Override + default String getType() { + return "WithStatement"; //$NON-NLS-1$ + } + + public IJSExpression getObject(); + + public IJSStatement getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlASTNode.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlASTNode.java new file mode 100644 index 00000000000..3e85efee2b2 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlASTNode.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import org.eclipse.cdt.qt.core.location.ISourceLocation; +import org.eclipse.cdt.qt.core.qmldir.IQDirASTNode; +import org.eclipse.cdt.qt.core.tern.ITernScope; + +/** + * The base node interface for all QML and JavaScript Abstract Syntax Tree elements. Conforms to the ESTree Specification as well as + * the extra features added by Acorn. + * + * @see ESTree Node Objects + */ +public interface IQmlASTNode { + + /** + * Gets the String representation of the type of AST node that this node represents. This is a bit redundant in Java with access + * to instanceof, but is provided for the sake of conforming to the ESTree Specification for node objects. + * + * @return the String representation of this node + */ + public String getType(); + + /** + * Gets a more detailed description of this node's location than {@link IQDirASTNode#getStart()} and + * {@link IQDirASTNode#getStart()}. This method allows the retrieval of line and column information in order to make output for + * syntax errors and the like more human-readable.
+ *
+ * Note: It is necessary to set the 'locations' option to true when parsing with acorn in order to use this + * method. + * + * @return the {@link ISourceLocation} representing this node's location in the source or null if not available + */ + public ISourceLocation getLocation(); + + /** + * Gets the range of this node if available. A range is an array of two integers containing the start and end offset of this + * node in that order. Like {@link IQmlASTNode#getStart()} and {@link IQmlASTNode#getEnd()}, this method returns zero-indexed + * offsets relative to the beginning of the source.
+ *
+ * Note: It is necessary to set the 'ranges' option to true when parsing with acorn in order to use this + * method. + * + * @return the range of this node or null if not available + */ + public int[] getRange(); + + /** + * Gets the zero-indexed offset indicating the start of this node relative to the beginning of the source. + * + * @return the node's start offset + */ + public int getStart(); + + /** + * Gets the zero-indexed offset indicating the end of this node relative to the beginning of the source. + * + * @return the node's end offset + */ + public int getEnd(); + + /** + * Gets the {@link ITernScope} attached to this node if one exists. This method will only return a non-null value if the AST was + * already processed by Tern. For example, if the AST was retrieved from Tern using the 'parseFile' query, then at least one of + * the AST nodes will contain a scope object. However, if the 'parseString' query was used, no static analysis will be performed + * on the parsed AST and there will be no scope objects attached to any of its nodes. + * + * @return the Tern scope or null if not available + */ + public ITernScope getScope(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlArrayBinding.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlArrayBinding.java new file mode 100644 index 00000000000..e37ddebd15e --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlArrayBinding.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlArrayBinding extends IQmlBinding { + @Override + default public String getType() { + return "QMLArrayBinding"; //$NON-NLS-1$ + }; + + public List getElements(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlBinding.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlBinding.java new file mode 100644 index 00000000000..a860c6994c7 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlBinding.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlBinding extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItem.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItem.java new file mode 100644 index 00000000000..dc0c606eb32 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItem.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlHeaderItem extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItemList.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItemList.java new file mode 100644 index 00000000000..617b60388b2 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlHeaderItemList.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlHeaderItemList extends IQmlASTNode { + public List getItems(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlImport.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlImport.java new file mode 100644 index 00000000000..cbbcc327b4f --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlImport.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlImport extends IQmlHeaderItem { + @Override + default public String getType() { + return "QMLImport"; //$NON-NLS-1$ + }; + + public IQmlModule getModule(); + + public IJSLiteral getDirectory(); + + public IQmlQualifier getQualifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlModule.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlModule.java new file mode 100644 index 00000000000..46b8dc05ee0 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlModule.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlModule extends IQmlASTNode { + public IQmlQualifiedID getIdentifier(); + + public IQmlVersionLiteral getVersion(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectBinding.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectBinding.java new file mode 100644 index 00000000000..61c51077248 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectBinding.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlObjectBinding extends IQmlBinding { + @Override + default public String getType() { + return "QMLObjectBinding"; //$NON-NLS-1$ + }; + + public IQmlQualifiedID getIdentifier(); + + public IQmlObjectInitializer getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectDefinition.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectDefinition.java new file mode 100644 index 00000000000..5af2289ed37 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectDefinition.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlObjectDefinition extends IQmlObjectMember { + @Override + default public String getType() { + return "QMLObjectDefinition"; //$NON-NLS-1$ + }; + + public IQmlQualifiedID getIdentifier(); + + public IQmlObjectInitializer getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectInitializer.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectInitializer.java new file mode 100644 index 00000000000..0ced8b072d6 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectInitializer.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlObjectInitializer extends IQmlASTNode { + @Override + default public String getType() { + return "QMLObjectInitializer"; //$NON-NLS-1$ + }; + + public List getMembers(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectMember.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectMember.java new file mode 100644 index 00000000000..f026675cfa4 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlObjectMember.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlObjectMember extends IQmlASTNode { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlParameter.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlParameter.java new file mode 100644 index 00000000000..f1d413cc450 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlParameter.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlParameter extends IQmlASTNode { + @Override + default public String getType() { + return "QMLParameter"; //$NON-NLS-1$ + }; + + public IQmlPropertyType getKind(); + + public IJSIdentifier getIdentifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPragma.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPragma.java new file mode 100644 index 00000000000..440a8818fad --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPragma.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlPragma extends IQmlHeaderItem { + @Override + default public String getType() { + return "QMLPragma"; //$NON-NLS-1$ + }; + + public IQmlQualifiedID getIdentifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlProgram.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlProgram.java new file mode 100644 index 00000000000..75d7ac137ea --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlProgram.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlProgram extends IQmlASTNode { + public static enum Modes { + QML("qml"), QMLTypes("qmltypes"), JavaScript("js"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private final String ident; + + private Modes(String s) { + this.ident = s; + } + + public String getModeIdentifier() { + return this.ident; + } + } + + @Override + default public String getType() { + return "QMLProgram"; //$NON-NLS-1$ + }; + + public Modes getMode(); + + public IQmlHeaderItemList getHeaderItemList(); + + public IQmlRootObject getRootObject(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyBinding.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyBinding.java new file mode 100644 index 00000000000..58da5d517a3 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyBinding.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlPropertyBinding extends IQmlObjectMember { + @Override + default public String getType() { + return "QMLPropertyBinding"; //$NON-NLS-1$ + }; + + public IQmlQualifiedID getIdentifier(); + + public IQmlBinding getBinding(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyDeclaration.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyDeclaration.java new file mode 100644 index 00000000000..5f5f1c17522 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyDeclaration.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlPropertyDeclaration extends IQmlObjectMember { + @Override + default public String getType() { + return "QMLPropertyDeclaration"; //$NON-NLS-1$ + }; + + public boolean isReadonly(); + + public boolean isDefault(); + + public IQmlPropertyType getKind(); + + public IQmlPropertyType getModifier(); + + public IJSIdentifier getIdentifier(); + + public IQmlBinding getBinding(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyType.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyType.java new file mode 100644 index 00000000000..133dfa2f681 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlPropertyType.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlPropertyType extends IQmlASTNode { + @Override + default public String getType() { + return "QMLPropertyType"; //$NON-NLS-1$ + }; + + public boolean isPrimitive(); + + public IJSIdentifier getIdentifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifiedID.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifiedID.java new file mode 100644 index 00000000000..42d947e0a51 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifiedID.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlQualifiedID extends IQmlASTNode { + @Override + default public String getType() { + return "QMLQualifiedID"; //$NON-NLS-1$ + }; + + public List getParts(); + + public String getName(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifier.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifier.java new file mode 100644 index 00000000000..7b3f01b3a9a --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlQualifier.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlQualifier extends IQmlASTNode { + @Override + default public String getType() { + return "QMLQualifier"; //$NON-NLS-1$ + }; + + public IJSIdentifier getIdentifier(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlRootObject.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlRootObject.java new file mode 100644 index 00000000000..e2fa2fcdc4c --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlRootObject.java @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlRootObject extends IQmlObjectDefinition { +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlScriptBinding.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlScriptBinding.java new file mode 100644 index 00000000000..fb73eafde36 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlScriptBinding.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlScriptBinding extends IQmlBinding { + @Override + default public String getType() { + return "QMLScriptBinding"; //$NON-NLS-1$ + }; + + public boolean isBlock(); + + /** + * @return {@link IJSExpression}, or {@link IQmlStatementBlock} + */ + public IQmlASTNode getScript(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlSignalDefinition.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlSignalDefinition.java new file mode 100644 index 00000000000..478beb3d499 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlSignalDefinition.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlSignalDefinition extends IQmlObjectMember { + @Override + default public String getType() { + return "QMLSignalDefinition"; //$NON-NLS-1$ + }; + + public IJSIdentifier getIdentifier(); + + public List getParams(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlStatementBlock.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlStatementBlock.java new file mode 100644 index 00000000000..e575a115f14 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlStatementBlock.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +import java.util.List; + +public interface IQmlStatementBlock extends IQmlASTNode { + @Override + default public String getType() { + return "QMLStatementBlock"; //$NON-NLS-1$ + }; + + public List getBody(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlVersionLiteral.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlVersionLiteral.java new file mode 100644 index 00000000000..7ce574997f8 --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/qmljs/IQmlVersionLiteral.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.qmljs; + +public interface IQmlVersionLiteral extends IQmlASTNode { + @Override + default public String getType() { + return "QMLVersionLiteral"; //$NON-NLS-1$ + }; + + public double getValue(); + + public String getRaw(); +} diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/tern/ITernScope.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/tern/ITernScope.java new file mode 100644 index 00000000000..5463f4899ee --- /dev/null +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/qt/core/tern/ITernScope.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.qt.core.tern; + +public interface ITernScope { + // TODO: Determine the necessary components of a Tern Scope +} diff --git a/qt/org.eclipse.cdt.qt.core/tern-qml/qml.js b/qt/org.eclipse.cdt.qt.core/tern-qml/qml.js index 8738e9dffa6..63bfd5d1b9d 100644 --- a/qt/org.eclipse.cdt.qt.core/tern-qml/qml.js +++ b/qt/org.eclipse.cdt.qt.core/tern-qml/qml.js @@ -141,7 +141,7 @@ // Walk the AST for any imports var ih = this; walk.simple(file.ast, { - QMLImportStatement: function (node) { + QMLImport: function (node) { var prop = null; var scope = file.scope; if (node.qualifier) { @@ -551,19 +551,22 @@ // Infers the property's type from its given primitive value function infKind(kind, out) { - switch (kind) { - case "int": - case "double": - case "real": - infer.cx().num.propagate(out); - break; - case "string": - case "color": - infer.cx().str.propagate(out); - break; - case "boolean": - infer.cx().bool.propagate(out); - break; + // TODO: infer list type + if (kind.primitive) { + switch (kind.id.name) { + case "int": + case "double": + case "real": + infer.cx().num.propagate(out); + break; + case "string": + case "color": + infer.cx().str.propagate(out); + break; + case "boolean": + infer.cx().bool.propagate(out); + break; + } } } @@ -612,11 +615,15 @@ function extendTernScopeGatherer(scopeGatherer) { // Extend the Tern scopeGatherer to build up our custom QML scoping extendWalk(scopeGatherer, { - QMLObjectLiteral: function (node, scope, c) { + QMLObjectDefinition: function (node, scope, c) { var inner = node.scope = getScopeBuilder().newObjScope(node); c(node.body, inner); }, - QMLMemberBlock: function (node, scope, c) { + QMLObjectBinding: function (node, scope, c) { + var inner = node.scope = getScopeBuilder().newObjScope(node); + c(node.body, inner); + }, + QMLObjectInitializer: function (node, scope, c) { var memScope = node.scope = getScopeBuilder().newMemberScope(scope, node); for (var i = 0; i < node.members.length; i++) { var member = node.members[i]; @@ -667,8 +674,8 @@ QMLStatementBlock: function (node, scope, c) { var inner = getScopeBuilder().newJSScope(scope, node); node.scope = inner; - for (var i = 0; i < node.statements.length; i++) { - c(node.statements[i], inner, "Statement"); + for (var i = 0; i < node.body.length; i++) { + c(node.body[i], inner, "Statement"); } }, QMLSignalDefinition: function (node, scope, c) { @@ -707,8 +714,11 @@ QMLScriptBinding: fill(function (node, scope, out, name) { return inf(node.script, node.scope, out, name); }), - QMLObjectLiteral: ret(function (node, scope, name) { + QMLObjectBinding: ret(function (node, scope, name) { return node.scope.objType; + }), + QMLArrayBinding: ret(function (node, scope, name) { + return new infer.Arr(null); // TODO: populate with type of array contents }) }); } @@ -716,10 +726,13 @@ function extendTernInferWrapper(inferWrapper) { // Extend the inferWrapper methods extendWalk(inferWrapper, { - QMLObjectLiteral: function (node, scope, c) { + QMLObjectDefinition: function (node, scope, c) { c(node.body, node.scope); }, - QMLMemberBlock: function (node, scope, c) { + QMLObjectBinding: function (node, scope, c) { + c(node.body, node.scope); + }, + QMLObjectInitializer: function (node, scope, c) { for (var i = 0; i < node.members.length; i++) { var member = node.members[i]; if (member.type === "QMLPropertyDeclaration" || member.type === "QMLPropertyBinding") { @@ -765,15 +778,15 @@ c(node.script, node.scope); }, QMLStatementBlock: function (node, scope, c) { - for (var i = 0; i < node.statements.length; i++) { - c(node.statements[i], node.scope, "Statement"); + for (var i = 0; i < node.body.length; i++) { + c(node.body[i], node.scope, "Statement"); } }, QMLSignalDefinition: function (node, scope, c) { var sig = scope.getProp(node.id.name); for (var i = 0; i < node.params.length; i++) { var param = node.params[i]; - infKind(param.kind.name, sig.sigType.args[i]); + infKind(param.kind, sig.sigType.args[i]); } sig.sigType.retval = infer.ANull; sig.sigType.propagate(sig); @@ -788,10 +801,13 @@ function extendTernTypeFinder(typeFinder) { // Extend the type finder to return valid types for QML AST elements extendWalk(typeFinder, { - QMLObjectLiteral: function (node, scope) { + QMLObjectDefinition: function (node, scope) { return node.scope.objType; }, - QMLMemberBlock: function (node, scope) { + QMLObjectBinding: function (node, scope) { + return node.scope.objType; + }, + QMLObjectInitializer: function (node, scope) { return infer.ANull; }, FunctionDeclaration: function (node, scope) { @@ -819,10 +835,13 @@ function extendTernSearchVisitor(searchVisitor) { // Extend the search visitor to traverse the scope properly extendWalk(searchVisitor, { - QMLObjectLiteral: function (node, scope, c) { + QMLObjectDefinition: function (node, scope, c) { c(node.body, node.scope); }, - QMLMemberBlock: function (node, scope, c) { + QMLObjectBinding: function (node, scope, c) { + c(node.body, node.scope); + }, + QMLObjectInitializer: function (node, scope, c) { for (var i = 0; i < node.members.length; i++) { var member = node.members[i]; if (member.type === "QMLPropertyDeclaration" || member.type === "QMLPropertyBinding") { @@ -868,8 +887,8 @@ // Ignore }, QMLStatementBlock: function (node, scope, c) { - for (var i = 0; i < node.statements.length; i++) { - c(node.statements[i], node.scope, "Statement"); + for (var i = 0; i < node.body.length; i++) { + c(node.body[i], node.scope, "Statement"); } } }); diff --git a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLContentAssistProcessor.java b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLContentAssistProcessor.java index dd163674e87..a7de25a2720 100644 --- a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLContentAssistProcessor.java +++ b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLContentAssistProcessor.java @@ -42,7 +42,7 @@ public class QMLContentAssistProcessor implements IContentAssistProcessor { String prefix = lastWord(document, offset); // Save the file IFileEditorInput fileInput = (IFileEditorInput) editor.getEditorInput(); - String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath().substring(1); + String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath(); try { String contents = document.get(); diff --git a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java index 5437b92c200..7339ca15618 100644 --- a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java +++ b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.qt.ui.editor; +import java.io.File; + import javax.script.ScriptException; import org.eclipse.cdt.internal.qt.ui.Activator; @@ -50,7 +52,7 @@ public class QMLEditor extends TextEditor { @Override public void doSave(IProgressMonitor progressMonitor) { IFileEditorInput fileInput = (IFileEditorInput) getEditorInput(); - String fileName = fileInput.getFile().getFullPath().toString().substring(1); + String fileName = new File(fileInput.getFile().getLocationURI()).getAbsolutePath(); IDocument document = getSourceViewer().getDocument(); try {