Java Code Examples for org.eclipse.xtext.xbase.XConstructorCall#getTypeArguments()

The following examples show how to use org.eclipse.xtext.xbase.XConstructorCall#getTypeArguments() . 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: TypeInsteadOfConstructorLinkingCandidate.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public List<LightweightTypeReference> getSyntacticTypeArguments() {
	XConstructorCall constructorCall = getConstructorCall();
	List<JvmTypeReference> typeArguments = constructorCall.getTypeArguments();
	if (typeArguments.isEmpty())
		return Collections.emptyList();
	List<LightweightTypeReference> result = Lists.newArrayList();
	for(JvmTypeReference typeArgument: typeArguments) {
		result.add(getState().getReferenceOwner().toLightweightTypeReference(typeArgument));
	}
	return result;
}
 
Example 2
Source File: UnresolvableConstructorCall.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<LightweightTypeReference> getTypeArguments() {
	XConstructorCall constructorCall = getConstructorCall();
	List<JvmTypeReference> typeArguments = constructorCall.getTypeArguments();
	if (typeArguments.isEmpty())
		return Collections.emptyList();
	List<LightweightTypeReference> result = Lists.newArrayList();
	for(JvmTypeReference typeArgument: typeArguments) {
		result.add(getState().getReferenceOwner().toLightweightTypeReference(typeArgument));
	}
	return result;
}
 
Example 3
Source File: XtendReentrantTypeResolver.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmParameterizedTypeReference createSuperTypeReference(JvmType superType, XConstructorCall constructorCall) {
	JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
	result.setType(superType);
	for(JvmTypeReference typeReference: constructorCall.getTypeArguments()) {
		result.getArguments().add(typesBuilder.cloneWithProxies(typeReference));
	}
	return result;
}
 
Example 4
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Check
public void checkTypeArguments(XConstructorCall expression) {
	for (JvmTypeReference typeRef : expression.getTypeArguments()) {
		ensureNotPrimitiveNorWildcard(typeRef);
	}
}
 
Example 5
Source File: XbaseSemanticSequencer.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Constraint:
 *     (
 *         constructor=[JvmConstructor|QualifiedName] 
 *         (typeArguments+=JvmArgumentTypeReference typeArguments+=JvmArgumentTypeReference*)? 
 *         (arguments+=XShortClosure | (arguments+=XExpression arguments+=XExpression*))? 
 *         arguments+=XClosure?
 *     )
 */
@Override
protected void sequence_XConstructorCall(ISerializationContext context, XConstructorCall constructorCall) {
	INodesForEObjectProvider nodes = createNodeProvider(constructorCall);
	SequenceFeeder acceptor = createSequencerFeeder(context, constructorCall, nodes);
	XConstructorCallElements constructorCallElements = grammarAccess.getXConstructorCallAccess();

	// constructor=[types::JvmConstructor|QualifiedName]
	acceptor.accept(constructorCallElements.getConstructorJvmConstructorQualifiedNameParserRuleCall_2_0_1(), constructorCall.getConstructor());

	// '<' typeArguments+=JvmArgumentTypeReference (',' typeArguments+=JvmArgumentTypeReference)* '>'
	List<JvmTypeReference> typeArguments = constructorCall.getTypeArguments();
	if (!typeArguments.isEmpty()) {
		acceptor.accept(constructorCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_3_1_0(), typeArguments.get(0), 0);
		for (int i = 1; i < typeArguments.size(); i++)
			acceptor.accept(constructorCallElements.getTypeArgumentsJvmArgumentTypeReferenceParserRuleCall_3_2_1_0(), typeArguments.get(i), i);
	}
	

	/*
	 * Constraint:
	 *      
	 *     (explicitConstructorCall?='(' (arguments+=XShortClosure | (arguments+=XExpression arguments+=XExpression*))?)? 
	 *     arguments+=XClosure?
	 *     
	 */
	if (constructorCall.isExplicitConstructorCall()) {
		acceptor.accept(constructorCallElements.getExplicitConstructorCallLeftParenthesisKeyword_4_0_0());
	}
	List<XExpression> arguments = constructorCall.getArguments();
	if (!arguments.isEmpty()) {
		if (constructorCall.isExplicitConstructorCall() && isXShortClosureAndBuilderSyntax(arguments, XbasePackage.Literals.XCONSTRUCTOR_CALL__ARGUMENTS, nodes)) {
			acceptor.accept(constructorCallElements.getArgumentsXShortClosureParserRuleCall_4_1_0_0(), arguments.get(0), 0);
			acceptor.accept(constructorCallElements.getArgumentsXClosureParserRuleCall_5_0(), arguments.get(1), 1);
		} else if (constructorCall.isExplicitConstructorCall() && isXShortClosure(constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__ARGUMENTS, nodes)) {
			acceptor.accept(constructorCallElements.getArgumentsXShortClosureParserRuleCall_4_1_0_0(), arguments.get(0), 0);
		} else {
			int diff = 0;
			if (isBuilderSyntax(arguments, XbasePackage.Literals.XCONSTRUCTOR_CALL__ARGUMENTS, nodes)) {
				diff = 1;
			}
			if (constructorCall.isExplicitConstructorCall()) {
				if (arguments.size() - diff > 0)
					acceptor.accept(constructorCallElements.getArgumentsXExpressionParserRuleCall_4_1_1_0_0(), arguments.get(0), 0);
				for (int i = 1; i < arguments.size() - diff; i++)
					acceptor.accept(constructorCallElements.getArgumentsXExpressionParserRuleCall_4_1_1_1_1_0(), arguments.get(i), i);
			}
			if (diff != 0) {
				int lastIdx = arguments.size() - 1;
				acceptor.accept(constructorCallElements.getArgumentsXClosureParserRuleCall_5_0(), arguments.get(lastIdx), lastIdx);
			}
		}
	}
	acceptor.finish();
}