// TODO: This does not recognize non-resource named objects yet public TypeSymbol?GetTypeByName(string?typeName) { /* * Obtaining the type by name currently does not involve processing outgoing edges in the expression graph (function or variable refs) * This means that we do not need to check for cycles. However, if that ever changes, ensure that proper cycle detection is added here. */ if (typeName == null) { return(null); } if (LanguageConstants.DeclarationTypes.TryGetValue(typeName, out TypeSymbol primitiveType)) { return(primitiveType); } // TODO: This needs proper namespace, type, and version resolution logic in the future ResourceTypeReference?typeReference = ResourceTypeReference.TryParse(typeName); if (typeReference == null) { return(null); } // TODO: Construct/lookup type information based on JSON schema or swagger // for now assuming very basic resource schema return(new ResourceType(typeName, LanguageConstants.CreateResourceProperties(typeReference), additionalPropertiesType: null, typeReference)); }
public override void VisitResourceDeclarationSyntax(ResourceDeclarationSyntax syntax) => AssignTypeWithCaching(syntax, () => { var stringSyntax = syntax.TryGetType(); if (stringSyntax != null && stringSyntax.IsInterpolated()) { // TODO: in the future, we can relax this check to allow interpolation with compile-time constants. // right now, codegen will still generate a format string however, which will cause problems for the type. return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.Type).ResourceTypeInterpolationUnsupported())); } var stringContent = stringSyntax?.GetLiteralValue(); if (stringContent == null) { return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.Type).InvalidResourceType())); } // TODO: This needs proper namespace, type, and version resolution logic in the future var typeReference = ResourceTypeReference.TryParse(stringContent); if (typeReference == null) { return(new ErrorTypeSymbol(DiagnosticBuilder.ForPosition(syntax.Type).InvalidResourceType())); } // TODO: Construct/lookup type information based on JSON schema or swagger // for now assuming very basic resource schema return(new ResourceType(stringContent, LanguageConstants.CreateResourceProperties(typeReference), additionalProperties: null, typeReference)); });
public ResourceType GetType(ResourceTypeReference typeReference) { var resourceType = TryGetResource(typeReference); if (resourceType != null) { return(resourceType); } // TODO move default definition into types assembly return(new ResourceType(typeReference, LanguageConstants.CreateResourceProperties(typeReference))); }
public ResourceType GetType(ResourceTypeReference typeReference) { var resourceType = TryGetResource(typeReference); if (resourceType != null) { return(resourceType); } // TODO move default definition into types assembly return(new ResourceType(typeReference, new NamedObjectType(typeReference.FormatName(), TypeSymbolValidationFlags.Default, LanguageConstants.CreateResourceProperties(typeReference), null), TypeSymbolValidationFlags.Default)); }
public ResourceType GetType(ResourceScope scopeType, ResourceTypeReference typeReference) { if (loadedTypeCache.TryGetValue(typeReference, out var resourceType)) { return(resourceType); } if (availableResourceTypes[scopeType].TryGetValue(typeReference, out var typeLocation)) { // It's important to cache this result because LoadResourceType is an expensive operation, and // duplicating types means the resourceTypeFactor won't be able to use its cache. var serializedResourceType = typeLoader.LoadResourceType(typeLocation); resourceType = resourceTypeFactory.GetResourceType(serializedResourceType); } else { var resourceBodyType = new NamedObjectType(typeReference.FormatName(), TypeSymbolValidationFlags.Default, LanguageConstants.CreateResourceProperties(typeReference), null); resourceType = new ResourceType(typeReference, resourceBodyType); } loadedTypeCache[typeReference] = resourceType; return(resourceType); }
public ResourceType GetType(ResourceTypeReference reference, ResourceTypeGenerationFlags flags) { var bodyType = new ObjectType(reference.FormatName(), TypeSymbolValidationFlags.Default, LanguageConstants.CreateResourceProperties(reference), null); var resourceType = new ResourceType(reference, ResourceScope.Tenant | ResourceScope.ManagementGroup | ResourceScope.Subscription | ResourceScope.ResourceGroup | ResourceScope.Resource, bodyType); return(AzResourceTypeProvider.SetBicepResourceProperties(resourceType, flags)); }
public ResourceType GetType(ResourceTypeReference reference) => new ResourceType(reference, new NamedObjectType(reference.FormatName(), TypeSymbolValidationFlags.Default, LanguageConstants.CreateResourceProperties(reference), null), TypeSymbolValidationFlags.Default);
public ResourceType GetType(ResourceTypeReference reference) => new ResourceType(reference, LanguageConstants.CreateResourceProperties(reference));
private ResourceType GenerateResourceType(ResourceTypeReference typeReference, bool isExistingResource) { if (availableResourceTypes.TryGetValue(typeReference, out var typeLocation)) { var serializedResourceType = typeLoader.LoadResourceType(typeLocation); var resourceType = resourceTypeFactory.GetResourceType(serializedResourceType); return(SetBicepResourceProperties(resourceType, isExistingResource)); } else { var resourceBodyType = new NamedObjectType(typeReference.FormatName(), TypeSymbolValidationFlags.Default, LanguageConstants.CreateResourceProperties(typeReference), null); var resourceType = new ResourceType(typeReference, ResourceScope.Tenant | ResourceScope.ManagementGroup | ResourceScope.Subscription | ResourceScope.ResourceGroup | ResourceScope.Resource, resourceBodyType); return(SetBicepResourceProperties(resourceType, isExistingResource)); } }
public ResourceType GetType(ResourceTypeReference reference) => new ResourceType(reference, new NamedObjectType(reference.FormatName(), LanguageConstants.CreateResourceProperties(reference), null));