Commit 8ef9f4ee authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ scoping refinements for latest MM changes

parent df6f85e4
Loading
Loading
Loading
Loading
+53 −10
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import org.etsi.mts.tdl.FormalParameterUse;
import org.etsi.mts.tdl.FunctionCall;
import org.etsi.mts.tdl.GateInstance;
import org.etsi.mts.tdl.GateReference;
import org.etsi.mts.tdl.LiteralValueUse;
import org.etsi.mts.tdl.LocalExpression;
import org.etsi.mts.tdl.MappableDataElement;
import org.etsi.mts.tdl.MemberAssignment;
@@ -157,6 +158,13 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
				}
				EList<EObject> elements = new BasicEList<>();
				for (Connection c : configuration.getConnection()) {
					if (c.getEndPoint().get(0).getName() != null) {
						elements.add(c.getEndPoint().get(0));
					}
					if (c.getEndPoint().get(1).getName() != null) {
						elements.add(c.getEndPoint().get(1));
					}
					//TODO: also for procedure?!
					if (context instanceof Message) {
						//TODO: quick hack until a better solution is found
						//TODO: add further safety checks 
@@ -165,12 +173,16 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
							ICompositeNode oppositeNode = NodeModelUtils.findActualNodeFor(targets.get(0));
							if (oppositeNode != null) {
								String targetGateName = oppositeNode.getText()
										.replaceAll("(the|a|an)\\s+", "")
										.replaceAll("(?s)where\\s+it\\s+is.+", "")
										.replaceAll("(?s)assigned\\s*.+", "")
										.replaceAll("(?s).+=\\s*", "")
										.replaceAll("(?s)with\\s*\\{.+", "")
										.trim();
								String[] split = targetGateName.split("\\.");
								String[] split = targetGateName.split("\\."); //TODO: make configurable..
								if (targetGateName.contains("::")) {
									split = targetGateName.split("::");
								}
								if (split.length == 2) {
									String gate = split[1];
									String component = split[0];
@@ -228,7 +240,13 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
			        @Override 
			        public QualifiedName apply(EObject o) {
			        	GateReference r = (GateReference) o;
			        	if (r.getName()!=null) {
				            QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(r.getName());
				            return qualifiedName;
			        	}
			        	String n = r.getComponent().getName()+"."+r.getGate().getName();
			        	//TODO: make configurable
			        	n = r.getComponent().getName()+"::"+r.getGate().getName();
			            QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(n);
			            return qualifiedName;
			        }
@@ -321,10 +339,23 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
					} else if (dataElement instanceof StructuredDataType) {
						IScope scope = Scopes.scopeFor(((StructuredDataType)dataElement).allMembers());
						return scope;
					} else if (dataElement == null) {
						//TODO: use more widely! Will save a lot of the code in here...
						DataType resolvedDataType = ((DataElementUse)context.eContainer()).resolveDataType();
						if (resolvedDataType instanceof StructuredDataType) {
							IScope scope = Scopes.scopeFor(((StructuredDataType)resolvedDataType).allMembers());
							return scope;
						}
					}
						
//					IScope scope = Scopes.scopeFor(dataElement.eContents());
//					return scope;
				} else if (context.eContainer() instanceof LiteralValueUse) {
					DataType resolvedDataType = ((LiteralValueUse)context.eContainer()).resolveDataType();
					if (resolvedDataType instanceof StructuredDataType) {
						IScope scope = Scopes.scopeFor(((StructuredDataType)resolvedDataType).allMembers());
						return scope;
					}
				}
			} else if (context instanceof MemberReference) {
				if (((DataUse)context.eContainer()).getReduction().indexOf(context)>0) {
@@ -391,8 +422,20 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
					} else if (dataElement instanceof StructuredDataType) {
						IScope scope = Scopes.scopeFor(((StructuredDataType)dataElement).allMembers());
						return scope;
					} else if (dataElement == null) {
						//TODO: use more widely! Will save a lot of the code in here...
						DataType resolvedDataType = ((DataElementUse)context.eContainer()).resolveDataType();
						if (resolvedDataType instanceof StructuredDataType) {
							IScope scope = Scopes.scopeFor(((StructuredDataType)resolvedDataType).allMembers());
							return scope;
						}
					}
				} else if (context.eContainer() instanceof LiteralValueUse) {
					DataType resolvedDataType = ((LiteralValueUse)context.eContainer()).resolveDataType();
					if (resolvedDataType instanceof StructuredDataType) {
						IScope scope = Scopes.scopeFor(((StructuredDataType)resolvedDataType).allMembers());
						return scope;
					}

				} else {
				}
			} else if (context instanceof ValueAssignment) {
@@ -400,12 +443,13 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
				return scope;
			}
		} else if (reference.getEType().getInstanceClass() == Variable.class) {
			if (context instanceof Assignment) {
				if (((Assignment)context).getComponentInstance()!=null) {
					IScope scope = Scopes.scopeFor(((Assignment)context).getComponentInstance().getType().allVariables());
					return scope;
				}
			}
			//DONE: handle with new super class? -> no longer needed! (clean up)
//			if (context instanceof Assignment) {
//				if (((Assignment)context).getComponentInstance()!=null) {
//					IScope scope = Scopes.scopeFor(((Assignment)context).getComponentInstance().getType().allVariables());
//					return scope;
//				}
//			}
			if (context instanceof VariableUse) {
				if (((VariableUse)context).getComponentInstance()!=null && ((VariableUse)context).getComponentInstance().getType()!=null) {
					IScope scope = Scopes.scopeFor(((VariableUse)context).getComponentInstance().getType().allVariables());
@@ -444,7 +488,6 @@ public class TDLScopeProvider extends AbstractDeclarativeScopeProvider {
			//return Scopes.scopeFor(dataElement.eContents());
		}

		
		if (context instanceof Block) {
			TestDescription testDescription = getTestDescription((Element) context);
			if (testDescription!=null) {