Skip to main content

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

Jump to: navigation, search

Difference between revisions of "JDT Core/Plan/4.8/JEP286"

m
(Added bugzilla numbers for JEP 286)
Line 3: Line 3:
 
Main tracking bug: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=525750 JEP286 Bug]
 
Main tracking bug: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=525750 JEP286 Bug]
  
== Break-down of items ==
+
== Compiler changes ==
 
+
Changes regarding the compiler: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=527554 Compiler Bug]
 
=== Grammar changes ===
 
=== Grammar changes ===
 
Since var is not a keyword, but a reserved type name AND we need to be backwards compatible anyway,
 
Since var is not a keyword, but a reserved type name AND we need to be backwards compatible anyway,
Line 29: Line 29:
 
Shouldn't be much work since the stack frame would be filled in with the bound type anyway.
 
Shouldn't be much work since the stack frame would be filled in with the bound type anyway.
  
=== DOM support ===
+
== DOM support ==
Add DOM access to aforementioned AST+type bits.
+
Changes regarding the DOM: [https://bugs.eclipse.org/bugs/show_bug.cgi?id=527558 DOM Bug]
  
=== New info + quick fix (nice to have) ===
+
== UI Changes ==
Convert diamond operator to var, like fixing "List<String> names = new LinkedList<>()" into "var names = new LinkedList<String>()"
+
This hasn't been looked into yet. Some ideas:
  
 
=== Code hover ===
 
=== Code hover ===
Show type of variable (if not already handled by framework)
+
* Show inferred type of variable
 +
 
 +
=== Preferences ===
 +
* 'Code Style' option to prefer 'var' over specific types (to control the irritants generated by the compiler)
 +
 
 +
=== Quick fixes ===
 +
* Convert 'var' into the resolved type
 +
* Convert explicit typed local variable into 'var', like changing "String coolIde = "Eclipse";" into "var coolIde = "Eclipse";"
 +
* Convert diamond operator to var, like fixing "List<String> names = new LinkedList<>()" into "var names = new LinkedList<String>()"
 +
 
 +
=== Code templates ===
 +
* Use 'var' in templates for loops and introduce new variable, if preferred by the code style.

Revision as of 11:30, 21 November 2017

Planning page for JDT Implementation of Local Variable Type Inference (JEP 286) for Photon (4.8)

Main tracking bug: JEP286 Bug

Compiler changes

Changes regarding the compiler: Compiler Bug

Grammar changes

Since var is not a keyword, but a reserved type name AND we need to be backwards compatible anyway, it should be handled in type resolution instead of grammar. Local variable type inference should be denoted by a bit AST node and type binding.

Type checking

  • Determine the type of the var declaration
  • Determine upwards/downwards type projection for type
  • Fallback to "Object" type in case of error

Error reports

  • Errors where local variable type cannot be inferred:
    • Cannot use 'var' on variable without initializer
    • Lambda expression needs an explicit target-type
    • Variable initializer is 'null'
    • Inferred type is non denotable
    • When method reference needs an explicit target-type.
    • array initializer needs an explicit target-type
  • Error when defining a type called 'var':

This should be a configurable 'warning'/'info' for Java 9 and earlier.

Code generation

Shouldn't be much work since the stack frame would be filled in with the bound type anyway.

DOM support

Changes regarding the DOM: DOM Bug

UI Changes

This hasn't been looked into yet. Some ideas:

Code hover

  • Show inferred type of variable

Preferences

  • 'Code Style' option to prefer 'var' over specific types (to control the irritants generated by the compiler)

Quick fixes

  • Convert 'var' into the resolved type
  • Convert explicit typed local variable into 'var', like changing "String coolIde = "Eclipse";" into "var coolIde = "Eclipse";"
  • Convert diamond operator to var, like fixing "List<String> names = new LinkedList<>()" into "var names = new LinkedList<String>()"

Code templates

  • Use 'var' in templates for loops and introduce new variable, if preferred by the code style.

Back to the top