removed SessionState directive
This commit is contained in:
parent
891dfa5e3e
commit
ff3ddfcc53
|
|
@ -43,8 +43,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
// Separate the usings and the class
|
// Separate the usings and the class
|
||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
|
|
||||||
new CSharpClassAttributeVisitor(writer, Context).Accept(Tree.Chunks);
|
|
||||||
|
|
||||||
using (BuildClassDeclaration(writer))
|
using (BuildClassDeclaration(writer))
|
||||||
{
|
{
|
||||||
if (Host.DesignTimeMode)
|
if (Host.DesignTimeMode)
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using Microsoft.AspNet.Razor.Parser;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
|
||||||
{
|
|
||||||
public class CSharpClassAttributeVisitor : CodeVisitor<CSharpCodeWriter>
|
|
||||||
{
|
|
||||||
public CSharpClassAttributeVisitor(CSharpCodeWriter writer, CodeBuilderContext context)
|
|
||||||
: base(writer, context)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void Visit(SessionStateChunk chunk)
|
|
||||||
{
|
|
||||||
Writer.Write("[")
|
|
||||||
.Write(typeof(RazorDirectiveAttribute).FullName)
|
|
||||||
.Write("(")
|
|
||||||
.WriteStringLiteral(SyntaxConstants.CSharp.SessionStateKeyword)
|
|
||||||
.WriteParameterSeparator()
|
|
||||||
.WriteStringLiteral(chunk.Value)
|
|
||||||
.WriteLine(")]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -113,10 +113,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
{
|
{
|
||||||
Visit((ChunkBlock)chunk);
|
Visit((ChunkBlock)chunk);
|
||||||
}
|
}
|
||||||
else if (chunk is SessionStateChunk)
|
|
||||||
{
|
|
||||||
Visit((SessionStateChunk)chunk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void Visit(LiteralChunk chunk);
|
protected abstract void Visit(LiteralChunk chunk);
|
||||||
|
|
@ -138,6 +134,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
protected abstract void Visit(TemplateChunk chunk);
|
protected abstract void Visit(TemplateChunk chunk);
|
||||||
protected abstract void Visit(SetLayoutChunk chunk);
|
protected abstract void Visit(SetLayoutChunk chunk);
|
||||||
protected abstract void Visit(ExpressionBlockChunk chunk);
|
protected abstract void Visit(ExpressionBlockChunk chunk);
|
||||||
protected abstract void Visit(SessionStateChunk chunk);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
protected override void Visit(SetLayoutChunk chunk)
|
protected override void Visit(SetLayoutChunk chunk)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
protected override void Visit(SessionStateChunk chunk)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Razor.Generator.Compiler
|
|
||||||
{
|
|
||||||
public class SessionStateChunk : Chunk
|
|
||||||
{
|
|
||||||
public string Value { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -145,14 +145,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
}, association, topLevel: true);
|
}, association, topLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSessionStateChunk(string value, SyntaxTreeNode association)
|
|
||||||
{
|
|
||||||
AddChunk(new SessionStateChunk
|
|
||||||
{
|
|
||||||
Value = value
|
|
||||||
}, association, topLevel: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T StartChunkBlock<T>(SyntaxTreeNode association) where T : ChunkBlock, new()
|
public T StartChunkBlock<T>(SyntaxTreeNode association) where T : ChunkBlock, new()
|
||||||
{
|
{
|
||||||
return StartChunkBlock<T>(association, topLevel: false);
|
return StartChunkBlock<T>(association, topLevel: false);
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.AspNet.Razor.Parser;
|
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Razor.Generator
|
|
||||||
{
|
|
||||||
public class RazorDirectiveAttributeCodeGenerator : SpanCodeGenerator
|
|
||||||
{
|
|
||||||
public RazorDirectiveAttributeCodeGenerator(string name, string value)
|
|
||||||
{
|
|
||||||
if (String.IsNullOrEmpty(name))
|
|
||||||
{
|
|
||||||
throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "name");
|
|
||||||
}
|
|
||||||
Name = name;
|
|
||||||
Value = value ?? String.Empty; // Coerce to empty string if it was null.
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name { get; private set; }
|
|
||||||
|
|
||||||
public string Value { get; private set; }
|
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
|
||||||
{
|
|
||||||
if (Name == SyntaxConstants.CSharp.SessionStateKeyword)
|
|
||||||
{
|
|
||||||
context.CodeTreeBuilder.AddSessionStateChunk(Value, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return "Directive: " + Name + ", Value: " + Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
var other = obj as RazorDirectiveAttributeCodeGenerator;
|
|
||||||
return other != null &&
|
|
||||||
Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) &&
|
|
||||||
Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return Tuple.Create(Name.ToUpperInvariant(), Value.ToUpperInvariant())
|
|
||||||
.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -25,7 +25,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
MapDirectives(SectionDirective, SyntaxConstants.CSharp.SectionKeyword);
|
MapDirectives(SectionDirective, SyntaxConstants.CSharp.SectionKeyword);
|
||||||
MapDirectives(HelperDirective, SyntaxConstants.CSharp.HelperKeyword);
|
MapDirectives(HelperDirective, SyntaxConstants.CSharp.HelperKeyword);
|
||||||
MapDirectives(LayoutDirective, SyntaxConstants.CSharp.LayoutKeyword);
|
MapDirectives(LayoutDirective, SyntaxConstants.CSharp.LayoutKeyword);
|
||||||
MapDirectives(SessionStateDirective, SyntaxConstants.CSharp.SessionStateKeyword);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void AddTagHelperDirective()
|
protected virtual void AddTagHelperDirective()
|
||||||
|
|
@ -58,65 +57,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
Output(SpanKind.MetaCode, foundNewline ? AcceptedCharacters.None : AcceptedCharacters.Any);
|
Output(SpanKind.MetaCode, foundNewline ? AcceptedCharacters.None : AcceptedCharacters.Any);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void SessionStateDirective()
|
|
||||||
{
|
|
||||||
AssertDirective(SyntaxConstants.CSharp.SessionStateKeyword);
|
|
||||||
AcceptAndMoveNext();
|
|
||||||
|
|
||||||
SessionStateDirectiveCore();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SessionStateDirectiveCore()
|
|
||||||
{
|
|
||||||
SessionStateTypeDirective(RazorResources.ParserEror_SessionDirectiveMissingValue, (key, value) => new RazorDirectiveAttributeCodeGenerator(key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SessionStateTypeDirective(string noValueError, Func<string, string, SpanCodeGenerator> createCodeGenerator)
|
|
||||||
{
|
|
||||||
// Set the block type
|
|
||||||
Context.CurrentBlock.Type = BlockType.Directive;
|
|
||||||
|
|
||||||
// Accept whitespace
|
|
||||||
var remainingWs = AcceptSingleWhiteSpaceCharacter();
|
|
||||||
|
|
||||||
if (Span.Symbols.Count > 1)
|
|
||||||
{
|
|
||||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Output(SpanKind.MetaCode);
|
|
||||||
|
|
||||||
if (remainingWs != null)
|
|
||||||
{
|
|
||||||
Accept(remainingWs);
|
|
||||||
}
|
|
||||||
AcceptWhile(IsSpacingToken(includeNewLines: false, includeComments: true));
|
|
||||||
|
|
||||||
// Parse a Type Name
|
|
||||||
if (!ValidSessionStateValue())
|
|
||||||
{
|
|
||||||
Context.OnError(CurrentLocation, noValueError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pull out the type name
|
|
||||||
var sessionStateValue = String.Concat(
|
|
||||||
Span.Symbols
|
|
||||||
.Cast<CSharpSymbol>()
|
|
||||||
.Select(sym => sym.Content)).Trim();
|
|
||||||
|
|
||||||
// Set up code generation
|
|
||||||
Span.CodeGenerator = createCodeGenerator(SyntaxConstants.CSharp.SessionStateKeyword, sessionStateValue);
|
|
||||||
|
|
||||||
// Output the span and finish the block
|
|
||||||
CompleteBlock();
|
|
||||||
Output(SpanKind.Code);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual bool ValidSessionStateValue()
|
|
||||||
{
|
|
||||||
return Optional(CSharpSymbolType.Identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Coupling will be reviewed at a later date")]
|
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Coupling will be reviewed at a later date")]
|
||||||
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "C# Keywords are always lower-case")]
|
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "C# Keywords are always lower-case")]
|
||||||
protected virtual void HelperDirective()
|
protected virtual void HelperDirective()
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
"namespace",
|
"namespace",
|
||||||
"class",
|
"class",
|
||||||
"layout",
|
"layout",
|
||||||
"sessionstate"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>();
|
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>();
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
public static readonly string NamespaceKeyword = "namespace";
|
public static readonly string NamespaceKeyword = "namespace";
|
||||||
public static readonly string ClassKeyword = "class";
|
public static readonly string ClassKeyword = "class";
|
||||||
public static readonly string LayoutKeyword = "layout";
|
public static readonly string LayoutKeyword = "layout";
|
||||||
public static readonly string SessionStateKeyword = "sessionstate";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -300,11 +300,6 @@ namespace Microsoft.AspNet.Razor.Test.Framework
|
||||||
return _self.With(new SetBaseTypeCodeGenerator(baseType));
|
return _self.With(new SetBaseTypeCodeGenerator(baseType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanConstructor AsRazorDirectiveAttribute(string key, string value)
|
|
||||||
{
|
|
||||||
return _self.With(new RazorDirectiveAttributeCodeGenerator(key, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public SpanConstructor AsAddTagHelper(string lookupText)
|
public SpanConstructor AsAddTagHelper(string lookupText)
|
||||||
{
|
{
|
||||||
return _self.With(
|
return _self.With(
|
||||||
|
|
|
||||||
|
|
@ -247,32 +247,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
.AsBaseType("$rootnamespace$.MyBase")));
|
.AsBaseType("$rootnamespace$.MyBase")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SessionStateDirectiveWorks()
|
|
||||||
{
|
|
||||||
ParseBlockTest("@sessionstate InProc",
|
|
||||||
new DirectiveBlock(
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode(SyntaxConstants.CSharp.SessionStateKeyword + " ")
|
|
||||||
.Accepts(AcceptedCharacters.None),
|
|
||||||
Factory.Code("InProc")
|
|
||||||
.AsRazorDirectiveAttribute("sessionstate", "InProc")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SessionStateDirectiveParsesInvalidSessionValue()
|
|
||||||
{
|
|
||||||
ParseBlockTest("@sessionstate Blah",
|
|
||||||
new DirectiveBlock(
|
|
||||||
Factory.CodeTransition(),
|
|
||||||
Factory.MetaCode(SyntaxConstants.CSharp.SessionStateKeyword + " ")
|
|
||||||
.Accepts(AcceptedCharacters.None),
|
|
||||||
Factory.Code("Blah")
|
|
||||||
.AsRazorDirectiveAttribute("sessionstate", "Blah")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void FunctionsDirective()
|
public void FunctionsDirective()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue