-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
method chaining only worked for method chains that were params of other methods
- Loading branch information
Showing
7 changed files
with
204 additions
and
39 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
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
113 changes: 113 additions & 0 deletions
113
VRL/VRL-Lang/src/test/java/eu/mihosoft/vrl/lang/model/MethodChainingTest.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,113 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package eu.mihosoft.vrl.lang.model; | ||
|
||
import eu.mihosoft.vrl.lang.model.transform.*; | ||
import eu.mihosoft.vrl.base.IOUtil; | ||
import eu.mihosoft.vrl.instrumentation.InstrumentationEventType; | ||
import eu.mihosoft.vrl.instrumentation.VRLInstrumentationUtil; | ||
import groovy.lang.GroovyClassLoader; | ||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Collection; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import junit.framework.Assert; | ||
import org.codehaus.groovy.control.CompilationFailedException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author Michael Hoffer <[email protected]> | ||
*/ | ||
public class MethodChainingTest { | ||
|
||
public static InputStream getResourceAsStream(String resourceName) { | ||
return CommentTest.class.getResourceAsStream("/eu/mihosoft/vrl/lang/" + resourceName); | ||
} | ||
|
||
public static Reader getResourceAsStringReader(String resourceName) { | ||
|
||
return new StringReader(getResourceAsString(resourceName)); | ||
} | ||
|
||
public static String getResourceAsString(String resourceName) { | ||
InputStream is = CommentTest.class.getResourceAsStream("/eu/mihosoft/vrl/lang/" + resourceName); | ||
String tmpCode = IOUtil.convertStreamToString(is); | ||
return tmpCode; | ||
} | ||
|
||
@Test | ||
public void methodChaining() { | ||
createInstrumentationTest("MethodChaining01.groovy"); | ||
} | ||
|
||
public void createInstrumentationTest(String fileName) { | ||
|
||
UIBinding.scopes.clear(); | ||
|
||
String code = getResourceAsString(fileName); | ||
|
||
// checking whether sample code compiles and generate model | ||
boolean successCompile = false; | ||
try { | ||
GroovyClassLoader gcl = new GroovyClassLoader(); | ||
gcl.parseClass(code); | ||
successCompile = true; | ||
|
||
} catch (Exception ex) { | ||
Logger.getLogger(LangModelTest.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
|
||
Assert.assertTrue(fileName + ": " + "Sample code must compile", successCompile); | ||
Assert.assertTrue(fileName + ": " + "UIBindings.scopes must be initialized", UIBinding.scopes != null); | ||
Assert.assertTrue(fileName + ": " + "UIBindings must contain exactly one scope, got " + UIBinding.scopes.size(), UIBinding.scopes.size() == 1); | ||
|
||
// generating new code from model | ||
String newCode = ""; | ||
CompilationUnitDeclaration cu = null; | ||
for (Collection<Scope> scopeList : UIBinding.scopes.values()) { | ||
for (Scope s : scopeList) { | ||
if (s instanceof CompilationUnitDeclaration) { | ||
cu = (CompilationUnitDeclaration) s; | ||
newCode = Scope2Code.getCode(cu); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
System.out.println(newCode); | ||
|
||
// InstrumentCode instrumentCode = new InstrumentCode(); | ||
// | ||
// CompilationUnitDeclaration newCu = instrumentCode.transform(cu); | ||
// | ||
// String instrumentedCode = Scope2Code.getCode(newCu); | ||
// | ||
// VRLInstrumentationUtil.addEventHandler(InstrumentationEventType.PRE_INVOCATION, | ||
// (evt) -> { | ||
// System.out.println("pre-evt:\t" + evt.toString()); | ||
// }); | ||
// VRLInstrumentationUtil.addEventHandler(InstrumentationEventType.POST_INVOCATION, | ||
// (evt) -> { | ||
// System.out.println("post-evt:\t" + evt.toString()); | ||
// }); | ||
|
||
// System.out.println(instrumentedCode); | ||
// | ||
// try { | ||
// GroovyClassLoader gcl = new GroovyClassLoader(); | ||
// Class<?> instrumentedCodeClass = gcl.parseClass(instrumentedCode); | ||
// instrumentedCodeClass.getMethod("main", String[].class). | ||
// invoke(instrumentedCodeClass, (Object) new String[0]); | ||
// | ||
// } catch (CompilationFailedException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | ||
// Logger.getLogger(LangModelTest.class.getName()).log(Level.SEVERE, null, ex); | ||
// } | ||
} | ||
} |
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
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
36 changes: 36 additions & 0 deletions
36
VRL/VRL-Lang/src/test/resources/eu/mihosoft/vrl/lang/Instrumentation03.groovy
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,36 @@ | ||
/* global comment*/ | ||
|
||
package my.testpackage; | ||
|
||
/** | ||
* class MyFileClass | ||
*/ | ||
@eu.mihosoft.vrl.instrumentation.VRLVisualization | ||
public class MyFileClass { | ||
|
||
private MyFileClass m(int a) { | ||
println("m: " + a); | ||
return this; | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
int a = 2+3*2; | ||
int b = 5-a; | ||
|
||
if (b<a) { | ||
println("a<b: " + (b < a)); | ||
} | ||
|
||
int i = 0; | ||
|
||
while(i<a) { | ||
println("i: " + i); | ||
i+=1; | ||
} | ||
|
||
MyFileClass mfc = new MyFileClass(); | ||
|
||
mfc.m(a).m(a) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
VRL/VRL-Lang/src/test/resources/eu/mihosoft/vrl/lang/MethodChaining01.groovy
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,20 @@ | ||
|
||
/** | ||
* | ||
* @author Michael Hoffer <[email protected]> | ||
*/ | ||
@eu.mihosoft.vrl.instrumentation.VRLVisualization | ||
public class MethodChaining01 { | ||
public MethodChaining01 mym(int a) { | ||
return this; | ||
} | ||
|
||
public MethodChaining01 mym2(int a) { | ||
return new MethodChaining01().mym(1).mym(1); ; | ||
} | ||
|
||
public static void main(String[] args) { | ||
new MethodChaining01().mym(1).mym2(2); | ||
} | ||
} | ||
|