Java Code Examples for org.eclipse.xtext.common.types.JvmTypeReference

The following examples show how to use org.eclipse.xtext.common.types.JvmTypeReference. These examples are extracted from open source projects. 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 Project: sarl   Source File: SARLValidator.java    License: Apache License 2.0 6 votes vote down vote up
private Collection<ActionParameterTypes> doGetConstructorParameterTypes(Class<?> type, Notifier context) {
	final Collection<ActionParameterTypes> parameters = new ArrayList<>();
	final JvmTypeReference typeReference = this.typeReferences.getTypeForName(type, context);
	final JvmType jvmType = typeReference.getType();
	if (jvmType instanceof JvmDeclaredType) {
		final JvmDeclaredType declaredType = (JvmDeclaredType) jvmType;
		for (final JvmConstructor constructor : declaredType.getDeclaredConstructors()) {
			final ActionParameterTypes types = this.sarlActionSignatures.createParameterTypesFromJvmModel(
					constructor.isVarArgs(), constructor.getParameters());
			if (types != null) {
				parameters.add(types);
			}
		}
	}
	if (parameters.isEmpty()) {
		parameters.add(this.sarlActionSignatures.createParameterTypesForVoid());
	}
	return parameters;
}
 
Example 2
@Override
public void applyToModel(IResolvedTypes resolvedTypes) {
	if (!closure.isExplicitSyntax()) {
		List<JvmFormalParameter> parametersToAdd = getParameters();
		InternalEList<JvmFormalParameter> targetList = (InternalEList<JvmFormalParameter>) closure.getImplicitFormalParameters();
		if (!targetList.isEmpty()) {
			// things are already available, do nothing
			return;
		}
		for(int i = 0; i < parametersToAdd.size(); i++) {
			JvmFormalParameter parameter = parametersToAdd.get(i);
			LightweightTypeReference parameterType = resolvedTypes.getActualType(parameter);
			if (parameterType == null) {
				throw new IllegalStateException("Cannot find type for parameter " + parameter.getSimpleName());
			}
			JvmTypeReference typeReference = parameterType.toTypeReference();
			parameter.setParameterType(typeReference);
			targetList.addUnique(parameter);
		}
	}
	((XClosureImplCustom) closure).setLinked(true);
}
 
Example 3
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setParameterType(JvmTypeReference newParameterType)
{
	if (newParameterType != parameterType)
	{
		NotificationChain msgs = null;
		if (parameterType != null)
			msgs = ((InternalEObject)parameterType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_FORMAL_PARAMETER__PARAMETER_TYPE, null, msgs);
		if (newParameterType != null)
			msgs = ((InternalEObject)newParameterType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TypesPackage.JVM_FORMAL_PARAMETER__PARAMETER_TYPE, null, msgs);
		msgs = basicSetParameterType(newParameterType, msgs);
		if (msgs != null) msgs.dispatch();
	}
	else if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.JVM_FORMAL_PARAMETER__PARAMETER_TYPE, newParameterType, newParameterType));
}
 
Example 4
@Test
public void test_ParameterizedTypes_Inner_Y_01() {
	String typeName = ParameterizedTypes.Inner.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmTypeParameter typeParameterY = type.getTypeParameters().get(1);
	assertEquals("Y", typeParameterY.getIdentifier());
	assertSame(type, typeParameterY.getDeclarator());
	assertEquals(1, typeParameterY.getConstraints().size());
	JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0);
	assertTrue(typeConstraint instanceof JvmUpperBound);
	JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
	assertNotNull(upperBound.getTypeReference());
	assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier());
	JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference();
	assertEquals(1, listType.getArguments().size());
	JvmTypeReference typeArgument = listType.getArguments().get(0);
	assertEquals("X", typeArgument.getIdentifier());
	JvmTypeParameter x = type.getTypeParameters().get(0);
	assertSame(x, typeArgument.getType());
}
 
Example 5
Source Project: sarl   Source File: Bug776Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void parsing_08() throws Exception {
	ParseHelper<SarlScript> parser = getParseHelper();
	SarlScript mas1 = parser.parse(multilineString(
			"package io.sarl.lang.tests.bug776.b",
			"class Toto{}"));
	SarlScript mas2 = parser.parse(multilineString(
			"package io.sarl.lang.tests.bug776",
			"import io.sarl.lang.tests.bug776.b.Toto",
			"class X {",
			"}",
			"class Y extends Z {",
			" static class YX {",
			"    var a : Toto",
			" }",
			"}",
			"class Z {",
			"}",
			""),
			mas1.eResource().getResourceSet());
	XtendClass container = ((XtendClass) mas2.getXtendTypes().get(1).getMembers().get(0));
	JvmTypeReference typeRef = ((SarlField) container.getMembers().get(0)).getType();
	assertEquals("Toto", this.strings.referenceToString(typeRef, "Object"));
}
 
Example 6
@Override
public String toString() {
	StringBuilder result = new StringBuilder(eClass().getName());
	result.append(": ");
	if (references != null && !references.isEmpty()) {
		boolean first = true;
		for(JvmTypeReference reference: references) {
			if (!first)
				result.append(getDelimiter());
			first = false;
			result.append(reference.toString());
		}
	} else {
		result.append(" ./. ");
	}
	return result.toString();
}
 
Example 7
@Test
public void testImplements() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      it.setAbstract(true);
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this.typeRef(expression, Iterable.class, String.class);
      this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiled = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source Project: xtext-extras   Source File: TypeReferences.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public JvmTypeReference getArgument(JvmTypeReference left, int index) {
	if (left.getType() instanceof JvmGenericType) {
		List<JvmTypeParameter> typeParameters = ((JvmGenericType) left.getType()).getTypeParameters();
		if (typeParameters.size() <= index) {
			throw new IllegalArgumentException("The type " + left.getType().getIdentifier()
					+ " cannot be parameterized with more than " + typeParameters.size() + " type arguments.");
		}
		if (left instanceof JvmParameterizedTypeReference) {
			List<JvmTypeReference> arguments = ((JvmParameterizedTypeReference) left).getArguments();
			if (arguments.size() == typeParameters.size()) {
				return arguments.get(index);
			}
		}
		final JvmTypeParameter jvmTypeParameter = typeParameters.get(index);
		return createTypeRef(jvmTypeParameter);
	}
	throw new IllegalArgumentException(left.getType().getIdentifier() + " is not generic.");
}
 
Example 9
protected Object _internalEvaluate(final XNumberLiteral it, final Context ctx) {
  try {
    Number _xblockexpression = null;
    {
      Class<? extends Number> _xifexpression = null;
      JvmTypeReference _expectedType = ctx.getExpectedType();
      boolean _tripleEquals = (_expectedType == null);
      if (_tripleEquals) {
        _xifexpression = this.numberLiterals.getJavaType(it);
      } else {
        Class<?> _javaType = this.getJavaType(ctx.getExpectedType().getType(), ctx.getClassFinder());
        _xifexpression = ((Class<? extends Number>) _javaType);
      }
      final Class<? extends Number> type = _xifexpression;
      _xblockexpression = this.numberLiterals.numberValue(it, type);
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
@Test
public void testExtends() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      it.setAbstract(true);
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this.typeRef(expression, AbstractList.class, String.class);
      this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiled = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
    Assert.assertTrue(AbstractList.class.isAssignableFrom(compiled));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
@Test
public void test_ParameterizedTypes_Inner_07() {
	String typeName = ParameterizedTypes.Inner.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_01()");
	JvmTypeReference listZ = methodV.getReturnType();
	assertEquals("java.util.List<Z[][]>", listZ.getIdentifier());
	JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ;
	assertEquals(1, listType.getArguments().size());
	JvmTypeReference typeArgument = listType.getArguments().get(0);
	JvmType argumentType = typeArgument.getType();
	assertTrue(argumentType instanceof JvmArrayType);
	assertTrue(((JvmArrayType) argumentType).getComponentType() instanceof JvmArrayType);
	JvmComponentType componentType = ((JvmArrayType) ((JvmArrayType) argumentType).getComponentType())
			.getComponentType();
	JvmTypeParameter z = type.getTypeParameters().get(2);
	assertSame(z, componentType);
}
 
Example 12
Source Project: dsl-devkit   Source File: MemberImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID)
{
	switch (featureID)
	{
		case CheckPackage.MEMBER__ANNOTATIONS:
			getAnnotations().clear();
			return;
		case CheckPackage.MEMBER__TYPE:
			setType((JvmTypeReference)null);
			return;
		case CheckPackage.MEMBER__NAME:
			setName(NAME_EDEFAULT);
			return;
		case CheckPackage.MEMBER__VALUE:
			setValue((XExpression)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example 13
Source Project: sarl   Source File: PyGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/** Generate the given object.
 *
 * @param agent the agent.
 * @param context the context.
 */
protected void _generate(SarlAgent agent, IExtraLanguageGeneratorContext context) {
	final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(agent);
	final PyAppendable appendable = createAppendable(jvmType, context);
	final List<JvmTypeReference> superTypes;
	if (agent.getExtends() != null) {
		superTypes = Collections.singletonList(agent.getExtends());
	} else {
		superTypes = Collections.singletonList(getTypeReferences().getTypeForName(Agent.class, agent));
	}
	final String qualifiedName = this.qualifiedNameProvider.getFullyQualifiedName(agent).toString();
	if (generateTypeDeclaration(
			qualifiedName,
			agent.getName(), agent.isAbstract(), superTypes,
			getTypeBuilder().getDocumentation(agent),
			true,
		agent.getMembers(), appendable, context, (it, context2) -> {
			generateGuardEvaluators(qualifiedName, it, context2);
		})) {
		final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(agent);
		writeFile(name, appendable, context);
	}
}
 
Example 14
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XbasePackage.XABSTRACT_FEATURE_CALL__FEATURE:
			setFeature((JvmIdentifiableElement)newValue);
			return;
		case XbasePackage.XABSTRACT_FEATURE_CALL__TYPE_ARGUMENTS:
			getTypeArguments().clear();
			getTypeArguments().addAll((Collection<? extends JvmTypeReference>)newValue);
			return;
		case XbasePackage.XABSTRACT_FEATURE_CALL__IMPLICIT_RECEIVER:
			setImplicitReceiver((XExpression)newValue);
			return;
		case XbasePackage.XABSTRACT_FEATURE_CALL__INVALID_FEATURE_ISSUE_CODE:
			setInvalidFeatureIssueCode((String)newValue);
			return;
		case XbasePackage.XABSTRACT_FEATURE_CALL__IMPLICIT_FIRST_ARGUMENT:
			setImplicitFirstArgument((XExpression)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example 15
Source Project: sarl   Source File: SARLJvmModelInferrer.java    License: Apache License 2.0 6 votes vote down vote up
/** Clone the given type reference that is associated to another Xtext resource.
 *
 * <p>This function ensures that the resource of the reference clone is not pointing
 * to the resource of the original reference.
 *
 * <p>This function calls {@link JvmTypesBuilder#cloneWithProxies(JvmTypeReference)} or
 * {@link #cloneWithTypeParametersAndProxies(JvmTypeReference, JvmExecutable)} if the
 * {@code target} is {@code null} for the first, and not {@code null} for the second.
 *
 * @param type the source type.
 * @param target the operation for which the type is clone, or {@code null} if not relevant.
 * @return the result type, i.e. a copy of the source type.
 */
protected JvmTypeReference cloneWithProxiesFromOtherResource(JvmTypeReference type, JvmOperation target) {
	if (type == null) {
		return this._typeReferenceBuilder.typeRef(Void.TYPE);
	}
	// Do not clone inferred types because they are not yet resolved and it is located within the current resource.
	if (InferredTypeIndicator.isInferred(type)) {
		return type;
	}
	// Do not clone primitive types because the associated resource to the type reference will not be correct.
	final String id = type.getIdentifier();
	if (Objects.equal(id, Void.TYPE.getName())) {
		return this._typeReferenceBuilder.typeRef(Void.TYPE);
	}
	if (this.services.getPrimitives().isPrimitive(type)) {
		return this._typeReferenceBuilder.typeRef(id);
	}
	// Clone the type
	if (target != null) {
		return cloneWithTypeParametersAndProxies(type, target);
	}
	return this.typeBuilder.cloneWithProxies(type);
}
 
Example 16
Source Project: xtext-extras   Source File: UIStrings.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected String parametersToString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs, boolean includeName) {
	StringBuilder result = new StringBuilder();
	boolean needsSeparator = false;
	Iterator<? extends JvmFormalParameter> iterator = elements.iterator();
	while (iterator.hasNext()) {
		JvmFormalParameter parameter = iterator.next();
		if (needsSeparator)
			result.append(", ");
		needsSeparator = true;
		JvmTypeReference typeRef = parameter.getParameterType();
		if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) {
			typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType();
			result.append(referenceToString(typeRef, "[null]"));
			result.append("...");
		} else {
			result.append(referenceToString(typeRef, "[null]"));
		}
		if (includeName) {
			result.append(" " + parameter.getName());
		}
	}
	return result.toString();
}
 
Example 17
@Test
public void test_twoListParamsNoResult_03() {
	JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods(
			"twoListParamsNoResult(java.util.List,java.util.List)");
	JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0);
	JvmTypeReference paramType = firstParam.getParameterType();
	JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType;
	assertEquals(1, parameterized.getArguments().size());
	JvmTypeReference typeParameter = parameterized.getArguments().get(0);
	JvmType referencedType = typeParameter.getType();
	assertFalse(referencedType.eIsProxy());
	assertTrue(referencedType instanceof JvmTypeParameter);
	JvmTypeParameter typeVar = (JvmTypeParameter) referencedType;
	assertEquals("T", typeVar.getName());
	assertSame(twoListParamsNoResult, typeVar.getDeclarator());
}
 
Example 18
@Override
protected String getStringRepresentation(Object object) {
	if (object instanceof JvmType) {
		return _getStringRepresentation((JvmType) object);
	} else if (object instanceof Class) {
		return _getStringRepresentation((Class<?>) object);
	} else if (object instanceof JvmTypeReference) {
		return _getStringRepresentation((JvmTypeReference) object);
	} else if (object instanceof LightweightTypeReference) {
		return _getStringRepresentation((LightweightTypeReference) object);
	} else if (object != null) {
		return _getStringRepresentation(object);
	} else {
		throw new IllegalArgumentException(
				"Unhandled parameter types: " + Arrays.<Object>asList(object).toString());
	}
}
 
Example 19
protected void _infer(final Model m, final IJvmDeclaredTypeAcceptor acceptor, final boolean prelinkingPhase) {
  final XBlockExpression e = m.getBlock();
  final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
    EList<JvmMember> _members = it.getMembers();
    final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
      EList<JvmTypeReference> _exceptions = it_1.getExceptions();
      JvmTypeReference _typeRef = this._typeReferenceBuilder.typeRef(Throwable.class);
      this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef);
      this._jvmTypesBuilder.setBody(it_1, e);
    };
    JvmOperation _method = this._jvmTypesBuilder.toMethod(e, "myMethod", this._jvmTypesBuilder.inferredType(), _function_1);
    this._jvmTypesBuilder.<JvmOperation>operator_add(_members, _method);
  };
  acceptor.<JvmGenericType>accept(this._jvmTypesBuilder.toClass(e, this.name(e.eResource())), _function);
}
 
Example 20
Source Project: xtext-extras   Source File: XCasePartImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetTypeGuard(JvmTypeReference newTypeGuard, NotificationChain msgs)
{
	JvmTypeReference oldTypeGuard = typeGuard;
	typeGuard = newTypeGuard;
	if (eNotificationRequired())
	{
		ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XbasePackage.XCASE_PART__TYPE_GUARD, oldTypeGuard, newTypeGuard);
		if (msgs == null) msgs = notification; else msgs.add(notification);
	}
	return msgs;
}
 
Example 21
Source Project: xtext-extras   Source File: UnboundTypeReference.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public JvmTypeReference toTypeReference() {
	if (internalGetResolvedTo() != null) {
		return resolvedTo.toTypeReference();
	}
	XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference();
	result.setTypeProvider(new UnboundTypeReferenceResolver(this));
	return result;
}
 
Example 22
@Override
public List<LightweightTypeReference> getResolvedTypeParameterConstraints(int idx) throws IndexOutOfBoundsException {
	JvmTypeParameter typeParameter = getResolvedTypeParameters().get(idx);
	List<JvmTypeConstraint> constraints = typeParameter.getConstraints();
	List<JvmTypeReference> constraintReferences = Lists.newArrayListWithCapacity(constraints.size());
	for(JvmTypeConstraint constraint: constraints) {
		constraintReferences.add(constraint.getTypeReference());
	}
	List<LightweightTypeReference> result = getResolvedReferences(constraintReferences);
	return result;
}
 
Example 23
private boolean isRawType(JvmTypeParameter current, RecursionGuard<JvmTypeParameter> guard) {
	if (guard.tryNext(current)) {
		List<JvmTypeConstraint> constraints = current.getConstraints();
		for(int i = 0, size = constraints.size(); i < size; i++) {
			JvmTypeConstraint constraint = constraints.get(i);
			if (constraint.eClass() == TypesPackage.Literals.JVM_UPPER_BOUND && constraint.getTypeReference() != null) {
				JvmTypeReference superType = constraint.getTypeReference();
				JvmType rawSuperType = superType.getType();
				if (rawSuperType != null) {
					if (rawSuperType.eClass() == TypesPackage.Literals.JVM_TYPE_PARAMETER) {
						if (isRawType((JvmTypeParameter) rawSuperType, guard)) {
							return true;
						}
					}
					if (rawSuperType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
						if (!((JvmGenericType) rawSuperType).getTypeParameters().isEmpty()) {
							if (superType.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
								JvmParameterizedTypeReference casted = (JvmParameterizedTypeReference) superType;
								if (casted.getArguments().isEmpty()) {
									return true;
								}
							}
						}
					}
				}
			}
		}
	}
	return false;
}
 
Example 24
Source Project: xtext-xtend   Source File: XtendClassImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<JvmTypeReference> getImplements()
{
	if (implements_ == null)
	{
		implements_ = new EObjectContainmentEList<JvmTypeReference>(JvmTypeReference.class, this, XtendPackage.XTEND_CLASS__IMPLEMENTS);
	}
	return implements_;
}
 
Example 25
Source Project: dsl-devkit   Source File: CheckJavaValidator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks that type of a default expression of a formal parameter actually matches the declared type.
 *
 * @param parameter
 *          to check
 */
@Check
public void checkFormalParameterTypeConformance(final FormalParameter parameter) {
  JvmTypeReference jvmType = parameter.getType();
  XExpression value = parameter.getRight();
  if (jvmType == null || value == null) {
    return;
  }
  LightweightTypeReference declaredType = toLightweightTypeReference(jvmType);
  LightweightTypeReference valueType = getActualType(value);
  if (!declaredType.isAssignableFrom(valueType, new TypeConformanceComputationArgument())) {
    error(Messages.CheckJavaValidator_FormalParameterType_Incompatibility, value, null, IssueCodes.FORMAL_PARAMETER_TYPE);
  }
}
 
Example 26
Source Project: sarl   Source File: SARLJvmModelInferrer.java    License: Apache License 2.0 5 votes vote down vote up
/** Generate the extended types for the given SARL statement.
 *
 * @param context the context of the generation.
 * @param owner the JVM element to change.
 * @param defaultJvmType the default JVM type.
 * @param defaultSarlType the default Sarl type.
 * @param supertypes the supertypes.
 */
protected void appendConstrainedExtends(
		GenerationContext context,
		JvmGenericType owner, Class<?> defaultJvmType, Class<? extends XtendTypeDeclaration> defaultSarlType,
		List<? extends JvmParameterizedTypeReference> supertypes) {
	boolean explicitType = false;
	final String ownerId = owner.getIdentifier();
	for (final JvmParameterizedTypeReference superType : supertypes) {
		String superTypeId;
		try {
			superTypeId = superType.getIdentifier();
		} catch (Exception ex) {
			logInternalError(ex);
			superTypeId = null;
		}
		if (!Objects.equal(ownerId, superTypeId)
				&& superType.getType() instanceof JvmGenericType
				/*&& this.inheritanceHelper.isProxyOrSubTypeOf(superType, defaultJvmType, defaultSarlType, isInterface)*/) {
			owner.getSuperTypes().add(this.typeBuilder.cloneWithProxies(superType));
			context.incrementSerial(superType.getIdentifier().hashCode());
			explicitType = true;
		}
	}
	if (!explicitType) {
		final JvmTypeReference type = this._typeReferenceBuilder.typeRef(defaultJvmType);
		if (!(type instanceof JvmUnknownTypeReference)) {
			owner.getSuperTypes().add(type);
		}
		context.incrementSerial(type.getIdentifier().hashCode());
	}
}
 
Example 27
@Test
public void test_twoListParamsListResult_03() {
	JvmOperation twoListParamsListResult = getMethodFromParameterizedMethods(
			"twoListParamsListResult(java.util.List,java.util.List)");
	JvmTypeReference returnType = twoListParamsListResult.getReturnType();
	JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) returnType;
	assertEquals(1, parameterized.getArguments().size());
	JvmTypeReference typeParameter = parameterized.getArguments().get(0);
	JvmType referencedType = typeParameter.getType();
	assertFalse(referencedType.eIsProxy());
	assertTrue(referencedType instanceof JvmTypeParameter);
	JvmTypeParameter typeVar = (JvmTypeParameter) referencedType;
	assertEquals("T", typeVar.getName());
	assertSame(twoListParamsListResult, typeVar.getDeclarator());
}
 
Example 28
@Test
public void test_ParameterizedTypes2_inner_return_02() {
	String typeName = ParameterizedTypes2.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmOperation operation = getMethodFromType(type, ParameterizedTypes2.class, "concreteInner()");
	JvmTypeReference returnType = operation.getReturnType();
	assertTrue(returnType.getIdentifier(), returnType instanceof JvmInnerTypeReference);
	assertEquals("ParameterizedTypes2<Number>$Inner<String>", returnType.getSimpleName());
}
 
Example 29
private JvmTypeReference enhanceTypeReference(ParameterizedType parameterizedType,
		JvmParameterizedTypeReference result) {
	result.setType(createProxy(parameterizedType.getRawType()));
	Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
	if (actualTypeArguments.length != 0) {
		InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>)result.getArguments();
		for (Type actualTypeArgument : actualTypeArguments) {
			JvmTypeReference argument = createTypeArgument(actualTypeArgument);
			arguments.addUnique(argument);
		}
	}
	return result;
}
 
Example 30
protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def void m(");
    _builder.append(type);
    _builder.append(") {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append(expression, "\t");
    _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);
    final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions());
    JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters());
    JvmTypeReference _parameterType = null;
    if (_head!=null) {
      _parameterType=_head.getParameterType();
    }
    final JvmTypeReference declaredType = _parameterType;
    if ((declaredType != null)) {
      LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType);
      return new AssignmentFeatureCallArguments(value, _lightweightTypeReference);
    } else {
      return new AssignmentFeatureCallArguments(value, null);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}