Browse Source

Merge changes from SharpDevelop repository to NRefactory.

pull/32/merge
Daniel Grunwald 12 years ago
parent
commit
17c1eeaf2b
  1. 1
      .gitignore
  2. 5
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
  3. 2
      ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
  4. 1
      ICSharpCode.NRefactory/TypeSystem/IAmbience.cs
  5. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs
  6. 127
      ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs
  7. BIN
      NRefactory.suo

1
.gitignore vendored

@ -1,5 +1,6 @@
bin bin
obj obj
*.suo
/lib/*.dll /lib/*.dll
/ICSharpCode.NRefactory.Tests/PartCover/* /ICSharpCode.NRefactory.Tests/PartCover/*
_ReSharper*/* _ReSharper*/*

5
ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs

@ -267,6 +267,11 @@ namespace ICSharpCode.NRefactory.CSharp
astType.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy)); astType.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
} }
public string ConvertConstantValue(object constantValue)
{
return CSharpOutputVisitor.PrintPrimitiveValue(constantValue);
}
public string WrapComment(string comment) public string WrapComment(string comment)
{ {
return "// " + comment; return "// " + comment;

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

@ -83,7 +83,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
/// <param name="allowProtectedAccess"> /// <param name="allowProtectedAccess">
/// Whether protected access to instance members is allowed. /// Whether protected access to instance members is allowed.
/// True if the type of the reference is derived from the current class. /// True if the type of the reference is derived from the current class.
/// Protected static members may be accessibe even if false is passed for this parameter. /// Protected static members may be accessible even if false is passed for this parameter.
/// </param> /// </param>
public bool IsAccessible(IEntity entity, bool allowProtectedAccess) public bool IsAccessible(IEntity entity, bool allowProtectedAccess)
{ {

1
ICSharpCode.NRefactory/TypeSystem/IAmbience.cs

@ -89,6 +89,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
string ConvertEntity(IEntity entity); string ConvertEntity(IEntity entity);
string ConvertType(IType type); string ConvertType(IType type);
string ConvertVariable(IVariable variable); string ConvertVariable(IVariable variable);
string ConvertConstantValue(object constantValue);
string WrapComment(string comment); string WrapComment(string comment);
} }

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

@ -395,9 +395,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
KnownTypeCode result = this.knownTypeCode; KnownTypeCode result = this.knownTypeCode;
if (result == (KnownTypeCode)(-1)) { if (result == (KnownTypeCode)(-1)) {
result = KnownTypeCode.None; result = KnownTypeCode.None;
ICompilation compilation = this.Compilation;
for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) { for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) {
KnownTypeReference r = KnownTypeReference.Get((KnownTypeCode)i); if (compilation.FindType((KnownTypeCode)i) == this) {
if (r != null && r.Resolve(parentContext) == this) {
result = (KnownTypeCode)i; result = (KnownTypeCode)i;
break; break;
} }

127
ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs

@ -85,11 +85,27 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary> /// </summary>
public static bool IsDerivedFrom(this ITypeDefinition type, ITypeDefinition baseType) public static bool IsDerivedFrom(this ITypeDefinition type, ITypeDefinition baseType)
{ {
if (type == null)
throw new ArgumentNullException("type");
if (baseType == null)
return false;
if (type.Compilation != baseType.Compilation) { if (type.Compilation != baseType.Compilation) {
throw new InvalidOperationException("Both arguments to IsDerivedFrom() must be from the same compilation."); throw new InvalidOperationException("Both arguments to IsDerivedFrom() must be from the same compilation.");
} }
return type.GetAllBaseTypeDefinitions().Contains(baseType); return type.GetAllBaseTypeDefinitions().Contains(baseType);
} }
/// <summary>
/// Gets whether this type definition is derived from a given known type.
/// </summary>
public static bool IsDerivedFrom(this ITypeDefinition type, KnownTypeCode baseType)
{
if (type == null)
throw new ArgumentNullException("type");
if (baseType == KnownTypeCode.None)
return false;
return IsDerivedFrom(type, type.Compilation.FindType(baseType).GetDefinition());
}
#endregion #endregion
#region IsOpen / IsUnbound / IsKnownType #region IsOpen / IsUnbound / IsKnownType
@ -536,6 +552,117 @@ namespace ICSharpCode.NRefactory.TypeSystem
} }
#endregion #endregion
#region ITypeDefinition.GetAttribute
/// <summary>
/// Gets the attribute of the specified attribute type (or derived attribute types).
/// </summary>
/// <param name="entity">The entity on which the attributes are declared.</param>
/// <param name="attributeType">The attribute type to look for.</param>
/// <param name="inherit">
/// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
/// should be returned. The default is <c>true</c>.
/// </param>
/// <returns>
/// Returns the attribute that was found; or <c>null</c> if none was found.
/// If inherit is true, an from the entity itself will be returned if possible;
/// and the base entity will only be searched if none exists.
/// </returns>
public static IAttribute GetAttribute(this IEntity entity, IType attributeType, bool inherit = true)
{
return GetAttributes(entity, attributeType, inherit).FirstOrDefault();
}
/// <summary>
/// Gets the attributes of the specified attribute type (or derived attribute types).
/// </summary>
/// <param name="entity">The entity on which the attributes are declared.</param>
/// <param name="attributeType">The attribute type to look for.</param>
/// <param name="inherit">
/// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
/// should be returned. The default is <c>true</c>.
/// </param>
/// <returns>
/// Returns the list of attributes that were found.
/// If inherit is true, attributes from the entity itself are returned first; followed by attributes inherited from the base entity.
/// </returns>
public static IEnumerable<IAttribute> GetAttributes(this IEntity entity, IType attributeType, bool inherit = true)
{
if (entity == null)
throw new ArgumentNullException("entity");
if (attributeType == null)
throw new ArgumentNullException("attributeType");
return GetAttributes(entity, attributeType.Equals, inherit);
}
/// <summary>
/// Gets the attribute of the specified attribute type (or derived attribute types).
/// </summary>
/// <param name="entity">The entity on which the attributes are declared.</param>
/// <param name="attributeType">The attribute type to look for.</param>
/// <param name="inherit">
/// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
/// should be returned. The default is <c>true</c>.
/// </param>
/// <returns>
/// Returns the attribute that was found; or <c>null</c> if none was found.
/// If inherit is true, an from the entity itself will be returned if possible;
/// and the base entity will only be searched if none exists.
/// </returns>
public static IAttribute GetAttribute(this IEntity entity, FullTypeName attributeType, bool inherit = true)
{
return GetAttributes(entity, attributeType, inherit).FirstOrDefault();
}
/// <summary>
/// Gets the attributes of the specified attribute type (or derived attribute types).
/// </summary>
/// <param name="entity">The entity on which the attributes are declared.</param>
/// <param name="attributeType">The attribute type to look for.</param>
/// <param name="inherit">
/// Specifies whether attributes inherited from base classes and base members (if the given <paramref name="entity"/> in an <c>override</c>)
/// should be returned. The default is <c>true</c>.
/// </param>
/// <returns>
/// Returns the list of attributes that were found.
/// If inherit is true, attributes from the entity itself are returned first; followed by attributes inherited from the base entity.
/// </returns>
public static IEnumerable<IAttribute> GetAttributes(this IEntity entity, FullTypeName attributeType, bool inherit = true)
{
if (entity == null)
throw new ArgumentNullException("entity");
return GetAttributes(entity, attrType => {
ITypeDefinition typeDef = attrType.GetDefinition();
return typeDef != null && typeDef.FullTypeName == attributeType;
}, inherit);
}
static IEnumerable<IAttribute> GetAttributes(IEntity entity, Predicate<IType> attributeTypePredicate, bool inherit)
{
if (!inherit) {
foreach (var attr in entity.Attributes) {
if (attributeTypePredicate(attr.AttributeType))
yield return attr;
}
yield break;
}
ITypeDefinition typeDef = entity as ITypeDefinition;
if (typeDef != null) {
foreach (var baseType in typeDef.GetNonInterfaceBaseTypes().Reverse()) {
ITypeDefinition baseTypeDef = baseType.GetDefinition();
if (baseTypeDef == null)
continue;
foreach (var attr in baseTypeDef.Attributes) {
if (attributeTypePredicate(attr.AttributeType))
yield return attr;
}
}
}
IMember member = entity as IMember;
if (member != null)
throw new NotImplementedException();
throw new NotSupportedException("Unknown entity type");
}
#endregion
#region IAssembly.GetTypeDefinition(string,string,int) #region IAssembly.GetTypeDefinition(string,string,int)
/// <summary> /// <summary>

BIN
NRefactory.suo

Binary file not shown.
Loading…
Cancel
Save