Exemplo n.º 1
0
        public ClassDecl(Cursor c, ISymbolTable table)
            : base(c, table)
        {
            Debug.Assert(CursorKinds.IsClassStructEtc(c.Kind));
    
            _templateKind = Symbols.TemplateKind.NonTemplate;
            if (c.Kind == CursorKind.ClassTemplate)
                _templateKind = Symbols.TemplateKind.Template;
            else if (c.Kind == CursorKind.ClassTemplatePartialSpecialization)
                _templateKind = Symbols.TemplateKind.TemplatePartialSpecialization;
            else if (c.TemplateSpecialisedCursorTemplate != null)
                _templateKind = Symbols.TemplateKind.TemplateSpecialization;

            if(c.SemanticParentCurosr.Kind == CursorKind.Namespace)
            {
                _parent = table.FindNamespaceDeclaration(c.SemanticParentCurosr.Usr);
                Debug.Assert(_parent != null);
            }
            else if (c.SemanticParentCurosr.Kind == CursorKind.TranslationUnit ||
                c.SemanticParentCurosr.Kind == CursorKind.UnexposedDecl)
            {
                _parent = null;
            }
            else if(CursorKinds.IsClassStructEtc(c.SemanticParentCurosr.Kind))
            {
                _parent = table.FindClassDeclaration(c.SemanticParentCurosr.Usr);
                Debug.Assert(_parent != null);
            }
            else
            {
                Debug.Assert(false);
            }
        }
Exemplo n.º 2
0
 public Reference(Cursor c, IDeclaration decl, ISymbolTable table)
 {
     _cursor = c;
     _decl = decl;
     _table = table;
     _location = new CodeLocation(c.Extent.Start); //todo - replace for doc tracking
 }
Exemplo n.º 3
0
 public VariableDecl(Cursor c, ISymbolTable table)
     : base(c, table)
 {
    // Debug.Assert(c.Kind == CursorKind.VarDecl);
     if (c.SemanticParentCurosr.Kind == CursorKind.Namespace)
     {
         _parent = table.FindNamespaceDeclaration(c.SemanticParentCurosr.Usr);
         Debug.Assert(_parent != null);
     }
     else if (CursorKinds.IsClassStructEtc(c.SemanticParentCurosr.Kind))
     {
         _parent = table.FindClassDeclaration(c.SemanticParentCurosr.Usr);
         Debug.Assert(_parent != null);
     }
     else if(CursorKinds.IsFunctionEtc(c.SemanticParentCurosr.Kind))
     {
         _parent = table.FindFunctionDeclaration(c.SemanticParentCurosr.Usr);
     }
     else if (c.SemanticParentCurosr.Kind == CursorKind.TranslationUnit ||
         c.SemanticParentCurosr.Kind == CursorKind.UnexposedDecl)
     {
         _parent = null;
     }
     else
     {
         Debug.Assert(false);
     }
 }
		protected override IList<string> CalculateQuickSearchTexts(IDeclaration declaration) {
			if (!declaration.IsValid())
				return EmptyList<string>.InstanceList;

			var owner = declaration as IInterfaceQualificationOwner;
			if (owner != null && owner.InterfaceQualificationReference != null)
				return new[] { owner.GetDeclaredShortName(), owner.InterfaceQualificationReference.ShortName };

			var constructorDeclaration = declaration as IConstructorDeclaration;
			if (constructorDeclaration != null)
				return new[] { constructorDeclaration.DeclaredName, "new", "ctor" };

			var indexerDeclaration = declaration as IIndexerDeclaration;
			if (indexerDeclaration != null)
				return new[] { indexerDeclaration.DeclaredName, "this" };

			var destructorDeclaration = declaration as IDestructorDeclaration;
			if (destructorDeclaration != null)
				return new[] { destructorDeclaration.DeclaredName, "Finalize" };

			var operatorDeclaration = declaration as IOperatorDeclaration;
			if (operatorDeclaration != null)
				return new[] { operatorDeclaration.DeclaredName, "operator" };

			var eventDeclaration = declaration as IEventDeclaration;
			if (eventDeclaration != null)
				return new[] { eventDeclaration.DeclaredName, "event" };

			return base.CalculateQuickSearchTexts(declaration);
		}
 public PsiIntentionResult(List<ITemplateFieldHolder> holders, IDeclaration declaration, ITreeNode anchor, DocumentRange range)
 {
   myDeclaration = declaration;
   myHolders = holders;
   myPrefferedSelection = range;
   myAnchor = anchor;
 }
 public NTriplesIntentionResult(
     List<ITemplateFieldHolder> holders, IDeclaration declaration, ITreeNode anchor, DocumentRange range)
 {
     this.myDeclaration = declaration;
     this.myHolders = holders;
     this.myPreferredSelection = range;
     this.myAnchor = anchor;
 }
 public void SetUp()
 {
     mocks = new MockRepository();
     objectBuilder = mocks.DynamicMock<IObjectBuilder<MyClass>>();
     operable = mocks.DynamicMultiMock<IDeclaration<MyClass>>(typeof(IOperable<MyClass>));
     func = x => x.Float = 1f;
     propertyExpression = x => x.IntGetterOnly;
 }
Exemplo n.º 8
0
 private DeclarationViewModel FindOrAddParentNode(IDeclaration decl)
 {            
     if(decl is NamespaceDecl)
         return FindOrAddNamespaceNode(decl as NamespaceDecl);
     if(decl is ClassDecl)
         return FindOrAddClassNode(decl as ClassDecl);
     return null;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            _declaration = new ApplicationFactory(_loginName, _ipAddress).CreateDeclarationApplication();

            if (!IsPostBack)
            {
                ccmbTerm.DoDataBind();
            }
        }
        public void Check(IDeclaration declaration, INamingPolicyProvider namingPolicyProvider, out bool isFinalResult, out NamingConsistencyCheckResult result)
        {
            isFinalResult = false;

            var methodDeclaration = declaration as IMethodDeclaration;
            var method = methodDeclaration?.DeclaredElement;

            if (method != null)
            {
                var unityApi = method.GetSolution().GetComponent<UnityApi>();
                isFinalResult = unityApi.IsEventFunction(method);
            }

            result = isFinalResult ? NamingConsistencyCheckResult.OK : null;
        }
Exemplo n.º 11
0
        public void SetUp()
        {
            mocks = new MockRepository();
            declarations = new DeclarationQueue<MyClass>(listSize);

            declaration1 = mocks.DynamicMock<IDeclaration<MyClass>>();
            declaration2 = mocks.DynamicMock<IDeclaration<MyClass>>();
            globalDeclaration = mocks.DynamicMock<IGlobalDeclaration<MyClass>>();

            using (mocks.Record())
            {
                declaration1.Stub(x => x.Start).Return(0).Repeat.Any();
                declaration1.Stub(x => x.End).Return(10).Repeat.Any();
            }
        }
        protected override IEnumerable <IType> GetRelatedTypes(IDeclaration declaration)
        {
            if (declaration is ITypeDeclaration)
            {
                return(this.GetSuperTypes(declaration as ITypeDeclaration).Cast <IType>());
            }

            var fieldDeclaration = declaration as IFieldDeclaration;

            if (fieldDeclaration != null)
            {
                return(new[] { fieldDeclaration.Type });
            }

            var parameterDeclaration = declaration as IParameterDeclaration;

            if (parameterDeclaration != null)
            {
                return(new[] { parameterDeclaration.Type });
            }

            var propertyDeclaration = declaration as IPropertyDeclaration;

            if (propertyDeclaration != null)
            {
                return(new[] { propertyDeclaration.Type });
            }

            var variableDeclaration = declaration as ILocalVariableDeclaration;

            if (variableDeclaration != null)
            {
                return(new[] { variableDeclaration.Type });
            }

            var methodDeclaration = declaration as IMethodDeclaration;

            if (methodDeclaration != null)
            {
                return(new List <IType>(methodDeclaration.ParameterDeclarations.Select(x => x.Type))
                {
                    methodDeclaration.Type
                });
            }

            return(Enumerable.Empty <IType>());
        }
Exemplo n.º 13
0
    public IUnitTestElement CreateContext(string assemblyPath, IDeclaration declaration)
    {
      var type = (ITypeElement) declaration.DeclaredElement;
      var context = GetOrCreateContext(assemblyPath,
                                       declaration.GetProject(),
                                       type.GetClrName().GetPersistent(),
                                       type.GetSubjectString(),
                                       type.GetTags(), type.IsIgnored());

      foreach (var child in context.Children)
      {
        child.State = UnitTestElementState.Pending;
      }

      _cache.AddContext(type, context);
      return context;
    }
Exemplo n.º 14
0
        public override ISet <IMethodDeclaration> getStaticMemberMethods(Context context, String name)
        {
            IDeclaration decl = getDeclaration(context);

            if (decl is EnumeratedCategoryDeclaration || decl is EnumeratedNativeDeclaration)
            {
                return(decl.GetIType(context).getStaticMemberMethods(context, name));
            }
            else if (decl is SingletonCategoryDeclaration)
            {
                return(decl.GetIType(context).getMemberMethods(context, name));
            }
            else
            {
                return(base.getStaticMemberMethods(context, name));
            }
        }
Exemplo n.º 15
0
        public IDeclaration Resolve(string symbol)
        {
            IDeclaration local = ResolveHere(symbol);

            if (local != null)
            {
                return(local);
            }
            else if (parentScope != null)
            {
                return(parentScope.Resolve(symbol));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 16
0
        public override IValue getStaticMemberValue(Context context, String name)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(GetTypeName());

            if (!(decl is IEnumeratedDeclaration <CategorySymbol>))
            {
                throw new SyntaxError(name + " is not an enumerated type!");
            }
            if ("symbols" == name)
            {
                return(((IEnumeratedDeclaration <CategorySymbol>)decl).getSymbols());
            }
            else
            {
                return(base.getStaticMemberValue(context, name));
            }
        }
Exemplo n.º 17
0
        private Value visitOnDeclaration(IDeclaration decl)
        {
            switch (decl.Type)
            {
            case Nodes.ClassDeclaration:
            case Nodes.ExportAllDeclaration:
            case Nodes.ExportDefaultDeclaration:
            case Nodes.ExportNamedDeclaration:
            case Nodes.FunctionDeclaration:
            case Nodes.ImportDeclaration:
            case Nodes.VariableDeclaration:
                break;
            }

            // never triggered.
            throw new InvalidOperationException();
        }
Exemplo n.º 18
0
        public override IValue ConvertCSharpValueToIValue(Context context, object value)
        {
            IDeclaration decl = getDeclaration(context);

            if (decl is EnumeratedNativeDeclaration || decl is EnumeratedCategoryDeclaration)
            {
                return(LoadEnumValue(context, decl, value));
            }
            else if (decl is CategoryDeclaration)
            {
                return(ConvertCSharpValueToIValue(context, (CategoryDeclaration)decl, value));
            }
            else
            {
                return(base.ConvertCSharpValueToIValue(context, value));
            }
        }
Exemplo n.º 19
0
 public ConcreteMethodDeclaration getInitializeMethod(Context context)
 {
     registerMethods(context);
     if (methodsMap.ContainsKey("initialize"))
     {
         IDeclaration decl = methodsMap["initialize"];
         if (decl is MethodDeclarationMap)
         {
             IMethodDeclaration method = ((MethodDeclarationMap)decl).GetFirst();
             if (method is ConcreteMethodDeclaration)
             {
                 return((ConcreteMethodDeclaration)method);
             }
         }
     }
     return(null);
 }
Exemplo n.º 20
0
        private IExpression resolveUnresolvedDeclaration(Context context, string name)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(name);

            if (decl == null)
            {
                return(null);
            }
            else if (decl is CategoryDeclaration)
            {
                return(new ConstructorExpression(new CategoryType(name), null, arguments));
            }
            else
            {
                return(new MethodCall(new MethodSelector(name), arguments));
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Generate a declaration use.
        /// </summary>
        /// <param name="declaration">The used declaration.</param>
        /// <param name="typeSourceCode">The type source code.</param>
        /// <param name="setup">The action delegate to do additional setup on the mock.</param>
        /// <returns>The mocked declaration use.</returns>
        public static TDeclarationUse SetupDeclarationUse <TDeclarationUse>(IDeclaration <SyntaxNode> declaration, string typeSourceCode = null, Action <Mock <TDeclarationUse> > setup = null)
            where TDeclarationUse : class, IDeclarationUse <SyntaxNode>
        {
            var propertyTypeMock = new Mock <TDeclarationUse>();

            propertyTypeMock.Setup(t => t.Declaration).Returns(declaration);
            if (typeSourceCode != null)
            {
                var typeNode     = SyntaxTreeHelper.GetTypeSyntax(typeSourceCode);
                var nodeProvider = SyntaxTreeHelper.GetSyntaxNodeProvider(typeNode);
                propertyTypeMock.Setup(t => t.SyntaxNodeProvider).Returns(nodeProvider);
            }

            setup?.Invoke(propertyTypeMock);

            return(propertyTypeMock.Object);
        }
Exemplo n.º 22
0
        public override IValue getStaticMemberValue(Context context, String name)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(this.typeName);

            if (!(decl is EnumeratedNativeDeclaration))
            {
                throw new SyntaxError(name + " is not an enumerated type!");
            }
            if ("symbols" == name)
            {
                return(((EnumeratedNativeDeclaration)decl).getSymbols());
            }
            else
            {
                throw new SyntaxError("Unknown member:" + name);
            }
        }
        public IUnitTestElement CreateContext(string assemblyPath, IDeclaration declaration)
        {
            var type    = (ITypeElement)declaration.DeclaredElement;
            var context = this.GetOrCreateContext(assemblyPath,
                                                  declaration.GetProject(),
                                                  type.GetClrName().GetPersistent(),
                                                  type.GetSubjectString(),
                                                  type.GetTags(), type.IsIgnored());

            foreach (var child in context.Children)
            {
                child.State = UnitTestElementState.Pending;
            }

            this._cache.AddContext(type, context);
            return(context);
        }
        private static void ProcessCSharpDeclaration(
            [NotNull] IDeclaration declaration,
            [NotNull] CodeStructureElement parentElement,
            [NotNull] CSharpCodeStructureProcessingState state
            )
        {
            switch (declaration)
            {
            case IClassLikeDeclaration classLikeDeclaration: {
                var codeStructureClass = new T4CSharpCodeStructureDeclaredElement(parentElement, declaration, state);
                if (classLikeDeclaration.Body != null)
                {
                    ProcessCSharpChildren(classLikeDeclaration.Body, codeStructureClass, state);
                }
                return;
            }

            case ICSharpNamespaceDeclaration namespaceDeclaration: {
                var structureNamespace = new T4CSharpCodeStructureNamespace(parentElement, declaration, state);
                if (namespaceDeclaration.Body != null)
                {
                    ProcessCSharpChildren(namespaceDeclaration.Body, structureNamespace, state);
                }
                return;
            }

            case IAccessorDeclaration _:
                return;

            case IEnumDeclaration enumDeclaration: {
                var codeStructureElement = new T4CSharpCodeStructureDeclaredElement(parentElement, declaration, state)
                {
                    InitiallyExpanded = false
                };
                ProcessCSharpChildren(enumDeclaration.EnumBody, codeStructureElement, state);
                return;
            }

            default: {
                var codeStructureElement2 = new T4CSharpCodeStructureDeclaredElement(parentElement, declaration, state);
                ProcessCSharpChildren(declaration, codeStructureElement2, state);
                break;
            }
            }
        }
Exemplo n.º 25
0
        public override IDeclaredElement Analyze(IDeclaration element, IHighlightingConsumer consumer, DaemonProcessKind kind)
        {
            if (!(element is IFieldDeclaration field))
            {
                return(null);
            }

            var declaredElement = field.DeclaredElement;

            if (declaredElement == null)
            {
                return(null);
            }

            bool isSerializedField = myUnityApi.IsSerialisedField(declaredElement);

            if (isSerializedField)
            {
                const string displayText = "Serializable";
                const string baseTooltip = "This field is initialized from Inspector";
                if (myUnityApi.IsDescendantOfMonoBehaviour(declaredElement.GetContainingType()))
                {
                    AddMonoBehaviourHighlighting(consumer, field, displayText, baseTooltip, kind);
                    return(declaredElement);
                }
                else if (myUnityApi.IsDescendantOfScriptableObject(declaredElement.GetContainingType()))
                {
                    AddScriptableObjectHighlighting(consumer, field, displayText, baseTooltip, kind);
                    return(declaredElement);
                }
                else if (myUnityApi.IsInjectedField(declaredElement))
                {
                    AddECSHighlighting(consumer, field, displayText, "This field is injected by Unity", kind);
                    return(declaredElement);
                }
                else
                {
                    AddSerializableHighlighting(consumer, field, displayText, "This field is serialized by Unity", kind);
                }

                return(null);
            }

            return(null);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Finds a declaration (excluding methods) with the specified name
        /// </summary>
        /// <param name="name">The name of the declaration to search for.</param>
        /// <returns>The declaration with the specified name or null if not found.</returns>
        public IDeclaration GetDeclaration(string name)
        {
            // Project
            if (Project == null)
            {
                return(null);
            }

            IDeclaration superGlobalDeclaration = Project.GetDeclaration(name);

            if (superGlobalDeclaration != null)
            {
                return(superGlobalDeclaration);
            }

            // Sprite
            if (CurrentSprite == null)
            {
                return(null);
            }

            ITypedDeclaration globalDeclaration = CurrentSprite.GetDeclaration(name);

            if (globalDeclaration != null)
            {
                return(globalDeclaration);
            }

            // Methods
            if (CurrentScope == null)
            {
                return(null);
            }

            // Method params
            ParamDeclaration methodParam = (CurrentScope.Method as MethodDeclaration)?.FindParam(name);

            if (methodParam != null)
            {
                return(methodParam);
            }

            // Scoped variables
            return(CurrentScope.Search(name));
        }
Exemplo n.º 27
0
        private bool isDeclMatch(IDeclaration declaration)
        {
            if (declaration is IAccessorDeclaration)
            {
                return(false);
            }

            if (declaration.DeclaredElement != null)
            {
                DeclaredElementType type = declaration.DeclaredElement.GetElementType();
                return(_declaration == Declaration.Any ||
                       _declMap.ContainsKey(type) && _declMap[type] == _declaration);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 28
0
        protected virtual string GetConceptIdentifier(IDeclaration decl)
        {
            string name = null;

            if (options.NameHandler.HandlesName(decl))
            {
                name = options.NameHandler.HandleName(decl);
            }
            else
            {
                name = decl.Name;
            }
            if (this.IsKeyword(name))
            {
                name = EscapeIdentifier(name);
            }
            return(name);
        }
        private void AddGutterMark(IDeclaration declaration, UnityEventFunction eventFunction,
                                   IHighlightingConsumer consumer)
        {
            var tooltip = "Unity event function";

            if (!string.IsNullOrEmpty(eventFunction.Description))
            {
                tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description;
            }
            if (eventFunction.Coroutine)
            {
                tooltip += Environment.NewLine + "This function can be a coroutine.";
            }

            var highlighting = new UnityGutterMarkInfo(declaration, tooltip);

            consumer.AddHighlighting(highlighting);
        }
Exemplo n.º 30
0
        public override void ResolveNames(LexicalScope ls)
        {
            if (ls != null)
            {
                var result = ls.Resolve(Identifier.Name);
                if (result == null)
                {
                    throw new ApplicationException($"Error: Undeclared identifier {Identifier.Name}");
                }
                else
                {
                    Declaration = result;
                    type        = Declaration.GetDeclarationType();
                }
            }

            //ls.SymbolTable.Add(GetName(), this);
        }
Exemplo n.º 31
0
        public override IType checkStaticMember(Context context, String name)
        {
            IDeclaration decl = context.getRegisteredDeclaration <IDeclaration>(GetTypeName());

            if (decl == null)
            {
                throw new SyntaxError("Not a category:" + GetTypeName());
            }
            if (decl is EnumeratedCategoryDeclaration || decl is EnumeratedNativeDeclaration)
            {
                return(decl.GetIType(context).checkStaticMember(context, name));
            }
            if (decl is SingletonCategoryDeclaration)
            {
                return(checkAttribute(context, (SingletonCategoryDeclaration)decl, name));
            }
            throw new SyntaxError("No attribute:" + name + " in category:" + GetTypeName());
        }
Exemplo n.º 32
0
        public override IValue getStaticMemberValue(Context context, String name)
        {
            IDeclaration decl = getDeclaration(context);

            if (decl is EnumeratedCategoryDeclaration || decl is EnumeratedNativeDeclaration)
            {
                return(decl.GetIType(context).getStaticMemberValue(context, name));
            }
            else if (decl is SingletonCategoryDeclaration)
            {
                ConcreteInstance singleton = context.loadSingleton(this);
                return(singleton.GetMemberValue(context, name, false));
            }
            else
            {
                return(base.getStaticMemberValue(context, name));
            }
        }
Exemplo n.º 33
0
 public void enterMethod(Context context, IDeclaration method)
 {
     terminateIfRequested();
     stack.Push(new StackFrame(context, method.GetName(), method));
     if (stack.Count > 0 && stack.Count <= stepDepth)
     {
         suspend(SuspendReason.STEPPING, context, method);
     }
     else if (method.Breakpoint)
     {
         suspend(SuspendReason.BREAKPOINT, context, method);
     }
     else
     {
         suspendIfRequested(context, method);
     }
     terminateIfRequested();
 }
        private void AddGutterMark(IDeclaration declaration, UnityEventFunction eventFunction,
                                   IHighlightingConsumer consumer)
        {
            var documentRange = declaration.GetNameDocumentRange();
            var tooltip       = "Unity event function";

            if (!string.IsNullOrEmpty(eventFunction.Description))
            {
                tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description;
            }
            if (eventFunction.Coroutine)
            {
                tooltip += Environment.NewLine + "This function can be a coroutine.";
            }
            var highlighting = new UnityMarkOnGutter(Api, declaration, documentRange, tooltip);

            consumer.AddHighlighting(highlighting, documentRange);
        }
Exemplo n.º 35
0
        private static void ProcessMemberDeclarations(IDeclaration declaration, OrderingOptions options)
        {
            bool propertyAccessorsMustFollowOrder = options.SA1212PropertyAccessorsMustFollowOrder;
            bool eventAccessorsMustFollowOrder    = options.SA1213EventAccessorsMustFollowOrder;

            if (declaration is IIndexerDeclaration && propertyAccessorsMustFollowOrder)
            {
                CheckAccessorOrder(declaration as IIndexerDeclaration);
            }
            else if (declaration is IPropertyDeclaration && propertyAccessorsMustFollowOrder)
            {
                CheckAccessorOrder(declaration as IPropertyDeclaration);
            }
            else if (declaration is IEventDeclaration && eventAccessorsMustFollowOrder)
            {
                CheckAccessorOrder(declaration as IEventDeclaration);
            }
        }
Exemplo n.º 36
0
        public void Check(IDeclaration declaration, INamingPolicyProvider namingPolicyProvider, out bool isFinalResult, out NamingConsistencyCheckResult result)
        {
            var methodDeclaration = declaration as IMethodDeclaration;

            if (methodDeclaration != null && MonoBehaviourUtil.IsEventHandler(methodDeclaration.DeclaredName))
            {
                var containingTypeElement = methodDeclaration.GetContainingTypeDeclaration().DeclaredElement;
                if (containingTypeElement != null && MonoBehaviourUtil.IsMonoBehaviourType(containingTypeElement, methodDeclaration.GetPsiModule()))
                {
                    result        = NamingConsistencyCheckResult.OK;
                    isFinalResult = true;
                    return;
                }
            }

            result        = null;
            isFinalResult = false;
        }
        private static void ProcessCSharpDeclaration([NotNull] IDeclaration declaration, [NotNull] CodeStructureElement parentElement,
                                                     [NotNull] CSharpCodeStructureProcessingState state)
        {
            var classLikeDeclaration = declaration as IClassLikeDeclaration;

            if (classLikeDeclaration != null)
            {
                var codeStructureClass = new T4CSharpCodeStructureDeclaredElement(parentElement, declaration, state);
                if (classLikeDeclaration.Body != null)
                {
                    ProcessCSharpChildren(classLikeDeclaration.Body, codeStructureClass, state);
                }
                return;
            }

            var namespaceDeclaration = declaration as ICSharpNamespaceDeclaration;

            if (namespaceDeclaration != null)
            {
                var structureNamespace = new T4CSharpCodeStructureNamespace(parentElement, declaration, state);
                if (namespaceDeclaration.Body != null)
                {
                    ProcessCSharpChildren(namespaceDeclaration.Body, structureNamespace, state);
                }
                return;
            }

            if (declaration is IAccessorDeclaration)
            {
                return;
            }

            var codeStructureElement = new T4CSharpCodeStructureDeclaredElement(parentElement, declaration, state);
            var enumDeclaration      = declaration as IEnumDeclaration;

            if (enumDeclaration != null)
            {
                codeStructureElement.InitiallyExpanded = false;
                ProcessCSharpChildren(enumDeclaration.EnumBody, codeStructureElement, state);
                return;
            }

            ProcessCSharpChildren(declaration, codeStructureElement, state);
        }
Exemplo n.º 38
0
        public void ExecuteTemplate()
        {
            IDeclaration newDeclaration = this.myDeclaration;

            newDeclaration.AssertIsValid();

            ISolution solution = newDeclaration.GetPsiModule().GetSolution();

            Debug.Assert(Shell.Instance.Invocator != null, "Shell.Instance.Invocator != null");
            Shell.Instance.Invocator.Dispatcher.AssertAccess();

            solution.GetComponent <SolutionDocumentTransactionManager>().AssertNotUnderTransaction();

            IFile file = this.myAnchor.GetContainingFile();

            Assertion.Assert(file != null, "fileFullName!= null");
            var item = file.GetSourceFile().ToProjectFile();

            var infos = GetFieldInfos(newDeclaration, this.myHolders);

            var textControl = EditorManager.GetInstance(solution).OpenProjectFile(item, true);

            if (textControl == null)
            {
                if (Shell.Instance.IsInInternalMode || Shell.Instance.IsTestShell)
                {
                    Logger.Fail("textControl != null");
                }
                return;
            }

            if (infos.Length > 0)
            {
                HotspotSession hotspotSession = LiveTemplatesManager.Instance.CreateHotspotSessionAtopExistingText(
                    solution,
                    TextRange.InvalidRange,
                    textControl,
                    LiveTemplatesManager.EscapeAction.LeaveTextAndCaret,
                    infos);
                hotspotSession.Execute();
            }

            Shell.Instance.GetComponent <NTriplesIntentionResultBehavior>().OnHotspotSessionExecutionStarted(this, textControl);
        }
Exemplo n.º 39
0
 public FunctionDecl(Cursor c, ISymbolTable table)
     : base(c, table)
 {
     Debug.Assert(c.Kind == CursorKind.FunctionDecl);
     if (c.SemanticParentCurosr.Kind == CursorKind.Namespace)
     {
         _parent = table.FindNamespaceDeclaration(c.SemanticParentCurosr.Usr);
         Debug.Assert(_parent != null);
     }
     else if (c.SemanticParentCurosr.Kind == CursorKind.TranslationUnit ||
             c.SemanticParentCurosr.Kind == CursorKind.UnexposedDecl)
     {
         _parent = null;
     }
     else
     {
         Debug.Assert(false);
     }
 }
		public T4CSharpCodeStructureDeclaredElement(CodeStructureElement parentElement, IDeclaration declaration, CSharpCodeStructureProcessingState state)
			: base(parentElement, declaration) {
			IDeclaredElement declaredElement = declaration.DeclaredElement;
			InitiallyExpanded = true;

			if (declaredElement != null && state.Options.BuildInheritanceInformation) {
				_inheritanceInformation = InheritanceInformation.FromDeclaredElement(declaredElement);
				if (_inheritanceInformation != null) {
					var structureDeclaredElement = parentElement as T4CSharpCodeStructureDeclaredElement;
					if (structureDeclaredElement != null)
						structureDeclaredElement.ChildrenWithInheritance = true;
				}
			}

			_parentRegion = state.Regions.TryPeek();

			if (declaredElement != null)
				_aspects = new T4CSharpCodeStructureAspects(this, declaration);
		}
Exemplo n.º 41
0
        public void ShouldBeAbleToBuildAList()
        {
            IDeclaration <MyClass> declaration = MockRepository.GenerateMock <IDeclaration <MyClass> >();

            var builder = new ListBuilder <MyClass>(listSize, propertyNamer, reflectionUtil, new BuilderSettings());

            using (mocks.Record())
            {
                reflectionUtil.Stub(x => x.RequiresConstructorArgs(typeof(MyClass))).Return(false).Repeat.Any();
                reflectionUtil.Expect(x => x.CreateInstanceOf <MyClass>()).Return(myClass).Repeat.Any();
                declaration.Expect(x => x.Construct());
                declaration.Expect(x => x.AddToMaster(Arg <MyClass[]> .Is.TypeOf));
                propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg <IList <MyClass> > .Is.TypeOf));
                declaration.Expect(x => x.CallFunctions(Arg <IList <MyClass> > .Is.TypeOf)).IgnoreArguments();
            }

            using (mocks.Playback())
                builder.Build();
        }
Exemplo n.º 42
0
        public static TreeNodeCollection <IFSharpAttribute> GetAttributes([NotNull] this IDeclaration declaration)
        {
            switch (declaration)
            {
            case IFSharpTypeDeclaration typeDeclaration:
                return(typeDeclaration.Attributes);

            case IMemberDeclaration memberDeclarationm:
                return(memberDeclarationm.Attributes);

            case ILet letBinding:
                return(letBinding.Attributes);

            case IModuleLikeDeclaration moduleLikeDeclaration:
                return(moduleLikeDeclaration.Attributes);

            default: return(TreeNodeCollection <IFSharpAttribute> .Empty);
            }
        }
Exemplo n.º 43
0
 public EnumDecl(Cursor c, ISymbolTable table)
     : base(c, table)
 {
     Debug.Assert(c.Kind == CursorKind.EnumDecl);
     if (c.SemanticParentCurosr.Kind == CursorKind.Namespace)
     {
         _parent = table.FindNamespaceDeclaration(c.SemanticParentCurosr.Usr);
         Debug.Assert(_parent != null);
     }
     else if (CursorKinds.IsClassStructEtc(c.SemanticParentCurosr.Kind))
     {
         _parent = table.FindClassDeclaration(c.SemanticParentCurosr.Usr);
         Debug.Assert(_parent != null);
     }
     else
     {
         CursorKind k = c.SemanticParentCurosr.Kind;
     }
 }
Exemplo n.º 44
0
        public static TreeNodeCollection <IAttribute> GetAttributes([NotNull] this IDeclaration declaration)
        {
            switch (declaration)
            {
            case IFSharpTypeOldDeclaration typeDeclaration:
                return(typeDeclaration.Attributes);

            case IMemberSignatureOrDeclaration memberDeclaration:
                return(memberDeclaration.Attributes);

            case IFSharpPattern fsPattern:
                return(fsPattern.Attributes);

            case IDeclaredModuleDeclaration moduleDeclaration:
                return(moduleDeclaration.Attributes);

            default: return(TreeNodeCollection <IAttribute> .Empty);
            }
        }
Exemplo n.º 45
0
        private void DefineType(string packageName, AccelTypeInfo declaringType, TypeBuilder declaringTypeBuilder, StructDeclaration def, Dictionary <string, AccelTypeInfo> result)
        {
            string name     = def.Name;
            string fullName = def.IsNested ? $"{declaringType.FullName}+{def.Name}" : $"{packageName}.{def.Name}";
            Dictionary <string, AccelFieldInfo> fields = new Dictionary <string, AccelFieldInfo>(def.Declarations.Declarations.Length);
            Type          baseType = def.IsRef ? typeof(object) : typeof(ValueType);
            TypeBuilder   builder  = RuntimeInjector.DefinePublicType(def.IsNested ? name : fullName, def.IsFinal, declaringTypeBuilder, baseType, Type.EmptyTypes);
            AccelTypeInfo info     = new AccelTypeInfo(name, fullName, def.Doc, TypeVisibility.Public, def.IsFinal, def.IsRef, def.IsNested, def.IsFieldIndexContinuous, (int)def.Size, declaringType, fields);

            for (int i = 0; i < def.Declarations.Declarations.Length; i++)
            {
                IDeclaration declaration = def.Declarations.Declarations[i];

                switch (declaration)
                {
                case FieldDeclaration fieldDeclaration:
                    Type fieldType = GetType(fieldDeclaration.Type);
                    Type realType  = fieldDeclaration.RealType == null ? null : GetType(fieldDeclaration.RealType);
                    builder.DefineField(fieldDeclaration.Name, fieldType, FieldAttributes.Public);
                    AccelFieldInfo fieldInfo = new AccelFieldInfo(fieldDeclaration.Name, fieldDeclaration.Doc, (int)fieldDeclaration.Index, fieldDeclaration.IsObsolete, fieldDeclaration.IsNeverNull, info, fieldType, realType);
                    fields.Add(fieldDeclaration.Name, fieldInfo);
                    break;

                case StructDeclaration structDeclaration:
                    DefineType(packageName, info, builder, structDeclaration, result);
                    break;

                default:
                    continue;
                }
            }

            Type type = builder.CreateType();

            info.TypeHandle = type.TypeHandle;

            foreach (FieldInfo field in type.GetFields())
            {
                fields[field.Name].FieldHandle = field.FieldHandle;
            }

            result.Add(fullName, info);
        }
Exemplo n.º 46
0
        public void AddDeclaration(IDeclaration declaration)
        {
            List<IDeclaration> declarations;
            if (declaration.Name != null)
            {

                string name = declaration.Name.Text;
                if (string.IsNullOrEmpty(name))
                    return;

                if (!Declarations.TryGetValue(name, out declarations))
                {
                    declarations = new List<IDeclaration>();
                    Declarations.Add(name, declarations);
                }
            }
            else
            {
                declarations = new List<IDeclaration>();
            }

            var genericsDeclarator = declaration as IGenerics;
            if (genericsDeclarator != null)
            {
                for (int i = 0; i < genericsDeclarator.GenericParameters.Count; i++)
                {
                    var genericArgument = genericsDeclarator.GenericParameters[i];
                    var genericName = genericArgument.Name.Text;
                    List<GenericDeclaration> generics;
                    if (!Generics.TryGetValue(genericName, out generics))
                    {
                        generics = new List<GenericDeclaration>();
                        Generics.Add(genericName, generics);
                    }

                    generics.Add(new GenericDeclaration(genericArgument.Name, genericsDeclarator, i, false) { Span = genericArgument.Span });
                }
            }
            
            if (!declarations.Contains(declaration))
                declarations.Add(declaration);
        }
Exemplo n.º 47
0
        /// <summary>Checks the declaration documentation.</summary>
        /// <param name="declaration">The declaration.</param>
        /// <param name="options">The options.</param>
        private void Annotate(IDeclaration declaration, ValueAnalysisOptions options)
        {
            if (!options.AnnotateWithValueAnalysisAttributes && !options.InsertAssertStatements)
              {
            return;
              }

              var typeMemberDeclaration = declaration as ITypeMemberDeclaration;
              if (typeMemberDeclaration == null)
              {
            return;
              }

              var refactoring = new ValueAnalysisRefactoring(typeMemberDeclaration);

              refactoring.AnnotateWithValueAnalysisAttributes = options.AnnotateWithValueAnalysisAttributes;
              refactoring.InsertAssertStatements = options.InsertAssertStatements;
              refactoring.TreatAllMembersAsNonPublic = options.TreatAllMembersAsNonPublic;

              refactoring.Execute();
        }
        /// <summary>
        /// Updates the summary to include all <c>typeparam</c> and remove any extra ones and in the correct order.
        /// </summary>
        /// <param name="declaration">
        /// The <see cref="ITypeDeclaration"/> to check and fix.
        /// </param>
        public void InsertMissingTypeParamElement(IDeclaration declaration)
        {
            ITypeParametersOwner declaredElement = declaration.DeclaredElement as ITypeParametersOwner;

            if (declaredElement == null)
            {
                return;
            }

            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            XmlNode xmlNode = declarationHeader.XmlNode;

            Hashtable ht = new Hashtable();

            foreach (ITypeParameter parameter in declaredElement.TypeParameters)
            {
                ht.Add(parameter.ShortName, null);

                if (declarationHeader.ContainsTypeParameter(parameter.ShortName))
                {
                    continue;
                }

                XmlNode parameterNode = CreateTypeParamNode(xmlNode, parameter.ShortName);

                XmlNodeList paramNodeList = xmlNode.SelectNodes("//typeparam");
                if (paramNodeList != null)
                {
                    XmlNode c = paramNodeList.Count == 0 ? declarationHeader.SummaryXmlNode : paramNodeList.Item(paramNodeList.Count - 1);

                    xmlNode.InsertAfter(parameterNode, c);
                }
            }

            RemoveTypeParamsNotRequired(xmlNode, ht);
            ReorderTypeParams(xmlNode, declaredElement.TypeParameters);
            declarationHeader.Update();
        }
        /// <summary>
        /// Takes the XmlNode and creates a formatted StringBuilder of it all formatted lovely.
        /// </summary>
        /// <param name="xml">
        /// The xml to use.
        /// </param>
        /// <param name="declaration">
        /// The declaration we start with.
        /// </param>
        /// <returns>
        /// A String all formatted.
        /// </returns>
        private static string LayoutDocumentationHeader(XmlNode xml, IDeclaration declaration)
        {
            StringBuilder pattern = new StringBuilder();
            StringWriter writer = new StringWriter(pattern);

            bool writtenNewLine = true;
            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, declaration.GetSolution());
            bool useSingleLineDeclarationComments = settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.UseSingleLineDeclarationComments);

            LayoutDocumentationXml(xml, writer, ref writtenNewLine, useSingleLineDeclarationComments);

            if (pattern.ToString().EndsWith(Environment.NewLine))
            {
                pattern.Remove(pattern.Length - Environment.NewLine.Length, Environment.NewLine.Length);
            }

            if (pattern.ToString().StartsWith(Environment.NewLine))
            {
                pattern.Remove(0, Environment.NewLine.Length);
            }

            return pattern.ToString().Trim();
        }
        /// <summary>
        /// Insert a missing parameter element to the comment.
        /// </summary>
        /// <param name="declaration">
        /// The <see cref="IDeclaration"/> to check and fix.
        /// </param>
        public void InsertMissingParamElement(IDeclaration declaration)
        {
            Param.RequireNotNull(declaration, "declaration");

            IParametersOwnerDeclaration parametersOwnerDeclaration = declaration as IParametersOwnerDeclaration;

            if (parametersOwnerDeclaration == null)
            {
                return;
            }

            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            XmlNode xmlNode = declarationHeader.XmlNode;
            Hashtable ht = new Hashtable();

            IList<IParameterDeclaration> parameters = parametersOwnerDeclaration.ParameterDeclarations;

            if (parameters != null)
            {
                foreach (IParameterDeclaration parameter in parameters)
                {
                    ht.Add(parameter.DeclaredName, null);

                    if (declarationHeader.ContainsParameter(parameter.DeclaredName))
                    {
                        continue;
                    }

                    XmlNodeList paramNodeList = xmlNode.SelectNodes("//param");
                    if (paramNodeList != null)
                    {
                        XmlNode c = paramNodeList.Count == 0 ? declarationHeader.SummaryXmlNode : paramNodeList.Item(paramNodeList.Count - 1);

                        XmlNode parameterNode = CreateParamNode(xmlNode, parameter);

                        xmlNode.InsertAfter(parameterNode, c);
                    }
                }
            }

            RemoveParamsNotRequired(xmlNode, ht);
            ReorderParams(xmlNode, parameters);
            declarationHeader.Update();
        }
        /// <summary>
        /// Returns the xml for the given declaration or null.
        /// </summary>
        /// <param name="declaration">
        /// The declaration to get the docs for.
        /// </param>
        /// <returns>
        /// An XmlNode of the docs.
        /// </returns>
        private static XmlNode GetXmlNodeForDeclaration(IDeclaration declaration)
        {
            IDeclaration declarationTreeNode = declaration;

            ITreeNode treeNode = declarationTreeNode is IMultipleDeclarationMember ? declarationTreeNode.Parent.FirstChild : declarationTreeNode.FirstChild;

            XmlNode node;
            StringBuilder text = new StringBuilder();

            text.AppendLine("<member>");

            for (ITreeNode child = treeNode.FirstChild; child != null; child = child.NextSibling)
            {
                if (child.IsNewLine())
                {
                    text.AppendLine(string.Empty);
                    continue;
                }

                IDocCommentNode docCommentNode = child as IDocCommentNode;
                if (docCommentNode != null)
                {
                    text.Append(docCommentNode.CommentText);
                }
            }

            text.AppendLine("</member>");
            try
            {
                XmlDocument xmlDoc = new XmlDocument { PreserveWhitespace = true };
                xmlDoc.LoadXml(text.ToString());
                node = xmlDoc.SelectSingleNode("member");
            }
            catch (XmlException)
            {
                return null;
            }

            return node;
        }
        /// <summary>
        /// Formats a summary element.
        /// </summary>
        /// <param name="declaration">
        /// The <see cref="IDeclaration"/> to format the text for.
        /// </param>
        public void FormatSummaryElement(IDeclaration declaration)
        {
            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited || declarationHeader.HasEmptySummary || !declarationHeader.HasSummary)
            {
                return;
            }

            declarationHeader.Update();
        }
        /// <summary>
        /// Ensures the declaration passed has its comments beginning with a capital letter.
        /// </summary>
        /// <param name="declaration">
        /// The destructor <see cref="IDeclaration"/>.
        /// </param>
        public void EnsureDocumentationTextIsUppercase(IDeclaration declaration)
        {
            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, declaration.GetSolution());
            if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                return;
            }

            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            this.SwapToUpper(declarationHeader.XmlNode);
            declarationHeader.Update();
        }
        /// <summary>
        /// Ensures the declaration passed has no blank lines unless inside code elements.
        /// </summary>
        /// <param name="declaration">
        /// The destructor <see cref="IDeclaration"/>.
        /// </param>
        public void EnsureDocumentationHasNoBlankLines(IDeclaration declaration)
        {
            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return;
            }

            this.RemoveBlankLines(declarationHeader.XmlNode);
            declarationHeader.Update();
        }
 /// <summary>
 /// Initializes a new instance of the DeclarationHeader class.
 /// </summary>
 /// <param name="declaration">
 /// The declaration to use.
 /// </param>
 public DeclarationHeader(IDeclaration declaration)
 {
     this.Init(declaration);
 }
        /// <summary>
        /// Initializes this type.
        /// </summary>
        /// <param name="declaration">
        /// The declaration.
        /// </param>
        private void Init(IDeclaration declaration)
        {
            if (declaration == null)
            {
                this.IsMissing = true;
                return;
            }

            this.Declaration = declaration;

            this.DocCommentBlockNode = Utils.GetDocCommentBlockNodeForDeclaration(declaration);
            if (this.DocCommentBlockNode == null)
            {
                this.IsMissing = true;
            }
            else
            {
                this.XmlNode = GetXmlNodeForDeclaration(declaration);

                if (this.XmlNode == null)
                {
                    this.IsMissing = true;
                }
                else
                {
                    if (this.XmlNode.SelectSingleNode("//inheritdoc") != null)
                    {
                        this.IsInherited = true;
                    }

                    XmlNode node = this.XmlNode.SelectSingleNode("//summary");
                    if (node != null)
                    {
                        this.HasSummary = true;
                        this.SummaryXmlNode = node;
                    }

                    node = this.XmlNode.SelectSingleNode("//returns");
                    if (node != null)
                    {
                        this.HasReturns = true;
                        this.ReturnsXmlNode = node;
                    }

                    node = this.XmlNode.SelectSingleNode("//value");
                    if (node != null)
                    {
                        this.HasValue = true;
                        this.ValueXmlNode = node;
                    }
                }
            }
        }
        /// <summary>
        /// Inserts a missing summary element.
        /// </summary>
        /// <param name="declaration">
        /// The <see cref="IDeclaration"/> to get comment from.
        /// </param>
        /// <returns>
        /// True if the element was inserted.
        /// </returns>
        public bool InsertMissingSummaryElement(IDeclaration declaration)
        {
            bool returnValue = false;
            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            if (declarationHeader.IsMissing || declarationHeader.IsInherited)
            {
                return false;
            }

            string summaryText = string.Empty;
            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, declaration.GetSolution());
            if (settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation))
            {
                string text;
                if (declaration is IInterfaceDeclaration)
                {
                    text = declaration.DeclaredName.Substring(1) + " interface";
                }
                else
                {
                    text = Utils.ConvertTextToSentence(declaration.DeclaredName).ToLower();
                }

                summaryText = string.Format("The {0}.", text);
            }

            summaryText = Utils.UpdateTextWithToDoPrefixIfRequired(summaryText, settingsStore);

            XmlNode summaryXmlNode = declarationHeader.SummaryXmlNode;

            if (declarationHeader.HasSummary)
            {
                if (declarationHeader.HasEmptySummary)
                {
                    summaryXmlNode.InnerText = summaryText;
                    declarationHeader.Update();
                    returnValue = true;
                }
            }
            else
            {
                XmlNode newChild = CreateNode(declarationHeader.XmlNode, "summary");
                newChild.InnerText = summaryText;
                declarationHeader.XmlNode.InsertBefore(newChild, declarationHeader.XmlNode.FirstChild);
                declarationHeader.Update();
                returnValue = true;
            }

            return returnValue;
        }
        /// <summary>
        /// Checks declaration comment blocks.
        /// </summary>
        /// <param name="file">
        /// The <see cref="ICSharpFile"/> to use.
        /// </param>
        /// <param name="declaration">
        /// The <see cref="IDeclaration"/> to check.
        /// </param>
        /// <param name="options">
        /// <see cref="OrderingOptions"/>Current options that we can reference.
        /// </param>
        public void CheckDeclarationDocumentation(ICSharpFile file, IDeclaration declaration, DocumentationOptions options)
        {
            Param.RequireNotNull(file, "file");
            Param.RequireNotNull(declaration, "declaration");
            Param.Ignore(options);

            bool insertMissingElementDocOption = true;
            bool documentationTextMustBeginWithACapitalLetter = true;
            bool documentationTextMustEndWithAPeriod = true;
            bool elementDocumentationMustHaveSummary = true;
            bool constructorSummaryDocBeginsWithStandardText = true;
            bool destructorSummaryDocBeginsWithStandardText = true;
            bool propertyDocumentationMustHaveValueDocumented = true;
            bool insertMissingParamTagOption = true;
            bool genericTypeParametersMustBeDocumented = true;

            if (options != null)
            {
                insertMissingElementDocOption = options.SA1600ElementsMustBeDocumented;
                documentationTextMustBeginWithACapitalLetter = options.SA1628DocumentationTextMustBeginWithACapitalLetter;
                documentationTextMustEndWithAPeriod = options.SA1629DocumentationTextMustEndWithAPeriod;
                elementDocumentationMustHaveSummary = options.SA1604ElementDocumentationMustHaveSummary;
                constructorSummaryDocBeginsWithStandardText = options.SA1642ConstructorSummaryDocumentationMustBeginWithStandardText;
                destructorSummaryDocBeginsWithStandardText = options.SA1643DestructorSummaryDocumentationMustBeginWithStandardText;
                propertyDocumentationMustHaveValueDocumented = options.SA1609PropertyDocumentationMustHaveValue;
                insertMissingParamTagOption = options.SA1611ElementParametersMustBeDocumented;
                genericTypeParametersMustBeDocumented = options.SA1618GenericTypeParametersMustBeDocumented;
            }

            DeclarationHeader declarationHeader = new DeclarationHeader(declaration);

            bool formatSummary = false;
            if (insertMissingElementDocOption && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1600) && declarationHeader.IsMissing)
            {
                formatSummary = this.InsertMissingDeclarationHeader(file, declaration);
            }

            if (elementDocumentationMustHaveSummary && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1604) && !declarationHeader.HasSummary)
            {
                formatSummary = formatSummary | this.InsertMissingSummaryElement(declaration);
            }

            if (formatSummary)
            {
                this.FormatSummaryElement(declaration);
            }

            if (declaration is IConstructorDeclaration)
            {
                if (insertMissingParamTagOption && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1611))
                {
                    IConstructorDeclaration constructorDeclaration = declaration as IConstructorDeclaration;

                    if (constructorDeclaration.ParameterDeclarations.Count > 0)
                    {
                        this.InsertMissingParamElement(constructorDeclaration);
                    }
                }

                if (constructorSummaryDocBeginsWithStandardText && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1642))
                {
                    this.EnsureConstructorSummaryDocBeginsWithStandardText(declaration as IConstructorDeclaration);
                }
            }

            DocumentationRulesConfiguration docConfig = this.GetDocumentationRulesConfig(file);

            // However it can be on/off depending on the file so we'd have to cache it per file
            bool ruleIsEnabled = docConfig.GetStyleCopRuleEnabled("DocumentationTextMustBeginWithACapitalLetter");

            if (documentationTextMustBeginWithACapitalLetter && ruleIsEnabled && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1628))
            {
                this.EnsureDocumentationTextIsUppercase(declaration);
            }

            ruleIsEnabled = docConfig.GetStyleCopRuleEnabled("DocumentationTextMustEndWithAPeriod");

            if (documentationTextMustEndWithAPeriod && ruleIsEnabled && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1629))
            {
                this.EnsureDocumentationTextEndsWithAPeriod(declaration);
            }

            if (declaration is IDestructorDeclaration)
            {
                if (destructorSummaryDocBeginsWithStandardText && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1643))
                {
                    this.EnsureDestructorSummaryDocBeginsWithStandardText(declaration as IDestructorDeclaration);
                }
            }

            if (declaration is IMethodDeclaration || declaration is IIndexerDeclaration)
            {
                this.CheckMethodAndIndexerDeclarationDocumentation(declaration as IParametersOwnerDeclaration, options);
            }

            if (declaration is IPropertyDeclaration)
            {
                ruleIsEnabled = docConfig.GetStyleCopRuleEnabled("PropertyDocumentationMustHaveValue");

                if (propertyDocumentationMustHaveValueDocumented && ruleIsEnabled && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1609))
                {
                    this.InsertValueElement(declaration as IPropertyDeclaration);
                }
            }

            if (declaration is ITypeParametersOwner && (genericTypeParametersMustBeDocumented && !Utils.IsRuleSuppressed(declaration, StyleCopRules.SA1618)))
            {
                this.InsertMissingTypeParamElement(declaration);
            }
        }
        /// <summary>
        /// Insert a summary element if missing.
        /// </summary>
        /// <param name="file">
        /// The <see cref="ICSharpFile"/> to use.
        /// </param>
        /// <param name="declaration">
        /// The <see cref="ITypeDeclaration"/> to check and fix.
        /// </param>
        /// <returns>
        /// True if it inserted a missing header.
        /// </returns>
        public bool InsertMissingDeclarationHeader(ICSharpFile file, IDeclaration declaration)
        {
            StyleCopTrace.In(file, declaration);
            Param.RequireNotNull(file, "file");
            Param.RequireNotNull(declaration, "declaration");
            Debug.Assert(declaration.DeclaredElement != null, "declaration.DeclaredElement != null");

            bool returnValue = false;
            DocumentationRulesConfiguration docConfig = this.GetDocumentationRulesConfig(file);

            bool isIFieldDeclaration = declaration is IFieldDeclaration;

            AccessRights accessRights = ((IModifiersOwnerDeclaration)declaration).GetAccessRights();

            DeclaredElementType elementType = declaration.DeclaredElement.GetElementType();
            if ((!isIFieldDeclaration || docConfig.RequireFields) && (accessRights != AccessRights.PRIVATE || !docConfig.IgnorePrivates)
                && (accessRights != AccessRights.INTERNAL || !docConfig.IgnoreInternals))
            {
                DeclarationHeader.CreateNewHeader(declaration, docConfig);
                returnValue = true;
            }

            return StyleCopTrace.Out(returnValue);
        }
        /// <summary>
        /// Builds a xml doc header from the string passed in all set out correctly.
        /// </summary>
        /// <param name="header">
        /// The text to use to build the header.
        /// </param>
        /// <param name="declaration">
        /// The declaration we start with.
        /// </param>
        /// <returns>
        /// A String of the correctly formatted header.
        /// </returns>
        private static string LayoutDocumentationHeader(string header, IDeclaration declaration)
        {
            StringBuilder text = new StringBuilder();
            text.AppendLine("<member>");
            text.AppendLine(header);
            text.AppendLine("</member>");

            XmlDocument xmlDoc = new XmlDocument { PreserveWhitespace = true };
            xmlDoc.LoadXml(text.ToString());

            return LayoutDocumentationHeader(xmlDoc.SelectSingleNode("member"), declaration);
        }