removed SessionState directive

This commit is contained in:
Ajay Bhargav Baaskaran 2014-12-29 11:57:00 -08:00
parent 891dfa5e3e
commit ff3ddfcc53
12 changed files with 0 additions and 199 deletions

View File

@ -43,8 +43,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
// Separate the usings and the class
writer.WriteLine();
new CSharpClassAttributeVisitor(writer, Context).Accept(Tree.Chunks);
using (BuildClassDeclaration(writer))
{
if (Host.DesignTimeMode)

View File

@ -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(")]");
}
}
}

View File

@ -113,10 +113,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
{
Visit((ChunkBlock)chunk);
}
else if (chunk is SessionStateChunk)
{
Visit((SessionStateChunk)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(SetLayoutChunk chunk);
protected abstract void Visit(ExpressionBlockChunk chunk);
protected abstract void Visit(SessionStateChunk chunk);
}
}

View File

@ -66,8 +66,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
protected override void Visit(SetLayoutChunk chunk)
{
}
protected override void Visit(SessionStateChunk chunk)
{
}
}
}

View File

@ -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; }
}
}

View File

@ -145,14 +145,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
}, 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()
{
return StartChunkBlock<T>(association, topLevel: false);

View File

@ -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();
}
}
}

View File

@ -25,7 +25,6 @@ namespace Microsoft.AspNet.Razor.Parser
MapDirectives(SectionDirective, SyntaxConstants.CSharp.SectionKeyword);
MapDirectives(HelperDirective, SyntaxConstants.CSharp.HelperKeyword);
MapDirectives(LayoutDirective, SyntaxConstants.CSharp.LayoutKeyword);
MapDirectives(SessionStateDirective, SyntaxConstants.CSharp.SessionStateKeyword);
}
protected virtual void AddTagHelperDirective()
@ -58,65 +57,6 @@ namespace Microsoft.AspNet.Razor.Parser
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.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "C# Keywords are always lower-case")]
protected virtual void HelperDirective()

View File

@ -37,7 +37,6 @@ namespace Microsoft.AspNet.Razor.Parser
"namespace",
"class",
"layout",
"sessionstate"
};
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>();

View File

@ -28,7 +28,6 @@ namespace Microsoft.AspNet.Razor.Parser
public static readonly string NamespaceKeyword = "namespace";
public static readonly string ClassKeyword = "class";
public static readonly string LayoutKeyword = "layout";
public static readonly string SessionStateKeyword = "sessionstate";
}
}
}

View File

@ -300,11 +300,6 @@ namespace Microsoft.AspNet.Razor.Test.Framework
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)
{
return _self.With(

View File

@ -247,32 +247,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
.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]
public void FunctionsDirective()
{