/// <summary> /// If the resourceManagerMember is a property, this method tries /// to find the field that this property is associated to. /// This association is cached in the /// resourceManagerFieldAccessedByProperty field /// to improve performance. /// </summary> void TryResolveResourceManagerProperty() { if (this.resourceManagerFieldAccessedByProperty == null && !this.triedToResolvePropertyAssociation) { // Don't try this more than once in the same CompilationUnit this.triedToResolvePropertyAssociation = true; IProperty prop = this.resourceManagerMember as IProperty; if (prop != null) { // Resolve the property association. PropertyFieldAssociationVisitor visitor = new PropertyFieldAssociationVisitor(prop, this.FileName, this.FileContent); this.compilationUnit.AcceptVisitor(visitor, null); // Store the association in the instance field. this.resourceManagerFieldAccessedByProperty = visitor.AssociatedField; } } }
public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { if (this.FoundResourceSet == null && // skip if already found to improve performance assignmentExpression.Op == AssignmentOperatorType.Assign && this.PositionAvailable && (!this.isLocalVariable || this.resourceManagerMember.Region.IsInside(this.CurrentNodeStartLocation.Y, this.CurrentNodeStartLocation.X)) // skip if local variable is out of scope ) { IMember resolvedMember = null; ResolveResult rr = this.Resolve(assignmentExpression.Left); if (rr != null) { // Support both local variables and member variables MemberResolveResult mrr = rr as MemberResolveResult; if (mrr != null) { resolvedMember = mrr.ResolvedMember; } else { LocalResolveResult lrr = rr as LocalResolveResult; if (lrr != null) { resolvedMember = lrr.Field; } } } if (resolvedMember != null) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: Resolved member: "+resolvedMember.ToString()); #endif // HACK: The GetType()s are necessary because the DOM IComparable implementations try to cast the parameter object to their own interface type which may fail. if (resolvedMember.GetType().Equals(this.resourceManagerMember.GetType()) && resolvedMember.CompareTo(this.resourceManagerMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to field: "+assignmentExpression.ToString()); #endif data = true; // Resolving the property association only makes sense if // there is a possible relationship between the return types // of the resolved member and the member we are looking for. } else if (this.compilationUnit != null && !this.isLocalVariable && IsTypeRelationshipPossible(resolvedMember, this.resourceManagerMember)) { if (this.resourceManagerMember is IProperty && resolvedMember is IField) { // Find out if the resourceManagerMember is a property whose get block returns the value of the resolved member. // We might already have found this association in the // resourceManagerFieldAccessedByProperty field. this.TryResolveResourceManagerProperty(); if (this.resourceManagerFieldAccessedByProperty != null && this.resourceManagerFieldAccessedByProperty.CompareTo(resolvedMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to field: "+assignmentExpression.ToString()); #endif data = true; } } else if (this.resourceManagerMember is IField && resolvedMember is IProperty) { // Find out if the resolved member is a property whose set block assigns the value to the resourceManagerMember. PropertyFieldAssociationVisitor visitor = new PropertyFieldAssociationVisitor((IField)this.resourceManagerMember, this.FileName, this.FileContent); this.compilationUnit.AcceptVisitor(visitor, null); if (visitor.AssociatedProperty != null && visitor.AssociatedProperty.CompareTo(resolvedMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to property: "+assignmentExpression.ToString()); #endif data = true; } } } } } return base.TrackedVisitAssignmentExpression(assignmentExpression, data); }
public override object TrackedVisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { if (this.FoundResourceSet == null && // skip if already found to improve performance assignmentExpression.Op == AssignmentOperatorType.Assign && this.PositionAvailable && (!this.isLocalVariable || this.resourceManagerMember.Region.IsInside(this.CurrentNodeStartLocation.Y, this.CurrentNodeStartLocation.X)) // skip if local variable is out of scope ) { IMember resolvedMember = null; ResolveResult rr = this.Resolve(assignmentExpression.Left); if (rr != null) { // Support both local variables and member variables MemberResolveResult mrr = rr as MemberResolveResult; if (mrr != null) { resolvedMember = mrr.ResolvedMember; } else { LocalResolveResult lrr = rr as LocalResolveResult; if (lrr != null) { resolvedMember = lrr.Field; } } } if (resolvedMember != null) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: Resolved member: " + resolvedMember.ToString()); #endif // HACK: The GetType()s are necessary because the DOM IComparable implementations try to cast the parameter object to their own interface type which may fail. if (resolvedMember.GetType().Equals(this.resourceManagerMember.GetType()) && resolvedMember.CompareTo(this.resourceManagerMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to field: " + assignmentExpression.ToString()); #endif data = true; // Resolving the property association only makes sense if // there is a possible relationship between the return types // of the resolved member and the member we are looking for. } else if (this.compilationUnit != null && !this.isLocalVariable && IsTypeRelationshipPossible(resolvedMember, this.resourceManagerMember)) { if (this.resourceManagerMember is IProperty && resolvedMember is IField) { // Find out if the resourceManagerMember is a property whose get block returns the value of the resolved member. // We might already have found this association in the // resourceManagerFieldAccessedByProperty field. this.TryResolveResourceManagerProperty(); if (this.resourceManagerFieldAccessedByProperty != null && this.resourceManagerFieldAccessedByProperty.CompareTo(resolvedMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to field: " + assignmentExpression.ToString()); #endif data = true; } } else if (this.resourceManagerMember is IField && resolvedMember is IProperty) { // Find out if the resolved member is a property whose set block assigns the value to the resourceManagerMember. PropertyFieldAssociationVisitor visitor = new PropertyFieldAssociationVisitor((IField)this.resourceManagerMember, this.FileName, this.FileContent); this.compilationUnit.AcceptVisitor(visitor, null); if (visitor.AssociatedProperty != null && visitor.AssociatedProperty.CompareTo(resolvedMember) == 0) { #if DEBUG LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found assignment to property: " + assignmentExpression.ToString()); #endif data = true; } } } } } return(base.TrackedVisitAssignmentExpression(assignmentExpression, data)); }