private static void ProcessT4FeatureBlock(
            [NotNull] IT4FeatureBlock featureBlock,
            [NotNull] CodeStructureElement parentElement,
            [NotNull] ICSharpFile cSharpFile,
            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator,
            [NotNull] CSharpCodeStructureProcessingState state
            )
        {
            TreeTextRange t4Range     = featureBlock.Code.GetTreeTextRange();
            TreeTextRange cSharpRange = secondaryRangeTranslator.OriginalToGenerated(t4Range);

            if (!cSharpRange.IsValid())
            {
                return;
            }

            TreeOffset cSharpStart = cSharpRange.StartOffset;
            TreeOffset cSharpEnd   = cSharpRange.EndOffset;

            ITreeNode containingNode = cSharpFile.FindNodeAt(cSharpRange);

            if (containingNode == null)
            {
                return;
            }

            for (ITreeNode node = containingNode.FirstChild; node != null; node = node.NextSibling)
            {
                TreeOffset nodeStart = node.GetTreeStartOffset();
                if (nodeStart >= cSharpStart && nodeStart < cSharpEnd)
                {
                    ProcessCSharpNode(node, parentElement, state);
                }
            }
        }
        public CodeStructureRootElement Build(IPsiSourceFile sourceFile, CodeStructureOptions options)
        {
            if (!(sourceFile.GetTheOnlyPsiFile(T4Language.Instance) is IT4File t4File))
            {
                return(null);
            }

            var cSharpFile = sourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance) as ICSharpFile;

            var secondaryRangeTranslator = (cSharpFile as IFileImpl)?.SecondaryRangeTranslator;

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

            var state = new CSharpCodeStructureProcessingState(CodeStructureOptions.Default);

            var rootElement = new T4CodeStructureRootElement(t4File);

            foreach (ITreeNode treeNode in t4File.Children())
            {
                ProcessT4Node(treeNode, rootElement, cSharpFile, secondaryRangeTranslator, state);
            }
            return(rootElement);
        }
Example #3
0
        public T4CSharpCodeStructureDeclaredElement(
            [NotNull] CodeStructureElement parentElement,
            [NotNull] IDeclaration declaration,
            [NotNull] CSharpCodeStructureProcessingState state
            )
            : base(parentElement, declaration)
        {
            IDeclaredElement declaredElement = declaration.DeclaredElement;

            InitiallyExpanded = true;

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

            _parentRegion = state.Regions.TryPeek();

            if (declaredElement != null)
            {
                _aspects = new T4CSharpCodeStructureAspects(this, declaration);
            }
        }
        private static void ProcessCSharpNode([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                              [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();

            var declaration = node as IDeclaration;

            if (declaration != null)
            {
                if (!declaration.IsSynthetic())
                {
                    ProcessCSharpDeclaration(declaration, parentElement, state);
                }
                return;
            }

            var multiDeclaration = node as IMultipleDeclaration;

            if (multiDeclaration != null)
            {
                ProcessCSharpMultipleDeclaration(multiDeclaration, parentElement, state);
                return;
            }

            var preprocessorDirective = node as IPreprocessorDirective;

            if (preprocessorDirective != null)
            {
                ProcessCSharpPreprocessorDirective(preprocessorDirective, parentElement, state);
            }
        }
 private static void ProcessCSharpChildren([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                           [NotNull] CSharpCodeStructureProcessingState state)
 {
     foreach (ITreeNode childNode in node.Children())
     {
         ProcessCSharpNode(childNode, parentElement, state);
     }
 }
Example #6
0
 public T4CSharpCodeStructureNamespace(
     [NotNull] CodeStructureElement parentElement,
     [NotNull] IDeclaration declaration,
     [NotNull] CSharpCodeStructureProcessingState state
     )
     : base(parentElement, declaration, state)
 {
 }
 public T4CSharpCodeStructureRegion(
     [NotNull] CodeStructureElement parentElement,
     [NotNull] ITreeNode preprocessorDirective,
     [NotNull] CSharpCodeStructureProcessingState state
     )
     : base(parentElement, preprocessorDirective, state)
 {
     _parentRegion = state.Regions.TryPeek();
 }
 private static void ProcessCSharpMultipleDeclaration([NotNull] IMultipleDeclaration declaration, [NotNull] CodeStructureElement parentElement,
                                                      CSharpCodeStructureProcessingState state)
 {
     foreach (IMultipleDeclarationMember declarationMember in declaration.Declarators)
     {
         if (!declarationMember.IsSynthetic())
         {
             ProcessCSharpDeclaration(declarationMember, parentElement, state);
         }
     }
 }
        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;
            }
            }
        }
		public CodeStructureRootElement Build(IPsiSourceFile sourceFile, CodeStructureOptions options) {
			var t4File = sourceFile.GetTheOnlyPsiFile(T4Language.Instance) as IT4File;
			if (t4File == null)
				return null;

			// TODO: handle VB
			var cSharpFile = sourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance) as ICSharpFile;
			var cSharpFileImpl = cSharpFile as IFileImpl;
			if (cSharpFileImpl == null || cSharpFileImpl.SecondaryRangeTranslator == null)
				return null;

			var state = new CSharpCodeStructureProcessingState(CodeStructureOptions.Default);

			var rootElement = new T4CodeStructureRootElement(t4File);
			foreach (ITreeNode treeNode in t4File.Children())
				ProcessT4Node(treeNode, rootElement, cSharpFile, cSharpFileImpl.SecondaryRangeTranslator, state);
			return rootElement;
		}
        private static void ProcessCSharpPreprocessorDirective(
            [NotNull] IPreprocessorDirective preprocessorDirective,
            [NotNull] CodeStructureElement parentElement,
            [NotNull] CSharpCodeStructureProcessingState state
            )
        {
            switch (preprocessorDirective.Kind)
            {
            case PreprocessorDirectiveKind.REGION:
                state.Regions.Push(new T4CSharpCodeStructureRegion(parentElement, preprocessorDirective, state));
                break;

            case PreprocessorDirectiveKind.ENDREGION:
                state.Regions.TryPop();
                new T4CSharpCodeStructureRegionEnd(parentElement, preprocessorDirective, state);
                break;
            }
        }
        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);
        }
		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);
		}
        private void ProcessT4Node(
            [NotNull] ITreeNode node,
            [NotNull] CodeStructureElement parentElement,
            [NotNull] ICSharpFile cSharpFile,
            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator,
            [NotNull] CSharpCodeStructureProcessingState state
            )
        {
            InterruptableActivityCookie.CheckAndThrow();

            switch (node)
            {
            case IT4Directive directive:
                ProcessT4Directive(directive, parentElement);
                return;

            case IT4FeatureBlock featureBlock:
                ProcessT4FeatureBlock(featureBlock, parentElement, cSharpFile, secondaryRangeTranslator, state);
                break;
            }
        }
        private static void ProcessCSharpNode([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                              [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();

            switch (node)
            {
            case IDeclaration declaration:
                if (!declaration.IsSynthetic())
                {
                    ProcessCSharpDeclaration(declaration, parentElement, state);
                }
                return;

            case IMultipleDeclaration multiDeclaration:
                ProcessCSharpMultipleDeclaration(multiDeclaration, parentElement, state);
                return;

            case IPreprocessorDirective preprocessorDirective:
                ProcessCSharpPreprocessorDirective(preprocessorDirective, parentElement, state);
                break;
            }
        }
        private void ProcessT4Node([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement, [NotNull] ICSharpFile cSharpFile,
                                   [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();


            var directive = node as IT4Directive;

            if (directive != null)
            {
                ProcessT4Directive(directive, parentElement);
                return;
            }

            var featureBlock = node as T4FeatureBlock;

            if (featureBlock != null)
            {
                ProcessT4FeatureBlock(featureBlock, parentElement, cSharpFile, secondaryRangeTranslator, state);
            }
        }
 public T4CSharpCodeStructureRegionEnd(CodeStructureElement parentElement, ITreeNode preprocessorDirective, CSharpCodeStructureProcessingState state)
     : base(parentElement, preprocessorDirective)
 {
     _parentRegion = state.Regions.TryPeek();
 }
		public T4CSharpCodeStructureRegionEnd(CodeStructureElement parentElement, ITreeNode preprocessorDirective, CSharpCodeStructureProcessingState state)
			: base(parentElement, preprocessorDirective) {
			_parentRegion = state.Regions.TryPeek();
		}
 private static void ProcessCSharpMultipleDeclaration([NotNull] IMultipleDeclaration declaration, [NotNull] CodeStructureElement parentElement,
     CSharpCodeStructureProcessingState state)
 {
     foreach (IMultipleDeclarationMember declarationMember in declaration.Declarators) {
         if (!declarationMember.IsSynthetic())
             ProcessCSharpDeclaration(declarationMember, parentElement, state);
     }
 }