use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method _doPrepare.
/**
* Initializes the type inference strategy for the cache field for create extensions.
*/
@Override
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmField field, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
JvmTypeReference knownType = field.getType();
if (InferredTypeIndicator.isInferred(knownType)) {
XComputedTypeReference castedKnownType = (XComputedTypeReference) knownType;
EObject sourceElement = associations.getPrimarySourceElement(field);
if (sourceElement instanceof XtendFunction) {
XtendFunction function = (XtendFunction) sourceElement;
if (function.getCreateExtensionInfo() != null) {
JvmOperation operation = associations.getDirectlyInferredOperation(function);
if (operation != null) {
declareTypeParameters(resolvedTypes, field, resolvedTypesByContext);
XComputedTypeReference fieldType = getServices().getXtypeFactory().createXComputedTypeReference();
fieldType.setTypeProvider(new CreateCacheFieldTypeReferenceProvider(operation, resolvedTypes, featureScopeSession));
castedKnownType.setEquivalent(fieldType);
return;
}
}
}
}
super._doPrepare(resolvedTypes, featureScopeSession, field, resolvedTypesByContext);
doPrepareLocalTypes(resolvedTypesByContext.get(field), featureScopeSession, field, resolvedTypesByContext);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkSuperTypes.
@Check
public void checkSuperTypes(AnonymousClass anonymousClass) {
JvmGenericType inferredType = associations.getInferredType(anonymousClass);
if (inferredType != null) {
JvmTypeReference superTypeRef = Iterables.getLast(inferredType.getSuperTypes());
JvmType superType = superTypeRef.getType();
if (superType instanceof JvmGenericType && ((JvmGenericType) superType).isFinal())
error("Attempt to override final class", anonymousClass.getConstructorCall(), XCONSTRUCTOR_CALL__CONSTRUCTOR, INSIGNIFICANT_INDEX, OVERRIDDEN_FINAL);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method contributesToConflict.
/**
* Determine whether the given type contributes to the conflict caused by the given default interface implementation.
*/
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
}
RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
if (rootType.isInterface()) {
int contributingCount = 0;
for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
JvmType rawType = typeRef.getType();
if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
contributingCount++;
}
}
return contributingCount >= 2;
} else {
return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkSuperTypes.
@Check
public void checkSuperTypes(XtendClass xtendClass) {
JvmTypeReference superClass = xtendClass.getExtends();
if (superClass != null && superClass.getType() != null) {
if (!(superClass.getType() instanceof JvmGenericType) || ((JvmGenericType) superClass.getType()).isInterface()) {
error("Superclass must be a class", XTEND_CLASS__EXTENDS, CLASS_EXPECTED);
} else {
if (((JvmGenericType) superClass.getType()).isFinal()) {
error("Attempt to override final class", XTEND_CLASS__EXTENDS, OVERRIDDEN_FINAL);
}
checkWildcardSupertype(xtendClass, superClass, XTEND_CLASS__EXTENDS, INSIGNIFICANT_INDEX);
}
}
for (int i = 0; i < xtendClass.getImplements().size(); ++i) {
JvmTypeReference implementedType = xtendClass.getImplements().get(i);
if (!isInterface(implementedType.getType())) {
error("Implemented interface must be an interface", XTEND_CLASS__IMPLEMENTS, i, INTERFACE_EXPECTED);
}
checkWildcardSupertype(xtendClass, implementedType, XTEND_CLASS__IMPLEMENTS, i);
}
JvmGenericType inferredType = associations.getInferredType(xtendClass);
if (inferredType != null && hasCycleInHierarchy(inferredType, Sets.<JvmGenericType>newHashSet())) {
error("The inheritance hierarchy of " + notNull(xtendClass.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 XtendValidator method reportMissingImplementations.
protected void reportMissingImplementations(XtendTypeDeclaration xtendClass, JvmGenericType inferredType, List<IResolvedOperation> operationsMissingImplementation) {
StringBuilder errorMsg = new StringBuilder();
String name = xtendClass.getName();
boolean needsNewLine = operationsMissingImplementation.size() > 1;
if (xtendClass.isAnonymous()) {
JvmTypeReference superType = Iterables.getLast(inferredType.getSuperTypes());
errorMsg.append("The anonymous subclass of ").append(superType.getSimpleName());
errorMsg.append(" does not implement ");
} else {
errorMsg.append("The class ").append(name);
errorMsg.append(" must be defined abstract because it does not implement ");
}
if (needsNewLine) {
errorMsg.append("its inherited abstract methods ");
}
IResolvedOperation operation;
for (int i = 0; i < operationsMissingImplementation.size() && i < 3; ++i) {
operation = operationsMissingImplementation.get(i);
if (needsNewLine)
errorMsg.append("\n- ");
errorMsg.append(operation.getSimpleSignature());
}
int numUnshownOperations = operationsMissingImplementation.size() - 3;
if (numUnshownOperations > 0)
errorMsg.append("\nand " + numUnshownOperations + " more.");
List<String> uris = transform(operationsMissingImplementation, new Function<IResolvedOperation, String>() {
@Override
public String apply(IResolvedOperation from) {
return EcoreUtil.getURI(from.getDeclaration()).toString();
}
});
if (xtendClass.isAnonymous()) {
error(errorMsg.toString(), xtendClass, ANONYMOUS_CLASS__CONSTRUCTOR_CALL, ANONYMOUS_CLASS_MISSING_MEMBERS, toArray(uris, String.class));
} else {
error(errorMsg.toString(), xtendClass, XTEND_TYPE_DECLARATION__NAME, CLASS_MUST_BE_ABSTRACT, toArray(uris, String.class));
}
}
Aggregations