Search in sources :

Example 81 with JvmFormalParameter

use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksByOffset.

@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
    final EObject element = getEObjectAtOffsetHelper().resolveElementAt(resource, offset);
    if (element instanceof XImportDeclaration) {
        XImportDeclaration importDeclaration = (XImportDeclaration) element;
        if (importDeclaration.isStatic() && !importDeclaration.isWildcard()) {
            final ITextRegion textRegion = getTextRegion(importDeclaration, offset);
            if (textRegion != null) {
                final Region region = new Region(textRegion.getOffset(), textRegion.getLength());
                Iterable<JvmFeature> _allFeatures = staticImpMemberProvider.getAllFeatures(importDeclaration);
                for (final JvmFeature feature : _allFeatures) {
                    this.createHyperlinksTo(resource, region, feature, acceptor);
                }
            }
        }
    }
    super.createHyperlinksByOffset(resource, offset, acceptor);
    if (canShowMany(acceptor)) {
        if (element instanceof XVariableDeclaration) {
            XVariableDeclaration variableDeclaration = (XVariableDeclaration) element;
            ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
            if (isNameNode(element, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, node) && variableDeclaration.getType() == null) {
                addOpenInferredTypeHyperlink(resource, variableDeclaration, node, acceptor);
            }
        }
        if (element instanceof JvmFormalParameter) {
            JvmFormalParameter param = (JvmFormalParameter) element;
            ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
            if (isNameNode(element, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, node) && param.getParameterType() == null) {
                addOpenInferredTypeHyperlink(resource, param, node, acceptor);
            }
        }
    }
    createHyperlinksInJavaDoc(resource, offset, acceptor);
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Example 82 with JvmFormalParameter

use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-eclipse by eclipse.

the class DomainmodelJvmModelInferrer method removeDuplicateGettersSetters.

private void removeDuplicateGettersSetters(final JvmDeclaredType inferredType) {
    final Consumer<Collection<JvmOperation>> _function = (Collection<JvmOperation> jvmOperations) -> {
        final Function1<JvmOperation, Boolean> _function_1 = (JvmOperation it) -> {
            EObject _primarySourceElement = this._iJvmModelAssociations.getPrimarySourceElement(it);
            return Boolean.valueOf((_primarySourceElement instanceof Property));
        };
        final JvmOperation getterOrSetter = IterableExtensions.<JvmOperation>head(IterableExtensions.<JvmOperation>filter(jvmOperations, _function_1));
        if ((getterOrSetter != null)) {
            this._iJvmModelAssociator.removeAllAssociation(getterOrSetter.getReturnType());
            EList<JvmFormalParameter> _parameters = getterOrSetter.getParameters();
            for (final JvmFormalParameter p : _parameters) {
                {
                    this._iJvmModelAssociator.removeAllAssociation(p.getParameterType());
                    this._iJvmModelAssociator.removeAllAssociation(p);
                }
            }
            this._iJvmModelAssociator.removeAllAssociation(getterOrSetter);
            inferredType.getMembers().remove(getterOrSetter);
        }
    };
    this._domainmodelJvmModelHelper.handleDuplicateJvmOperations(inferredType, _function);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EList(org.eclipse.emf.common.util.EList) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EObject(org.eclipse.emf.ecore.EObject) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Collection(java.util.Collection) Property(org.eclipse.xtext.example.domainmodel.domainmodel.Property)

Example 83 with JvmFormalParameter

use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-eclipse by eclipse.

the class RuleEngineSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == RuleEnginePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case RuleEnginePackage.DEVICE:
                sequence_Device(context, (Device) semanticObject);
                return;
            case RuleEnginePackage.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
            case RuleEnginePackage.RULE:
                sequence_Rule(context, (Rule) semanticObject);
                return;
            case RuleEnginePackage.STATE:
                sequence_State(context, (State) semanticObject);
                return;
        }
    else if (epackage == TypesPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TypesPackage.JVM_FORMAL_PARAMETER:
                if (rule == grammarAccess.getFullJvmFormalParameterRule()) {
                    sequence_FullJvmFormalParameter(context, (JvmFormalParameter) semanticObject);
                    return;
                } else if (rule == grammarAccess.getJvmFormalParameterRule()) {
                    sequence_JvmFormalParameter(context, (JvmFormalParameter) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.JVM_GENERIC_ARRAY_TYPE_REFERENCE:
                sequence_JvmTypeReference(context, (JvmGenericArrayTypeReference) semanticObject);
                return;
            case TypesPackage.JVM_INNER_TYPE_REFERENCE:
                sequence_JvmParameterizedTypeReference(context, (JvmInnerTypeReference) semanticObject);
                return;
            case TypesPackage.JVM_LOWER_BOUND:
                if (rule == grammarAccess.getJvmLowerBoundAndedRule()) {
                    sequence_JvmLowerBoundAnded(context, (JvmLowerBound) semanticObject);
                    return;
                } else if (rule == grammarAccess.getJvmLowerBoundRule()) {
                    sequence_JvmLowerBound(context, (JvmLowerBound) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.JVM_PARAMETERIZED_TYPE_REFERENCE:
                if (action == grammarAccess.getJvmParameterizedTypeReferenceAccess().getJvmInnerTypeReferenceOuterAction_1_4_0_0_0()) {
                    sequence_JvmParameterizedTypeReference_JvmInnerTypeReference_1_4_0_0_0(context, (JvmParameterizedTypeReference) semanticObject);
                    return;
                } else if (rule == grammarAccess.getJvmTypeReferenceRule() || action == grammarAccess.getJvmTypeReferenceAccess().getJvmGenericArrayTypeReferenceComponentTypeAction_0_1_0_0() || rule == grammarAccess.getJvmParameterizedTypeReferenceRule() || rule == grammarAccess.getJvmArgumentTypeReferenceRule()) {
                    sequence_JvmParameterizedTypeReference(context, (JvmParameterizedTypeReference) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.JVM_TYPE_PARAMETER:
                sequence_JvmTypeParameter(context, (JvmTypeParameter) semanticObject);
                return;
            case TypesPackage.JVM_UPPER_BOUND:
                if (rule == grammarAccess.getJvmUpperBoundAndedRule()) {
                    sequence_JvmUpperBoundAnded(context, (JvmUpperBound) semanticObject);
                    return;
                } else if (rule == grammarAccess.getJvmUpperBoundRule()) {
                    sequence_JvmUpperBound(context, (JvmUpperBound) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.JVM_WILDCARD_TYPE_REFERENCE:
                sequence_JvmWildcardTypeReference(context, (JvmWildcardTypeReference) semanticObject);
                return;
        }
    else if (epackage == XbasePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case XbasePackage.XASSIGNMENT:
                sequence_XAssignment_XMemberFeatureCall(context, (XAssignment) semanticObject);
                return;
            case XbasePackage.XBASIC_FOR_LOOP_EXPRESSION:
                sequence_XBasicForLoopExpression(context, (XBasicForLoopExpression) semanticObject);
                return;
            case XbasePackage.XBINARY_OPERATION:
                sequence_XAdditiveExpression_XAndExpression_XAssignment_XEqualityExpression_XMultiplicativeExpression_XOrExpression_XOtherOperatorExpression_XRelationalExpression(context, (XBinaryOperation) semanticObject);
                return;
            case XbasePackage.XBLOCK_EXPRESSION:
                if (rule == grammarAccess.getXBlockExpressionRule() || rule == grammarAccess.getXExpressionRule() || rule == grammarAccess.getXAssignmentRule() || action == grammarAccess.getXAssignmentAccess().getXBinaryOperationLeftOperandAction_1_1_0_0_0() || rule == grammarAccess.getXOrExpressionRule() || action == grammarAccess.getXOrExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXAndExpressionRule() || action == grammarAccess.getXAndExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXEqualityExpressionRule() || action == grammarAccess.getXEqualityExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXRelationalExpressionRule() || action == grammarAccess.getXRelationalExpressionAccess().getXInstanceOfExpressionExpressionAction_1_0_0_0_0() || action == grammarAccess.getXRelationalExpressionAccess().getXBinaryOperationLeftOperandAction_1_1_0_0_0() || rule == grammarAccess.getXOtherOperatorExpressionRule() || action == grammarAccess.getXOtherOperatorExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXAdditiveExpressionRule() || action == grammarAccess.getXAdditiveExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXMultiplicativeExpressionRule() || action == grammarAccess.getXMultiplicativeExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXUnaryOperationRule() || rule == grammarAccess.getXCastedExpressionRule() || action == grammarAccess.getXCastedExpressionAccess().getXCastedExpressionTargetAction_1_0_0_0() || rule == grammarAccess.getXPostfixOperationRule() || action == grammarAccess.getXPostfixOperationAccess().getXPostfixOperationOperandAction_1_0_0() || rule == grammarAccess.getXMemberFeatureCallRule() || action == grammarAccess.getXMemberFeatureCallAccess().getXAssignmentAssignableAction_1_0_0_0_0() || action == grammarAccess.getXMemberFeatureCallAccess().getXMemberFeatureCallMemberCallTargetAction_1_1_0_0_0() || rule == grammarAccess.getXPrimaryExpressionRule() || rule == grammarAccess.getXParenthesizedExpressionRule() || rule == grammarAccess.getXExpressionOrVarDeclarationRule()) {
                    sequence_XBlockExpression(context, (XBlockExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getXExpressionInClosureRule()) {
                    sequence_XExpressionInClosure(context, (XBlockExpression) semanticObject);
                    return;
                } else
                    break;
            case XbasePackage.XBOOLEAN_LITERAL:
                sequence_XBooleanLiteral(context, (XBooleanLiteral) semanticObject);
                return;
            case XbasePackage.XCASE_PART:
                sequence_XCasePart(context, (XCasePart) semanticObject);
                return;
            case XbasePackage.XCASTED_EXPRESSION:
                sequence_XCastedExpression(context, (XCastedExpression) semanticObject);
                return;
            case XbasePackage.XCATCH_CLAUSE:
                sequence_XCatchClause(context, (XCatchClause) semanticObject);
                return;
            case XbasePackage.XCLOSURE:
                if (rule == grammarAccess.getXExpressionRule() || rule == grammarAccess.getXAssignmentRule() || action == grammarAccess.getXAssignmentAccess().getXBinaryOperationLeftOperandAction_1_1_0_0_0() || rule == grammarAccess.getXOrExpressionRule() || action == grammarAccess.getXOrExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXAndExpressionRule() || action == grammarAccess.getXAndExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXEqualityExpressionRule() || action == grammarAccess.getXEqualityExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXRelationalExpressionRule() || action == grammarAccess.getXRelationalExpressionAccess().getXInstanceOfExpressionExpressionAction_1_0_0_0_0() || action == grammarAccess.getXRelationalExpressionAccess().getXBinaryOperationLeftOperandAction_1_1_0_0_0() || rule == grammarAccess.getXOtherOperatorExpressionRule() || action == grammarAccess.getXOtherOperatorExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXAdditiveExpressionRule() || action == grammarAccess.getXAdditiveExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXMultiplicativeExpressionRule() || action == grammarAccess.getXMultiplicativeExpressionAccess().getXBinaryOperationLeftOperandAction_1_0_0_0() || rule == grammarAccess.getXUnaryOperationRule() || rule == grammarAccess.getXCastedExpressionRule() || action == grammarAccess.getXCastedExpressionAccess().getXCastedExpressionTargetAction_1_0_0_0() || rule == grammarAccess.getXPostfixOperationRule() || action == grammarAccess.getXPostfixOperationAccess().getXPostfixOperationOperandAction_1_0_0() || rule == grammarAccess.getXMemberFeatureCallRule() || action == grammarAccess.getXMemberFeatureCallAccess().getXAssignmentAssignableAction_1_0_0_0_0() || action == grammarAccess.getXMemberFeatureCallAccess().getXMemberFeatureCallMemberCallTargetAction_1_1_0_0_0() || rule == grammarAccess.getXPrimaryExpressionRule() || rule == grammarAccess.getXLiteralRule() || rule == grammarAccess.getXClosureRule() || rule == grammarAccess.getXParenthesizedExpressionRule() || rule == grammarAccess.getXExpressionOrVarDeclarationRule()) {
                    sequence_XClosure(context, (XClosure) semanticObject);
                    return;
                } else if (rule == grammarAccess.getXShortClosureRule()) {
                    sequence_XShortClosure(context, (XClosure) semanticObject);
                    return;
                } else
                    break;
            case XbasePackage.XCONSTRUCTOR_CALL:
                sequence_XConstructorCall(context, (XConstructorCall) semanticObject);
                return;
            case XbasePackage.XDO_WHILE_EXPRESSION:
                sequence_XDoWhileExpression(context, (XDoWhileExpression) semanticObject);
                return;
            case XbasePackage.XFEATURE_CALL:
                sequence_XFeatureCall(context, (XFeatureCall) semanticObject);
                return;
            case XbasePackage.XFOR_LOOP_EXPRESSION:
                sequence_XForLoopExpression(context, (XForLoopExpression) semanticObject);
                return;
            case XbasePackage.XIF_EXPRESSION:
                sequence_XIfExpression(context, (XIfExpression) semanticObject);
                return;
            case XbasePackage.XINSTANCE_OF_EXPRESSION:
                sequence_XRelationalExpression(context, (XInstanceOfExpression) semanticObject);
                return;
            case XbasePackage.XLIST_LITERAL:
                sequence_XListLiteral(context, (XListLiteral) semanticObject);
                return;
            case XbasePackage.XMEMBER_FEATURE_CALL:
                sequence_XMemberFeatureCall(context, (XMemberFeatureCall) semanticObject);
                return;
            case XbasePackage.XNULL_LITERAL:
                sequence_XNullLiteral(context, (XNullLiteral) semanticObject);
                return;
            case XbasePackage.XNUMBER_LITERAL:
                sequence_XNumberLiteral(context, (XNumberLiteral) semanticObject);
                return;
            case XbasePackage.XPOSTFIX_OPERATION:
                sequence_XPostfixOperation(context, (XPostfixOperation) semanticObject);
                return;
            case XbasePackage.XRETURN_EXPRESSION:
                sequence_XReturnExpression(context, (XReturnExpression) semanticObject);
                return;
            case XbasePackage.XSET_LITERAL:
                sequence_XSetLiteral(context, (XSetLiteral) semanticObject);
                return;
            case XbasePackage.XSTRING_LITERAL:
                sequence_XStringLiteral(context, (XStringLiteral) semanticObject);
                return;
            case XbasePackage.XSWITCH_EXPRESSION:
                sequence_XSwitchExpression(context, (XSwitchExpression) semanticObject);
                return;
            case XbasePackage.XSYNCHRONIZED_EXPRESSION:
                sequence_XSynchronizedExpression(context, (XSynchronizedExpression) semanticObject);
                return;
            case XbasePackage.XTHROW_EXPRESSION:
                sequence_XThrowExpression(context, (XThrowExpression) semanticObject);
                return;
            case XbasePackage.XTRY_CATCH_FINALLY_EXPRESSION:
                sequence_XTryCatchFinallyExpression(context, (XTryCatchFinallyExpression) semanticObject);
                return;
            case XbasePackage.XTYPE_LITERAL:
                sequence_XTypeLiteral(context, (XTypeLiteral) semanticObject);
                return;
            case XbasePackage.XUNARY_OPERATION:
                sequence_XUnaryOperation(context, (XUnaryOperation) semanticObject);
                return;
            case XbasePackage.XVARIABLE_DECLARATION:
                sequence_XVariableDeclaration(context, (XVariableDeclaration) semanticObject);
                return;
            case XbasePackage.XWHILE_EXPRESSION:
                sequence_XWhileExpression(context, (XWhileExpression) semanticObject);
                return;
        }
    else if (epackage == XtypePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case XtypePackage.XFUNCTION_TYPE_REF:
                sequence_XFunctionTypeRef(context, (XFunctionTypeRef) semanticObject);
                return;
            case XtypePackage.XIMPORT_DECLARATION:
                sequence_XImportDeclaration(context, (XImportDeclaration) semanticObject);
                return;
            case XtypePackage.XIMPORT_SECTION:
                sequence_XImportSection(context, (XImportSection) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : XCatchClause(org.eclipse.xtext.xbase.XCatchClause) XDoWhileExpression(org.eclipse.xtext.xbase.XDoWhileExpression) ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) XBasicForLoopExpression(org.eclipse.xtext.xbase.XBasicForLoopExpression) XClosure(org.eclipse.xtext.xbase.XClosure) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XPostfixOperation(org.eclipse.xtext.xbase.XPostfixOperation) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) XListLiteral(org.eclipse.xtext.xbase.XListLiteral) EPackage(org.eclipse.emf.ecore.EPackage) XInstanceOfExpression(org.eclipse.xtext.xbase.XInstanceOfExpression) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XCasePart(org.eclipse.xtext.xbase.XCasePart) XForLoopExpression(org.eclipse.xtext.xbase.XForLoopExpression) XNumberLiteral(org.eclipse.xtext.xbase.XNumberLiteral) XReturnExpression(org.eclipse.xtext.xbase.XReturnExpression) XAssignment(org.eclipse.xtext.xbase.XAssignment) XThrowExpression(org.eclipse.xtext.xbase.XThrowExpression) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XCastedExpression(org.eclipse.xtext.xbase.XCastedExpression) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XStringLiteral(org.eclipse.xtext.xbase.XStringLiteral) JvmLowerBound(org.eclipse.xtext.common.types.JvmLowerBound) Device(org.eclipse.xtext.example.homeautomation.ruleEngine.Device) XSetLiteral(org.eclipse.xtext.xbase.XSetLiteral) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XTypeLiteral(org.eclipse.xtext.xbase.XTypeLiteral) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) XSynchronizedExpression(org.eclipse.xtext.xbase.XSynchronizedExpression) XBooleanLiteral(org.eclipse.xtext.xbase.XBooleanLiteral) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) State(org.eclipse.xtext.example.homeautomation.ruleEngine.State) XNullLiteral(org.eclipse.xtext.xbase.XNullLiteral) XUnaryOperation(org.eclipse.xtext.xbase.XUnaryOperation) XWhileExpression(org.eclipse.xtext.xbase.XWhileExpression) Model(org.eclipse.xtext.example.homeautomation.ruleEngine.Model) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Parameter(org.eclipse.xtext.Parameter) ParserRule(org.eclipse.xtext.ParserRule) Rule(org.eclipse.xtext.example.homeautomation.ruleEngine.Rule) XTryCatchFinallyExpression(org.eclipse.xtext.xbase.XTryCatchFinallyExpression) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 84 with JvmFormalParameter

use of org.eclipse.xtext.common.types.JvmFormalParameter in project xtext-eclipse by eclipse.

the class RuleEngineJvmModelInferrer method _infer.

protected void _infer(final Model element, final IJvmDeclaredTypeAcceptor acceptor, final boolean isPreIndexingPhase) {
    final String className = StringExtensions.toFirstUpper(element.eResource().getURI().trimFileExtension().lastSegment());
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
        Iterable<Rule> _filter = Iterables.<Rule>filter(element.getDeclarations(), Rule.class);
        for (final Rule device : _filter) {
            EList<JvmMember> _members = it.getMembers();
            final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
                it_1.setStatic(true);
                this._jvmTypesBuilder.setBody(it_1, device.getThenPart());
            };
            JvmOperation _method = this._jvmTypesBuilder.toMethod(device, RuleEngineJvmModelInferrer.getRuleMethodName(device), this._typeReferenceBuilder.typeRef(void.class), _function_1);
            this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method);
        }
        EList<JvmMember> _members_1 = it.getMembers();
        final Procedure1<JvmOperation> _function_2 = (JvmOperation it_1) -> {
            it_1.setStatic(true);
            EList<JvmFormalParameter> _parameters = it_1.getParameters();
            JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(element, "event", this._typeReferenceBuilder.typeRef(Object.class));
            this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    {
                        Iterable<Device> _filter = Iterables.<Device>filter(element.getDeclarations(), Device.class);
                        for (final Device device : _filter) {
                            {
                                EList<State> _states = device.getStates();
                                for (final State state : _states) {
                                    _builder.append("if (event == ");
                                    String _qualifiedJavaName = RuleEngineJvmModelInferrer.this.getQualifiedJavaName(state);
                                    _builder.append(_qualifiedJavaName);
                                    _builder.append(") {");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("\t");
                                    _builder.append("System.out.println(\"");
                                    String _name = device.getName();
                                    _builder.append(_name, "\t");
                                    _builder.append(" is now ");
                                    String _name_1 = state.getName();
                                    _builder.append(_name_1, "\t");
                                    _builder.append("!\");");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("}");
                                    _builder.newLine();
                                }
                            }
                        }
                    }
                    {
                        Iterable<Rule> _filter_1 = Iterables.<Rule>filter(element.getDeclarations(), Rule.class);
                        for (final Rule rule : _filter_1) {
                            _builder.append("if (event == ");
                            String _qualifiedJavaName_1 = RuleEngineJvmModelInferrer.this.getQualifiedJavaName(rule.getDeviceState());
                            _builder.append(_qualifiedJavaName_1);
                            _builder.append(") {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            String _ruleMethodName = RuleEngineJvmModelInferrer.getRuleMethodName(rule);
                            _builder.append(_ruleMethodName, "\t");
                            _builder.append("();");
                            _builder.newLineIfNotEmpty();
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                }
            };
            this._jvmTypesBuilder.setBody(it_1, _client);
        };
        JvmOperation _method_1 = this._jvmTypesBuilder.toMethod(element, "fire", this._typeReferenceBuilder.typeRef(void.class), _function_2);
        this._jvmTypesBuilder.<JvmOperation>operator_add(_members_1, _method_1);
        EList<JvmMember> _members_2 = it.getMembers();
        final Procedure1<JvmOperation> _function_3 = (JvmOperation it_1) -> {
            it_1.setStatic(true);
            EList<JvmFormalParameter> _parameters = it_1.getParameters();
            JvmFormalParameter _parameter = this._jvmTypesBuilder.toParameter(element, "args", this._jvmTypesBuilder.addArrayTypeDimension(this._typeReferenceBuilder.typeRef(String.class)));
            this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter);
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append(Scanner.class);
                    _builder.append(" scanner = new Scanner(System.in);");
                    _builder.newLineIfNotEmpty();
                    _builder.append("System.out.println(\"Welcome home!\");");
                    _builder.newLine();
                    _builder.append("System.out.println(\"Available commands : \");");
                    _builder.newLine();
                    {
                        Iterable<Device> _filter = Iterables.<Device>filter(element.getDeclarations(), Device.class);
                        for (final Device device : _filter) {
                            {
                                EList<State> _states = device.getStates();
                                for (final State state : _states) {
                                    _builder.append("System.out.println(\"  ");
                                    String _name = device.getName();
                                    _builder.append(_name);
                                    _builder.append(" ");
                                    String _name_1 = state.getName();
                                    _builder.append(_name_1);
                                    _builder.append("\" );");
                                    _builder.newLineIfNotEmpty();
                                }
                            }
                        }
                    }
                    _builder.append("System.out.println(\"Have fun!\");");
                    _builder.newLine();
                    _builder.append("while(true) {");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("String command = scanner.next();");
                    _builder.newLine();
                    {
                        Iterable<Device> _filter_1 = Iterables.<Device>filter(element.getDeclarations(), Device.class);
                        for (final Device device_1 : _filter_1) {
                            _builder.append("\t");
                            _builder.append("if (command.equalsIgnoreCase(\"");
                            String _name_2 = device_1.getName();
                            _builder.append(_name_2, "\t");
                            _builder.append("\")) {");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("String secondaryCommand = scanner.next();");
                            _builder.newLine();
                            {
                                EList<State> _states_1 = device_1.getStates();
                                for (final State state_1 : _states_1) {
                                    _builder.append("\t");
                                    _builder.append("\t");
                                    _builder.append("if (secondaryCommand.equalsIgnoreCase(\"");
                                    String _name_3 = state_1.getName();
                                    _builder.append(_name_3, "\t\t");
                                    _builder.append("\")) {");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("\t");
                                    _builder.append("\t");
                                    _builder.append("\t");
                                    _builder.append("fire(");
                                    String _qualifiedJavaName = RuleEngineJvmModelInferrer.this.getQualifiedJavaName(state_1);
                                    _builder.append(_qualifiedJavaName, "\t\t\t");
                                    _builder.append(");");
                                    _builder.newLineIfNotEmpty();
                                    _builder.append("\t");
                                    _builder.append("\t");
                                    _builder.append("} else ");
                                    _builder.newLine();
                                }
                            }
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("{");
                            _builder.newLine();
                            _builder.append("\t");
                            _builder.append("\t\t");
                            _builder.append("System.out.println(\"");
                            String _name_4 = device_1.getName();
                            _builder.append(_name_4, "\t\t\t");
                            _builder.append(" can only have the following states: ");
                            final Function1<State, String> _function = (State it_2) -> {
                                return it_2.getName();
                            };
                            String _join = IterableExtensions.join(ListExtensions.<State, String>map(device_1.getStates(), _function), ",");
                            _builder.append(_join, "\t\t\t");
                            _builder.append(".\");");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("}");
                            _builder.newLine();
                            _builder.append("\t");
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                    _builder.append("\t");
                    _builder.append("if (command.equalsIgnoreCase(\"bye\")) {");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("System.out.println(\"Ciao!\");");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("break;");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("}");
                    _builder.newLine();
                }
            };
            this._jvmTypesBuilder.setBody(it_1, _client);
        };
        JvmOperation _method_2 = this._jvmTypesBuilder.toMethod(element, "main", this._typeReferenceBuilder.typeRef(void.class), _function_3);
        this._jvmTypesBuilder.<JvmOperation>operator_add(_members_2, _method_2);
    };
    acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(element, className), _function);
    Iterable<Device> _filter = Iterables.<Device>filter(element.getDeclarations(), Device.class);
    for (final Device device : _filter) {
        final Procedure1<JvmEnumerationType> _function_1 = (JvmEnumerationType it) -> {
        };
        final Procedure1<JvmEnumerationType> _function_2 = (JvmEnumerationType it) -> {
            EList<State> _states = device.getStates();
            for (final State state : _states) {
                EList<JvmMember> _members = it.getMembers();
                final Procedure1<JvmEnumerationLiteral> _function_3 = (JvmEnumerationLiteral it_1) -> {
                    it_1.setVisibility(JvmVisibility.PUBLIC);
                };
                JvmEnumerationLiteral _enumerationLiteral = this._jvmTypesBuilder.toEnumerationLiteral(state, state.getName(), _function_3);
                this._jvmTypesBuilder.<JvmEnumerationLiteral>operator_add(_members, _enumerationLiteral);
            }
        };
        acceptor.<JvmEnumerationType>accept(this._jvmTypesBuilder.toEnumerationType(device, device.getName(), _function_1), _function_2);
    }
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Device(org.eclipse.xtext.example.homeautomation.ruleEngine.Device) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EList(org.eclipse.emf.common.util.EList) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) State(org.eclipse.xtext.example.homeautomation.ruleEngine.State) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) EObject(org.eclipse.emf.ecore.EObject) Rule(org.eclipse.xtext.example.homeautomation.ruleEngine.Rule) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Aggregations

JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)84 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)37 Test (org.junit.Test)30 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)15 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)14 JvmType (org.eclipse.xtext.common.types.JvmType)13 EObject (org.eclipse.emf.ecore.EObject)12 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)11 XExpression (org.eclipse.xtext.xbase.XExpression)11 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)10 XClosure (org.eclipse.xtext.xbase.XClosure)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)9 JvmMember (org.eclipse.xtext.common.types.JvmMember)8 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)7 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)7 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)7