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

The following examples show how to use org.eclipse.xtext.common.types.JvmTypeReference. 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: SARLJvmModelInferrer.java    From sarl with 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 #2
Source File: JvmFormalParameterImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #3
Source File: AbstractClosureTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #4
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 File: SARLValidator.java    From sarl with 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 #6
Source File: Bug776Test.java    From sarl with 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 #7
Source File: JvmCompoundTypeReferenceImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #8
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #9
Source File: TypeReferences.java    From xtext-extras with 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 #10
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #11
Source File: ImportingStringConcatenation.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #12
Source File: XAbstractFeatureCallImpl.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #13
Source File: PyGenerator.java    From sarl with 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
Source File: MemberImpl.java    From dsl-devkit with 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 #15
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #16
Source File: UIStrings.java    From xtext-extras with 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
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #18
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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 #19
Source File: PyGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Generate the given object.
 *
 * @param handler the behavior unit.
 * @param it the target for the generated content.
 * @param context the context.
 */
protected void _generate(SarlBehaviorUnit handler, PyAppendable it, IExtraLanguageGeneratorContext context) {
	final JvmTypeReference event = handler.getName();
	final String handleName = it.declareUniqueNameVariable(handler, "__on_" + event.getSimpleName() + "__"); //$NON-NLS-1$ //$NON-NLS-2$
	it.append("def ").append(handleName).append("(self, occurrence):"); //$NON-NLS-1$ //$NON-NLS-2$
	it.increaseIndentation().newLine();
	generateDocString(getTypeBuilder().getDocumentation(handler), it);
	if (handler.getExpression() != null) {
		generate(handler.getExpression(), null, it, context);
	} else {
		it.append("pass"); //$NON-NLS-1$
	}
	it.decreaseIndentation().newLine();
	final String key = this.qualifiedNameProvider.getFullyQualifiedName(handler.getDeclaringType()).toString();
	final Map<String, Map<String, List<Pair<XExpression, String>>>> map = context.getMapData(EVENT_GUARDS_MEMENTO);
	Map<String, List<Pair<XExpression, String>>> submap = map.get(key);
	if (submap == null) {
		submap = new HashMap<>();
		map.put(key, submap);
	}
	final String eventId = event.getIdentifier();
	List<Pair<XExpression, String>> guards = submap.get(eventId);
	if (guards == null) {
		guards = new ArrayList<>();
		submap.put(eventId, guards);
	}
	guards.add(new Pair<>(handler.getGuard(), handleName));
}
 
Example #20
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRawIterable_01() {
	String typeName = RawIterable.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	List<JvmTypeReference> superTypes = type.getSuperTypes();
	JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1);
	assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier());
	assertTrue(iterableSuperType.getArguments().isEmpty());
}
 
Example #21
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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 #22
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public ITreeAppendable compile(XExpression obj, ITreeAppendable parentAppendable, /* @Nullable */ LightweightTypeReference expectedReturnType, /* @Nullable */ Set<JvmTypeReference> declaredExceptions) {
	if (declaredExceptions == null) {
		declaredExceptions = newHashSet();
		assert declaredExceptions != null;
	}
	ITreeAppendable appendable = parentAppendable.trace(obj, true);
	final boolean isPrimitiveVoidExpected = expectedReturnType.isPrimitiveVoid(); 
	final boolean isPrimitiveVoid = isPrimitiveVoid(obj);
	final boolean earlyExit = isEarlyExit(obj);
	boolean needsSneakyThrow = needsSneakyThrow(obj, declaredExceptions);
	if (needsSneakyThrow && isPrimitiveVoidExpected && hasJvmConstructorCall(obj)) {
		compileWithJvmConstructorCall((XBlockExpression) obj, appendable);
		return parentAppendable;
	}
	if (needsSneakyThrow) {
		appendable.newLine().append("try {").increaseIndentation();
	}
	internalToJavaStatement(obj, appendable, !isPrimitiveVoidExpected && !isPrimitiveVoid && !earlyExit);
	if (!isPrimitiveVoidExpected && !earlyExit) {
		appendable.newLine().append("return ");
		if (isPrimitiveVoid && !isPrimitiveVoidExpected) {
			appendDefaultLiteral(appendable, expectedReturnType);
		} else {
			internalToConvertedExpression(obj, appendable, expectedReturnType);
		}
		appendable.append(";");
	}
	if (needsSneakyThrow) {
		generateCheckedExceptionHandling(appendable);
	}
	return parentAppendable;
}
 
Example #23
Source File: PureXbaseJvmModelInferrer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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 #24
Source File: AbstractResolvedOperation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@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 #25
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmWildcardTypeReference wildCardExtends(JvmTypeReference clone) {
	JvmWildcardTypeReference result = factory.createJvmWildcardTypeReference();
	JvmUpperBound upperBound = factory.createJvmUpperBound();
	upperBound.setTypeReference(clone);
	result.getConstraints().add(upperBound);
	return result;
}
 
Example #26
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug427098() {
	String typeName = Bug427098.class.getName();
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(typeName);
	JvmAnnotationReference annotationReference = type.getAnnotations().get(0);
	JvmTypeAnnotationValue annotationValue = getClassArrayAnnotationValue(annotationReference);
	assertEquals("classArray", annotationValue.getOperation().getSimpleName());
	List<JvmTypeReference> typeReferences = annotationValue.getValues();
	assertEquals(5, typeReferences.size());
	assertTypeReference("int", typeReferences, 0);
	assertTypeReference("void", typeReferences, 1);
	assertTypeReference("double[][][]", typeReferences, 2);
	assertTypeReference("CharSequence[]", typeReferences, 3);
	assertTypeReference("Iterable", typeReferences, 4);
}
 
Example #27
Source File: XbaseTypeComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _computeTypes(XCastedExpression object, ITypeComputationState state) {
	// TODO: should we hold on the previously known expression?
	/* 
	 * ('foo' as CharSequence) as NullPointerException
	 * In this case, we know - even though it's CharSequence on the Java side - 
	 * that the type of ('foo' as CharSequence) is still a String
	 * which is not conformant to NPE. The subsequent cast will always fail at
	 * runtime. This could be detected.
	 * 
	 * It could be interesting to have a subtype of MultiTypeReference, e.g. CastedTypeReference
	 * that still knows about the original type. This would be similar to a nested switch
	 * with the difference, that we want to know which type to use on the Java side in order
	 * to disambiguate overloaded methods:
	 * 
	 * m(Object o) {} // 1
	 * m(String s) {}
	 * 
	 * {
	 *   val o = '' as Object
	 *   m(o) // calls 1
	 *   o.substring(1) // valid, too - compiler could insert the cast back to String
	 * }
	 */
	JvmTypeReference type = object.getType();
	if (type != null) {
		state.withNonVoidExpectation().computeTypes(object.getTarget());
		state.acceptActualType(state.getReferenceOwner().toLightweightTypeReference(type));
	} else {
		state.computeTypes(object.getTarget());
	}
}
 
Example #28
Source File: XCasePartImpl.java    From xtext-extras with 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 #29
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isTypeParameterOfClosureImpl(JvmTypeReference ref) {
	JvmFormalParameter parameter = EcoreUtil2.getContainerOfType(ref, JvmFormalParameter.class);
	if (parameter != null) {
		return parameter.eContainer() instanceof XClosure;
	}
	return false;
}
 
Example #30
Source File: XConstructorCallImpl.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<JvmTypeReference> getTypeArguments()
{
	if (typeArguments == null)
	{
		typeArguments = new EObjectContainmentEList<JvmTypeReference>(JvmTypeReference.class, this, XbasePackage.XCONSTRUCTOR_CALL__TYPE_ARGUMENTS);
	}
	return typeArguments;
}