Browse Source

Port NRefactory to .NET 3.5.

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
41b4385d7c
  1. 1
      ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj
  2. 1
      ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj
  3. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  4. 2
      ICSharpCode.NRefactory/CSharp/Ast/MemberType.cs
  5. 2
      ICSharpCode.NRefactory/CSharp/Ast/SimpleType.cs
  6. 36
      ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs
  7. 18
      ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs
  8. 10
      ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs
  9. 2
      ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs
  10. 2
      ICSharpCode.NRefactory/CSharp/Resolver/OverloadResolution.cs
  11. 2
      ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs
  12. 2
      ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs
  13. 2
      ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs
  14. 15
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  15. 2
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  16. 8
      ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs
  17. 4
      ICSharpCode.NRefactory/TypeSystem/IAttribute.cs
  18. 4
      ICSharpCode.NRefactory/TypeSystem/IConstantValue.cs
  19. 4
      ICSharpCode.NRefactory/TypeSystem/IEntity.cs
  20. 4
      ICSharpCode.NRefactory/TypeSystem/IExplicitInterfaceImplementation.cs
  21. 4
      ICSharpCode.NRefactory/TypeSystem/IField.cs
  22. 4
      ICSharpCode.NRefactory/TypeSystem/IFreezable.cs
  23. 4
      ICSharpCode.NRefactory/TypeSystem/IInterningProvider.cs
  24. 4
      ICSharpCode.NRefactory/TypeSystem/IMember.cs
  25. 11
      ICSharpCode.NRefactory/TypeSystem/IMethod.cs
  26. 4
      ICSharpCode.NRefactory/TypeSystem/INamedElement.cs
  27. 4
      ICSharpCode.NRefactory/TypeSystem/IParameter.cs
  28. 4
      ICSharpCode.NRefactory/TypeSystem/IParameterizedMember.cs
  29. 4
      ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs
  30. 4
      ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs
  31. 4
      ICSharpCode.NRefactory/TypeSystem/IType.cs
  32. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs
  33. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs
  34. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs
  35. 4
      ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs
  36. 4
      ICSharpCode.NRefactory/TypeSystem/IVariable.cs
  37. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs
  38. 9
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs
  39. 23
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs
  40. 24
      ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleInterningProvider.cs
  41. 58
      ICSharpCode.NRefactory/Utils/DotNet35Compat.cs
  42. 8
      NRefactory.sln
  43. 1
      VBDomGenerator/VBDomGenerator.csproj

1
ICSharpCode.NRefactory.Tests/ICSharpCode.NRefactory.Tests.csproj

@ -11,6 +11,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<ProductVersion>10.0.0</ProductVersion> <ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>

1
ICSharpCode.NRefactory.VB.Tests/ICSharpCode.NRefactory.VB.Tests.csproj

@ -19,6 +19,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>

1
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -9,6 +9,7 @@
<AssemblyName>ICSharpCode.NRefactory.VB</AssemblyName> <AssemblyName>ICSharpCode.NRefactory.VB</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> <PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>

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

@ -77,7 +77,7 @@ namespace ICSharpCode.NRefactory.CSharp
b.Append(this.MemberName); b.Append(this.MemberName);
if (this.TypeArguments.Any()) { if (this.TypeArguments.Any()) {
b.Append('<'); b.Append('<');
b.Append(string.Join(", ", this.TypeArguments)); b.Append(DotNet35Compat.StringJoin(", ", this.TypeArguments));
b.Append('>'); b.Append('>');
} }
return b.ToString(); return b.ToString();

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

@ -76,7 +76,7 @@ namespace ICSharpCode.NRefactory.CSharp
StringBuilder b = new StringBuilder(this.Identifier); StringBuilder b = new StringBuilder(this.Identifier);
if (this.TypeArguments.Any()) { if (this.TypeArguments.Any()) {
b.Append('<'); b.Append('<');
b.Append(string.Join(", ", this.TypeArguments)); b.Append(DotNet35Compat.StringJoin(", ", this.TypeArguments));
b.Append('>'); b.Append('>');
} }
return b.ToString(); return b.ToString();

36
ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs

@ -181,12 +181,34 @@ namespace ICSharpCode.NRefactory.CSharp
RPar(); RPar();
} }
void WriteCommaSeparatedListInBrackets(IEnumerable<AstNode> list) #if DOTNET35
void WriteCommaSeparatedList(IEnumerable<VariableInitializer> list)
{
WriteCommaSeparatedList(list.SafeCast<VariableInitializer, AstNode>());
}
void WriteCommaSeparatedList(IEnumerable<AstType> list)
{
WriteCommaSeparatedList(list.SafeCast<AstType, AstNode>());
}
void WriteCommaSeparatedListInParenthesis(IEnumerable<Expression> list, bool spaceWithin)
{
WriteCommaSeparatedListInParenthesis(list.SafeCast<Expression, AstNode>(), spaceWithin);
}
void WriteCommaSeparatedListInParenthesis(IEnumerable<ParameterDeclaration> list, bool spaceWithin)
{
WriteCommaSeparatedListInParenthesis(list.SafeCast<ParameterDeclaration, AstNode>(), spaceWithin);
}
#endif
void WriteCommaSeparatedListInBrackets(IEnumerable<Expression> list)
{ {
WriteToken("[", AstNode.Roles.LBracket); WriteToken("[", AstNode.Roles.LBracket);
if (list.Any()) { if (list.Any()) {
Space(policy.SpacesWithinBrackets); Space(policy.SpacesWithinBrackets);
WriteCommaSeparatedList(list); WriteCommaSeparatedList(list.SafeCast<Expression, AstNode>());
Space(policy.SpacesWithinBrackets); Space(policy.SpacesWithinBrackets);
} }
WriteToken("]", AstNode.Roles.RBracket); WriteToken("]", AstNode.Roles.RBracket);
@ -354,7 +376,7 @@ namespace ICSharpCode.NRefactory.CSharp
{ {
if (typeParameters.Any()) { if (typeParameters.Any()) {
WriteToken("<", AstNode.Roles.LChevron); WriteToken("<", AstNode.Roles.LChevron);
WriteCommaSeparatedList(typeParameters); WriteCommaSeparatedList(typeParameters.SafeCast<TypeParameterDeclaration, AstNode>());
WriteToken(">", AstNode.Roles.RChevron); WriteToken(">", AstNode.Roles.RChevron);
} }
} }
@ -1036,7 +1058,7 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode(queryOrderClause); StartNode(queryOrderClause);
WriteKeyword("orderby"); WriteKeyword("orderby");
Space(); Space();
WriteCommaSeparatedList(queryOrderClause.Orderings); WriteCommaSeparatedList(queryOrderClause.Orderings.SafeCast<QueryOrdering, AstNode>());
return EndNode(queryOrderClause); return EndNode(queryOrderClause);
} }
@ -1099,7 +1121,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteToken(":", AttributeSection.Roles.Colon); WriteToken(":", AttributeSection.Roles.Colon);
Space(); Space();
} }
WriteCommaSeparatedList(attributeSection.Attributes); WriteCommaSeparatedList(attributeSection.Attributes.SafeCast<Attribute, AstNode>());
WriteToken("]", AstNode.Roles.RBracket); WriteToken("]", AstNode.Roles.RBracket);
NewLine(); NewLine();
return EndNode(attributeSection); return EndNode(attributeSection);
@ -1348,7 +1370,7 @@ namespace ICSharpCode.NRefactory.CSharp
LPar(); LPar();
Space(policy.WithinForParentheses); Space(policy.WithinForParentheses);
WriteCommaSeparatedList(forStatement.Initializers); WriteCommaSeparatedList(forStatement.Initializers.SafeCast<Statement, AstNode>());
WriteToken(";", AstNode.Roles.Semicolon); WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon); Space(policy.SpacesAfterSemicolon);
@ -1356,7 +1378,7 @@ namespace ICSharpCode.NRefactory.CSharp
WriteToken(";", AstNode.Roles.Semicolon); WriteToken(";", AstNode.Roles.Semicolon);
Space(policy.SpacesAfterSemicolon); Space(policy.SpacesAfterSemicolon);
WriteCommaSeparatedList(forStatement.Iterators); WriteCommaSeparatedList(forStatement.Iterators.SafeCast<Statement, AstNode>());
Space(policy.WithinForParentheses); Space(policy.WithinForParentheses);
RPar(); RPar();

18
ICSharpCode.NRefactory/CSharp/Resolver/CSharpResolver.cs

@ -26,13 +26,22 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
internal readonly CancellationToken cancellationToken; internal readonly CancellationToken cancellationToken;
#region Constructor #region Constructor
public CSharpResolver(ITypeResolveContext context, CancellationToken cancellationToken = default(CancellationToken)) public CSharpResolver(ITypeResolveContext context)
{
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
}
#if !DOTNET35
public CSharpResolver(ITypeResolveContext context, CancellationToken cancellationToken)
{ {
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException("context");
this.context = context; this.context = context;
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
} }
#endif
#endregion #endregion
#region Properties #region Properties
@ -1822,7 +1831,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
} else { } else {
// No candidate found at all (not even an inapplicable one). // No candidate found at all (not even an inapplicable one).
// This can happen with empty method groups (as sometimes used with extension methods) // This can happen with empty method groups (as sometimes used with extension methods)
return new UnknownMethodResolveResult(mgrr.TargetType, mgrr.MethodName, mgrr.TypeArguments, CreateParameters(arguments, argumentNames)); return new UnknownMethodResolveResult(
mgrr.TargetType, mgrr.MethodName, mgrr.TypeArguments, CreateParameters(arguments, argumentNames));
} }
} }
UnknownMemberResolveResult umrr = target as UnknownMemberResolveResult; UnknownMemberResolveResult umrr = target as UnknownMemberResolveResult;
@ -1840,9 +1850,9 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return ErrorResult; return ErrorResult;
} }
static List<DefaultParameter> CreateParameters(ResolveResult[] arguments, string[] argumentNames) static List<IParameter> CreateParameters(ResolveResult[] arguments, string[] argumentNames)
{ {
List<DefaultParameter> list = new List<DefaultParameter>(); List<IParameter> list = new List<IParameter>();
if (argumentNames == null) { if (argumentNames == null) {
argumentNames = new string[arguments.Length]; argumentNames = new string[arguments.Length];
} else { } else {

10
ICSharpCode.NRefactory/CSharp/Resolver/MemberLookup.cs

@ -170,10 +170,10 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
Predicate<IMember> memberFilter = delegate(IMember member) { Predicate<IMember> memberFilter = delegate(IMember member) {
return !member.IsOverride && member.Name == name && IsAccessible(member, allowProtectedAccess); return !member.IsOverride && member.Name == name && IsAccessible(member, allowProtectedAccess);
}; };
members.AddRange(type.GetMethods(context, memberFilter)); members.AddRange(type.GetMethods(context, memberFilter.SafeCast<IMember, IMethod>()).SafeCast<IMethod, IMember>());
members.AddRange(type.GetProperties(context, memberFilter)); members.AddRange(type.GetProperties(context, memberFilter.SafeCast<IMember, IProperty>()).SafeCast<IProperty, IMember>());
members.AddRange(type.GetFields(context, memberFilter)); members.AddRange(type.GetFields(context, memberFilter.SafeCast<IMember, IField>()).SafeCast<IField, IMember>());
members.AddRange(type.GetEvents(context, memberFilter)); members.AddRange(type.GetEvents(context, memberFilter.SafeCast<IMember, IEvent>()).SafeCast<IEvent, IMember>());
if (isInvocation) if (isInvocation)
members.RemoveAll(m => !IsInvocable(m, context)); members.RemoveAll(m => !IsInvocable(m, context));
} else { } else {
@ -183,7 +183,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
return method.TypeParameters.Count == typeArgumentCount return method.TypeParameters.Count == typeArgumentCount
&& !method.IsOverride && method.Name == name && IsAccessible(method, allowProtectedAccess); && !method.IsOverride && method.Name == name && IsAccessible(method, allowProtectedAccess);
}; };
members.AddRange(type.GetMethods(context, memberFilter)); members.AddRange(type.GetMethods(context, memberFilter).SafeCast<IMethod, IMember>());
} }
// TODO: can't members also hide types? // TODO: can't members also hide types?

2
ICSharpCode.NRefactory/CSharp/Resolver/MemberTypeOrNamespaceReference.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (typeArguments.Count == 0) if (typeArguments.Count == 0)
return target.ToString() + "." + identifier; return target.ToString() + "." + identifier;
else else
return target.ToString() + "." + identifier + "<" + string.Join(",", typeArguments) + ">"; return target.ToString() + "." + identifier + "<" + DotNet35Compat.StringJoin(",", typeArguments) + ">";
} }
} }
} }

2
ICSharpCode.NRefactory/CSharp/Resolver/OverloadResolution.cs

@ -446,7 +446,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{ {
bool c1IsBetter = false; bool c1IsBetter = false;
bool c2IsBetter = false; bool c2IsBetter = false;
foreach (var pair in t1.Zip<IType, IType, Tuple<IType, IType>>(t2, Tuple.Create)) { foreach (var pair in t1.Zip(t2, (a,b) => new { Item1 = a, Item2 = b })) {
switch (MoreSpecificFormalParameter(pair.Item1, pair.Item2)) { switch (MoreSpecificFormalParameter(pair.Item1, pair.Item2)) {
case 1: case 1:
c1IsBetter = true; c1IsBetter = true;

2
ICSharpCode.NRefactory/CSharp/Resolver/ResolveVisitor.cs

@ -593,7 +593,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
} }
} }
ResolveResult[] GetArguments(IEnumerable<AstNode> argumentExpressions, out string[] argumentNames) ResolveResult[] GetArguments(IEnumerable<Expression> argumentExpressions, out string[] argumentNames)
{ {
argumentNames = null; // TODO: add support for named arguments argumentNames = null; // TODO: add support for named arguments
ResolveResult[] arguments = new ResolveResult[argumentExpressions.Count()]; ResolveResult[] arguments = new ResolveResult[argumentExpressions.Count()];

2
ICSharpCode.NRefactory/CSharp/Resolver/SimpleTypeOrNamespaceReference.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (typeArguments.Count == 0) if (typeArguments.Count == 0)
return identifier; return identifier;
else else
return identifier + "<" + string.Join(",", typeArguments) + ">"; return identifier + "<" + DotNet35Compat.StringJoin(",", typeArguments) + ">";
} }
} }
} }

2
ICSharpCode.NRefactory/CSharp/Resolver/TypeInference.cs

@ -856,7 +856,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
bool success; bool success;
IType[] result = InferTypeArgumentsFromBounds( IType[] result = InferTypeArgumentsFromBounds(
candidateDef.TypeParameters, candidateDef.TypeParameters,
new ParameterizedType(candidateDef, candidateDef.TypeParameters), new ParameterizedType(candidateDef, candidateDef.TypeParameters.SafeCast<ITypeParameter, IType>()),
lowerBounds, upperBounds, lowerBounds, upperBounds,
out success); out success);
if (success) { if (success) {

15
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -7,7 +7,7 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.NRefactory</RootNamespace> <RootNamespace>ICSharpCode.NRefactory</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory</AssemblyName> <AssemblyName>ICSharpCode.NRefactory</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<ProductVersion>10.0.0</ProductVersion> <ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
@ -15,6 +15,7 @@
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<NoWarn>1591,0618</NoWarn> <NoWarn>1591,0618</NoWarn>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@ -27,24 +28,27 @@
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DebugType>Full</DebugType> <DebugType>Full</DebugType>
<Optimize>False</Optimize> <Optimize>False</Optimize>
<DefineConstants>DEBUG;TRACE;FULL_AST</DefineConstants> <DefineConstants>DEBUG;TRACE;FULL_AST;DOTNET35</DefineConstants>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DebugType>None</DebugType> <DebugType>None</DebugType>
<Optimize>True</Optimize> <Optimize>True</Optimize>
<DefineConstants>TRACE;FULL_AST</DefineConstants> <DefineConstants>TRACE;FULL_AST;DOTNET35</DefineConstants>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType> <DebugType>Full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType> <DebugType>None</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
@ -322,6 +326,7 @@
<Compile Include="Utils\BusyManager.cs" /> <Compile Include="Utils\BusyManager.cs" />
<Compile Include="Utils\CacheManager.cs" /> <Compile Include="Utils\CacheManager.cs" />
<Compile Include="Utils\CSharpPrimitiveCast.cs" /> <Compile Include="Utils\CSharpPrimitiveCast.cs" />
<Compile Include="Utils\DotNet35Compat.cs" />
<Compile Include="Utils\EmptyList.cs" /> <Compile Include="Utils\EmptyList.cs" />
<Compile Include="Utils\ExtensionMethods.cs" /> <Compile Include="Utils\ExtensionMethods.cs" />
<Compile Include="Utils\TreeTraversal.cs" /> <Compile Include="Utils\TreeTraversal.cs" />

2
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -297,7 +297,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
static readonly string DynamicAttributeFullName = typeof(DynamicAttribute).FullName; const string DynamicAttributeFullName = "System.Runtime.CompilerServices.DynamicAttribute";
static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex) static bool HasDynamicAttribute(ICustomAttributeProvider attributeProvider, int typeIndex)
{ {

8
ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs

@ -70,15 +70,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
throw new ArgumentNullException("context"); throw new ArgumentNullException("context");
HashSet<ITypeDefinition> typeDefinitions = new HashSet<ITypeDefinition>(); HashSet<ITypeDefinition> typeDefinitions = new HashSet<ITypeDefinition>();
Func<IType, IEnumerable<ITypeDefinition>> recursion = Func<ITypeDefinition, IEnumerable<ITypeDefinition>> recursion =
t => t.GetBaseTypes(context).Select(b => b.GetDefinition()).Where(d => d != null && typeDefinitions.Add(d)); t => t.GetBaseTypes(context).Select(b => b.GetDefinition()).Where(d => d != null && typeDefinitions.Add(d));
ITypeDefinition typeDef = type as ITypeDefinition; ITypeDefinition typeDef = type as ITypeDefinition;
if (typeDef != null) { if (typeDef != null) {
typeDefinitions.Add(typeDef); typeDefinitions.Add(typeDef);
return TreeTraversal.PreOrder<ITypeDefinition>(typeDef, recursion); return TreeTraversal.PreOrder(typeDef, recursion);
} else { } else {
return TreeTraversal.PreOrder<ITypeDefinition>(recursion(type), recursion); return TreeTraversal.PreOrder(
type.GetBaseTypes(context).Select(b => b.GetDefinition()).Where(d => d != null && typeDefinitions.Add(d)),
recursion);
} }
} }

4
ICSharpCode.NRefactory/TypeSystem/IAttribute.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents an attribute. /// Represents an attribute.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IAttributeContract))] [ContractClass(typeof(IAttributeContract))]
#endif
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public interface IAttribute : IFreezable public interface IAttribute : IFreezable
{ {
@ -35,6 +37,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IList<KeyValuePair<string, IConstantValue>> NamedArguments { get; } IList<KeyValuePair<string, IConstantValue>> NamedArguments { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IAttribute))] [ContractClassFor(typeof(IAttribute))]
abstract class IAttributeContract : IFreezableContract, IAttribute abstract class IAttributeContract : IFreezableContract, IAttribute
{ {
@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IConstantValue.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(IConstantValueContract))] [ContractClass(typeof(IConstantValueContract))]
#endif
public interface IConstantValue : IFreezable public interface IConstantValue : IFreezable
{ {
/// <summary> /// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
object GetValue(ITypeResolveContext context); object GetValue(ITypeResolveContext context);
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IConstantValue))] [ContractClassFor(typeof(IConstantValue))]
abstract class IConstantValueContract : IFreezableContract, IConstantValue abstract class IConstantValueContract : IFreezableContract, IConstantValue
{ {
@ -46,4 +49,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null; return null;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IEntity.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(IEntityContract))] [ContractClass(typeof(IEntityContract))]
#endif
public interface IEntity : INamedElement, IFreezable public interface IEntity : INamedElement, IFreezable
{ {
EntityType EntityType { get; } EntityType EntityType { get; }
@ -75,6 +77,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
//bool IsAccessible(IClass callingClass, bool isAccessThoughReferenceOfCurrentClass); //bool IsAccessible(IClass callingClass, bool isAccessThoughReferenceOfCurrentClass);
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IEntity))] [ContractClassFor(typeof(IEntity))]
abstract class IEntityContract : INamedElementContract, IEntity abstract class IEntityContract : INamedElementContract, IEntity
{ {
@ -144,4 +147,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IExplicitInterfaceImplementation.cs

@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents an explicit interface implementation. /// Represents an explicit interface implementation.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IExplicitInterfaceImplementationContract))] [ContractClass(typeof(IExplicitInterfaceImplementationContract))]
#endif
public interface IExplicitInterfaceImplementation : IFreezable public interface IExplicitInterfaceImplementation : IFreezable
{ {
/// <summary> /// <summary>
@ -23,6 +25,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
string MemberName { get; } string MemberName { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IExplicitInterfaceImplementation))] [ContractClassFor(typeof(IExplicitInterfaceImplementation))]
abstract class IExplicitInterfaceImplementationContract : IFreezableContract, IExplicitInterfaceImplementation abstract class IExplicitInterfaceImplementationContract : IFreezableContract, IExplicitInterfaceImplementation
{ {
@ -40,4 +43,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IField.cs

@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents a field or constant. /// Represents a field or constant.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IFieldContract))] [ContractClass(typeof(IFieldContract))]
#endif
public interface IField : IMember, IVariable public interface IField : IMember, IVariable
{ {
/// <summary> /// <summary>
@ -28,6 +30,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsVolatile { get; } bool IsVolatile { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IField))] [ContractClassFor(typeof(IField))]
abstract class IFieldContract : IMemberContract, IField abstract class IFieldContract : IMemberContract, IField
{ {
@ -63,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return null; } get { return null; }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IFreezable.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(IFreezableContract))] [ContractClass(typeof(IFreezableContract))]
#endif
public interface IFreezable public interface IFreezable
{ {
/// <summary> /// <summary>
@ -20,6 +22,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
void Freeze(); void Freeze();
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IFreezable))] [ContractClassFor(typeof(IFreezable))]
abstract class IFreezableContract : IFreezable abstract class IFreezableContract : IFreezable
{ {
@ -33,4 +36,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
Contract.Ensures(self.IsFrozen); Contract.Ensures(self.IsFrozen);
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IInterningProvider.cs

@ -25,7 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// and which are used only within a single type definition. Then a persistent file format could be organized so /// and which are used only within a single type definition. Then a persistent file format could be organized so
/// that shared objects are loaded only once, yet non-shared objects get loaded lazily together with the class. /// that shared objects are loaded only once, yet non-shared objects get loaded lazily together with the class.
/// </remarks> /// </remarks>
#if WITH_CONTRACTS
[ContractClass(typeof(IInterningProviderContract))] [ContractClass(typeof(IInterningProviderContract))]
#endif
public interface IInterningProvider public interface IInterningProvider
{ {
/// <summary> /// <summary>
@ -39,6 +41,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IList<T> InternList<T>(IList<T> list) where T : class; IList<T> InternList<T>(IList<T> list) where T : class;
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IInterningProvider))] [ContractClassFor(typeof(IInterningProvider))]
abstract class IInterningProviderContract : IInterningProvider abstract class IInterningProviderContract : IInterningProvider
{ {
@ -54,4 +57,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return list; return list;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IMember.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Method/field/entity. /// Method/field/entity.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IMemberContract))] [ContractClass(typeof(IMemberContract))]
#endif
public interface IMember : IEntity public interface IMember : IEntity
{ {
/// <summary> /// <summary>
@ -58,6 +60,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IMember))] [ContractClassFor(typeof(IMember))]
abstract class IMemberContract : IEntityContract, IMember abstract class IMemberContract : IEntityContract, IMember
{ {
@ -101,4 +104,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return false; } get { return false; }
} }
} }
#endif
} }

11
ICSharpCode.NRefactory/TypeSystem/IMethod.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents a method, constructor, destructor or operator. /// Represents a method, constructor, destructor or operator.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IMethodContract))] [ContractClass(typeof(IMethodContract))]
#endif
public interface IMethod : IParameterizedMember public interface IMethod : IParameterizedMember
{ {
/// <summary> /// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsOperator { get; } bool IsOperator { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IMethod))] [ContractClassFor(typeof(IMethod))]
abstract class IMethodContract : IParameterizedMemberContract, IMethod abstract class IMethodContract : IParameterizedMemberContract, IMethod
{ {
@ -47,13 +50,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
// IList<string> IMethod.HandlesClauses {
// get {
// Contract.Ensures(Contract.Result<IList<string>>() != null);
// return null;
// }
// }
bool IMethod.IsExtensionMethod { bool IMethod.IsExtensionMethod {
get { return false; } get { return false; }
} }
@ -70,4 +66,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return false; } get { return false; }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/INamedElement.cs

@ -6,7 +6,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(INamedElementContract))] [ContractClass(typeof(INamedElementContract))]
#endif
public interface INamedElement public interface INamedElement
{ {
/// <summary> /// <summary>
@ -63,6 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(INamedElement))] [ContractClassFor(typeof(INamedElement))]
abstract class INamedElementContract : INamedElement abstract class INamedElementContract : INamedElement
{ {
@ -94,4 +97,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IParameter.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(IParameterContract))] [ContractClass(typeof(IParameterContract))]
#endif
public interface IParameter : IVariable, IFreezable public interface IParameter : IVariable, IFreezable
{ {
/// <summary> /// <summary>
@ -46,6 +48,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool IsOptional { get; } bool IsOptional { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IParameter))] [ContractClassFor(typeof(IParameter))]
abstract class IParameterContract : IVariableContract, IParameter abstract class IParameterContract : IVariableContract, IParameter
{ {
@ -92,4 +95,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IParameterizedMember.cs

@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents a method or property. /// Represents a method or property.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IParameterizedMemberContract))] [ContractClass(typeof(IParameterizedMemberContract))]
#endif
public interface IParameterizedMember : IMember public interface IParameterizedMember : IMember
{ {
IList<IParameter> Parameters { get; } IList<IParameter> Parameters { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IParameterizedMember))] [ContractClassFor(typeof(IParameterizedMember))]
abstract class IParameterizedMemberContract : IMemberContract, IParameterizedMember abstract class IParameterizedMemberContract : IMemberContract, IParameterizedMember
{ {
@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs

@ -10,12 +10,15 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Mutable container of all classes in an assembly. /// Mutable container of all classes in an assembly.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IProjectContentContract))] [ContractClass(typeof(IProjectContentContract))]
#endif
public interface IProjectContent : ITypeResolveContext public interface IProjectContent : ITypeResolveContext
{ {
IList<IAttribute> AssemblyAttributes { get; } IList<IAttribute> AssemblyAttributes { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IProjectContent))] [ContractClassFor(typeof(IProjectContent))]
abstract class IProjectContentContract : ITypeResolveContextContract, IProjectContent abstract class IProjectContentContract : ITypeResolveContextContract, IProjectContent
{ {
@ -26,4 +29,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs

@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Interface for TypeSystem objects that support interning. /// Interface for TypeSystem objects that support interning.
/// See <see cref="IInterningProvider"/> for more information. /// See <see cref="IInterningProvider"/> for more information.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ISupportsInterningContract))] [ContractClass(typeof(ISupportsInterningContract))]
#endif
public interface ISupportsInterning public interface ISupportsInterning
{ {
/// <summary> /// <summary>
@ -30,6 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool EqualsForInterning(ISupportsInterning other); bool EqualsForInterning(ISupportsInterning other);
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(ISupportsInterning))] [ContractClassFor(typeof(ISupportsInterning))]
abstract class ISupportsInterningContract : ISupportsInterning abstract class ISupportsInterningContract : ISupportsInterning
{ {
@ -48,4 +51,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return false; return false;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IType.cs

@ -7,7 +7,9 @@ using System.Diagnostics.Contracts;
namespace ICSharpCode.NRefactory.TypeSystem namespace ICSharpCode.NRefactory.TypeSystem
{ {
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeContract))] [ContractClass(typeof(ITypeContract))]
#endif
public interface IType : ITypeReference, INamedElement, IEquatable<IType> public interface IType : ITypeReference, INamedElement, IEquatable<IType>
{ {
/// <summary> /// <summary>
@ -90,6 +92,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IEnumerable<IEvent> GetEvents(ITypeResolveContext context, Predicate<IEvent> filter = null); IEnumerable<IEvent> GetEvents(ITypeResolveContext context, Predicate<IEvent> filter = null);
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IType))] [ContractClassFor(typeof(IType))]
abstract class ITypeContract : ITypeReferenceContract, IType abstract class ITypeContract : ITypeReferenceContract, IType
{ {
@ -209,4 +212,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return this; return this;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/ITypeDefinition.cs

@ -10,7 +10,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents a class, enum, interface, struct, delegate or VB module. /// Represents a class, enum, interface, struct, delegate or VB module.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeDefinitionContract))] [ContractClass(typeof(ITypeDefinitionContract))]
#endif
public interface ITypeDefinition : IType, IEntity public interface ITypeDefinition : IType, IEntity
{ {
ClassType ClassType { get; } ClassType ClassType { get; }
@ -44,6 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IEnumerable<IMember> Members { get; } IEnumerable<IMember> Members { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeDefinition))] [ContractClassFor(typeof(ITypeDefinition))]
abstract class ITypeDefinitionContract : ITypeContract, ITypeDefinition abstract class ITypeDefinitionContract : ITypeContract, ITypeDefinition
{ {
@ -181,4 +184,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
#endregion #endregion
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/ITypeParameter.cs

@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Type parameter of a generic class/method. /// Type parameter of a generic class/method.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeParameterContract))] [ContractClass(typeof(ITypeParameterContract))]
#endif
public interface ITypeParameter : IType, IFreezable public interface ITypeParameter : IType, IFreezable
{ {
/// <summary> /// <summary>
@ -99,6 +101,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
Contravariant Contravariant
}; };
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeParameter))] [ContractClassFor(typeof(ITypeParameter))]
abstract class ITypeParameterContract : ITypeContract, ITypeParameter abstract class ITypeParameterContract : ITypeContract, ITypeParameter
{ {
@ -178,4 +181,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/ITypeReference.cs

@ -11,7 +11,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Represents a reference to a type. /// Represents a reference to a type.
/// Must be resolved before it can be used as type. /// Must be resolved before it can be used as type.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeReferenceContract))] [ContractClass(typeof(ITypeReferenceContract))]
#endif
public interface ITypeReference public interface ITypeReference
{ {
// Keep this interface simple: I decided against having GetMethods/GetEvents etc. here, // Keep this interface simple: I decided against having GetMethods/GetEvents etc. here,
@ -26,6 +28,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IType Resolve(ITypeResolveContext context); IType Resolve(ITypeResolveContext context);
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeReference))] [ContractClassFor(typeof(ITypeReference))]
abstract class ITypeReferenceContract : ITypeReference abstract class ITypeReferenceContract : ITypeReference
{ {
@ -36,4 +39,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null; return null;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/ITypeResolveContext.cs

@ -12,7 +12,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Context representing the set of assemblies in which a type is being searched. /// Context representing the set of assemblies in which a type is being searched.
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(ITypeResolveContextContract))] [ContractClass(typeof(ITypeResolveContextContract))]
#endif
public interface ITypeResolveContext public interface ITypeResolveContext
{ {
/// <summary> /// <summary>
@ -91,6 +93,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
CacheManager CacheManager { get; } CacheManager CacheManager { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(ITypeResolveContext))] [ContractClassFor(typeof(ITypeResolveContext))]
abstract class ITypeResolveContextContract : ITypeResolveContext abstract class ITypeResolveContextContract : ITypeResolveContext
{ {
@ -140,4 +143,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
return null; return null;
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/IVariable.cs

@ -9,7 +9,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// <summary> /// <summary>
/// Represents a variable (name/return type pair). /// Represents a variable (name/return type pair).
/// </summary> /// </summary>
#if WITH_CONTRACTS
[ContractClass(typeof(IVariableContract))] [ContractClass(typeof(IVariableContract))]
#endif
public interface IVariable public interface IVariable
{ {
/// <summary> /// <summary>
@ -33,6 +35,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
IConstantValue ConstantValue { get; } IConstantValue ConstantValue { get; }
} }
#if WITH_CONTRACTS
[ContractClassFor(typeof(IVariable))] [ContractClassFor(typeof(IVariable))]
abstract class IVariableContract : IVariable abstract class IVariableContract : IVariable
{ {
@ -62,4 +65,5 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return null; } get { return null; }
} }
} }
#endif
} }

4
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractType.cs

@ -19,9 +19,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
if (string.IsNullOrEmpty(ns)) { if (string.IsNullOrEmpty(ns)) {
return name; return name;
} else { } else {
string combinedName = ns + "." + name; return ns + "." + name;
Contract.Assume(!string.IsNullOrEmpty(combinedName));
return combinedName;
} }
} }
} }

9
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs

@ -53,19 +53,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
base.FreezeInternal(); base.FreezeInternal();
} }
[ContractInvariantMethod]
void ObjectInvariant()
{
Contract.Invariant(type != null);
Contract.Invariant(name != null);
}
public string Name { public string Name {
get { return name; } get { return name; }
set { set {
if (value == null) if (value == null)
throw new ArgumentNullException(); throw new ArgumentNullException();
Contract.EndContractBlock();
CheckBeforeMutation(); CheckBeforeMutation();
name = value; name = value;
} }
@ -76,7 +68,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
set { set {
if (value == null) if (value == null)
throw new ArgumentNullException(); throw new ArgumentNullException();
Contract.EndContractBlock();
CheckBeforeMutation(); CheckBeforeMutation();
type = value; type = value;
} }

23
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultTypeDefinition.cs

@ -60,7 +60,6 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
throw new ArgumentNullException("declaringTypeDefinition"); throw new ArgumentNullException("declaringTypeDefinition");
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
throw new ArgumentException("name"); throw new ArgumentException("name");
Contract.EndContractBlock();
this.projectContent = declaringTypeDefinition.ProjectContent; this.projectContent = declaringTypeDefinition.ProjectContent;
this.declaringTypeDefinition = declaringTypeDefinition; this.declaringTypeDefinition = declaringTypeDefinition;
this.name = name; this.name = name;
@ -73,20 +72,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
throw new ArgumentNullException("projectContent"); throw new ArgumentNullException("projectContent");
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
throw new ArgumentException("name"); throw new ArgumentException("name");
Contract.EndContractBlock();
this.projectContent = projectContent; this.projectContent = projectContent;
this.ns = ns ?? string.Empty; this.ns = ns ?? string.Empty;
this.name = name; this.name = name;
} }
[ContractInvariantMethod]
void ObjectInvariant()
{
Contract.Invariant(projectContent != null);
Contract.Invariant(!string.IsNullOrEmpty(name));
Contract.Invariant(ns != null);
}
public ClassType ClassType { public ClassType ClassType {
get { return classType; } get { return classType; }
set { set {
@ -164,7 +154,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public IEnumerable<IMember> Members { public IEnumerable<IMember> Members {
get { get {
return this.Fields.Concat<IMember>(this.Properties).Concat(this.Methods).Concat(this.Events); return this.Fields.SafeCast<IField, IMember>()
.Concat(this.Properties.SafeCast<IProperty, IMember>())
.Concat(this.Methods.SafeCast<IMethod, IMember>())
.Concat(this.Events.SafeCast<IEvent, IMember>());
} }
} }
@ -187,15 +180,11 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public string FullName { public string FullName {
get { get {
if (declaringTypeDefinition != null) { if (declaringTypeDefinition != null) {
string combinedName = declaringTypeDefinition.FullName + "." + this.name; return declaringTypeDefinition.FullName + "." + this.name;
Contract.Assume(!string.IsNullOrEmpty(combinedName));
return combinedName;
} else if (string.IsNullOrEmpty(ns)) { } else if (string.IsNullOrEmpty(ns)) {
return this.name; return this.name;
} else { } else {
string combinedName = this.ns + "." + this.name; return this.ns + "." + this.name;
Contract.Assume(!string.IsNullOrEmpty(combinedName));
return combinedName;
} }
} }
} }

24
ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleInterningProvider.cs

@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt) // This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
@ -51,16 +52,27 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
} }
} }
sealed class ListComparer : IEqualityComparer<IEnumerable<object>> sealed class ListComparer : IEqualityComparer<IEnumerable>
{ {
public bool Equals(IEnumerable<object> a, IEnumerable<object> b) public bool Equals(IEnumerable a, IEnumerable b)
{ {
if (a.GetType() != b.GetType()) if (a.GetType() != b.GetType())
return false; return false;
return Enumerable.SequenceEqual(a, b, ReferenceComparer.Instance); IEnumerator e1 = a.GetEnumerator();
IEnumerator e2 = b.GetEnumerator();
while (e1.MoveNext()) {
// e1 has more elements than e2; or elements are different
if (!e2.MoveNext() || e1.Current != e2.Current)
return false;
}
if (e2.MoveNext()) // e2 has more elements than e1
return false;
// No need to dispose e1/e2: non-generic IEnumerator doesn't implement IDisposable,
// and the underlying enumerator will likely be a List<T>.Enumerator which has an empty Dispose() method.
return true;
} }
public int GetHashCode(IEnumerable<object> obj) public int GetHashCode(IEnumerable obj)
{ {
int hashCode = obj.GetType().GetHashCode(); int hashCode = obj.GetType().GetHashCode();
unchecked { unchecked {
@ -75,7 +87,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
Dictionary<object, object> byValueDict = new Dictionary<object, object>(); Dictionary<object, object> byValueDict = new Dictionary<object, object>();
Dictionary<ISupportsInterning, ISupportsInterning> supportsInternDict = new Dictionary<ISupportsInterning, ISupportsInterning>(new InterningComparer()); Dictionary<ISupportsInterning, ISupportsInterning> supportsInternDict = new Dictionary<ISupportsInterning, ISupportsInterning>(new InterningComparer());
Dictionary<IEnumerable<object>, IEnumerable<object>> listDict = new Dictionary<IEnumerable<object>, IEnumerable<object>>(new ListComparer()); Dictionary<IEnumerable, IEnumerable> listDict = new Dictionary<IEnumerable, IEnumerable>(new ListComparer());
public T Intern<T>(T obj) where T : class public T Intern<T>(T obj) where T : class
{ {
@ -118,7 +130,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
} }
if (!list.IsReadOnly) if (!list.IsReadOnly)
list = new ReadOnlyCollection<T>(list); list = new ReadOnlyCollection<T>(list);
IEnumerable<object> output; IEnumerable output;
if (listDict.TryGetValue(list, out output)) if (listDict.TryGetValue(list, out output))
list = (IList<T>)output; list = (IList<T>)output;
else else

58
ICSharpCode.NRefactory/Utils/DotNet35Compat.cs

@ -0,0 +1,58 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
internal static class DotNet35Compat
{
public static string StringJoin<T>(string separator, IEnumerable<T> elements)
{
#if DOTNET35
return string.Join(separator, elements.Select(e => e != null ? e.ToString() : null).ToArray());
#else
return string.Join(separator, elements);
#endif
}
public static IEnumerable<U> SafeCast<T, U>(this IEnumerable<T> elements) where T : U
{
#if DOTNET35
foreach (T item in elements)
yield return item;
#else
return elements;
#endif
}
public static Predicate<U> SafeCast<T, U>(this Predicate<T> predicate) where U : T
{
#if DOTNET35
return e => predicate(e);
#else
return predicate;
#endif
}
#if DOTNET35
public static IEnumerable<R> Zip<T1, T2, R>(this IEnumerable<T1> input1, IEnumerable<T2> input2, Func<T1, T2, R> f)
{
using (var e1 = input1.GetEnumerator())
using (var e2 = input2.GetEnumerator())
while (e1.MoveNext() && e2.MoveNext())
yield return f(e1.Current, e2.Current);
}
#endif
}
#if DOTNET35
namespace System.Diagnostics.Contracts { }
namespace System.Threading
{
internal struct CancellationToken
{
public void ThrowIfCancellationRequested() {}
}
}
#endif

8
NRefactory.sln

@ -71,13 +71,13 @@ Global
{870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.Build.0 = Release|Any CPU {870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.Build.0 = Release|Any CPU
{870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.ActiveCfg = Release|Any CPU {870115DD-960A-4406-A6B9-600BCDC36A03}.Release|x86.ActiveCfg = Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.Build.0 = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.Build.0 = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.ActiveCfg = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|x86.ActiveCfg = net_3_5_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.ActiveCfg = net_3_5_Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.Build.0 = net_4_0_Debug|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.Build.0 = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.ActiveCfg = net_4_0_Release|Any CPU {D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|x86.ActiveCfg = net_3_5_Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj StartupItem = ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj

1
VBDomGenerator/VBDomGenerator.csproj

@ -19,6 +19,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>

Loading…
Cancel
Save