use of org.eclipse.xtext.common.types.JvmParameterizedTypeReference in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method doPrepareLocalTypes.
protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
List<JvmGenericType> localClasses = container.getLocalClasses();
for (final JvmGenericType localClass : localClasses) {
JvmTypeReference superType = localClass.getSuperTypes().get(0);
final IFeatureScopeSession nestedSession = featureScopeSession;
if (InferredTypeIndicator.isInferred(superType)) {
final XComputedTypeReference casted = (XComputedTypeReference) superType;
InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
XConstructorCall constructorCall = anonymousClass.getConstructorCall();
IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
if (type == null) {
JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
inferAnonymousClassConstructor(anonymousClass, localClass);
}
});
} else {
final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
@SuppressWarnings("deprecation")
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
inferAnonymousClassConstructor(anonymousClass, localClass);
} else {
for (JvmMember superMember : type.getMembers()) {
if (superMember instanceof JvmConstructor) {
JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
boolean visible = mySession.isVisible(superTypeConstructor);
inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
}
}
}
}
});
}
}
}
}
use of org.eclipse.xtext.common.types.JvmParameterizedTypeReference in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method createSuperTypeReference.
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;
}
use of org.eclipse.xtext.common.types.JvmParameterizedTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method validateInferredType.
protected void validateInferredType(JvmTypeReference inferredType, XtendMember member, String messagePrefix, EAttribute location) {
if (inferredType != null) {
TreeIterator<EObject> iterator = EcoreUtil2.eAll(inferredType);
while (iterator.hasNext()) {
EObject next = iterator.next();
if (next instanceof JvmParameterizedTypeReference) {
JvmParameterizedTypeReference candidate = (JvmParameterizedTypeReference) next;
JvmType type = candidate.getType();
if (type instanceof JvmGenericType && !((JvmGenericType) type).getTypeParameters().isEmpty()) {
if (candidate.getArguments().isEmpty()) {
StringBuilder message = new StringBuilder(messagePrefix);
message = proxyAwareUIStrings.visit(inferredType, message);
if (message != null) {
message.append(" uses the raw type ");
message.append(type.getSimpleName());
message.append(". References to generic type ");
message = proxyAwareUIStrings.appendTypeSignature(type, message);
message.append(" should be parameterized");
warning(message.toString(), member, location, org.eclipse.xtext.xbase.validation.IssueCodes.RAW_TYPE);
}
return;
}
}
} else if (next instanceof XComputedTypeReference) {
validateInferredType(((XComputedTypeReference) next).getEquivalent(), member, messagePrefix, location);
iterator.prune();
}
}
}
}
use of org.eclipse.xtext.common.types.JvmParameterizedTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method computeFieldName.
/* @Nullable */
protected String computeFieldName(XtendField field) {
if (field.getName() != null)
return field.getName();
JvmTypeReference type = field.getType();
String name = null;
if (type != null) {
while (type instanceof JvmGenericArrayTypeReference) {
type = ((JvmGenericArrayTypeReference) type).getComponentType();
}
if (type instanceof JvmParameterizedTypeReference) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
if (!nodes.isEmpty()) {
String typeName = nodes.get(0).getText().trim();
int lastDot = typeName.lastIndexOf('.');
if (lastDot != -1) {
typeName = typeName.substring(lastDot + 1);
}
name = "_" + Strings.toFirstLower(typeName);
}
}
}
return name;
}
use of org.eclipse.xtext.common.types.JvmParameterizedTypeReference in project xtext-xtend by eclipse.
the class InferredJvmModelTest method testInferredSuperTypeTypeArgument.
@Test
public void testInferredSuperTypeTypeArgument() throws Exception {
XtendFile xtendFile = file("class Foo extends Iterable<Object> { }");
JvmGenericType inferredType = getInferredType(xtendFile);
XtendClass xtendClass = (XtendClass) xtendFile.getXtendTypes().get(0);
assertEquals(1, inferredType.getSuperTypes().size());
JvmTypeReference xtendSuperType = xtendClass.getExtends();
JvmTypeReference jvmSuperType = inferredType.getSuperTypes().get(0);
assertFalse(xtendSuperType == jvmSuperType);
assertTrue(jvmSuperType instanceof JvmParameterizedTypeReference);
assertTrue(xtendSuperType instanceof JvmParameterizedTypeReference);
EList<JvmTypeReference> xtendTypeArguments = ((JvmParameterizedTypeReference) xtendSuperType).getArguments();
EList<JvmTypeReference> jvmTypeArguments = ((JvmParameterizedTypeReference) jvmSuperType).getArguments();
assertEquals(1, jvmTypeArguments.size());
JvmTypeReference xtendTypeArgument = xtendTypeArguments.get(0);
JvmTypeReference jvmTypeArgument = jvmTypeArguments.get(0);
assertFalse(xtendTypeArgument == jvmTypeArgument);
assertEquals(xtendTypeArgument.getType(), jvmTypeArgument.getType());
}
Aggregations