blob: 70f4a5590a8270d2a862237a97513a3feeaff07a [file] [log] [blame]
/**
*
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.xtext.cubedsl.scoping;
import com.google.common.base.Objects;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
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.LEntity;
import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute;
import org.eclipse.osbp.dsl.semantic.entity.LEntityFeature;
import org.eclipse.osbp.dsl.semantic.entity.LEntityReference;
import org.eclipse.osbp.xtext.cubedsl.CubeAggregatorEnum;
import org.eclipse.osbp.xtext.cubedsl.CubeDSLPackage;
import org.eclipse.osbp.xtext.cubedsl.CubeDimension;
import org.eclipse.osbp.xtext.cubedsl.CubeDimensionEntity;
import org.eclipse.osbp.xtext.cubedsl.CubeDimensionEntityEntity;
import org.eclipse.osbp.xtext.cubedsl.CubeDimensionUsage;
import org.eclipse.osbp.xtext.cubedsl.CubeEntity;
import org.eclipse.osbp.xtext.cubedsl.CubeHierarchy;
import org.eclipse.osbp.xtext.cubedsl.CubeMeasure;
import org.eclipse.osbp.xtext.cubedsl.CubePackage;
import org.eclipse.osbp.xtext.cubedsl.CubeTypeEntity;
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.Scopes;
import org.eclipse.xtext.xbase.annotations.typesystem.XbaseWithAnnotationsBatchScopeProvider;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
/**
* 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 CubeDSLScopeProvider extends XbaseWithAnnotationsBatchScopeProvider {
@Override
public IScope getScope(final EObject context, final EReference reference) {
boolean _equals = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_DIMENSION_ENTITY_ENTITY__OVER_VALUE);
if (_equals) {
return this.getScope_CubeDimensionEntityEntityOverValue(((CubeDimensionEntityEntity) context));
} else {
boolean _equals_1 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_DIMENSION_USAGE__OVER_VALUE);
if (_equals_1) {
return this.getScope_CubeDimensionUsage_OverValue(((CubeDimensionUsage) context));
} else {
boolean _equals_2 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_MEASURE__MEASURE_COL);
if (_equals_2) {
return this.getScope_CubeMeasureCol(((CubeMeasure) context));
} else {
boolean _or = false;
boolean _equals_3 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_LEVEL__LEVEL_COL_VALUE);
if (_equals_3) {
_or = true;
} else {
boolean _equals_4 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_LEVEL_PROP__LEVEL_PROP_COL_VALUE);
_or = _equals_4;
}
if (_or) {
return this.getScope_CubeEntityColRef(((EObject) context));
} else {
boolean _equals_5 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_ENTITY__KEY_VALUE);
if (_equals_5) {
return this.getScope_CubeEntity_KeyValue(((CubeEntity) context));
} else {
boolean _equals_6 = Objects.equal(reference, CubeDSLPackage.Literals.CUBE_DIMENSION_USAGE__SOURCE_VALUE);
if (_equals_6) {
return this.getScope_CubeDimensionUsage_SourceValue(((CubeDimensionUsage) context));
} else {
return super.getScope(context, reference);
}
}
}
}
}
}
}
public IScope getScope_CubeDimensionUsage_SourceValue(final CubeDimensionUsage cubeDimUsage) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
EObject eObj = cubeDimUsage.eContainer();
while ((!(eObj instanceof CubePackage))) {
EObject _eContainer = eObj.eContainer();
eObj = _eContainer;
}
CubePackage cubePackage = ((CubePackage) eObj);
boolean _notEquals = (!Objects.equal(cubePackage, null));
if (_notEquals) {
EList<CubeDimension> _dimensions = cubePackage.getDimensions();
for (final CubeDimension cubeDim : _dimensions) {
String _name = cubeDim.getName();
boolean _notEquals_1 = (!Objects.equal(_name, null));
if (_notEquals_1) {
result.add(cubeDim);
}
}
}
return Scopes.scopeFor(result);
}
public IScope getScope_CubeDimensionUsage_OverValue(final CubeDimensionUsage cubeDimUsage) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
ArrayList<String> dimEntities = CollectionLiterals.<String>newArrayList();
CubeDimension dimUsageSource = cubeDimUsage.getSourceValue();
LEntity cubeEnt = this.getCubeEntity(cubeDimUsage);
boolean _notEquals = (!Objects.equal(dimUsageSource, null));
if (_notEquals) {
EList<CubeHierarchy> _hierarchies = dimUsageSource.getHierarchies();
for (final CubeHierarchy cubeHierarchy : _hierarchies) {
String _dimEntityName = this.getDimEntityName(cubeHierarchy);
dimEntities.add(_dimEntityName);
}
boolean _isTypeTime = dimUsageSource.isTypeTime();
if (_isTypeTime) {
List<LEntityAttribute> _allAttributes = cubeEnt.getAllAttributes();
for (final LEntityAttribute entityAttr : _allAttributes) {
boolean _isDate = this.isDate(entityAttr);
if (_isDate) {
result.add(entityAttr);
}
}
}
}
boolean _notEquals_1 = (!Objects.equal(cubeEnt, null));
if (_notEquals_1) {
String _name = cubeEnt.getName();
boolean _contains = dimEntities.contains(_name);
if (_contains) {
List<LEntityAttribute> _allAttributes_1 = cubeEnt.getAllAttributes();
for (final LEntityAttribute entityAttr_1 : _allAttributes_1) {
result.add(entityAttr_1);
}
} else {
List<LEntityReference> _allReferences = cubeEnt.getAllReferences();
for (final LEntityReference entityRef : _allReferences) {
String _typeName = this.getTypeName(entityRef);
boolean _contains_1 = dimEntities.contains(_typeName);
if (_contains_1) {
result.add(entityRef);
}
}
}
}
return Scopes.scopeFor(result);
}
public ArrayList<EObject> getRefResultList(final LEntity cubeEnt, final ArrayList<EObject> result) {
List<LEntityReference> _allReferences = cubeEnt.getAllReferences();
for (final LEntityReference entityRef : _allReferences) {
String _name = entityRef.getName();
boolean _notEquals = (!Objects.equal(_name, null));
if (_notEquals) {
result.add(entityRef);
}
}
return result;
}
public LEntity getCubeEntity(final EObject childEObj) {
LEntity cubeEnt = null;
EObject eObj = childEObj.eContainer();
while ((!(eObj instanceof CubeTypeEntity))) {
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
EObject _eContainer = eObj.eContainer();
eObj = _eContainer;
}
}
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
CubeEntity _entityRef = ((CubeTypeEntity) eObj).getEntityRef();
LEntity _entityValue = _entityRef.getEntityValue();
cubeEnt = _entityValue;
}
return cubeEnt;
}
public IScope getScope_CubeMeasureCol(final CubeMeasure cubeMeasure) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
LEntity cubeEnt = this.getCubeEntity(cubeMeasure);
boolean _notEquals = (!Objects.equal(cubeEnt, null));
if (_notEquals) {
boolean _and = false;
CubeAggregatorEnum _aggregator = cubeMeasure.getAggregator();
boolean _notEquals_1 = (!Objects.equal(_aggregator, null));
if (!_notEquals_1) {
_and = false;
} else {
boolean _or = false;
CubeAggregatorEnum _aggregator_1 = cubeMeasure.getAggregator();
boolean _equals = _aggregator_1.equals(CubeAggregatorEnum.COUNT);
if (_equals) {
_or = true;
} else {
CubeAggregatorEnum _aggregator_2 = cubeMeasure.getAggregator();
boolean _equals_1 = _aggregator_2.equals(CubeAggregatorEnum.DSC);
_or = _equals_1;
}
_and = _or;
}
if (_and) {
ArrayList<EObject> _refResultList = this.getRefResultList(cubeEnt, result);
result = _refResultList;
} else {
List<LEntityAttribute> _allAttributes = cubeEnt.getAllAttributes();
for (final LEntityAttribute entityAttr : _allAttributes) {
boolean _and_1 = false;
boolean _and_2 = false;
boolean _and_3 = false;
LScalarType _type = entityAttr.getType();
boolean _notEquals_2 = (!Objects.equal(_type, null));
if (!_notEquals_2) {
_and_3 = false;
} else {
LScalarType _type_1 = entityAttr.getType();
_and_3 = (_type_1 instanceof LDataType);
}
if (!_and_3) {
_and_2 = false;
} else {
LScalarType _type_2 = entityAttr.getType();
boolean _isAsPrimitive = ((LDataType) _type_2).isAsPrimitive();
_and_2 = _isAsPrimitive;
}
if (!_and_2) {
_and_1 = false;
} else {
LScalarType _type_3 = entityAttr.getType();
String _name = ((LDataType) _type_3).getName();
boolean _equals_2 = "String".equals(_name);
boolean _not = (!_equals_2);
_and_1 = _not;
}
if (_and_1) {
result.add(entityAttr);
}
}
}
}
return Scopes.scopeFor(result);
}
public IScope getScope_CubeEntityColRef(final EObject context) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
EObject eObj = context;
while ((!(((eObj instanceof CubeDimensionEntity) || (eObj instanceof CubeDimensionEntityEntity)) || (eObj instanceof CubeTypeEntity)))) {
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
EObject _eContainer = eObj.eContainer();
eObj = _eContainer;
}
}
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
LEntity cubeEnt = null;
if ((eObj instanceof CubeDimensionEntityEntity)) {
CubeEntity _entityRef = ((CubeDimensionEntityEntity) eObj).getEntityRef();
LEntity _entityValue = _entityRef.getEntityValue();
cubeEnt = _entityValue;
} else {
if ((eObj instanceof CubeDimensionEntity)) {
CubeEntity _entityRef_1 = ((CubeDimensionEntity) eObj).getEntityRef();
LEntity _entityValue_1 = _entityRef_1.getEntityValue();
cubeEnt = _entityValue_1;
} else {
if ((eObj instanceof CubeTypeEntity)) {
CubeEntity _entityRef_2 = ((CubeTypeEntity) eObj).getEntityRef();
LEntity _entityValue_2 = _entityRef_2.getEntityValue();
cubeEnt = _entityValue_2;
}
}
}
ArrayList<EObject> _attrResultList = this.getAttrResultList(cubeEnt, result);
result = _attrResultList;
}
return Scopes.scopeFor(result);
}
public IScope getScope_CubeDimensionEntityEntityOverValue(final CubeDimensionEntityEntity cubeDimEntityEntity) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
EObject eObj = cubeDimEntityEntity.eContainer();
while ((!(eObj instanceof CubeDimensionEntity))) {
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
EObject _eContainer = eObj.eContainer();
eObj = _eContainer;
}
}
boolean _notEquals = (!Objects.equal(eObj, null));
if (_notEquals) {
if ((eObj instanceof CubeDimensionEntity)) {
ArrayList<EObject> _joinableRefsResultList = this.getJoinableRefsResultList(cubeDimEntityEntity, ((CubeDimensionEntity) eObj), result);
result = _joinableRefsResultList;
}
}
return Scopes.scopeFor(result);
}
public IScope getScope_CubeEntity_KeyValue(final CubeEntity entity) {
ArrayList<EObject> result = CollectionLiterals.<EObject>newArrayList();
boolean _notEquals = (!Objects.equal(entity, null));
if (_notEquals) {
LEntity _entityValue = entity.getEntityValue();
ArrayList<EObject> _attrResultList = this.getAttrResultList(_entityValue, result);
result = _attrResultList;
}
return Scopes.scopeFor(result);
}
public ArrayList<EObject> getJoinableRefsResultList(final CubeDimensionEntityEntity cubeDimEntityEntity, final CubeDimensionEntity entity, final ArrayList<EObject> result) {
boolean _and = false;
boolean _and_1 = false;
boolean _and_2 = false;
boolean _notEquals = (!Objects.equal(entity, null));
if (!_notEquals) {
_and_2 = false;
} else {
CubeEntity _entityRef = entity.getEntityRef();
boolean _notEquals_1 = (!Objects.equal(_entityRef, null));
_and_2 = _notEquals_1;
}
if (!_and_2) {
_and_1 = false;
} else {
CubeEntity _entityRef_1 = entity.getEntityRef();
LEntity _entityValue = _entityRef_1.getEntityValue();
boolean _notEquals_2 = (!Objects.equal(_entityValue, null));
_and_1 = _notEquals_2;
}
if (!_and_1) {
_and = false;
} else {
CubeEntity _entityRef_2 = entity.getEntityRef();
LEntity _entityValue_1 = _entityRef_2.getEntityValue();
String _name = _entityValue_1.getName();
boolean _notEquals_3 = (!Objects.equal(_name, null));
_and = _notEquals_3;
}
if (_and) {
CubeEntity _entityRef_3 = entity.getEntityRef();
LEntity cubeEnt = _entityRef_3.getEntityValue();
List<LEntityReference> _allReferences = cubeEnt.getAllReferences();
for (final LEntityReference lEntRef : _allReferences) {
boolean _and_3 = false;
boolean _and_4 = false;
boolean _and_5 = false;
CubeEntity _entityRef_4 = cubeDimEntityEntity.getEntityRef();
boolean _notEquals_4 = (!Objects.equal(_entityRef_4, null));
if (!_notEquals_4) {
_and_5 = false;
} else {
CubeEntity _entityRef_5 = cubeDimEntityEntity.getEntityRef();
LEntity _entityValue_2 = _entityRef_5.getEntityValue();
boolean _notEquals_5 = (!Objects.equal(_entityValue_2, null));
_and_5 = _notEquals_5;
}
if (!_and_5) {
_and_4 = false;
} else {
CubeEntity _entityRef_6 = cubeDimEntityEntity.getEntityRef();
LEntity _entityValue_3 = _entityRef_6.getEntityValue();
String _name_1 = _entityValue_3.getName();
boolean _notEquals_6 = (!Objects.equal(_name_1, null));
_and_4 = _notEquals_6;
}
if (!_and_4) {
_and_3 = false;
} else {
CubeEntity _entityRef_7 = cubeDimEntityEntity.getEntityRef();
LEntity _entityValue_4 = _entityRef_7.getEntityValue();
String _name_2 = _entityValue_4.getName();
LEntity _type = lEntRef.getType();
String _name_3 = _type.getName();
boolean _equals = _name_2.equals(_name_3);
_and_3 = _equals;
}
if (_and_3) {
result.add(lEntRef);
}
}
}
return result;
}
public ArrayList<EObject> getAttrResultList(final LEntity cubeEnt, final ArrayList<EObject> result) {
boolean _notEquals = (!Objects.equal(cubeEnt, null));
if (_notEquals) {
List<LEntityAttribute> _allAttributes = cubeEnt.getAllAttributes();
for (final LEntityAttribute entityAttr : _allAttributes) {
String _name = entityAttr.getName();
boolean _notEquals_1 = (!Objects.equal(_name, null));
if (_notEquals_1) {
result.add(entityAttr);
}
}
}
return result;
}
public ArrayList<EObject> getAllFeaturesResultList(final LEntity cubeEnt, final ArrayList<EObject> result) {
boolean _notEquals = (!Objects.equal(cubeEnt, null));
if (_notEquals) {
List<LEntityFeature> _allFeatures = cubeEnt.getAllFeatures();
for (final LEntityFeature entityFeature : _allFeatures) {
String _name = entityFeature.getName();
boolean _notEquals_1 = (!Objects.equal(_name, null));
if (_notEquals_1) {
result.add(entityFeature);
}
}
}
return result;
}
public String getDimEntityName(final CubeHierarchy cubeHierarchy) {
boolean _and = false;
boolean _and_1 = false;
boolean _and_2 = false;
boolean _notEquals = (!Objects.equal(cubeHierarchy, null));
if (!_notEquals) {
_and_2 = false;
} else {
CubeDimensionEntity _cubeDimEntity = cubeHierarchy.getCubeDimEntity();
boolean _notEquals_1 = (!Objects.equal(_cubeDimEntity, null));
_and_2 = _notEquals_1;
}
if (!_and_2) {
_and_1 = false;
} else {
CubeDimensionEntity _cubeDimEntity_1 = cubeHierarchy.getCubeDimEntity();
CubeEntity _entityRef = _cubeDimEntity_1.getEntityRef();
boolean _notEquals_2 = (!Objects.equal(_entityRef, null));
_and_1 = _notEquals_2;
}
if (!_and_1) {
_and = false;
} else {
CubeDimensionEntity _cubeDimEntity_2 = cubeHierarchy.getCubeDimEntity();
CubeEntity _entityRef_1 = _cubeDimEntity_2.getEntityRef();
LEntity _entityValue = _entityRef_1.getEntityValue();
boolean _notEquals_3 = (!Objects.equal(_entityValue, null));
_and = _notEquals_3;
}
if (_and) {
CubeDimensionEntity _cubeDimEntity_3 = cubeHierarchy.getCubeDimEntity();
CubeEntity _entityRef_2 = _cubeDimEntity_3.getEntityRef();
LEntity _entityValue_1 = _entityRef_2.getEntityValue();
return _entityValue_1.getName();
}
return null;
}
public String getTypeName(final LEntityReference entityRef) {
boolean _and = false;
LEntity _type = entityRef.getType();
String _name = _type.getName();
boolean _notEquals = (!Objects.equal(_name, null));
if (!_notEquals) {
_and = false;
} else {
LEntity _type_1 = entityRef.getType();
String _name_1 = _type_1.getName();
boolean _notEquals_1 = (!Objects.equal(_name_1, null));
_and = _notEquals_1;
}
if (_and) {
LEntity _type_2 = entityRef.getType();
return _type_2.getName();
}
return null;
}
public boolean isDate(final LEntityAttribute entityAttr) {
ArrayList<Class> dateTypes = CollectionLiterals.<Class>newArrayList();
dateTypes.add(Date.class);
dateTypes.add(java.sql.Date.class);
boolean _and = false;
LScalarType _type = entityAttr.getType();
if (!(_type instanceof LDataType)) {
_and = false;
} else {
boolean _or = false;
LScalarType _type_1 = entityAttr.getType();
boolean _isDate = ((LDataType) _type_1).isDate();
if (_isDate) {
_or = true;
} else {
LScalarType _type_2 = entityAttr.getType();
boolean _containsInstanceOf = this.containsInstanceOf(dateTypes, ((LDataType) _type_2));
_or = _containsInstanceOf;
}
_and = _or;
}
boolean isDateBoolean = _and;
return isDateBoolean;
}
public boolean containsInstanceOf(final ArrayList<Class> dateTypes, final LDataType dataType) {
for (final Class dateObj : dateTypes) {
boolean _and = false;
boolean _notEquals = (!Objects.equal(dateObj, null));
if (!_notEquals) {
_and = false;
} else {
String _name = dateObj.getName();
JvmTypeReference _jvmTypeReference = dataType.getJvmTypeReference();
JvmType _type = _jvmTypeReference.getType();
String _identifier = _type.getIdentifier();
boolean _equals = _name.equals(_identifier);
_and = _equals;
}
if (_and) {
return true;
}
}
return false;
}
}