Search in sources :

Example 1 with LocationReference

use of org.osate.aadl2.parsesupport.LocationReference in project osate2 by osate.

the class AadlBaTypeChecker method propertyNameListResolver.

private void propertyNameListResolver(EList<DeclarativePropertyName> dpns, EList<PropertyNameHolder> result) {
    PropertyNameHolder pnh = null;
    PropertyElementHolder peh = null;
    EList<IntegerValue> indexes = null;
    LocationReference loc = null;
    Element global, primary;
    for (DeclarativePropertyName dpn : dpns) {
        pnh = _fact.createPropertyNameHolder();
        pnh.setLocationReference(dpn.getLocationReference());
        global = dpn.getOsateRef();
        primary = dpn.getPropertyName().getOsateRef();
        if (// Item list case.
        primary != global) {
            loc = dpn.getPropertyName().getLocationReference();
            peh = propertyElementHolderResolver(primary, loc);
        } else {
            loc = dpn.getLocationReference();
            peh = propertyElementHolderResolver(global, loc);
        }
        indexes = peh.getArrayIndexes();
        if (dpn.getField() != null) {
            pnh.setField(dpn.getField());
        } else {
            for (IntegerValue iv : dpn.getIndexes()) {
                // Report any error.
                IntegerValue tmp = integerValueCheck(iv);
                if (tmp != null) {
                    indexes.add(tmp);
                }
            }
        }
        pnh.setProperty(peh);
        result.add(pnh);
    }
}
Also used : LocationReference(org.osate.aadl2.parsesupport.LocationReference) Element(org.osate.aadl2.Element) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) DeclarativePropertyName(org.osate.ba.declarative.DeclarativePropertyName)

Example 2 with LocationReference

use of org.osate.aadl2.parsesupport.LocationReference in project osate2 by osate.

the class AadlUtil method getInstanceOrigin.

// /**
// * Find the Element whose location reference is close to the line number.
// *
// * @param modelelement The model element used as root of the search
// * @param location line number
// * @return Element
// */
// public static Element findElement(Element modelelement, int location) {
// return doFindElement(modelelement, location, modelelement);
// }
// 
// /**
// * Find an Element whose reference location is the largest less or equal to
// * the location we are looking for. This find method cannot assume that the
// * elements of the object model are visited in unparse order. Therefore we
// * search the whole containment tree for the closest element whose location
// * reference is less or equal to the desired location.
// *
// * @param modelelement The model element and its sub elements to be visited
// * @param location The location as line whose Element equivalent we are
// *            trying to find
// * @param closestLocation the last Element whose location reference is less
// *            or equal than the location
// * @return Element the last visited Element whose location reference matches
// *         the condition
// */
// private static Element doFindElement(Element modelelement, int location, Element closestLocation) {
// LocationReference loc = modelelement.getLocationReference();
// if (loc != null) {
// int thisline = loc.getLine();
// if (thisline > location) {
// return closestLocation;
// } else if (thisline == location) {
// return modelelement;
// } else {
// // out location is less than the desired location. Check if it
// // closer than the previously remembered location
// LocationReference closeloc = closestLocation.getLocationReference();
// if (closeloc == null) {
// closestLocation = modelelement;
// } else if (thisline > closeloc.getLine()) {
// closestLocation = modelelement;
// }
// }
// }
// EList<EObject> list = modelelement.eContents();//getOwnedElements();		for (Iterator<Element> it = list.iterator(); it.hasNext();) {
// for (Iterator<EObject> it = list.iterator(); it.hasNext();) {
// Element child = (Element) it.next();
// Element result = doFindElement(child, location, closestLocation);
// if (result != closestLocation) {
// closestLocation = result;
// }
// }
// return closestLocation;
// }
// 
// private static final String PropertySetLabel = "propertySet[@name=";
// private static final String PackageLabel = "aadlPackage[@name=";
public static Element getInstanceOrigin(InstanceObject io) {
    List<? extends NamedElement> el = io.getInstantiatedObjects();
    Element target = null;
    if (el.size() == 0) {
        return null;
    } else if (el.size() == 1) {
        target = el.get(0);
    } else if (el.size() > 1) {
        for (NamedElement o : el) {
            if (o instanceof Connection) {
                Connection conn = (Connection) o;
                if ((conn.getAllSourceContext() instanceof Subcomponent && conn.getAllDestinationContext() instanceof Subcomponent) || (conn.getAllSourceContext() == null || conn.getAllDestinationContext() == null)) {
                    target = conn;
                    break;
                }
            }
        }
        if (target instanceof InstanceObject) {
            target = el.get(0);
        }
    }
    return target;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) ModalElement(org.osate.aadl2.ModalElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) FlowElement(org.osate.aadl2.FlowElement) ConnectedElement(org.osate.aadl2.ConnectedElement) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) ProcessorSubcomponent(org.osate.aadl2.ProcessorSubcomponent) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) NamedElement(org.osate.aadl2.NamedElement)

Example 3 with LocationReference

use of org.osate.aadl2.parsesupport.LocationReference in project osate2 by osate.

the class Aadl2LocationInFile method getTextRegion.

@Override
protected ITextRegion getTextRegion(EObject obj, boolean isSignificant) {
    ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
    /**
     * This is an old code that was initially removed but
     * added again to fix some bugs.
     * See. https://github.com/osate/osate2-ba/issues/1
     */
    if (node == null) {
        // it may be in annex
        if (obj instanceof AObject) {
            LocationReference locref = ((AObject) obj).getLocationReference();
            if (locref != null) {
                return new TextRegion(locref.getOffset(), locref.getLength());
            } else {
            // try AnnexSource adapter
            }
        }
        if (obj.eContainer() == null) {
            return ITextRegion.EMPTY_REGION;
        }
        return getTextRegion(obj.eContainer(), isSignificant);
    }
    /**
     * end of handling error with the behavior annex
     */
    List<INode> nodes = null;
    if (isSignificant) {
        nodes = getLocationNodes(obj);
    }
    if (nodes == null || nodes.isEmpty()) {
        nodes = Collections.<INode>singletonList(node);
    }
    return createRegion(nodes);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) LocationReference(org.osate.aadl2.parsesupport.LocationReference) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) AObject(org.osate.aadl2.parsesupport.AObject)

Example 4 with LocationReference

use of org.osate.aadl2.parsesupport.LocationReference in project osate2 by osate.

the class Aadl2Utils method getLocationReference.

/**
 * Return the location reference of the given Element object.
 *
 * @param e the given Element
 * @return a LocationReference object
 */
public static LocationReference getLocationReference(Element e) {
    LocationReference result = null;
    result = e.getLocationReference();
    if (result == null) {
        ICompositeNode node = NodeModelUtils.findActualNodeFor(e);
        result = new LocationReference();
        if (node != null && e.eResource() != null) {
            result.setFilename(e.eResource().getURI().lastSegment());
            result.setOffset(node.getOffset());
            result.setLength(node.getLength());
            result.setLine(node.getStartLine());
        } else {
            // DEBUG
            System.err.println("Aadl2Utils.getLocationReference: node or eResource " + "not found for " + e);
        }
    }
    return result;
}
Also used : LocationReference(org.osate.aadl2.parsesupport.LocationReference) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 5 with LocationReference

use of org.osate.aadl2.parsesupport.LocationReference in project osate2 by osate.

the class AadlBaTypeChecker method propertyElementHolderResolver.

private PropertyElementHolder propertyElementHolderResolver(Element el, LocationReference loc) {
    PropertyElementHolder result = null;
    if (el instanceof BasicProperty) {
        BasicProperty bp = (BasicProperty) el;
        BasicPropertyHolder tmp = _fact.createBasicPropertyHolder();
        tmp.setBasicProperty(bp);
        result = tmp;
    } else if (el instanceof PropertyAssociation) {
        PropertyAssociation pa = (PropertyAssociation) el;
        PropertyAssociationHolder tmp = _fact.createPropertyAssociationHolder();
        tmp.setPropertyAssociation(pa);
        result = tmp;
    } else if (el instanceof PropertyExpression) {
        PropertyExpression pe = (PropertyExpression) el;
        PropertyExpressionHolder tmp = _fact.createPropertyExpressionHolder();
        tmp.setPropertyExpression(pe);
        result = tmp;
    } else if (el instanceof PropertyType) {
        PropertyType pt = (PropertyType) el;
        PropertyTypeHolder tmp = _fact.createPropertyTypeHolder();
        tmp.setPropertyType(pt);
        result = tmp;
    } else if (el instanceof EnumerationLiteral) {
        EnumerationLiteral enumLit = (EnumerationLiteral) el;
        EnumLiteralHolder tmp = _fact.createEnumLiteralHolder();
        tmp.setEnumLiteral(enumLit);
        result = tmp;
    } else {
        String errorMsg = "type: " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    result.setLocationReference(loc);
    return result;
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) PropertyType(org.osate.aadl2.PropertyType) BasicProperty(org.osate.aadl2.BasicProperty) PropertyExpression(org.osate.aadl2.PropertyExpression) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Aggregations

LocationReference (org.osate.aadl2.parsesupport.LocationReference)3 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 Element (org.osate.aadl2.Element)2 NamedElement (org.osate.aadl2.NamedElement)2 INode (org.eclipse.xtext.nodemodel.INode)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 TextRegion (org.eclipse.xtext.util.TextRegion)1 AbstractSubcomponent (org.osate.aadl2.AbstractSubcomponent)1 ArrayableElement (org.osate.aadl2.ArrayableElement)1 BasicProperty (org.osate.aadl2.BasicProperty)1 ConnectedElement (org.osate.aadl2.ConnectedElement)1 Connection (org.osate.aadl2.Connection)1 DeviceSubcomponent (org.osate.aadl2.DeviceSubcomponent)1 EndToEndFlowElement (org.osate.aadl2.EndToEndFlowElement)1 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)1 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)1 FlowElement (org.osate.aadl2.FlowElement)1 ModalElement (org.osate.aadl2.ModalElement)1 ProcessSubcomponent (org.osate.aadl2.ProcessSubcomponent)1 ProcessorSubcomponent (org.osate.aadl2.ProcessorSubcomponent)1