Search in sources :

Example 1 with Position

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);
    }
}
Also used : Position(org.sireum.message.Position) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance)

Example 2 with Position

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;
}
Also used : Arrays(java.util.Arrays) DataImplementation(org.osate.aadl2.DataImplementation) ListValue(org.osate.aadl2.ListValue) Element(org.osate.aadl2.Element) NamedValue(org.osate.aadl2.NamedValue) RangeValue(org.osate.aadl2.RangeValue) PropertyUtils(org.osate.xtext.aadl2.properties.util.PropertyUtils) PropertyExpression(org.osate.aadl2.PropertyExpression) AnnexLib(org.sireum.hamr.ir.AnnexLib) Classifier(org.osate.aadl2.Classifier) RecordValue(org.osate.aadl2.RecordValue) FeatureConnection(org.osate.aadl2.FeatureConnection) AccessImpl(org.osate.aadl2.impl.AccessImpl) Map(java.util.Map) ParameterConnection(org.osate.aadl2.ParameterConnection) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) Bundle(org.osgi.framework.Bundle) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) Annex(org.sireum.hamr.ir.Annex) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) DirectedFeatureImpl(org.osate.aadl2.impl.DirectedFeatureImpl) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) InstancePackage(org.osate.aadl2.instance.InstancePackage) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) BusAccessImpl(org.osate.aadl2.impl.BusAccessImpl) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory) Collectors(java.util.stream.Collectors) UnitLiteral(org.osate.aadl2.UnitLiteral) List(java.util.List) Property(org.osate.aadl2.Property) AccessType(org.osate.aadl2.AccessType) ReferenceValue(org.osate.aadl2.ReferenceValue) BusSubcomponentImpl(org.osate.aadl2.impl.BusSubcomponentImpl) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) StringLiteral(org.osate.aadl2.StringLiteral) Option(org.sireum.Option) Feature(org.osate.aadl2.Feature) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PreferenceValues(org.sireum.aadl.osate.PreferenceValues) DirectionType(org.osate.aadl2.DirectionType) Subcomponent(org.osate.aadl2.Subcomponent) Position(org.sireum.message.Position) FeatureGroup(org.osate.aadl2.FeatureGroup) NumberValue(org.osate.aadl2.NumberValue) FeatureGroupImpl(org.osate.aadl2.impl.FeatureGroupImpl) ClassifierValue(org.osate.aadl2.ClassifierValue) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) Some(org.sireum.Some) PropertyConstant(org.osate.aadl2.PropertyConstant) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataClassifier(org.osate.aadl2.DataClassifier) BooleanLiteral(org.osate.aadl2.BooleanLiteral) Platform(org.eclipse.core.runtime.Platform) NamedElement(org.osate.aadl2.NamedElement) FlowSpecificationInstance(org.osate.aadl2.instance.FlowSpecificationInstance) ConnectedElement(org.osate.aadl2.ConnectedElement) Position(org.sireum.message.Position) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with Position

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;
}
Also used : Position(org.sireum.message.Position) AadlASTJavaFactory(org.sireum.hamr.ir.AadlASTJavaFactory)

Example 4 with Position

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();
                    }
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Message(org.sireum.message.Message) CoreException(org.eclipse.core.runtime.CoreException) Position(org.sireum.message.Position) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

Position (org.sireum.message.Position)4 AadlASTJavaFactory (org.sireum.hamr.ir.AadlASTJavaFactory)3 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)2 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)2 ModeTransitionInstance (org.osate.aadl2.instance.ModeTransitionInstance)2 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 Platform (org.eclipse.core.runtime.Platform)1 EObject (org.eclipse.emf.ecore.EObject)1