本文整理汇总了C#中DocumentRange.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentRange.IsValid方法的具体用法?C# DocumentRange.IsValid怎么用?C# DocumentRange.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentRange
的用法示例。
在下文中一共展示了DocumentRange.IsValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostfixTemplateAcceptanceContext
public PostfixTemplateAcceptanceContext([NotNull] ITreeNode reference,
[NotNull] ICSharpExpression expression, DocumentRange replaceRange,
bool forceMode, [NotNull] PostfixExecutionContext context)
{
myReparsedContext = context.ReparsedContext;
myMostInnerExpression = expression;
PostfixReferenceNode = reference;
ForceMode = forceMode;
PsiModule = context.PsiModule;
LookupItemsOwner = context.LookupItemsOwner;
MostInnerReplaceRange = replaceRange;
if (!replaceRange.IsValid())
{
var referenceExpression = reference as IReferenceExpression;
if (referenceExpression != null)
{
MostInnerReplaceRange =
ToDocumentRange(referenceExpression.QualifierExpression.NotNull()).SetEndTo(
ToDocumentRange(referenceExpression.Delimiter.NotNull()).TextRange.EndOffset);
}
var referenceName = reference as IReferenceName;
if (referenceName != null)
{
MostInnerReplaceRange =
ToDocumentRange(referenceName.Qualifier).SetEndTo(
ToDocumentRange(referenceName.Delimiter).TextRange.EndOffset);
}
}
// build expression contexts
var expressionContexts = new List<PrefixExpressionContext>();
var endOffset = Math.Max(
MostInnerReplaceRange.TextRange.EndOffset,
ToDocumentRange(reference).TextRange.EndOffset);
for (ITreeNode node = expression; node != null; node = node.Parent)
{
if (node is ICSharpStatement) break;
var expr = node as ICSharpExpression;
if (expr == null || expr == reference) continue;
var exprRange = myReparsedContext.ToDocumentRange(expr);
if (!exprRange.IsValid())
break; // stop when out of generated
if (exprRange.TextRange.EndOffset > endOffset)
break; // stop when 'a.var + b'
// skip relational expressions like this: 'List<int.{here}>'
if (CommonUtils.IsRelationalExpressionWithTypeOperand(expr)) continue;
var expressionContext = new PrefixExpressionContext(this, expr);
if (expressionContext.ReferencedElement is ITypeElement)
{
// skip types that are parts of 'List<T.>'-like expressions
if (!CommonUtils.CanTypeBecameExpression(expression)) continue;
}
expressionContexts.Add(expressionContext);
if (expressionContext.CanBeStatement) break;
}
Expressions = (expressionContexts.Count == 0)
? EmptyList<PrefixExpressionContext>.InstanceList
: expressionContexts.AsReadOnly();
}
示例2: Translate
public TreeTextRange Translate(DocumentRange documentRange) {
if (!documentRange.IsValid()
|| _sourceFile == null
|| !_sourceFile.IsValid())
return TreeTextRange.InvalidRange;
if (documentRange.Document != _sourceFile.Document) {
foreach (IT4Include include in _includes) {
if (include.DocumentRangeTranslator != null) {
TreeTextRange textRange = include.DocumentRangeTranslator.Translate(documentRange);
if (textRange.IsValid())
return textRange;
}
}
return TreeTextRange.InvalidRange;
}
TextRange range = documentRange.TextRange;
TreeOffset rootStartOffset = _root.GetTreeStartOffset();
// no includes, tree and document are matching
if (_includes.Count == 0)
return new TreeTextRange(rootStartOffset + range.StartOffset, rootStartOffset + range.EndOffset);
TreeOffset startOffset = Translate(range.StartOffset);
if (!startOffset.IsValid())
return TreeTextRange.InvalidRange;
TreeOffset endOffset = Translate(range.EndOffset);
if (!endOffset.IsValid())
return TreeTextRange.InvalidRange;
return new TreeTextRange(startOffset, endOffset);
}
示例3: FindDeclaredElement
private DeclaredElementInfo FindDeclaredElement(DocumentRange documentRange) {
IDocument document = documentRange.Document;
if (document == null || !documentRange.IsValid())
return null;
IPsiServices psiServices = _solution.GetPsiServices();
if (!psiServices.Files.AllDocumentsAreCommitted || psiServices.Caches.HasDirtyFiles)
return null;
return document
.GetPsiSourceFiles(_solution)
.SelectMany(
psiSourceFile => psiServices.Files.GetPsiFiles(psiSourceFile, documentRange),
(psiSourceFile, file) => FindDeclaredElement(documentRange, file))
.FirstOrDefault(info => info != null && info.DeclaredElement.IsValid());
}