Browse Source

Remove IAccessor and use IMethod instead.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
06f96bf068
  1. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs
  2. 9
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
  3. 58
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  4. 3
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  5. 38
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  6. 67
      ICSharpCode.NRefactory/TypeSystem/IAccessor.cs
  7. 12
      ICSharpCode.NRefactory/TypeSystem/IEvent.cs
  8. 8
      ICSharpCode.NRefactory/TypeSystem/IProperty.cs
  9. 16
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs
  10. 81
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedAccessor.cs
  11. 48
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedEvent.cs
  12. 32
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedProperty.cs
  13. 157
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAccessor.cs
  14. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedEvent.cs
  15. 6
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedProperty.cs
  16. 12
      ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedEvent.cs
  17. 10
      ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMember.cs
  18. 8
      ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedProperty.cs

2
ICSharpCode.NRefactory.CSharp/Refactoring/TypeSystemAstBuilder.cs

@ -518,7 +518,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -518,7 +518,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return decl;
}
Accessor ConvertAccessor(IAccessor accessor)
Accessor ConvertAccessor(IMethod accessor)
{
if (accessor == null)
return Accessor.Null;

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

@ -916,11 +916,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -916,11 +916,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
Expression resolveExpr;
var name = GetAnonymousTypePropertyName(expr, out resolveExpr);
if (!string.IsNullOrEmpty(name)) {
var returnType = new VarTypeReference(this, resolver, resolveExpr);
var property = new DefaultUnresolvedProperty {
Name = name,
Accessibility = Accessibility.Public,
ReturnType = new VarTypeReference(this, resolver, resolveExpr),
Getter = DefaultUnresolvedAccessor.GetFromAccessibility(Accessibility.Public)
ReturnType = returnType,
Getter = new DefaultUnresolvedMethod {
Name = "get_" + name,
Accessibility = Accessibility.Public,
ReturnType = returnType
}
};
properties.Add(property);
}

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

@ -600,8 +600,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -600,8 +600,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
p.InterfaceImplementations.Add(new DefaultMemberReference(
p.EntityType, ConvertType(propertyDeclaration.PrivateImplementationType), p.Name));
}
p.Getter = ConvertAccessor(propertyDeclaration.Getter, p.Accessibility);
p.Setter = ConvertAccessor(propertyDeclaration.Setter, p.Accessibility);
p.Getter = ConvertAccessor(propertyDeclaration.Getter, p, "get_");
p.Setter = ConvertAccessor(propertyDeclaration.Setter, p, "set_");
currentTypeDefinition.Members.Add(p);
if (interningProvider != null) {
p.ApplyInterningProvider(interningProvider);
@ -619,8 +619,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -619,8 +619,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
p.ReturnType = ConvertType(indexerDeclaration.ReturnType);
ConvertAttributes(p.Attributes, indexerDeclaration.Attributes);
p.Getter = ConvertAccessor(indexerDeclaration.Getter, p.Accessibility);
p.Setter = ConvertAccessor(indexerDeclaration.Setter, p.Accessibility);
p.Getter = ConvertAccessor(indexerDeclaration.Getter, p, "get_");
p.Setter = ConvertAccessor(indexerDeclaration.Setter, p, "set_");
ConvertParameters(p.Parameters, indexerDeclaration.Parameters);
if (!indexerDeclaration.PrivateImplementationType.IsNull) {
@ -636,17 +636,27 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -636,17 +636,27 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
return p;
}
IUnresolvedAccessor ConvertAccessor(Accessor accessor, Accessibility defaultAccessibility)
DefaultUnresolvedMethod ConvertAccessor(Accessor accessor, IUnresolvedMember p, string prefix)
{
if (accessor.IsNull)
return null;
DefaultUnresolvedAccessor a = new DefaultUnresolvedAccessor();
a.Accessibility = GetAccessibility(accessor.Modifiers) ?? defaultAccessibility;
var a = new DefaultUnresolvedMethod(currentTypeDefinition, prefix + p.Name);
a.Accessibility = GetAccessibility(accessor.Modifiers) ?? p.Accessibility;
a.Region = MakeRegion(accessor);
DefaultUnresolvedParameter param = null;
if (accessor.Role == PropertyDeclaration.GetterRole) {
a.ReturnType = p.ReturnType;
} else {
param = new DefaultUnresolvedParameter(p.ReturnType, "value");
a.Parameters.Add(param);
a.ReturnType = KnownTypeReference.Void;
}
foreach (AttributeSection section in accessor.Attributes) {
if (section.AttributeTarget == "return") {
ConvertAttributes(a.ReturnTypeAttributes, section);
} else if (section.AttributeTarget != "param") {
} else if (param != null && section.AttributeTarget == "param") {
ConvertAttributes(param.Attributes, section);
} else {
ConvertAttributes(a.Attributes, section);
}
}
@ -670,16 +680,17 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -670,16 +680,17 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
ev.ReturnType = ConvertType(eventDeclaration.ReturnType);
if (eventDeclaration.Attributes.Any(a => a.AttributeTarget == "method")) {
ev.AddAccessor = ev.RemoveAccessor = new DefaultUnresolvedAccessor { Accessibility = ev.Accessibility };
} else {
// if there's no attributes on the accessors, we can re-use the shared accessor instance
ev.AddAccessor = ev.RemoveAccessor = DefaultUnresolvedAccessor.GetFromAccessibility(ev.Accessibility);
}
var valueParameter = new DefaultUnresolvedParameter(ev.ReturnType, "value");
ev.AddAccessor = CreateDefaultEventAccessor(ev, "get_" + ev.Name, valueParameter);
ev.RemoveAccessor = CreateDefaultEventAccessor(ev, "set_" + ev.Name, valueParameter);
foreach (AttributeSection section in eventDeclaration.Attributes) {
if (section.AttributeTarget == "method") {
// as we use the same instance for AddAccessor and RemoveAccessor, we only need to add the attribute once
ConvertAttributes(ev.AddAccessor.Attributes, section);
foreach (var attrNode in section.Attributes) {
IUnresolvedAttribute attr = ConvertAttribute(attrNode);
ev.AddAccessor.Attributes.Add(attr);
ev.RemoveAccessor.Attributes.Add(attr);
}
} else if (section.AttributeTarget != "field") {
ConvertAttributes(ev.Attributes, section);
}
@ -693,6 +704,17 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -693,6 +704,17 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
return isSingleEvent ? ev : null;
}
DefaultUnresolvedMethod CreateDefaultEventAccessor(IUnresolvedEvent ev, string name, IUnresolvedParameter valueParameter)
{
var a = new DefaultUnresolvedMethod(currentTypeDefinition, name);
a.Region = ev.BodyRegion;
a.BodyRegion = ev.BodyRegion;
a.Accessibility = ev.Accessibility;
a.ReturnType = KnownTypeReference.Void;
a.Parameters.Add(valueParameter);
return a;
}
public override IUnresolvedEntity VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration, object data)
{
DefaultUnresolvedEvent e = new DefaultUnresolvedEvent(currentTypeDefinition, eventDeclaration.Name);
@ -708,8 +730,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -708,8 +730,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
e.EntityType, ConvertType(eventDeclaration.PrivateImplementationType), e.Name));
}
e.AddAccessor = ConvertAccessor(eventDeclaration.AddAccessor, e.Accessibility);
e.RemoveAccessor = ConvertAccessor(eventDeclaration.RemoveAccessor, e.Accessibility);
e.AddAccessor = ConvertAccessor(eventDeclaration.AddAccessor, e, "add_");
e.RemoveAccessor = ConvertAccessor(eventDeclaration.RemoveAccessor, e, "remove_");
currentTypeDefinition.Members.Add(e);
if (interningProvider != null) {

3
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -109,7 +109,6 @@ @@ -109,7 +109,6 @@
<Compile Include="TypeSystem\DomRegion.cs" />
<Compile Include="TypeSystem\EntityType.cs" />
<Compile Include="TypeSystem\ExtensionMethods.cs" />
<Compile Include="TypeSystem\IAccessor.cs" />
<Compile Include="TypeSystem\IAmbience.cs" />
<Compile Include="TypeSystem\IAssembly.cs" />
<Compile Include="TypeSystem\IAttribute.cs" />
@ -134,7 +133,6 @@ @@ -134,7 +133,6 @@
<Compile Include="TypeSystem\Implementation\DefaultAssemblyReference.cs" />
<Compile Include="TypeSystem\Implementation\DefaultMemberReference.cs" />
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DefaultResolvedAccessor.cs" />
<Compile Include="TypeSystem\Implementation\DefaultResolvedEvent.cs" />
<Compile Include="TypeSystem\Implementation\DefaultResolvedField.cs" />
<Compile Include="TypeSystem\Implementation\DefaultResolvedMethod.cs" />
@ -142,7 +140,6 @@ @@ -142,7 +140,6 @@
<Compile Include="TypeSystem\Implementation\DefaultResolvedTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\DefaultResolvedTypeParameter.cs" />
<Compile Include="TypeSystem\Implementation\DefaultSolutionSnapshot.cs" />
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedAccessor.cs" />
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedAssembly.cs" />
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedAttribute.cs" />
<Compile Include="TypeSystem\Implementation\DefaultUnresolvedEvent.cs" />

38
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -1584,15 +1584,13 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1584,15 +1584,13 @@ namespace ICSharpCode.NRefactory.TypeSystem
td.AddDefaultConstructorIfRequired = (td.Kind == TypeKind.Struct || td.Kind == TypeKind.Enum);
if (typeDefinition.HasMethods) {
foreach (MethodDefinition method in typeDefinition.Methods) {
if (IsVisible(method.Attributes)) {
if (IsVisible(method.Attributes) && !IsAccessor(method.SemanticsAttributes)) {
EntityType type = EntityType.Method;
if (method.IsSpecialName) {
if (method.IsConstructor)
type = EntityType.Constructor;
else if (method.Name.StartsWith("op_", StringComparison.Ordinal))
type = EntityType.Operator;
else
continue;
}
td.Members.Add(ReadMethod(method, td, type));
}
@ -1629,12 +1627,19 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1629,12 +1627,19 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
}
static bool IsAccessor(MethodSemanticsAttributes semantics)
{
return !(semantics == MethodSemanticsAttributes.None || semantics == MethodSemanticsAttributes.Other);
}
#endregion
#region Read Method
[CLSCompliant(false)]
public IUnresolvedMethod ReadMethod(MethodDefinition method, IUnresolvedTypeDefinition parentType, EntityType methodType = EntityType.Method)
{
if (method == null)
return null;
DefaultUnresolvedMethod m = new DefaultUnresolvedMethod(parentType, method.Name);
m.EntityType = methodType;
if (method.HasGenericParameters) {
@ -1862,8 +1867,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1862,8 +1867,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
TranslateModifiers(property.GetMethod ?? property.SetMethod, p);
p.ReturnType = ReadTypeReference(property.PropertyType, typeAttributes: property);
p.Getter = ReadAccessor(property.GetMethod);
p.Setter = ReadAccessor(property.SetMethod);
p.Getter = ReadMethod(property.GetMethod, parentType);
p.Setter = ReadMethod(property.SetMethod, parentType);
if (property.HasParameters) {
foreach (ParameterDefinition par in property.Parameters) {
@ -1875,23 +1880,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1875,23 +1880,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
FinishReadMember(p, property);
return p;
}
IUnresolvedAccessor ReadAccessor(MethodDefinition accessorMethod)
{
if (accessorMethod != null && IsVisible(accessorMethod.Attributes)) {
Accessibility accessibility = GetAccessibility(accessorMethod.Attributes);
if (HasAnyAttributes(accessorMethod)) {
DefaultUnresolvedAccessor a = new DefaultUnresolvedAccessor();
a.Accessibility = accessibility;
AddAttributes(accessorMethod, a.Attributes, a.ReturnTypeAttributes);
return a;
} else {
return DefaultUnresolvedAccessor.GetFromAccessibility(accessibility);
}
} else {
return null;
}
}
#endregion
#region Read Event
@ -1907,9 +1895,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -1907,9 +1895,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
TranslateModifiers(ev.AddMethod, e);
e.ReturnType = ReadTypeReference(ev.EventType, typeAttributes: ev);
e.AddAccessor = ReadAccessor(ev.AddMethod);
e.RemoveAccessor = ReadAccessor(ev.RemoveMethod);
e.InvokeAccessor = ReadAccessor(ev.InvokeMethod);
e.AddAccessor = ReadMethod(ev.AddMethod, parentType);
e.RemoveAccessor = ReadMethod(ev.RemoveMethod, parentType);
e.InvokeAccessor = ReadMethod(ev.InvokeMethod, parentType);
AddAttributes(ev, e);

67
ICSharpCode.NRefactory/TypeSystem/IAccessor.cs

@ -1,67 +0,0 @@ @@ -1,67 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Represents an accessor (property getter/setter; or event add/remove/invoke).
/// </summary>
public interface IUnresolvedAccessor : IHasAccessibility
{
/// <summary>
/// Gets the accessor region.
/// </summary>
DomRegion Region { get; }
/// <summary>
/// Gets the attributes defined on this accessor.
/// </summary>
IList<IUnresolvedAttribute> Attributes { get; }
/// <summary>
/// Gets the attributes defined on the return type of the accessor. (e.g. [return: MarshalAs(...)])
/// </summary>
IList<IUnresolvedAttribute> ReturnTypeAttributes { get; }
IAccessor CreateResolvedAccessor(ITypeResolveContext context);
}
/// <summary>
/// Represents an accessor (property getter/setter; or event add/remove/invoke).
/// </summary>
public interface IAccessor : IHasAccessibility
{
/// <summary>
/// Gets the accessor region.
/// </summary>
DomRegion Region { get; }
/// <summary>
/// Gets the attributes defined on this accessor.
/// </summary>
IList<IAttribute> Attributes { get; }
/// <summary>
/// Gets the attributes defined on the return type of the accessor. (e.g. [return: MarshalAs(...)])
/// </summary>
IList<IAttribute> ReturnTypeAttributes { get; }
}
}

12
ICSharpCode.NRefactory/TypeSystem/IEvent.cs

@ -28,9 +28,9 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -28,9 +28,9 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool CanRemove { get; }
bool CanInvoke { get; }
IUnresolvedAccessor AddAccessor { get; }
IUnresolvedAccessor RemoveAccessor { get; }
IUnresolvedAccessor InvokeAccessor { get; }
IUnresolvedMethod AddAccessor { get; }
IUnresolvedMethod RemoveAccessor { get; }
IUnresolvedMethod InvokeAccessor { get; }
}
public interface IEvent : IMember
@ -39,8 +39,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -39,8 +39,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool CanRemove { get; }
bool CanInvoke { get; }
IAccessor AddAccessor { get; }
IAccessor RemoveAccessor { get; }
IAccessor InvokeAccessor { get; }
IMethod AddAccessor { get; }
IMethod RemoveAccessor { get; }
IMethod InvokeAccessor { get; }
}
}

8
ICSharpCode.NRefactory/TypeSystem/IProperty.cs

@ -28,8 +28,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -28,8 +28,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool CanGet { get; }
bool CanSet { get; }
IUnresolvedAccessor Getter { get; }
IUnresolvedAccessor Setter { get; }
IUnresolvedMethod Getter { get; }
IUnresolvedMethod Setter { get; }
bool IsIndexer { get; }
}
@ -42,8 +42,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -42,8 +42,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
bool CanGet { get; }
bool CanSet { get; }
IAccessor Getter { get; }
IAccessor Setter { get; }
IMethod Getter { get; }
IMethod Setter { get; }
bool IsIndexer { get; }
}

16
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedMember.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
@ -51,7 +52,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -51,7 +52,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolved; }
}
public IList<IMember> InterfaceImplementations {
IList<IMember> IMember.InterfaceImplementations {
get {
throw new NotImplementedException();
}
@ -77,5 +78,18 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -77,5 +78,18 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
return new DefaultMemberReference(this.EntityType, this.DeclaringType.ToTypeReference(), this.Name);
}
internal IMethod GetAccessor(ref IMethod accessorField, IUnresolvedMethod unresolvedAccessor)
{
if (unresolvedAccessor == null)
return null;
IMethod result = accessorField;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref accessorField, (IMethod)unresolvedAccessor.CreateResolved(context));
}
}
}
}

81
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedAccessor.cs

@ -1,81 +0,0 @@ @@ -1,81 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
public sealed class DefaultResolvedAccessor : IAccessor
{
readonly Accessibility accessibility;
readonly DomRegion region;
readonly IList<IAttribute> attributes;
readonly IList<IAttribute> returnTypeAttributes;
public DefaultResolvedAccessor(Accessibility accessibility, DomRegion region = default(DomRegion), IList<IAttribute> attributes = null, IList<IAttribute> returnTypeAttributes = null)
{
this.accessibility = accessibility;
this.region = region;
this.attributes = attributes ?? EmptyList<IAttribute>.Instance;
this.returnTypeAttributes = returnTypeAttributes ?? EmptyList<IAttribute>.Instance;
}
public DomRegion Region {
get { return region; }
}
public IList<IAttribute> Attributes {
get { return attributes; }
}
public IList<IAttribute> ReturnTypeAttributes {
get { return returnTypeAttributes; }
}
public Accessibility Accessibility {
get { return accessibility; }
}
public bool IsPrivate {
get { return accessibility == Accessibility.Private; }
}
public bool IsPublic {
get { return accessibility == Accessibility.Public; }
}
public bool IsProtected {
get { return accessibility == Accessibility.Protected; }
}
public bool IsInternal {
get { return accessibility == Accessibility.Internal; }
}
public bool IsProtectedOrInternal {
get { return accessibility == Accessibility.ProtectedOrInternal; }
}
public bool IsProtectedAndInternal {
get { return accessibility == Accessibility.ProtectedAndInternal; }
}
}
}

48
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedEvent.cs

@ -25,9 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -25,9 +25,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public class DefaultResolvedEvent : AbstractResolvedMember, IEvent
{
protected new readonly IUnresolvedEvent unresolved;
IAccessor addAccessor;
IAccessor removeAccessor;
IAccessor invokeAccessor;
IMethod addAccessor;
IMethod removeAccessor;
IMethod invokeAccessor;
public DefaultResolvedEvent(IUnresolvedEvent unresolved, ITypeResolveContext parentContext)
: base(unresolved, parentContext)
@ -47,46 +47,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -47,46 +47,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolved.CanInvoke; }
}
public IAccessor AddAccessor {
get {
if (!unresolved.CanAdd)
return null;
IAccessor result = this.addAccessor;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref this.addAccessor, unresolved.AddAccessor.CreateResolvedAccessor(context));
}
}
public IMethod AddAccessor {
get { return GetAccessor(ref addAccessor, unresolved.AddAccessor); }
}
public IAccessor RemoveAccessor {
get {
if (!unresolved.CanRemove)
return null;
IAccessor result = this.removeAccessor;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref this.removeAccessor, unresolved.RemoveAccessor.CreateResolvedAccessor(context));
}
}
public IMethod RemoveAccessor {
get { return GetAccessor(ref removeAccessor, unresolved.RemoveAccessor); }
}
public IAccessor InvokeAccessor {
get {
if (!unresolved.CanInvoke)
return null;
IAccessor result = this.invokeAccessor;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref this.invokeAccessor, unresolved.InvokeAccessor.CreateResolvedAccessor(context));
}
}
public IMethod InvokeAccessor {
get { return GetAccessor(ref invokeAccessor, unresolved.InvokeAccessor); }
}
}
}

32
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedProperty.cs

@ -27,8 +27,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,8 +27,8 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
protected new readonly IUnresolvedProperty unresolved;
readonly IList<IParameter> parameters;
IAccessor getter;
IAccessor setter;
IMethod getter;
IMethod setter;
public DefaultResolvedProperty(IUnresolvedProperty unresolved, ITypeResolveContext parentContext)
: base(unresolved, parentContext)
@ -49,32 +49,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -49,32 +49,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolved.CanSet; }
}
public IAccessor Getter {
get {
if (!unresolved.CanGet)
return null;
IAccessor result = this.getter;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref this.getter, unresolved.Getter.CreateResolvedAccessor(context));
}
}
public IMethod Getter {
get { return GetAccessor(ref getter, unresolved.Getter); }
}
public IAccessor Setter {
get {
if (!unresolved.CanSet)
return null;
IAccessor result = this.setter;
if (result != null) {
LazyInit.ReadBarrier();
return result;
} else {
return LazyInit.GetOrSet(ref this.setter, unresolved.Setter.CreateResolvedAccessor(context));
}
}
public IMethod Setter {
get { return GetAccessor(ref setter, unresolved.Setter); }
}
public bool IsIndexer {

157
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAccessor.cs

@ -1,157 +0,0 @@ @@ -1,157 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Default implementation of <see cref="IAccessor"/>.
/// </summary>
[Serializable]
public sealed class DefaultUnresolvedAccessor : AbstractFreezable, IUnresolvedAccessor, ISupportsInterning, IFreezable
{
static readonly DefaultUnresolvedAccessor[] defaultAccessors = CreateDefaultAccessors();
static DefaultUnresolvedAccessor[] CreateDefaultAccessors()
{
DefaultUnresolvedAccessor[] accessors = new DefaultUnresolvedAccessor[(int)Accessibility.ProtectedAndInternal + 1];
for (int i = 0; i < accessors.Length; i++) {
accessors[i] = new DefaultUnresolvedAccessor();
accessors[i].accessibility = (Accessibility)i;
accessors[i].Freeze();
}
return accessors;
}
/// <summary>
/// Gets the default accessor with the specified accessibility (and without attributes or region).
/// </summary>
public static IUnresolvedAccessor GetFromAccessibility(Accessibility accessibility)
{
int index = (int)accessibility;
if (index >= 0 && index < defaultAccessors.Length) {
return defaultAccessors[index];
} else {
DefaultUnresolvedAccessor a = new DefaultUnresolvedAccessor();
a.accessibility = accessibility;
a.Freeze();
return a;
}
}
Accessibility accessibility;
DomRegion region;
IList<IUnresolvedAttribute> attributes;
IList<IUnresolvedAttribute> returnTypeAttributes;
protected override void FreezeInternal()
{
base.FreezeInternal();
this.attributes = FreezableHelper.FreezeListAndElements(this.attributes);
this.returnTypeAttributes = FreezableHelper.FreezeListAndElements(this.returnTypeAttributes);
}
public Accessibility Accessibility {
get { return accessibility; }
set {
FreezableHelper.ThrowIfFrozen(this);
accessibility = value;
}
}
public DomRegion Region {
get { return region; }
set {
FreezableHelper.ThrowIfFrozen(this);
region = value;
}
}
public IList<IUnresolvedAttribute> Attributes {
get {
if (attributes == null)
attributes = new List<IUnresolvedAttribute>();
return attributes;
}
}
public IList<IUnresolvedAttribute> ReturnTypeAttributes {
get {
if (returnTypeAttributes == null)
returnTypeAttributes = new List<IUnresolvedAttribute>();
return returnTypeAttributes;
}
}
bool IHasAccessibility.IsPrivate {
get { return accessibility == Accessibility.Private; }
}
bool IHasAccessibility.IsPublic {
get { return accessibility == Accessibility.Public; }
}
bool IHasAccessibility.IsProtected {
get { return accessibility == Accessibility.Protected; }
}
bool IHasAccessibility.IsInternal {
get { return accessibility == Accessibility.Internal; }
}
bool IHasAccessibility.IsProtectedOrInternal {
get { return accessibility == Accessibility.ProtectedOrInternal; }
}
bool IHasAccessibility.IsProtectedAndInternal {
get { return accessibility == Accessibility.ProtectedAndInternal; }
}
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
{
if (!this.IsFrozen) {
attributes = provider.InternList(attributes);
returnTypeAttributes = provider.InternList(returnTypeAttributes);
}
}
int ISupportsInterning.GetHashCodeForInterning()
{
return (attributes != null ? attributes.GetHashCode() : 0)
^ (returnTypeAttributes != null ? returnTypeAttributes.GetHashCode() : 0)
^ region.GetHashCode() ^ (int)accessibility;
}
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{
DefaultUnresolvedAccessor o = other as DefaultUnresolvedAccessor;
return o != null && (attributes == o.attributes && returnTypeAttributes == o.returnTypeAttributes
&& accessibility == o.accessibility && region == o.region);
}
public IAccessor CreateResolvedAccessor(ITypeResolveContext context)
{
Freeze();
return new DefaultResolvedAccessor(accessibility, region, attributes.CreateResolvedAttributes(context), returnTypeAttributes.CreateResolvedAttributes(context));
}
}
}

8
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedEvent.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -26,7 +26,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
[Serializable]
public class DefaultUnresolvedEvent : AbstractUnresolvedMember, IUnresolvedEvent
{
IUnresolvedAccessor addAccessor, removeAccessor, invokeAccessor;
IUnresolvedMethod addAccessor, removeAccessor, invokeAccessor;
protected override void FreezeInternal()
{
@ -70,7 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -70,7 +70,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return invokeAccessor != null; }
}
public IUnresolvedAccessor AddAccessor {
public IUnresolvedMethod AddAccessor {
get { return addAccessor; }
set {
ThrowIfFrozen();
@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public IUnresolvedAccessor RemoveAccessor {
public IUnresolvedMethod RemoveAccessor {
get { return removeAccessor; }
set {
ThrowIfFrozen();
@ -86,7 +86,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -86,7 +86,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public IUnresolvedAccessor InvokeAccessor {
public IUnresolvedMethod InvokeAccessor {
get { return invokeAccessor; }
set {
ThrowIfFrozen();

6
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedProperty.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
[Serializable]
public class DefaultUnresolvedProperty : AbstractUnresolvedMember, IUnresolvedProperty
{
IUnresolvedAccessor getter, setter;
IUnresolvedMethod getter, setter;
IList<IUnresolvedParameter> parameters;
protected override void FreezeInternal()
@ -80,7 +80,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -80,7 +80,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return setter != null; }
}
public IUnresolvedAccessor Getter {
public IUnresolvedMethod Getter {
get { return getter; }
set {
ThrowIfFrozen();
@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -88,7 +88,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
public IUnresolvedAccessor Setter {
public IUnresolvedMethod Setter {
get { return setter; }
set {
ThrowIfFrozen();

12
ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedEvent.cs

@ -53,16 +53,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -53,16 +53,16 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return eventDefinition.CanInvoke; }
}
public IAccessor AddAccessor {
get { return eventDefinition.AddAccessor; }
public IMethod AddAccessor {
get { return WrapAccessor(eventDefinition.AddAccessor); }
}
public IAccessor RemoveAccessor {
get { return eventDefinition.RemoveAccessor; }
public IMethod RemoveAccessor {
get { return WrapAccessor(eventDefinition.RemoveAccessor); }
}
public IAccessor InvokeAccessor {
get { return eventDefinition.InvokeAccessor; }
public IMethod InvokeAccessor {
get { return WrapAccessor(eventDefinition.InvokeAccessor); }
}
}
}

10
ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedMember.cs

@ -70,6 +70,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -70,6 +70,14 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
return type.AcceptVisitor(substitution);
}
internal IMethod WrapAccessor(IMethod accessorDefinition)
{
if (accessorDefinition == null)
return null;
else
return new SpecializedMethod(declaringType, accessorDefinition);
}
public IType DeclaringType {
get { return declaringType; }
}
@ -118,7 +126,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -118,7 +126,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return memberDefinition.Attributes; }
}
public IList<IMember> InterfaceImplementations {
IList<IMember> IMember.InterfaceImplementations {
get { throw new NotImplementedException(); }
}

8
ICSharpCode.NRefactory/TypeSystem/Implementation/SpecializedProperty.cs

@ -49,12 +49,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -49,12 +49,12 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return propertyDefinition.CanSet; }
}
public IAccessor Getter {
get { return propertyDefinition.Getter; }
public IMethod Getter {
get { return WrapAccessor(propertyDefinition.Getter); }
}
public IAccessor Setter {
get { return propertyDefinition.Setter; }
public IMethod Setter {
get { return WrapAccessor(propertyDefinition.Setter); }
}
public bool IsIndexer {

Loading…
Cancel
Save