Commit 79b9e2fd authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ scoping refinements and safety checks

parent ec29d1ff
Loading
Loading
Loading
Loading
+40 −7
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import org.etsi.mts.tdl.DataElementMapping;
import org.etsi.mts.tdl.DataInstance;
import org.etsi.mts.tdl.DataInstanceUse;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.CollectionDataType;
import org.etsi.mts.tdl.CollectionDataInstance;
import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.Element;
import org.etsi.mts.tdl.ElementImport;
@@ -126,10 +128,12 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
					testDescription = ((TestDescriptionReference)context.eContainer()).getTestDescription();
				}
				TestConfiguration configuration = testDescription.getTestConfiguration();
				if (configuration!=null) {
					EList<ComponentInstance> components = configuration.getComponentInstance();
					IScope scope = Scopes.scopeFor(components);
					return scope;
				}
			} 
		} else if (reference.getEType().getInstanceClass() == GateReference.class) {
			//TODO: safety checks in case invalid configuration is specified
			//TODO: only suggest connected gates as targets?
@@ -157,6 +161,8 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
							if (oppositeNode != null) {
								String targetGateName = oppositeNode.getText()
										.replaceAll("(?s)where\\s+it\\s+is.+", "")
										.replaceAll("(?s)assigned\\s*.+", "")
										.replaceAll("(?s).+=\\s*", "")
										.replaceAll("(?s)with\\s*\\{.+", "")
										.trim();
								String[] split = targetGateName.split("\\.");
@@ -260,7 +266,9 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
									.allMembers());
							return scope;
						}
					} else if (context.eContainer().eContainer() instanceof ParameterBinding) {
					} else if (context.eContainer().eContainer() instanceof ParameterBinding && 
							((ParameterBinding)context.eContainer().eContainer()).getParameter().getDataType() instanceof StructuredDataType 
							) {
						IScope scope = Scopes.scopeFor(((StructuredDataType)((ParameterBinding)context.eContainer().eContainer()).getParameter().getDataType()).allMembers());
						return scope;
					}
@@ -299,6 +307,23 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
							IScope scope = Scopes.scopeFor(((StructuredDataType)((MemberReference)targetContext).getMember().getDataType()).allMembers());
							return scope;
						}
					} else if (((MemberReference)targetContext).getCollectionIndex()!=null) {
						if (targetContext.eContainer() instanceof DataInstanceUse) {
							DataInstanceUse dataInstanceUse = (DataInstanceUse)targetContext.eContainer();
							if (dataInstanceUse.getDataType()!=null) {
								//TODO:?
							} else if (dataInstanceUse.getDataInstance()!=null) {
								//TODO: check type
								DataType itemType = ((CollectionDataType)dataInstanceUse.getDataInstance().getDataType()).getItemType();
								if (itemType instanceof StructuredDataType) {
									IScope scope = Scopes.scopeFor(((StructuredDataType)itemType).allMembers());
									return scope;
								}
							}
						} else {
							//TODO: handle other scenarios?
						}
						
					}
				} 
				if (context.eContainer() instanceof DataInstanceUse) {
@@ -326,6 +351,9 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
					}
				} else {
				}
			} else if (context instanceof ValueAssignment) {
				IScope scope = Scopes.scopeFor(((ProcedureCall)context.eContainer().eContainer()).getSignature().getParameter());
				return scope;
			}
		} else if (reference.getEType().getInstanceClass() == Variable.class) {
			if (context instanceof Assignment) {
@@ -335,7 +363,7 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
				}
			}
			if (context instanceof VariableUse) {
				if (((VariableUse)context).getComponentInstance()!=null) {
				if (((VariableUse)context).getComponentInstance()!=null && ((VariableUse)context).getComponentInstance().getType()!=null) {
					IScope scope = Scopes.scopeFor(((VariableUse)context).getComponentInstance().getType().allVariables());
					return scope;
				}
@@ -347,7 +375,7 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
				}
			}
		} else if (reference.getEType().getInstanceClass() == Timer.class) {
			if (context instanceof TimerOperation) {
			if (context instanceof TimerOperation && ((TimerOperation)context).getComponentInstance().getType()!=null) {
				IScope scope = Scopes.scopeFor(((TimerOperation)context).getComponentInstance().getType().allTimers());
				return scope;
			}
@@ -414,7 +442,7 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
		}
	}
	
	private EList<EObject> getScopedElementsOfType(EObject context, Class c) {
	protected EList<EObject> getScopedElementsOfType(EObject context, Class c) {
		EList<EObject> elements = new BasicEList<>();
		Package p = getPackage(context);
		
@@ -422,6 +450,11 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
		for (PackageableElement e : p.getPackagedElement()) {
			if (c.isInstance(e)) {
				elements.add(e);
			} else if (e instanceof EnumDataType) {
				//TODO: naive enum handling (also below
				for (SimpleDataInstance ev : ((EnumDataType) e).getValue()) {
					elements.add(ev);
				}
			}
		}