import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import junit.framework.TestCase;
import junit.framework.TestSuite;
aspect RTXF {
class RTXF {
public static String sanitise(String s) {
return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll("\"", """);
}
public static String fieldref(FieldDeclaration fd) {
return "";
}
public static String tempref(Variable v) {
BodyDecl bd = null;
if(v instanceof VariableDeclaration)
bd = ((VariableDeclaration)v).hostBodyDecl();
else if(v instanceof ParameterDeclaration)
bd = ((ParameterDeclaration)v).hostBodyDecl();
else
throw new Error("cannot create tempref for " + v);
return "";
}
public static String program(int indent, Program prog) {
StringBuffer res = new StringBuffer();
res.append(indent(indent) + "\n");
for(Iterator iter = prog.compilationUnitIterator(); iter.hasNext();) {
CompilationUnit cu = iter.next();
if(cu.fromSource()) {
String path = cu.getPackageDecl();
if(!path.equals(""))
path = path + ".";
res.append(indent(indent+2) + "\n");
res.append(sanitise(cu.toString()) + "\n");
res.append(indent(indent+2) + "\n");
}
}
res.append(indent(indent) + "\n");
return res.toString();
}
public static String indent(int indent) {
StringBuffer res = new StringBuffer();
for(int i=0;i\n");
for(Program prog : progs)
res.append(program(indent+2, prog));
res.append(indent(indent) + "\n");
return res.toString();
}
public static void compare(rtxf.Result expected, Object actual) {
if(actual instanceof String) {
if(expected.getMayfail().equals("yes"))
return;
String expected_prog = Program.fromRTXF(expected.getProgram().get(0)).toString();
throw new junit.framework.ComparisonFailure(null, expected_prog, (String)actual);
} else {
String actual_prog = actual.toString();
String expected_prog = null;
for(rtxf.Program prog : expected.getProgram()) {
expected_prog = Program.fromRTXF(prog).toString();
if(expected_prog.equals(actual_prog))
return;
}
throw new junit.framework.ComparisonFailure(null, expected_prog == null ? "" : expected_prog, actual_prog);
}
}
public static TestSuite makeSuite(String path) {
TestSuite suite = new TestSuite();
try {
JAXBContext jc = JAXBContext.newInstance("rtxf");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Object res = unmarshaller.unmarshal(new File(path));
assert(res instanceof rtxf.Testsuite);
java.util.List tcs = ((rtxf.Testsuite)res).getTestcase();
for(int i=0; i fds = new ArrayList();
for(String fn : r.getFields()) {
FieldDeclaration fd = td.findField(fn);
assertNotNull(fd);
fds.add(fd);
}
try {
((ClassDecl)td).doExtractClass(fds, r.getClassname(), r.getFieldname(),
r.getEncapsulate().equals("yes"), r.getToplevel().equals("yes"));
RTXF.compare(tc.getResult(), in);
} catch (RefactoringException rfe) {
RTXF.compare(tc.getResult(), rfe.getMessage());
}
}
};
}
private static TestCase makeTestCase(final rtxf.Testcase tc, final rtxf.ExtractConstant r) {
return new TestCase(tc.getName()) {
public void runTest() {
rtxf.Program prog = tc.getProgram();
Program in = Program.fromRTXF(prog);
assertNotNull(in);
Expr e = in.resolveExpref(r.getExpref());
assertNotNull(e);
try {
e.doExtractConstant(r.getName());
RTXF.compare(tc.getResult(), in);
} catch (RefactoringException rfe) {
RTXF.compare(tc.getResult(), rfe.getMessage());
}
}
};
}
}
public String TypeDecl.rtxfId() {
throw new Error("cannot compute RTXF id for " + fullName());
}
public String ClassDecl.rtxfId() {
if(isTopLevelType())
return fullName();
if(getParent() instanceof MemberClassDecl)
return enclosingType().rtxfId() + "." + name();
if(getParent() instanceof LocalClassDeclStmt)
return hostBodyDecl().rtxfId() + "#" + name();
return super.rtxfId();
}
public String InterfaceDecl.rtxfId() {
if(isTopLevelType())
return fullName();
if(getParent() instanceof MemberInterfaceDecl)
return enclosingType().rtxfId() + "." + name();
return super.rtxfId();
}
public String GenericElement.rtxfId() {
return super.rtxfId();
}
public String TypeVariable.rtxfId() {
return owner().rtxfId() + "@" + name();
}
public String BodyDecl.rtxfId() {
return hostType().rtxfId();
}
public String MethodDecl.rtxfId() {
return hostType().rtxfId() + "." + signature();
}
public String ConstructorDecl.rtxfId() {
return hostType().rtxfId() + "." + signature();
}
public static Program Program.fromRTXF(rtxf.Program prog) {
if(prog.getCu() != null) {
RawCU[] cus = new RawCU[prog.getCu().size()];
for(int i=0;i