本文整理汇总了C#中IElement.ToTreeNode方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.ToTreeNode方法的具体用法?C# IElement.ToTreeNode怎么用?C# IElement.ToTreeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.ToTreeNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes the specified solution.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
protected override void Execute(IElement element)
{
Shell.Instance.Locks.AssertReadAccessAllowed();
var node = element.ToTreeNode();
if (node == null)
{
return;
}
IInvocationExpression invocationExpression = null;
while (node != null)
{
invocationExpression = node as IInvocationExpression;
if (invocationExpression != null)
{
break;
}
node = node.Parent;
}
if (invocationExpression == null)
{
return;
}
Execute(invocationExpression);
}
示例2: Execute
/// <summary>Executes the specified solution.</summary>
/// <param name="element">The element.</param>
protected override void Execute(IElement element)
{
var node = element.ToTreeNode();
if (node == null)
{
return;
}
IInvocationExpression invocationExpression = null;
while (node != null)
{
invocationExpression = node as IInvocationExpression;
if (invocationExpression != null)
{
break;
}
node = node.Parent;
}
if (invocationExpression == null)
{
return;
}
Execute(invocationExpression);
}
示例3: Populate
/// <summary>
/// Gets the nearest variable.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// The populated list.
/// </returns>
public static List<ScopeEntry> Populate(IElement element)
{
var result = new List<ScopeEntry>();
var node = element.ToTreeNode();
while (node != null)
{
GetLocalVariable(result, node);
var prevSibling = node.PrevSibling;
if (prevSibling == null)
{
node = node.Parent;
GetForEach(result, node);
GetFor(result, node);
GetFunctionParameters(result, node);
GetUsing(result, node);
}
else
{
node = prevSibling;
}
}
return result;
}
示例4: IsAvailable
/// <summary>Determines whether this instance is available.</summary>
/// <param name="element">The element.</param>
/// <returns><c>true</c> if this instance is available; otherwise, <c>false</c>.</returns>
public override bool IsAvailable(IElement element)
{
var text = element.GetText();
if (text != "abstract")
{
return false;
}
var parent = element.ToTreeNode().Parent;
if (parent == null)
{
return false;
}
var classNode = parent.Parent;
return classNode is IClassDeclaration;
}
示例5: IsAvailable
/// <summary>
/// Determines whether the specified solution is available.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// <c>true</c> if the specified solution is available; otherwise, <c>false</c>.
/// </returns>
public static bool IsAvailable(IElement element)
{
Shell.Instance.Locks.AssertReadAccessAllowed();
var typeMemberDeclaration = element.ToTreeNode().Parent as ITypeMemberDeclaration;
if (typeMemberDeclaration == null)
{
return false;
}
var function = typeMemberDeclaration.DeclaredElement as IFunction;
if (function == null)
{
return false;
}
var type = function.ReturnType;
var name = type.GetPresentableName(element.Language);
return name == "bool";
}
示例6: GetIndent
/// <summary>
/// Gets the indent.
/// </summary>
/// <param name="anchor">
/// The anchor.
/// </param>
/// <returns>
/// The indent.
/// </returns>
private static string GetIndent(IElement anchor)
{
var indent = string.Empty;
var whitespace = anchor.ToTreeNode().PrevSibling as IWhitespaceNode;
if (whitespace != null)
{
indent = whitespace.GetText();
}
return indent;
}
示例7: IsAvailable
/// <summary>
/// Determines whether the specified cache is available.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// <c>true</c> if the specified cache is available; otherwise, <c>false</c>.
/// </returns>
protected override bool IsAvailable(IElement element)
{
var node = element.ToTreeNode();
if (node == null)
{
return false;
}
IInvocationExpression invocationExpression = null;
while (node != null)
{
invocationExpression = node as IInvocationExpression;
if (invocationExpression != null)
{
break;
}
if (node is IStatement)
{
break;
}
node = node.Parent;
}
if (invocationExpression == null)
{
return false;
}
var exceptions = new List<string[]>();
GetExceptions(invocationExpression, exceptions);
return exceptions.Count > 0;
}
示例8: InsertAssertionCode
/// <summary>Inserts the assert.</summary>
/// <param name="assertion">The assertion.</param>
/// <param name="element">The element.</param>
private void InsertAssertionCode(string assertion, IElement element)
{
IStatement anchor = null;
string name;
var assignmentExpression = element as IAssignmentExpression;
if (assignmentExpression != null)
{
anchor = assignmentExpression.GetContainingStatement();
var referenceExpression = assignmentExpression.Dest as IReferenceExpression;
if (referenceExpression == null)
{
return;
}
name = referenceExpression.Reference.GetName();
}
else
{
var treeNode = element.ToTreeNode();
while (treeNode != null)
{
anchor = treeNode as IStatement;
if (anchor != null)
{
break;
}
treeNode = treeNode.Parent;
}
var localVariable = element as ILocalVariable;
if (localVariable == null)
{
return;
}
name = localVariable.ShortName;
}
if (anchor == null)
{
return;
}
var functionDeclaration = anchor.GetContainingTypeMemberDeclaration() as IMethodDeclaration;
if (functionDeclaration == null)
{
return;
}
var body = functionDeclaration.Body;
if (body == null)
{
return;
}
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
var csharpElement = element as ICSharpElement;
if (csharpElement == null)
{
return;
}
var code = string.Format(assertion, name);
var statement = factory.CreateStatement(code);
if (statement == null)
{
return;
}
var result = body.AddStatementAfter(statement, anchor);
var range = result.GetDocumentRange();
var codeFormatter = new CodeFormatter();
codeFormatter.Format(this.Solution, range);
}
示例9: Execute
/// <summary>
/// Executes this instance.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
protected override void Execute(IElement element)
{
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
if (factory == null)
{
return;
}
var parent = element.ToTreeNode().Parent;
if (parent == null)
{
return;
}
var classDeclaration = parent.Parent as IClassDeclaration;
if (classDeclaration == null)
{
return;
}
classDeclaration.SetAbstract(false);
var methodDeclarations = classDeclaration.MethodDeclarations;
foreach (var methodDeclaration in methodDeclarations)
{
if (!methodDeclaration.IsAbstract)
{
continue;
}
methodDeclaration.SetAbstract(false);
methodDeclaration.SetVirtual(true);
if (methodDeclaration.Body != null)
{
continue;
}
var block = factory.CreateEmptyBlock();
methodDeclaration.SetBody(block);
CSharpMemberBodyUtil.Instance.SetBodyToDefault(methodDeclaration);
}
var propertyDeclarations = classDeclaration.PropertyDeclarations;
foreach (var propertyDeclaration in propertyDeclarations)
{
if (!propertyDeclaration.IsAbstract)
{
continue;
}
propertyDeclaration.SetAbstract(false);
propertyDeclaration.SetVirtual(true);
foreach (var accessorDeclaration in propertyDeclaration.AccessorDeclarations)
{
if (accessorDeclaration.Body != null)
{
continue;
}
var block = factory.CreateEmptyBlock();
accessorDeclaration.SetBody(block);
CSharpPropertyBodyUtil.SetDefaultBody(accessorDeclaration);
}
}
}
示例10: ProcessElement
///<returns>
///True if further search is not needed
///</returns>
///
public bool ProcessElement(IElement element)
{
Logger.Assert(element != null, "The condition (element != null) is false.");
return (new ReferenceSearchSourceFileProcessor(this, element.ToTreeNode()).Run() == FindExecution.Stop);
}
示例11: Execute
/// <summary>
/// Executes the specified element.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// Returns the text range.
/// </returns>
private static global::JetBrains.Util.TextRange Execute(IElement element)
{
var typeMemberDeclaration = element.ToTreeNode().Parent as ICSharpTypeMemberDeclaration;
if (typeMemberDeclaration == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var classDeclaration = typeMemberDeclaration.GetContainingTypeDeclaration() as IClassDeclaration;
if (classDeclaration == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var text = typeMemberDeclaration.GetText();
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
if (factory == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var declaration = factory.CreateTypeMemberDeclaration(text) as IClassMemberDeclaration;
if (declaration == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var anchor = typeMemberDeclaration as IClassMemberDeclaration;
if (anchor == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var after = classDeclaration.AddClassMemberDeclarationAfter(declaration, anchor);
if (after != null)
{
var treeTextRange = after.GetNameRange();
return new global::JetBrains.Util.TextRange(treeTextRange.StartOffset.Offset, treeTextRange.EndOffset.Offset);
}
return global::JetBrains.Util.TextRange.InvalidRange;
}
示例12: ProcessElement
public bool ProcessElement(IElement element) {
return (new ReferenceSearchSourceFileProcessor(this, element.ToTreeNode()).Run() == FindExecution.Stop);
}
示例13: ProcessElementParametersOwner
private void ProcessElementParametersOwner(IElement element)
{
IDeclaredParametersOwner declaredParametersOwner = element as IDeclaredParametersOwner;
// TODO use get reference
if(declaredParametersOwner != null)
{
IParameterDescriptorProvider parameterDescriptorProvider = declaredParametersOwner as IParameterDescriptorProvider;
if (parameterDescriptorProvider == null)
return;
if(!parameterDescriptorProvider.IsAvailable)
return;
ICollection<IParameterDescriptor> infos = parameterDescriptorProvider.GetParameterDescriptors();
ICollection<IDeclaredParameter> declaredParameters = declaredParametersOwner.GetParams();
// Highlight invalid names
foreach (IDeclaredParameter param in declaredParameters)
{
if(ParametersUtil.GetByName(infos, param.Name) == null)
{
highlightings.Add(new HighlightingInfo(param.NameDocumentRange, new InvalidPropertyHighlighting()));
}
}
// Highlight requred attributes
IXmlTag tag = element as IXmlTag;
foreach (IParameterDescriptor descriptor in infos)
{
if(descriptor.IsRequired)
{
if(ParametersUtil.GetByName(declaredParameters, descriptor.Name) != null
// it is conxeption hak, TODO fix parameters conception
|| (tag != null && tag.GetAttribute(descriptor.Name) != null))
continue;
DocumentRange range;
if (tag != null)
range = GetHighlightRange(tag.ToTreeNode().Header);
else
range = element.ToTreeNode().GetDocumentRange();
highlightings.Add(new HighlightingInfo(range, new MissedParameterError(descriptor, element)));
}
}
// highlight invalid values
foreach (IDeclaredParameter param in declaredParameters)
{
IParameterDescriptor descriptor = ParametersUtil.GetByName(infos, param.Name);
if (descriptor == null)
continue;
IParameterStringValueValidator validator = ValidatorsManager.Instance().GetValidator(descriptor);
if (validator == null)
continue;
// TODO introduce interface marker to determine tag pased parameters
PropertyParamImpl propertyParam = param as PropertyParamImpl;
IXmlAttributeValue attributeValue = null;
if (propertyParam != null)
{
attributeValue = propertyParam.Value;
}
else // attribute
{
IXmlAttribute attribute = ((IXmlTag)declaredParametersOwner).GetAttribute(param.Name);
if (attribute != null)
attributeValue = attribute.Value;
}
if (attributeValue == null)
continue;
string unquotedValue = attributeValue.UnquotedValue;
ValidationResult validateResult = validator.Validate(unquotedValue);
if (validateResult == ValidationResult.Ok)
continue;
if(validateResult.Range == TextRange.InvalidRange)
continue;
int valueStart = attributeValue.ToTreeNode().GetDocumentRange().TextRange.StartOffset + 1;
TextRange valueRange = new TextRange(valueStart, valueStart + unquotedValue.Length);
int errorStart = valueRange.StartOffset + validateResult.Range.StartOffset;
TextRange errorRange = new TextRange(errorStart, errorStart + validateResult.Range.Length);
errorRange = valueRange.Intersect(errorRange);
if (errorRange == TextRange.InvalidRange)
continue;
if(errorRange.IsEmpty)
{
if (attributeValue.UnquotedValue.Length == 0)
{
//.........这里部分代码省略.........
示例14: Execute
/// <summary>
/// Executes this instance.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
protected override void Execute(IElement element)
{
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
if (factory == null)
{
return;
}
var statement = element.ToTreeNode().Parent as IForStatement;
if (statement == null)
{
return;
}
var localVariableDeclarations = statement.InitializerDeclarations;
if (localVariableDeclarations.Count != 1)
{
return;
}
var localVariableDeclaration = localVariableDeclarations[0];
if (localVariableDeclaration == null)
{
return;
}
var expressionInitializer = localVariableDeclaration.Initial as IExpressionInitializer;
if (expressionInitializer == null)
{
return;
}
var from = expressionInitializer.Value;
var relationalExpression = statement.Condition as IRelationalExpression;
if (relationalExpression == null)
{
return;
}
var to = relationalExpression.RightOperand;
var iterators = statement.IteratorExpressions;
if (iterators == null)
{
return;
}
if (iterators.Count != 1)
{
return;
}
var postfixOperatorExpression = iterators[0] as IPostfixOperatorExpression;
if (postfixOperatorExpression == null)
{
return;
}
if (postfixOperatorExpression.PostfixOperatorType == PostfixOperatorType.INVALID)
{
return;
}
if (postfixOperatorExpression.PostfixOperatorType == PostfixOperatorType.PLUSPLUS)
{
var expression = AddToExpression(factory, to, '-');
expressionInitializer.SetValue(expression);
var condition = GetCondition(factory, relationalExpression.LeftOperand, relationalExpression.OperatorSign.GetText(), from);
relationalExpression.ReplaceBy(condition);
var dec = factory.CreateExpression(string.Format("{0}--", postfixOperatorExpression.Operand.GetText()));
postfixOperatorExpression.ReplaceBy(dec);
}
else
{
var expression = AddToExpression(factory, from, '+');
expressionInitializer.SetValue(to);
var condition = GetCondition(factory, relationalExpression.LeftOperand, relationalExpression.OperatorSign.GetText(), expression);
relationalExpression.ReplaceBy(condition);
var inc = factory.CreateExpression(string.Format("{0}++", postfixOperatorExpression.Operand.GetText()));
postfixOperatorExpression.ReplaceBy(inc);
}
}
示例15: IsAvailable
/// <summary>
/// Determines whether this instance is available.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// <c>true</c> if this instance is available; otherwise, <c>false</c>.
/// </returns>
protected override bool IsAvailable(IElement element)
{
var statement = element.ToTreeNode().Parent as IForStatement;
if (statement == null)
{
return false;
}
var localVariableDeclarations = statement.InitializerDeclarations;
if (localVariableDeclarations.Count != 1)
{
return false;
}
var localVariableDeclaration = localVariableDeclarations[0];
if (localVariableDeclaration == null)
{
return false;
}
var localVariable = localVariableDeclaration.DeclaredElement as ILocalVariable;
if (localVariable == null)
{
return false;
}
if (localVariable.Type.GetPresentableName(element.Language) != "int")
{
return false;
}
var iterators = statement.IteratorExpressions;
if (iterators == null)
{
return false;
}
if (iterators.Count != 1)
{
return false;
}
var postfixOperatorExpression = iterators[0] as IPostfixOperatorExpression;
if (postfixOperatorExpression == null)
{
return false;
}
if (postfixOperatorExpression.PostfixOperatorType == PostfixOperatorType.INVALID)
{
return false;
}
return true;
}