|
|
@@ -20,12 +20,9 @@ import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.emf.ecore.EReference;
|
|
|
import org.eclipse.emf.ecore.util.EcoreUtil;
|
|
|
import org.eclipse.xtext.EcoreUtil2;
|
|
|
-import org.eclipse.xtext.resource.IEObjectDescription;
|
|
|
import org.eclipse.xtext.scoping.IScope;
|
|
|
import org.eclipse.xtext.scoping.Scopes;
|
|
|
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
|
|
|
-import org.eclipse.xtext.scoping.impl.FilteringScope;
|
|
|
-import org.eclipse.xtext.scoping.impl.SimpleScope;
|
|
|
import org.eclipse.xtext.util.PolymorphicDispatcher.ErrorHandler;
|
|
|
import org.yakindu.base.expressions.expressions.ElementReferenceExpression;
|
|
|
import org.yakindu.base.expressions.expressions.Expression;
|
|
|
@@ -40,12 +37,9 @@ import org.yakindu.sct.model.sgraph.SGraphPackage;
|
|
|
import org.yakindu.sct.model.sgraph.Scope;
|
|
|
import org.yakindu.sct.model.sgraph.Statechart;
|
|
|
import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
|
|
|
-import org.yakindu.sct.model.stext.scoping.ContextPredicateProvider.EmptyPredicate;
|
|
|
import org.yakindu.sct.model.stext.stext.InterfaceScope;
|
|
|
import org.yakindu.sct.model.stext.stext.InternalScope;
|
|
|
|
|
|
-import com.google.common.base.Predicate;
|
|
|
-import com.google.common.collect.Iterables;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.inject.Inject;
|
|
|
|
|
|
@@ -60,9 +54,9 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
|
|
|
@Inject
|
|
|
private ITypeSystemInferrer typeInferrer;
|
|
|
- @Inject
|
|
|
+ @Inject
|
|
|
private ITypeSystem typeSystem;
|
|
|
-
|
|
|
+
|
|
|
private static class ErrorHandlerDelegate<T> implements ErrorHandler<T> {
|
|
|
|
|
|
private ErrorHandler<T> delegate;
|
|
|
@@ -83,7 +77,7 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public IScope getScope(EObject context, EReference reference) {
|
|
|
try {
|
|
|
@@ -98,31 +92,17 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Inject
|
|
|
- private ContextPredicateProvider predicateProvider;
|
|
|
-
|
|
|
- /**
|
|
|
- * Scoping for types and taking imported namespaces into account e.g. in
|
|
|
- * variable declarations.
|
|
|
- */
|
|
|
public IScope scope_TypeSpecifier_type(final EObject context, EReference reference) {
|
|
|
- IScope scope = getDelegate().getScope(context, reference);
|
|
|
- Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
|
|
|
- return new FilteringScope(scope, predicate);
|
|
|
+ return getDelegate().getScope(context, reference);
|
|
|
}
|
|
|
|
|
|
public IScope scope_ElementReferenceExpression_reference(final EObject context, EReference reference) {
|
|
|
- IScope namdScope = getNamedTopLevelScope(context, reference);
|
|
|
- IScope unnamedScope = getUnnamedTopLevelScope(context, reference);
|
|
|
- Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
|
|
|
- unnamedScope = new FilteringScope(unnamedScope, predicate);
|
|
|
- return new SimpleScope(Iterables.concat(namdScope.getAllElements(), unnamedScope.getAllElements()));
|
|
|
+ IScope scope = getUnnamedTopLevelScope(context, reference);
|
|
|
+ scope = getNamedTopLevelScope(context, reference, scope);
|
|
|
+ return scope;
|
|
|
}
|
|
|
|
|
|
public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
|
|
|
-
|
|
|
- Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
|
|
|
-
|
|
|
Expression owner = context.getOwner();
|
|
|
EObject element = null;
|
|
|
if (owner instanceof ElementReferenceExpression) {
|
|
|
@@ -138,53 +118,30 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
Type ownerType = result != null ? result.getType() : null;
|
|
|
|
|
|
if (element instanceof Scope) {
|
|
|
- scope = Scopes.scopeFor(((Scope) element).getDeclarations());
|
|
|
- return new FilteringScope(scope, predicate);
|
|
|
- }else if(ownerType != null){
|
|
|
+ return Scopes.scopeFor(((Scope) element).getDeclarations());
|
|
|
+ } else if (ownerType != null) {
|
|
|
scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
|
|
|
- scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType),scope);
|
|
|
+ scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (ownerType instanceof ComplexType) {
|
|
|
- return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
|
|
|
+ return addScopeForComplexType((ComplexType) ownerType, scope);
|
|
|
}
|
|
|
if (ownerType instanceof EnumerationType) {
|
|
|
- return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
|
|
|
+ return addScopeForEnumType((EnumerationType) ownerType, scope);
|
|
|
}
|
|
|
return scope;
|
|
|
}
|
|
|
|
|
|
- protected IScope addScopeForEnumType(EnumerationType element, IScope scope, final Predicate<IEObjectDescription> predicate) {
|
|
|
- scope = Scopes.scopeFor((element).getEnumerator(), scope);
|
|
|
- scope = new FilteringScope(scope, predicate);
|
|
|
- return scope;
|
|
|
- }
|
|
|
-
|
|
|
- protected IScope addScopeForComplexType(final ComplexType type, IScope scope, final Predicate<IEObjectDescription> predicate) {
|
|
|
- scope = Scopes.scopeFor(type.getAllFeatures(), scope);
|
|
|
- scope = new FilteringScope(scope, predicate);
|
|
|
- return scope;
|
|
|
+ protected IScope addScopeForEnumType(EnumerationType element, IScope scope) {
|
|
|
+ return Scopes.scopeFor((element).getEnumerator(), scope);
|
|
|
}
|
|
|
|
|
|
- private Predicate<IEObjectDescription> calculateFilterPredicate(final EObject context, final EReference reference) {
|
|
|
- Predicate<IEObjectDescription> predicate = null;
|
|
|
- EObject container = context;
|
|
|
- EReference ref = reference;
|
|
|
- while (container != null) {
|
|
|
- predicate = predicateProvider.getPredicate(container.eClass(), ref);
|
|
|
- if (!(predicate instanceof EmptyPredicate)) {
|
|
|
- break;
|
|
|
- }
|
|
|
- ref = (EReference) container.eContainingFeature();
|
|
|
- container = container.eContainer();
|
|
|
- }
|
|
|
- return predicate;
|
|
|
+ protected IScope addScopeForComplexType(final ComplexType type, IScope scope) {
|
|
|
+ return Scopes.scopeFor(type.getAllFeatures(), scope);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns the toplevel scope
|
|
|
- */
|
|
|
- protected IScope getNamedTopLevelScope(final EObject context, EReference reference) {
|
|
|
+ protected IScope getNamedTopLevelScope(final EObject context, EReference reference, IScope outer) {
|
|
|
List<EObject> scopeCandidates = Lists.newArrayList();
|
|
|
Statechart statechart = getStatechart(context);
|
|
|
if (statechart == null)
|
|
|
@@ -198,12 +155,9 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return Scopes.scopeFor(scopeCandidates);
|
|
|
+ return Scopes.scopeFor(scopeCandidates, outer);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns a scope with all toplevel declarations of unnamed scope
|
|
|
- */
|
|
|
protected IScope getUnnamedTopLevelScope(final EObject context, EReference reference) {
|
|
|
List<EObject> scopeCandidates = Lists.newArrayList();
|
|
|
Statechart statechart = getStatechart(context);
|
|
|
@@ -226,9 +180,6 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
|
|
|
return Scopes.scopeFor(scopeCandidates, scope);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns the {@link Statechart} for a context element
|
|
|
- */
|
|
|
protected Statechart getStatechart(EObject context) {
|
|
|
final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
|
|
|
ContextElementAdapter.class);
|