本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatement类的具体用法?C# ExpressionStatement怎么用?C# ExpressionStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionStatement类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ExpressionStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrackedVisitConstructorDeclaration
public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
{
const string initializerBlock = "InitializerBlock";
if (constructorDeclaration.Name == initializerBlock)
{
TypeDeclaration type = (TypeDeclaration) constructorDeclaration.Parent;
string initName = "Init" + type.Name;
MethodDeclaration initMethod = GetInitMethod(type);
initMethod.Body.Children.AddRange(constructorDeclaration.Body.Children);
Expression initInvocation = new InvocationExpression(new IdentifierExpression(initName));
ExpressionStatement initInvocationStatement = new ExpressionStatement(initInvocation);
IList constructors = AstUtil.GetChildrenWithType(type, typeof(ConstructorDeclaration));
if (constructors.Count > 1)
{
foreach (ConstructorDeclaration constructor in constructors)
{
if (constructor.Name != initializerBlock && !HasInitInvocation(constructor))
constructor.Body.Children.Insert(0, initInvocationStatement);
}
}
else if (((ConstructorDeclaration) constructors[0]).Name == initializerBlock)
{
ConstructorDeclaration constructor = new ConstructorDeclaration(type.Name, Modifiers.Public, null, null);
constructor.Body = new BlockStatement();
constructor.Body.AddChild(initInvocationStatement);
type.AddChild(constructor);
}
RemoveCurrentNode();
}
return base.TrackedVisitConstructorDeclaration(constructorDeclaration, data);
}
示例2: TrackedVisitExpressionStatement
public override object TrackedVisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
IList list = new ArrayList();
base.TrackedVisitExpressionStatement(expressionStatement, list);
if (list.Count > 0)
RemoveCurrentNode();
return null;
}
示例3: TrackedVisitExpressionStatement
public override object TrackedVisitExpressionStatement(ExpressionStatement ExpressionStatement, object data)
{
IList removeStatement = new ArrayList();
base.TrackedVisitExpressionStatement(ExpressionStatement, removeStatement);
if (removeStatement.Count > 0 && data != null && data is IList)
((IList) data).Add(ExpressionStatement);
return null;
}
示例4: VisitExpressionStatement
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
tw.WriteStartElement("ExpressionStatement");
base.VisitExpressionStatement(expressionStatement, data);
tw.WriteEndElement();
return null;
}
示例5: VisitExpressionStatement
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
Contract.Requires(expressionStatement != null);
// Visit the expression of the expression statement (E.g InnvocationExpression)
expressionStatement.Expression.AcceptVisitor(this, null);
return null;
}
示例6: GetConstructor
private ConstructorDeclaration GetConstructor(ExpressionStatement expression, TypeDeclaration typeDeclaration)
{
ConstructorDeclaration constructorDeclaration;
constructorDeclaration = new ConstructorDeclaration(typeDeclaration.Name, Modifiers.Public, null, null);
constructorDeclaration.Body = new BlockStatement();
constructorDeclaration.Body.Children.Add(expression);
typeDeclaration.Children.Add(constructorDeclaration);
return constructorDeclaration;
}
示例7: GetArrayInitStatements
private List<Statement> GetArrayInitStatements(ArrayCreateExpression arrayCreateExpression, string variableName, List<Expression> initializerList)
{
List<Statement> list = new List<Statement>();
for (int idx = 0; idx < initializerList.Count; idx++)
{
AssignmentExpression assignment = InitArrayStatement(arrayCreateExpression, variableName, ((CollectionInitializerExpression) initializerList[idx]).CreateExpressions, idx);
ExpressionStatement expressionStatement = new ExpressionStatement(assignment);
list.Add(expressionStatement);
}
return list;
}
示例8: GenerateCode
protected override string GenerateCode(LanguageProperties language, IClass currentClass)
{
StringBuilder builder = new StringBuilder();
IDocumentLine line = editor.Document.GetLineForOffset(anchor.Offset);
string indent = DocumentUtilitites.GetWhitespaceAfter(editor.Document, line.Offset);
bool implementInterface = this.implementInterface.IsChecked == true;
bool hasOnPropertyChanged = HasOnPropertyChanged(currentClass);
bool useEventArgs = false;
if (implementInterface && !currentClass.IsStatic) {
if (!hasOnPropertyChanged) {
var nodes = new List<AbstractNode>();
var rt = new GetClassReturnType(currentClass.ProjectContent, "System.ComponentModel.INotifyPropertyChanged", 0);
if (!currentClass.ClassInheritanceTree.Any(bt => bt.FullyQualifiedName == "System.ComponentModel.INotifyPropertyChanged")) {
int insertion = editor.Document.PositionToOffset(currentClass.BodyRegion.BeginLine, currentClass.BodyRegion.BeginColumn);
if (currentClass.BaseTypes.Count > 0)
editor.Document.Insert(insertion, ", INotifyPropertyChanged");
else
editor.Document.Insert(insertion, " : INotifyPropertyChanged");
}
language.CodeGenerator.ImplementInterface(nodes, rt, false, currentClass);
var ev = rt.GetEvents().First(e => e.Name == "PropertyChanged");
MethodDeclaration onEvent = language.CodeGenerator.CreateOnEventMethod(new DefaultEvent(ev.Name, ev.ReturnType, ev.Modifiers, ev.Region, ev.BodyRegion, currentClass));
nodes.Add(onEvent);
onEvent.Parameters[0].TypeReference = new TypeReference("string", true);
onEvent.Parameters[0].ParameterName = "propertyName";
((RaiseEventStatement)onEvent.Body.Children[0]).Arguments[1] = new ObjectCreateExpression(new TypeReference("PropertyChangedEventArgs"), new List<Expression> { new IdentifierExpression("propertyName") });
foreach (var node in nodes)
builder.AppendLine(language.CodeGenerator.GenerateCode(node, indent));
useEventArgs = false;
} else {
useEventArgs = currentClass.DefaultReturnType.GetMethods().First(m => m.Name == "OnPropertyChanged").Parameters[0].ReturnType.FullyQualifiedName != "System.String";
}
}
foreach (FieldWrapper field in listBox.SelectedItems) {
var prop = language.CodeGenerator.CreateProperty(field.Field, true, field.AddSetter);
if (!field.Field.IsStatic && !currentClass.IsStatic && field.AddSetter && implementInterface) {
var invocation = new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs));
var assignment = prop.SetRegion.Block.Children[0];
prop.SetRegion.Block.Children.Clear();
prop.SetRegion.Block.AddChild(
new IfElseStatement(
new BinaryOperatorExpression(new IdentifierExpression(field.MemberName), BinaryOperatorType.InEquality, new IdentifierExpression("value")),
new BlockStatement { Children = { assignment, invocation } }
)
);
}
builder.AppendLine(language.CodeGenerator.GenerateCode(prop, indent));
}
return builder.ToString().Trim();
}
示例9: TrackedVisitFieldDeclaration
public override object TrackedVisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data)
{
VariableDeclaration field = (VariableDeclaration) fieldDeclaration.Fields[0];
TypeDeclaration typeDeclaration = (TypeDeclaration) fieldDeclaration.Parent;
NodeTypeExistenceVisitor nodeTypeExistenceVisitor = new NodeTypeExistenceVisitor(typeof(ThisReferenceExpression));
NodeTypeExistenceVisitor indexerNodeExistenceVisitor = new NodeTypeExistenceVisitor(typeof(IndexerExpression));
field.Initializer.AcceptVisitor(nodeTypeExistenceVisitor, null);
field.Initializer.AcceptVisitor(indexerNodeExistenceVisitor, null);
if (field.Initializer != null && (field.Initializer is InvocationExpression || IsArrayCreation(fieldDeclaration) || nodeTypeExistenceVisitor.Contains || indexerNodeExistenceVisitor.Contains)
&& !AstUtil.ContainsModifier(fieldDeclaration, Modifiers.Static))
{
IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
IdentifierExpression left = new IdentifierExpression(field.Name);
Expression right = field.Initializer;
AssignmentExpression assignmentExpression = new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
ExpressionStatement ExpressionStatement = new ExpressionStatement(assignmentExpression);
field.Initializer = null;
ConstructorDeclaration constructorDeclaration = null;
ExpressionStatement.Parent = constructorDeclaration;
foreach (ConstructorDeclaration consDec in constructors)
{
if (!AstUtil.ContainsModifier(consDec, Modifiers.Static))
{
if (consDec.Parameters.Count == 0)
{
constructorDeclaration = consDec;
constructorDeclaration.Body.Children.Add(ExpressionStatement);
constructorDeclaration.Parent = typeDeclaration;
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
else
{
consDec.ConstructorInitializer = new ConstructorInitializer();
consDec.ConstructorInitializer.ConstructorInitializerType = ConstructorInitializerType.This;
}
}
}
constructorDeclaration = GetConstructor(ExpressionStatement, typeDeclaration);
constructorDeclaration.Parent = typeDeclaration;
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
return base.TrackedVisitFieldDeclaration(fieldDeclaration, data);
}
示例10: VisitExpressionStatement
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
UnaryOperatorExpression uoe = expressionStatement.Expression as UnaryOperatorExpression;
if (uoe != null) {
switch (uoe.Op) {
case UnaryOperatorType.Increment:
case UnaryOperatorType.PostIncrement:
expressionStatement.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Add, new PrimitiveExpression(1, "1"));
break;
case UnaryOperatorType.Decrement:
case UnaryOperatorType.PostDecrement:
expressionStatement.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Subtract, new PrimitiveExpression(1, "1"));
break;
}
}
return base.VisitExpressionStatement(expressionStatement, data);
}
示例11: VisitExpressionStatement
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
base.VisitExpressionStatement(expressionStatement, data);
AssignmentExpression ass = expressionStatement.Expression as AssignmentExpression;
if (ass != null && ass.Right is AddressOfExpression) {
if (ass.Op == AssignmentOperatorType.Add) {
ReplaceCurrentNode(new AddHandlerStatement(ass.Left, ass.Right));
} else if (ass.Op == AssignmentOperatorType.Subtract) {
ReplaceCurrentNode(new RemoveHandlerStatement(ass.Left, ass.Right));
}
}
return null;
}
示例12: ResourceAcquisition
void ResourceAcquisition(
#line 1783 "cs.ATG"
out Statement stmt) {
#line 1785 "cs.ATG"
stmt = null;
Expression expr;
if (
#line 1790 "cs.ATG"
IsLocalVarDecl()) {
LocalVariableDecl(
#line 1790 "cs.ATG"
out stmt);
} else if (StartOf(6)) {
Expr(
#line 1791 "cs.ATG"
out expr);
#line 1795 "cs.ATG"
stmt = new ExpressionStatement(expr);
} else SynErr(204);
}
示例13: PerformChanges
public override List<Change> PerformChanges (RefactoringOptions options, object prop)
{
List<Change> result = new List<Change> ();
ExtractMethodParameters param = (ExtractMethodParameters)prop;
TextEditorData data = options.GetTextEditorData ();
INRefactoryASTProvider provider = options.GetASTProvider ();
IResolver resolver = options.GetResolver ();
ICSharpCode.NRefactory.Ast.INode node = Analyze (options, param, false);
if (param.VariablesToGenerate.Count > 0) {
TextReplaceChange varGen = new TextReplaceChange ();
varGen.Description = GettextCatalog.GetString ("Generate some temporary variables");
varGen.FileName = options.Document.FileName;
LineSegment line = data.Document.GetLine (Math.Max (0, data.Document.OffsetToLineNumber (data.SelectionRange.Offset) - 1));
varGen.Offset = line.Offset + line.EditableLength;
varGen.InsertedText = Environment.NewLine + options.GetWhitespaces (line.Offset);
foreach (VariableDescriptor var in param.VariablesToGenerate) {
TypeReference tr = options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ();
varGen.InsertedText += provider.OutputNode (options.Dom, new LocalVariableDeclaration (new VariableDeclaration (var.Name, null, tr))).Trim ();
}
result.Add (varGen);
}
InvocationExpression invocation = new InvocationExpression (new IdentifierExpression (param.Name));
foreach (VariableDescriptor var in param.Parameters) {
if (!param.OneChangedVariable && param.ChangedVariables.Contains (var.Name)) {
FieldDirection fieldDirection = FieldDirection.Ref;
VariableDescriptor outsideVar = null;
if (param.VariablesOutside.TryGetValue (var.Name, out outsideVar) && (var.GetsAssigned || param.VariablesToGenerate.Where (v => v.Name == var.Name).Any ())) {
if (!outsideVar.GetsAssigned)
fieldDirection = FieldDirection.Out;
}
invocation.Arguments.Add (new DirectionExpression (fieldDirection, new IdentifierExpression (var.Name)));
} else {
invocation.Arguments.Add (new IdentifierExpression (var.Name));
}
}
// string mimeType = DesktopService.GetMimeTypeForUri (options.Document.FileName);
TypeReference returnType = new TypeReference ("System.Void", true);
ICSharpCode.NRefactory.Ast.INode outputNode;
if (param.OneChangedVariable) {
string name = param.ChangedVariables.First ();
returnType = options.ShortenTypeName (param.Variables.Find (v => v.Name == name).ReturnType).ConvertToTypeReference ();
if (param.OutsideVariableList.Any (v => v.Name == name && !v.IsDefined)) {
LocalVariableDeclaration varDecl = new LocalVariableDeclaration (returnType);
varDecl.Variables.Add (new VariableDeclaration (name, invocation));
outputNode = varDecl;
} else {
outputNode = new ExpressionStatement (new AssignmentExpression (new IdentifierExpression (name), ICSharpCode.NRefactory.Ast.AssignmentOperatorType.Assign, invocation));
}
} else {
outputNode = node is BlockStatement ? (ICSharpCode.NRefactory.Ast.INode)new ExpressionStatement (invocation) : invocation;
}
TextReplaceChange replacement = new TextReplaceChange ();
replacement.Description = string.Format (GettextCatalog.GetString ("Substitute selected statement(s) with call to {0}"), param.Name);
replacement.FileName = options.Document.FileName;
replacement.Offset = options.Document.Editor.SelectionRange.Offset;
replacement.RemovedChars = options.Document.Editor.SelectionRange.Length;
replacement.MoveCaretToReplace = true;
LineSegment line1 = data.Document.GetLineByOffset (options.Document.Editor.SelectionRange.EndOffset);
if (options.Document.Editor.SelectionRange.EndOffset == line1.Offset) {
if (line1.Offset > 0) {
LineSegment line2 = data.Document.GetLineByOffset (line1.Offset - 1);
replacement.RemovedChars -= line2.DelimiterLength;
}
}
replacement.InsertedText = options.GetWhitespaces (options.Document.Editor.SelectionRange.Offset) + provider.OutputNode (options.Dom, outputNode).Trim ();
result.Add (replacement);
TextReplaceChange insertNewMethod = new TextReplaceChange ();
insertNewMethod.FileName = options.Document.FileName;
insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name);
insertNewMethod.RemovedChars = param.InsertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : param.InsertionPoint.Location.Column;
insertNewMethod.Offset = data.Document.LocationToOffset (param.InsertionPoint.Location) - insertNewMethod.RemovedChars;
ExtractMethodAstTransformer transformer = new ExtractMethodAstTransformer (param.VariablesToGenerate);
node.AcceptVisitor (transformer, null);
if (!param.OneChangedVariable && node is Expression) {
ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
if (resolveResult.ResolvedType != null)
returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference ();
}
MethodDeclaration methodDecl = new MethodDeclaration ();
methodDecl.Name = param.Name;
methodDecl.Modifier = param.Modifiers;
methodDecl.TypeReference = returnType;
if (!param.ReferencesMember)
methodDecl.Modifier |= ICSharpCode.NRefactory.Ast.Modifiers.Static;
if (node is BlockStatement) {
methodDecl.Body = new BlockStatement ();
methodDecl.Body.AddChild (new EmptyStatement ());
if (param.OneChangedVariable)
methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ())));
} else if (node is Expression) {
methodDecl.Body = new BlockStatement ();
methodDecl.Body.AddChild (new ReturnStatement (node as Expression));
}
//.........这里部分代码省略.........
示例14: VisitForeachStatement
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data)
{
base.VisitForeachStatement(foreachStatement, data);
if (resolver.CompilationUnit == null)
return null;
if (foreachStatement.TypeReference.IsNull) {
ResolveResult rr = resolver.ResolveIdentifier(foreachStatement.VariableName, foreachStatement.StartLocation, ExpressionContext.Default);
if (rr != null && rr.ResolvedType != null) {
BlockStatement blockStatement = foreachStatement.EmbeddedStatement as BlockStatement;
if (blockStatement == null) {
blockStatement = new BlockStatement();
blockStatement.AddChild(foreachStatement.EmbeddedStatement);
foreachStatement.EmbeddedStatement = blockStatement;
}
string newVariableName = foreachStatement.VariableName + "_loopVariable";
ExpressionStatement st = new ExpressionStatement(
new AssignmentExpression(
new IdentifierExpression(foreachStatement.VariableName),
AssignmentOperatorType.Assign,
new IdentifierExpression(newVariableName)));
blockStatement.Children.Insert(0, st);
st.Parent = blockStatement;
foreachStatement.VariableName = newVariableName;
foreachStatement.TypeReference = ConvertType(rr.ResolvedType);
}
}
return null;
}
示例15: StatementExpr
void StatementExpr(
#line 1799 "cs.ATG"
out Statement stmt) {
#line 1800 "cs.ATG"
Expression expr;
Expr(
#line 1802 "cs.ATG"
out expr);
#line 1805 "cs.ATG"
stmt = new ExpressionStatement(expr);
}