1 / 29

A Survey on Java Modeling Languages

A Survey on Java Modeling Languages. Gergely Kovásznai , Eszterházy Károly College Wolfgang Schreiner , Johannes Kepler University Gábor Kusper , Eszterházy Károly College Gábor Guta , Johannes Kepler University János Sztrik , University of Debrecen. Goal.

levi
Download Presentation

A Survey on Java Modeling Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Survey on Java Modeling Languages Gergely Kovásznai, Eszterházy Károly College Wolfgang Schreiner, Johannes Kepler University Gábor Kusper, Eszterházy Károly College Gábor Guta, Johannes Kepler University János Sztrik, University of Debrecen

  2. Goal • A specification language is used to express the concepts of the programmer on a high level • using pre-conditions and post-conditions, • also called contracts, • and invariants. • The surveyed meta languages have also tools which can detectwhetherthe Java implementation breaks or not the high level description. • So we cansee the clauses of the high level design as syntactical or semantical constraints.

  3. Goal Motivation: Design Patterns & OODesign Principles Semantical constraint – Assertion Syntactical constraint outside Java Syntactical constraint inside Java

  4. Previous work • Austro – Hungarian Joint Research Project:Introducing Syntactical Constraints in Object-Oriented Programming Supporting Design Pattern Principles • Wolfgang Schreiner:A JML Specification of the Design Pattern "Proxy".RISC-Technical report, April 2009. • Gergely Kovasznai:Java Framework Implementing Design Patterns by the Use of JML and Contract4J.RISC-Technical report, 2009. • Wolfgang Schreiner:Supporting the Design Pattern "Object Structures as Plain Values".RISC-Technical report, September 2009.

  5. Java 1.4: Assert • Syntax: • assert Test ; • where Test is a boolean expression. When the system runs the assertion, it evaluates Test and if it is false throws an AssertionError with no detail message. • The second form of the assertion statement is: • assert Test : ErrorMessage ;

  6. Java 1.4: Assert • Example:public real division(int a, int b){ assert b!=0; …} • We cannot divide by zero. • We can test this in runtime by an assert.

  7. Java 1.4: Assert • To enable assertions use the -enableassertions, or -ea, switch. • To disable assertions use the -disableassertions, or -da, switch. • java –ea HelloWorld

  8. Goal Motivation: Design Patterns & OODesign Principles Semantical constraint – Assertion Syntactical constraint outside Java Syntactical constraint inside Java

  9. JML: “Java Modeling Language” • JML is a behavioral interface specification language. • In JML one can specify for each class • its interface, which consists of the names and static information found in Java declarations, • its behavior, which tells how the module acts when used.

  10. JML Example public class BankAccount { //@ invariant0<=balanceprivate short balance; /*@requires amount>=0;ensures balance== \old(balance-amount)&&\result==balance;@*/public int debit(int amount) { ...} }

  11. JML as a Contract Language • Precondition:requires <predicate> • Postcondition:ensures <predicate> • Invariant:invariant <predicate> • A predicate may contain: • Java literals • method calls, field references • Java operators • \forall, \exists, \max, \min, \sum, \result, \old etc.

  12. JML Example public class IntMathOps {/*@ public normal_behavior@ requires y >= 0;@ assignable \nothing;@ ensures 0 <= \result@ && \result * \result <= y@ && ((0 <= (\result + 1) * (\result + 1))@ ==> y < (\result + 1) * (\result + 1));@*/ public static int isqrt(int y){return (int) Math.sqrt(y);} }

  13. JML Assert • Assert: Specifies a predicate that should hold at some point in the code:assert <predicate> • Example:for(n=0; n<a.length; n++) if (a[n] == null) break;//@ assert(\forall int i; 0<=i && i<n; a[i]!=null);

  14. JML Tools • ESC/Java2 does static analysis • Iowa State’s JML release: • jml BankAccount.java • jmlc BankAccount.javajmlrac BankAccount • jmldoc BankAccount.java • OpenJML • JMLEclipse

  15. More JML tools • http://www.eecs.ucf.edu/~leavens/JML/

  16. Contract4J • Based on Aspect4J, Aspect Oriented Programming

  17. Contract4J • For each class and interface with a contract use: • @Contract • Precondition:@Pre(<predicate>) • Postcondition:@Post(<predicate>) • Invariant:@Invar(<predicate>) • Predicate: • Java literals • method calls, field references • Java operators • $this, $return, $old, $args[n] etc.

  18. Contract4J Example @Contract @Invar("$this.balance > = 0.0") interface BankAccount { @Post("$return >= 0.0") float getBalance(); @Pre("amount >= 0.0") @Post("$this.balance == $old($this.balance)+amount && $return == $this.balance") float deposit(float amount); }

  19. Contract4J Tools • Contract4J for Eclipse

  20. Goal Motivation: Design Patterns & OODesign Principles Semantical constraint – Assertion Syntactical constraint outside Java Syntactical constraint inside Java

  21. An OO Design Principle from GOF Program to an interface,not an implementation. • This means in practice the following:A client of a class may knowonly the interface of its abstract ancestor. • ,i.e., if the class has more services the client cannot call them, i.e., the ancestor is should be closed.

  22. Closed class in Contract4J • New constraint: closed class. • Def: A child of a closed class may not have public methods.

  23. Closed class in Contract4J @Invar("!Tool.hasPublicMethod($this.getClass())") public abstract class Decorator<R, A> implements IComponent<R, A>{...} … class Tool{public static boolean hasPublicMethod(Class c){ Method[] ms = c.getDeclaredMethods(); for(Method m : ms){ int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers)) return true; } return false; } }

  24. Goal Motivation: Design Patterns & OODesign Principles Semantical constraint – Assertion Syntactical constraint outside Java Syntactical constraint inside Java

  25. Other Java Meta Languages • Modern Jass, is a design by contract tool that works with the latest versions of Java and is closely related to JML.

  26. Modern Jass • @Invariant-define an invariant. • @Pre/@Post - Pre/Post-conditions • @SpecCase - A full method specification • @Also - A container for multiple specifications • @NonNull - A flyweight annotation to state that a reference is not null

  27. Modern Jass 1: package foo; 2: import jass.modern.*; 3: public class Bar { 4: @Pre("args.length % 2 == 0") 5: public static void main(String[] args){ 6: System.out.println("Hello,„ + args.length); 7: } }

  28. Modern Jass • Compiling / Validating contracts: • javac -cp .:jass.modern.core-20070519.jar foo/Bar.java • Running: • java -javaagent:jass.modern.core-20070519.jar foo.Bar

  29. Thank you for your attention! The side of our joint project: www.risc.uni-linz.ac.at/projects/syntactical

More Related