Browse Source

TypeSystemConvertVisitor: add constructor that initializes the visitor with a given context.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
d8b8b53ba3
  1. 2
      ICSharpCode.NRefactory/CSharp/Dom/DomLocation.cs
  2. 45
      ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs
  3. 2
      ICSharpCode.NRefactory/Utils/CSharpPrimitiveCast.cs

2
ICSharpCode.NRefactory/CSharp/Dom/DomLocation.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.CSharp
public bool IsEmpty {
get {
return Line <= 0;
return line <= 0;
}
}

45
ICSharpCode.NRefactory/CSharp/Parser/TypeSystemConvertVisitor.cs

@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
@ -22,12 +22,36 @@ namespace ICSharpCode.NRefactory.CSharp @@ -22,12 +22,36 @@ namespace ICSharpCode.NRefactory.CSharp
DefaultTypeDefinition currentTypeDefinition;
DefaultMethod currentMethod;
/// <summary>
/// Creates a new TypeSystemConvertVisitor.
/// </summary>
/// <param name="pc">The parent project content (used as owner for the types being created).</param>
/// <param name="fileName">The file name (used for DomRegions).</param>
public TypeSystemConvertVisitor(IProjectContent pc, string fileName)
{
if (pc == null)
throw new ArgumentNullException("pc");
if (fileName == null)
throw new ArgumentNullException("fileName");
this.parsedFile = new ParsedFile(fileName, new UsingScope(pc));
this.usingScope = parsedFile.RootUsingScope;
}
/// <summary>
/// Creates a new TypeSystemConvertVisitor and initializes it with a given context.
/// </summary>
/// <param name="parsedFile">The parsed file to which members should be added.</param>
/// <param name="currentUsingScope">The current using scope.</param>
/// <param name="currentTypeDefinition">The current type definition.</param>
public TypeSystemConvertVisitor(ParsedFile parsedFile, UsingScope currentUsingScope = null, DefaultTypeDefinition currentTypeDefinition = null)
{
if (parsedFile == null)
throw new ArgumentNullException("parsedFile");
this.parsedFile = parsedFile;
this.usingScope = currentUsingScope ?? parsedFile.RootUsingScope;
this.currentTypeDefinition = currentTypeDefinition;
}
public ParsedFile ParsedFile {
get { return parsedFile; }
}
@ -241,6 +265,25 @@ namespace ICSharpCode.NRefactory.CSharp @@ -241,6 +265,25 @@ namespace ICSharpCode.NRefactory.CSharp
}
return isSingleField ? field : null;
}
public override IEntity VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, object data)
{
DefaultField field = new DefaultField(currentTypeDefinition, enumMemberDeclaration.Name);
field.Region = field.BodyRegion = MakeRegion(enumMemberDeclaration);
ConvertAttributes(field.Attributes, enumMemberDeclaration.Attributes);
field.ReturnType = currentTypeDefinition;
field.Accessibility = Accessibility.Public;
field.IsStatic = true;
if (enumMemberDeclaration.Initializer != null) {
field.ConstantValue = ConvertConstantValue(currentTypeDefinition, enumMemberDeclaration.Initializer);
} else {
throw new NotImplementedException();
}
currentTypeDefinition.Fields.Add(field);
return field;
}
#endregion
#region Methods

2
ICSharpCode.NRefactory/Utils/CSharpPrimitiveCast.cs

@ -407,7 +407,7 @@ namespace ICSharpCode.NRefactory.Utils @@ -407,7 +407,7 @@ namespace ICSharpCode.NRefactory.Utils
}
break;
}
throw new InvalidCastException("Cast from " + sourceType + " to " + targetType + "not supported.");
throw new InvalidCastException("Cast from " + sourceType + " to " + targetType + " not supported.");
}
}
}

Loading…
Cancel
Save