Last Updated: 2019-08-21

Authors:
Jens von Pilgrim, Jakub Siberski, Mark-Oliver Reiser, Torsten Krämer, Ákos Kitta, Sebastian Zarnekow, Lorenzo Bettini, Jörg Reichert, Kristian Duske, Marcus Mews, Minh Quang Tran, Luca Beurer-Kellner

Abstract

This document contains the N4JS IDE Specification.

Introduction

This document describes the features of the N4JS IDE, that is the user interface and features available to users of the IDE. The language N4JS is described in [N4JSSpec] and is not part of this document.

1. Views

This section briefly introduces all the views that belong to the application’s default perspective.

1.1. Eclipse Standard Views

In the following we descibe views usually available in Eclipse based IDEs. Some of the views were slightly adjusted to match specific N4JS needs.

1.1.1. Project Explorer

The Project Explorer view shows the resources from the underlying workspace in a hierarchical way. From this view one can open a resource for editing in the associated editor or select it to perform an operation on the resource. A popup contest menu is available from the Project Explorer for each resources if used right clicks any of them. A lot of convenient actions are available for from the popping context menu: file modifications (such as Copy, Cut, Paste and Delete) and import/export. Project Explorer support file system modifications by drag-and-dropping resources. One can link the Project Explorer with the editors, if one enables the view-editor-linking then the node in the tree representing a particular resource in the workspace will be automatically revealed and highlighted once one activates the corresponding editor. This works the other way around as well, when a node is selected in the tree and the corresponding resource is opened in an editor, then the editor will be activated.

1.1.2. Outline

The Outline view is responsible for displaying the outline of a structured file that is currently opened in an editor. In case of opening an N4JS file the view depicts all the types defined in the file. The owned members, functions and methods of a particular type are represented in a tree structure. Furthermore in case of opening an N4JS file in the editor, one can link the Outline view with the editor which means whenever one selects a node from the outline view the corresponding item will be revealed and highlighted in the editor.

1.1.3. Problems

This view is used to show all validation errors and warnings in a table that are generated for workbench resources such as N4JS files. For instance when one writes and/or saves an N4JS file that contains validation errors and/or warnings those issues will be automatically logged into the Problems view. One can reveal the actual problem in the N4JS by simply double-clicking on the problem in the view. In this case the corresponding N4JS file will be opened (if it was not already opened), activated and the relevant line will be revealed in the editor. By default the grouping in the Problems view is done by the severity of the issues. One can group the issues by issue type or just disable the grouping at all. The first column of the table is the actual description of the issue for a particular resource. The second column names the problematic resource itself. The third column shows the relative path of the problematic resource. The location, fifth, column describes the problematic line in the resource. And last but not least the sixth column is for naming the type of the problem. This is optional and might be missing for some cases. One can customise the content of the view from the view menu. One can limit the number of revealed items in the table or can modify the behaviour of the content provider.

1.1.4. Console

The Console view is used to reveal a text based output provided by a running process and also allows user to provide any input to the running process from the keyboard.

1.1.5. History

History view supports a way to track the changes of the workbench resources. This view also responsible for providing a convenient way to reveal historical revisions of a particular resource and it is even supports a mechanism to compare two different revisions of a resource. By default this view only provides local historical information but if a resource is under version control then one can retrieve revisions for that particular resource even it was made by remotely by another IDE user.

1.1.6. Error Log

The Error Log view captures and logs all errors and warnings in a table generated by the application itself. Unlike Problems view the Error Log is responsible to collect and to reveal issues caused by a malfunctioned component or module of the IDE.

1.2. N4JS Specific Views

The following views are specific to N4JS. Some of these views are useful for developers of the N4JS language itself as they reveal internal details at runtime. Most of these views can be opened via Windows/Show View/Other.., see N4JS category.

1.2.1. Test Results

The N4JS equivalent to the JUnit test view.

1.2.2. Source Graphs

Shows the AST of the current source code in the editor windows.

1.2.3. API Compare

Shows compare results, i.e. the difference between an API definition project and its implementation.

1.2.4. Performance Graphs

Shows some performance measurements of typical tasks such as builds.

1.2.5. Source Mapping

Shows source maps, i.e. the relation between N4JS source code and the generated plain JavaScript code.

1.2.6. Xpect View

Shows result of an Xpext run, may be used to submit bug reports.

2. Navigation

In this chapter we describe specific views and features to allow for easy navigation.

2.1. Outline

In general, a outline view and a quick outline are supported. Both outlines work similar, which is why both are specified together. The outline of an N4JS file is a tree which should show the following structure:

  • Top-level defined classes, interfaces, roles, enums, functions and exported variables. For all these different types, icons are to be used (similar to JDT). Beside the name, type variables should be shown as well, if defined.

  • Members of classifiers are to be shown in the classifier branch. All members (fields, methods, field accessors) are to be shown, with appropriate icons indicating the type (field/member), static flag, access modifier, abstract flag. The icons should look similar to JDT.

  • an import declaration should have a node in the outline view, if multiple elements are imported these should represented as child nodes of that import declaration node. If the import uses aliases the original name and the alias name should appear in the outline node text.

  • for a non exported function declaration no outline node should be created

  • for a non exported variable declaration no outline node should be created

  • for a exported variable statement there should be a node in the outline, if this statement contains only one variable declaration the node represents this declaration. For multiple variable declarations in the statement the statement node just is a comma separated list of the variable names and for each variable there is child node

  • for fields, functions, methods, getters and variables their declared (return) type should be shown (by adding : typeName after the element name). If the type is inferred then the type name should be presented in a different color

  • for functions, methods and setters each formal parameter should be represented by its declared or inferred type (when inferred than with different color)

  • constructors are represented by the method icon and a decorator in the top right corner

  • enumeration literals are represented with the same decoration as static final fields

The top-level elements must be sortable either by order in the file (default) or alphabetically.

2.1.1. Quick Outline

The quick outline supports two modes. The modes are iteratively selected by pressing CMD/CTRL+O.

owned

This is the default mode, only members directly owned by the type are shown

inherited

In this mode, the owned members are shown including inherited, consumed, or polyfilled members. The origin is also shown and a different color is used to highlight the special status of these members. For usability reasons (limiting the number of filters), inherited, consumed and polyfilled members are treated similarly.

2.1.2. Normal Outline

In the normal outline view, toggles are used for the same purpose. Visualisations are similar to the quick outline view.

inherited

By default, only owned members of a type are shown. If the "inherited" toggle is active, inherited, consumed, or polyfilled members as well. For usability reasons (limiting the number of filters), inherited, consumed, and polyfilled members are treated similarly.

sorting

By default, all elements are sorted in the order of their appearance in the source code. If alphabetic sorting is enabled, they are sorted alphabetically.

Potential improvements:

  • show decorator when a member overrides and member from a super class / super interface or role

  • show object literals and their members in the outline view (just filter eAllContents of an element that already has a node in outline view for object literals)

  • show function expression in the outline view (just filter eAllContents of an element that already has a node in outline view for function expressions)

2.2. Navigation Commands

2.2.1. Navigate to Declaration

It is possible to Command-click on almost every reference and jump to its declaration.

2.2.2. Find by References

For each referenceable element in an open N4JS file you can click your mouse and invoke the context menu to select Find references. Then in the Eclipse search view all found references are displayed as tree: each match is structured by resource path and coarse grained element in the resource (like a method). If there are multiple matches within a method only the first match is linked but in its display string the total match count is shown in brackets.

  1. find by references shows the result as tree in the Eclipse search view with having elements that are members or have defined type displayed as nodes

  2. every found reference is displayed under its nearest parent that is a member or has a defined type

  3. if there a multiple found references in a node only the first one is displayed (and linked) + the number of all total matches is shown as part of the display string (like in JDT)

2.2.3. Open Type Declaration

One can quickly browse the workbench for available types. The declaration of the types can be opened in editor from this dialog. The N4JS type search dialog can be raised with the Cmd + Shift + T key binding (Ctrl + Shift + T on Windows and Linux systems).

  • Enter exact type name, prefix name or a camel case pattern to run a query against the types. The following rules and patterns are supported.

    • Wildcards: ? for any character and * for any string.

    • Camel case: DM will return with all types that contains D and M with the given order such as DataMap and DataMapEntry but not ImmutableDataMap.

      AcBuGr will return with all types that contain Ac, Bu and Gr with the given order such as ActionButtonGroup.

  • Highlighting: The matching types names are highlighted according to the matching parts.

  • Decorator for duplicate type names: The internally used fully qualified name of the type will be appended to the type name automatically, so one can easily distinguish between types even there are type name collision.

  • Opening types in editor: Type declarations can be opened in the editor in the following ways: after entering the type name prefix or pattern to the filter text one can navigate among the filtered items with the up and/or down arrow keys. Simply hitting return on the keyboard or clicking on the ’OK’ button the currently selected declaration of the selected type will be opened in the editor. For opening multiple type declarations one can use the Shift modifier to select more than one element. Single type can be opened with double clicking on it in the dialog.

  • History: Once a type is being opened then it will be available among the recently opened type in the type search dialog. These items will show up in the upper part of the list in the dialog.

2.3. Working Sets

Working sets are used to logically group resources, projects in the Project Explorer (navigator) and in the UI in general. Although a couple of projects can be easily handled and shown without any sophisticated working set support in the navigator, larger code sources consisting of multiple projects could cause some trouble when one has to maintain them. Indeed one could use multiple workspaces and could switch between them or can simply manually open-close relevant projects, but this gets cumbersome too.

This section describes the general design of the N4JS specific working set support and also introduces a couple of use cases while enumerating the constraints.

2.3.1. Working Set Managers

Just like the JDT (org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel) based working set support, the N4JS IDE based approach is also aware of the org.eclipse.ui.IWorkingSet and the org.eclipse.ui.IWorkingSetManager APIs but besides simply using them it comes with its own implementation and adapts it to the default Eclipse based one, furthermore it also comes with an Eclipse extension point based mechanism to support various working set managers at the same time to provide even better user experience and a more convenient way of working set management.

A working set manager can be contributed to the IDE via the org.eclipse.n4js.ui.workingSetManager extension point, then the implementation class must implement the org.eclipse.n4js.ui.workingsets.WorkingSetManager interface but it is highly recommended to rather extend the org.eclipse.n4js.ui.workingsets.WorkingSetManagerImpl class. Guice based dependency injection should also be considered when implementing the custom working set manager. It means that each custom working set manager implementation must have a public no-args constructor. This no-args constructor will be invoked when creating the instances via IConfigurationElement#createExecutableExtension(String) method. Then the members, if any will be injected by the working set manager broker. Below plugin.xml snippet describes how to contribute a custom working set manager to the IDE.

   <extension
         point="org.eclipse.n4js.ui.workingSetManager">
      <manager
            class="some.package.name.MyExecutableExtensionFactory:some.package.name.MyWorkingSetManager">
      </manager>
   </extension>

By default the N4JS IDE comes with five different built-in working set managers. These are the followings:

  • Manual Association Working Set Manager,

  • Project Name Filter Working Set Manager,

  • Git Repository Working Set Manager,

  • Project Location Working Set Manager and

  • N4JS Project Type Working Set Manager.

The benefits and the details of each built-in working set managers will be discussed in later sections but first we have to distinguish between three conceptually different working set manager approaches.

First off, IDE supports fully static working set managers. Fully static working set managers might manage any arbitrary number of working sets, and each working set might be associated with any number of Eclipse projects. That means, user might create, edit and remove working sets and manually associate projects with individual working sets. One project might belong to multiple working sets. There is a dedicated working set, Other Projects, that cannot be renamed and/or deleted. When no user defined working sets are available this dedicated working set will be still available. IDE comes with one single fully static working set manager: Manual Association Working Set Manager.

The second kind of working set manager is the semi-dynamic one. That means, user can create, modify and delete working sets, but the associations between the projects and the working sets are automatic. This means, the user might define a working set - project association rule, and the projects will be automatically associated with the working sets. Just like in the above kind, one project might belong to multiple working sets and here as well, there is a dedicated working set manager, that cannot be modified: Other Projects. IDE comes with one semi-dynamic working set manager. That is the Project Name Filter Working Set Manager. User might define a project name filter rule with a regular expression, and each project which name matches a pattern will be associated with the working set. If a project does not comply to any working set manager rule, then it will belong to the Other Projects working set.

The third kind of working set manager is the fully-dynamic working set manager. Both the working sets and the project associations are done by some implementation specific rules. Such as Git repository provider based, or project location based approaches. These working set managers have the dedicated Other Projects working set that is used as a fallback working set. For instance, if the Git Repository Working Set Manager is the active one, all projects that are shared with Git will belong to the corresponding working set manager but if a project is not yet a shared project, then it will belong to the dedicated fallback working set. As always that working set manager cannot be deleted and/or modified.

2.3.2. Working Set Constraints

This section enumerates a set of constraints that have to considered by both end users and implementors:

  • Working set manager identifier must be unique.

  • The identifier of the working set manager must be unique per container working set managers.

  • Each working set must have a working set with Other Projects unique ID and name.

  • Working sets with Other Projects unique ID must not be editable nor deletable.

  • At least one working set should be visible (not hidden) per working set managers.

  • Working set managers are activated when the Working Sets are configured as Top Level Elements in the Project Explorer.

  • Working set order can be specified and customized by the user if it is not specified yet, then a case sensitive ordering based on the working set names should be applied.

2.3.3. Manual Association Working Set Manager - UI Features

This section describes the working set manager by introducing the UI capabilities as well.

This working set manager is a fully static working set manager and activated and used as the default one when the working set manager support is turned on in the IDE. With this working set manager one can create a new working set by simply defining a unique name for the working set and associating any number of workspace project to the working set. Furthermore existing working sets can be modified and deleted but the Other Projects working set. The working set support can be turned on in the Project Explorer view. Via the view menu one has to select Top Level Elements > Working Sets menu item.

Activate_Working_Set_Managers
Figure 1. Activate Working Set Managers

After the working set manager mode activation, a new toolbar contribution item become visible and user can select among the available working set managers.

Select_Working_Set_Manager
Figure 2. Select Working Set Manager

As the below picture depicts the available working set managers are listed and the currently active manager is marked with a check. In our case that is the Manual Association Working Set Manager.

Activate_Working_Set_Manager
Figure 3. Activate Working Set Manager

Once the the Configure Manual Association…​ menu item is selected, the working set manager configuration dialog pops up. By clicking on the New…​ button in the configuration dialog, a new working set wizard will be invoked and the manual working set - project association can be configured.

Configure_Working_Sets
Figure 4. Configure Working Sets

In the wizard after specifying the desired unique name of the working set an arbitrary number of workspace projects can be associated with the working set. It is important to note, that a project can be associated with more than one working sets. If a project is not associated with any working sets then it will be automatically linked to the fallback Other Projects working set.

Configure_Working_Set_Project_Association
Figure 5. Working Set - Projects Association

Once all the changes made are confirmed and the configuration dialog is closed via the OK button, the Project Explorer will be refreshed and will reflect the working set changes.

Custom_Working_Sets_In_Project_Explorer
Figure 6. Custom Working Sets In Project Explorer

The order of the working sets can be configured and customized in the working set manager configuration dialog, or just simply reordering it from the navigator itself by drag and dropping the available working set managers.

Re_Ordering_Working_Sets_In_Project_Explorer
Figure 7. Re-ordering Working Sets In Project Explorer

Besides changing the order of the working sets, working sets can be hidden from the navigator. Just like the ordering, this can be changed from the working set configuration dialog, or by simply selecting working sets in the navigator and hiding them via Hide Selected Working Set menu item. Important to note, at least one working set should be visible in the navigator, so if all the working sets are selected in the navigator, then the menu item will be disabled. Same behavior in the working set customization dialog, if all items are unchecked, then the OK button is disabled in the dialog.

Hide_Working_Sets_In_Project_Explorer
Figure 8. Hide Working Sets In Project Explorer

Once at least one working set is hidden from the UI, then a new toolbar contribution become visible in the Project Explorer. This UI contribution provides a quick, convenient way to show a specific or all hidden working sets in the navigator. It is worth to note, if a project is automatically associated with the Other Projects working set (because it does not belong to any working sets due to the lack of manual association) it will be not shown in the navigator if the Other Projects working set is hidden. Once all working sets are visible, indeed the Show Hidden Working Sets toolbar contribution become invisible.

Show_Hidden_Working_Sets_In_Project_Explorer
Figure 9. Show Hidden Working Sets In Project Explorer

Besides the above described generic working set UI support, projects can be associated with working sets by simply drag and dropping them from one working set into another. Note, this is only supported for the Manual Association Working Set Manager.

2.3.4. Project Name Filter Working Set Manager

As mentioned earlier, this working set is a semi-dynamic working set. The working sets can be created, edited and deleted by the user by simply specifying project name filter pattern as valid regular expressions but the project association itself is fully automatic. If the name of a project does not match with any project name filter rule, then the project will be associated with the Other Projects working set. Although reordering the working sets from the navigator by simple drag and dropping them is supported, project association is disabled.

2.3.5. Git Repository Working Set Manager

This working set is a fully-dynamic working set. Projects will be associated by the Git providers. It means, if a project is imported from a pre-configured local Git repository, then the project will be associated with the working set linked with the Git repository. The subset of the available working sets is become automatically updated once the Git repository preferences changed by the user. These preferences can be changed on the Git perspective in the Git Repositories view by simple adding or hiding/removing a repository from the view.

2.3.6. Project Location Working Set Manager

This fully-dynamic working set manager calculates the subset of available working sets based on the parent folder of the projects. The benefit of this working set manager is to support the convention recommended by the maven/Git folder structuring. The following constraints are applied when associating the projects with the available working sets:

  • If a project is located in the root of the Eclipse workspace, then it will be associated with Other Projects working set.

  • If a project is nested somewhere in the Eclipse workspace, then it will be associated with a working set that has the same name as the parent folder of the project. Let assume the Eclipse workspace root points to /eclipse/root and there is a project P1 nested in the workspace root at /eclipse/root/path/to/nested/location/P1, then the associated working set will be location.

  • If a project is not contained in the workspace, but has a Git provider that is configured in IDE, and the project root is the local Git repository root, then the associated working set name will be the name of the Git repository. For example, if we have Eclipse workspace root pointing to /eclipse/root location and a P2 project located /some/path/to/git/P2 but this location is the location of a registered Git repository, then the name of the associated working set will be neither Other Projects not git but P2 since that is known Git local repository root.

  • If project P3 is not contained in the Eclipse workspace but contained in a known local Git repository just like above, but the project root is not the local Git repository root, then the name of the parent folder will be considered as the name of the associated working set. This rule is a hybrid alternative of the second and the third constraints, hence for instance if the project is under /some/path/to/git/repositoryName/plugins/P3 and repositoryName is local git repository, then the name of the associated working set will be plugins and not repositoryName.

  • Else the associated working set will be the Other Projects fallback working set.

2.3.7. N4JS Project Type Working Set Manager

This is working set manager is a N4JS specific fully-dynamic working set manager. The working sets will be calculated based on the instances defined by the org.eclipse.n4js.n4mf.ProjectType type. Each accessible N4JS project will be associated to a working set based on the project type. A workspace project will be associated with the Other Projects fallback working set if any of the followings are true to the project:

  • The project is not accessible. (It does not exist or is not opened.)

  • The project does not configured with Xtext nature.

  • The project does not have an Xtext builder command ID.

  • The project does not have a valid N4 manifest file.

3. Assistance

In this chapter we describe all kind of tools assisting the user when writing code, i.e. content assist, quickfixes, quick assists, etc.

Not all features are yet implemented!

3.1. Content Assist

Content assist may change the document at various places at once. In those cases, it is important to prevent flickering in the editor. The FQNImporter provides a blue print how to adjust line numbers properly and scroll the viewport of the current editor to minimize flickering in the UI.

Completions not listed here as they are provided by template proposals:

  1. Classifier declaration template proposal

  2. Function declaration template proposal

  3. Getter/Setter pair template proposal

3.1.1. Complete Keywords

Complete keyword which are syntactically correct at a given location. Do not suggest completions which would lead to wrong code.

Keywords that contain only a single character are not proposed since they would pollute the proposal window and don’t offer added value.

Special attention has to be given to operators. Since they are modelled in the grammar and not as cross references, their validaty is purely syntactically. That is, there is no generic facility in Xtext, that allows to filter unapplicable operators as there is for cross references.

3.1.2. Complete Annotations

Annotations can be proposed depending on the following elements or the context.

3.1.3. Complete Identifier Reference

References to identifiers can be automatically completed. This is even true if the declaration is not imported yet, as the import may be automatically added as well.

Complete identifier references

The IDE supports auto-completion of an identifier referencing to a declaration.

  1. Complete type references.

  2. Complete function references.

  3. Complete variable references.

  4. Complete parameter references.

  5. If necessary, imports are added automatically to complete reference r to declaration D.

    Precondition

    -

    Postcondition

    bindrD

    r.name=D.name
    Dr.module

    NamedImportSpecifierNIS:
    WIS.importDecl.importedModule=D.module
    WildcardImportSpecifierWIS:

    Description

    There might be multiple declarations D in project (or in dependent projects) with D.name=r.name. If the declaration D is not local, then a named import may be created by the content assist:

    1. If the declaration D is local, no import is created

    2. If an import enabling access to the declaration already exists, no other import is created.

    3. If an alias already exists, the alias name is used, even if the prefix was different when the content assist was activated.

    4. If the import would conflict with an existing member, an alias is proposed along with the import. Linked editing helps to choose a proper alias.

    5. All imports from a single module are done within a single import declaration. The exception to this rule are wildcard imports that provide a simple name which is currently unused. In that case, a new import may be necessary to disambiguate the wildcard.

  6. If the identifier reference refers to a function (or method), an opening and a closing parenthesis are appended and the cursor is positioned between these two parentheses.

3.1.4. Complete Member Overrides

Complete Member Overrides Inside a classifier

A prefix of an inherited member can be used to autocomplete that to a complete declaration. This is in particular true for methods.

3.1.5. Constructor Completion

Constructor Completion

Constructor Completion Based on the declared fields and super constructor, constructor methods can be completed.

3.1.6. Complete Function Expression with Known Type

Complete Function Expression

If a function expression is used as an argument or assigned to a typed variable, the signature of the function can be derived from the type. This can be used to complete a function expression.

3.1.7. Complete Variable and Parameter Names

Type based completion of Variable and Parameter Names

Variable and parameter names can be completed based on the type. Camel case detection is used to propose different variations.

Completion of variables references see Complete Identifier Reference.

3.2. Quick Fixes

Quick fixes try to solve issues, i.e. errors or warnings, automatically. This is done by rewriting code, either at the location of the issue or at referenced locations.

In all cases, a quick fix must only be suggested if the following preconditions are fulfilled:

  1. All locations at which modifications have to be done must be writeable.

  2. If bindings are involved, e.g., names are to be changed, all previous bindings must remain similar. This might be more complicated as it seems!

3.2.1. N4JS Issue User data

As some quick fixes need more information to decide upfront which strategy to use, some issues provide additional data. These properties are defined in the file IssueUserDataKeys.java in the org.eclipse.n4js.validation package. They can for example be accessed by passing the according key to the getUserData method of an N4JSIssue instance. They are also available as array based Xtext Issue user data.

All available user data keys are described for each Issue code in N4JS Issue Fixes.

3.2.2. N4JS Issue Fixes

The principle idea is to provide a quick fix for every issue, if it is possible to automatically solve it.

3.2.2.1. Linking Issues

Linking issues are special in that they are created by the standard Xtext linker and use all the same built-in issue code Diagnostic.LINKING_DIAGNOSTIC. Therefore, we cannot refer to these issues using one of our custom N4JS issue codes.

Diagnostic.LINKING_DIAGNOSTIC

Couldn’t resolve reference to n

  1. Add missing import declaration for unresolved name n.

Precondition
  1. An exported identifiable element e with name n exists in another module m.

  2. e is visible from the given location.

Label

Import n - m

Postcondition

An import declaration was added such that name n is now resolvable at the given location and bound to e.

Description

Some important notes:

  1. A separate quick fix is proposed for each candidate element instead of having a single generic quick fix for adding imports and showing a dialog later (for example, create two quick fixes “Import class X from module M1" and “Import interface X from module M2" instead of a single quick fix “Add import for name X").
    This is unusual for quick fixes, because it means significant work has to be done upfront when creating the quick fix / modification proposals, which raises performance concerns. However,

    1. the JDT handles this the same way and

    2. this brings the implementation closer to content assist allowing more reuse, therefore this decision was taken.

  2. For consistency, matching of lower/upper/camel case is to be handled as in code completion during content assist. The same applies to display string formatting, esp. name formatting and coloring of element e and module m.

  3. Note that here we can make more assumptions than during import as part of content assist. For example, we know that the element is not imported yet (otherwise there would not be an error) and there won’t be a need for an alias and linked editing.

3.2.2.3. Visibility Issues
VIS_ILLEGAL_MEMBER_ACCESS

The memberType member is not visible.

  1. Change access modifier to protected/public or remove @Internal annotation.

    Precondition

    The file containing the declaration of member is modifiable

    Postcondition

    The access modifier has been changed so that member is visible at issue location.

    User Data
    • ACCESS_SUGGESTION The most restrictive modifier making the member visible.

    • DECLARATION_OBJECT_URI The EObject URI of the member declaration

This table shows the access modifier changes to perform to fix the visibility issue while maintaining the strongest access restrictions possible.

Access Modifier

Accessible From

Inside Module

Inside Project

Vendor Subtypes

Vendor Projects

Other Subtypes

Everywhere

private

-

project

protected@Internal

public@Internal

protected

public

project

-

-

protected@Internal

public@Internal

protected

public

protected@Internal

-

-

-

public@Internal

protected

public

protected

-

-

-

public@Internal

-

public

public@Internal

-

-

-

-

public

public

public

-

-

-

-

-

-

Member access modifier changes for quick fixes

VIS_ILLEGAL_FUN_ACCESS

The function f is not visible.

  1. Change access modifier to protected/public or remove @Internal annotation.

    Precondition

    Postcondition

    The access modifier has been changed so that f is visible at issue location.

    User Data
    • ACCESS_SUGGESTION The most restrictive modifier making the function visible.

    • DECLARATION_OBJECT_URI The EObject URI of the function declaration

VIS_ILLEGAL_TYPE_ACCESS

The type T is not visible.

  1. Change access modifier to protected/public or remove @Internal annotation.

    Precondition

    Postcondition

    The access modifier has been changed so that T is visible at issue location.

    User Data

    see VIS_ILLEGAL_FUN_ACCESS

VIS_ILLEGAL_VARIABLE_ACCESS

The variable v is not visible.

  1. Change access modifier to protected/public or remove @Internal annotation.

    Precondition

    Module containing v is writeable.

    Postcondition

    The access modifier has been changed so that v is visible at issue location.

    User Data

    see VIS_ILLEGAL_FUN_ACCESS

For type, variable and function visibility issues the following changes have to be made to solve the visibility issue:

Table 1. Type,function and variable access modifier changes for quick fixes

Access Modifier

Accessible From

Module

Project

Vendor

World

private

-

export project

export public@Internal

export public

project

-

export project

export public@Internal

export public

export project

-

-

export public@Internal

export public

export public@Internal

-

-

-

export public

export public

-

-

-

export public

3.2.2.4. Classifier Issues
CLF_EXTEND_FINAL

Cannot extend final class C.

  1. Remove @Final annotation in class C

    Precondition

    Postcondition

    ¬C.final

CLF_OBSERVABLE_MISSING

Class e0 extends observable class e1 and must therefore be annotated with @Observable.

  1. Add @Obervable annotation in class e0

    Precondition

    Postcondition

    e0.observable

CLF_OVERRIDE_ANNOTATION

The e0 overriding e1 must be annotated with @Override.

  1. Add @Override annotation to e0

    Precondition

    Label

    Add @Override

    Postcondition

    e0.override

CLF_OVERRIDE_FINAL

The e0 cannot override final e1.

  1. Remove @Final annotation in e1

    Precondition

    Postcondition

    ¬e1.final

CLF_OVERRIDE_VISIBILITY

The e0 cannot reduce the visibility of e1.

  1. Set access modifier of e0 to access modifier of e1

    Precondition

    Postcondition

    e0.acc==e1.acc

CLF_OVERRIDE_NON_EXISTENT

The e0 e1 must override or implement a e0 from a super class, consumed role or implemented interface.

  1. Remove @Override annotation in e1

    Precondition

    Label

    Remove @Override

    Postcondition

    ¬e1.override

CLF_REDEFINED_TYPE_NOT_SAME_TYPE

Type of e0 must equal type of e1 e2.

  1. Set declared type of e0 to declared type of e2

    Precondition

    Postcondition

    τe0=e2

CLF_REDEFINED_MEMBER_TYPE_INVALID

Type of e0 does not conform to e2 e1: e3.

  1. Set declared type of e0 to declared type of e1

    Precondition

    Postcondition

    τe0=e1

CLF_REDEFINED_METHOD_TYPE_CONFLICT

Signature of e0 does not conform to e1 e2: e3.

  1. Set declared type of e0 to declared type of e2

    Precondition

    Postcondition

    τe0=e2

CLF_MISSING_IMPLEMENTATION

Class C must either be defined abstract or implement m.

  1. Declare C as abstract

    Precondition

    Postcondition

    C.abstract

CLF_ABSTRACT_BODY

Abstract methods do not specify a body. for method M

  1. Remove abstract annotation from method.

    Precondition

    Postcondition

    ¬M.abstract

CLF_ABSTRACT_MISSING

The abstract e0 e1 in class C can only be defined in an abstract class.

  1. Declare C as abstract

    Precondition

    Postcondition

    C.abstract

    Multi appliable

    false

CLF_MISSING_BODY

The e0 e1 has to have either a body or must be defined abstract.

  1. Declare e1 as abstract

    Precondition

    Postcondition

    e1.abstract

CLF_EXT_EXTERNAL_N4JSD

e0 declared as external have to be placed in a file with file extension ’n4jsd’.

  1. Remove external annotation

    Precondition

    Postcondition

    ¬e0.external

  2. Change module file extension to n4jsd

    Precondition

    Postcondition

    module file extension is n4jsd

CLF_NOT_EXPORTED_NOT_PRIVATE

A e0 with visibility e1 must be marked as exported.

  1. Export e0

    Precondition

    Postcondition

    e0 is exported

3.2.2.5. Function Issues
FUN_BLOCK

Functions declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function. with function F

  1. Change function declaration to function expression

    Precondition

    Postcondition
Variable vF.vee:v.name=Fv.expr.μ=FunctionExpressionv.expr.name=F.name,v.expr.body=F.body
Description

Change function declaration to function expression assigned to variable of the function name

3.2.2.6. Syntax Issues
AST_STR_FUN_NOT_NESTED

Functions must only be declared on script level or as part of other expressions

  1. Change function declaration to function expression assigned to variable of the function name

    Precondition

    Postcondition
Variable vF.vee:v.name=Fv.expr.μ=FunctionExpressionv.expr.name=F.name,v.expr.body=F.body
SYN_MODIFIER_BAD_ORDER

Modifiers should appear in this order: O

  1. Rearrange access modifiers

    Precondition

    Postcondition

    Modifiers are in order O

    Description

    Reorder the access modifiers to match the N4JS compliant order.

3.2.2.9. Expression Issues
EXP_WRONG_NUMBER_OF_TYPEARGS

Incorrect number of type arguments for T C: expected tpcount, got tacount.

  1. Remove superfluous arguments

    Precondition

    tacount>tpcount

    Postcondition

    tacount=tpcount

    Description
EXP_NUM_OF_ARGS_TOO_MANY

Incorrect number of arguments: expected fpcount, got argcount.

  1. Remove superfluous arguments

    Precondition

    argcount>fpcount

    Postcondition

    argcount=fpcount

    Description
EXP_CAST_UNNECESSARY

Unnecessary cast from S to T

  1. Remove cast

    Precondition

    Postcondition

    cast removed

    Description

3.4. Cleanup Operations

3.4.2. Organize Imports

Import statements can be cleaned up or automatically inserted by invoking Organize Imports. Organize Imports is available in the context menu Source / Organise imports , in menu Source > Organize imports or by hitting Cmd + Option +O (Win/Linux - Ctrl +Alt +O).

For a valid file without errors, this will result in the following actions:

  • Unused explicit imports will be removed.

  • Unused wildcard imports will be removed.

  • In each import statement the imported elements will be lexicographically sorted depending on the imported element’s name.

  • All import statements will be lexicographically sorted depending on the module specifier as major and the element name as minor key.

  • All import statements will be moved to the top of the file.

For a file with error-conditions of unresolved references, this will result in the automatic actions:

  • All ambiguous wildcard imports will be presented in one dialog, requesting the user to resolve the ambiguity.

  • Each uniquely resolvable unresolved Classifier will be added by a named import. The search scope is limited to the dependencies declared in the current project-setup.

No action will be taken, if …​

  • a classifier with name X is already imported by name from a module A and a unknown member of this classifier is marked. Even though the import of X from a different module B could remove this error, the semantic consequences could not be evaluated. The state will be left as-is.

If more then one option leads to a possible resolution the situation should be clarified using quick-fixes, e.g. if …​

  • more then one module provides an element, which would render a formerly unresolved reference to be valid.

  • for a wildcard-imported element X there are unknown members and a different module provides an element X containing the missing members. In such a case a named import of X would be proposed, optionally using an alias.

4. Wizards

Some descriptions may be outdated.
All requirement sections are not linked to real issues. They were left here as an example and to complete the issues.

4.1. N4JS Project Wizard

Wizard creates a new N4JS project.

The following information is to be specified by the user:

Project Name

string, name of project

Default Location

boolean, true by default

Location

string, computed default location, if user set location then default location flag must be false

Project Type

enumeration, the type of the new project

The following files are to be created:

Project Folder

with name of project at given location

Manifest

with default project structure and name

Source Folder

default source folder (src)

Output Folder

default source folder (src-gen)

4.2. Empty N4JS File

The following information is to be specified by the user:

Package Name

dot separated name of the package, empty by default (or set to the package/folder selected in the navigator)

Module Name

string, name of the module – must be a valid module name without extension

The following files are to be created:

Package Folder(s)

if folders representing package structure do not exist, they are to be created

Module File

empty file with name of module and extension n4js in the appropriate package folder

4.3. Empty JS File

Similar to Empty N4JS File but with the file extension js.

4.3.1. N4JS Class Wizard

It is recommended to define a single classifier in a file, the name of the classifier should have the same name as the file. Based on that assumption, file wizards are provided for N4JS classes, interfaces and enumerations.

newclasswizard

4.3.2. Field Properties

The New N4JS Class wizard offers following fields:

Project

Specifies the containing project.

Req. GH-1413a: Project constraints (ver. 1)

Constraints
  1. It is a path of a valid project in the current workspace

  2. This field must not be empty

Req. GH-1413b: Project browse button (ver. 1)

Browse Button

Browsing only allows the selection of projects in the current workspace. Project creation is not possible.

Req. GH-1413c: Project initial selection inference (ver. 1)

Initial selection

The project should be derived from the initial selection.

Req. GH-1413d: Project content assist (ver. 1)

Content Assist

Workspace projects

Source folder

Specifies the containing source folder.

Req. GH-1413e: Source folder constraints (ver. 1)

Constraints
  1. The folder is listed as source folder in the project manifest

  2. This field must not be empty.

  3. The name is a valid path that means each segment of the path matches the following expression:

    [a-zA-z_](([\\.][a-zA-z_0-9\\-])|[a-zA-z_0-9\\-])*

Req. GH-1413f: Source folder browse button (ver. 1)

Browse Button

Browsing only allows the selection of source folders in the selected project. The dialog should provide a list of all source folders of the selected project. This includes nested source folders. A list element is a relative path of a source folder in the project.

Initial selection

The source folder field should be derived from the initial selection

Req. GH-1413h: Source folder content assist (ver. 1)

Content Assist

source folders defined by the project manifest

Module specifier

Specifies the module specifier. May only specify a module container (a folder) but could also include module name. May also be an already existing module. Does not include the file extension.

Req. GH-1413i: Module specifier constraints (ver. 1)

The specifier is a valid module specifier that is - Segments are separated by the path separator - No separator at the beginning or end

Req. GH-1413j: Module specifier completion (ver. 1)

Manually inserting a specifier ending with a separator is valid. It is then interpreted as base path for the full module specifier automatically completed by the class name. (cf. grey suffix)

Req. GH-1413k: Module specifier grey suffix (ver. 1)

A grey suffix should suggest the attached class name as module name if the specifier only specifies a base path.

Req. GH-1413l: Module specifier browse button (ver. 1)

Browsing only allows the selection of modules or module containers in the selected source folder. The browse dialog has to offer a module container creation functionality. In contrast to the other parts of the wizard, the creation of module containers in this dialog should be immediate and on file system level. This is important to comply with the conceptual model of eclipse and the operating system.

When inserting a non-existent path in the text input and opening the browse dialog, an additional dialog should ask the user whether he wants to create this structure on the file system. If he denies, the dialog shows the selection to the level it already exists on the file system.

The module specifier should be derived from the initial selection by using the container of the selection as initial module container

Req. GH-1413n: Module specifier content assist (ver. 1)

Modules in the selected source folder

For now the spec doesn’t specify any constraints for module specifiers

Class name

Specifies the class name.

Req. GH-1413o: Class name basic constraints (ver. 1)

Constraints
  1. The name is a valid n4js class identifier Must not be empty

  2. If the target module already exists no other type with the same identifier may exist in this module

Req. GH-1413p: Class name conflict validation (ver. 1)

If the target module already exists no other type with the same identifier may exist in this module

Req. GH-1413q: File type options (ver. 1)

Definition file (.n4jsd)

Specifies whether the class should be declared external. This option changes the file extension to n4jsd

Req. GH-1413r: Access modifier constraints (ver. 1)

Specifies the access modifiers of the class. One of public, project, private. @Internal is an additionally selectable option.

Constraints
  1. One of the provided access modifiers has to be selected

  2. The @Internal option is only selectable in case of public or project

Other modifiers

Specifies other modifiers and annotations of the class. The non-exclusive options are @Final and @N4JS

Req. GH-1413s: Other modifiers constraints (ver. 1)

Constraints
  1. @N4JS annotation is only enabled and selectable if the Definition File box is checked

Super class

Specifies the super class

Req. GH-1413t: Super class constraints (ver. 1)

Constraints
  1. A valid absolute class specifier that is a module specifier and a class name separated by a dot.

Req. GH-1413u: Super class browse button (ver. 1)

Browse Button

Browsing allows the selection of all classes in the current workspace with modifiable source and visible classes with unmodifiable sources.

Req. GH-1413v: Super class content assist (ver. 1)

Content Assist

All classes matching mentioned criteria

Interfaces

Specifies the implemented interfaces of the class

Req. GH-1413w: Interfaces constraints (ver. 1)

  1. A valid absolute interface specifier that is a module specifier and an interface name separated by a dot.

Req. GH-1413x: Interfaces browsing (ver. 1)

Add Button

Browsing allows the selection of all interfaces in the current workspace with modifiable source and visible interfaces with unmodifiable sources.

Remove Button

Removes the selected interface from the list. Disabled if nothing is selected.

Req. GH-1413y: Interfaces content assist (ver. 1)

Text input is available by clicking in empty space at the end of the list. Content Assist provides all interfaces matching mentioned criteria.

Req. GH-1413z1: Create method stubs (ver. 1)

Specifies if the wizard should generate method stubs for all abstract methods of the newly generated class. That are abstract super class methods or methods that need to be implemented by the class to conform to the selected interfaces.

Req. GH-1413z2: Create method stub conflict detection (ver. 1)

If the selected interfaces are impossible to implement (e.g. method name overlap with unrelated parameter types) this option needs to be disabled and a warning needs to be shown.

Shouldn’t this be a constraint of the selected interfaces? (Never generate invalid code)

4.3.3. Visibility issues or @Final super classes

Req. GH-1413z3: Visibility issue conflict solving (ver. 1)

By allowing the user to select invisible interfaces and super classes or unextendable @Final-annotated super classes, accessability issues may come up. The goal is to never generate a file containing invalid code. To accomplish this, conflicts must get solved before the file is generated.

The slight limitation of the selection of interfaces and classes to elements from modifiable sources (cf. super class browse button) allows to solve all possibly occurring visibility issues.

If the modifications by finishing the wizard do imply changes different from insertions and creations, a compare view is to be shown, giving the user an overview of the needed changes before they’re applied.

4.3.4. Generation

Req. GH-1413z4: Wizard generation (ver. 1)

The following changes are to be made by the wizard:

  1. Create a new file containing the new class (optional)

  2. Insert the new class into the specified module

  3. Change the source module of the super class to fix possible visibility issues (optional)

  4. Change the source module of the interfaces to fix possible visibility issues (optional)

  5. Change the project manifest to add a new source folder (optional) or add new project dependencies (optional)

4.3.5. Preview

Req. GH-1413z5: Generation preview (ver. 1)

On the right of the wizard form a preview window should be provided. It should preview the full path of the generated file and all code that is generated with the options of the wizard. Changes should be updated in realtime as the user is choosing different options.

4.4. Interface Wizard

The N4JS interface wizards is strongly similar to the N4JS Class Wizard. The following paragraph is meant to state the differences and will strongly refer to the N4JS Class Wizard as a lot of properties stay the same.

newinterfacewizard

4.4.1. Field Properties

Project

Specifies the containing project. See N4JS Class Wizard Project.

Source Folder

Specifies the containing source folder.
See N4JS Class Wizard Source Folder

Module Specifier

Specifies the containing source folder.
See N4JS Class Wizard Module specifier

Interface name

Specifies the name of the interface

Constraints
  1. The name is a valid n4js interface identifier

  2. Must not be empty

  3. If the target module already exists, no other type with the same identifier may exist in this module

Definition file (.n4jsd)

Specifies whether the interface should be declared external. This option changes the file extension to n4jsd .

Access Modifiers

Specifies the interface’s access modifiers

See N4JS Class Wizard Modifier Field except for the following point:

Other than classes, interfaces must not be declared as @Final, therefore this option is removed.

Interfaces

The interfaces the interface is implementing

See N4JS Class Wizard Interfaces field except for the following point:

Other than classes interfaces must not be declared as @Final, therefore this option is removed.

Create method stubs

Specifies if the wizard should generate method stubs for all abstract methods of the newly generated class. That are abstract super interface methods or methods that need to be implemented by the interface to conform to the given interfaces.

If the selected interfaces are impossible to implement (e.g. method name overlap with unrelated parameter types) this option needs to be disabled and a warning needs to be shown.

Shouldn’t this be a constraint of the selected interfaces? (Never generate invalid code)

4.4.2. Visibility Issues

As the user might select invisible interfaces, the wizard has to solve these visibility issues. See ** for details.

4.4.3. Import naming conflicts

As the user may select identically named interfaces, the wizard has to solve these naming conflicts. See Class Wizard Visibility Issues for details.

4.4.4. Generation

  1. Create a new file at the given module specifier location (optional)

  2. Insert the new interface into the specified module

  3. Change the source module of the super class to fix visibility issues (optional)

  4. Change the source module of the interfaces to fix possible visibility issues (optional)

  5. Change the project manifest to add a possibly new source folder (optional) or add new project dependencies (optional)

4.4.5. Preview

The Interface Wizard should provided a preview. (See Wizard Preview)

4.5. Enum Wizard

The N4JS Enum File wizards provides the user a wizard to create enums. When speaking of enums in this context ordinary enums as specified in the N4JS Specification are meant.

4.5.1. Field Properties

Project

Specifies the containing project.
See N4JS Class Wizard Project

Source Folder

Specifies the containing source folder.
See N4JS Class Wizard Source Folder

Module Specifier

Specifies the containing source folder. See N4JS Class Wizard Module specifier

Enum name

Specifies the name of the interface

Constraints
  1. The name is a valid n4js enum identifier

  2. Must not be empty

  3. If the target module already exists, no other type with the same identifier may exist in this module

Modifiers

Specifies the interface’s access modifiers + Allows the user to select from following modifier options: public,project,private. The wizard automatically adds missing export if needed. + Furthermore the enum can be declared @Internal using a checkbox.

Should the enum wizard also provide functionality to create enum literals?

4.5.2. Generation

The following changes are to be made by the wizard:

  1. Create a new file containing the new enum (optional, only if module doesn’t exists yet )

  2. Insert the new enum into the specified module

4.5.3. Preview

The Enum Wizard should provided a preview. (See Wizard Preview)

5. Execution Support

Parts of this document may be outdated.

5.2. UI Execution

The N4JS IDE supports launching a file via a so called "runner". That is, a selected file is started as main file with Node.js or Chrome, depending on the available runners.

Chrome support not available yet.

For testing, a file, package, or even a whole project can be executed with a "tester". In that case, instead of directly executing the selected resource with Node.js (or other runners), the "mangelhaft" framework is used to run the selected resource or all its content as tests. For test support in general, see next chapter.

Running or testing a resource is done via a launch configuration. This can be configured.

The node.js runner/tester allows for configuration of

  • the NODE_MODULE path. This can be adjusted if the automatically path is not suited.

  • other environment variables (simply as key=value pairs per line)

  • node.js options to be passed as arguments to node.js

  • the system loader to be used, this is "System.js" by default

Since in the JavaScript world these configurations are often used, it is cumbersome, particularly for tests, to define them for every single file. Thus the N4JS IDE copies the node.js settings found in a project launch configuration to a resource specific launch configuration.

6. Test Support

N4IDE provides tests support by allowing different TestRunners to extend it with test specific functionality. This allows to support specialized and very different from each other test requirements (e.g. nodejs based tests, browser based interactive ui tests, server integration tests).

cd testsupport
Figure 10. Test Support Diagram

Explanation of the main components:

User Project
  • a project with production code (e.g. src folder), and test code (e.g. test folder)

  • test code may contain special language features contributed by Test Library

N4IDE
  • manage user project, including all test related parts (e.g. support test related code, validate some test code constraints)

  • host runner, allow its UI contributions

Test Runner
  • contribute to N4IDE necessary elements (test results view, user test selection, test start/stop actions)

  • use N4IDE mechanisms to access user project test fragment (e.g. discover tests)

  • configure Test Execution Environment

  • manage test runtime (e.g. start/stop execution environment)

Test Execution Environment
  • hosts (directly or indirectly) js engine in which tests are executed

  • executes test library logic

  • is responsible for some tests execution aspects (e.g. test isolation)

  • deals with some execution errors (e.g. no callback from async test, infinite loop in test)

Test Library
  • provides test api that user can use in his project

  • coordinates scheduling and test code execution (e.g. order of tests, execution of setups / teardowns)

  • creates test results

Below picture and listings depicts the components of the Test Runner in the IDE:

test runner components
Figure 11. Test Runner Components
Test Delegate
  • After the test discovery it starts and stops the test session via the Test Facade.

Test Facade
  • Ensures that an embedded HTTP server is running to receive messages from the Test Execution Environment. Registers a test session into the IDE side via the Test Finite State Machine Registry and triggers the actual test running at Test Execution Environment.

HTTP Server
  • HTTP server is listening for HTTP requests from the Test Execution Environment via its RESTful API.

Resource Router Servlet
  • This servlet is deployed into the servlet container of the HTTP Server. The servlet percepts the HTTP requests from the Test Execution Environment and delegates the request body to the corresponding REST Endpoint Logic.

REST Endpoint Logic
  • Parses the HTTP request bodies, creates special events and sends them to all subscribers via the Test Event Bus.

Test Event Bus
  • This component is used to asynchronously deliver messages between the main test runner components in a decoupled fashion.

Test Finite State Machine Registry
  • This registry is used to cache test sessions represented as test trees and Test Finite State Machines. Percepts all messages initially sent by the Test Execution Environment and delegates them to the corresponding subscribers.

Test Finite State Machine
  • Ensures the lifecycle of a test session. Handles timeouts duo to possible communication errors between the HTTP server and the Test Execution Environment.

Test Tree Registry
  • Registry to handle the state of a test session. Responsible for updating a test tree associated with a test session with the received test results.

Test UI
  • This UI component provides feedback about the running test session to the end-user.

6.1. N4JS Mangelhaft support

xUnitSupportDesign
Figure 12. xUnit Support Design

In this section and subsections we specify N4IDE support for testing with Mangelhaft.

Mangelhaft is N4JS Test Library. It is focused more on a xUnit tests than other forms of testing (BDD, Acceptance Testing, Functional UI Testing).

The following test scenarios are supported on different Test Execution Environments:

Table 2. Test Scenarios
Test Node Browser Wrapper

Plain

yes

yes

DOM

-

yes

-

non-interactive UI

-

interactive UI (iUI)

(non UI) Server

iUI Server

-

6.1.1. Asynchronous Tests, Test Isolation and Timeouts

A special problem about JavaScript tests is to control asynchronous tests and non-terminating tests.

Performance and test isolation are conflicting goals: a perfect isolation would mean to run every tests by a separate JavaScript engine, which is not performant. For that reason, all tests are run by the same JS-engine in general. A test has to notify the test runner when it has been finished (successfully or with failure). If it does not finish in a defined time (timeout), Test Execution Environment or Manglehaft needs to handle that (e.g. restart node vm in which code is executed)…​

Main concerns with running test in parallel on js side are:

  1. Timeouts Mangelhaft is supposed to track test timeout. If tests are running in fake parallel mode achieved by cooperative multitasking, then one test running eats up time for other test. This can cause tests to timeout when running in parallel, while succeed when running in sequential mode.

  2. Mutability on client. Tests running in parallel can affect each other by mutating global state in which they operate. When they run in sequential mode this can happen too, but it is much less likely to.

  3. Mutable state on the server. Tests running on the same session/login are prone to affecting each other through server interaction (and or mutating data on the server).

6.1.2. Supported xUnit API

xUnit API is user facing API for defining tests. It allows test developer to define tests and configure some test execution aspects. N4IDE (via Test Runner extension) supports defined API by :

  • gathering information via AST analysis and reflection

  • presenting user available actions, based on gathered information

  • gathering user input and configurations for test execution

  • generating proper data for test infrastructure, based on user actions

6.1.2.1. Test Group

A test group is a logical collection of tests. It is created by grouping N4ClassDeclarations that contain test methods or test methods directly (see Test Method). Those classes or individual methods can be assigned to a Group by annotating them with @Group annotation. This annotation takes non empty list of strings as parameter. Passed strings are used as category name (which is like its id).

Annotation:
    '@Group'
    (' $group+=$STRING ')?
    AnnotatedElement
;

AnnnotatedElement:
    N4JSClassDeclaration | N4JSMethodDeclaration
;

@Group properties

  • name → Group

  • targets → N4Method, N4Class

  • retention policy → RUNTIME

  • transitive → YES

  • repeatable → YES

  • arguments → Strings

  • arguments are optional → NO

6.1.2.2. Test Method

Test Method marks procedure that has to be executed by Test Library.

Annotation:
    '@Test'
    AnnotatedElement
;

AnnnotatedElement:
    N4JSMethodDeclaration
;

@Test properties

  • name → Test

  • targets → N4Method

  • retention policy → RUNTIME

  • transitive → NO

  • repeatable → NO

  • arguments → none

Additional TestMethod constraints:

Test Method

  • allowed only N4ClassDeclarations in project test fragment

  • method must be public

  • method takes no parameters

  • method return type is Promise?

  • method must not be referenced by other owning class members or other classes (also no @override)

6.1.2.3. BeforeAll Setup

@BeforeAll marks method that will be executed once before all tests in a given test class will be executed.

Annotation:
    '@BeforeAll'
    AnnotatedElement
;

AnnnotatedElement:
    N4JSMethodDeclaration
;

@BeforeAll properties

  • name → BeforeAll

  • targets → N4Method

  • retention policy → RUNTIME

  • transitive → NO

  • repeatable → NO

  • arguments → none

The same constraints apply as for the test method, see Test Method Constraints.

6.1.2.4. Before Setup

@Before marks method that will be executed once before each tests in a given test class will be executed.

Annotation:
    '@Before'
    AnnotatedElement
;

AnnnotatedElement:
    N4JSMethodDeclaration
;

@Before properties

  • name → Before

  • targets → N4Method

  • retention policy → RUNTIME

  • transitive → NO

  • repeatable → NO

  • arguments → none

The same constraints apply as for the test method, see Test Method Constraints.

6.1.2.5. After Teardown

@After marks method that will be executed once after each tests in a given test class will be executed.

Annotation:
    '@After'
    AnnotatedElement
;

AnnnotatedElement:
    N4JSMethodDeclaration
;

@After properties

  • name → After

  • targets → N4Method

  • retention policy → RUNTIME

  • transitive → NO

  • repeatable → NO

  • arguments → none

The same constraints apply as for the test method, see Test Method Constraints.

6.1.2.6. AfterAll Teardown

@AfterAll marks method that will be executed once after all tests in a given test class will be executed.

Annotation:
    '@After'
    AnnotatedElement
;

AnnnotatedElement:
    N4JSMethodDeclaration
;
  • allowed only in class marked with @TestClass

  • method must be public

  • method takes no parameters

  • method return type is void

  • method must not be referenced by other owning class members

@AfterAll properties

  • name → AfterAll

  • targets → N4Method

  • retention policy → RUNTIME

  • transitive → NO

  • repeatable → NO

  • arguments → none

The same constraints apply as for the test method, see Test Method Constraints.

6.1.2.7. Test Ignore
name

@Ignore

targets

N4Method, N4Class

retention policy

RUNTIME

transitive

YES

repeatable

NO

arguments

String reason

arguments are optional

→ Yes

Test Ignore allows to mark tests that should be skipped during the test execution. That is the preferred way to temporarily disable tests without removing them (or commenting them out). Test developers may provide reason for skipping to make reason/intentions clearer.

This annotation is transitive, which means that: Test Method is considered as marked with Test Skip

  • explicitly when it is directly marked or

  • implicitly, when container of a Test Method is marked.

If a class is marked as @Ignore, then all its contained test methods will be ignored.
When @Ignore occurs at class level in a test class hierarchy chain, then the following rules are applied. Assume the following test classes:

export public class A {

    @Test
    public aTest(): void {
        console.log('A#aTest');
    }

}
import { A } from "A"

@Ignore('Class B is ignored.')
export public class B extends A {

    @Test
    public b1Test(): void {
        console.log('B#b1Test');
    }

    @Ignore("Method B#b2Test is ignored.")
    @Test
    public b2Test(): void {
        console.log("B#b2Test");
    }

}
import { B } from "B"

export public class C extends B {

    @Test
    public cTest(): void {
        console.log('C#cTest');
    }

}
  • When module A is being tested, then it is obvious that all the test methods of A will be tested. No methods will be skipped at all.

  • When module B is being tested, then although the inherited members of class A will be included in the test tree, all methods, including the inherited ones (from class A from module A) will be skipped. Nothing will be tested.

  • When module C is being tested, then all inherited members from class B and class A will be collected an included in the test tree. The @Ignore annotation declared at class level at B will be ignored but the @Ignore at method level in class B will be considered. In a nutshell, the following methods will be executed:

    • A#aTest

    • B#b1Test

    • C#cTest

The above described behavior is identical to the behavior of JUnit 4 with respect to the @Ignore annotation handling in case of test class inheritance.

6.1.2.8. Timeout

Timeout allows test developer to set custom timeout when executing given test code. This can be used to set timeout for both Test Methods or Test Fixtures

Annotation:
    '@Timeout'
    ($timoeout+=$INT)?
    AnnotatedElement
;

AnnnotatedElement:
    N4JSClassDeclaration | N4JSMethodDeclaration
;

@Timeout properties

  • name → Timeout

  • targets → N4Method, N4Class

  • retention policy → RUNTIME

  • transitive → YES

  • repeatable → NO

  • arguments → Number

  • arguments are optional → NO

6.1.2.9. Description

Description allows test developer provide string describing given test or test class that can be used in IDE test view or in the test report.

Annotation:
    '@Description'
    ($desc+=$STRING)?
    AnnotatedElement
;

AnnnotatedElement:
    N4JSClassDeclaration | N4JSMethodDeclaration
;

@Description properties

  • name → Description

  • targets → N4Method, N4Class

  • retention policy → RUNTIME

  • transitive → YES

  • arguments → String

  • arguments are optional → NO

6.2. Test Reporting

Test Runtime Environment communicates with Test Runner over HTTP. Defined communication is based on protocol used between lupenrein and old ide. It is used to send the information about test execution progress from the Test Runtime to Test Runner. Information send by this protocol is not equivalent to test results. Test Runner interprets progress it receives and based on gathered information it generates test results. Under specific conditions Test Runner may change reported test status PASS to test result FAILED and put this information to the test report e.g. when timeout happens (see note on timeouts below).

sm TestListener
Figure 13. TestListener

Test Listener shows Communication flow expected by the Test Runner. When the Test Runner is started first it waits for Start Session message. Next Test Tree message is expected. This describes list of all tests that are expected to be executed. For all tests in the list Test Runner expects Test Start and Test End message to be received. End Session is expected to be last message in the test session. Ping message can be send multiple times in between other messages to manage synchronization issues between Test Runner and Test Runtime (see below).

Since all communication is asynchronous, IDE Test Runner must assume some timeout values that will define standard wait time during communication:

  • Initial 90s timeout to wait for the Start Session message. It may be fixed or adjusted to given environment (local/remote) and project (library/application).

  • Default timeout between all other test messages is 10 seconds. Test Runtime may notify IDE Test Runner that it should wait longer with Ping test message. This is one time thing, as soon as another command is received the default timeout will have to be reused again.

Do to the asynchronous nature of the tests, status updates can be given out of order by the Test Runtime Environment. The only sure thing is that all tests begin with SessionStart and ends with a SessionEnd. Furthermore a TestStart will be send before the TestEnd for a particular test.

6.2.1. Test Messages

IDE Test Runner will be waiting for specific messages from Test Runtime. We assume that communication will be done over HTTP protocol. Test Execution Environement should be configured by the Test Runner in a way that Test Runtime knows address where it has to send messages (see Test Runtime Configuration). Test Runner exposes RESTful API allowing him to receive messages. Below we define parts of that api that enable specific messages to be communicated.

When defining Test Messages we assume following model of tests:

TestTree {
    ID sessionId,
    Array<TestSuite>? testSuites
}

TestSuite {
    string name,
    Array<TestCase>? testCases,
    Array<TestSuite>? children
}

TestCase {
    ID id,
    string className,
    string origin,
    string name,
    string displayName,
    TestResult? result
}

TestResult {
    TestStatus teststatus,
    number elapsed,
    string? expected,
    string? actual,
    string? message,
    array<string>? trace
}

enum TestStatus {
    PASSED, SKIPPED, FAILED, ERROR
}

ID {
    string value
}
6.2.1.1. Test Case IDs

The ID of a test case in the following specifications is referred to as testID. This ID is of the following structure:

testID: fqn '#' methodName

When used as part of the URL the testID is percent-escaped as defined in RFC3986 Section 2.1. This is necessarry to circumvent the fact that the N4JS FQN delimiter / is a reserved character in URLs and cannot be used in its original form.

6.2.1.2. Start Session

Signals start of the test session. When user triggers test execution, configures IDETestRunnerCtrl, afterwards IDE Listener waits for this message from TestRunner.

StartSession :
    uri : /n4js/testing/sessions/{sessionID}/start
    method : POST
    contentType : application/vnd.n4js.start_session_req.tm+json
    accept: application/json
    responses:
        200:
        400:

Start session request object MIME type application/vnd.n4js.start_session_req.tm+json:

{
    map<string, string>? properties
}
6.2.1.3. Ping Session

Signals that test runner is still busy doing things, and will report later to the listener.

PingSession :
    uri : /n4js/testing/sessions/{sessionID}/ping
    method : POST
    contentType : application/vnd.n4js.ping_session_req.tm+json
    accept: application/json
    responses:
        200:
        400:

Ping session request object MIME type application/vnd.n4js.ping_session_req.tm+json:

{
    number timeout,
    string? comment
}
6.2.1.4. End Session

Signals end of test session Notifies IDE Listener that session is finished and no further related TestMessages are expected. IDE, can stop listening and proceed with its own tasks (e.g. create summary test report ).

EndSession :
    uri : /n4js/testing/sessions/{sessionID}/end
    method : POST
    responses:
        200:
        400:
6.2.1.5. Start Test

Signals that a test run has started. Updates the state of the test reported with the tree .

StartTest :
    uri : /n4js/testing/sessions/{sessionID}/tests/{testID}/start
    method : POST
    contentType : application/vnd.n4js.start_test_req.tm+json
    accept: application/json
    responses:
        200:
            contentType : application/vnd.n4js.start_test_res.tm+json
        400:

Start test request object MIME type application/vnd.n4js.start_test_req.tm+json:

{
    number timeout,
    map<string, string>? properties
}

Start test response object MIME type application/vnd.n4js.start_test_res.tm+json:

{
    links : [
        {
            rel: "ping test",
            uri: "/n4js/testing/sessions/{sessionID}/tests/{testID}/ping"
        },
        {
            rel: "end test",
            uri: "/n4js/testing/sessions/{sessionID}/tests/{testID}/end"
        }
    ]
}
6.2.1.6. End Test

Signals that a test run has ended. Updates the state of the test reported with the tree .

EndTest :
    uri : /n4js/testing/sessions/{sessionID}/tests/{testID}/end
    method : POST
    contentType : application/vnd.n4js.end_test_req.tm+json
    accept: application/json
    responses:
        200:
        400:

End test request object MIME type application/vnd.n4js.end_test_req.tm+json:

{
    TestResult result
}
6.2.1.7. Ping Test

Notifies IDE that TestRunner is doing something (e.g. test setup/teardown code, long running test). Without this notification IDE might interpret long pause in received messages as timeout, TestRunner crash or other issues (in consequence it might terminate whole test execution environment).

PingTest :
    uri : /n4js/testing/sessions/{sessionID}/tests/{testID}/ping
    method : POST
    contentType : application/vnd.n4js.ping_test_req.tm+json
    accept: application/json
    responses:
        200:
        400:

Ping test request object MIME type application/vnd.n4js.ping_test_req.tm+json:

{
    number timeout,
    string? comment
}
6.2.1.8. Test Catalog

Assembles and returns with the test catalog representing all the tests available in the underlying IN4JSCore specific workspace. The content of the test catalog is calculated dynamically. The test catalog calculation depends on the current built state of the workspace. If the workspace was cleaned and not built yet, then a test catalog containing zero test suites (and test cases) will be provided as a response. If the workspace is built and in consistent state, then a catalog containing all test cases will be sent as the response body. The provided test catalog format complies to the Mangelhaft reporters.

TestCatalog :
    uri : /n4js/testing/sessions/testcatalog
    method : GET
    contentType : application/vnd.n4js.assemble_test_catalog_req.tm+json
    accept: application/json
    responses:
        200:
        400:

Below listings represents an example of the test catalog format:

{
  "endpoint": "http://localhost:9415",
  "sessionId": "fc3a425c-b675-47d7-8602-8877111cf909",
  "testDescriptors": [
    {
      "origin": "SysProjectA-0.0.1",
      "fqn": "T/T",
      "testMethods": [
        "t"
      ]
    },
    {
      "origin": "TestProjectA-0.0.1",
      "fqn": "A/A",
      "testMethods": [
        "a"
      ]
    },
    {
      "origin": "TestProjectA-0.0.1",
      "fqn": "B/B",
      "testMethods": [
        "b1",
        "b2"
      ]
    },
    {
      "origin": "TestProjectB-0.0.1",
      "fqn": "CSub1/CSub1",
      "testMethods": [
        "c1",
        "c2"
      ]
    },
    {
      "origin": "TestProjectB-0.0.1",
      "fqn": "CSub2/CSub2",
      "testMethods": [
        "c1",
        "c2",
        "c3"
      ]
    }
  ]
}
6.2.1.9. Test Session Example

Below example demonstrates what are the expected HTTP requests and JSON structures for a simple test group.

class A {

    @Test
    public void foo() {}

    @Test
    @Ignore
    public void bar() {}
}

class B {

    @Test
    public void baz() {}
}

class C {

    @Test
    public void qux() {}
}
Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/start/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.start_session_req.tm+json; charset=ISO-8859-1
Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FC%23qux/start/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.start_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 1000
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FB%23baz/start/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.start_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 1000
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FA%23bar/start/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.start_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 1000
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FA%23foo/start/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.start_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 1000
}
Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FA%23bar/ping
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.ping_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 1000
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FC%23qux/ping/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.ping_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "timeout": 2000
}
Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FB%23baz/end/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.end_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "message": "Some optional message.",
        "trace": [
        "trace_element_1",
        "trace_element_2",
        "trace_element_3"
    ],
    "expected": "1",
    "testStatus": "FAILED",
    "elapsedTime": 100,
    "actual": "2"
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FC%23qux/end/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.end_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "message": "Some failure message.",
        "trace": [
        "trace_element_1",
        "trace_element_2",
        "trace_element_3"
    ],
    "expected": "4",
    "testStatus": "FAILED",
    "elapsedTime": 50,
    "actual": "3"
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2F%23foo/end/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.end_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "expected": "2",
    "testStatus": "PASSED",
    "elapsedTime": 60,
    "actual": "power of 2 for 2"
}


Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/tests/Test%2FA%23bar/end/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.end_test_req.tm+json; charset=ISO-8859-1
Body:
{
    "testStatus": "SKIPPED",
    "elapsedTime": 0,
}
Request method: POST
Request path:   http://localhost:9415/n4js/testing/sessions/19f47a37-c1d1-4cb7-a514-1e131f26ab13/end/
Headers:        Accept=*/*
                Content-Type=application/vnd.n4js.end_session_req.tm+json; charset=ISO-8859-1

6.2.2. Test Runtime Configuration

Test Runner must gather relevant information and send it to Test Environment to allow proper test execution:

  • gathering user input and test options

  • gathering information about user project test code

  • maintaining proper name mappings (e.g. if project is minimized test names/references must be mapped correctly)

6.2.3. Test Plan

Test Runner uses N4IDE infrastructure to obtain information about test fragment of the user project. Based on that information and user input in UI (e.g. triggering test execution on whole project) IDE can determine Test Methods that should be executed. Such test list or Test Plan is send to Test Environment and is expected to be executed by a Test Library.

TestPlan {
    Array<TestProcedure> procedures
}

TestProcedure {
    string functionName,
    string functionType,
    string functionContainer,
    string containerModule
}

6.2.4. Test Environment Configuration

Additionally Test Runner sends to Test Environment other configuration options:

  • Test Runner test communication protocol base url (baseURL)

6.2.5. Test Environment Configuration Example

For example assuming that user selects ProjectX to test that contains only one test class in src/test/n4js/core path like:

class MyTestClass{

    @BeforeAll
    public void someOneTimeSetup(){ /* setup code */}

    @Test
    public void testA(){ /* some test code*/ }
    @Test
    public void testB(){ /* some test code*/ }
    @Test
    public void testC(){ /* some test code*/ }

    @After
    public void afterCleanup(){ /* setup code */}

}

Configuration sent for Test Execution Environment would look like:

{
    "baseURL" : "http://localhost:1234/",
    "testPlan":
        [
          {
            "functionName": "someOneTimeSetup",
            "functionType": "@BeforeAll",
            "functionContainer": "MyTestClass",
            "containerModule": "test/n4js/core/MyTestClass",
          },
          {
            "functionName": "testA",
            "functionType": "@Test",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          },
          {
            "functionName": "afterCleanup",
            "functionType": "@After",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          },
          {
            "functionName": "testB",
            "functionType": "@Test",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          },
          {
            "functionName": "afterCleanup",
            "functionType": "@After",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          },
          {
            "functionName": "testC",
            "functionType": "@Test",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          },
          {
            "functionName": "afterCleanup",
            "functionType": "@After",
            "functionContainer": "MyTestClassA",
            "containerModule": "test/n4js/core/MyTestClassA",
          }
        ]
}

7. Help System

7.5. Hovering

Hovering over an element (such as type, field, method, function or variable declaration) in the N4JS editor will cause a tooltip appear containing information about the underlying element. Currently this information is the type (could be the inferred type as well), the name and the keyword (such as class, variable, field) of the actual element. By default the tooltip does not grab the focus from the currently active workbench window and will automatically disappear after the focus is lost from the element. One can grab the focus for the tooltip by clicking into the tooltip area or pressing F2 function key.

7.5.1. Show Type Information of Selection

In some cases, during the development process, one would like to know what is the actual or even the inferred type of an N4JS expression. To use this functionality one can select the desired expression in the editor and invoke the ’Show Type Information’ command via the Cmd + Option+ I ( Ctrl + Alt+ I Windows/Linux) from the keyboard. This case a popup window will be raised containing the type information of the actual selection.

8. Bug Management

Parts of this document may be outdated.

8.1. Built-In Xpect Support

N4IDE contains built-in support for xpect based tests. The purpose of those is to create tests for N4IDE support for user code, not the user code itself. Users can create fileName.n4js.xt to write their test for a given N4IDE functionality. Those files can be executed (via context menu, run configurations, etc.) to verify user expectations.

8.1.1. Report View

When executing xpect tests, users can view the results in a special view available in the IDE: WindowShow ViewOtherTest ViewsXpect View.

testView
Figure 14. Test View

This view allows user to generate bug report (see Generating Bug Reports).

In case of failing tests, users can see additional information (e.g. a stacktrace), or call a comparison view.

comparison
Figure 15. Comparison

8.1.2. Generate Bug Report

Generating bug reports can be done when there is some .n4js.xt file with all passing expectations, and at least one of them marked with FIXME. In this case icon of the executed test suite changes and via context menu user can call generate bug report option. When it is done, user can see contents of the bug generated in the console view. This output is prepared for out JIRA ticketing system.

bugReport
Figure 16. Bug Report

There is also possibility to generate bug report via file selection and context menu. In this case xpect test is not executed, only bug contents are generated.

bug
Figure 17. Submited Bug

8.1.3. Supported Xpect Tests

Xpect methods are special form of comments inside .xt files. General syntax for declaring usage of such method is XPECT marker followed by XpectMethodName and parameters for that method, all placed in comment. This can have three forms:

  • Single line comment (see the first comment in the listing below), Notice separating the method name and its parameters.

  • Multi line comment with one method invocation, notice - separating the method name and its parameters

  • Multi line comment with multiple method invocations, simmilar to one above, but each line of method parameters indicates separate method invocation

    //XPECT errors --> "Couldn't resolve reference to IdentifiableElement 'consoleX'." at "consoleX"
    consoleX.log(10);
    
    /*XPECT errors ---
     "Couldn't resolve reference to IdentifiableElement 'logY'." at "logY"
    ---*/
    console.logY(10);
    
    /*XPECT errors ---
     "Couldn't resolve reference to IdentifiableElement 'log'." at "log"
     "Couldn't resolve reference to IdentifiableElement 'ref'." at "ref"
     --- */
    log(ref);
8.1.3.1. Errors, Warnings, Infos, Issues

Errors, Warnings, Infos are xpect methods that allow to capture marker of given severity. Additionally Issues allows to allow markers of all above severities.

All of those methods can be used single invocations or as mutline invocations.

//XPECT errors --> "Couldn't resolve reference to IdentifiableElement 'x'." at "x"
console.log(x)

//XPECT warnings --> "Variable names should start with lower case letter." at "String"
var String = "some string"
8.1.3.2. Noerrors

No errors allows to catch (and suppress) marker of any severity (error, warning, info).

//XPECT noerrors --> "window object should be recognized"
console.log(window)
8.1.3.3. Output, OutputRegex

Output methods are special in sense that they are not intended to be used on single element of the script, but they apply to the whole script.

/* XPECT output ---
<==
stdout:
hello world
stderr:
==>
--- */
console.log("hello world")

Second method accepts regex expressions. This allows to deal with troublesome output (e.g. dates)

/* XPECT outputRegex ---
<==
stdout:
[^\n]*
stderr:
==>
--- */
console.log(new Date())
/* XPECT outputRegex ---
<==
stdout:
hello world
stderr:

[^\n]+
throw ' cruel world'
\^
 cruel world
==>
--- */
console.log("hello world")
throw ' cruel world'
8.1.3.4. Type Of

Xpect type methods allow test type inference, both for inferred type or expected type.

//XPECT type of 'probablySomeString' --> string
var probablySomeString = "some string";

var union{string,number} u;
// XPECT expectedType at 'null' --> {function(number?):string}
u.toString = null
8.1.3.5. Advanced methods

There are also other methods provided, that allow to test quick fixes and content assist. Their parameters syntax is more complicated. Additionally they actively modify contents of the editor, or even close it if needed. Their usage exceeds scope of this document.

9. CLI

Parts of this document may be outdated.

9.1. Headless Compiler

The headless compiler is provided as a separate tool, coming as a single jar file n4jsc.jar. It is to be invoked via

java -jar n4jsc.jar

Simply invoking the headless compiler with no further arguments will print out a description of command line options.

The headless compiler works in three major modes (given as arguments to the switch -bt):

  • compilation of single files (-bt singlefile, default),

  • compilation of given projects (-bt projects) or

  • compilation of all projects (-bt allprojects)

The command-line invocation usually has the form of

java -jar n4jsc.jar  ^$[options]$^  file1 file2 ...

Standard compiler options:

--buildType , -bt mode

With mode as exactly one of

singlefile

only the source files given by file1, file2, …​ are compiled.

projects

file1, file2, …​ denote projects (folders containing a manifest.n4mf). These projects will be compiled.

allprojects

All project found under the project-root(s) are compiled. There should be no file…​ given.

dontcompile

Nothing will be compiled. There should be no file…​ given. (This is the default if no -t option is given).

--projectlocations (-pl) path

provide folder(s) to search for projects. If not set, the base folder of the running JVM will be taken as the location. Multiple folders are separated by the systems path-separator (’:’ on Mac / Unix and ’;’ on Windows). Only direct subfolders will be queried for projects. A subfolder is assumed to be a N4JS-project if it contains a manifest.n4mf file. All found projects are taken into consideration for dependency-resolution. Example on Linux:
-pl  /rootA/: /rootB:/some/absolute/path/to/projects.

Advanced compiler options (optional):

--notests

turn off compilation of code in test-folders. Can not be combined with –testonly

--testonly

only compile test code. Externals and sources will not be compiled. Can not be combined with –notests

--keepCompiling

try to compile even if some errors occur.

--preference file

uses file as there internal preferences-store similar to the preferences internally stored by the N4IDE.

Additional command line options (optional):

--help , -h

prints out help to the console and exits.

--verbose , -v

verbose output during build

--debug

before executing, summarises the information of the current setup like resolved pathnames and other information, carries on with normal workflow and prints additional status information about loading and unloading projects and processing each resource.

--log

write a log file n4jsc.log to the base folder. (Change filename with –logfile filename)

9.2. Headless Dependnecies

Compiler can manage dependencies of the processed projects:

--installMissingDependencies , -imd

alnalyzes available projects and installs missing dependencies

--targetPlatformInstallLocation , -tl

location to which dependencies will be installed, if not provided temporal location will be used

--npmrcRootLocation

location of the .npmrc file to be used in npm invocations

9.3. Headless Execution

For headless compiling, running and testing of N4JS code a general command line tool is provided. Many parameters of the different use cases are shared. Although you can combine the use cases each of them is described in its own section. This section is about running compiled code.

For compiling refer to Headless Compiler for executing tests refer to Tests.

9.3.1. Cleaning Headlessly

It is possible to use the headless compiler to clean projects by using the following option

--clean (-c)

When this option is used. The headless compiler only cleans projects without compilation. Moreover, the use of this option requires that the option -t must be specified and must be either -t projects or -t allprojects.

For instance, n4jsc --clean -t allprojects -pl path/to/project or n4jsc --clean -t projects project1 project2 are valid use while n4jsc --clean -t singlefile file1 file2 is invalid. After the calling the command with --clean (-c`), the output folders of the specified projects (e.g. src-gen folders) are cleaned.

9.3.2. Running Headlessly

Running code from the command line requires basically three different pieces of information:

  1. The locations where projects, libraries and environments can be found must be given.

  2. The starting point of execution must be given by pointing to a module.

  3. Since there are multiple different project types, an adequate Runner has to be selected.

The follwing command line switches are used to provide this information:

--projectlocations (-pl) path

path of locations to search for projects (c.f. Headless Compiler ,Project Locations)

--runWith (-rw) VAL

denotes the runner-id (as listed with --list-runners) or at least the last segment of it

--run (-r) FILE

source-module to run. Note you should point to the full location of the source file (*.n4js). The runner is responsible to determine the compiled file. It is not sufficient to give a project-relative path, it always needs to be a full path to the source file.

It is possible to compile and run with a single CLI line. Compilation always precedes the execution. It the compilation fails the runner will not be started.

To ease the usage of different runners it is allowed to provide the last segment(s) of the runner-id in a case-insensitive way, e.g. one can use the runner with id org.eclipse.n4js.runner.nodejs.NODEJS as follows:

.. --runWith org.eclipse.n4js.runner.nodejs.NODEJS ..

or in short

.. --rw NODEJS ..

or even lower-cased with

.. --rw nodejs ..

Assume having a common workspace location ’wsp’ with a project ’P1’ containing the module ’A’. The following line shows how to run this code:

java -jar n4jsc.jar -pl wsp -rw nodejs -r wsp/P1/src/A.n4js

9.3.3. Information about running headlessly

Available runner-ids can be actively queried:

--listRunners (-lr)

prints out a list of all available command-line runners

9.3.4. Testing Headlessly

Testing code from the command line requires basically three different pieces of information:

  1. The locations where projects, libraries and environments can be found must be given.

  2. The starting point of test execution must be given by pointing to what is supposed to be tested (single file / whole project)/

  3. Since there are multiple different project types, an adequate Tester has to be selected.

The follwing command line switches are used to provide this information:

--projectlocations (-pl) path

path of locations to search for projects (c.f. Headless Compiler ,Project Locations)

--testWith (-tw) VAL

denotes the tester-id (as listed with --list-testers) or at least the last segment of it

--test (-t) FILE

source-module to run. Note you should point to the full location of the project with tests, specific folder inside project with tests or the test source file (*.n4js). It is not sufficient to give a project-relative path, it always needs to be a full path to the source file.

It is possible to compile and run with a single CLI line. Compilation always precedes the execution. It the compilation fails the tester will not be started.

To ease the usage of different testers it is allowed to provide the last segment(s) of the tester-id in a case-insensitive way, e.g. one can use the runner with id org.eclipse.n4js.tester.nodejs.NODEJS_MANGELHAFT as follows:

.. --runWith org.eclipse.n4js.tester.nodejs.NODEJS_MANGELHAFT ..

or in short

.. --rw NODEJS_MANGELHAFT ..

or even lower-cased with

.. --rw nodejs_mangelhaft ..

Assume having a common workspace location ’wsp’ with a project ’P1’ containing the module ’TestA’. The following line shows how to execute this test code:

java -jar n4jsc.jar -pl wsp -tw nodejs_mangelhaft -t wsp/P1/src/TestA.n4js

9.3.5. Information about testing headlessly

Available tester-ids can be actively queried:

--listTesters (-lt)

prints out a list of all available command-line testers

Appendix A: License

This specification and the accompanying materials is 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

Eclipse Public License - v 1.0

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (AGREEMENT). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT’S ACCEPTANCE OF THIS AGREEMENT.

1. DEFINITIONS

Contribution means:
  1. in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and

  2. in the case of each subsequent Contributor:

    1. changes to the Program, and

    2. additions to the Program;

      where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution ’originates’ from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor’s behalf. Contributions do not include additions to the Program which:

      1. are separate modules of software distributed in conjunction with the Program under their own license agreement, and

      2. are not derivative works of the Program.

Contributor

means any person or entity that distributes the Program.

Licensed Patents

mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.

Program

means the Contributions distributed in accordance with this Agreement.

Recipient

means anyone who receives the Program under this Agreement, including all Contributors.

2. GRANT OF RIGHTS

  1. Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.

  2. Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.

  3. Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient’s responsibility to acquire that license before distributing the Program.

  4. Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.

3. REQUIREMENTS

A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:

  1. it complies with the terms and conditions of this Agreement; and

  2. its license agreement:

    1. effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;

    2. effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;

    3. states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and

    4. states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.

When the Program is made available in source code form:

  1. it must be made available under this Agreement; and

  2. a copy of this Agreement must be included with each copy of the Program.

Contributors may not remove or alter any copyright notices contained within the Program.

Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.

4. COMMERCIAL DISTRIBUTION

Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor (Commercial Contributor) hereby agrees to defend and indemnify every other Contributor (Indemnified Contributor) against any losses, damages and costs (collectively Losses) arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.

For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor’s responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.

5. NO WARRANTY

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.

6. DISCLAIMER OF LIABILITY

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. GENERAL

If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.

If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient’s patent(s), then such Recipient’s rights granted under Section 2(b) shall terminate as of the date such litigation is filed.

All Recipient’s rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient’s rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient’s obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.

Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.

This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.

Appendix B: Acronyms

CDep

Compile-Time Dependency

RDep

Run-Time Dependency

LDep

Load-Time Dependency

IDep

Initialization-Time Dependency

EDep

Execution-Time Dependency

ANTLR

ANother Tool for Language Recognition

API

Application Programming Interface

AST

Abstract Syntax Tree

ASI

Automatic Semicolon Insertion

BNF

Backus-Naur Form

CLI

Command Line Interface (including a headless compiler and runner.)

DI

Dependency Injection

DIC

DI Component

DOM

Document Object Model

DSL

Domain Specific Language

EBNF

Extended Backus-Naur Form

EMF

Eclipse Modeling Framework

FQN

Fully Qualified Name

GLB

Greatest Lower Bound, also known as infimum

GCST

Greatest Common Sub Type, also known as meet

IDE

Integrated Development Environment

IDL

Interface Definition Language

LSP

Liskov Substitution Principle [Martin96b]

LUB

Least Upper Bound, also known as supremum

LCST

Least Common Super Type, also known as join

N4JS

N4JS for JavaScript

N4JSED

N4JS Environment Definition

N4JSIDE

N4JS Integrated Development Environment (Eclipse-based IDE for all N4JS related languages and projects)

VM

Virtual Machine

XML

Extensible Markup Language

XSLT / XSL

XSL Transformations

XSL

Extensible Stylesheet Language

WYSIWYG

What You See Is What You Get

WLOG

Without loss of generality

Appendix C: Bibliography

N4JS Language Specification.

Martin, Robert C. (1996). The Liskov Substitution Principle. Retrieved from http://www.objectmentor.com/publications/lsp.pdf