Jetbrains MPS As a Tool for Extending Java

Total Page:16

File Type:pdf, Size:1020Kb

Jetbrains MPS As a Tool for Extending Java JetBrains MPS as a Tool for Extending Java Vaclav Pech Alex Shatalin Markus Voelter JetBrains JetBrains independent/Itemis [email protected] [email protected] [email protected] Abstract bench [8], MetaEdit+1, Eclipse Xtext 2 and Spoofax 3 (for a JetBrains MPS is an integrated environment for language brief comparison of some of these tools see Related Work in Section 4). For a general overview of language workbenches, engineering. It allows language designers to define new pro- 4 gramming languages, both general-purpose and domain- please refer to the Language Workbench Competition . specific, either as standalone entities or as modular exten- Real-world use of MPS As a real-world proof of MPS, sions of already existing ones. Since MPS leverages the con- JetBrains has built YouTrack 5, a web-based bug tracking cept of projectional editing, non-textual and non-parseable application. It heavily relies on an MPS-based set of lan- syntactic forms are possible, including tables or mathemat- guages for web application development and database map- ical symbols. This tool paper introduces MPS and shows ping { Webr-DNQ. In less than three years YouTrack became how its novel approach can be applied to Java development. an important part of JetBrains' product portfolio, validating Special attention will be paid to the ability to modularize the LOP idea as well as its implementation in MPS. More and compose languages. on how YouTrack benefits from LOP can be found in [9]. Categories and Subject Descriptors D.2.6 [Software The MPS team cooperated with several universities to Engineering]: Programming Environments - Programmer help them adopt MPS as a tool for language design research. workbench For example, a student at the Faculty of Mathematics and Physics of Charles University in Prague implemented a real- General Terms D.3.2 Extensible languages, D.3.4 Code time Java development environment as part of his master generation, D.3.4 Translator writing systems and compiler thesis in 2012 [3]. generators Although MPS is historically bound to Java and the JVM, its principles are universal and can be applied to any Keywords language extension, DSLs, development envi- technological domain. The mbeddr project [11] successfully ronments, formal methods built a powerful development stack for embedded C develop- 1. Introduction ment. They primarily target programmers who write C code for micro-controllers in robots, avionics or car appliances. JetBrains MPS is an open-source language workbench based on a projectional editor. It started as an experimental Further plans Inspired by the success of YouTrack and project about ten years ago with the aim to test and vali- mbeddr, JetBrains has been gradually turning MPS into a date the ideas of Language Oriented Programming (LOP), solid open-source language workbench that is ready for the as summarized in [2]. In essence, MPS attempted to bring tasks in the mainstream of software development. The re- code generation and projectional editing (also known as cent 2.5 version can be considered a fully functional, stable structured editing, see [12] for a good definition) to the production-ready tool, targeting language and DSL design- programming mainstream, enabling easy language modular- ers as well as programmers. The open source license facili- ization and composition. The approach blurs the distinction tates adoption for open-source and academic use. between general-purpose (GPL) and domain-specific (DSL) programming languages with an intended positive impact on developer productivity. This paper introduces MPS, fo- cusing on extensibility of languages and IDEs in general and 2. Language Engineering in MPS for Java, specifically. Eating its own dog food, MPS, like many other language The term Language Workbench was coined by Mar- workbenches, offers a set of DSLs for defining various aspects tin Fowler [4]. Besides MPS, there are several other lan- of languages. These include the structure, editor, type sys- guage workbenches including the Intentional Domain Work- tem, the generator as well as support for sophisticated IDE functionality, such as code completion, intentions, refactor- ings, debugger and dataflow analysis. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. 1 Copyrights for third-party components of this work must be honored. http://metacase.com For all other uses, contact the owner/author(s). 2 http://eclipse.org/Xtext PPPJ'13,, September 11{13, 2013, Stuttgart, Germany.. 3 http://spoofax.org Copyright is held by the owner/author(s). 4 ACM 978-1-4503-2111-2/13/09. http://languageworkbenches.net http://dx.doi.org/10.1145/2500828.2500846 5 http://youtrack.jetbrains.com You may also check out two introductory screen-casts on inspect values in the high-level language (DSL), avoiding projectional editing in MPS 6 and on language definition7, exposure to the actual execution technology used. to get a concrete example of the discussed content. Type System The next step is the definition of the Abstract Syntax As a first step when defining a new type system. For example, the type of a condition of an language we specify the structure (aka abstract syntax or IfStatement must be boolean, or a type of a return state- meta model). This resembles object-oriented programming, ment must be compatible with the return type of the sur- language concepts are similar to classes. Concepts in MPS rounding method. MPS comes with a type system engine represent types of AST nodes and define the properties, that is capable of evaluating type system rules to assign methods, children and references that instance nodes may types to language elements (type inference) and to verify have. MPS offers three language aspects to define abstract correctness of types. Typing rules are specified as a set of syntax: the structure aspect defines the concepts, their prop- equations, such as the following: erties and relationships, constraints restrict the allowed set of values for properties and references, and the behavior as- infer typeof(ifStatement.condition) :<=: <boolean>; sociates methods with concepts. where the :<=: symbol specifies equal type or a subtype. The Concrete Syntax The second step is defining the editor engine tries to assign values to the type variables so that all for the concepts. This reflects the projectional nature of equations are satisfied. The declarative approach (based on MPS. Since code in MPS is never represented as plain unification8) enables easy extension of the type system by text (neither on the screen nor on disk), MPS languages adding additional equations and types. are never parsed and thus no grammar is required. This MPS also support checks that are not directly related enables the use of non-parseable notations, such as tables or to typing rules. A dedicated type of rules, called checking mathematical symbols. Instead of a parser, we define editors rules, may analyze the model and report warnings or errors for language concepts { a visual representation for AST whenever an incorrect construct is detected. Examples for nodes. MPS' editor definition capabilities let the language checking rules in Java include detecting the repetitive use designer define editors for her new language constructs as of the same string literal, assignment to a final variable, well as override editors of concepts from existing languages. ignoring a return value and many others. Language designers Editors can be modularized to support reuse of visual syntax may associate automated fixes with checking rules, which elements and multiple editors can be defined for a concept, users can choose to execute in order to fix the problem. allowing the programmer to choose the notation that fits Code generation Languages in MPS also define transfor- best the task at hands. mation rules to lower-level languages or to plain text. The The default MPS editor needs some getting used to generation process in MPS consists of two phases. Phase for programmers familiar with text editing. Building code one uses a template-based model-to-model transformation from predefined language concepts instead of from individual engine to reduce the program code into the target language, characters definitely feels different. However, MPS goes a based on reduction rules specified in the generator. The tar- long way towards the editing experience of text editors. The get language may be further reduced based on its own re- editor's behavior can be tuned by specifying many of its duction rules, and so on. When no further model-to-model dynamic characteristics using, for example, node factories, transformation is applicable to a model, the second phase side transformations, or replacement rules. uses text generators to convert that final model into regular IDE Functionality Developers today expect the editor program text that can be fed into a compiler. to instantly assist them with code completion, smart navi- A language generator aspect consists of two main build- gation, intentions, refactorings, hints and code analysis. Be- ing blocks. Mapping Configurations define which concepts ing able to quickly build an IDE for a language is one of the are processed with which templates and in which context. most noteworthy advantages of MPS. The editor offers many Templates define the code in the target language that will re- of its essential features out-of-the-box, the remainder can place the specified piece of the source concept(s). Templates be implemented by the language designer through appropri- work differently from normal text generation templates such ate language aspects. For example, whenever the developer as for example Xpand9, Jet10 or StringTemplate11, since in hits Ctrl-Space, the code-completion pop-up menu is auto- MPS they do not define text output, but instead model-to- matically populated with all type-compatible nodes that are model transformations.
Recommended publications
  • MPS 3.4 Tutorials
    MPS 3.4 Tutorials Formatted by Space2Latex from the MPS wiki 2016-09-30 i Credits The MPS user guide has evolved thanks to numerous big and small contributions of many contributors. Although most of the work has beed done by the individual members of the MPS core team, external MPS users have done their share, as well. On this page we list the prominent external contributors, who have helped evolve the user guide: • Markus Voelter • Marco Lombardo Contents Front cover i Credits i Contents ii I Start 1 1 Fast Track to MPS 2 1.1 Ten steps to mastery..............................................2 1.2 Step 1 - Install MPS...............................................2 1.3 Step 2 - MPS from the programmer’s perspective...............................2 1.4 Step 3 - MPS from the language designer’s perspective............................3 1.5 Step 4 - Creating your first language.....................................4 1.6 Step 5 - Why MPS...............................................5 1.7 Step 6 - Projectional editing tips and tricks..................................5 1.8 Step 7 - Shapes tutorial.............................................5 1.9 Step 8 - Calculator tutorial...........................................6 1.9.1 The Calculator tutorial in JavaScript..................................6 1.10 Step 9 - Other sample projects.........................................7 1.11 Step 10 - Generator tutorial...........................................8 1.12 Reviewing the progress.............................................8 1.13 Moving up the ladder..............................................9
    [Show full text]
  • An MPS Implementation for Simplic
    An MPS implementation for SimpliC Raphaël Castanier D11, Lund University, Sweden [email protected] Abstract a structure that allows better flexibility for language design, The goal of this study was to evaluate JetBrains language including extension and visualisation [9]. editor provided as an Open Source project called MPS (Meta- MPS represents programs in tree models stored in XML Programming System). One way to evaluate MPS perfor- files. The tree represents the structure of program and each mances for designing simple language compiler was to imple- node is called concept. Each concept can have hierarchical ment the SimpliC language in MPS through its projectional inheritance and specific rules, allowing complex structure editor. We will present in this paper what a projectional constructions. Thus, the program can be represented in the editor is and its opportunities for language design. Then editor, i.e. projected, into different views, using editor aspects. we will introduce basic concepts of language design in MPS For instance, the same program can be projected into textual through our SimpliC implementation, and discuss the lessons notation, diagram editor or symbolic editor [7]. Moreover, we learned from this. We also discuss an evaluation of this constraints and behaviours add rules to construct program process and present related academic work. structure. Finally, previous aspects of language contruction enable MPS to perform a lot of static analysis such as type 1 Introduction checking, name analysis and code generation. For educational purpose, we used a C-like language called Designing compilers is a complex task, requiring different SimpliC. SimpliC is a reduced-concepts language with most steps.
    [Show full text]
  • Alembicue: a Projectional Editor & IDE for Container Application Architecture
    Computer Science 18COC251 B627091 Alembicue: A projectional editor & IDE for container application architecture George Garside Supervisor: Dr. Daniel Reidenbach Loughborough University Summer 2019 Abstract The lack of a competent integrated development environment for Docker is a detriment to the field of containerisation and cloud computing. This project documents the development of Alembicue, a projectional and productive Docker IDE, implementing a more formally specified language definition, representative of what is necessary to create imagesfor use with a containerisation platform. Alembicue guarantees syntactic correctness with a projectional editor mutating an abstract syntax tree, incorporating contextual intentions and quick fixes to suggest and automatically apply standards and best practices. Alembicue’s launch has been a success, being received well by the community with tens of thousands of interested visitors to the project page, and elated testimonials from those having used the application and the innovative concepts portrayed within. Acknowledgements I would like to thank my supervisor, Dr. Daniel Reidenbach, for his consistent support and valuable feedback on my work. I would also like to thank my family and friends for their support in my studies. ii alembicate, v. 1627. transitive. Chiefly figurative: to produce, refine, or transform (an idea, emotion, etc.) as if in an alembic. Cf. alembicated adj. cue, n.2 1553. 1c. A stimulus or signal to perception, articulation, or other physiological response. Oxford English Dictionary (1989). alembicue, n. 2019. Chiefly emblematic: the juncture of the production of imagery and the container articulation process founded on the aforesaid. With apologies to linguists. iii Contents I Foundation 1 1 Introduction 2 1.1 Overview .
    [Show full text]
  • Deep, Seamless, Multi-Format, Multi-Notation Definition and Use of Domain-Specific Languages
    Deep, Seamless, Multi-format, Multi-notation Definition and Use of Domain-specific Languages Inauguraldissertation zur Erlangung des akademischen Grades eines Doktors der Naturwissenschaften der Universität Mannheim vorgelegt von Diplom-Wirtschaftsinformatiker Ralph Gerbig aus Worms Mannheim, 2017 Dekan: Professor Dr. Heinz Jürgen Müller, Unversität Mannheim Referent: Professor Dr. Colin Atkinson, Unversität Mannheim Korreferent: Professor Dr. Juan de Lara, Universidad Autónoma de Madrid Tag der mündlichen Prüfung: 24. Februar 2017 To Valerie. Acknowledgments I thank Colin Atkinson for the supervision and the support he provided during the last six exciting years. We had a lot of open minded and fruitful discussi- ons and he gave invaluable guidance and feedback on this dissertation and the Melanee tool. I also thank Juan de Lara, my second supervisor, for his input to this dis- sertation and the joint research. Especially, I want to thank him for hosting one of my students at the Universidad Autónoma de Madrid and the support he gave to this student during his master thesis. I thank all the students who contributed towards the success of this dis- sertation in the form of seminars and bachelor/master theses and as student assistants. Especially, I want to thank Nicole Wesemeyer, Katharina Markert, Daniel Gritzner and Dominik Kantner for their outstanding contributions to the Melanee tool. I thank Bastian Kennel, for supervising my diploma (cf. master) thesis on the topic of deep modeling. This built the foundation for all following research leading to the Melanee tool as it is today and the approach described in the dissertation. I thank Mathias Fritzsche for the opportunity to join him for an internship at SAP Research in Belfast where I had my first taste of research, model-driven development and Eclipse Plug-in development.
    [Show full text]