Skip to main content
Jump to: navigation, search

Difference between revisions of "JDT UI/Java8"

(DOM AST node changes in JLS8)
(Things to remember/caveats: removed collapsible section)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
This page tracks the work in progress to add Java™ 8 support (mainly jsr308 "Type Annotations" and jsr335 "Lambda Expressions") into Eclipse JDT UI. See [[JDT Core/Java8]] for the work in the JDT Core plug-ins.  
 
This page tracks the work in progress to add Java™ 8 support (mainly jsr308 "Type Annotations" and jsr335 "Lambda Expressions") into Eclipse JDT UI. See [[JDT Core/Java8]] for the work in the JDT Core plug-ins.  
  
 +
'''Note: This is an internal project page that may be horribly out of date.'''
 +
 +
<!-- commented out; not up-to-date:
 
= Test matrix =
 
= Test matrix =
 
  
 
<br>
 
<br>
 
+
{| cellspacing="0" cellpadding="5" border="1" align="center" style="background: none repeat scroll 0% 0%;"
{| cellspacing="0" cellpadding="5" border="1" align="center"
+
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" |  
+
! align="center" |  
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Lambda Expressions
+
! align="center" width="200" | Lambda Expressions
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Method references
+
! align="center" width="200" | Method references
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Default Methods
+
! align="center" width="200" | Default Methods
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Type Annotations / Receiver parameter
+
! align="center" width="200" | Type Annotations / Receiver parameter
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Typing, reconciler
+
! Typing, reconciler
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Syntax coloring
+
! Syntax coloring
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Semantic highlighting
+
! Semantic highlighting
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Mark occurrences
+
! Mark occurrences
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Outline
+
! Outline
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Content assist
+
! Content assist
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Type hierarchy
+
! Type hierarchy
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Quick assists
+
! Quick assists
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Quick fixes
+
! Quick fixes
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Clean ups
+
! Clean ups
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Refactoring operations (core)
+
! Refactoring operations (core)
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Refactoring UIs
+
! Refactoring UIs
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Formatter
+
! Formatter
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #D2F2D2;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #D2F2D2;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Search
+
! Search
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Javadoc (hover, view)
+
! Javadoc (hover, view)
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Source actions
+
! Source actions
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|-
 
|-
! width="200" align="center" style="background: none repeat scroll 0% 0%" | Call hierarchy
+
! Call hierarchy
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
! width="200" align="center" style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" |
+
| align="center" style="background: #F0D0D0;" |
 
|}
 
|}
<br>  
+
<br>
  
{| cellspacing="0" cellpadding="5" border="1" style="width: 300px; height: 25px;"
+
{| cellspacing="0" cellpadding="5" border="1" style="width: 300px; height: 25px; background: none repeat scroll 0% 0%;"
 
|-
 
|-
! style="background: none repeat scroll 0% 0% rgb(206, 242, 206);" | &nbsp;&nbsp;
+
| align="center" style="width: 2em; background: #D2F2D2;" | || Done
| Done
+
 
|-
 
|-
! style="background: none repeat scroll 0% 0% rgb(206, 206, 242);" | <br>
+
| align="center" style="width: 2em; background: #D1D1F1;" | || Tested and works, but can be improved (e.g. by adding Quick Assists or Quick Fixes)
| Tested and works but can be improved (e.g. by adding Quick Assists or Quick Fixes)
+
 
|-
 
|-
! style="background: none repeat scroll 0% 0% rgb(242, 206, 206);" | <br>
+
| align="center" style="width: 2em; background: #F0D0D0;" | || Not done yet
| Not done yet
+
 
|}
 
|}
 
(1) more work needed if spec changes
 
(1) more work needed if spec changes
 +
 +
-->
  
 
= Work areas =
 
= Work areas =
Line 139: Line 139:
 
** MethodDeclaration#thrownExceptions() -> thrownExceptionsTypes() ({{bug|403924}})
 
** MethodDeclaration#thrownExceptions() -> thrownExceptionsTypes() ({{bug|403924}})
 
** Annotations on Extra Dimensions ({{bug|403923}})
 
** Annotations on Extra Dimensions ({{bug|403923}})
** Receiver parameter on instance methods and inner class constructors
+
** Receiver parameter on instance methods and inner class constructors ({{bug|404147}})
** Render annotations in Javadoc hover/view. Do not render in Outline, etc. for now. ({{bug|403917}})
+
 
** Refactoring dialogs that allow to modify types
 
** Refactoring dialogs that allow to modify types
 +
** deferred: Render annotations in Javadoc hover/view. Do not render in Outline, etc. for now. ({{bug|403917}})
 
* Default Methods
 
* Default Methods
* Lambda Expressions
+
* Lambda Expressions ({{bug|405305}})
 
** check code that walks the parent chain to find the enclosing Block or BodyDeclaration
 
** check code that walks the parent chain to find the enclosing Block or BodyDeclaration
 
* Method References
 
* Method References
Line 156: Line 156:
  
 
*Use the following @since tag on all newly added members: "3.9 BETA_JAVA8"
 
*Use the following @since tag on all newly added members: "3.9 BETA_JAVA8"
 +
 +
= How to set up the IDE =
 +
See [[JDT Core/Java8#What_to_do_to_set_up_the_IDE]].
 +
 +
= Early access binaries =
 +
Please see [[JDT/Eclipse Java 8 Support (BETA)]] for details.
 +
 +
= UI decisions =
 +
== TYPE_USE annotations ==
 +
ITypeBindings can now carry TYPE_USE annotations. API of ITypeBindings#equals needs to be updated and we eventually need to replace usages of == with #equals(Object).
 +
 +
=> Conclusion: ITypeBindings don't carry TYPE_USE annotations.
 +
 +
Should TYPE_USE annotations show up in the Java model (IJavaElements)? The intention of the Java model is to provide a high-level structure for rendering elements in an outline and to serve as enclosing elements in search results. TYPE_USE annotations don't show up in type signatures and the compiler doesn't consult them. They are second-class citizens. The Java model cannot contain every detail of an element (e.g. it also doesn't contain comments). Furthermore, it's not clear how TYPE_USE annotations should be represented. They can't be part of a signature.
 +
 +
=> Conclusion: IJavaElements don't carry TYPE_USE annotations.
 +
 +
== Lambda expressions in the Java model ==
 +
Currently, anonymous classes are represented in the Java model. Should lambda expressions and method references also be part of the model?
 +
The problem with that is that lambda expressions are perceived more lightweight than anonymous classes, so lambda expressions will be used much more frequently. Method references are another form of implicit class declarations, since some forms already bind a receiver object.
 +
 +
Anonymous classes must be part of the Java model, because they can define multiple members (fields/methods) that should be visible in an Outline and that should support operations like "Open Super Implementation". OTOH, lambda expressions and method references don't have sub-members. However, a lambda expression can contain anonymous and local classes, and the lambda expression itself would be interesting as the enclosing element in a search result.
 +
 +
=> Conclusion: Lambda expressions are currently not represented in the Java model but might be added later.
  
 
= Things to remember/caveats  =
 
= Things to remember/caveats  =
Line 165: Line 189:
 
*For ASTNode changes:  
 
*For ASTNode changes:  
 
**Search for references to a changed AST Node and update code that relies on the concrete structure
 
**Search for references to a changed AST Node and update code that relies on the concrete structure
 +
***in most cases, JDT UI only supports ASTs with the latest AST level (internal ASTProvider.SHARED_AST_LEVEL)
 +
***we only do AST#apiLevel() checks where old ASTs can be passed in via JDT UI APIs:
 +
****CodeGeneration -> StubUtility
 +
****ASTFlattener
 +
****AddUnimplementedConstructorsAction -> StubUtility2#createConstructorStub(..)
 +
****AddUnimplementedMethodsOperation -> -> StubUtility2#createImplementationStub(..)
 +
****in general: search for references to type "org.eclipse.jdt.core.dom.*" in org.eclipse.jdt.ui and subpackages
 
**Remember there are multiple ways to access AST node properties:
 
**Remember there are multiple ways to access AST node properties:
 
*** via getter/setter or List-valued accessor
 
*** via getter/setter or List-valued accessor
Line 175: Line 206:
 
*Think about cases where new bindings can show up.
 
*Think about cases where new bindings can show up.
  
= DOM AST node changes in JLS8 =
+
= DOM AST changes in JLS8 =
''If everything is correct, then you should find these as references to ASTNode#unsupportedIn2_3_4() and #supportedOnlyIn2_3_4().''
+
''If everything is correct, then you should find the ASTNode changes as references to ASTNode#unsupportedIn2_3_4() and #supportedOnlyIn2_3_4().''
  
 +
~AST
 +
  ~newArrayType(Type): used to take a component type; now only accepts an element type that is not an array type
 +
  ~newArrayType(Type, int): (same as above)
 +
 
  +AnnotatableType (abstract superclass):
 
  +AnnotatableType (abstract superclass):
   +annotations: List<Annotation> (also in subtypes PrimitiveType, ArrayType, SimpleType, QualifiedType, WildcardType)
+
   +annotations: List<Annotation> (also in subtypes PrimitiveType, SimpleType, QualifiedType, NameQualifiedType, WildcardType)
 
   
 
   
  +ExtraDimension
+
  ~ArrayType
 +
  -componentType: Type
 +
  +setElementType(Type)
 +
  +dimensions: Dimension
 +
 +
+NameQualifiedType extends AnnotatableType
 +
  +qualifier: Name
 +
  +annotations: List<Annotation>
 +
  +name: SimpleName
 +
 +
+IntersectionType extends Type
 +
  +types: List<Type>
 +
 +
+Dimension extends ASTNode
 
   +annotations: List<Annotation>
 
   +annotations: List<Annotation>
 
   
 
   
  +LambdaExpression:
+
  +LambdaExpression extends Expression
 
   +parentheses: boolean
 
   +parentheses: boolean
 
   +parameters: List<SingleVariableDeclaration> or List<VariableDeclarationFragment>
 
   +parameters: List<SingleVariableDeclaration> or List<VariableDeclarationFragment>
Line 192: Line 240:
 
  ~MethodDeclaration:
 
  ~MethodDeclaration:
 
   -setExtraDimensions(int)
 
   -setExtraDimensions(int)
   +extraDimensions: List<ExtraDimension> (incl. annotations on extra dimensions)
+
   +extraDimensions: List<Dimension> (incl. annotations on extra dimensions)
 
   +receiverType: AnnotatableType
 
   +receiverType: AnnotatableType
 
   +receiverQualifier: SimpleName
 
   +receiverQualifier: SimpleName
 
   -thrownExceptions: List<Name>
 
   -thrownExceptions: List<Name>
 
   +thrownExceptionTypes: List<Type>
 
   +thrownExceptionTypes: List<Type>
 +
 +
+MethodReference extends Expression (abstract class)
 +
  +typeArguments: List<Type>
 +
  +resolveMethodBinding(): IMethodBinding
 +
 
 +
  (+Subypes:)
 +
 
 +
  +CreationReference
 +
    +expression: Expression
 +
 
 +
  +ExpressionMethodReference
 +
    +expression: Expression
 +
    +name: SimpleName
 +
 
 +
  +SuperMethodReference
 +
    +qualifier: Name
 +
    +name: SimpleName
 +
 
 +
  +TypeMethodReference
 +
    +type: Type
 +
    +name: SimpleName
 
   
 
   
 
  ~SingleVariableDeclaration:
 
  ~SingleVariableDeclaration:
Line 206: Line 275:
 
  ~VariableDeclaration:
 
  ~VariableDeclaration:
 
   +extraDimensions List<ExtraDimension> (also in subtypes SingleVariableDeclaration, VariableDeclarationFragment)
 
   +extraDimensions List<ExtraDimension> (also in subtypes SingleVariableDeclaration, VariableDeclarationFragment)
 +
 +
~ITypeBinding:
 +
  +getTypeAnnotations(): IAnnotationBinding[]
 +
  +getFunctionalInterfaceMethod(): IMethodBinding
  
 
For JLS4, the changes were:
 
For JLS4, the changes were:
Line 214: Line 287:
 
  +UnionType
 
  +UnionType
 
   +types: List<Type>
 
   +types: List<Type>
 +
 +
Annotated array dimensions are not clearly defined by the current JLS8. See [http://mail.openjdk.java.net/pipermail/type-annotations-spec-comments/2014-March/000070.html this post]. The assumption is that array dimensions are nested like this, from innermost (element type) to outermost:
 +
* element type (with annotations just in front of the type)
 +
* extra dimensions, from left to right
 +
* type dimensions, from left to right
  
 
= TODOs =
 
= TODOs =
Line 227: Line 305:
 
</pre></blockquote>
 
</pre></blockquote>
  
 +
* A VariableDeclarationFragment can now also show up in a LambdaExpression
 +
** check usages of VariableDeclarationFragment.getParent()
 +
** check usages of VariableDeclarationFragment that assume there's an associated type (e.g. ASTNodes.getType(VariableDeclaration))
 +
 +
* Check helper methods in ASTNodes
 +
** e.g. getTopMostName(Name) is not correct any more to find an exception type
 +
 +
* Check all ASTVisitors that override one of the visit/endVisit methods for one of the changed AST node types
 +
 +
== TYPE_USE annotations ==
 +
 +
* Code affected by lack of TYPE_USE annotations in ITypeBindings: The code in UI that currently loses TYPE_USE annotations will need to be adjusted once ({{bug|409586}}) is fixed.
 +
** Introduce Indirection refactoring: IntroduceIndirectionRefactoring#createIntermediaryMethod()
 +
** Move Method refactoring: MoveInstanceMethodProcessor#createMethodArguments(...)#getArgumentNode(...)
 +
 +
* Code affected by lack of TYPE_USE annotations in IJavaElements: ({{bug|405843}})
 +
** Javadoc hover and view cannot display TYPE_USE annotations.
 +
** Method signature previews in refactoring wizards cannot display TYPE_USE annotations - Change Method Signature, Introduce Parameter Object, Introduce Parameter, Extract Method.
  
 
[[Category:JDT]]
 
[[Category:JDT]]

Latest revision as of 08:33, 22 June 2017

This page tracks the work in progress to add Java™ 8 support (mainly jsr308 "Type Annotations" and jsr335 "Lambda Expressions") into Eclipse JDT UI. See JDT Core/Java8 for the work in the JDT Core plug-ins.

Note: This is an internal project page that may be horribly out of date.


Work areas

  • set ASTProvider.SHARED_AST_LEVEL to JLS8 (bug 403927)
    • fix problems that need immediate handling
    • fix other references to JLS4
  • Annotations on types
    • Annotations that moved to another node in the AST (under discussion in bug 403834)
    • MethodDeclaration#thrownExceptions() -> thrownExceptionsTypes() (bug 403924)
    • Annotations on Extra Dimensions (bug 403923)
    • Receiver parameter on instance methods and inner class constructors (bug 404147)
    • Refactoring dialogs that allow to modify types
    • deferred: Render annotations in Javadoc hover/view. Do not render in Outline, etc. for now. (bug 403917)
  • Default Methods
  • Lambda Expressions (bug 405305)
    • check code that walks the parent chain to find the enclosing Block or BodyDeclaration
  • Method References

IMPORTANT NOTE

  • The following lines must be added in all headers of modified files for Java™ 8 implementation:
 * This is an implementation of an early-draft specification developed under the Java
 * Community Process (JCP) and is made available for testing and evaluation purposes
 * only. The code is not compatible with any specification of the JCP.
 *

  • Use the following @since tag on all newly added members: "3.9 BETA_JAVA8"

How to set up the IDE

See JDT Core/Java8#What_to_do_to_set_up_the_IDE.

Early access binaries

Please see JDT/Eclipse Java 8 Support (BETA) for details.

UI decisions

TYPE_USE annotations

ITypeBindings can now carry TYPE_USE annotations. API of ITypeBindings#equals needs to be updated and we eventually need to replace usages of == with #equals(Object).

=> Conclusion: ITypeBindings don't carry TYPE_USE annotations.

Should TYPE_USE annotations show up in the Java model (IJavaElements)? The intention of the Java model is to provide a high-level structure for rendering elements in an outline and to serve as enclosing elements in search results. TYPE_USE annotations don't show up in type signatures and the compiler doesn't consult them. They are second-class citizens. The Java model cannot contain every detail of an element (e.g. it also doesn't contain comments). Furthermore, it's not clear how TYPE_USE annotations should be represented. They can't be part of a signature.

=> Conclusion: IJavaElements don't carry TYPE_USE annotations.

Lambda expressions in the Java model

Currently, anonymous classes are represented in the Java model. Should lambda expressions and method references also be part of the model? The problem with that is that lambda expressions are perceived more lightweight than anonymous classes, so lambda expressions will be used much more frequently. Method references are another form of implicit class declarations, since some forms already bind a receiver object.

Anonymous classes must be part of the Java model, because they can define multiple members (fields/methods) that should be visible in an Outline and that should support operations like "Open Super Implementation". OTOH, lambda expressions and method references don't have sub-members. However, a lambda expression can contain anonymous and local classes, and the lambda expression itself would be interesting as the enclosing element in a search result.

=> Conclusion: Lambda expressions are currently not represented in the Java model but might be added later.

Things to remember/caveats

  • Goal of the first pass is to make Eclipse work with the new language features. For more advanced support (new quick fixes / refactorings / templates / ...), please file an enhancement request with the [1.8] tag.
  • Bugs that went into the BETA_JAVA8 branch should be RESOLVED/FIXED with Target Milestone "BETA_JAVA8" and the [1.8] tag in front of the summary.
  • For ASTNode changes:
    • Search for references to a changed AST Node and update code that relies on the concrete structure
      • in most cases, JDT UI only supports ASTs with the latest AST level (internal ASTProvider.SHARED_AST_LEVEL)
      • we only do AST#apiLevel() checks where old ASTs can be passed in via JDT UI APIs:
        • CodeGeneration -> StubUtility
        • ASTFlattener
        • AddUnimplementedConstructorsAction -> StubUtility2#createConstructorStub(..)
        • AddUnimplementedMethodsOperation -> -> StubUtility2#createImplementationStub(..)
        • in general: search for references to type "org.eclipse.jdt.core.dom.*" in org.eclipse.jdt.ui and subpackages
    • Remember there are multiple ways to access AST node properties:
      • via getter/setter or List-valued accessor
      • via the StructuralPropertyDescriptor constant
      • for properties declared in an abstract class: via get*Property() instance method
    • Check references to superclasses of the changed/added node type. E.g. for IntersectionType, code that thinks it handles all known subtypes of Type needs to be adjusted.
    • Add new node types to switch or if-else-if statements
    • Think about cases where code could use StructuralPropertyDescriptors
  • Think about cases where new bindings can show up.

DOM AST changes in JLS8

If everything is correct, then you should find the ASTNode changes as references to ASTNode#unsupportedIn2_3_4() and #supportedOnlyIn2_3_4().

~AST
 ~newArrayType(Type): used to take a component type; now only accepts an element type that is not an array type
 ~newArrayType(Type, int): (same as above)

+AnnotatableType (abstract superclass):
  +annotations: List<Annotation> (also in subtypes PrimitiveType, SimpleType, QualifiedType, NameQualifiedType, WildcardType)

~ArrayType
 -componentType: Type
 +setElementType(Type)
 +dimensions: Dimension

+NameQualifiedType extends AnnotatableType
 +qualifier: Name
 +annotations: List<Annotation>
 +name: SimpleName

+IntersectionType extends Type
 +types: List<Type>

+Dimension extends ASTNode
  +annotations: List<Annotation>

+LambdaExpression extends Expression
  +parentheses: boolean
  +parameters: List<SingleVariableDeclaration> or List<VariableDeclarationFragment>
  +body: Block or Expression
  +resolveMethodBinding(): IMethodBinding

~MethodDeclaration:
  -setExtraDimensions(int)
  +extraDimensions: List<Dimension> (incl. annotations on extra dimensions)
  +receiverType: AnnotatableType
  +receiverQualifier: SimpleName
  -thrownExceptions: List<Name>
  +thrownExceptionTypes: List<Type>

+MethodReference extends Expression (abstract class)
  +typeArguments: List<Type>
  +resolveMethodBinding(): IMethodBinding
  
  (+Subypes:)
  
  +CreationReference
    +expression: Expression
  
  +ExpressionMethodReference
    +expression: Expression
    +name: SimpleName
  
  +SuperMethodReference
    +qualifier: Name
    +name: SimpleName
  
  +TypeMethodReference
    +type: Type
    +name: SimpleName

~SingleVariableDeclaration:
  +varargsAnnotations: List<Annotation>

~TypeParameter:
  +annotations: List<Annotation>

~VariableDeclaration:
  +extraDimensions List<ExtraDimension> (also in subtypes SingleVariableDeclaration, VariableDeclarationFragment)

~ITypeBinding:
 +getTypeAnnotations(): IAnnotationBinding[]
 +getFunctionalInterfaceMethod(): IMethodBinding

For JLS4, the changes were:

~TryStatement:
  +resources: List<VariableDeclarationExpression>

+UnionType
  +types: List<Type>

Annotated array dimensions are not clearly defined by the current JLS8. See this post. The assumption is that array dimensions are nested like this, from innermost (element type) to outermost:

  • element type (with annotations just in front of the type)
  • extra dimensions, from left to right
  • type dimensions, from left to right

TODOs

  • 'default' flag:
    • show in the UI?
    • update JdtFlags?
  • The ITypeBinding of a TYPE_USE-annotated expression (e.g. ClassInstanceCreation or reference to a variable) doesn't contain the TYPE_USE annotations. References to "String s" and "@NonEmpty String ns" have identical type bindings. Should TYPE_USE annotations show up in reference bindings? Note that for some expressions, the annotated type is not defined by jsr 308, e.g. for the conditional expression here:
@Deprecated @NonEmpty String s = new Random().nextBoolean()
	? new @NonEmpty String("hi")
	: new String();
  • A VariableDeclarationFragment can now also show up in a LambdaExpression
    • check usages of VariableDeclarationFragment.getParent()
    • check usages of VariableDeclarationFragment that assume there's an associated type (e.g. ASTNodes.getType(VariableDeclaration))
  • Check helper methods in ASTNodes
    • e.g. getTopMostName(Name) is not correct any more to find an exception type
  • Check all ASTVisitors that override one of the visit/endVisit methods for one of the changed AST node types

TYPE_USE annotations

  • Code affected by lack of TYPE_USE annotations in ITypeBindings: The code in UI that currently loses TYPE_USE annotations will need to be adjusted once (bug 409586) is fixed.
    • Introduce Indirection refactoring: IntroduceIndirectionRefactoring#createIntermediaryMethod()
    • Move Method refactoring: MoveInstanceMethodProcessor#createMethodArguments(...)#getArgumentNode(...)
  • Code affected by lack of TYPE_USE annotations in IJavaElements: (bug 405843)
    • Javadoc hover and view cannot display TYPE_USE annotations.
    • Method signature previews in refactoring wizards cannot display TYPE_USE annotations - Change Method Signature, Introduce Parameter Object, Introduce Parameter, Extract Method.

Back to the top