Search in sources :

Example 1 with PolymorphicDispatcher

use of org.eclipse.xtext.util.PolymorphicDispatcher in project xtext-core by eclipse.

the class AbstractDeclarativeScopeProvider method polymorphicFindScopeForClassName.

protected IScope polymorphicFindScopeForClassName(EObject context, EReference reference) {
    IScope scope = null;
    PolymorphicDispatcher<IScope> dispatcher = new PolymorphicDispatcher<IScope>(Collections.singletonList(this), getPredicate(context, reference.getEReferenceType()), errorHandler) {

        @Override
        protected IScope handleNoSuchMethod(Object... params) {
            if (PolymorphicDispatcher.NullErrorHandler.class.equals(errorHandler.getClass()))
                return null;
            return super.handleNoSuchMethod(params);
        }
    };
    EObject current = context;
    while (scope == null && current != null) {
        scope = dispatcher.invoke(current, reference);
        current = current.eContainer();
    }
    current = context;
    while (scope == null && current != null) {
        scope = dispatcher.invoke(current, reference.getEReferenceType());
        if (scope != null)
            logger.warn("scope_<EClass>(EObject,EClass) is deprecated. Use scope_<EClass>(EObject,EReference) instead.");
        current = current.eContainer();
    }
    return scope;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) EObject(org.eclipse.emf.ecore.EObject) PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher)

Example 2 with PolymorphicDispatcher

use of org.eclipse.xtext.util.PolymorphicDispatcher in project xtext-core by eclipse.

the class AbstractDeclarativeScopeProvider method polymorphicFindScopeForReferenceName.

protected IScope polymorphicFindScopeForReferenceName(EObject context, EReference reference) {
    Predicate<Method> predicate = getPredicate(context, reference);
    PolymorphicDispatcher<IScope> dispatcher = new PolymorphicDispatcher<IScope>(Collections.singletonList(this), predicate, errorHandler) {

        @Override
        protected IScope handleNoSuchMethod(Object... params) {
            if (PolymorphicDispatcher.NullErrorHandler.class.equals(errorHandler.getClass()))
                return null;
            return super.handleNoSuchMethod(params);
        }
    };
    EObject current = context;
    IScope scope = null;
    while (scope == null && current != null) {
        scope = dispatcher.invoke(current, reference);
        current = current.eContainer();
    }
    return scope;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) EObject(org.eclipse.emf.ecore.EObject) Method(java.lang.reflect.Method) PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)2 IScope (org.eclipse.xtext.scoping.IScope)2 PolymorphicDispatcher (org.eclipse.xtext.util.PolymorphicDispatcher)2 Method (java.lang.reflect.Method)1