use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class TraitTest method addModifyModifierAtRuntimeBackComp.
@Test
public void addModifyModifierAtRuntimeBackComp() {
Model model = assertParseOk("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("m", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt(), new SkipStmt())), false);
ModifyMethodModifier opr = new ModifyMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.addDeltaAccess(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(1, cls.getMethods().getNumChild());
assertEquals(2, cls.getMethod(0).getBlock().getNumChild());
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class ABSUnitTestCaseBuilder method initialiseDeltaForTestClass.
/**
* Initialise (create if necessary) a delta to modify the given test class.
* In particular it ensures the delta contains a class modifier for the
* given test class and within that modifier, a method modifier for the given
* method name.
*
* @param testClass
* @param setOrAssertMethodForTest
* @return the method block of the method modifier.
*/
Block initialiseDeltaForTestClass(ClassDecl testClass, String setOrAssertMethodForTest) {
String testClassName = testClass.getName();
DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
if (delta == null) {
delta = deltaBuilder.createDeltaFor(testClass);
}
ModifyClassModifier modifier = findClassOrIfaceModifier(delta, ModifyClassModifier.class, new ModifyClassModifierNamePredicate(testClassName));
if (modifier == null) {
modifier = new ModifyClassModifier();
modifier.setName(testClassName);
delta.addModuleModifier(modifier);
}
MethodSig sig = new MethodSig();
sig.setName(setOrAssertMethodForTest);
sig.setReturnType(getUnit());
// add an empty method to be modified
MethodImpl setOrAssertMethodForObjectImpl = new MethodImpl(sig, new Block(), false);
testClass.addMethod(setOrAssertMethodForObjectImpl);
ModifyMethodModifier mmm = new ModifyMethodModifier(setOrAssertMethodForObjectImpl.treeCopyNoTransform());
Block modifyBlock = mmm.getMethodImpl().getBlock();
modifier.addModifier(mmm);
return modifyBlock;
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class DeltaForGetSetFieldsBuilder method addGetter.
AddMethodModifier addGetter(Exp returnValue, String fieldName, Access returnType) {
MethodSig sig = new MethodSig(testCaseNameBuilder.getterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), returnType, new abs.frontend.ast.List<ParamDecl>());
Block block = new Block();
ReturnStmt rs = new ReturnStmt();
rs.setRetExp(new FieldUse(fieldName));
block.addStmtNoTransform(rs);
MethodImpl method = new MethodImpl(sig, block, false);
AddMethodModifier modifier = new AddMethodModifier(method);
return modifier;
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class HyperlinkInformationControl method widgetSelected.
@Override
public void widgetSelected(SelectionEvent e) {
if (firstSelect) {
// ignore the first selection event
firstSelect = false;
return;
}
MethodImpl m = implementingMethods.get(list.getSelectionIndex());
AbsHyperlinkDetector.jumpToPosition(editor, AbsHyperlinkDetector.getPosition(m));
dispose();
}
Aggregations