Browse Source

Use AstType.ToTypeReference() instead of TypeSystemConvertVisitor.ConvertType().

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
6d7abd9b0f
  1. 8
      ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs
  3. 53
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

8
ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs

@ -85,12 +85,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -85,12 +85,16 @@ namespace ICSharpCode.NRefactory.CSharp
if (nodes != null)
nodes = nodes.ToList();
Clear();
foreach (T node in nodes)
Add(node);
if (nodes != null) {
foreach (T node in nodes)
Add(node);
}
}
public void MoveTo(ICollection<T> targetCollection)
{
if (targetCollection == null)
throw new ArgumentNullException("targetCollection");
foreach (T node in this) {
node.Remove();
targetCollection.Add(node);

2
ICSharpCode.NRefactory.CSharp/Ast/PrimitiveType.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -91,7 +91,7 @@ namespace ICSharpCode.NRefactory.CSharp
return Keyword ?? base.ToString();
}
public override ITypeReference ToTypeReference(SimpleNameLookupMode lookupMode)
public override ITypeReference ToTypeReference(SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
{
KnownTypeCode typeCode = GetTypeCodeForPrimitiveType(this.Keyword);
if (typeCode == KnownTypeCode.None)

53
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -121,7 +121,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -121,7 +121,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
public override IUnresolvedEntity VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data)
{
TypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, SimpleNameLookupMode.TypeInUsingDeclaration) as TypeOrNamespaceReference;
TypeOrNamespaceReference u = usingDeclaration.Import.ToTypeReference(SimpleNameLookupMode.TypeInUsingDeclaration) as TypeOrNamespaceReference;
if (u != null) {
if (interningProvider != null)
u = interningProvider.Intern(u);
@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -132,7 +132,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
public override IUnresolvedEntity VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, object data)
{
TypeOrNamespaceReference u = ConvertType(usingDeclaration.Import, SimpleNameLookupMode.TypeInUsingDeclaration) as TypeOrNamespaceReference;
TypeOrNamespaceReference u = usingDeclaration.Import.ToTypeReference(SimpleNameLookupMode.TypeInUsingDeclaration) as TypeOrNamespaceReference;
if (u != null) {
if (interningProvider != null)
u = interningProvider.Intern(u);
@ -202,7 +202,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -202,7 +202,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints, EntityType.TypeDefinition);
foreach (AstType baseType in typeDeclaration.BaseTypes) {
td.BaseTypes.Add(ConvertType(baseType, SimpleNameLookupMode.BaseTypeReference));
td.BaseTypes.Add(baseType.ToTypeReference(SimpleNameLookupMode.BaseTypeReference));
}
foreach (AttributedNode member in typeDeclaration.Members) {
@ -228,7 +228,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -228,7 +228,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints, EntityType.TypeDefinition);
ITypeReference returnType = ConvertType(delegateDeclaration.ReturnType);
ITypeReference returnType = delegateDeclaration.ReturnType.ToTypeReference();
List<IUnresolvedParameter> parameters = new List<IUnresolvedParameter>();
ConvertParameters(parameters, delegateDeclaration.Parameters);
AddDefaultMethodsToDelegate(td, returnType, parameters);
@ -339,7 +339,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -339,7 +339,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
field.IsVolatile = (modifiers & Modifiers.Volatile) != 0;
field.IsReadOnly = (modifiers & Modifiers.Readonly) != 0;
field.ReturnType = ConvertType(fieldDeclaration.ReturnType);
field.ReturnType = fieldDeclaration.ReturnType.ToTypeReference();
if ((modifiers & Modifiers.Const) != 0) {
field.ConstantValue = ConvertConstantValue(field.ReturnType, vi.Initializer);
@ -407,7 +407,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -407,7 +407,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
} else {
ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints, EntityType.Method);
}
m.ReturnType = ConvertType(methodDeclaration.ReturnType);
m.ReturnType = methodDeclaration.ReturnType.ToTypeReference();
ConvertAttributes(m.Attributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget != "return"));
ConvertAttributes(m.ReturnTypeAttributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget == "return"));
@ -422,7 +422,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -422,7 +422,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
m.Accessibility = Accessibility.None;
m.IsExplicitInterfaceImplementation = true;
m.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
m.EntityType, ConvertType(methodDeclaration.PrivateImplementationType), m.Name,
m.EntityType, methodDeclaration.PrivateImplementationType.ToTypeReference(), m.Name,
m.TypeParameters.Count, GetParameterTypes(m.Parameters)));
}
@ -484,7 +484,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -484,7 +484,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
continue;
}
}
tp.Constraints.Add(ConvertType(type));
tp.Constraints.Add(type.ToTypeReference());
}
break;
}
@ -494,7 +494,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -494,7 +494,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
IMemberReference ConvertInterfaceImplementation(AstType interfaceType, AbstractUnresolvedMember unresolvedMember)
{
ITypeReference interfaceTypeReference = ConvertType(interfaceType);
ITypeReference interfaceTypeReference = interfaceType.ToTypeReference();
int typeParameterCount = 0;
IList<ITypeReference> parameterTypes = null;
if (unresolvedMember.EntityType == EntityType.Method) {
@ -507,7 +507,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -507,7 +507,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
parameterTypes[i] = parameterizedMember.Parameters[i].Type;
}
}
return new DefaultMemberReference(unresolvedMember.EntityType, ConvertType(interfaceType), unresolvedMember.Name, typeParameterCount, parameterTypes);
return new DefaultMemberReference(unresolvedMember.EntityType, interfaceTypeReference, unresolvedMember.Name, typeParameterCount, parameterTypes);
}
#endregion
@ -519,7 +519,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -519,7 +519,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
m.Region = MakeRegion(operatorDeclaration);
m.BodyRegion = MakeRegion(operatorDeclaration.Body);
m.ReturnType = ConvertType(operatorDeclaration.ReturnType);
m.ReturnType = operatorDeclaration.ReturnType.ToTypeReference();
ConvertAttributes(m.Attributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget != "return"));
ConvertAttributes(m.ReturnTypeAttributes, operatorDeclaration.Attributes.Where(s => s.AttributeTarget == "return"));
@ -594,13 +594,13 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -594,13 +594,13 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
p.Region = MakeRegion(propertyDeclaration);
p.BodyRegion = MakeBraceRegion(propertyDeclaration);
ApplyModifiers(p, propertyDeclaration.Modifiers);
p.ReturnType = ConvertType(propertyDeclaration.ReturnType);
p.ReturnType = propertyDeclaration.ReturnType.ToTypeReference();
ConvertAttributes(p.Attributes, propertyDeclaration.Attributes);
if (!propertyDeclaration.PrivateImplementationType.IsNull) {
p.Accessibility = Accessibility.None;
p.IsExplicitInterfaceImplementation = true;
p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
p.EntityType, ConvertType(propertyDeclaration.PrivateImplementationType), p.Name));
p.EntityType, propertyDeclaration.PrivateImplementationType.ToTypeReference(), p.Name));
}
p.Getter = ConvertAccessor(propertyDeclaration.Getter, p, "get_");
p.Setter = ConvertAccessor(propertyDeclaration.Setter, p, "set_");
@ -618,7 +618,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -618,7 +618,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
p.Region = MakeRegion(indexerDeclaration);
p.BodyRegion = MakeBraceRegion(indexerDeclaration);
ApplyModifiers(p, indexerDeclaration.Modifiers);
p.ReturnType = ConvertType(indexerDeclaration.ReturnType);
p.ReturnType = indexerDeclaration.ReturnType.ToTypeReference();
ConvertAttributes(p.Attributes, indexerDeclaration.Attributes);
p.Getter = ConvertAccessor(indexerDeclaration.Getter, p, "get_");
@ -629,7 +629,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -629,7 +629,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
p.Accessibility = Accessibility.None;
p.IsExplicitInterfaceImplementation = true;
p.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
p.EntityType, ConvertType(indexerDeclaration.PrivateImplementationType), p.Name, 0, GetParameterTypes(p.Parameters)));
p.EntityType, indexerDeclaration.PrivateImplementationType.ToTypeReference(), p.Name, 0, GetParameterTypes(p.Parameters)));
}
currentTypeDefinition.Members.Add(p);
@ -681,7 +681,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -681,7 +681,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ApplyModifiers(ev, modifiers);
ev.ReturnType = ConvertType(eventDeclaration.ReturnType);
ev.ReturnType = eventDeclaration.ReturnType.ToTypeReference();
var valueParameter = new DefaultUnresolvedParameter(ev.ReturnType, "value");
ev.AddAccessor = CreateDefaultEventAccessor(ev, "get_" + ev.Name, valueParameter);
@ -724,14 +724,14 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -724,14 +724,14 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
e.Region = MakeRegion(eventDeclaration);
e.BodyRegion = MakeBraceRegion(eventDeclaration);
ApplyModifiers(e, eventDeclaration.Modifiers);
e.ReturnType = ConvertType(eventDeclaration.ReturnType);
e.ReturnType = eventDeclaration.ReturnType.ToTypeReference();
ConvertAttributes(e.Attributes, eventDeclaration.Attributes);
if (!eventDeclaration.PrivateImplementationType.IsNull) {
e.Accessibility = Accessibility.None;
e.IsExplicitInterfaceImplementation = true;
e.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
e.EntityType, ConvertType(eventDeclaration.PrivateImplementationType), e.Name));
e.EntityType, eventDeclaration.PrivateImplementationType.ToTypeReference(), e.Name));
}
e.AddAccessor = ConvertAccessor(eventDeclaration.AddAccessor, e, "add_");
@ -819,7 +819,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -819,7 +819,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
internal static ITypeReference ConvertAttributeType(AstType type)
{
ITypeReference tr = ConvertType(type, SimpleNameLookupMode.Type);
ITypeReference tr = type.ToTypeReference();
if (!type.GetChildByRole(AstNode.Roles.Identifier).IsVerbatim) {
// Try to add "Attribute" suffix, but only if the identifier
// (=last identifier in fully qualified name) isn't a verbatim identifier.
@ -865,6 +865,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -865,6 +865,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
#endregion
#region Types
[Obsolete("Use AstType.ToTypeReference() instead.")]
public static ITypeReference ConvertType(AstType type, SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
{
return type.ToTypeReference(lookupMode);
@ -933,7 +934,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -933,7 +934,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ITypeReference[] result = new ITypeReference[count];
int pos = 0;
foreach (AstType type in types) {
result[pos++] = ConvertType(type);
result[pos++] = type.ToTypeReference();
}
return result;
}
@ -949,7 +950,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -949,7 +950,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
if (tre != null) {
// handle "int.MaxValue"
return new ConstantMemberReference(
ConvertType(tre.Type),
tre.Type.ToTypeReference(),
memberReferenceExpression.MemberName,
ConvertTypeArguments(memberReferenceExpression.TypeArguments));
}
@ -971,7 +972,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -971,7 +972,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ConstantExpression v = castExpression.Expression.AcceptVisitor(this, data);
if (v == null)
return null;
return new ConstantCast(ConvertType(castExpression.Type), v);
return new ConstantCast(castExpression.Type.ToTypeReference(), v);
}
public override ConstantExpression VisitCheckedExpression(CheckedExpression checkedExpression, object data)
@ -994,7 +995,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -994,7 +995,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
public override ConstantExpression VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data)
{
return new ConstantDefaultValue(ConvertType(defaultValueExpression.Type));
return new ConstantDefaultValue(defaultValueExpression.Type.ToTypeReference());
}
public override ConstantExpression VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
@ -1025,7 +1026,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -1025,7 +1026,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
public override ConstantExpression VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data)
{
if (isAttributeArgument) {
return new TypeOfConstantExpression(ConvertType(typeOfExpression.Type));
return new TypeOfConstantExpression(typeOfExpression.Type.ToTypeReference());
} else {
return null;
}
@ -1040,7 +1041,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -1040,7 +1041,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
if (arrayCreateExpression.Type.IsNull) {
type = null;
} else {
type = ConvertType(arrayCreateExpression.Type);
type = arrayCreateExpression.Type.ToTypeReference();
foreach (var spec in arrayCreateExpression.AdditionalArraySpecifiers.Reverse()) {
type = new ArrayTypeReference(type, spec.Dimensions);
}
@ -1065,7 +1066,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -1065,7 +1066,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
void ConvertParameters(IList<IUnresolvedParameter> outputList, IEnumerable<ParameterDeclaration> parameters)
{
foreach (ParameterDeclaration pd in parameters) {
DefaultUnresolvedParameter p = new DefaultUnresolvedParameter(ConvertType(pd.Type), pd.Name);
DefaultUnresolvedParameter p = new DefaultUnresolvedParameter(pd.Type.ToTypeReference(), pd.Name);
p.Region = MakeRegion(pd);
ConvertAttributes(p.Attributes, pd.Attributes);
switch (pd.ParameterModifier) {

Loading…
Cancel
Save