本文整理汇总了C#中IElement.GetContainingElement方法的典型用法代码示例。如果您正苦于以下问题:C# IElement.GetContainingElement方法的具体用法?C# IElement.GetContainingElement怎么用?C# IElement.GetContainingElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IElement
的用法示例。
在下文中一共展示了IElement.GetContainingElement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Executes this instance.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
protected override void Execute(IElement element)
{
var classDeclaration = element.GetContainingElement<IClassDeclaration>(true);
var functionDeclaration = element.GetContainingElement<IMethodDeclaration>(true);
if (functionDeclaration != null)
{
functionDeclaration.SetAbstract(true);
functionDeclaration.SetVirtual(false);
functionDeclaration.SetBody(null);
}
var propertyDeclaration = element.GetContainingElement<IPropertyDeclaration>(true);
if (propertyDeclaration != null)
{
propertyDeclaration.SetAbstract(true);
propertyDeclaration.SetVirtual(false);
var accessorDeclarations = propertyDeclaration.AccessorDeclarations;
foreach (var accessorDeclaration in accessorDeclarations)
{
accessorDeclaration.SetBody(null);
}
}
if (classDeclaration == null)
{
return;
}
classDeclaration.SetAbstract(true);
}
示例2: GetPreviousStatement
public static IStatement GetPreviousStatement(IElement element)
{
var block = element.GetContainingElement(typeof(IBlock), true) as IBlock;
if (block == null)
{
return null;
}
var statement = element.GetContainingElement(typeof(IStatement), true);
if (statement != null && !block.Contains(statement))
{
return null;
}
return GetPreviousStatement(block, element);
}
示例3: GetNewStatementPosition
/// <summary>
/// Gets the new statement position.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// The new statement position.
/// </returns>
public static global::JetBrains.Util.TextRange GetNewStatementPosition(IElement element)
{
var block = element.GetContainingElement(typeof(IBlock), true) as IBlock;
if (block == null)
{
return global::JetBrains.Util.TextRange.InvalidRange;
}
var statement = element.GetContainingElement(typeof(IStatement), true) as IStatement;
if (statement != null && statement != block && block.Contains(statement))
{
var range = statement.GetTreeTextRange();
return new global::JetBrains.Util.TextRange(range.EndOffset.Offset + 1);
}
return global::JetBrains.Util.TextRange.InvalidRange;
}
示例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>
protected override bool IsAvailable(IElement element)
{
var ifStatement = element.GetContainingElement<IIfStatement>(true);
if (ifStatement == null)
{
return false;
}
IExpression condition = ifStatement.Condition;
if (condition == null)
{
return false;
}
if (!condition.Contains(element))
{
return false;
}
return true;
}
示例5: GetText
/// <summary>
/// Gets the text.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// Returns the string.
/// </returns>
private static string GetText(IElement element)
{
var typeMemberDeclaration = element.GetContainingElement<ITypeMemberDeclaration>(true);
if (typeMemberDeclaration == null)
{
return null;
}
var parametersOwner = typeMemberDeclaration.DeclaredElement as IParametersOwner;
if (parametersOwner == null)
{
return null;
}
if (parametersOwner.Parameters.Count == 0)
{
return null;
}
var first = true;
var parametersBuilder = new StringBuilder();
foreach (var parameter in parametersOwner.Parameters)
{
if (!first)
{
parametersBuilder.Append(", ");
}
first = false;
parametersBuilder.Append(parameter.ShortName);
}
return parametersBuilder.ToString();
}
示例6: PerformValueAnalysis
/// <summary>
/// Performs the value analysis.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <param name="type">
/// The type parameter.
/// </param>
/// <param name="range">
/// The range.
/// </param>
/// <param name="name">
/// The variable name.
/// </param>
private void PerformValueAnalysis(IElement element, IType type, global::JetBrains.Util.TextRange range, string name)
{
if (!type.IsReferenceType())
{
return;
}
var functionDeclaration = element.GetContainingElement(typeof(IFunctionDeclaration), true) as ICSharpFunctionDeclaration;
if (functionDeclaration == null)
{
return;
}
var expression = element.GetContainingElement(typeof(IReferenceExpression), true) as IReferenceExpression;
if (expression == null)
{
return;
}
var graf = CSharpControlFlowBuilder.Build(functionDeclaration);
var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC);
var state = inspect.GetExpressionNullReferenceState(expression);
switch (state)
{
case CSharpControlFlowNullReferenceState.UNKNOWN:
this.AddAction("Check if '{0}' is null", "F802DB32-A0B1-4227-BE5C-E7D20670284B", range, name);
break;
case CSharpControlFlowNullReferenceState.NOT_NULL:
break;
case CSharpControlFlowNullReferenceState.NULL:
this.AddAction("Check if '{0}' is null", "F802DB32-A0B1-4227-BE5C-E7D20670284B", range, name);
break;
case CSharpControlFlowNullReferenceState.MAY_BE_NULL:
break;
}
}
示例7: GetExpressionNullReferenceState
/// <summary>
/// Gets the state.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <param name="name">
/// The variable name.
/// </param>
/// <returns>
/// The null reference state.
/// </returns>
private static CSharpControlFlowNullReferenceState GetExpressionNullReferenceState(IElement element, string name)
{
const CSharpControlFlowNullReferenceState UNKNOWN = CSharpControlFlowNullReferenceState.UNKNOWN;
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
var statement = factory.CreateStatement("if(" + name + " == null) { }");
var anchorSatement = StatementUtil.GetPreviousStatement(element);
var block = element.GetContainingElement(typeof(IBlock), true) as IBlock;
if (block == null)
{
return UNKNOWN;
}
var ifStatement = block.AddStatementAfter(statement, anchorSatement) as IIfStatement;
if (ifStatement == null)
{
return UNKNOWN;
}
var equalityExpression = ifStatement.Condition as IEqualityExpression;
if (equalityExpression == null)
{
return UNKNOWN;
}
var referenceExpression = equalityExpression.LeftOperand as IReferenceExpression;
if (referenceExpression == null)
{
return UNKNOWN;
}
var functionDeclaration = ifStatement.GetContainingElement<ICSharpFunctionDeclaration>(true);
if (functionDeclaration == null)
{
return UNKNOWN;
}
var graf = CSharpControlFlowBuilder.Build(functionDeclaration);
var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC);
return inspect.GetExpressionNullReferenceState(referenceExpression);
}
示例8: Negate
/// <summary>
/// Reverses the specified element.
/// </summary>
/// <param name="element">
/// The element.
/// </param>
private static void Negate(IElement element)
{
var ifStatement = element.GetContainingElement<IIfStatement>(true);
if (ifStatement == null)
{
return;
}
IExpression condition = ifStatement.Condition;
if (condition == null)
{
return;
}
var factory = CSharpElementFactory.GetInstance(element.GetPsiModule());
if (factory == null)
{
return;
}
var equalityExpression = ifStatement.Condition as IEqualityExpression;
if (equalityExpression != null)
{
NegateEqualityExpression(factory, equalityExpression);
return;
}
var relationalExpression = ifStatement.Condition as IRelationalExpression;
if (relationalExpression != null)
{
NegateRelationalExpression(factory, relationalExpression);
return;
}
var unaryOperatorExpression = ifStatement.Condition as IUnaryOperatorExpression;
if (unaryOperatorExpression != null)
{
NegateUnaryExpression(factory, unaryOperatorExpression);
return;
}
var invocationExpression = ifStatement.Condition as IInvocationExpression;
if (invocationExpression != null)
{
NegateInvocationExpression(factory, invocationExpression);
return;
}
var literalExpression = ifStatement.Condition as ILiteralExpression;
if (literalExpression != null)
{
NegateLiteralExpression(factory, literalExpression);
return;
}
NegateExpression(factory, ifStatement.Condition);
}
示例9: IsAfterLastStatement
/// <summary>
/// Determines whether [is after last statement] [the specified element].
/// </summary>
/// <param name="element">
/// The element.
/// </param>
/// <returns>
/// <c>true</c> if [is after last statement] [the specified element]; otherwise, <c>false</c>.
/// </returns>
public static bool IsAfterLastStatement(IElement element)
{
var block = element.GetContainingElement(typeof(IBlock), true) as IBlock;
if (block == null)
{
return false;
}
if (block.Statements.Count <= 0)
{
return true;
}
var statement = block.Statements[block.Statements.Count - 1];
var range = statement.GetDocumentRange();
var end = range.TextRange.StartOffset + range.TextRange.Length;
if (end > element.GetTreeTextRange().StartOffset.Offset)
{
return false;
}
return true;
}
示例10: 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 text = element.GetText();
if (text != "virtual")
{
return false;
}
var functionDeclaration = element.GetContainingElement<IFunctionDeclaration>(true);
if (functionDeclaration != null)
{
return true;
}
var propertyDeclaration = element.GetContainingElement<IPropertyDeclaration>(true);
if (propertyDeclaration != null)
{
return true;
}
return false;
}