Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #502 from Yakindu/issue_500
Browse files Browse the repository at this point in the history
Moved filter on EnumerationType to context predicate. Added scoping f…
  • Loading branch information
tkutz committed Mar 17, 2016
2 parents c29159e + d07ed95 commit 212abc8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@
*/
public class ContextPredicateProvider {

static class TypePredicate implements Predicate<IEObjectDescription> {
public static class TypePredicate implements Predicate<IEObjectDescription> {
public boolean apply(IEObjectDescription input) {
return TypesPackage.Literals.TYPE.isSuperTypeOf(input.getEClass())
&& !TypesPackage.Literals.TYPE_PARAMETER.isSuperTypeOf(input.getEClass());
}
}

static class FeaturedTypePredicate implements Predicate<IEObjectDescription> {
public static class FeaturedTypePredicate implements Predicate<IEObjectDescription> {
public boolean apply(IEObjectDescription input) {
return TypesPackage.Literals.TYPE.isSuperTypeOf(input.getEClass())
&& TypesPackage.Literals.DECLARATION.isSuperTypeOf(input.getEClass());
}
}

static class EventPredicate extends FeaturedTypePredicate {
public static class EventPredicate extends FeaturedTypePredicate {
@Override
public boolean apply(IEObjectDescription input) {
if (super.apply(input))
Expand All @@ -91,7 +91,7 @@ protected boolean isComplexTypeVariable(IEObjectDescription input) {
}
}

static class VariablePredicate extends FeaturedTypePredicate {
public static class VariablePredicate extends FeaturedTypePredicate {
@Override
public boolean apply(IEObjectDescription input) {
if (super.apply(input))
Expand All @@ -101,7 +101,7 @@ public boolean apply(IEObjectDescription input) {

};

static class VariableOperationPredicate extends FeaturedTypePredicate {
public static class VariableOperationPredicate extends FeaturedTypePredicate {
@Override
public boolean apply(IEObjectDescription input) {
if (super.apply(input))
Expand All @@ -111,19 +111,20 @@ public boolean apply(IEObjectDescription input) {
}
}

static class VariableOperationEventEnumeratorPredicate extends FeaturedTypePredicate {
public static class VariableOperationEventEnumeratorPredicate extends FeaturedTypePredicate {
@Override
public boolean apply(IEObjectDescription input) {
if (super.apply(input))
return true;
return (TypesPackage.Literals.PROPERTY.isSuperTypeOf(input.getEClass())
|| TypesPackage.Literals.OPERATION.isSuperTypeOf(input.getEClass())
|| TypesPackage.Literals.EVENT.isSuperTypeOf(input.getEClass()) || TypesPackage.Literals.ENUMERATOR
.isSuperTypeOf(input.getEClass()));
return (TypesPackage.Literals.PROPERTY.isSuperTypeOf(input.getEClass()) //
|| TypesPackage.Literals.OPERATION.isSuperTypeOf(input.getEClass()) //
|| TypesPackage.Literals.EVENT.isSuperTypeOf(input.getEClass()) //
|| TypesPackage.Literals.ENUMERATOR.isSuperTypeOf(input.getEClass()) //
|| TypesPackage.Literals.ENUMERATION_TYPE.isSuperTypeOf(input.getEClass()));
}
}

static class EmptyPredicate implements Predicate<IEObjectDescription> {
public static class EmptyPredicate implements Predicate<IEObjectDescription> {

public boolean apply(IEObjectDescription input) {
return true;
Expand All @@ -146,11 +147,11 @@ public ContextPredicateProvider() {
initMap();
}

private Pair<EClass, EReference> key(EClass eClass) {
protected Pair<EClass, EReference> key(EClass eClass) {
return Tuples.create(eClass, null);
}

private Pair<EClass, EReference> key(EClass eClass, EReference ref) {
protected Pair<EClass, EReference> key(EClass eClass, EReference ref) {
return Tuples.create(eClass, ref);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.yakindu.base.types.EnumerationType;
import org.yakindu.base.types.Type;
import org.yakindu.base.types.TypeAlias;
import org.yakindu.base.types.TypesPackage;
import org.yakindu.base.xtext.utils.jface.viewers.ContextElementAdapter;
import org.yakindu.sct.model.sgraph.SGraphPackage;
import org.yakindu.sct.model.sgraph.Scope;
Expand Down Expand Up @@ -66,7 +65,6 @@ private static class ErrorHandlerDelegate<T> implements ErrorHandler<T> {

public ErrorHandlerDelegate(ErrorHandler<T> delegate) {
this.delegate = delegate;

}

public T handle(Object[] params, Throwable throwable) {
Expand Down Expand Up @@ -112,17 +110,7 @@ public IScope scope_ElementReferenceExpression_reference(final EObject context,
IScope unnamedScope = getUnnamedTopLevelScope(context, reference);
Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
unnamedScope = new FilteringScope(unnamedScope, predicate);

// TODO: this might be a performance problem -> fix this in context of Add Support for Enumerations #165
IScope enumerations = new FilteringScope(getDelegate().getScope(context, reference),
new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return input.getEClass() == TypesPackage.Literals.ENUMERATION_TYPE;
}
});
return new SimpleScope(Iterables.concat(namdScope.getAllElements(), unnamedScope.getAllElements(),
enumerations.getAllElements()));
return new SimpleScope(Iterables.concat(namdScope.getAllElements(), unnamedScope.getAllElements()));
}

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
Expand Down Expand Up @@ -150,11 +138,17 @@ public IScope scope_FeatureCall_feature(final FeatureCall context, EReference re
scope = addScopeForComplexType((ComplexType) element, scope, predicate);
}

// enumerators can be either within enum types or an type alias that refers to an enum type
if (element instanceof EnumerationType) {
return Scopes.scopeFor(((EnumerationType) element).getEnumerator(), scope);
// scope = new FilteringScope(scope, predicate);
return addScopeForEnumType((EnumerationType) element, scope, predicate);
}

if (element instanceof TypeAlias) {
Type originType = ((TypeAlias) element).getOriginType();
if (originType instanceof EnumerationType) {
return addScopeForEnumType((EnumerationType) originType, scope, predicate);
}
}

if (element instanceof Declaration) {
Declaration decl = (Declaration) element;
if (decl.getType() instanceof ComplexType) {
Expand All @@ -170,6 +164,12 @@ public IScope scope_FeatureCall_feature(final FeatureCall context, EReference re
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);
Expand Down

0 comments on commit 212abc8

Please sign in to comment.