converting to JSON and adding a few more tests
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
index d8f87a2..4814945 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
@@ -4,11 +4,10 @@
this._name = null;
this._versionRange = orion.VersionRange.EMPTY_RANGE;
- this._bundleSymbolicName = null;
+ this._bundleName = null;
this._bundleVersionRange = orion.VersionRange.EMPTY_RANGE;
this._optional = false;
this._attributes = {};
- this._directives = {};
this._wiredExport = null;
this._parseImport(header);
@@ -16,44 +15,29 @@
orion.Import.prototype = {
_parseImport : function(header) {
- var tokens = header.split(orion.Constants.PARAMETER_DELIMITER);
- this._name = tokens[0].replace(/^\s+|\s+$/g, '');
- for ( var i = 1; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.indexOf(orion.Constants.DIRECTIVE_EQUALS) !== -1)
- this._parseDirective(token);
- else if (token.indexOf(orion.Constants.ATTRIBUTE_EQUALS) !== -1)
- this._parseAttribute(token);
- else
- throw "bad import syntax: " + token + " in " + header;
+ if (typeof header == "string") {
+ this._name = header;
+ return;
}
- },
- _parseAttribute : function(token) {
- var index = token.indexOf(orion.Constants.ATTRIBUTE_EQUALS);
- var attributeName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (attributeName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.ATTRIBUTE_EQUALS.length).replace(/^\s+|\s+$/g, '');
-
- if (attributeName === orion.Constants.VERSION_ATTRIBUTE)
- this._versionRange = orion.VersionRange.parseVersionRange(value);
- else if (attributeName === orion.Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)
- this._bundleSymbolicName = value;
- else if (attributeName === orion.Constants.BUNDLE_VERSION_ATTRIBUTE)
- this._bundleVersionRange = orion.VersionRange.parseVersionRange(value);
- this._attributes[attributeName] = value;
- },
- _parseDirective : function(token) {
- var index = token.indexOf(orion.Constants.DIRECTIVE_EQUALS);
- var directiveName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (directiveName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.DIRECTIVE_EQUALS.length).replace(/^\s+|\s+$/g, '');
- if (directiveName === orion.Constants.RESOLUTION_DIRECTIVE && value === orion.Constants.RESOLUTION_OPTIONAL)
- this._optional = true;
- this._directives[directiveName] = value;
+
+ this._name = header.name;
+ if (header.version)
+ this._versionRange = orion.VersionRange.parseVersionRange(header.version);
+
+ if (header.bundleName)
+ this._bundleName = orion.VersionRange.parseVersionRange(header.bundleName);
+
+ if (header.bundleVersion)
+ this._bundleVersionRange = orion.VersionRange.parseVersionRange(header.bundleVersion);
+
+ if (header.resolution)
+ this._optional = (header.resolution === "optional");
+
+ var attributeName;
+ for (attributeName in header) {
+ if (header.hasOwnProperty(attributeName))
+ this._attributes[attributeName] = header[attributeName];
+ }
},
getName : function() {
return this._name;
@@ -61,8 +45,8 @@
getVersionRange : function() {
return this._versionRange;
},
- getBundleSymbolicName : function() {
- return this._bundleSymbolicName;
+ getBundleName : function() {
+ return this._bundleName;
},
getBundleVersionRange : function() {
return this._bundleVersionRange;
@@ -73,9 +57,6 @@
getAttributes : function() {
this._attributes;
},
- getDirectives : function() {
- return this._directives;
- },
wire : function(candidate) {
if (this._name !== candidate.getName())
return false;
@@ -91,13 +72,13 @@
},
_checkAttributes : function(candidate) {
for ( var key in this._attributes) {
- if (key === orion.Constants.VERSION_ATTRIBUTE) {
+ if (key === "version") {
if (!this._versionRange.isIncluded(candidate.getVersion()))
return false;
- } else if (key === orion.Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE) {
- if (!this._bundleSymbolicName === candidate.getBundleSymbolicName())
+ } else if (key === "bundleName") {
+ if (this._bundleName !== candidate.getBundleName())
return false;
- } else if (key === orion.Constants.BUNDLE_VERSION_ATTRIBUTE) {
+ } else if (key === "bundleVersion") {
if (!this._bundleVersionRange.isIncluded(candidate.getBundleVersion()))
return false;
} else {