Skip to content

Commit

Permalink
Created new BaseSelector and moved SimpleSelector into a sealed subcl…
Browse files Browse the repository at this point in the history
…ass.
  • Loading branch information
Peter Hultqvist committed Feb 5, 2014
1 parent ef6fa98 commit 02c11d2
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 46 deletions.
8 changes: 3 additions & 5 deletions ExCSS/ExCSS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{26881075-3F64-4825-A6B5-EAA0D5419D20}</ProjectGuid>
<OutputType>Library</OutputType>
Expand Down Expand Up @@ -57,9 +57,6 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>ExCSS.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down Expand Up @@ -111,7 +108,6 @@
<Compile Include="Model\Rules\MediaRule.cs" />
<Compile Include="Model\Rules\NamespaceRule.cs" />
<Compile Include="Model\Rules\PageRule.cs" />
<Compile Include="Model\Rules\RuleSet.cs" />
<Compile Include="Model\Rules\StyleDeclaration.cs" />
<Compile Include="Model\Rules\StyleRule.cs" />
<Compile Include="Model\Rules\SupportsRule.cs" />
Expand Down Expand Up @@ -143,6 +139,8 @@
<Compile Include="Model\Values\GenericFunction.cs" />
<Compile Include="StylesheetReader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Model\Rules\RuleSet.cs" />
<Compile Include="Model\Selector\BaseSelector.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
2 changes: 1 addition & 1 deletion ExCSS/Model/ICssSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
interface ISupportsSelector
{
SimpleSelector Selector { get; set; }
BaseSelector Selector { get; set; }
}
}
4 changes: 2 additions & 2 deletions ExCSS/Model/Rules/PageRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ExCSS
public class PageRule : RuleSet, ISupportsSelector, ISupportsDeclarations
{
private readonly StyleDeclaration _declarations;
private SimpleSelector _selector;
private BaseSelector _selector;
private string _selectorText;

public PageRule()
Expand All @@ -22,7 +22,7 @@ internal PageRule AppendRule(Property rule)
return this;
}

public SimpleSelector Selector
public BaseSelector Selector
{
get { return _selector; }
set
Expand Down
4 changes: 2 additions & 2 deletions ExCSS/Model/Rules/StyleRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ExCSS
public class StyleRule : RuleSet, ISupportsSelector, ISupportsDeclarations
{
private string _value;
private SimpleSelector _selector;
private BaseSelector _selector;
private readonly StyleDeclaration _declarations;

public StyleRule() : this( new StyleDeclaration())
Expand All @@ -20,7 +20,7 @@ public StyleRule(StyleDeclaration declarations)
_declarations = declarations;
}

public SimpleSelector Selector
public BaseSelector Selector
{
get { return _selector; }
set
Expand Down
15 changes: 15 additions & 0 deletions ExCSS/Model/Selector/BaseSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace ExCSS
{
public abstract class BaseSelector
{
public sealed override string ToString()
{
return ToString(false);
}

public abstract string ToString(bool friendlyFormat, int indentation = 0);
}
}

4 changes: 2 additions & 2 deletions ExCSS/Model/Selector/CombinatorSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace ExCSS
{
public struct CombinatorSelector
{
public SimpleSelector Selector;
public BaseSelector Selector;
public Combinator Delimiter;

public CombinatorSelector(SimpleSelector selector, Combinator delimiter)
public CombinatorSelector(BaseSelector selector, Combinator delimiter)
{
Selector = selector;
Delimiter = delimiter;
Expand Down
8 changes: 4 additions & 4 deletions ExCSS/Model/Selector/ComplexSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public class ComplexSelector : SimpleSelector, IEnumerable<CombinatorSelector>
public class ComplexSelector : BaseSelector, IEnumerable<CombinatorSelector>
{
private readonly List<CombinatorSelector> _selectors;

Expand All @@ -15,7 +15,7 @@ public ComplexSelector()
_selectors = new List<CombinatorSelector>();
}

public ComplexSelector AppendSelector(SimpleSelector selector, Combinator combinator)
public ComplexSelector AppendSelector(BaseSelector selector, Combinator combinator)
{
_selectors.Add(new CombinatorSelector(selector, combinator));
return this;
Expand All @@ -26,7 +26,7 @@ public IEnumerator<CombinatorSelector> GetEnumerator()
return _selectors.GetEnumerator();
}

internal void ConcludeSelector(SimpleSelector selector)
internal void ConcludeSelector(BaseSelector selector)
{
_selectors.Add(new CombinatorSelector { Selector = selector });
}
Expand All @@ -41,7 +41,7 @@ IEnumerator IEnumerable.GetEnumerator()
return ((IEnumerable)_selectors).GetEnumerator();
}

public new string ToString(bool friendlyFormat, int indentation = 0)
public override string ToString(bool friendlyFormat, int indentation = 0)
{
var builder = new StringBuilder();

Expand Down
2 changes: 1 addition & 1 deletion ExCSS/Model/Selector/FirstChildSelector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ReSharper disable once CheckNamespace
namespace ExCSS
{
internal sealed class FirstChildSelector : SimpleSelector, IToString
internal sealed class FirstChildSelector : BaseSelector, IToString
{
FirstChildSelector()
{ }
Expand Down
2 changes: 1 addition & 1 deletion ExCSS/Model/Selector/LastChildSelector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ReSharper disable once CheckNamespace
namespace ExCSS
{
internal sealed class LastChildSelector : SimpleSelector, IToString
internal sealed class LastChildSelector : BaseSelector, IToString
{
LastChildSelector()
{ }
Expand Down
4 changes: 2 additions & 2 deletions ExCSS/Model/Selector/NthChildSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ReSharper disable once CheckNamespace
namespace ExCSS
{
internal abstract class NthChildSelector : SimpleSelector, IToString
internal abstract class NthChildSelector : BaseSelector, IToString
{
public int Step;
public int Offset;
Expand All @@ -19,6 +19,6 @@ internal string FormatSelector(string functionName)
: string.Format(":{0}({1})", functionName, FunctionText);
}

public new abstract string ToString(bool friendlyFormat, int indentation = 0);
public abstract override string ToString(bool friendlyFormat, int indentation = 0);
}
}
10 changes: 5 additions & 5 deletions ExCSS/Model/Selector/SelectorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ExCSS
internal sealed class SelectorFactory
{
private SelectorOperation _selectorOperation;
private SimpleSelector _currentSelector;
private BaseSelector _currentSelector;
private AggregateSelectorList _aggregateSelectorList;
private ComplexSelector _complexSelector;
private bool _hasCombinator;
Expand All @@ -24,7 +24,7 @@ internal SelectorFactory()
ResetFactory();
}

internal SimpleSelector Result
internal BaseSelector Result
{
get
{
Expand Down Expand Up @@ -539,7 +539,7 @@ private void InsertCommaDelimited()
_currentSelector = null;
}

private void Insert(SimpleSelector selector)
private void Insert(BaseSelector selector)
{
if (_currentSelector != null)
{
Expand Down Expand Up @@ -630,7 +630,7 @@ private void ParseDelimiter(Block token)
}
}

private SimpleSelector GetChildSelector<T>() where T : NthChildSelector, new()
private BaseSelector GetChildSelector<T>() where T : NthChildSelector, new()
{
var selector = new T();

Expand Down Expand Up @@ -698,7 +698,7 @@ private void ParseDelimiter(Block token)
return selector;
}

private static SimpleSelector GetPseudoSelector(Block token)
private static BaseSelector GetPseudoSelector(Block token)
{
switch (((SymbolBlock)token).Value)
{
Expand Down
12 changes: 6 additions & 6 deletions ExCSS/Model/Selector/SelectorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
// ReSharper disable once CheckNamespace
namespace ExCSS
{
public abstract class SelectorList : SimpleSelector, IEnumerable<SimpleSelector>
public abstract class SelectorList : BaseSelector, IEnumerable<BaseSelector>
{
protected List<SimpleSelector> Selectors;
protected List<BaseSelector> Selectors;

protected SelectorList()
{
Selectors = new List<SimpleSelector>();
Selectors = new List<BaseSelector>();
}

public int Length
{
get { return Selectors.Count; }
}

public SimpleSelector this[int index]
public BaseSelector this[int index]
{
get { return Selectors[index]; }
set { Selectors[index] = value; }
}

public SelectorList AppendSelector(SimpleSelector selector)
public SelectorList AppendSelector(BaseSelector selector)
{
Selectors.Add(selector);
return this;
Expand All @@ -42,7 +42,7 @@ public SelectorList ClearSelectors()
return this;
}

public IEnumerator<SimpleSelector> GetEnumerator()
public IEnumerator<BaseSelector> GetEnumerator()
{
return Selectors.GetEnumerator();
}
Expand Down
16 changes: 2 additions & 14 deletions ExCSS/Model/Selector/SimpleSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

namespace ExCSS
{
public class SimpleSelector
public sealed class SimpleSelector : BaseSelector
{
private readonly string _code;
internal static readonly SimpleSelector All = new SimpleSelector("*");

protected SimpleSelector()
{
//Leave _code = null
}

public SimpleSelector(string selectorText)
{
_code = selectorText;
Expand Down Expand Up @@ -123,15 +118,8 @@ private static string GetValueAsString(string value)
return "'" + value + "'";
}

public sealed override string ToString()
{
return ToString(false);
}

public virtual string ToString(bool friendlyFormat, int indentation = 0)
public override string ToString(bool friendlyFormat, int indentation = 0)
{
if (_code == null)
throw new InvalidOperationException();
return _code;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ExCSS/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public StyleSheet Parse(string css)
return _styleSheet;
}

internal static SimpleSelector ParseSelector(string selector)
internal static BaseSelector ParseSelector(string selector)
{
var tokenizer = new Lexer(new StylesheetReader(selector));
var tokens = tokenizer.Tokens;
Expand Down

0 comments on commit 02c11d2

Please sign in to comment.