/** * Produces an inferred type which will be resolved on demand. It should not be attempted to resolve * this type during the model inference. * * @param expression the expression that will be used resolve the type. May not be <code>null</code>. * @return an inferred type. */ public JvmTypeReference inferredType(XExpression expression) { Preconditions.checkNotNull(expression); XComputedTypeReference result = xtypesFactory.createXComputedTypeReference(); result.setTypeProvider(new InferredTypeIndicator(expression)); return result; }
protected XImportDeclaration createImport(String importedNamespace, final String member) { XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedNamespace(importedNamespace); if (member != null) { importDeclaration.setMemberName(member); } return importDeclaration; }
public void update() { XImportSection importSection = importsConfiguration.getImportSection(resource); if (importSection == null && importsConfiguration instanceof IMutableImportsConfiguration) { importSection = XtypeFactory.eINSTANCE.createXImportSection(); IMutableImportsConfiguration mutableImportsConfiguration = (IMutableImportsConfiguration) importsConfiguration; mutableImportsConfiguration.setImportSection(resource, importSection); } if (importSection == null) { return; } removeObsoleteStaticImports(); List<XImportDeclaration> allImportDeclarations = newArrayList(); allImportDeclarations.addAll(originalImportDeclarations); allImportDeclarations.addAll(addedImportDeclarations); allImportDeclarations.removeAll(removedImportDeclarations); List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations(); importDeclarations.clear(); importDeclarations.addAll(allImportDeclarations); }
JvmType type = findType(getScript(), importName).getType(); if (concreteImports.addImportFor(type) && type instanceof JvmDeclaredType) { XImportDeclaration declaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); declaration.setImportedType((JvmDeclaredType) type); if (importSection == null) { importSection = XtypeFactory.eINSTANCE.createXImportSection(); getScript().setImportSection(importSection);
final XFunctionTypeRef cloneReference = XtypeFactory.eINSTANCE.createXFunctionTypeRef(); for (final JvmTypeReference paramType : functionRef.getParamTypes()) { cloneReference.getParamTypes().add(cloneAndAssociate(
@Override public JvmTypeReference toTypeReference() { XFunctionTypeRef result = getOwner().getServices().getXtypeFactory().createXFunctionTypeRef(); result.setType(getType()); result.setEquivalent(getEquivalentTypeReference()); if (parameterTypes != null) { for(LightweightTypeReference parameterType: parameterTypes) { result.getParamTypes().add(parameterType.toTypeReference()); } } if (returnType != null) { result.setReturnType(returnType.toTypeReference()); } return result; }
/** * Produces an inferred type which will be resolved on demand. It should not be attempted to resolve * this type during the model inference. * * @return an inferred type. */ public JvmTypeReference inferredType() { XComputedTypeReference result = xtypesFactory.createXComputedTypeReference(); result.setTypeProvider(new InferredTypeIndicator(null)); return result; }
public boolean addImport(JvmDeclaredType type) { if (plainImports.containsKey(type.getSimpleName()) || !needsImport(type)) return false; Maps2.putIntoListMap(type.getSimpleName(), type, plainImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); addedImportDeclarations.add(importDeclaration); return true; }
protected void requestCapturedLocalVariables(JvmTypeReference toBeWrapped, JvmDeclaredType type, ResolvedTypes resolvedTypes, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, IAcceptor<JvmTypeReference> result) { LocalVariableCapturerImpl capturer = new LocalVariableCapturerImpl(toBeWrapped, type, this, resolvedTypes, resolvedTypesByContext); XComputedTypeReference ref = getServices().getXtypeFactory().createXComputedTypeReference(); ref.setTypeProvider(capturer); result.accept(ref); capturer.awaitCapturing(); } }
public boolean addStaticImport(JvmDeclaredType type, String memberName) { if (hasStaticImport(staticImports, type, memberName)) { return false; } Maps2.putIntoSetMap(type, memberName, staticImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); importDeclaration.setStatic(true); if (memberName == null) { importDeclaration.setWildcard(true); } else { importDeclaration.setMemberName(memberName); } addedImportDeclarations.add(importDeclaration); return true; }
@Override public JvmTypeReference toTypeReference() { if (internalGetResolvedTo() != null) { return resolvedTo.toTypeReference(); } XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); result.setTypeProvider(new UnboundTypeReferenceResolver(this)); return result; }
public boolean addStaticExtensionImport(JvmDeclaredType type, String memberName) { if (hasStaticImport(staticExtensionImports, type, memberName)) { return false; } Maps2.putIntoSetMap(type, memberName, staticExtensionImports); XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration(); importDeclaration.setImportedType(type); importDeclaration.setStatic(true); importDeclaration.setExtension(true); if (memberName == null) { importDeclaration.setWildcard(true); } else { importDeclaration.setMemberName(memberName); } addedImportDeclarations.add(importDeclaration); return true; }
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); if (InferredTypeIndicator.isInferred(parameterType)) { XComputedTypeReference casted = (XComputedTypeReference) parameterType; XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference(); computedParameterType.setTypeProvider(new InitializerParameterTypeReferenceProvider( firstParameter,
protected JvmTypeReference createComputedTypeReference( Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmMember member, /* @Nullable */ InferredTypeIndicator indicator, boolean returnType) { XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); if (indicator == null || indicator.getExpression() == null) result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, returnType)); else result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, indicator.getExpression(), returnType)); // TODO do we need a lightweight computed type reference? // resolvedTypes.setType(member, result); return result; }
/** * 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); }