Java 1.5 Language Features in Rose J

The following Java 1.5 constructs are preserved during round trip engineering:

•	Enumerations
•	For Each loop
•	AutoBoxing/UnBoxing

The following Java 1.5 constructs are supported during reverse engineering, however, only the bodies of the following constructs will be preserved during forward engineering.

•	Static Import
•	Generics
•	Variable Arguments (VarArgs)

The Java 1.5 construct, Annotations, is currently not supported during forward or reverse engineering.

Enumerations <refer Java Language specification, Third Edition>

Enumerations in Rose are provided with modeling, forward engineering and reverse engineering capabilities.  An Enumeration Specification is provided for Enumerations in parallel to Class Specification for a Class. 

The Enumeration Specification can be opened by (i) Double clicking an enumeration or (ii) selecting an enumeration > right click > Open Specification.

Creation of an Enumeration in Rose:

An enumeration in Rose is a Class with stereotype set to “Enum”. 

1)	Create a Class with a stereotype of “Enum”

Creation of Enumeration literals: 

The Enumeration Specification includes a page called “Enumeration Code”. This page is used to create Enumeration literals / constants. 

•	The “Enumeration literal” list box in the specification is used to add, rename, and delete enumeration literals. 
•	Every enum literal can have an optional enum body. The “Enumeration Constant Body <Read Only>” shows the optional enum body. This cannot be edited.
•	Selection of an enum constant in the list box shows it’s optional enum body in the edit box of  “Enumeration Constant Body <Read Only>”
•	The Preview button shows the complete list of enum constants with their enum body in the “Preview <Read Only>” edit box.

Forward Engineering and Reverse Engineering of Enumerations:

The code for the modeled enumeration can be generated using the Rose J code generator. It generates the complete, syntactically correct code. In addition, existing code containing enumerations can be reverse engineered to a rose model.

Code Sample:

public enum Month {
	January(31),
February(28),
	March(31),
	April(30),
	May(31),
	June(30),
	July(31),
	August(31),
	September(30),
	October(31),
	November(30),
	December(31);
	
	private final int days;

    Month(int days) {
        this.days = days;
    }

	public static void main(String[] args) {
                
		for(Month month : Month.values( ))
		{
			System.out.println(month+":"+month.days);
		}
		
    }}

				

For-Each Loop <refer Java Language specification, Third Edition>

For each loop can be used in the method body and enum body. 

Code Sample:

		for(Month month : Month.values( ))
		{
			System.out.println(month+":"+month.days);
		}

Static Import <refer Java Language specification, Third Edition>

Static imports will be recognized during reverse engineering. 
Note:  These imports will not be preserved in the rose model for further usage.

Code Sample:
	
	import static java.lang.Math.*;
	import static java.lang.Math.PI;

AutoBoxing/UnBoxing <refer Java Language specification, Third Edition>
Autoboxing and Unboxing code statements can occur inside the method body and enum body.

Code Sample:

	int i = 10;
Integer val = i; //Autoboxing
i=val+i; //Unboxing

Generics <refer Java Language specification, Third Edition>

Generics are supported during reverse engineering in Rose.

Code sample :

In the following example, T and E are type parameters. When reverse engineering, a nested class of stereotype is created, entitled “Generics”.  Type arguments in type are ignored i.e., List<String> is considered as List.

Variable Arguments <refer Java Language specification, Third Edition>

Variable Arguments or VarArgs will be recognized during reverse engineering.  The VarArgs are stored in the reverse engineered Rose Model as single dimensional arrays.

For Example the method specification for the VarArgs method 

static void trial(int y,int ... x)
	{
	System.out.println("documentation for varargs in java 1.5");
	}

will be as shown on the next page.

In this method specification the variable argument int …x has been converted to the single dimensional array int[] x in the model.