use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method evaluate.
public Object evaluate(final XExpression expression, final JvmTypeReference expectedType) {
final ClassLoader classLoader = this.classLoaderProvider.getClassLoader(expression);
final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
JvmTypeReference _xifexpression = null;
if ((expectedType instanceof XComputedTypeReference)) {
_xifexpression = null;
} else {
_xifexpression = expectedType;
}
ClassFinder _classFinder = new ClassFinder(classLoader);
LinkedHashSet<XExpression> _newLinkedHashSet = CollectionLiterals.<XExpression>newLinkedHashSet();
Context _context = new Context(_xifexpression, _classFinder, visibleFeatures, _newLinkedHashSet);
final Object result = this.evaluate(expression, _context);
return result;
}
use of org.eclipse.xtext.xtype.XComputedTypeReference 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.xtype.XComputedTypeReference 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.xtype.XComputedTypeReference 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.xtype.XComputedTypeReference 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();
}
}
}
}
Aggregations