Skip to content

Commit

Permalink
Merge changes from SharpDevelop repository to NRefactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed May 8, 2013
1 parent 17c4315 commit 17c1eea
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin
obj
*.suo
/lib/*.dll
/ICSharpCode.NRefactory.Tests/PartCover/*
_ReSharper*/*
5 changes: 5 additions & 0 deletions ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpAmbience.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ public void ConvertType(IType type, IOutputFormatter formatter, CSharpFormatting
astType.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
}

public string ConvertConstantValue(object constantValue)
{
return CSharpOutputVisitor.PrintPrimitiveValue(constantValue);
}

public string WrapComment(string comment)
{
return "// " + comment;
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.NRefactory.CSharp/Resolver/MemberLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public bool IsProtectedAccessAllowed(IType targetType)
/// <param name="allowProtectedAccess">
/// Whether protected access to instance members is allowed.
/// 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>
public bool IsAccessible(IEntity entity, bool allowProtectedAccess)
{
Expand Down
1 change: 1 addition & 0 deletions ICSharpCode.NRefactory/TypeSystem/IAmbience.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public interface IAmbience
string ConvertEntity(IEntity entity);
string ConvertType(IType type);
string ConvertVariable(IVariable variable);
string ConvertConstantValue(object constantValue);

string WrapComment(string comment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ public KnownTypeCode KnownTypeCode {
KnownTypeCode result = this.knownTypeCode;
if (result == (KnownTypeCode)(-1)) {
result = KnownTypeCode.None;
ICompilation compilation = this.Compilation;
for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) {
KnownTypeReference r = KnownTypeReference.Get((KnownTypeCode)i);
if (r != null && r.Resolve(parentContext) == this) {
if (compilation.FindType((KnownTypeCode)i) == this) {
result = (KnownTypeCode)i;
break;
}
Expand Down
129 changes: 128 additions & 1 deletion ICSharpCode.NRefactory/TypeSystem/TypeSystemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,27 @@ public static IEnumerable<ITypeDefinition> GetAllBaseTypeDefinitions(this IType
/// </summary>
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) {
throw new InvalidOperationException("Both arguments to IsDerivedFrom() must be from the same compilation.");
}
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

#region IsOpen / IsUnbound / IsKnownType
Expand Down Expand Up @@ -535,7 +551,118 @@ public static IType Resolve (this ITypeReference reference, ICompilation compila
return reference.Resolve (compilation.TypeResolveContext);
}
#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)
/// <summary>
Expand Down
Binary file removed NRefactory.suo
Binary file not shown.

0 comments on commit 17c1eea

Please sign in to comment.