use of org.sireum.message.Position in project osate-plugin by sireum.
the class Visitor method buildEndPoint.
private org.sireum.hamr.ir.EndPoint buildEndPoint(ConnectionInstanceEnd cie) {
final List<String> component = Arrays.asList(cie.getComponentInstance().getInstanceObjectPath().split("\\."));
final Position componentPos = VisitorUtil.buildPosInfo(cie.getComponentInstance().getInstantiatedObjects().get(0));
if (cie instanceof FeatureInstance) {
final List<String> feature = Arrays.asList(cie.getInstanceObjectPath().split("\\."));
final Position featurePos = VisitorUtil.buildPosInfo(cie.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = handleDirection(((FeatureInstance) cie).getDirection());
return factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction);
} else if (cie instanceof ComponentInstance) {
return factory.endPoint(factory.name(component, componentPos), null, null);
} else if (cie instanceof ModeTransitionInstance) {
throw new RuntimeException("Need to handle ModeTransitionInstanceImpl: " + cie);
} else {
throw new RuntimeException("Unexpected: " + cie);
}
}
use of org.sireum.message.Position in project osate-plugin by sireum.
the class Visitor method buildEndPoint.
private List<org.sireum.hamr.ir.EndPoint> buildEndPoint(ConnectionInstanceEnd connInstEnd, List<String> path) {
List<org.sireum.hamr.ir.EndPoint> result = VisitorUtil.iList();
final List<String> component = Arrays.asList(connInstEnd.getComponentInstance().getInstanceObjectPath().split("\\."));
final Position componentPos = VisitorUtil.buildPosInfo(connInstEnd.getComponentInstance().getInstantiatedObjects().get(0));
if (connInstEnd instanceof FeatureInstance) {
FeatureInstance connElem = (FeatureInstance) connInstEnd;
String featurePre = connElem.getFeature().getName();
FeatureInstance temp = connElem;
while (temp.eContainer() instanceof FeatureInstance) {
featurePre = ((FeatureInstance) temp.eContainer()).getName() + "_" + featurePre;
temp = (FeatureInstance) temp.eContainer();
}
if (connElem.getCategory() == FeatureCategory.FEATURE_GROUP && !connElem.getFeatureInstances().isEmpty()) {
// Feature ff = connElem.getFeature().getRefined();
final String fp = featurePre;
result = VisitorUtil.addAll(result, connElem.getFeatureInstances().stream().flatMap(fii -> flattenFeatureGroupInstance(fii, fp, component, componentPos, false).stream()).collect(Collectors.toList()));
} else if (connElem.getCategory() == FeatureCategory.BUS_ACCESS) {
final List<String> feature = VisitorUtil.add(component, featurePre);
final Position featurePos = VisitorUtil.buildPosInfo(connElem.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = AadlASTJavaFactory.Direction.InOut;
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction));
} else {
final List<String> feature = VisitorUtil.add(component, featurePre);
final Position featurePos = VisitorUtil.buildPosInfo(connElem.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = handleDirection(connElem.getDirection());
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction));
}
// org.sireum.hamr.ir.Feature f = buildFeature(connElem, component);
// if(connElem.getCategory() == FeatureCategory.FEATURE_GROUP) {
// connElem.getFeatureInstances().forEach(fi -> {
//
// });
// }
// final List<String> component = (connElem.getgetContext() != null) && (connElem
// .getContext() instanceof Subcomponent)
// ? VisitorUtil.add(path, connElem.getContext().getName())
// : path;
} else if (connInstEnd instanceof ComponentInstance) {
result = VisitorUtil.toIList(factory.endPoint(factory.name(component, componentPos), null, null));
} else if (connInstEnd instanceof ModeTransitionInstance) {
throw new RuntimeException("Need to handle ModeTransitionInstanceImpl: " + connInstEnd);
} else {
throw new RuntimeException("Unexpected: " + connInstEnd);
}
if (result.size() > 1) {
// System.out.println("");
}
return result;
}
use of org.sireum.message.Position in project osate-plugin by sireum.
the class Visitor method flattenFeatureGroupInstance.
private List<org.sireum.hamr.ir.EndPoint> flattenFeatureGroupInstance(FeatureInstance fii, String featurePre, List<String> component, Position componentPos, Boolean isInverse) {
List<org.sireum.hamr.ir.EndPoint> result = VisitorUtil.iList();
if (fii.getCategory() == FeatureCategory.FEATURE_GROUP && !fii.getFeatureInstances().isEmpty()) {
result = fii.getFeatureInstances().stream().flatMap(fisl -> flattenFeatureGroupInstance(fisl, featurePre + "_" + fii.getName(), component, componentPos, isInverse).stream()).collect(Collectors.toList());
} else {
String fname = featurePre + "_" + fii.getName();
List<String> feature = VisitorUtil.add(component, fname);
final Position featurePos = VisitorUtil.buildPosInfo(fii.getInstantiatedObjects().get(0));
AadlASTJavaFactory.Direction dir = null;
if (isInverse) {
dir = (handleDirection(fii.getDirection()) == AadlASTJavaFactory.Direction.In) ? AadlASTJavaFactory.Direction.Out : AadlASTJavaFactory.Direction.In;
} else {
dir = handleDirection(fii.getDirection());
}
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), dir));
}
if (result.size() > 1) {
// System.out.println("");
}
return result;
}
use of org.sireum.message.Position in project osate-plugin by sireum.
the class LaunchHAMR method report.
/**
* Adds any message with position info to the OSATE problems view
* @param reporter
* @param si
*/
private void report(Reporter reporter, SystemInstance si) {
clearHamrMarkers(si);
for (int i = 0; i < reporter.messages().size().toInt(); i++) {
Message m = reporter.messages().apply(SlangUtils.toZ(i));
if (m.getPosOpt() == null) {
System.out.println("Sireum message's position info is null rather than None. Please report - " + m.getText());
} else if (m.getPosOpt().nonEmpty()) {
Position pos = m.getPosOpt().get();
if (pos.uriOpt().nonEmpty()) {
String uri = "/resource" + pos.uriOpt().get().value();
Resource r = null;
for (Resource cand : si.eResource().getResourceSet().getResources()) {
if (cand.getURI().path().equals(uri)) {
r = cand;
break;
}
}
if (r != null) {
IFile iresource = Util.toIFile(r.getURI());
try {
IMarker marker = iresource.createMarker(PreferenceValues.HAMR_MARKER_ID);
marker.setAttribute(IMarker.MESSAGE, m.getText().toString());
if (m.isError()) {
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
} else if (m.isWarning()) {
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
} else {
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
}
marker.setAttribute(IMarker.LINE_NUMBER, pos.beginLine().toInt());
if (pos.offset().toInt() != 0 && pos.length().toInt() > 0) {
marker.setAttribute(IMarker.CHAR_START, pos.offset().toInt());
marker.setAttribute(IMarker.CHAR_END, pos.offset().toInt() + pos.length().toInt());
}
} catch (CoreException e) {
// e.printStackTrace();
}
}
}
}
}
}
Aggregations