use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class DeltaForGetSetFieldsBuilder method addSetter.
/**
* Add an add method modifier
* @param fieldName
* @param exp
* @param decl
* @return
*/
AddMethodModifier addSetter(String fieldName, Access type) {
MethodSig sig = new MethodSig(testCaseNameBuilder.setterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), getUnit(), new abs.frontend.ast.List<ParamDecl>());
sig.addParam(new ParamDecl("v", type, new abs.frontend.ast.List<Annotation>()));
Block block = new Block();
block.addStmtNoTransform(getVAssign(new FieldUse(fieldName), new VarUse("v")));
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 DeltaForGetSetFieldsBuilder method updateDelta.
/**
* Add a delta that adds Getters and Setters for clazz.
*
* @param extensions
* @param interf
* @param clazz
*/
void updateDelta(Map<String, String> typeHierarchy, InterfaceTypeUse interf, ClassDecl clazz) {
String className = clazz.getName();
String deltaOnClassName = testCaseNameBuilder.deltaOnClass(className);
String interfaceForModifyingClassFieldName = testCaseNameBuilder.interfaceForModifyingFieldOfClass(className);
DeltaDecl dd = getDelta(deltaOnClassName);
if (dd != null) {
typeHierarchy.put(interf.getName(), interfaceForModifyingClassFieldName);
return;
}
dd = new DeltaDecl();
dd.setName(deltaOnClassName);
dd.addDeltaAccess(new DeltaAccess(clazz.getModuleDecl().getName()));
// add Setters and Getters
ModifyClassModifier mcm = new ModifyClassModifier();
mcm.setName(className);
InterfaceDecl ai = new InterfaceDecl();
ai.setName(interfaceForModifyingClassFieldName);
// extends the existing interface
InterfaceTypeUse inf = interf.treeCopyNoTransform();
ai.addExtendedInterfaceUse(inf.treeCopyNoTransform());
mcm.addAddedInterface(new InterfaceTypeUse(ai.getName(), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
typeHierarchy.put(inf.getName(), interfaceForModifyingClassFieldName);
for (MethodImpl m : clazz.getMethodList()) {
if (RUN_METHOD.equals(m.getMethodSig().getName())) {
mcm.addModifier(removeRun());
break;
}
}
for (FieldDecl fd : clazz.getFieldList()) {
AddMethodModifier smm = addSetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
AddMethodModifier gmm = addGetter(fd.getName(), fd.getAccess().treeCopyNoTransform());
mcm.addModifier(smm);
mcm.addModifier(gmm);
ai.addBody(smm.getMethodImpl().getMethodSig());
ai.addBody(gmm.getMethodImpl().getMethodSig());
}
dd.addModuleModifier(new AddInterfaceModifier(ai));
dd.addModuleModifier(mcm);
deltas.add(new DeltaWrapper(dd, false));
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class HyperlinkInformationControl method createContent.
@Override
protected void createContent(Composite parent) {
list = new org.eclipse.swt.widgets.List(parent, SWT.SINGLE);
for (MethodImpl m : implementingMethods) {
list.add(getDispayedString(m));
}
firstSelect = true;
list.addSelectionListener(this);
list.setBackground(parent.getBackground());
list.setForeground(parent.getForeground());
}
use of abs.frontend.ast.MethodImpl in project abstools by abstools.
the class ClassDeclGenerator method generateClassBody.
private void generateClassBody() {
// singleton() method instantiates strictly one dynamic class object and does initialisation,
// i.e. adds fields, constructor and methods.
stream.println("{");
stream.println("private static " + ABSDynamicClass.class.getName() + " instance;");
stream.println("public static void setInstance(" + ABSDynamicClass.class.getName() + " cls) { instance = cls; }");
stream.println("public static " + ABSDynamicClass.class.getName() + " singleton() {");
stream.println("if (instance == null) {");
stream.println("instance = new " + ABSDynamicClass.class.getName() + "();");
stream.println("instance.setName(\"" + decl.getName() + "\");");
// add class parameters
for (ParamDecl p : decl.getParams()) {
String name = JavaBackend.getVariableName(p.getName());
stream.println("instance.addField(\"" + name + "\", new " + ABSField.class.getName() + "());");
}
// add fields
for (FieldDecl f : decl.getFields()) {
String name = JavaBackend.getVariableName(f.getName());
stream.println("instance.addField(\"" + name + "\", " + className + ".field$" + name + ".singleton());");
}
// add constructor
stream.println("instance.setConstructor(" + className + ".CON$TRUCT.singleton());");
stream.print("instance.setParams(");
for (int i = 0; i < decl.getNumParam(); i++) {
if (i != 0)
stream.print(", ");
stream.print("\"" + JavaBackend.getVariableName(decl.getParam(i).getName()) + "\"");
}
stream.println(");");
// add methods
for (MethodImpl m : decl.getMethods()) {
String methodName = m.getMethodSig().getName();
stream.println("instance.addMethod(\"" + methodName + "\", " + className + "." + methodName + ".singleton());");
}
stream.println("}");
stream.println("return instance;");
stream.println("}");
// generate field inner classes
for (FieldDecl field : decl.getFields()) {
field.generateJavaDynamic(stream);
}
// generate CON$TRUCT inner class
generateConstructor();
// generate method inner classes
for (MethodImpl method : decl.getMethods()) {
method.generateJavaDynamic(stream);
// FIXME not sure how to handle FLI methods
if (method.isForeign()) {
stream.println("/* FLI method: not implemented yet */");
DynamicJavaGeneratorHelper.generateFLIMethod(stream, method);
}
}
generateCreateNewCOGMethod();
generateNewObjectMethods();
stream.println("}");
}
use of abs.frontend.ast.MethodImpl 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");
}
Aggregations