| /** |
| * 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.reportdsl.scoping; |
| |
| import com.google.common.base.Objects; |
| import java.util.ArrayList; |
| import javax.inject.Inject; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EReference; |
| import org.eclipse.osbp.dsl.common.xtext.extensions.ModelExtensions; |
| import org.eclipse.osbp.dsl.dto.xtext.jvmmodel.TypeHelper; |
| import org.eclipse.osbp.dsl.semantic.common.types.LDataType; |
| import org.eclipse.osbp.dsl.semantic.common.types.LScalarType; |
| import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute; |
| import org.eclipse.osbp.utils.entityhelper.DataType; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartAttribute; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartDefinition; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartEntity; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartMember; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartNavigation; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartOwner; |
| import org.eclipse.osbp.xtext.datamartdsl.DatamartSource; |
| import org.eclipse.osbp.xtext.datamartdsl.util.DatamartAttributeUtil; |
| import org.eclipse.osbp.xtext.reportdsl.DatamartContainer; |
| import org.eclipse.osbp.xtext.reportdsl.ReportDSLPackage; |
| import org.eclipse.osbp.xtext.reportdsl.TableUnaryAggregation; |
| import org.eclipse.osbp.xtext.reportdsl.scoping.AbstractReportDSLScopeProvider; |
| import org.eclipse.xtext.common.types.JvmDeclaredType; |
| import org.eclipse.xtext.common.types.JvmType; |
| import org.eclipse.xtext.common.types.util.RawSuperTypes; |
| import org.eclipse.xtext.resource.EObjectDescription; |
| import org.eclipse.xtext.resource.IEObjectDescription; |
| import org.eclipse.xtext.scoping.IScope; |
| import org.eclipse.xtext.scoping.impl.MapBasedScope; |
| import org.eclipse.xtext.xbase.lib.CollectionLiterals; |
| import org.eclipse.xtext.xbase.lib.Extension; |
| import org.eclipse.xtext.xbase.lib.IterableExtensions; |
| |
| /** |
| * This class contains custom scoping description. |
| * |
| * see : http://www.eclipse.org/Xtext/documentation.html#scoping |
| * on how and when to use it |
| */ |
| @SuppressWarnings("all") |
| public class ReportDSLScopeProvider extends AbstractReportDSLScopeProvider { |
| @Inject |
| @Extension |
| private DataType _dataType; |
| |
| @Inject |
| @Extension |
| private TypeHelper _typeHelper; |
| |
| @Inject |
| @Extension |
| private ModelExtensions _modelExtensions; |
| |
| @Override |
| public IScope getScope(final EObject context, final EReference reference) { |
| IScope _xblockexpression = null; |
| { |
| boolean _equals = Objects.equal(reference, ReportDSLPackage.Literals.DATAMART_TABLE_GROUP__GROUPING_REF); |
| if (_equals) { |
| return this.getScope_DatamartProperty(context); |
| } else { |
| boolean _equals_1 = Objects.equal(reference, ReportDSLPackage.Literals.TABLE_ATTRIBUTE__VALUE_REF); |
| if (_equals_1) { |
| return this.getScope_DatamartProperty(context); |
| } else { |
| boolean _equals_2 = Objects.equal(reference, ReportDSLPackage.Literals.VISIBILITY__VISIBILITY_ATTRIBUTE); |
| if (_equals_2) { |
| return this.getScope_BooleanDatamartProperty(context); |
| } else { |
| boolean _equals_3 = Objects.equal(reference, ReportDSLPackage.Literals.TABLE_BASE_AGGREGATION__VALUE_REFS); |
| if (_equals_3) { |
| if ((context instanceof TableUnaryAggregation)) { |
| return this.getLimitedScopeToSuperTypedNumber(this.getScope_DatamartProperty(context)); |
| } |
| return this.getScope_DatamartProperty(context); |
| } |
| } |
| } |
| } |
| _xblockexpression = super.getScope(context, reference); |
| } |
| return _xblockexpression; |
| } |
| |
| public IScope getLimitedScopeToSuperTypedNumber(final IScope scope) { |
| ArrayList<IEObjectDescription> result = CollectionLiterals.<IEObjectDescription>newArrayList(); |
| Iterable<IEObjectDescription> _allElements = scope.getAllElements(); |
| for (final IEObjectDescription eObjDescription : _allElements) { |
| { |
| EObject eObj = eObjDescription.getEObjectOrProxy(); |
| if ((eObj instanceof DatamartAttribute)) { |
| DatamartAttribute attribute = ((DatamartAttribute) eObj); |
| LScalarType type = attribute.getAttributeRef().getType(); |
| if ((type instanceof LDataType)) { |
| boolean _isNumericOrWrapperType = this._modelExtensions.isNumericOrWrapperType(((LDataType)type)); |
| if (_isNumericOrWrapperType) { |
| result.add(eObjDescription); |
| } |
| } |
| } |
| } |
| } |
| boolean _isEmpty = result.isEmpty(); |
| if (_isEmpty) { |
| return scope; |
| } |
| return MapBasedScope.createScope(IScope.NULLSCOPE, result); |
| } |
| |
| public ArrayList<IEObjectDescription> getDatamartPropertyResultList(final EObject context) { |
| ArrayList<IEObjectDescription> result = CollectionLiterals.<IEObjectDescription>newArrayList(); |
| EObject eObj = context; |
| while (((eObj != null) && (!(eObj instanceof DatamartContainer)))) { |
| eObj = eObj.eContainer(); |
| } |
| if ((eObj != null)) { |
| DatamartDefinition datamart = ((DatamartContainer) eObj).getDatamartRef(); |
| if (((datamart != null) && (datamart.getSource() != null))) { |
| DatamartSource _source = datamart.getSource(); |
| if ((_source instanceof DatamartEntity)) { |
| DatamartSource _source_1 = datamart.getSource(); |
| this.getDatamartAttributes(((DatamartEntity) _source_1), result); |
| } |
| } else { |
| result = this.getDatamartPropertyResultList(eObj.eContainer()); |
| } |
| } |
| return result; |
| } |
| |
| public IScope getScope_DatamartProperty(final EObject context) { |
| return MapBasedScope.createScope(IScope.NULLSCOPE, this.getDatamartPropertyResultList(context)); |
| } |
| |
| public IScope getScope_BooleanDatamartProperty(final EObject context) { |
| ArrayList<IEObjectDescription> resultBoolean = CollectionLiterals.<IEObjectDescription>newArrayList(); |
| ArrayList<IEObjectDescription> _datamartPropertyResultList = this.getDatamartPropertyResultList(context); |
| for (final IEObjectDescription resultItem : _datamartPropertyResultList) { |
| EObject _eObjectOrProxy = resultItem.getEObjectOrProxy(); |
| if ((_eObjectOrProxy instanceof DatamartAttribute)) { |
| EObject _eObjectOrProxy_1 = resultItem.getEObjectOrProxy(); |
| LEntityAttribute entityAttribute = ((DatamartAttribute) _eObjectOrProxy_1).getAttributeRef(); |
| boolean _isBoolean = this._typeHelper.isBoolean(this._dataType.getJvmType(entityAttribute)); |
| if (_isBoolean) { |
| resultBoolean.add(resultItem); |
| } |
| } |
| } |
| return MapBasedScope.createScope(IScope.NULLSCOPE, resultBoolean); |
| } |
| |
| public void getDatamartAttributes(final DatamartEntity datamartEntity, final ArrayList<IEObjectDescription> result) { |
| EList<DatamartNavigation> _navigations = datamartEntity.getNavigations(); |
| for (final DatamartNavigation navigation : _navigations) { |
| { |
| if ((navigation instanceof DatamartMember)) { |
| this.getDatamartAttributes(((DatamartMember) navigation).getDatamartEntity(), result); |
| EList<DatamartAttribute> _attributes = ((DatamartMember) navigation).getDatamartEntity().getAttributes(); |
| for (final DatamartAttribute attribute : _attributes) { |
| result.add( |
| EObjectDescription.create(DatamartAttributeUtil.getAliasedAttributeName(attribute), attribute)); |
| } |
| } |
| if ((navigation instanceof DatamartOwner)) { |
| this.getDatamartAttributes(((DatamartOwner) navigation).getDatamartEntity(), result); |
| EList<DatamartAttribute> _attributes_1 = ((DatamartOwner) navigation).getDatamartEntity().getAttributes(); |
| for (final DatamartAttribute attribute_1 : _attributes_1) { |
| result.add( |
| EObjectDescription.create(DatamartAttributeUtil.getAliasedAttributeName(attribute_1), attribute_1)); |
| } |
| } |
| } |
| } |
| EList<DatamartAttribute> _attributes = null; |
| if (datamartEntity!=null) { |
| _attributes=datamartEntity.getAttributes(); |
| } |
| boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(_attributes); |
| if (_isNullOrEmpty) { |
| DatamartAttributeUtil.fillEmptyAttributes(datamartEntity); |
| } |
| EList<DatamartAttribute> _attributes_1 = datamartEntity.getAttributes(); |
| for (final DatamartAttribute datamartAttribute : _attributes_1) { |
| result.add( |
| EObjectDescription.create(DatamartAttributeUtil.getAliasedAttributeName(datamartAttribute), datamartAttribute)); |
| } |
| } |
| |
| public boolean containsSuperType(final JvmType type, final Class<?> clazz) { |
| if ((!(type instanceof JvmDeclaredType))) { |
| return false; |
| } |
| return new RawSuperTypes().collectNames(type).contains(clazz.getCanonicalName()); |
| } |
| } |