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
public bool IsEmpty { public bool IsEmpty {
get { get {
return Line <= 0; return line <= 0;
} }
} }

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

@ -3,8 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
@ -22,12 +22,36 @@ namespace ICSharpCode.NRefactory.CSharp
DefaultTypeDefinition currentTypeDefinition; DefaultTypeDefinition currentTypeDefinition;
DefaultMethod currentMethod; 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) 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.parsedFile = new ParsedFile(fileName, new UsingScope(pc));
this.usingScope = parsedFile.RootUsingScope; 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 { public ParsedFile ParsedFile {
get { return parsedFile; } get { return parsedFile; }
} }
@ -241,6 +265,25 @@ namespace ICSharpCode.NRefactory.CSharp
} }
return isSingleField ? field : null; 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 #endregion
#region Methods #region Methods

2
ICSharpCode.NRefactory/Utils/CSharpPrimitiveCast.cs

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

Loading…
Cancel
Save