blob: 1d9ce387f3d86a4ac6d0434dbfab6ec95db285f4 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.dsl.entity.xtext.scope;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.osbp.dsl.common.xtext.scope.CommonScopeProvider;
import org.eclipse.osbp.dsl.common.xtext.scope.ConstraintEnumMatchingLiteralScope;
import org.eclipse.osbp.dsl.semantic.common.types.LAttribute;
import org.eclipse.osbp.dsl.semantic.common.types.LAttributeMatchingConstraint;
import org.eclipse.osbp.dsl.semantic.common.types.LReference;
import org.eclipse.osbp.dsl.semantic.common.types.LResultFilters;
import org.eclipse.osbp.dsl.semantic.common.types.OSBPTypesPackage;
import org.eclipse.osbp.dsl.semantic.entity.LBeanReference;
import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute;
import org.eclipse.osbp.dsl.semantic.entity.LEntityReference;
import org.eclipse.osbp.dsl.semantic.entity.LIndex;
import org.eclipse.osbp.dsl.semantic.entity.OSBPEntityPackage;
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping on
* how and when to use it
*
*/
@SuppressWarnings("restriction")
public class EntityScopeProvider extends CommonScopeProvider {
@Override
public IScope getScope(final EObject context, EReference reference) {
if (reference == OSBPEntityPackage.Literals.LENTITY_REFERENCE__OPPOSITE) {
return new EntityRefOppositeScope((LEntityReference) context);
} else if (reference == OSBPEntityPackage.Literals.LENTITY_ATTRIBUTE__OPPOSITE) {
return new EntityAttOppositeScope((LEntityAttribute) context);
} else if (reference == OSBPEntityPackage.Literals.LBEAN_REFERENCE__OPPOSITE) {
return new BeanRefOppositeScope((LBeanReference) context);
} else if (reference == OSBPTypesPackage.Literals.LATTRIBUTE__TYPE) {
return new DatatypesScope(super.getScope(context, reference),
(LAttribute) context, reference);
} else if (reference == OSBPEntityPackage.Literals.LINDEX__FEATURES) {
return new IndexScope((LIndex) context);
} else if (reference == OSBPTypesPackage.Literals.LATTRIBUTE_MATCHING_CONSTRAINT__ATTRIBUTE) {
if (context instanceof LResultFilters) {
return new EntityConstraintAttributeScope(
(LReference) context.eContainer());
} else {
return new EntityConstraintAttributeScope((LReference) context
.eContainer().eContainer());
}
} else if (reference == OSBPTypesPackage.Literals.LATTRIBUTE_MATCHING_CONSTRAINT__MATCHING_LITERAL) {
return new ConstraintEnumMatchingLiteralScope(
(LAttributeMatchingConstraint) context);
}
return super.getScope(context, reference);
}
}