blob: 58055520c19e4e52a8962b0e2e0f4b9e90978ba8 [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
*
*
* This copyright notice shows up in the generated Java code
*/
package org.eclipse.osbp.xtext.entitymock.ui.contentassist;
import com.google.common.base.Objects;
import com.google.inject.Inject;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.osbp.dsl.semantic.common.types.LEnum;
import org.eclipse.osbp.dsl.semantic.common.types.LEnumLiteral;
import org.eclipse.osbp.dsl.semantic.entity.LEntityAttribute;
import org.eclipse.osbp.ui.api.datamart.IDataMart;
import org.eclipse.osbp.utils.entityhelper.DataType;
import org.eclipse.osbp.xtext.basic.ui.contentassist.BasicDSLProposalProviderHelper;
import org.eclipse.osbp.xtext.entitymock.EntityMockAttributeByObject;
import org.eclipse.osbp.xtext.entitymock.EntityMockAttributeFiller;
import org.eclipse.osbp.xtext.entitymock.EntityMockEntity;
import org.eclipse.osbp.xtext.entitymock.EntityMockObject;
import org.eclipse.osbp.xtext.entitymock.EntityMockObjectArrayValue;
import org.eclipse.osbp.xtext.entitymock.EntityMockObjectEmbed;
import org.eclipse.osbp.xtext.entitymock.EntityMockObjectEnum;
import org.eclipse.osbp.xtext.entitymock.EntityMockObjectFunction;
import org.eclipse.osbp.xtext.entitymock.EntityMockReferencedObjectAttribute;
import org.eclipse.osbp.xtext.entitymock.EntityMockResource;
import org.eclipse.osbp.xtext.entitymock.EntityMockResourceDataRow;
import org.eclipse.osbp.xtext.entitymock.EntityMockTemplate;
import org.eclipse.osbp.xtext.entitymock.IEntityMockObjectAttribute;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerDateFuture;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerDatePast;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerDateRange;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerSignedDoubleRandom;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerSignedDoubleRange;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerSignedIntegerRandom;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerSignedIntegerRange;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerTextParagraphs;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerTextRandom;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerTextSentences;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerTextWords;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerUnsignedDoubleRandom;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerUnsignedDoubleRange;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerUnsignedIntegerRandom;
import org.eclipse.osbp.xtext.entitymock.PropertyFillerUnsignedIntegerRange;
import org.eclipse.osbp.xtext.entitymock.ui.EntityMockDSLUiDocumentationTranslator;
import org.eclipse.osbp.xtext.entitymock.ui.contentassist.AbstractEntityMockDSLProposalProvider;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.ParserRule;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.common.ui.contentassist.TerminalsProposalProvider;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
/**
* see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to customize content assistant
*/
@SuppressWarnings("all")
public class EntityMockDSLProposalProvider extends AbstractEntityMockDSLProposalProvider {
@Inject
private DataType dtType;
@Inject
private TerminalsProposalProvider provider;
@Inject
private BasicDSLProposalProviderHelper providerHelper;
/**
* @see BasicDSLProposalProviderHelper#getKeywordDisplayString(Keyword, BasicDSLUiTranslator)
* @param keyword the keyword to get the displayed string for
* @return the displayed string
*/
@Override
protected StyledString getKeywordDisplayString(final Keyword keyword) {
return BasicDSLProposalProviderHelper.getKeywordDisplayString(keyword, EntityMockDSLUiDocumentationTranslator.instance());
}
/**
* This override will enable 1 length non letter characters as keyword.
*/
@Override
protected boolean isKeywordWorthyToPropose(final Keyword keyword) {
return true;
}
/**
* propose all available enumeration values for the referenced enumeration
*/
@Override
public void completeEntityMockObjectItemValue_Datarow(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
EObject mockValueItem = model;
while (((!(mockValueItem instanceof EntityMockObjectArrayValue)) && (!Objects.equal(mockValueItem, null)))) {
mockValueItem = mockValueItem.eContainer();
}
if ((mockValueItem instanceof EntityMockObjectArrayValue)) {
LEnum _usingResource = ((EntityMockObjectArrayValue)mockValueItem).getEnumeration().getUsingResource();
if ((_usingResource instanceof EntityMockResource)) {
LEnum _usingResource_1 = ((EntityMockObjectArrayValue)mockValueItem).getEnumeration().getUsingResource();
final EntityMockResource resource = ((EntityMockResource) _usingResource_1);
EList<EntityMockResourceDataRow> _datarows = resource.getDatarows();
for (final EntityMockResourceDataRow datarow : _datarows) {
acceptor.accept(
this.createCompletionProposal(datarow.getName(), datarow.getName(), null, context));
}
} else {
final LEnum lenum = ((EntityMockObjectArrayValue)mockValueItem).getEnumeration().getUsingResource();
EList<LEnumLiteral> _literals = lenum.getLiterals();
for (final LEnumLiteral datarow_1 : _literals) {
acceptor.accept(
this.createCompletionProposal(datarow_1.getName(), datarow_1.getName(), null, context));
}
}
}
}
/**
* propose all template mock object variables defined previously in this mock entity
*/
@Override
public void completeEntityMockReferencedObjectAttribute_Template(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
EObject _eContainer = ((EntityMockAttributeByObject) model).eContainer();
EList<EntityMockTemplate> _templates = ((EntityMockEntity) _eContainer).getTemplates();
for (final EntityMockTemplate template : _templates) {
acceptor.accept(
this.createCompletionProposal(template.getName(), template.getName(), null, context));
}
}
/**
* propose all embedded mock objects inside the referenced template mock object
*/
@Override
public void completeEntityMockReferencedObjectAttribute_Embedded(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
EntityMockReferencedObjectAttribute emroa = ((EntityMockReferencedObjectAttribute) null);
if ((model instanceof EntityMockReferencedObjectAttribute)) {
emroa = ((EntityMockReferencedObjectAttribute)model);
}
if ((model instanceof EntityMockAttributeByObject)) {
emroa = ((EntityMockAttributeByObject)model).getReference();
}
EntityMockObject mockObject = emroa.getTemplate().getObject();
boolean _isEmpty = emroa.getEmbedded().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
mockObject = IterableExtensions.<EntityMockObjectEmbed>last(emroa.getEmbedded()).getObject();
}
EList<IEntityMockObjectAttribute> _attributes = mockObject.getAttributes();
for (final IEntityMockObjectAttribute attribute : _attributes) {
if ((attribute instanceof EntityMockObjectEmbed)) {
acceptor.accept(
this.createCompletionProposal(((EntityMockObjectEmbed)attribute).getName(), ((EntityMockObjectEmbed)attribute).getName(), null, context));
}
}
}
@Override
public void completeEntityMockEntityFunction_AttributeRef(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
EObject _eContainer = model.eContainer();
if ((_eContainer instanceof EntityMockEntity)) {
EObject _eContainer_1 = model.eContainer();
List<LEntityAttribute> _allAttributes = ((EntityMockEntity) _eContainer_1).getEntityRef().getAllAttributes();
for (final LEntityAttribute attribute : _allAttributes) {
acceptor.accept(
this.createCompletionProposal(attribute.getName(), attribute.getName(), null, context));
}
} else {
super.completeEntityMockEntityFunction_AttributeRef(model, assignment, context, acceptor);
}
}
/**
* propose all enumerations and attributes of the referenced (may be embedded) mock object
*/
@Override
public void completeEntityMockReferencedObjectAttribute_Attribute(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
EntityMockReferencedObjectAttribute emroa = ((EntityMockReferencedObjectAttribute) null);
if ((model instanceof EntityMockReferencedObjectAttribute)) {
emroa = ((EntityMockReferencedObjectAttribute)model);
}
if ((model instanceof EntityMockAttributeByObject)) {
emroa = ((EntityMockAttributeByObject)model).getReference();
}
EntityMockObject mockObject = emroa.getTemplate().getObject();
boolean _isEmpty = emroa.getEmbedded().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
mockObject = IterableExtensions.<EntityMockObjectEmbed>last(emroa.getEmbedded()).getObject();
}
EList<EntityMockObjectEnum> _enumerations = mockObject.getEnumerations();
for (final EntityMockObjectEnum enumeration : _enumerations) {
acceptor.accept(
this.createCompletionProposal(enumeration.getName(), enumeration.getName(), null, context));
}
EList<IEntityMockObjectAttribute> _attributes = mockObject.getAttributes();
for (final IEntityMockObjectAttribute attribute : _attributes) {
if ((!(attribute instanceof EntityMockObjectEmbed))) {
acceptor.accept(
this.createCompletionProposal(attribute.getName(), attribute.getName(), null, context));
}
}
EList<EntityMockObjectFunction> _calculations = mockObject.getCalculations();
for (final EntityMockObjectFunction calculation : _calculations) {
acceptor.accept(
this.createCompletionProposal(calculation.getName(), calculation.getName(), null, context));
}
}
/**
* get the parser rule name for the given EObject
*/
protected String getParserRuleName(final EObject object) {
String retcode = ((String) null);
EObject parserRule = object;
while (((!Objects.equal(parserRule, null)) && (!(parserRule instanceof ParserRule)))) {
parserRule = parserRule.eContainer();
}
if ((parserRule instanceof ParserRule)) {
retcode = ((ParserRule)parserRule).getName();
}
return retcode;
}
/**
* checks if the keywords parser rule is contained in the given Class
*/
protected boolean isKeywordInsideParserRule(final Keyword keyword, final Class<?> eClass) {
String className = eClass.getCanonicalName();
return className.endsWith(this.getParserRuleName(keyword));
}
/**
* returns the allowed data type for the given Keyword
*/
protected IDataMart.EType getPropertyFillerType(final Keyword keyword) {
boolean _isKeywordInsideParserRule = this.isKeywordInsideParserRule(keyword, PropertyFillerDateFuture.class);
if (_isKeywordInsideParserRule) {
return IDataMart.EType.DATE;
}
boolean _isKeywordInsideParserRule_1 = this.isKeywordInsideParserRule(keyword, PropertyFillerDatePast.class);
if (_isKeywordInsideParserRule_1) {
return IDataMart.EType.DATE;
}
boolean _isKeywordInsideParserRule_2 = this.isKeywordInsideParserRule(keyword, PropertyFillerDateRange.class);
if (_isKeywordInsideParserRule_2) {
return IDataMart.EType.DATE;
}
boolean _isKeywordInsideParserRule_3 = this.isKeywordInsideParserRule(keyword, PropertyFillerSignedDoubleRandom.class);
if (_isKeywordInsideParserRule_3) {
return IDataMart.EType.DOUBLE;
}
boolean _isKeywordInsideParserRule_4 = this.isKeywordInsideParserRule(keyword, PropertyFillerSignedDoubleRange.class);
if (_isKeywordInsideParserRule_4) {
return IDataMart.EType.DOUBLE;
}
boolean _isKeywordInsideParserRule_5 = this.isKeywordInsideParserRule(keyword, PropertyFillerUnsignedDoubleRandom.class);
if (_isKeywordInsideParserRule_5) {
return IDataMart.EType.DOUBLE;
}
boolean _isKeywordInsideParserRule_6 = this.isKeywordInsideParserRule(keyword, PropertyFillerUnsignedDoubleRange.class);
if (_isKeywordInsideParserRule_6) {
return IDataMart.EType.DOUBLE;
}
boolean _isKeywordInsideParserRule_7 = this.isKeywordInsideParserRule(keyword, PropertyFillerSignedIntegerRandom.class);
if (_isKeywordInsideParserRule_7) {
return IDataMart.EType.INTEGER;
}
boolean _isKeywordInsideParserRule_8 = this.isKeywordInsideParserRule(keyword, PropertyFillerSignedIntegerRange.class);
if (_isKeywordInsideParserRule_8) {
return IDataMart.EType.INTEGER;
}
boolean _isKeywordInsideParserRule_9 = this.isKeywordInsideParserRule(keyword, PropertyFillerUnsignedIntegerRandom.class);
if (_isKeywordInsideParserRule_9) {
return IDataMart.EType.INTEGER;
}
boolean _isKeywordInsideParserRule_10 = this.isKeywordInsideParserRule(keyword, PropertyFillerUnsignedIntegerRange.class);
if (_isKeywordInsideParserRule_10) {
return IDataMart.EType.INTEGER;
}
boolean _isKeywordInsideParserRule_11 = this.isKeywordInsideParserRule(keyword, PropertyFillerTextParagraphs.class);
if (_isKeywordInsideParserRule_11) {
return IDataMart.EType.STRING;
}
boolean _isKeywordInsideParserRule_12 = this.isKeywordInsideParserRule(keyword, PropertyFillerTextRandom.class);
if (_isKeywordInsideParserRule_12) {
return IDataMart.EType.STRING;
}
boolean _isKeywordInsideParserRule_13 = this.isKeywordInsideParserRule(keyword, PropertyFillerTextSentences.class);
if (_isKeywordInsideParserRule_13) {
return IDataMart.EType.STRING;
}
boolean _isKeywordInsideParserRule_14 = this.isKeywordInsideParserRule(keyword, PropertyFillerTextWords.class);
if (_isKeywordInsideParserRule_14) {
return IDataMart.EType.STRING;
}
return IDataMart.EType.NONE;
}
/**
* checks if the given Keyword is allowed for the given entity attribute type
*/
@Override
protected boolean isKeywordWorthyToPropose(final Keyword keyword, final ContentAssistContext context) {
boolean _isKeywordWorthyToPropose = super.isKeywordWorthyToPropose(keyword, context);
boolean _not = (!_isKeywordWorthyToPropose);
if (_not) {
return false;
}
EObject currentModel = context.getCurrentModel();
if ((currentModel instanceof EntityMockAttributeFiller)) {
EntityMockAttributeFiller attributeByObject = ((EntityMockAttributeFiller) currentModel);
LEntityAttribute _attributeRef = attributeByObject.getAttributeRef();
LEntityAttribute attributeRef = ((LEntityAttribute) _attributeRef);
return this.dtType.canBeCastFrom(attributeRef, this.getPropertyFillerType(keyword));
}
return true;
}
@Override
protected boolean isValidProposal(final String proposal, final String prefix, final ContentAssistContext context) {
boolean _isValidProposal = super.isValidProposal(proposal, prefix, context);
boolean _not = (!_isValidProposal);
if (_not) {
return false;
} else {
EObject currentModel = context.getCurrentModel();
boolean _matched = false;
if (currentModel instanceof EntityMockObjectArrayValue) {
_matched=true;
return true;
}
return true;
}
}
@Override
public void complete_ID(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.provider.complete_ID(model, ruleCall, context, acceptor);
}
@Override
public void complete_STRING(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.provider.complete_STRING(model, ruleCall, context, acceptor);
}
@Override
public void complete_INT(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.provider.complete_INT(model, ruleCall, context, acceptor);
}
@Override
public void complete_SINT(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.provider.complete_INT(model, ruleCall, context, acceptor);
}
@Override
public void complete_QualifiedName(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.providerHelper.complete_PackageName(model, ruleCall, context, acceptor, this);
}
@Override
public void complete_UnsignedNumber(final EObject model, final RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
this.providerHelper.createNumberProposal(context, acceptor, ruleCall, this);
}
}