Exemple #1
0
        public bool IsAvailable(IUserDataHolder cache)
        {
            var methodName = this._myProvider.GetSelectedElement <ICSharpIdentifier>();

            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(methodName);

            ICSharpParametersOwnerDeclaration paramsOwnerDeclaration = methodDeclaration;
            IFormalParameterList paramsList = methodDeclaration?.Params;

            //If unable to resolve by method declaration, try to resolve for ctor.
            if (paramsOwnerDeclaration == null)
            {
                var constructorDeclaration = ConstructorDeclarationNavigator.GetByTypeName(methodName);
                paramsOwnerDeclaration = constructorDeclaration;
                paramsList             = constructorDeclaration?.Params;
            }

            if (paramsOwnerDeclaration == null)
            {
                return(false);
            }
            if (paramsOwnerDeclaration.ParameterDeclarations.IsEmpty)
            {
                return(false);
            }

            this.ParametersOwnerDeclaration = paramsOwnerDeclaration;
            this.FormalParameterList        = paramsList;

            return(true);
        }
Exemple #2
0
        private void DoCleanupLineBreaks([NotNull] ICSharpParametersOwnerDeclaration parametersOwnerDeclaration, [NotNull] IFormalParameterList parameters)
        {
            var nodesToRemove = new List <ITokenNode>();

            //Remove line breaks between parenthesis and arguments.
            for (var node = parametersOwnerDeclaration.LPar; node != null && node != parametersOwnerDeclaration.RPar; node = node.GetNextToken())
            {
                if (IsLineBreak(node))
                {
                    nodesToRemove.Add(node);
                }
            }

            nodesToRemove.ForEach(LowLevelModificationUtil.DeleteChild);

            //Remove all line breaks between arguments.
            nodesToRemove.Clear();
            nodesToRemove.AddRange(parameters.Children().OfType <ITokenNode>().Where(IsLineBreak));

            nodesToRemove.ForEach(LowLevelModificationUtil.DeleteChild);
        }
Exemple #3
0
        private static IEnumerable <IArgumentsOwner> FindReferences(ICSharpParametersOwnerDeclaration parametersOwner, IProgressIndicator progressIndicator)
        {
            var references = new List <IArgumentsOwner>();
            var consumer   = new FindResultConsumer(
                r =>
            {
                var owners    = new HashSet <IArgumentsOwner>();
                var reference = r as FindResultReference;
                if (reference != null)
                {
                    var ref2        = reference.Reference;
                    var resolveType = ref2.CheckResolveResult();
                    if (resolveType == ResolveErrorType.INCORRECT_PARAMETER_NUMBER)
                    {
                        return(FindExecution.Continue);
                    }
                    var argumentsOwner = ref2.GetTreeNode().GetContainingNode <IArgumentsOwner>(true);
                    if (argumentsOwner != null)
                    {
                        if (owners.Contains(argumentsOwner))
                        {
                            return(FindExecution.Continue);
                        }
                        owners.Add(argumentsOwner);
                        references.Add(argumentsOwner);
                    }
                }
                return(FindExecution.Continue);
            });
            var searchAction = new SearchAction(
                parametersOwner.GetPsiServices().Finder,
                parametersOwner.DeclaredElement,
                consumer,
                SearchPattern.FIND_USAGES);

            searchAction.Task(progressIndicator);
            return(references);
        }
Exemple #4
0
        /// <summary>
        /// Returns an xml string of the documentation for an element.
        /// </summary>
        /// <param name="owner">
        /// The owner of the doc comment block.
        /// </param>
        /// <param name="docConfig">
        /// The config for the current ProjectFile.
        /// </param>
        /// <returns>
        /// A string of the declarations summary text.
        /// </returns>
        private static string CreateDocumentationForElement(IDocCommentBlockOwnerNode owner, DocumentationRulesConfiguration docConfig)
        {
            ITreeNode        element         = owner;
            IDeclaredElement declaredElement = (element is IDeclaration) ? ((IDeclaration)element).DeclaredElement : null;
            StringBuilder    text            = new StringBuilder();

            text.AppendLine("<summary>");
            string summaryText = string.Empty;

            if (element is IConstructorDeclaration)
            {
                summaryText = Utils.CreateSummaryForConstructorDeclaration((IConstructorDeclaration)element);
            }

            if (element is IDestructorDeclaration)
            {
                summaryText = Utils.CreateSummaryForDestructorDeclaration((IDestructorDeclaration)element);
            }

            if (element is IPropertyDeclaration)
            {
                summaryText = Utils.CreateSummaryDocumentationForProperty((IPropertyDeclaration)element);
            }

            text.AppendLine(summaryText);
            text.AppendLine("</summary>");

            ICSharpParametersOwnerDeclaration declarationWithParameters = element as ICSharpParametersOwnerDeclaration;

            if (declarationWithParameters != null)
            {
                foreach (IRegularParameterDeclaration parameterDeclaration in declarationWithParameters.ParameterDeclarations)
                {
                    text.AppendLine(Utils.CreateDocumentationForParameter(parameterDeclaration));
                }
            }

            ICSharpTypeDeclaration typeDeclaration = element as ICSharpTypeDeclaration;

            if (typeDeclaration != null && (typeDeclaration.TypeParameters.Count > 0))
            {
                foreach (ITypeParameterOfTypeDeclaration typeParameter in typeDeclaration.TypeParameters)
                {
                    text.AppendLine(Utils.CreateDocumentationForParameter(typeParameter));
                }
            }

            ITypeParametersOwner typeParametersOwner = element as ITypeParametersOwner;

            if (typeParametersOwner != null && (typeParametersOwner.TypeParameters.Count > 0))
            {
                foreach (ITypeParameter typeParameter in typeParametersOwner.TypeParameters)
                {
                    text.AppendLine(Utils.CreateDocumentationForTypeParameterDeclaration((ITypeParameterDeclaration)typeParameter));
                }
            }

            IMethodDeclaration methodDeclaration = element as IMethodDeclaration;

            if (methodDeclaration != null && (methodDeclaration.TypeParameterDeclarations.Count > 0))
            {
                foreach (ITypeParameterOfMethodDeclaration typeParameter in methodDeclaration.TypeParameterDeclarations)
                {
                    text.AppendLine(Utils.CreateDocumentationForParameter(typeParameter));
                }
            }

            IParametersOwner parametersOwner = declaredElement as IParametersOwner;

            if ((parametersOwner != null && ((parametersOwner is IMethod) || (parametersOwner is IOperator))) &&
                !parametersOwner.ReturnType.Equals(parametersOwner.Module.GetPredefinedType().Void))
            {
                text.AppendLine("<returns></returns>");
            }

            bool ruleIsEnabled = docConfig.GetStyleCopRuleEnabled("PropertyDocumentationMustHaveValue");

            if (element is IPropertyDeclaration && ruleIsEnabled)
            {
                text.AppendLine(Utils.CreateValueDocumentationForProperty((IPropertyDeclaration)element));
            }

            List <IType> exceptions = new List <IType>();
            ICSharpFunctionDeclaration functionDeclaration = element as ICSharpFunctionDeclaration;

            if (functionDeclaration != null && functionDeclaration.Body != null)
            {
                CollectExceptions(functionDeclaration.Body, exceptions);
            }

            IPropertyDeclaration propertyDeclaration = element as IPropertyDeclaration;

            if (propertyDeclaration != null)
            {
                CollectExceptions(propertyDeclaration.AccessorDeclarations, exceptions);
            }

            IIndexerDeclaration indexerDeclaration = element as IIndexerDeclaration;

            if (indexerDeclaration != null)
            {
                CollectExceptions(indexerDeclaration.AccessorDeclarations, exceptions);
            }

            IEventDeclaration eventDeclaration = element as IEventDeclaration;

            if (eventDeclaration != null)
            {
                CollectExceptions(eventDeclaration.AccessorDeclarations, exceptions);
            }

            foreach (IType exception in exceptions)
            {
                string presentableName = exception.GetPresentableName(CSharpLanguage.Instance);

                string a = Utils.StripClassName(presentableName);
                string b = exception.ToString();
                text.AppendLine("<exception cref=\"" + Utils.SwapGenericTypeToDocumentation(a) + "\"></exception>");
            }

            return(text.ToString());
        }
 public OnelineMethodArgumentsAction([NotNull] ICSharpParametersOwnerDeclaration parametersOwnerDeclaration, [NotNull] IFormalParameterList paramList)
     : base(parametersOwnerDeclaration, paramList)
 {
 }
Exemple #6
0
 protected ChopInlineMethodActionBase([NotNull] ICSharpParametersOwnerDeclaration parametersOwnerDeclaration, [NotNull] IFormalParameterList paramList)
 {
     this._parametersOwnerDeclaration = parametersOwnerDeclaration;
     this._paramList = paramList;
 }
 private static IEnumerable<IArgumentsOwner> FindReferences(ICSharpParametersOwnerDeclaration parametersOwner, IProgressIndicator progressIndicator)
 {
     var references = new List<IArgumentsOwner>();
     var consumer = new FindResultConsumer(
         r =>
         {
             var owners = new HashSet<IArgumentsOwner>();
             var reference = r as FindResultReference;
             if(reference != null)
             {
                 var ref2 = reference.Reference;
                 var resolveType = ref2.CheckResolveResult();
                 if (resolveType == ResolveErrorType.INCORRECT_PARAMETER_NUMBER)
                     return FindExecution.Continue;
                 var argumentsOwner = ref2.GetElement().GetContainingElement<IArgumentsOwner>(true);
                 if(argumentsOwner != null)
                 {
                     if (owners.Contains(argumentsOwner))
                         return FindExecution.Continue;
                     owners.Add(argumentsOwner);
                     references.Add(argumentsOwner);
                 }
             }
             return FindExecution.Continue;
         });
     var searchAction = new SearchAction(
         parametersOwner.GetManager().Finder,
         parametersOwner.DeclaredElement,
         consumer,
         SearchPattern.FIND_USAGES);
     searchAction.Task(progressIndicator);
     return references;
 }