| /** |
| * |
| * Copyright (c) 2011, 2016 - 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| * |
| * This copyright notice shows up in the generated Java code |
| * |
| */ |
| |
| package org.eclipse.osbp.xtext.gridsource.scoping |
| |
| import java.util.List |
| import java.util.Map |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.EReference |
| import org.eclipse.emf.ecore.util.EcoreUtil |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedField |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridNestedPath |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridProperty |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridSource |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridSourceEQFilter |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridSourceInput |
| import org.eclipse.osbp.infogrid.model.gridsource.CxGridSourcePackage |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropPriceStyle |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropQuantityStyle |
| import org.eclipse.osbp.infogrid.model.gridsource.style.CxGridPropSparklineStyle |
| import org.eclipse.xtext.common.types.JvmDeclaredType |
| import org.eclipse.xtext.common.types.JvmType |
| import org.eclipse.xtext.resource.EObjectDescription |
| import org.eclipse.xtext.resource.IEObjectDescription |
| import org.eclipse.xtext.scoping.IScope |
| import org.eclipse.xtext.scoping.impl.AbstractScope |
| |
| import static extension org.eclipse.osbp.infogrid.model.gridsource.util.Util.* |
| import javax.inject.Inject |
| |
| class GridSourceScopeProvider extends AbstractGridSourceScopeProvider { |
| |
| @Inject extension TypeHelper |
| |
| override IScope getScope(EObject context, EReference reference) { |
| return super.getScope(context, reference); |
| } |
| |
| def IScope scope_CxGridNestedPath_field(CxGridNestedPath exp, EReference ref) { |
| var JvmType type = null; |
| if (exp.eContainer instanceof CxGridNestedField) { |
| val CxGridNestedField prop = exp.eContainer as CxGridNestedField |
| type = prop.field?.returnType.type |
| } else { |
| val CxGridNestedPath parent = exp.eContainer as CxGridNestedPath |
| type = parent.field?.returnType.type |
| } |
| |
| return type.toGetterScope |
| } |
| |
| def IScope scope_CxGridNestedField_field(CxGridSource source, EReference ref) { |
| return source?.rootType?.type.toGetterScope |
| } |
| |
| def IScope scope_CxGridNestedField_field(CxGridPropQuantityStyle source, EReference ref) { |
| val CxGridProperty prop = source.eContainer as CxGridProperty |
| return prop.calcLeafType.toGetterScope |
| } |
| |
| def IScope scope_CxGridNestedField_field(CxGridPropPriceStyle source, EReference ref) { |
| val CxGridProperty prop = source.eContainer as CxGridProperty |
| return prop.calcLeafType.toGetterScope |
| } |
| |
| def IScope scope_CxGridNestedField_field(CxGridNestedField context, EReference reference) { |
| val container = context.eContainer |
| if (container instanceof CxGridSourceEQFilter) { |
| val input = container.eContainer as CxGridSourceInput |
| val ref = context.eContainingFeature |
| val model = EcoreUtil.getRootContainer(context) as CxGridSource |
| switch (ref) { |
| case CxGridSourcePackage.Literals.CX_GRID_SOURCE_EQ_FILTER__INPUT_TYPE_PROPERTY_PATH: { |
| return toGetterScope(input.inputType.type) |
| } |
| case CxGridSourcePackage.Literals.CX_GRID_SOURCE_EQ_FILTER__ROOT_TYPE_PROPERTY_PATH: { |
| return toGetterScope(model.rootType.type) |
| } |
| } |
| } else if (container instanceof CxGridProperty) { |
| val CxGridSource source = EcoreUtil.getRootContainer(container) as CxGridSource |
| return toGetterScope(source.rootType.type) |
| } |
| return null |
| } |
| |
| def IScope scope_CxGridSourceEQFilter_rootTypePropertyPath(CxGridSourceEQFilter source, EReference ref) { |
| return null |
| } |
| |
| def IScope scope_CxGridPropSparklineStyle_field(CxGridPropSparklineStyle style, EReference ref) { |
| val CxGridProperty prop = style.eContainer as CxGridProperty |
| val CxGridSource source = prop.eContainer as CxGridSource |
| return source?.rootType?.type.toGetterScope |
| } |
| |
| def IScope toGetterScope(JvmType type) { |
| if (type instanceof JvmDeclaredType) { |
| val Map<String, OperationExtensions.OperationInfo> info = OperationExtensions.getOperationInfos(type); |
| val IScope scope = new AbstractScope(IScope.NULLSCOPE, true) { |
| override protected getAllLocalElements() { |
| val List<IEObjectDescription> descriptions = newArrayList() |
| for (field : info.values.filter [ |
| !isStaticField && field !== null && !name.equals("class") && !name.equals("dirty") && !name.equals("disposed") && !name.equals("version") && !field.collection |
| ]) { |
| val Map<String, String> userData = newHashMap() |
| userData.put("readonly", field.readonly.toString) |
| descriptions.add(EObjectDescription.create(field.name, field.getter, userData)) |
| } |
| return descriptions |
| } |
| } |
| return scope |
| } |
| return IScope::NULLSCOPE |
| } |
| } |