Java Code Examples for org.eclipse.xtext.xbase.XFeatureCall#getFeatureCallArguments()

The following examples show how to use org.eclipse.xtext.xbase.XFeatureCall#getFeatureCallArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XFeatureCall expr, @Extension final IFormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.noSpace();
    };
    final ISemanticRegion open = format.prepend(this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getExplicitOperationCallLeftParenthesisKeyword_3_0_0()), _function);
    final ISemanticRegion close = this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getRightParenthesisKeyword_3_2());
    this.formatFeatureCallParams(expr.getFeatureCallArguments(), open, close, format);
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example 2
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XFeatureCall expr, final FormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final ILeafNode open = this._nodeModelAccess.nodeForKeyword(expr, "(");
    final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> {
      it.noSpace();
    };
    Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(open, _function);
    format.operator_add(_prepend);
    boolean _isMultiParamInOwnLine = this.isMultiParamInOwnLine(expr, format);
    if (_isMultiParamInOwnLine) {
      this.formatFeatureCallParamsMultiline(open, expr.getFeatureCallArguments(), format);
    } else {
      this.formatFeatureCallParamsWrapIfNeeded(open, expr.getFeatureCallArguments(), format);
    }
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example 3
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkConstructorArgumentsAreValid(XFeatureCall featureCall) {
	JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) {
		JvmType containerType = EcoreUtil2.getContainerOfType(logicalContainerProvider.getNearestLogicalContainer(featureCall), JvmType.class);
		for(XExpression argument: featureCall.getFeatureCallArguments()) {
			checkIsValidConstructorArgument(argument, containerType);
		}
	}
}
 
Example 4
Source File: StandardFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, StandardFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 5
Source File: VarArgFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, VarArgFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 6
Source File: ReorderedVarArgFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, ReorderedVarArgFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: ReorderedFeatureCallArgumentsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected IFeatureCallArguments toArguments(final String signature, final String invocation, final boolean receiver) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(signature);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("m(");
    _builder.append(invocation, "\t");
    _builder.append(")");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    final String functionString = _builder.toString();
    final XtendFunction function = this.function(functionString);
    XExpression _expression = function.getExpression();
    final XBlockExpression body = ((XBlockExpression) _expression);
    XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
    final XFeatureCall featureCall = ((XFeatureCall) _head);
    final EList<XExpression> arguments = featureCall.getFeatureCallArguments();
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final IFeatureCallArguments result = this.factory.createStandardArguments(arguments, operation.getParameters(), receiver, this.getOwner());
    Class<? extends IFeatureCallArguments> _class = result.getClass();
    boolean _equals = Objects.equal(_class, ReorderedFeatureCallArguments.class);
    Assert.assertTrue(_equals);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source File: Jdt2Ecore.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Add the given constructors to the Ecore container.
 *
 * @param codeBuilder the code builder to use.
 * @param superClassConstructors the constructors defined in the super class.
 * @param context the context of the constructors.
 * @throws JavaModelException if the Java model is invalid.
 */
public void createStandardConstructorsWith(
		ConstructorBuilder codeBuilder,
		Collection<IMethod> superClassConstructors,
		XtendTypeDeclaration context) throws JavaModelException {
	if (superClassConstructors != null) {
		for (final IMethod constructor : superClassConstructors) {
			if (!isGeneratedOperation(constructor)) {
				final ISarlConstructorBuilder cons = codeBuilder.addConstructor();
				// Create parameters
				final IFormalParameterBuilder[] sarlParams = createFormalParametersWith(
					name -> cons.addParameter(name), constructor);
				// Create the block
				final IBlockExpressionBuilder block = cons.getExpression();
				// Create thre super-call expression
				final IExpressionBuilder superCall = block.addExpression();
				final XFeatureCall call = XbaseFactory.eINSTANCE.createXFeatureCall();
				superCall.setXExpression(call);
				// Set the todo comment.
				superCall.setDocumentation(block.getAutoGeneratedActionString());
				// Create the super-call XExpression
				call.setFeature(getJvmConstructor(constructor, context));
				call.setExplicitOperationCall(true);
				final List<XExpression> arguments = call.getFeatureCallArguments();
				for (final IFormalParameterBuilder currentParam : sarlParams) {
					final XFeatureCall argumentSource = XbaseFactory.eINSTANCE.createXFeatureCall();
					arguments.add(argumentSource);
					currentParam.setReferenceInto(argumentSource);
				}
			}
		}
	}
}
 
Example 9
Source File: XbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constraint:
 *     (
 *         declaringType=[JvmDeclaredType|StaticQualifier]?
 *         (typeArguments+=JvmArgumentTypeReference typeArguments+=JvmArgumentTypeReference*)?
 *         feature=[JvmIdentifiableElement|IdOrSuper]
 *         (explicitOperationCall?='(' (featureCallArguments+=XShortClosure | (featureCallArguments+=XExpression featureCallArguments+=XExpression*))?)?
 *     )
 *     
 *
 * Features:
 *    feature[1, 1]
 *    typeArguments[0, *]
 *    featureCallArguments[1, *]
 *         EXCLUDE_IF_UNSET explicitOperationCall
 *    explicitOperationCall[0, 1]
 *         MANDATORY_IF_SET featureCallArguments
 *         EXCLUDE_IF_UNSET featureCallArguments
 *         MANDATORY_IF_SET featureCallArguments
 *         MANDATORY_IF_SET featureCallArguments
 *    declaringType[0, 1]
 */
@Override
protected void sequence_XFeatureCall(ISerializationContext context, XFeatureCall featureCall) {
	INodesForEObjectProvider nodes = createNodeProvider(featureCall);
	SequenceFeeder acceptor = createSequencerFeeder(context, featureCall, nodes);
	XFeatureCallElements featureCallElements = grammarAccess.getXFeatureCallAccess();

	// (typeArguments+=JvmArgumentTypeReference typeArguments+=JvmArgumentTypeReference*)?
	List<JvmTypeReference> typeArguments = featureCall.getTypeArguments();
	if (!typeArguments.isEmpty()) {
		acceptor.accept(featureCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_1_1_0(), typeArguments.get(0), 0);
		for (int i = 1; i < typeArguments.size(); i++)
			acceptor.accept(featureCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_1_2_1_0(), typeArguments.get(i), i);
	}

	// feature=[JvmIdentifiableElement|IdOrSuper]
	acceptor.accept(featureCallElements.getFeatureJvmIdentifiableElementIdOrSuperParserRuleCall_2_0_1(), featureCall.getFeature());

	// (explicitOperationCall?='(' (featureCallArguments+=XShortClosure | (featureCallArguments+=XExpression featureCallArguments+=XExpression*))?)? featureCallArguments+=XClosure?
	if (featureCall.isExplicitOperationCallOrBuilderSyntax()) {
		if (featureCall.isExplicitOperationCall())
			acceptor.accept(featureCallElements.getExplicitOperationCallLeftParenthesisKeyword_3_0_0());
		List<XExpression> arguments = featureCall.getFeatureCallArguments();
		if (!arguments.isEmpty()) {
			if (featureCall.isExplicitOperationCall() && isXShortClosureAndBuilderSyntax(arguments, XbasePackage.Literals.XFEATURE_CALL__FEATURE_CALL_ARGUMENTS, nodes)) {
				acceptor.accept(featureCallElements.getFeatureCallArgumentsXShortClosureParserRuleCall_3_1_0_0(), arguments.get(0), 0);
				acceptor.accept(featureCallElements.getFeatureCallArgumentsXClosureParserRuleCall_4_0(), arguments.get(1), 1);
			} else if (featureCall.isExplicitOperationCall() && isXShortClosure(featureCall, XbasePackage.Literals.XFEATURE_CALL__FEATURE_CALL_ARGUMENTS, nodes)) {
				acceptor.accept(featureCallElements.getFeatureCallArgumentsXShortClosureParserRuleCall_3_1_0_0(), arguments.get(0), 0);
			} else {
				int diff = 0;
				if (isBuilderSyntax(featureCall, XbasePackage.Literals.XFEATURE_CALL__FEATURE_CALL_ARGUMENTS, featureCall.isExplicitOperationCall(), nodes)) {
					diff = 1;
				}
				if (featureCall.isExplicitOperationCall()) {
					if (arguments.size() - diff > 0)
						acceptor.accept(featureCallElements.getFeatureCallArgumentsXExpressionParserRuleCall_3_1_1_0_0(), arguments.get(0), 0);
					for (int i = 1; i < arguments.size() - diff; i++)
						acceptor.accept(featureCallElements.getFeatureCallArgumentsXExpressionParserRuleCall_3_1_1_1_1_0(), arguments.get(i), i);
				}
				if (diff != 0) {
					int lastIdx = arguments.size() - 1;
					acceptor.accept(featureCallElements.getFeatureCallArgumentsXClosureParserRuleCall_4_0(), arguments.get(lastIdx), lastIdx);
				}
			}
		}
	}
	acceptor.finish();
}