Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EDT:JSONConversionJavaScriptGenerationAndRuntime

Revision as of 16:52, 17 July 2012 by Jvincens.us.ibm.com (Talk | contribs) (org.eclipse.edt.gen.javascript.templates:)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

JavaScript Plugins

org.eclipse.edt.gen.javascript.templates:

The Field preGen scans all fields for an EGL JSONName annotation, if a field does not have the annotation it is added to the field. When a record or handler is generated:

  • eze$$getAnnotations is generated and contains annotations on the part. There are no pertinent part annotations for JSON conversion.
  • eze$$getFieldInfos is generated and contains an array of 'generated annotations' for each field in the part:
    • A JSONName annotation will be generated . It will contain the name to be used by the JsonLib converters.
    • A FieldInfo object is generated that contains:
      • the field name or if there is a getter/setter function the getter/setter function name
      • the type signature
      • the EGL field type.
org.eclipse.edt.runtime.javascript:

The JSON string parser is located in eglx/json/JSONParser.js. This file actually contains the 3 parsers from Douglas Crockford's. 1 is an eval parser, 1 is a state parser and the other is a recursive descent parser.

  • By default we use JavaScript state parser. The eval parser has a problem because it converts numbers into JavaScript numbers which have a 15.955 digit precision limit. The state parser and recursive descent parser have been modified to determine if the number being parsed is < 16 digits. If it's < 16 digits a JavaScript number is created, if the length is 16 or greater an EGL BigDecimal is created. The state parser was chosen because it is faster than the recursive descent parser and doesn't introduce data errors like the eval parser.

The Json parser converts the JSON string into the objects. eglx.json.JSONLib

  • convertToJSON: loops through each field creating a name value pair.
  • convertFrom JSON first parses the 'JSON' string into intermediate objects.
    • Then loops through the egl fields for each field
      • Uses the JSON name from the annotations to get the JSON value
      • Uses the FieldInfo to assigns that value to the field.

Dictionaries have no generated annotations values are converted based on the JSON type not the EGL type.

Back to the top