/*
* generated by Xtext
*/
package org.applause.lang.scoping;
import static org.eclipse.xtext.scoping.Scopes.scopeFor;
import org.applause.lang.applauseDsl.ApplauseDslPackage;
import org.applause.lang.applauseDsl.ObjectReference;
import org.applause.lang.applauseDsl.Parameter;
import org.applause.lang.applauseDsl.SectionCell;
import org.applause.lang.applauseDsl.TableView;
import org.applause.lang.applauseDsl.ViewSection;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import com.google.common.collect.Lists;
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping
* on how and when to use it
*
*/
public class ApplauseDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope _scope_ObjectReference_object(SectionCell context, EReference ref) {
ViewSection section = (ViewSection) context.eContainer();
TableView tableView = (TableView) section.eContainer();
Parameter parameter = tableView.getContent();
return scopeFor(Lists.newArrayList(parameter));
}
@Override
public IScope getScope(EObject context, EReference reference) {
if (ApplauseDslPackage.Literals.VARIABLE_DECLARATION == reference.getEReferenceType()) {
return getVariableDeclarationScope(context);
}
return super.getScope(context, reference);
}
private IScope getVariableDeclarationScope(EObject context) {
if(context.eContainer() instanceof ObjectReference)
return new NestedDeclarationScope((ObjectReference) context.eContainer());
else
return new VariableDeclarationScope(context);
}
}