Scala Support for NetBeans Proposal

The Scala support for NetBeans will provide an integrated development environment for building, running, testing, and debugging Scala applications.

Planned Features

I. Editing

1. Syntax Highlighting

Lexical scanning and syntax parsing are done using Schliemann by defining a Scala LL(K) NBS file. The editor will know about Scala's traits/objects/classes, variables, functions, types, prefix/infix/postfix operators, and these elements will be properly highlighted.

2. Semantic Syntax Highlighting,

This identifies function calls and parameters, local/global/instance variables, and unused variables.

3. Navigation Display

The navigator displays the structure of the file, from Trait/Object/Class down to individual functions, fields. Double-clicking on an element in the navigator window warps to its source in the editor.

4. Code Folding

Traits/Objects/Classes, functions and block statements are foldable.

5. Background Error Parsing

The Scala parser is running in the background when the user stops typing, and provides error messages as error annotations. On a successful parse, the parse tree is used to drive additional features.

6. Mark Occurrences

Placing the caret on an element (such as a local variable, instance variable, global variable, function call, or class reference) will highlight all other references as well as definition of the current symbol.

7. Go To Declaration

Right click on an element and choose Go-To-Declaration will warp to the declaration for the element, if possible. (Note, it will work right for local variables, but for functions and such it needs to include the type inference prototype as well as some other facilities for finding references in the builtin libraries, or, remote source files.)

This feature is also available via editor hyperlinks - hold the Control key and as you drag the mouse over the source, identifiers are highlighted as hyperlinks. Clicking on a hyperlink will warp to its source if possible.

8. Instant Rename

Renaming a local variable or function is done in place and all references are updated on the fly. To invoke, press the keybinding Ctrl+R.

9. Code Completion

Some basic code completion is provided. When you hit Ctrl-Space, completion is provided for local variables in the current context, as well as function names, class names and constants in the same file.

In addition, various Scala builtins such as keywords and predefined constants are provided.

This is an area where further research is going to yield some improvements using Type inference etc.

Code completion also provides help in specific contexts. For example, if you invoke code completion after the "new" keyword it lists all local and imported Classes.

There are more scenarios; for example, invoking code completion after a "def" keyword will only list inherited methods from the superclasses, and so on.

10. Smart Indent and Formatting

Pressing Return to create a new line causes the new line to be indented appropriately, e.g. same line as the previous line, or further indented when a new block is establishes, e.g. in an if statement, case statement, etc.

11 Formatter

Reformat will reindent the source code.

12. Pair Matching

The editor automatically highlights matching parentheses, braces, brackets, string delimiters, etc. In addition, as you're editing, the editor tries to automatically insert (and remove) matching delimiters automatically. For example, if you type "{", the editor modifies the document to contain "{|}" The important part here is that while you're editing, the file stays valid such that code completion will work etc.

II. Project supporting

1. File Type Recognition

Scala files are recognized in the file system, assigned some default actions, etc.

2. Project Management

  • Scala project will be standard Ant based project.
  • Provides "Build", "Clean and Build", "Run", "Debug" actions.
  • Choosing a Main class for project is also supported.
  • Build failures are linked to the editor source.
  • Logical project representation (Source Files, Library, Test Files etc)
  • Basic file templates for simple scripts, traits, objects and classes are provided.
  • Allow Java source files in Scala project, and will be automatically built to classes and jars
  • Manage compile and run dependent libraries

3. Manage Java/Scala platform

  • A platform management will help user to add/remove Java or Scala platform that installed on user system
  • Configure the projects to execute with either Java platforms or Scala platform

4. Unit Tests

JUnit tests or Scala based unit test will be supported. There is a new unit test template. And when executing unit tests failures are linked to the editor source.

III. Interactive Scala Shell

You can open up an interactive Scala shell session from the Windows menu. The shell window let you interact with Scala directly. Use arrow keys for command history etc.

IV. Debugging

Debugging Scala will be invoked when you press the "Debug" button.

List of implemented features

  • Views:
  • Local Variables
  • Watches
  • Call Stack
  • Breakpoints
  • Balloon Evaluation. Holding mouse over text in the editor will evaluate underlying expression and show result in the tooltip.
  • Breakpoints management
  • Stepping (over/into/out) into project, standard Java and Scala library.

Implementation Plan

1. Editing

NetBeans' project Schliemann has a built-in, near full-featured scanning and parser. With a bit more enhancements, such as state stack and lookahead features for NBS, it can reach the same level of JavaCC. I'll follow the latest process of Schiliemann project.

Editing features will be based on project Schliemann. By defining a LL(K) NBS file for Scala tokens and grammar, we can get most basic editing features working. There will be some necessary enhancements of Schliemann modules, such as a refined formatter, better integration to external semantic analyzer etc. I'll work with the modules owner to get Schliemann more featured, flexible and stable.

Go-To-Declaration/Hyperlinks for remote variables and remote functions, Smart-Completion features will be base on a Semantic/Type-Inference analyzer, this analyzer is the most difficult and time-consumer part of whole project. By visiting the AST tree, we should get all semantic definitions, usages, and their contexts. Their types should also be inferred on the meantime. All these semantic information will be indexed in Lucene documents for further using.

2. Project Support

Project support module will be based on current j2se project support of NetBeans, thus Scala project can support mixing Scala/Java source files. This feature will track the newest Java Project Common API.

3. Debugger

Debugger modules will be based on current JPDA modules of NetBeans.

To hook mouse clicking to adding/removing breakpoints, should implement and register Scala's MIME type related "GlyphGutterActions" in layer.xml, so, org.netbeans.modules.editor.impl.GlyphGutterActionsProvider#getGlyphGutterActions(String mimeType) can lookup this action. GlyphGutterActionsProvider#getGlyphGutterActions will be invoked by org.netbeans.editor.GlyphGutter#GutterMouseListener#mouseClicked.

To get debugger recognizing source file's structure and context, should implement org.netbeans.spi.debugger.jpda.EditorContext.

Time Line

1. End of March (30% finished)

  • Syntax highlights
  • Code folding
  • Pair matching
  • Full featured indent and formatter
  • Basic Instant rename
  • Basic navigator
  • Basic completion (Keywords, local variables)
  • Basic Go-To-Declaration/Hyperlinks (for local variables, local functions)
  • Basic project management ("Build", "Clean and Build", "Run", "Debug")
  • Basic debugger
  • Interactive Scala shell

2. End of May (50% finished)

  • Finished Semantic/Type-Inference analyzer;
  • Finished Smart completion, Go-To-Declaration/Hyperlink (for remote variables, remote functions)

3. End of June (80% finished)

  • Finished debugger features
  • Finished editing features

4. End of July (100% finished)

  • Finished unit test integration
  • Finished all other features

All deliverables such as Installable modules, Source code, User guides will be available corresponding to each time line at:

Project Expansion Possibilities

I. Smart Completion for Imported Java Classes

To implement this feature, the Scala editing and project support should cooperate with existing Java features of NetBeans, such as querying the index of Java platform.

II. Full Featured Refactoring

1. Find Usages

Right-click on a symbol and choose Find-Usages (or use the keyboard shortcut). In the Find usages dialog user can also find subtypes of the class rather than usages

2. Rename

  • Rename variables
  • Rename functions
  • Rename Traits/objects/classes
  • Rename packages

* Notes

Due to the time frame, refactoring cross mixed Java source file may not be supported, this leaves more research area to enhance in the future.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo