use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class OtherAnalysisTests method testContext1.
@Test
public void testContext1() {
// FIXME: the code in this example is incorrect (no await statement in init block allowed)
Model m = assertParseOk("data Unit; interface I { Unit m(); } class C implements I {{Unit x = await this!m();}}");
ClassDecl cd = (ClassDecl) m.lookupModule("UnitTest").getDecl(2);
AwaitAsyncCall n = (AwaitAsyncCall) down(cd);
assertNull("Rewrite failed!", n);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class OtherAnalysisTests method testContext2.
@Test
public void testContext2() {
// FIXME: the code in this example is incorrect (no await statement in init block allowed)
Model m = assertParseOk("data Unit; interface I { Unit m(); } class C implements I {{Unit x = await this!m();}}");
ClassDecl cd = (ClassDecl) m.lookupModule("UnitTest").getDecl(2);
AwaitAsyncCall n = (AwaitAsyncCall) down(cd);
assertNull("Rewriting failed!", n);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class WizardUtil method validateClass.
/**
* Same as {@link #validate(String)} but additionally checks, whether the specified
* class name already exists in the given module declaration
*
* @param text
* Name to be checked.
* @param decl
* Target ModuleDecl.
* @return In case of a duplicate name, this method returns
* ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
* its information string.
*/
public static ErrorType validateClass(String text, ModuleDecl decl) {
if (decl != null) {
for (Decl d : decl.getDecls()) {
if (d instanceof ClassDecl && d.getName().equals(text)) {
ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
type.setInformationString(text);
return type;
}
}
}
return validate(text);
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class FreeVarTest method fieldUse.
@Test
public void fieldUse() {
ClassDecl clazz = getFirstClassDecl(assertParseOkStdLib("class C {" + "Int i = 0;" + "Int m() {" + "return i + 1;" + "}" + "}"));
MethodImpl method = clazz.lookupMethod("m");
assertNotNull(method);
Stmt stmt = method.getBlock().getStmt(0);
assertTrue(stmt instanceof ReturnStmt);
ReturnStmt returnStmt = (ReturnStmt) stmt;
Exp exp = returnStmt.getRetExp();
assertEquals(exp.getFreeVars(), "i");
}
use of abs.frontend.ast.ClassDecl in project abstools by abstools.
the class OtherAnalysisTests method awaitRewriteModule1.
@Test
public void awaitRewriteModule1() {
Model.doAACrewrite = false;
Model m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}");
ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
Model.doAACrewrite = true;
m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.WITH_STD_LIB);
c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt s = c.getMethod(0).getBlock().getStmt(0);
VarDeclStmt b = (VarDeclStmt) s;
Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
assertEquals("A.X", t.getQualifiedName());
}
Aggregations