use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkConnectionStatement.
@Check(CheckType.FAST)
public void checkConnectionStatement(ConnectionStatement conn) {
Classifier container = conn.getContainingClassifier();
if (container instanceof ComponentImplementation) {
NamedElement aadlConn = conn.getConn();
if (aadlConn == null) {
return;
}
if (!(aadlConn instanceof Connection)) {
error(conn, "The connection label in the connection statement is not a connection");
return;
}
TypeDef rhsType = (AgreeTypeSystem.infer(conn.getExpr()));
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, rhsType)) {
error(conn, "The expression for the connection statement is of type '" + nameOfTypeDef(rhsType) + "' but must be of type 'bool'");
}
} else {
error(conn, "Connection statements are allowed only in component implementations.");
}
warning(conn, "Connection statements are deprecated and will be removed in a future version of AGREE.");
}
use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkLiftContract.
@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
Classifier comp = lcst.getContainingClassifier();
if (comp instanceof ComponentImplementation) {
ComponentType ct = ((ComponentImplementation) comp).getType();
List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (agreeAnnexes.size() > 0) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
}
List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
if (subcomps.size() == 1) {
Subcomponent subcomp = subcomps.get(0);
Classifier subCls = subcomp.getClassifier();
ComponentType subCt = null;
if (subCls instanceof ComponentImplementation) {
subCt = ((ComponentImplementation) subCls).getType();
} else if (subCls instanceof ComponentType) {
subCt = (ComponentType) subCls;
} else {
throw new RuntimeException();
}
{
Set<String> usedParentInPorts = new HashSet<>();
Set<String> usedParentOutPorts = new HashSet<>();
Set<String> usedChildInPorts = new HashSet<>();
Set<String> usedChildOutPorts = new HashSet<>();
EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
{
NamedElement sourceNe = conn.getSource().getConnectionEnd();
if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedChildOutPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
}
usedChildOutPorts.add(sourceNe.getName());
}
if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedParentInPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
}
usedParentInPorts.add(sourceNe.getName());
}
}
{
NamedElement destNe = conn.getDestination().getConnectionEnd();
if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedChildInPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
}
usedChildInPorts.add(destNe.getName());
}
if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedParentOutPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
}
usedParentOutPorts.add(destNe.getName());
}
}
}
for (Feature feat : comp.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedParentInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
}
} else {
if (!usedParentOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
}
}
}
for (Feature feat : subCt.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedChildInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
}
} else {
if (!usedChildOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
}
}
}
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component interface.");
}
}
use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkGuarantee.
@Check(CheckType.FAST)
public void checkGuarantee(GuaranteeStatement guar) {
Classifier comp = guar.getContainingClassifier();
if (!(comp instanceof ComponentType)) {
error(guar, "Guarantee statements are allowed only in component types");
}
// the expression could be null if a pattern is used
Expr expr = guar.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(guar, "Expression for guarantee statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
if (guar.getName() == null) {
info(guar, "It is recommended that guarantee statements be named." + " (Hint: an identifier may be placed between the \"guarantee\" keyword and the quoted description.)");
}
}
use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.
the class AgreeValidator method checkLemma.
@Check(CheckType.FAST)
public void checkLemma(LemmaStatement lemma) {
Classifier comp = lemma.getContainingClassifier();
if (!(comp instanceof ComponentImplementation)) {
error(lemma, "Lemma statements are allowed only in component implementations and nodes");
}
Expr expr = lemma.getExpr();
if (expr != null) {
TypeDef exprType = AgreeTypeSystem.infer(expr);
if (!AgreeTypeSystem.typesEqual(AgreeTypeSystem.Prim.BoolTypeDef, exprType)) {
error(lemma, "Expression for lemma statement is of type '" + nameOfTypeDef(exprType) + "' but must be of type 'bool'");
}
}
if (lemma.getName() == null) {
info(lemma, "It is recommended that lemma statements be named." + " (Hint: an identifier may be placed between the \"lemma\" keyword and the quoted description.)");
}
}
use of org.geotoolkit.sml.xml.v101.Classifier in project AGREE by loonwerks.
the class AgreeTypeSystem method typeDefFromNE.
public static TypeDef typeDefFromNE(NamedElement ne) {
if (ne instanceof Classifier) {
return typeDefFromClassifier((Classifier) ne);
} else if (ne instanceof RecordDef) {
EList<Arg> args = ((RecordDef) ne).getArgs();
Map<String, TypeDef> fields = new HashMap<>();
for (Arg arg : args) {
String key = arg.getName();
TypeDef typeDef = typeDefFromType(arg.getType());
fields.put(key, typeDef);
}
return new RecordTypeDef(ne.getQualifiedName(), fields, ne);
} else if (ne instanceof EnumStatement) {
String name = ne.getQualifiedName();
List<String> enumValues = new ArrayList<String>();
for (NamedID nid : ((EnumStatement) ne).getEnums()) {
String enumValue = name + "_" + nid.getName();
enumValues.add(enumValue);
}
return new EnumTypeDef(name, enumValues, ne);
} else if (ne instanceof Arg) {
return typeDefFromType(((Arg) ne).getType());
} else {
return Prim.ErrorTypeDef;
}
}
Aggregations