Exemple #1
0
        private string IndentFeatureBlockMember([NotNull] ITreeNode node, FmtSettings <CSharpFormatSettingsKey> settings)
        {
            // In feature blocks, there are class features declared
            if (!IsClassFeature(node))
            {
                return(null);
            }
            bool isTopLevel = node.Parent?.GetParentsOfType <IClassLikeDeclaration>().IsSingle() ?? false;

            if (!isTopLevel)
            {
                return(null);
            }
            return(settings.Settings.GetIndentStr());
        }
Exemple #2
0
 public string Indent(
     [NotNull] ITreeNode node,
     CustomIndentType indentType,
     [NotNull] FmtSettings <CSharpFormatSettingsKey> settings
     )
 {
     if (node == null)
     {
         throw new ArgumentNullException(nameof(node));
     }
     if (settings == null)
     {
         throw new ArgumentNullException(nameof(settings));
     }
     if (!node.IsPhysical())
     {
         return(null);
     }
     if (!IsInT4File(node))
     {
         return(null);
     }
     if (indentType == CustomIndentType.RelativeNodeCalculation)
     {
         return(node.GetIndentViaDocument());
     }
     if (IsEndComment(node))
     {
         return(IndentBlockEnd());
     }
     if (IsTransformTextMember(node))
     {
         return(IndentTransformTextMember(node, indentType, settings));
     }
     if (IsFeatureBlockMember(node))
     {
         return(IndentFeatureBlockMember(node, settings));
     }
     return(null);
 }
Exemple #3
0
        private string IndentTransformTextMember(
            [NotNull] ITreeNode node,
            CustomIndentType indentType,
            FmtSettings <CSharpFormatSettingsKey> settings
            )
        {
            var rangeTranslator = GetRangeTranslator(node);

            if (indentType == CustomIndentType.RelativeLineCalculation)
            {
                return(CalculateRelativeIndentInTransformText(node, rangeTranslator));
            }

            var statement = node as ICSharpStatement;

            if (node.GetTokenType() == CSharpTokenType.LBRACE)
            {
                statement = node.Parent as IBlock;
            }
            var block = BlockNavigator.GetByStatement(statement);

            if (node is IComment || node is IStartRegion || node is IEndRegion)
            {
                block = node.GetContainingNode <ITreeNode>() as IBlock;
            }
            if (block == null)
            {
                return(null);
            }

            var generatedTreeRange      = new TreeTextRange(node.GetTreeStartOffset());
            var blockGeneratedTreeRange = new TreeTextRange(block.GetTreeStartOffset());
            var originalRange           = rangeTranslator.GeneratedToOriginal(generatedTreeRange);
            var blockOriginalRange      = rangeTranslator.GeneratedToOriginal(blockGeneratedTreeRange);

            if (!originalRange.IsValid())
            {
                return(null);
            }

            var t4Element = rangeTranslator.OriginalFile.FindNodeAt(originalRange);
            var codeBlock = t4Element?.GetParentOfType <IT4CodeBlock>();

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

            string indentFromPreviousStatement = GetIndentFromPreviousStatement(node, rangeTranslator);

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

            if (blockOriginalRange.IsValid() && codeBlock.GetTreeTextRange().Contains(blockOriginalRange))
            {
                return(null);
            }
            var blockStart = codeBlock.GetTreeStartOffset();
            int nodeStart  = originalRange.StartOffset.Offset;

            if (!HasLineBreak(codeBlock, nodeStart, blockStart))
            {
                return(null);
            }
            if (HasStatementsBefore(rangeTranslator, node))
            {
                return(null);
            }
            return(settings.Settings.GetIndentStr());
        }