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);
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations