/// <summary> /// We replace a field with a property to handle event subscription, so need to update the name so the winforms designer regenerates the file correctly in future /// </summary> /// <returns></returns> public static bool ShouldPrefixAssignedNameWithUnderscore(VBSyntax.StatementSyntax statementOrNull) { return(statementOrNull is VBSyntax.AssignmentStatementSyntax assignment && InMethodCalledInitializeComponent(assignment) && assignment.Left is VBSyntax.MemberAccessExpressionSyntax maes && !(maes.Expression is VBSyntax.MeExpressionSyntax) && maes.Name.ToString() == "Name"); }
public static CodeItem MapMember(VisualBasicSyntax.StatementSyntax member) { if (member == null) { return(null); } switch (member.Kind()) { case VisualBasic.SyntaxKind.FunctionBlock: case VisualBasic.SyntaxKind.SubBlock: return(MethodMapper.MapMethod(member as VisualBasicSyntax.MethodBlockSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.SubStatement: return(MethodMapper.MapMethod(member as VisualBasicSyntax.MethodStatementSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.EnumBlock: return(EnumMapper.MapEnum(member as VisualBasicSyntax.EnumBlockSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.EnumMemberDeclaration: return(EnumMapper.MapEnumMember(member as VisualBasicSyntax.EnumMemberDeclarationSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.InterfaceBlock: return(InterfaceMapper.MapInterface(member as VisualBasicSyntax.InterfaceBlockSyntax, _control, _semanticModel, _tree)); case VisualBasic.SyntaxKind.FieldDeclaration: return(FieldMapper.MapField(member as VisualBasicSyntax.FieldDeclarationSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.PropertyBlock: return(PropertyMapper.MapProperty(member as VisualBasicSyntax.PropertyBlockSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.StructureBlock: return(StructMapper.MapStruct(member as VisualBasicSyntax.StructureBlockSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.ClassBlock: case VisualBasic.SyntaxKind.ModuleBlock: return(ClassMapper.MapClass(member as VisualBasicSyntax.TypeBlockSyntax, _control, _semanticModel, _tree)); case VisualBasic.SyntaxKind.EventBlock: return(DelegateEventMapper.MapEvent(member as VisualBasicSyntax.EventBlockSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.DelegateFunctionStatement: return(DelegateEventMapper.MapDelegate(member as VisualBasicSyntax.DelegateStatementSyntax, _control, _semanticModel)); case VisualBasic.SyntaxKind.NamespaceBlock: return(NamespaceMapper.MapNamespace(member as VisualBasicSyntax.NamespaceBlockSyntax, _control, _semanticModel, _tree)); case VisualBasic.SyntaxKind.ConstructorBlock: return(MethodMapper.MapConstructor(member as VisualBasicSyntax.ConstructorBlockSyntax, _control, _semanticModel)); default: return(null); } }
private bool UnpackExpressionFromStatement(StatementSyntax statementSyntax, out ExpressionSyntax expression) { if (statementSyntax is ReturnStatementSyntax) { expression = ((ReturnStatementSyntax)statementSyntax).Expression; } else if (statementSyntax is YieldStatementSyntax) { expression = ((YieldStatementSyntax)statementSyntax).Expression; } else { expression = null; } return(expression != null); }
private static bool UnpackExpressionFromStatement(StatementSyntax statementSyntax, out ExpressionSyntax expression) { if (statementSyntax is ReturnStatementSyntax returnStmt) { expression = returnStmt.Expression; } else if (statementSyntax is YieldStatementSyntax yieldStmt) { expression = yieldStmt.Expression; } else { expression = null; } return(expression != null); }
private static bool TryGetNodeForeSingleLineLambdaExpression(SyntaxKind kind, StatementSyntax statement, out VisualBasicSyntaxNode singleNode) { switch (kind) { case SyntaxKind.SingleLineSubLambdaExpression when !(statement is MultiLineIfBlockSyntax): singleNode = statement; return(true); case SyntaxKind.SingleLineFunctionLambdaExpression when UnpackExpressionFromStatement(statement, out var expression): singleNode = expression; return(true); default: singleNode = null; return(false); } }
private static bool TryGetNodeForeSingleLineLambdaExpression(SyntaxKind kind, StatementSyntax statement, out VisualBasicSyntaxNode singleNode) { switch (kind) { case SyntaxKind.SingleLineSubLambdaExpression when statement.DescendantNodesAndSelf().OfType <StatementSyntax>().Count() == 1: singleNode = statement; return(true); case SyntaxKind.SingleLineFunctionLambdaExpression when UnpackExpressionFromStatement(statement, out var expression): singleNode = expression; return(true); default: singleNode = null; return(false); } }
public static List <CodeItem> MapStatement(VisualBasicSyntax.StatementSyntax statement, CodeViewUserControl control, SemanticModel semanticModel) { if (statement == null) { return(new List <CodeItem>()); } switch (statement.Kind()) { case VisualBasic.SyntaxKind.SelectBlock: return(new List <CodeItem> { MapSwitch(statement as VisualBasicSyntax.SelectBlockSyntax, control, semanticModel) }); case VisualBasic.SyntaxKind.TryStatement: return(MapStatement((statement as VisualBasicSyntax.TryBlockSyntax), control, semanticModel)); default: return(new List <CodeItem>()); } }
public override void VisitStatement(VBSyntax.StatementSyntax node, ExecutionState state, VariableState statementState, Configuration projectConfiguration) { if (!XssPreventionAnalyzer.ExecutionStates.ContainsKey(state)) { return; } var returnStatements = node.DescendantNodesAndSelf().OfType <VBSyntax.ReturnStatementSyntax>(); if (!returnStatements.Any()) { return; } if ((statementState.Taint & VariableTaint.Tainted) != 0 && (((ulong)statementState.Taint) & projectConfiguration.TaintTypeNameToBit["HtmlEscaped"]) == 0) { XssPreventionAnalyzer.Check(node, state, projectConfiguration, returnStatements); } }
public virtual void VisitStatement(VBSyntax.StatementSyntax node, ExecutionState state, Configuration projectConfiguration) { }
// (ii) Visual Basic public virtual void VisitStatement(VBSyntax.StatementSyntax node, ExecutionState state) { }