Commit afbc0dd1 authored by Sudeep Kanav's avatar Sudeep Kanav
Browse files

YELLOW

parent 1af4a4d6
......@@ -17,8 +17,6 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.specification.ui.ocra.databinding;
import static org.fortiss.af3.expression.utils.ExpressionUtils.formatStatements;
import org.eclipse.core.databinding.conversion.Converter;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.ocra.model.contract.Contract;
......@@ -26,41 +24,24 @@ import org.fortiss.af3.ocra.model.contract.Contract;
/**
* {@link Converter} from {@link Contract} to {@link String}.
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8E0676CD80DD58A180162FED58D9CC28
* @ConQAT.Rating YELLOW Hash: 2675134C9ACA051DE64F32ED364AAAAF
*/
public class ContractToStringConverter extends Converter {
/** Stores whether the statements are to be returned formatted. */
// TODO(VA) why do you need this?
private final boolean formatContract;
/** Constructor */
public ContractToStringConverter(boolean formatContract) {
public ContractToStringConverter() {
super(Contract.class, String.class);
this.formatContract = formatContract;
}
/** {@inheritDoc} */
@Override
public Object convert(Object fromObject) {
// TODO(VA) This might fit in two lines if you introduce a variable for (Contract)fromObject
// and use a " ... ? ... : ...." construct
if(formatContract) {
return formatStatements(((Contract)fromObject).toString());
}
return contractToString(((Contract)fromObject));
}
/**
* TODO Supposedly the toString method. It can be moved to the static implementation if the need
* arises and we think of doing it in the way things are done for expressions. I think decision
* can be deferred to the code review phase.
*/
// TODO(VA) Take your own TODO into account. If the need did not show up, then I'd leave it this
// way.
/** Returns the string representation of a contract. */
private String contractToString(Contract c) {
StringBuffer buf = new StringBuffer();
buf.append("CONTRACT " + c.getName() + "\n");
......@@ -68,13 +49,15 @@ public class ContractToStringConverter extends Converter {
buf.append("guarantee: " + c.getGuarantee().toString() + ";\n");
if(!c.getRefinedBy().isEmpty()) {
buf.append("REFINEDBY ");
// TODO(VA,19)
c.getRefinedBy().forEach(
con -> buf.append(((Component)con.eContainer().eContainer()).getName() + "." +
con.getName() + ", "));
c.getRefinedBy().forEach(con -> buf.append(getQualifiedContractName(con)));
buf.delete(buf.length() - 2, buf.length());
buf.append(";");
}
return buf.toString();
}
/** Returns the qualified contract name, i.e., <component.contract> */
protected String getQualifiedContractName(Contract con) {
return ((Component)con.eContainer().eContainer()).getName() + "." + con.getName() + ", ";
}
}
......@@ -34,7 +34,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BFB301B62FBF468D4A14F6479F7185D9
* @ConQAT.Rating YELLOW Hash: 0CBC7AF7222C1B60D8EDCECAAD611F94
*/
public class StringToContractConverter extends Converter {
......@@ -59,22 +59,20 @@ public class StringToContractConverter extends Converter {
Contract oldCon = ((ContractContainer)context).getContract();
ITopLevelElement modelContext =
IPersistencyService.getInstance().getTopLevelElementFor(context);
// TODO(VA) Use the construct "() -> ..." instead of a Runnable: more concise
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
oldCon.setAssume(newCon.getAssume());
oldCon.setGuarantee(newCon.getGuarantee());
oldCon.setName(newCon.getName());
oldCon.getRefinedBy().clear();
oldCon.getRefinedBy().addAll(newCon.getRefinedBy());
}
});
modelContext.runAsCommand(() -> updateContract(newCon, oldCon));
return oldCon;
} catch(final Exception e) {
error(getDefault(), "Had conversion problems not caught by the validator", e);
}
return null;
}
/** Updates and old contract with a new one. */
private void updateContract(Contract newCon, Contract oldCon) {
oldCon.setAssume(newCon.getAssume());
oldCon.setGuarantee(newCon.getGuarantee());
oldCon.setName(newCon.getName());
oldCon.getRefinedBy().clear();
oldCon.getRefinedBy().addAll(newCon.getRefinedBy());
}
}
......@@ -30,10 +30,9 @@ import org.fortiss.af3.ocra.model.contract.Contract;
/**
* {@link IValidator} for {@link String} to {@link Contract} conversion.
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 8476645DADF5823BC98DB3152403BE40
* @ConQAT.Rating YELLOW Hash: 56AC93688E1DEA39D128BD64B350E1CB
*/
public class StringToContractValidator implements IValidator {
/** Stores the type system compiler. */
......
......@@ -33,7 +33,7 @@ import org.fortiss.af3.specification.ui.ocra.databinding.StringToContractValidat
*
* @author doebber
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: C7F49401A7A15BEF6D0A0D7294B68D2F
* @ConQAT.Rating YELLOW Hash: 4A4CE1D8C4BA1866B091A1E90E0EFCCC
*/
public class ContractSpecificationEditor extends CodeSpecificationEditor {
......@@ -51,7 +51,7 @@ public class ContractSpecificationEditor extends CodeSpecificationEditor {
observeValue(getEditedObject(), CONTRACT_CONTAINER__CONTRACT);
performComplexTextBinding(dbc, codeViewer.getTextWidget(), modelObservable,
new ContractToStringConverter(false), new StringToContractConverter(
getEditedObject()), new StringToContractValidator(getEditedObject()), null);
new ContractToStringConverter(), new StringToContractConverter(getEditedObject()),
new StringToContractValidator(getEditedObject()), null);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment