SlideShare a Scribd company logo
Xtend
statically typed
Java-like language general purpose a better Java with less “noise”
interoperable with Java
possible to reuse Java libraries
Java type system generics annotations
more concise syntax
type inference
extension methods
dispatch methods
multiline template expressions
Xtend programs translated to Java
Xtend language implemented in Xtext can be used independently from Xtext
Example of Xtend code
less verbose than Java
optional semicolons
methods are public by default
Xtend Methods, fields and variables
no statements everything is an expression
last expression in body is the return expressionmethod
return type can be omitted if it can be inferred
types must always be specifiedmethod params
implicitly final (immutable)
method definition: either def or override
several classes can be defined in one file
private by defaultfield
Xtend Fields and variables
val for final
var for non-final
==
===
compares the values of objects
maps the operator to method equals object identifier equality in Java sense
final fields and variables must be initialized
o.getName()getters and setters o.name()
o.setName(...) o.name = ...
Xtend Extension methods
UFCS Uniform function call syntax as in programming language D
f(x)
x.f()
x.f
f is not defined in MyType
add new methods to existing types idea similar to class helpers
as if f were a method of class MyType
MyType x ...
as in Delphi
omitted parentheses
Xtend Extension methods
extension field of type T in class A –
methods of T become extension methods in A
extension variable – in code block
extension parameter – in method body
name is optional
methods defined in Xtend class
can be used as extension methods
Xtend Implicit variable it
class ItExamples {
def func1(String it) {
return toLowerCase // it.toLowerCase
}
def func2(String s) {
var it = s
toLowerCase // it.toLowerCase
}
}
all members of it are implicitly available similar to this
all members of this are available
in an instance method
Xtend Enhanced switch expressions
def String switchExample(Entity e, Entity specialEntity) {
switch e
{
case e.name.length > 0: “has a name”
case e.superType != null: “inherits some entity”
case specialEntity: “equals to special entity”
default: “nothing”
}
}
switch value – any object reference
Boolean – case matches if true
not Boolean – compare using equals
Boolean – case matches if true
Xtend Enhanced switch expressions
def toString(FieldType fieldType) {
switch (fieldType) {
BasicType : fieldType.typeName
EntityType : fieldType.entity.name
}
}
only the selected case is executed in Java falls though all matching cases
no need for explicit break instructions
does not support break statementsXtend
Type guards
cases are evaluated in the specification order
case matches only if
switch value conforms to type
Xtend Polymorphic method invocation
method
overloading
static mechanism
selection of the specific method according to static type of arguments
class hierarchy:
base class AnyType
two classes NumberType, TextType
method typeToString
defined in another class
static overloading would use AnyType
NumberType desired –
but only known at runtime
multiple dispatch method selected according to runtime type of arguments
Xtend Lambda expressions
val l = [String s, int i | s + i]
println(l.apply(“s”, 10))
val (String, int)=>String l = [String s, int i | s + i]
val (String, int)=>String l = [s, i | s + i]
def execute( (String, int)=>String f ) {
f.apply(“s”, 10)
}
execute([s, i | s + i])
val list = newArrayList(“John”, “Mary”, “David”, “Alice”)
Collections.sort(list, [arg0, arg1 | arg0.compareToIgnoreCase(arg1)])
Collections.sort(list) [arg0, arg1 | arg0.compareToIgnoreCase(arg1)]
mystrings.findFirst[s | s.startsWith(“T”)]
mystrings.findFirst[it.startsWith(“T”)]
mystrings.findFirst[startsWith(“T”)]
anonymous function
can be stored in a variable
can be passed to methods
types for lambda expressions
types can be omitted if can be inferred
SAM (Single Abstract Method)
known in Java as functional interfaces
Xtend With operator
return eINSTANCE.createPerson =>
[
name = “John”
surname = “Smith”
]
val person = eINSTANCE.createPerson
person.name = “John”
person.surname = “Smith”
return person
binds an object to the scope of a lambda expression
result of with operator is the object itself
lambda expression with single parameter
binary operator=> expressionleft operand
right operand
it can be omitted
executes lambda with left-hand side as the argument
result left operand after applying lambda

More Related Content

PPT
Xml Lecture Notes
PPT
Mapeamento de Objetos para o Modelo Relacional.ppt
PPT
Structure c
PPTX
Introduction to Python Programing
PDF
Python decision making
PPT
Java operators
PPTX
Python: The Iterator Pattern
PDF
Python programming : Classes objects
Xml Lecture Notes
Mapeamento de Objetos para o Modelo Relacional.ppt
Structure c
Introduction to Python Programing
Python decision making
Java operators
Python: The Iterator Pattern
Python programming : Classes objects

What's hot (20)

PPTX
Structure of c_program_to_input_output
PDF
PPT
Unit 4 Foc
PPTX
PPTX
Python Interview Questions | Python Interview Questions And Answers | Python ...
PDF
Programando em python excecoes
PDF
Java data types, variables and jvm
PPTX
python conditional statement.pptx
PDF
Plataforma iOS
PPT
Curso : Introdução Orientação a Objetos
PPT
How to execute a C program
PPT
Oops ppt
PPT
Exception handling and function in python
PPTX
Dynamic memory allocation and linked lists
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
PPTX
Day 1 Introduction to Python.pptx
PDF
Summation Operator
PPTX
Decision making and branching in c programming
PPT
Oop java
Structure of c_program_to_input_output
Unit 4 Foc
Python Interview Questions | Python Interview Questions And Answers | Python ...
Programando em python excecoes
Java data types, variables and jvm
python conditional statement.pptx
Plataforma iOS
Curso : Introdução Orientação a Objetos
How to execute a C program
Oops ppt
Exception handling and function in python
Dynamic memory allocation and linked lists
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Day 1 Introduction to Python.pptx
Summation Operator
Decision making and branching in c programming
Oop java
Ad

Similar to Xtend Programming Language (20)

PDF
The best of AltJava is Xtend
PDF
Xtend - better java with -less- noise
PPTX
Xbase implementing specific domain language for java
PDF
Invitation to Scala
PPTX
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
PDF
Introduction To Scala
ODP
Synapseindia reviews.odp.
PPT
JavaTutorials.ppt
PPT
Java tutorials
PPTX
Generics On The JVM (What you don't know will hurt you)
PDF
Scala Paradigms
PDF
Short intro to scala and the play framework
KEY
About java
PDF
Scala for Java Developers - Intro
PPT
java training faridabad
PPT
Java Fundamentals.pptJava Fundamentals.ppt
PPT
Java Tutorials
PPTX
Scala Back to Basics: Type Classes
PDF
Programming in scala - 1
The best of AltJava is Xtend
Xtend - better java with -less- noise
Xbase implementing specific domain language for java
Invitation to Scala
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
Introduction To Scala
Synapseindia reviews.odp.
JavaTutorials.ppt
Java tutorials
Generics On The JVM (What you don't know will hurt you)
Scala Paradigms
Short intro to scala and the play framework
About java
Scala for Java Developers - Intro
java training faridabad
Java Fundamentals.pptJava Fundamentals.ppt
Java Tutorials
Scala Back to Basics: Type Classes
Programming in scala - 1
Ad

More from Mikhail Barash (20)

PDF
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen
PDF
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...
PDF
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...
PDF
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity
PDF
Towards a mnemonic classification of software languages
PDF
Worst practices for domain-specific modelling
PPTX
An ABC of JetBrains MPS
PDF
KernelF: a functional core for domain-specific languages in JetBrains MPS
PDF
Reflections on teaching JetBrains MPS within a university course
PDF
Language Workbench Language Wheel
PDF
DSL development
PDF
Design concerns for concrete syntax
PDF
Design dimensions of DSLs
PDF
JetBrains MPS: Typesystem Aspect
PDF
JetBrains MPS: Editor Aspect
PDF
JetBrains MPS: Structure Aspect
PDF
Projectional editing
PDF
Xtext: type checking and scoping
PDF
Xtext: code generation
PDF
Xtext: validation, quickfixes, custom formatting
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity
Towards a mnemonic classification of software languages
Worst practices for domain-specific modelling
An ABC of JetBrains MPS
KernelF: a functional core for domain-specific languages in JetBrains MPS
Reflections on teaching JetBrains MPS within a university course
Language Workbench Language Wheel
DSL development
Design concerns for concrete syntax
Design dimensions of DSLs
JetBrains MPS: Typesystem Aspect
JetBrains MPS: Editor Aspect
JetBrains MPS: Structure Aspect
Projectional editing
Xtext: type checking and scoping
Xtext: code generation
Xtext: validation, quickfixes, custom formatting

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Transform Your Business with a Software ERP System
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
System and Network Administration Chapter 2
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Introduction to Artificial Intelligence
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
history of c programming in notes for students .pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PTS Company Brochure 2025 (1).pdf.......
How to Choose the Right IT Partner for Your Business in Malaysia
Operating system designcfffgfgggggggvggggggggg
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms I-SECS-1021-03
System and Network Administration Chapter 2
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administraation Chapter 3
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction to Artificial Intelligence
Wondershare Filmora 15 Crack With Activation Key [2025
history of c programming in notes for students .pptx
Reimagine Home Health with the Power of Agentic AI​

Xtend Programming Language

  • 1. Xtend statically typed Java-like language general purpose a better Java with less “noise” interoperable with Java possible to reuse Java libraries Java type system generics annotations more concise syntax type inference extension methods dispatch methods multiline template expressions Xtend programs translated to Java Xtend language implemented in Xtext can be used independently from Xtext
  • 2. Example of Xtend code less verbose than Java optional semicolons methods are public by default
  • 3. Xtend Methods, fields and variables no statements everything is an expression last expression in body is the return expressionmethod return type can be omitted if it can be inferred types must always be specifiedmethod params implicitly final (immutable) method definition: either def or override several classes can be defined in one file private by defaultfield
  • 4. Xtend Fields and variables val for final var for non-final == === compares the values of objects maps the operator to method equals object identifier equality in Java sense final fields and variables must be initialized o.getName()getters and setters o.name() o.setName(...) o.name = ...
  • 5. Xtend Extension methods UFCS Uniform function call syntax as in programming language D f(x) x.f() x.f f is not defined in MyType add new methods to existing types idea similar to class helpers as if f were a method of class MyType MyType x ... as in Delphi omitted parentheses
  • 6. Xtend Extension methods extension field of type T in class A – methods of T become extension methods in A extension variable – in code block extension parameter – in method body name is optional methods defined in Xtend class can be used as extension methods
  • 7. Xtend Implicit variable it class ItExamples { def func1(String it) { return toLowerCase // it.toLowerCase } def func2(String s) { var it = s toLowerCase // it.toLowerCase } } all members of it are implicitly available similar to this all members of this are available in an instance method
  • 8. Xtend Enhanced switch expressions def String switchExample(Entity e, Entity specialEntity) { switch e { case e.name.length > 0: “has a name” case e.superType != null: “inherits some entity” case specialEntity: “equals to special entity” default: “nothing” } } switch value – any object reference Boolean – case matches if true not Boolean – compare using equals Boolean – case matches if true
  • 9. Xtend Enhanced switch expressions def toString(FieldType fieldType) { switch (fieldType) { BasicType : fieldType.typeName EntityType : fieldType.entity.name } } only the selected case is executed in Java falls though all matching cases no need for explicit break instructions does not support break statementsXtend Type guards cases are evaluated in the specification order case matches only if switch value conforms to type
  • 10. Xtend Polymorphic method invocation method overloading static mechanism selection of the specific method according to static type of arguments class hierarchy: base class AnyType two classes NumberType, TextType method typeToString defined in another class static overloading would use AnyType NumberType desired – but only known at runtime multiple dispatch method selected according to runtime type of arguments
  • 11. Xtend Lambda expressions val l = [String s, int i | s + i] println(l.apply(“s”, 10)) val (String, int)=>String l = [String s, int i | s + i] val (String, int)=>String l = [s, i | s + i] def execute( (String, int)=>String f ) { f.apply(“s”, 10) } execute([s, i | s + i]) val list = newArrayList(“John”, “Mary”, “David”, “Alice”) Collections.sort(list, [arg0, arg1 | arg0.compareToIgnoreCase(arg1)]) Collections.sort(list) [arg0, arg1 | arg0.compareToIgnoreCase(arg1)] mystrings.findFirst[s | s.startsWith(“T”)] mystrings.findFirst[it.startsWith(“T”)] mystrings.findFirst[startsWith(“T”)] anonymous function can be stored in a variable can be passed to methods types for lambda expressions types can be omitted if can be inferred SAM (Single Abstract Method) known in Java as functional interfaces
  • 12. Xtend With operator return eINSTANCE.createPerson => [ name = “John” surname = “Smith” ] val person = eINSTANCE.createPerson person.name = “John” person.surname = “Smith” return person binds an object to the scope of a lambda expression result of with operator is the object itself lambda expression with single parameter binary operator=> expressionleft operand right operand it can be omitted executes lambda with left-hand side as the argument result left operand after applying lambda