forked from INRIA/spoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/java/spoon/test/template/testclasses/transfo/Hello.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package spoon.test.template.testclasses.transfo; | ||
|
||
public class Hello { | ||
int a; | ||
int b; | ||
class Inner { | ||
public int i; | ||
} | ||
public void print(boolean tt) throws Exception{ | ||
a = 0; | ||
//asdasdsda | ||
System.out.println("a: " + a); | ||
} | ||
} | ||
|
||
class Test { | ||
float q; | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/java/spoon/test/template/testclasses/transfo/MyTrans.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package spoon.test.template.testclasses.transfo; | ||
|
||
import spoon.processing.AbstractProcessor; | ||
import spoon.template.Substitution; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.code.CtBlock; | ||
import spoon.reflect.code.CtStatement; | ||
import spoon.reflect.declaration.CtType; | ||
import spoon.template.ExtensionTemplate; | ||
import spoon.reflect.declaration.CtParameter; | ||
import spoon.support.reflect.declaration.CtParameterImpl; | ||
import spoon.reflect.reference.CtTypeReference; | ||
|
||
import spoon.template.Parameter; | ||
import spoon.template.Local; | ||
|
||
import java.util.*; | ||
|
||
public class MyTrans extends AbstractProcessor<CtClass> { | ||
public void process (CtClass ctClass) { | ||
CtParameter newPara = getFactory().createParameter(); | ||
newPara.setSimpleName("abc"); | ||
newPara.setType(getFactory().Type().floatPrimitiveType()); | ||
|
||
ParaTemp temp = new ParaTemp(); | ||
|
||
if (ctClass.getSimpleName().equals("Hello")) { | ||
for (Object mo : ctClass.getAllMethods()) { | ||
CtMethod m = (CtMethod)mo; | ||
if (m.getSimpleName().equals("print")) { | ||
temp.type = m.getType(); | ||
temp.mName = m.getSimpleName(); | ||
temp.body = m.getBody(); | ||
temp.thrownType = m.getThrownTypes(); | ||
|
||
temp.params = m.getParameters(); | ||
temp.params.add(newPara); | ||
} | ||
} | ||
Substitution.insertAll(ctClass, temp); | ||
} | ||
} | ||
} | ||
|
||
class ParaTemp extends ExtensionTemplate { | ||
public void mName(Object params) { | ||
body.S(); | ||
} | ||
|
||
@Parameter | ||
public List<CtParameter> params; | ||
@Parameter | ||
public String mName; | ||
@Parameter | ||
public CtBlock body; | ||
@Parameter | ||
public Set<CtTypeReference> thrownType; | ||
@Parameter | ||
public CtTypeReference type; | ||
} |