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);
                }
            }
        }
Exemplo n.º 2
0
        private static string TryGetIndentFromStatement(
            [NotNull] ISecondaryRangeTranslator rangeTranslator,
            [NotNull] ITreeNode currentNode
            )
        {
            if (!(currentNode is IStatement))
            {
                return(null);
            }
            var token      = currentNode.GetFirstTokenIn();
            var tokenRange = token.GetDocumentRange();

            if (!tokenRange.IsValid())
            {
                return(null);
            }
            if (tokenRange.TextRange.EndOffset >= rangeTranslator.OriginalFile.GetTextLength())
            {
                return(null);
            }
            var generatedTokenRange = new TreeTextRange(token.GetTreeStartOffset());
            var originalTokenRange  = rangeTranslator.GeneratedToOriginal(generatedTokenRange);
            var t4Element           = rangeTranslator.OriginalFile.FindNodeAt(originalTokenRange);
            var otherCodeBlock      = t4Element?.GetParentOfType <IT4CodeBlock>();

            if (otherCodeBlock == null)
            {
                return(null);
            }
            return(tokenRange.GetIndentFromDocumentRange());
        }
Exemplo n.º 3
0
        public static T GetT4ContainerFromCSharpNode <T>([CanBeNull] this ITreeNode cSharpNode)
            where T : ITreeNode
        {
            ISecondaryRangeTranslator secondaryRangeTranslator = (cSharpNode?.GetContainingFile() as IFileImpl)?.SecondaryRangeTranslator;

            if (secondaryRangeTranslator == null)
            {
                return(default);
Exemplo n.º 4
0
 public T4SecondaryDocumentGenerationResult([NotNull] IPsiSourceFile sourceFile, [NotNull] string text, [NotNull] PsiLanguageType language,
                                            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] ILexerFactory lexerFactory,
                                            [NotNull] FileDependency fileDependency, [NotNull] OneToSetMap <FileSystemPath, FileSystemPath> includedFiles)
     : base(sourceFile, text, language, secondaryRangeTranslator, lexerFactory)
 {
     _fileDependency = fileDependency;
     _includedFiles  = includedFiles;
 }
 // ReSharper disable once UnusedParameter.Local
 public T4SecondaryDocumentGenerationResult([NotNull] IPsiSourceFile sourceFile, [NotNull] string text, [NotNull] PsiLanguageType language,
                                            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] ILexerFactory lexerFactory,
                                            [NotNull] T4FileDependencyManager t4FileDependencyManager, [NotNull] IEnumerable <FileSystemPath> includedFiles)
     : base(text, language, secondaryRangeTranslator, lexerFactory)
 {
     _sourceFile = sourceFile;
     _t4FileDependencyManager = t4FileDependencyManager;
     _includedFiles           = new HashSet <FileSystemPath>(includedFiles);
 }
Exemplo n.º 6
0
 private static bool HasStatementsBefore(
     [NotNull] ISecondaryRangeTranslator rangeTranslator,
     [NotNull] ITreeNode node
     ) => node.GetFirstTokenIn()
 .PrevTokens()
 .Where(token => !token.IsWhitespaceToken())
 .Select(token => token.GetTreeTextRange())
 .Select(rangeTranslator.GeneratedToOriginal)
 .Where(originalRange => originalRange.IsValid())
 .SelectNotNull(rangeTranslator.OriginalFile.FindNodeAt)
 .Any(it => it.GetParentOfType <IT4StatementBlock>() != null);
Exemplo n.º 7
0
        private static string CalculateRelativeIndentInTransformText(
            [NotNull] ITreeNode node,
            [NotNull] ISecondaryRangeTranslator rangeTranslator
            )
        {
            var firstToken          = node.GetFirstTokenIn();
            var generatedTreeRange1 = new TreeTextRange(firstToken.GetTreeStartOffset());
            var originalRange       = rangeTranslator.GeneratedToOriginal(generatedTreeRange1);

            if (!originalRange.IsValid())
            {
                return(null);
            }
            var t4Element = rangeTranslator.OriginalFile.FindNodeAt(originalRange);

            return(t4Element?.GetLineIndentFromOriginalNode(n =>
                                                            n is IT4Token token && token.GetTokenType() == T4TokenNodeTypes.RAW_CODE, originalRange.StartOffset));
        }
        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 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 void ProcessChangeFromPrimaryToGenerated(TreeTextRange range, string oldText, string newText, ISecondaryRangeTranslator rangeTranslator, IFile file, IPsiTransactionAction transactionAction)
 {
 }
 public void ProcessChangeFromPrimaryToGenerated(TreeTextRange range, string oldText, string newText, ISecondaryRangeTranslator rangeTranslator, IFile file, IPsiTransactionAction transactionAction)
 {
 }