/* * generated by Xtext */ package org.eclipse.amalgam.tutorials.xtext.scoping; import java.util.ArrayList; import org.eclipse.amalgam.tutorials.emf.droid.*; import org.eclipse.emf.ecore.EReference; import org.eclipse.xtext.scoping.IScope; import org.eclipse.xtext.scoping.Scopes; import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider; /** * 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 DroidScopeProvider extends AbstractDeclarativeScopeProvider { public IScope scope_LayoutParams_layout_above(LayoutParams lp, EReference ref){ return getSiblingsOfParentView(lp); } public IScope scope_LayoutParams_layout_below(LayoutParams lp, EReference ref){ return getSiblingsOfParentView(lp); } public IScope scope_LayoutParams_layout_roRightOf(LayoutParams lp, EReference ref){ return getSiblingsOfParentView(lp); } public IScope scope_LayoutParams_layout_roLeftOf(LayoutParams lp, EReference ref){ return getSiblingsOfParentView(lp); } private IScope getSiblingsOfParentView(LayoutParams lp) { IScope scope = IScope.NULLSCOPE; try { View containingView = ((View) lp.eContainer() ); ViewCollection containingCollection = ((ViewCollection) containingView.eContainer() ); //Removes the parent ArrayList<View> scopeViews = new ArrayList<View>(containingCollection.getViews()); scopeViews.remove(containingView); scope = Scopes.scopeFor(scopeViews); } catch (Exception e) { logger.debug("Error getting Scope", e); } return scope; } }