...
 
Commits (2)
......@@ -6,6 +6,7 @@ Bundle-Version: 1.0.0.qualifier
Bundle-SymbolicName: org.etsi.mts.tdl.TDLan2; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.etsi.mts.tdl.model,
org.etsi.mts.tdl.common,
org.eclipse.xtext,
org.eclipse.xtext.xbase,
org.eclipse.equinox.common;bundle-version="3.5.0",
......
......@@ -12,7 +12,8 @@ Require-Bundle: org.etsi.mts.tdl.model,
org.eclipse.xtext.xbase.lib;bundle-version="2.14.0",
org.eclipse.xtext.util,
org.eclipse.xtend.lib,
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)"
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)",
org.etsi.mts.tdl.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.etsi.mts.tdl.scoping,
org.etsi.mts.tdl,
......
......@@ -62,7 +62,7 @@ ElementImport returns tdl::ElementImport:
|
(importedElement+=[tdl::PackageableElement|Identifier] ( "," importedElement+=[tdl::PackageableElement|Identifier])*)
)
'from' importedPackage=[tdl::Package|Identifier]
'from' (importedPackage=[tdl::Package|Identifier] | importedPackage=[tdl::Package|QIdentifier])
';';
Group returns tdl::Package:
......@@ -582,6 +582,7 @@ OmitValue returns tdl::OmitValue:
'omitted'
;
ParameterBinding returns tdl::ParameterBinding:
parameter=[tdl::Parameter|Identifier]
(comment+=NotQualifier)?
......@@ -841,6 +842,9 @@ BindingDataReference returns to::DataReference:
content=StaticDataUse
;
QIdentifier returns ecore::EString:
ID ('.' ID)+
;
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'/')*;
......
......@@ -52,56 +52,21 @@ import com.google.inject.Inject;
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping
* on how and when to use it.
*/
public class TPLan2ScopeProvider extends AbstractDeclarativeScopeProvider {
public class TPLan2ScopeProvider extends TDLScopeProvider {
@Inject
private IQualifiedNameConverter qualifiedNameConverter;
@Override
public IScope getScope(EObject context, EReference reference) {
if (PackageableElement.class.isAssignableFrom(reference.getEType().getInstanceClass())
&& !(context instanceof ElementImport)) {
EList<EObject> elements = getScopedElementsOfType(context, reference.getEType().getInstanceClass());
IScope scope = Scopes.scopeFor(elements);
return scope;
}
if (reference.getEType().getInstanceClass() == GateInstance.class) {
if (context instanceof GateReference) {
GateReference gate = (GateReference) context;
if (gate.getComponent().getType()!=null) {
IScope scope = Scopes.scopeFor(gate.getComponent().getType().getGateInstance());
return scope;
}
}
} else if (Parameter.class.isAssignableFrom(reference.getEType().getInstanceClass())) {
if (context instanceof MemberAssignment) {
if (context.eContainer() instanceof StructuredDataInstance) {
IScope scope = Scopes.scopeFor(((StructuredDataType)((StructuredDataInstance)context.eContainer()).getDataType()).allMembers());
return scope;
}
} else if (context instanceof ParameterBinding) {
if (context.eContainer() instanceof DataInstanceUse) {
if (((DataInstanceUse)context.eContainer()).getDataInstance() instanceof StructuredDataInstance) {
IScope scope = Scopes.scopeFor(((StructuredDataType)((StructuredDataInstance)((DataInstanceUse)context.eContainer()).getDataInstance()).getDataType()).allMembers());
return scope;
}
}
} else if (context instanceof MemberReference) {
if (((DataUse)context.eContainer()).getReduction().indexOf(context)>0) {
EObject targetContext = ((DataUse)context.eContainer()).getReduction().get(((DataUse)context.eContainer()).getReduction().indexOf(context)-1);
if (((MemberReference)targetContext).getMember()!=null) {
if (((MemberReference)targetContext).getMember().getDataType() instanceof StructuredDataType) {
IScope scope = Scopes.scopeFor(((StructuredDataType)((MemberReference)targetContext).getMember().getDataType()).allMembers());
return scope;
}
}
}
if (context.eContainer() instanceof DataInstanceUse) {
if (((DataInstanceUse)context.eContainer()).getDataInstance() instanceof StructuredDataInstance) {
IScope scope = Scopes.scopeFor(((StructuredDataType)((StructuredDataInstance)((DataInstanceUse)context.eContainer()).getDataInstance()).getDataType()).allMembers());
return scope;
}
}
} else if (context instanceof Content) {
// if (PackageableElement.class.isAssignableFrom(reference.getEType().getInstanceClass())
// && !(context instanceof ElementImport)) {
// EList<EObject> elements = getScopedElementsOfType(context, reference.getEType().getInstanceClass());
// IScope scope = Scopes.scopeFor(elements);
// return scope;
// }
if (Parameter.class.isAssignableFrom(reference.getEType().getInstanceClass())) {
if (context instanceof Content) {
if (context.eContainer() instanceof LiteralValue) {
if (((LiteralValue)context.eContainer()).getDataType() instanceof StructuredDataType) {
IScope scope = Scopes.scopeFor(((StructuredDataType)((LiteralValue)context.eContainer()).getDataType()).allMembers());
......@@ -143,61 +108,4 @@ public class TPLan2ScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope = super.getScope(context, reference);
return scope;
}
public IScope scope_ElementImport_importedElement(ElementImport context, EReference ref) {
EList<EObject> elements = new BasicEList<>();
Package ip = context.getImportedPackage();
for (PackageableElement e : ip.getPackagedElement()) {
elements.add(e);
}
IScope scope = Scopes.scopeFor(elements);
return scope;
}
private Package getPackage(EObject e) {
if (e.eContainer()!=null) {
if (e.eContainer() instanceof Package) {
return (Package)e.eContainer();
} else {
return getPackage(e.eContainer());
}
} else {
return (Package)e;
}
}
private EList<EObject> getScopedElementsOfType(EObject context, Class c) {
EList<EObject> elements = new BasicEList<>();
Package p = getPackage(context);
//within same package
for (PackageableElement e : p.getPackagedElement()) {
if (c.isInstance(e)) {
elements.add(e);
}
}
//within imported packages
for (ElementImport i : p.getImport()) {
Package ip = i.getImportedPackage();
if (ip != null) {
if (i.getImportedElement().isEmpty()) {
//import all
for (PackageableElement e : ip.getPackagedElement()) {
if (c.isInstance(e)) {
elements.add(e);
}
}
} else {
//specific imports
for (PackageableElement e : i.getImportedElement()) {
if (c.isInstance(e)) {
elements.add(e);
}
}
}
}
}
return elements;
}
}