/// <summary> /// Extracts the method contracts. Does not visit property accessors. /// </summary> public override void Visit(IMethodDefinition methodDefinition) { Contract.Assert(methodDefinition != null); if (CCDocContractHelper.IsCompilerGenerated(this.host, methodDefinition)) { return; //Don't continue traverser } if (MethodHelper.IsGetter(methodDefinition) || MethodHelper.IsSetter(methodDefinition)) { return; } string methodId = MemberHelper.GetMemberSignature(methodDefinition, NameFormattingOptions.DocumentationId); docTracker.WriteLine(methodId); bool isPure = IsPure(methodDefinition);//TODO: Remove, this should be handled on the packager side. ContractPackager packager = new ContractPackager(host, docTracker); packager.PackageMethodContracts(methodDefinition, isPure); XContract[] contractArray; if (packager.TryGetContracts(out contractArray)) { docTracker.AddMemberInfo(contractArray.Length, MemberKind.Method); contracts.Add(new KeyValuePair <string, XContract[]>(methodId, contractArray)); } else { docTracker.AddMemberInfo(0, MemberKind.Method); } //base.TraverseChildren(methodDefinition); }
public override void TraverseChildren(ITypeDefinition typeDefinition) { if (CCDocContractHelper.IsCompilerGenerated(this.host, typeDefinition) || IsContractClass(typeDefinition)) { return; //Don't continue traverser } base.TraverseChildren(typeDefinition); }
/// <summary> /// Attempts to package all contracts for a type. Does not include inherited contracts. /// </summary> public void PackageTypeContracts(ITypeDefinition type) { Contract.Requires(type != null); #region Package contracts from this implementation ITypeContract typeContract; if (CCDocContractHelper.TryGetTypeContract(this.host, type, out typeContract, docTracker)) { if (IteratorHelper.EnumerableIsNotEmpty <ITypeInvariant>(typeContract.Invariants)) { PackageInvariants(typeContract.Invariants); } } #endregion }
public void PackageMethodContracts(IMethodDefinition method, bool isPure) { Contract.Requires(method != null); #region Package purity if (isPure) { PackageContract(new XPure(this.host, isPure, docTracker)); } //Don't package anything if it isn't pure. (That way it is easyer to deal with on the Sandcastle side) #endregion #region Package contracts from this implementation IMethodContract thisContract; if (CCDocContractHelper.TryGetMethodContract(host, method, out thisContract, docTracker)) { PackageMethodContracts(thisContract, null, null); } #endregion #region Package contracts from base overrides if (!method.IsNewSlot) // REVIEW: Is there a better test? { IMethodDefinition overriddenMethod = MemberHelper.GetImplicitlyOverriddenBaseClassMethod(method) as IMethodDefinition; while (overriddenMethod != null && overriddenMethod != Dummy.Method) { IMethodContract /*?*/ overriddenContract; if (CCDocContractHelper.TryGetMethodContract(host, overriddenMethod, out overriddenContract, docTracker)) { SubstituteParameters sps = new SubstituteParameters(this.host, method, overriddenMethod); IMethodContract newContract = sps.Rewrite(overriddenContract) as MethodContract; var unspecializedMethod = MethodHelper.Unspecialize(overriddenMethod); var methodId = MemberHelper.GetMemberSignature(unspecializedMethod, NameFormattingOptions.DocumentationId); var typeName = TypeHelper.GetTypeName(unspecializedMethod.ContainingType, NameFormattingOptions.OmitContainingNamespace | NameFormattingOptions.OmitContainingType); PackageMethodContracts(newContract, methodId, typeName); } overriddenMethod = MemberHelper.GetImplicitlyOverriddenBaseClassMethod(overriddenMethod) as IMethodDefinition; } } #endregion #region Package contracts from implicit interface implementations foreach (IMethodDefinition ifaceMethod in MemberHelper.GetImplicitlyImplementedInterfaceMethods(method)) { IMethodContract /*?*/ ifaceContract; if (!CCDocContractHelper.TryGetMethodContract(host, ifaceMethod, out ifaceContract, docTracker)) { continue; } SubstituteParameters sps = new SubstituteParameters(this.host, method, ifaceMethod); IMethodContract newContract = sps.Rewrite(ifaceContract) as MethodContract; var unspecializedMethod = MethodHelper.Unspecialize(ifaceMethod); var methodId = MemberHelper.GetMemberSignature(unspecializedMethod, NameFormattingOptions.DocumentationId); var typeName = TypeHelper.GetTypeName(unspecializedMethod.ContainingType, NameFormattingOptions.OmitContainingNamespace | NameFormattingOptions.OmitContainingType); PackageMethodContracts(newContract, methodId, typeName); } #endregion #region Package contracts from explicit interface implementations // REVIEW: Why does GetExplicitlyOverriddenMethods return IMethodReference when GetImplicitlyImplementedInterfaceMethods // returns IMethodDefinition? foreach (IMethodReference ifaceMethodRef in MemberHelper.GetExplicitlyOverriddenMethods(method)) { IMethodDefinition /*?*/ ifaceMethod = ifaceMethodRef.ResolvedMethod; if (ifaceMethod == null) { continue; } IMethodContract /*?*/ ifaceContract; if (!CCDocContractHelper.TryGetMethodContract(host, ifaceMethod, out ifaceContract, docTracker)) { continue; } SubstituteParameters sps = new SubstituteParameters(this.host, method, ifaceMethod); IMethodContract newContract = sps.Rewrite(ifaceContract) as MethodContract; var unspecializedMethod = MethodHelper.Unspecialize(ifaceMethod); var methodId = MemberHelper.GetMemberSignature(unspecializedMethod, NameFormattingOptions.DocumentationId); var typeName = TypeHelper.GetTypeName(unspecializedMethod.ContainingType, NameFormattingOptions.OmitContainingNamespace | NameFormattingOptions.OmitContainingType); PackageMethodContracts(newContract, methodId, typeName);; } #endregion }