System Description

         The project goal is to increase developers productivity when implementing applications in the Java language. In order to achieve this goal, we intend to build a system capable of, from a source program written in Java, obtain others based on transformations defined by the developer.
         Before we illustrate how a transformation is done, it is important to explain some concepts needed to understand how the system works. Transformations in JaTS are constructed in a language that consists of Java extended by JaTS constructions. These constructions make program matching possible. The most usual JaTS construction is the JaTS variable, any string preceded by the character "#".
         A JaTS transformation consists of two parts: a source file and a destination file. The source file is matched with the Java source program that we wish to transform. In order for the matching to succeed, the source file and the Java source program must have the same basic syntactic structure. The destination file is the skeleton of the program that will be the produced by the transformation.
         We use a simple example to illustrate the steps for applying a transformation to a Java program. Throughout the example, we explain some of the concepts mentioned above in greater detail.

         Consider the following Java source program:

public class TestJaTS extends Test {
    
    TestJaTS() {
    
    }    
    
    public void singleMethod() throws WeakException {   
    
    }
    
}    
         We want to apply to this program a transformation that has the following source file:

public class #a extends #b {
	
    #a() {
	    
    }   
    
    public void #c() throws #d { 
	    
    } 
    
}  
         And the following destination file:

public class #a extends #b {
	
    #a(int numberOfTests) {
    
    }
     
    #a() {
    
    }
    
    public synchronized void #c() throws #d, SomethingGoneTerriblyWrongException {
     
    }
    
}  
         The first step of a transformation application is the program matching. During this step, a pattern matching between the syntactic trees of the transformation source file and of the Java source program is performed. Both trees are traversed with the intent of verifying if they are compatible. By compatible, we mean that for every node in the tree of the Java source program, there is an identical node or a node representing a variable in the tree of the transformation source file, in the corresponding position.
         Putting this in the context of our example and thinking not in terms of nodes in a syntactic tree, but in terms of words in a program, the first two words of the source file and of the Java source program are identical (public and class), but the third words are not. In the Java source program, the third word, corresponding to the name of the class, is TestJaTS. In the source file, however, the third word is #a. Although they are not identical, these two words match because, as mentioned before, a word matches an identical word or a JaTS variable, and #a is a JaTS variable. Following the same idea, the name of the superclass of TestJaTS, Test, matches the variable #b, the name of the method singleMethod matches the variable #c, and the exception WeakException matches #d. The output of the program matching step is a result set which consists of mappings between variables and the nodes that matched with them. In the above example, the result set is { #a -> TestMatch, #b -> Test, #c -> singleMethod, #d -> WeakException }.
         The second step of a transformation application is the replacement. This step receives as input the transformation's destination file and the result set produced by the program matching. During the replacement step, the syntactic tree of the transformation's destination file is transversed according to the Visitor design pattern. Whenever a variable is found, it is verified if this variable is present on the result set. If it is and the value mapped is valid, the variable is replaced in the tree by this value. By valid value, we mean that the object that is mapped to that variable in the result set is equal or compatible with the type of node where the variable was found in the syntactic tree. For example, a variable representing the method return type can be replaced by a class name or a parameter type, but not by an interface list.
         In the above example, the result program of the replacement step is:

public class TestMatch extends Test {
	
    TesteMatch(int numberOfTests) { 
	    
    }  
    
    TestMatch() {    
	    
    }   
    
    public synchronized void singleMethod() throws WeakException,
          SomethingGoneTerriblyWrongException { 
    } 
    
}