Skip to content

Commit

Permalink
debug model consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Feb 16, 2017
1 parent 9421e2e commit 0c7d49d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/test/java/spoon/test/refactoring/ChangeVariableNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import static org.junit.Assert.*;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -73,6 +76,7 @@ public void testRenameLocalVariableToUsedName() throws Exception {
}
if (targetVariable instanceof CtLocalVariable<?>) {
if("nestedClassMethodWithShadowVar".equals(method.getSimpleName()) && "var1".equals(targetVariable.getSimpleName())) {
//@Martin, put breakpoint here and debug #printModelAndTestConsistency, which is called soon
this.getClass();
}
checkLocalVariableRename((CtLocalVariable<?>) targetVariable, newName, renameShouldPass);
Expand Down Expand Up @@ -134,12 +138,31 @@ private void printModelAndTestConsistency(String refactoringDescription) {
}
// 3) create instance using that new model and test consistency
try {
varRenameClass.newInstance();
// varRenameClass.newInstance();
TestClassloader classLoader = new TestClassloader();
Class testModelClass = classLoader.loadClass(VariableRename.class.getName());
testModelClass.newInstance();
} catch (Throwable e) {
new AssertionError("The model validation of code in "+launcher.getEnvironment().getBinaryOutputDirectory()+" failed after: "+refactoringDescription, e);
}
}

private class TestClassloader extends URLClassLoader {
TestClassloader() throws MalformedURLException {
super(new URL[] { new File(launcher.getEnvironment().getBinaryOutputDirectory()).toURL()}, ChangeVariableNameTest.class.getClassLoader());
}

@Override
public Class<?> loadClass(String s) throws ClassNotFoundException {
try {
return findClass(s);
} catch (Exception e) {
return super.loadClass(s);
}
}
}


private String getParentMethodName(CtElement ele) {
CtMethod parentMethod = ele.getParent(CtMethod.class);
CtMethod m;
Expand Down

0 comments on commit 0c7d49d

Please sign in to comment.