Skip to content

Commit

Permalink
Property compilation abstractions for VS extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Mikuš committed Feb 9, 2024
1 parent 7faf5a0 commit 14dd80a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public virtual IAbstractTreeRoot ResolveTree(DothtmlRootNode root, string fileNa
// We need to call BuildControlMetadata instead of ResolveControl. The control builder for the control doesn't have to be compiled yet so the
// metadata would be incomplete and ResolveControl caches them internally. BuildControlMetadata just builds the metadata and the control is
// actually resolved when the control builder is ready and the metadata are complete.
var viewMetadata = controlResolver.BuildControlMetadata(CreateControlType(directiveMetadata.BaseType, fileName));
var viewMetadata = controlResolver.BuildControlMetadata(CreateControlType(directiveMetadata.BaseType, directiveMetadata.Properties, fileName));

var dataContextTypeStack = CreateDataContextTypeStack(directiveMetadata.ViewModelType, null, directiveMetadata.Imports, new BindingExtensionParameter[] {
new CurrentMarkupControlExtensionParameter(directiveMetadata.BaseType),
Expand Down Expand Up @@ -776,7 +776,7 @@ public static (ITypeDescriptor? type, List<BindingExtensionParameter> extensionP
/// <summary>
/// Creates the IControlType identification of the control.
/// </summary>
protected abstract IControlType CreateControlType(ITypeDescriptor wrapperType, string virtualPath);
protected abstract IControlType CreateControlType(ITypeDescriptor wrapperType, IReadOnlyList<IPropertyDescriptor> properties, string virtualPath);

/// <summary>
/// Creates the data context type stack object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void ResolveRootContent(DothtmlRootNode root, IAbstractContro
((ResolvedTreeRoot)view).ResolveContentAction = () => base.ResolveRootContent(root, view, viewMetadata);
}

protected override IControlType CreateControlType(ITypeDescriptor wrapperType, string virtualPath)
protected override IControlType CreateControlType(ITypeDescriptor wrapperType, IReadOnlyList<IPropertyDescriptor> markupProperties, string virtualPath)
{
return new ControlType(ResolvedTypeDescriptor.ToSystemType(wrapperType), virtualPath: virtualPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public record MarkupPageMetadata(
ITypeDescriptor BaseType,
ITypeDescriptor? ViewModelType,
ViewModuleCompilationResult? ViewModuleResult,
ImmutableList<DotvvmProperty> Properties);
ImmutableList<IPropertyDescriptor> Properties);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace DotVVM.Framework.Compilation.Directives
{
public abstract class PropertyDeclarationDirectiveCompiler : DirectiveCompiler<IAbstractPropertyDeclarationDirective, ImmutableList<DotvvmProperty>>
public abstract class PropertyDeclarationDirectiveCompiler : DirectiveCompiler<IAbstractPropertyDeclarationDirective, ImmutableList<IPropertyDescriptor>>
{
private readonly ITypeDescriptor controlWrapperType;
private readonly ImmutableList<NamespaceImport> imports;
Expand Down Expand Up @@ -103,7 +103,7 @@ private AttributeInfo GetAttributeInfo(BindingParserNode attributeReference, Dot
return new AttributeInfo(type, attributePropertyNameReference, initializer);
}

protected override ImmutableList<DotvvmProperty> CreateArtefact(IReadOnlyList<IAbstractPropertyDeclarationDirective> directives)
protected override ImmutableList<IPropertyDescriptor> CreateArtefact(IReadOnlyList<IAbstractPropertyDeclarationDirective> directives)
{
foreach (var directive in directives)
{
Expand All @@ -117,7 +117,7 @@ protected override ImmutableList<DotvvmProperty> CreateArtefact(IReadOnlyList<IA
}

protected abstract bool HasPropertyType(IAbstractPropertyDeclarationDirective directive);
protected abstract DotvvmProperty TryCreateDotvvmPropertyFromDirective(IAbstractPropertyDeclarationDirective propertyDeclarationDirective);
protected abstract IPropertyDescriptor TryCreateDotvvmPropertyFromDirective(IAbstractPropertyDeclarationDirective propertyDeclarationDirective);

private record AttributeInfo(ActualTypeReferenceBindingParserNode Type, IdentifierNameBindingParserNode Name, BindingParserNode Initializer);
}
Expand All @@ -135,7 +135,7 @@ public ResolvedPropertyDeclarationDirectiveCompiler(
protected override bool HasPropertyType(IAbstractPropertyDeclarationDirective directive)
=> directive.PropertyType is ResolvedTypeDescriptor { Type: not null };

protected override DotvvmProperty TryCreateDotvvmPropertyFromDirective(IAbstractPropertyDeclarationDirective propertyDeclarationDirective)
protected override IPropertyDescriptor TryCreateDotvvmPropertyFromDirective(IAbstractPropertyDeclarationDirective propertyDeclarationDirective)
{
if (propertyDeclarationDirective.PropertyType is not ResolvedTypeDescriptor { Type: not null } propertyType) { throw new ArgumentException("propertyDeclarationDirective.PropertyType must be of type ResolvedTypeDescriptor and have non null type."); }
if (propertyDeclarationDirective.DeclaringType is not ResolvedTypeDescriptor { Type: not null } declaringType) { throw new ArgumentException("propertyDeclarationDirective.DeclaringType must be of type ResolvedTypeDescriptor and have non null type."); }
Expand Down

0 comments on commit 14dd80a

Please sign in to comment.