Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » How to inject code into java model MethodDeclaration
How to inject code into java model MethodDeclaration [message #883771] Sat, 09 June 2012 10:40 Go to next message
Federico Nicoli is currently offline Federico Nicoli
Messages: 6
Registered: June 2012
Junior Member
I tried to insert statements in a method but I can not put the statement in a specific place of the method, someone could help me ?
My input class :

public class prova {

	public void test1(){
	 String test1 ="";
	 test1.concat("test");
	 // ****  INJECTION *** ///
	 test1.concat("test");
	 test1.concat("test");
	}
	public void test2(){
		 String test1 ="";
		 test1.concat("test");
		 // ****  INJECTION *** ///
		 test1.concat("test");
		 test1.concat("test");
		}
}


And my ouput class should be :
public class prova {

	public void test1(){
	 String test1 ="";
	 test1.concat("test");
	 String test2 = "";
	 test1.concat("test");
	 test1.concat("test");
	}
	public void test2(){
		 String test1 ="";
		 test1.concat("test");
		 String test2 = "";
		 test1.concat("test");
		 test1.concat("test");
		}
}


My ATL trasformation :
module test;
create OUT : java from IN : java;

rule createStatement2 {
	from
		imd : java!MethodDeclaration(
			imd.name = 'test1' 
		)
		to		
			
		do{
			imd.body.statements  <- imd.body.statements  -> insertAt(3,thisModule.createFirstStatement(imd));
		}
}

rule createFirstStatement( cu:java!CompilationUnit) {
	to
		newStatement_1_VarDeclarationStat: java!VariableDeclarationStatement (
			originalCompilationUnit <- cu.originalCompilationUnit,
			type <- newStatement_1_TypeAccess_2,
			fragments <- newStatement_1_VariableDeclFragm
		)
		,newStatement_1_TypeAccess: java!TypeAccess (
			type <- java!ClassDeclaration.allInstances() -> select(e | e.name =
					'String') -> first()
		),
		newStatement_1_TypeAccess_2: java!TypeAccess (
			type <- java!ClassDeclaration.allInstances() -> select(e | e.name =
					'String') -> first()
		),
		newStatement_1_VariableDeclFragm: java!VariableDeclarationFragment (
			name <- 'sbQuery',
			originalCompilationUnit <- cu.originalCompilationUnit,
			variablesContainer <- newStatement_1_VarDeclarationStat,
			initializer <- newStatement_1_ClassInstanceCreat
		),
		newStatement_1_ClassInstanceCreat: java!ClassInstanceCreation (
			originalCompilationUnit <- cu.originalCompilationUnit,
			method <- java!ConstructorDeclaration.allInstances() -> select(e | e.name =
					'String') -> first(),
			type <- newStatement_1_TypeAccess
		)
	do {
		newStatement_1_VarDeclarationStat; 
	}
}

[Updated on: Sat, 09 June 2012 14:24]

Report message to a moderator

Re: How to inject code into java model MethodDeclaration [message #883772 is a reply to message #883771] Sat, 09 June 2012 10:41 Go to previous messageGo to next message
Federico Nicoli is currently offline Federico Nicoli
Messages: 6
Registered: June 2012
Junior Member
My problem is I can not make the inclusion in a place specified in the method
Re: How to inject code into java model MethodDeclaration [message #955245 is a reply to message #883772] Tue, 23 October 2012 16:35 Go to previous message
Cesar Caves is currently offline Cesar Caves
Messages: 22
Registered: July 2009
Junior Member
Hi Federico

Where is available the java meta-model (something like java.ecore, I guess...)? Thanks...
Previous Topic:EReference
Next Topic:Problems starting with "Create a simple ATL transformation"
Goto Forum:
  


Current Time: Wed Sep 24 02:42:46 GMT 2014

Powered by FUDForum. Page generated in 0.03239 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software