+ All Categories
Home > Software > The best of AltJava is Xtend

The best of AltJava is Xtend

Date post: 21-Jan-2018
Category:
Upload: takezoe
View: 3,408 times
Download: 2 times
Share this document with a friend
22
The best of AltJava is Naoki Takezoe @takezoen BizReach, Inc #渋谷java
Transcript

The best of AltJava is

Naoki Takezoe@takezoen

BizReach, Inc

#渋谷java

What's Xtend?

● Hosted by Eclipse Foundation● Based on Xtext● Similar syntax to Scala or Kotlin● Compiled to Java source code (not class file)● Eclipse and IntelliJ support

What's Xtend?

What's Xtend?

_人人人人人人_

> Java10!! <

 ̄Y^Y^Y^Y^Y ̄

What's Xtend?

Tool support

● IDE Plugins○ Eclipse○ IntelliJ IDEA (not work with IntelliJ 2017.1.2?)

● Build tools○ Maven○ Gradle

Eclipse support

You can install Xtend support from the update site.

About Xtext

● Framework for development of languages● Define language using BNF like DSL ● Generate toolkit like parser or editor from it

Language Definition

Parser

Compiler

Linker

Type checker

Editor

Generate

Xtext Summit

● In EclipseCon 2017 France● June 20-21 (2days!!)● One of the hottest projects in Eclipse.org

Language features

Basic syntax

● def / var / val● () in method invocation is optional● return and return type are optional● null-safe call: myRef?.doStuff● All exceptions are treated as runtime● if, try, switch and block are expression

(for and while are void, unfortunately)

Extension methods

class HelloWorld {def static print(String s){

println(s)}def static void main(String[] args){

"Hello World".print()}

}

Extension methods

class StringExtensions {def print(String s){ ... }

}

class HelloWorld {static extension StringExtensions extensions = …

def static void main(String[] args){"Hello World".print()

}}

Import extension methods defined in other class

Lambda expressions

def static void main(String[] args){val list = Arrays.asList("Kotlin", "Java", "Xtend")

Collections.sort(list) [ a, b | a.length - b.length]

println(list)}

Translated to lambda

Dispatch methods

def static dispatch printType(Number x) { "it's a number"

}def static dispatch printType(Integer x) {

"it's an int" }

def static void main(String[] args){println(10.printType)

}

Switch expressions

def length(Object x) {switch x {

String case x.length > 0 : x.lengthList<?> : x.sizedefault : -1

}}

Type guard and case guard are available

Template expressions

def someHTML(String content) ''' <html> <body> «content» </body> </html>'''

Three single quote!

Embed variables as «...»

Active annotations (Macro)

@Data class User {long userIdString userNameString email

}

Generate code triggered by annotation

Summary

Xtend...

● has simple and powerful syntax.● has excellent Eclipse support.● covers Web, GUI and Android.● offers 100% Java interop.

Tryhttp://www.eclipse.org/xtend/


Recommended