use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkSuperTypes.
@Check
public void checkSuperTypes(XtendInterface xtendInterface) {
for (int i = 0; i < xtendInterface.getExtends().size(); ++i) {
JvmTypeReference extendedType = xtendInterface.getExtends().get(i);
if (!isInterface(extendedType.getType()) && !isAnnotation(extendedType.getType())) {
error("Extended interface must be an interface", XTEND_INTERFACE__EXTENDS, i, INTERFACE_EXPECTED);
}
checkWildcardSupertype(xtendInterface, extendedType, XTEND_INTERFACE__EXTENDS, i);
}
JvmGenericType inferredType = associations.getInferredType(xtendInterface);
if (inferredType != null && hasCycleInHierarchy(inferredType, Sets.<JvmGenericType>newHashSet())) {
error("The inheritance hierarchy of " + notNull(xtendInterface.getName()) + " contains cycles", XTEND_TYPE_DECLARATION__NAME, CYCLIC_INHERITANCE);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
for (JvmTypeReference intf : source.getExtends()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
transform(member, inferredJvmType, false);
}
}
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method _doPrepare.
@Override
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
super._doPrepare(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
resolvedTypes = resolvedTypesByContext.get(operation);
if (dispatchHelper.isDispatcherFunction(operation)) {
List<JvmFormalParameter> parameters = operation.getParameters();
for (int i = 0; i < parameters.size(); i++) {
JvmFormalParameter parameter = parameters.get(i);
JvmTypeReference parameterType = parameter.getParameterType();
if (InferredTypeIndicator.isInferred(parameterType)) {
XComputedTypeReference casted = (XComputedTypeReference) parameterType;
XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
casted.setEquivalent(computedParameterType);
} else if (parameterType == null) {
XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
parameter.setParameterType(computedParameterType);
}
}
} else if (operation.getParameters().size() >= 1) {
EObject sourceElement = associations.getPrimarySourceElement(operation);
if (sourceElement instanceof XtendFunction) {
XtendFunction function = (XtendFunction) sourceElement;
if (function.getCreateExtensionInfo() != null) {
JvmFormalParameter firstParameter = operation.getParameters().get(0);
JvmTypeReference parameterType = firstParameter.getParameterType();
if (InferredTypeIndicator.isInferred(parameterType)) {
XComputedTypeReference casted = (XComputedTypeReference) parameterType;
XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
computedParameterType.setTypeProvider(new InitializerParameterTypeReferenceProvider(firstParameter, function, resolvedTypesByContext, resolvedTypes, featureScopeSession, this));
casted.setEquivalent(computedParameterType);
}
}
}
}
doPrepareLocalTypes(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkNonRawTypeInferred.
@Check
public void checkNonRawTypeInferred(XtendField field) {
if (field.getType() == null) {
JvmField jvmField = associations.getJvmField(field);
// field could have been removed by AA, thus the resource is possibly null
if (jvmField != null && jvmField.eResource() != null) {
JvmTypeReference fieldType = jvmField.getType();
validateInferredType(fieldType, field, "The inferred field type ", XTEND_FIELD__NAME);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class UIStringsTest method testReferenceToString_0.
/**
* Only the simple name of the type is specified.
* The JvmTypeReference is not a proxy.
*/
@Test
public void testReferenceToString_0() throws Exception {
XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + " def test() {\n" + " val x = new List<ClassC>\n" + " }\n" + "}\n");
XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
XConstructorCall cons = (XConstructorCall) declaration.getRight();
JvmTypeReference reference = cons.getTypeArguments().get(0);
assertNotNull(reference);
assertNotNull(reference.getType());
assertFalse(reference.getType().eIsProxy());
assertNotNull(reference.eResource());
assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Aggregations