private Method TraverseAccessVars(AssignmentStatementSyntax vnes) { Method retMethod = new Method(); if (vnes.Left is IdentifierNameSyntax) { Variables retVar = new Variables(); retVar.IsReferenced = true; retVar.Name = (vnes.Left as IdentifierNameSyntax).Identifier.ValueText; retMethod.AccessedVariables.Add(retVar); } else if (vnes.Left is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = vnes.Left as MemberAccessExpressionSyntax; Variables retVar = new Variables(); retVar.Name = maes.ToString(); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } else { foreach (SyntaxNode sn in vnes.Left.ChildNodes()) { if (sn is VariableDeclaratorSyntax) { Variables retVar = new Variables(); retVar = TraverseVariableSyntax(sn as VariableDeclaratorSyntax, null, null); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } else if (sn is CallStatementSyntax) { retMethod.InvokedMethods.Add(TraverseInvokedMethod(sn as CallStatementSyntax)); } else if (sn is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = sn as MemberAccessExpressionSyntax; Variables retVar = new Variables(); retVar.Name = maes.ToString(); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } } } if (vnes.Right is IdentifierNameSyntax) { Variables retVar = new Variables(); retVar.IsReferenced = true; retVar.Name = (vnes.Right as IdentifierNameSyntax).Identifier.ValueText; retMethod.AccessedVariables.Add(retVar); } else if (vnes.Right is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = vnes.Right as MemberAccessExpressionSyntax; Variables retVar = new Variables(); retVar.Name = maes.ToString(); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } else { foreach (SyntaxNode sn in vnes.Right.ChildNodes()) { if (sn is VariableDeclaratorSyntax) { Variables retVar = new Variables(); retVar = TraverseVariableSyntax(sn as VariableDeclaratorSyntax, null, null); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } else if (sn is CallStatementSyntax) { retMethod.InvokedMethods.Add(TraverseInvokedMethod(sn as CallStatementSyntax)); } else if (sn is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = sn as MemberAccessExpressionSyntax; Variables retVar = new Variables(); retVar.Name = maes.ToString(); retVar.IsReferenced = true; retMethod.AccessedVariables.Add(retVar); } } } return retMethod; }
private Method TraverseVarDecls(LocalDeclarationStatementSyntax ldss) { Method retMethod = new Method(); List<Encapsulation> accessability = new List<Encapsulation>(); List<Qualifiers> qualifiers = new List<Qualifiers>(); foreach (SyntaxToken st in ldss.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { accessability.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { qualifiers.Add(qual); } } foreach (SyntaxNode ss in ldss.ChildNodes()) { if (ss is VariableDeclaratorSyntax) { Variables retVar = new Variables(); retVar = TraverseVariableSyntax(ss as VariableDeclaratorSyntax, accessability, qualifiers); retMethod.AccessedVariables.Add(retVar); } else if (ss is CallStatementSyntax) { retMethod.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax)); } } return retMethod; }
private InvokedMethod TraverseInvokedMethod(CallStatementSyntax css) { InvokedMethod invokedMethod = new InvokedMethod(); InvocationExpressionSyntax invokeInfo = css.Invocation as InvocationExpressionSyntax; if (invokeInfo.ArgumentList != null) { foreach (ArgumentSyntax argSyn in invokeInfo.ArgumentList.Arguments) { Variables parameter = new Variables(); parameter.Name = argSyn.ToString(); invokedMethod.Parameters.Add(parameter); } } ExpressionSyntax es = invokeInfo.Expression; if (es is IdentifierNameSyntax) { invokedMethod.Name = (es as IdentifierNameSyntax).Identifier.ValueText; } else if(es is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = es as MemberAccessExpressionSyntax; invokedMethod.Name = (maes.Name as SimpleNameSyntax).Identifier.ValueText; //TODO: What about the expression? Is it a variable? I think so!? } return invokedMethod; }
private Variables TraverseParameters(ParameterSyntax vds) { Variables retVar = new Variables(); retVar.Name = vds.Identifier.ToString(); retVar.IsReferenced = false; //Encapsulation foreach (SyntaxToken st in vds.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { retVar.Accessibility.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { retVar.Qualifiers.Add(qual); } } AsClauseSyntax acs = vds.AsClause; TypeSyntax ts = acs.Type(); Model.Type type = new Model.Type(); type.Name = ts.ToString(); type.IsKnownType = SyntaxFacts.IsKeywordKind(ts.VisualBasicKind()); type.IsNotUserDefined = SyntaxFacts.IsKeywordKind(ts.VisualBasicKind()); return retVar; }
private ForEachStatement TraverseForeachStatement(ForEachStatementSyntax fess, ref int returnCnt, bool nested = false) { ForEachStatement foreachStm = new ForEachStatement(); foreachStm.IsNested = nested; foreachStm.ConditionCount = 1; bool skipId = false; int skipIds = 0; foreach (SyntaxNode sn in fess.ChildNodes()) { if (sn is BinaryExpressionSyntax) { foreachStm.ConditionCount++; } else if (sn is VariableDeclaratorSyntax) { foreachStm.AccessedVars.Add(TraverseVariableSyntax(sn as VariableDeclaratorSyntax, null, null)); skipId = true; } else if (sn is InvocationExpressionSyntax) { InvokedMethod invokedMethod = TraverseInvokedMethod(sn as InvocationExpressionSyntax); foreachStm.InvokedMethods.Add(invokedMethod); skipId = true; skipIds = invokedMethod.Parameters.Count; } else if (sn is IdentifierNameSyntax) { if (!skipId) { Variables variable = new Variables(); variable.IsReferenced = true; variable.Name = (sn as IdentifierNameSyntax).Identifier.ValueText; foreachStm.AccessedVars.Add(variable); } else if (skipIds == 0) { skipId = false; } else { skipIds--; } } } ForBlockSyntax fbs = fess.Parent as ForBlockSyntax; foreach (StatementSyntax ss in fbs.Statements) { if (ss is AssignmentStatementSyntax) { //TODO: need to look at more than just then name! Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax); foreachStm.AccessedVars.AddRange(tempMethod.AccessedVariables); foreachStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is LocalDeclarationStatementSyntax) { Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax); foreachStm.AccessedVars.AddRange(tempMethod.AccessedVariables); foreachStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is SingleLineIfStatementSyntax) { Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true); foreachStm.Nested.AddRange(decision.IfStatements); foreachStm.Nested.AddRange(decision.ElseStatements); } else if (ss is MultiLineIfBlockSyntax) { Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true); foreachStm.Nested.AddRange(decisions.IfStatements); foreachStm.Nested.AddRange(decisions.ElseStatements); } else if (ss is ForBlockSyntax) { Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true); foreachStm.Nested.AddRange(tempDecision.IfStatements); foreachStm.Nested.AddRange(tempDecision.ElseStatements); foreachStm.Nested.AddRange(tempDecision.ForEachStatements); foreachStm.Nested.AddRange(tempDecision.ForStatements); foreachStm.Nested.AddRange(tempDecision.WhileLoops); foreachStm.Nested.AddRange(tempDecision.DoWhileLoops); foreachStm.Nested.AddRange(tempDecision.Catches); foreachStm.Nested.AddRange(tempDecision.SwitchStatements); } else if (ss is ElseStatementSyntax) { foreachStm.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true)); } else if (ss is SelectBlockSyntax) { foreachStm.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true)); } else if (ss is DoLoopBlockSyntax) { foreachStm.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true)); } else if (ss is WhileBlockSyntax) { foreachStm.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true)); } else if (ss is CallStatementSyntax) { foreachStm.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax)); } else if (ss is ReturnStatementSyntax) { Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax); foreachStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); foreachStm.AccessedVars.AddRange(tempMethod.AccessedVariables); returnCnt++; } } return foreachStm; }
private IfStatement TraverseIfStatement(IfPartSyntax slips, ref int returnCnt, bool nested = false) { IfStatement ifStm = new IfStatement(); ifStm.IsNested = nested; IfStatementSyntax iss = slips.Begin; BinaryExpressionSyntax bes = iss.Condition as BinaryExpressionSyntax; if (bes != null) { foreach (SyntaxNode sn in bes.DescendantNodesAndSelf()) { if (sn is BinaryExpressionSyntax) { ifStm.ConditionCount++; } else if (sn is IdentifierNameSyntax) { Variables variable = new Variables(); variable.IsReferenced = true; variable.Name = (sn as IdentifierNameSyntax).Identifier.ValueText; ifStm.AccessedVars.Add(variable); } } } foreach (StatementSyntax ss in slips.Statements) { if (ss is AssignmentStatementSyntax) { //TODO: need to look at more than just then name! Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax); ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is LocalDeclarationStatementSyntax) { Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax); ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is SingleLineIfStatementSyntax) { Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true); ifStm.Nested.AddRange(decision.IfStatements); ifStm.Nested.AddRange(decision.ElseStatements); } else if (ss is MultiLineIfBlockSyntax) { Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true); ifStm.Nested.AddRange(decisions.IfStatements); ifStm.Nested.AddRange(decisions.ElseStatements); } else if (ss is ForBlockSyntax) { Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true); ifStm.Nested.AddRange(tempDecision.IfStatements); ifStm.Nested.AddRange(tempDecision.ElseStatements); ifStm.Nested.AddRange(tempDecision.ForEachStatements); ifStm.Nested.AddRange(tempDecision.ForStatements); ifStm.Nested.AddRange(tempDecision.WhileLoops); ifStm.Nested.AddRange(tempDecision.DoWhileLoops); ifStm.Nested.AddRange(tempDecision.Catches); ifStm.Nested.AddRange(tempDecision.SwitchStatements); } else if (ss is ElseStatementSyntax) { ifStm.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true)); } else if (ss is SelectBlockSyntax) { ifStm.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true)); } else if (ss is DoLoopBlockSyntax) { ifStm.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true)); } else if (ss is WhileBlockSyntax) { ifStm.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true)); } else if (ss is CallStatementSyntax) { ifStm.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax)); } else if (ss is ReturnStatementSyntax) { Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); returnCnt++; } } //!!!!!!!!!!!!!!!!!!Start Here!!!!!!!!!!!!!!!!!!!!!!! return ifStm; }
private Method TraverseVarDeclarators(VariableDeclaratorSyntax vds) { Method retMethod = new Method(); Variables retVar = new Variables(); if (vds.HasLeadingTrivia) { SetOuterComments(retVar, vds.GetLeadingTrivia().ToFullString()); } if (vds.HasTrailingTrivia) { SetInnerComments(retVar, vds.GetTrailingTrivia().ToFullString()); } retVar.Name = vds.Identifier.ValueText; Model.Type retType = new Model.Type(); retType.IsKnownType = SyntaxFacts.IsKeywordKind(vds.CSharpKind()); retType.IsNotUserDefined = SyntaxFacts.IsKeywordKind(vds.CSharpKind()); retVar.Type = retType; retMethod.AccessedVariables.Add(retVar); var valueClauses = from aValueClase in vds.ChildNodes().OfType<EqualsValueClauseSyntax>() select aValueClase; foreach (EqualsValueClauseSyntax evcs in valueClauses) { retMethod.AccessedVariables.AddRange(TraverseEqualsClause(evcs).AccessedVariables); } //TODO //Don't know if I need more stuff here //or even if i can fetch it from vds return retMethod; }
private Variables TransverseVariables(FieldDeclarationSyntax fds, bool isRef = false) { Variables retVar = new Variables(); if (fds.HasLeadingTrivia) { SetOuterComments(retVar, fds.GetLeadingTrivia().ToFullString()); } if (fds.HasTrailingTrivia) { SetInnerComments(retVar, fds.GetTrailingTrivia().ToFullString()); } retVar.IsReferenced = isRef; //Not sure if right retVar.Type.IsKnownType = SyntaxFacts.IsKeywordKind(fds.CSharpKind()); retVar.Type.IsNotUserDefined = SyntaxFacts.IsKeywordKind(fds.CSharpKind()); //This should pick up the "type" name retVar.Type.Name = fds.Declaration.Type.ToString(); foreach (SyntaxToken st in fds.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { retVar.Accessibility.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { retVar.Qualifiers.Add(qual); } } //This does return variable name but I don't know if fds can contain a list of //variables or if it will always be 1 retVar.Name = fds.Declaration.Variables.ToString(); return retVar; }
private Variables TraverseParamaters(ParameterSyntax ps, bool isRef = false) { Variables retVar = new Variables(); if (ps.HasLeadingTrivia) { SetOuterComments(retVar, ps.GetLeadingTrivia().ToFullString()); } if (ps.HasTrailingTrivia) { SetInnerComments(retVar, ps.GetTrailingTrivia().ToFullString()); } retVar.IsReferenced = isRef; TypeSyntax ts = ps.Type; //Breakpoint here to test return type! Model.Type retType = new Model.Type(); retType.Name = ts.ToString(); retType.IsKnownType = SyntaxFacts.IsKeywordKind(ts.CSharpKind()); retType.IsNotUserDefined = SyntaxFacts.IsKeywordKind(ts.CSharpKind()); //rettype.generictype retVar.Type = retType; foreach (SyntaxToken st in ps.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { retVar.Accessibility.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { retVar.Qualifiers.Add(qual); } else if (modifier == "Ref") { //TODO handle ref } } //need retvar's name //TODO check if this actually works retVar.Name = ps.Identifier.ValueText; return retVar; }
private Method TraversePrefixUnaryExpressions(PrefixUnaryExpressionSyntax pues) { Method retMethod = new Method(); if (pues.HasLeadingTrivia) { SetOuterComments(retMethod, pues.GetLeadingTrivia().ToFullString()); } if (pues.HasTrailingTrivia) { SetInnerComments(retMethod, pues.GetTrailingTrivia().ToFullString()); } var vars = from aVar in pues.ChildNodes().OfType<IdentifierNameSyntax>() select aVar; foreach (IdentifierNameSyntax ins in vars) { Variables tempVar = new Variables(); tempVar.Name = ins.Identifier.ValueText; retMethod.AccessedVariables.Add(tempVar); } return retMethod; }
private Method TraverseInvocationExpression(InvocationExpressionSyntax ies) { //TODO //get method name and accessed variables //and attributes and qualifiers Method retIm = new Method(); if (ies.HasLeadingTrivia) { SetOuterComments(retIm, ies.GetLeadingTrivia().ToFullString()); } if (ies.HasTrailingTrivia) { SetInnerComments(retIm, ies.GetTrailingTrivia().ToFullString()); } //havent tested this with extra stuff like setting the variable equal to the method call //or with variables in the method call var methods = from aMethod in ies.ChildNodes().OfType<IdentifierNameSyntax>() select aMethod; foreach (IdentifierNameSyntax ins in methods) { InvokedMethod tempMethod = new InvokedMethod(); tempMethod.Name = ins.Identifier.ValueText; retIm.InvokedMethods.Add(tempMethod); } //var args = from aArg in ies.ArgumentList.Arguments.OfType<ArgumentSyntax>() select aArg; //foreach (ArgumentSyntax asyn in args) //{ // Variables tempVar = new Variables(); //} var args = from aArg in ies.Expression.ChildNodes().OfType<IdentifierNameSyntax>() select aArg; foreach (IdentifierNameSyntax ins in args) { Variables tempVar = new Variables(); tempVar.Name = ins.Identifier.ValueText; retIm.AccessedVariables.Add(tempVar); } retIm.Name = ies.Expression.ToString(); return retIm; }
private Method TraverseCastExpressions(CastExpressionSyntax ces) { Method retMethod = new Method(); if (ces.HasLeadingTrivia) { SetOuterComments(retMethod, ces.GetLeadingTrivia().ToFullString()); } if (ces.HasTrailingTrivia) { SetInnerComments(retMethod, ces.GetTrailingTrivia().ToFullString()); } var variables = from aVariable in ces.ChildNodes().OfType<IdentifierNameSyntax>() select aVariable; Model.Type type = new Model.Type(); type.Name = ces.Type.ToString(); type.IsKnownType = SyntaxFacts.IsKeywordKind(ces.Type.CSharpKind()); type.IsNotUserDefined = SyntaxFacts.IsKeywordKind(ces.Type.CSharpKind()); foreach (IdentifierNameSyntax ins in variables) { //TODO put a bp here and test if this adds method names (bad) or just var names(good) Variables vars = new Variables(); vars.Name = ins.Identifier.ValueText; vars.IsReferenced = true; vars.Type = type; retMethod.AccessedVariables.Add(vars); } var binaryExprs = from aBinaryExpr in ces.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpr; foreach (BinaryExpressionSyntax bes in binaryExprs) { Method retMethod2 = TraverseBinaryExpression(bes); retMethod.AccessedVariables.AddRange(retMethod2.AccessedVariables); retMethod.InvokedMethods.AddRange(retMethod2.InvokedMethods); } var invokedMethods = from aInvokedMethod in ces.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod; foreach (InvocationExpressionSyntax ies in invokedMethods) { Method tempMethod = TraverseInvocationExpression(ies); retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods); retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables); } var castExprs = from aCastExpr in ces.ChildNodes().OfType<CastExpressionSyntax>() select aCastExpr; foreach (CastExpressionSyntax ces2 in castExprs) { Method retMethod3 = TraverseCastExpressions(ces2); retMethod.AccessedVariables.AddRange(retMethod3.AccessedVariables); retMethod.InvokedMethods.AddRange(retMethod3.InvokedMethods); } return retMethod; }
private Method TraverseBinaryExpression(BinaryExpressionSyntax bes) { var variables = from aVariable in bes.ChildNodes().OfType<IdentifierNameSyntax>() select aVariable; Method retMethod = new Method(); if (bes.HasLeadingTrivia) { SetOuterComments(retMethod, bes.GetLeadingTrivia().ToFullString()); } if (bes.HasTrailingTrivia) { SetInnerComments(retMethod, bes.GetTrailingTrivia().ToFullString()); } //Casting on the back end....ex: // abc = def as double ------- def as double is the binary expression if (bes.OperatorToken.IsKind(SyntaxKind.AsKeyword)) { if (bes.Left is IdentifierNameSyntax) { IdentifierNameSyntax ins = bes.Left as IdentifierNameSyntax; Variables tempVar = new Variables(); tempVar.Name = ins.Identifier.ValueText; if (bes.Right is PredefinedTypeSyntax) { PredefinedTypeSyntax pts = bes.Right as PredefinedTypeSyntax; Model.Type tempType = new Model.Type(); tempType.Name = pts.ToString(); tempType.IsKnownType = true; tempType.IsNotUserDefined = true; tempVar.Type = tempType; } retMethod.AccessedVariables.Add(tempVar); } else if (bes.Left is MemberAccessExpressionSyntax) { MemberAccessExpressionSyntax maes = bes.Left as MemberAccessExpressionSyntax; Variables tempVar = new Variables(); tempVar.Name = maes.ToString(); tempVar.IsReferenced = true; retMethod.AccessedVariables.Add(tempVar); } } else { foreach (IdentifierNameSyntax ins in variables) { //TODO put a bp here and test if this adds method names (bad) or just var names(good) Variables vars = new Variables(); vars.Name = ins.Identifier.ValueText; vars.IsReferenced = true; retMethod.AccessedVariables.Add(vars); //TODO variable types } var binaryExprs = from aBinaryExpr in bes.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpr; foreach (BinaryExpressionSyntax bes2 in binaryExprs) { Method retMethod2 = TraverseBinaryExpression(bes2); retMethod.AccessedVariables.AddRange(retMethod2.AccessedVariables); retMethod.InvokedMethods.AddRange(retMethod2.InvokedMethods); } var invokedMethods = from aInvokedMethod in bes.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod; foreach (InvocationExpressionSyntax ies in invokedMethods) { Method tempMethod = TraverseInvocationExpression(ies); retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods); retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables); } var castExprs = from aCastExpr in bes.ChildNodes().OfType<CastExpressionSyntax>() select aCastExpr; foreach (CastExpressionSyntax ces in castExprs) { Method retMethod3 = TraverseCastExpressions(ces); retMethod.AccessedVariables.AddRange(retMethod3.AccessedVariables); retMethod.InvokedMethods.AddRange(retMethod3.InvokedMethods); } } return retMethod; }
private Variables TraverseVariableSyntax(VariableDeclaratorSyntax vds, List<Encapsulation> accessability, List<Qualifiers> qualifiers) { Variables retVar = new Variables(); if (accessability != null) { retVar.Accessibility = accessability; } if (qualifiers != null) { retVar.Qualifiers = qualifiers; } foreach (ModifiedIdentifierSyntax mis in vds.Names) { retVar.Name = retVar.Name == null ? mis.Identifier.ValueText : retVar.Name + "." + mis.Identifier.ValueText; } AsClauseSyntax acs = vds.AsClause; TypeSyntax ts = acs.Type(); Model.Type type = new Model.Type(); type.Name = ts.ToString(); type.IsKnownType = SyntaxFacts.IsKeywordKind(ts.VisualBasicKind()); type.IsNotUserDefined = SyntaxFacts.IsKeywordKind(ts.VisualBasicKind()); return retVar; }
private Variables TraverseField(FieldDeclarationSyntax fds) { Variables retVar = new Variables(); //Name //Encapsulation foreach (SyntaxToken st in fds.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { retVar.Accessibility.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { retVar.Qualifiers.Add(qual); } } return retVar; }
private DoWhileLoop TraverseDoWhileLoop(DoLoopBlockSyntax dbs, ref int returnCnt, bool nested = false) { DoWhileLoop doWhileLoop = new DoWhileLoop(); DoStatementSyntax dss = dbs.DoStatement; doWhileLoop.IsNested = nested; foreach (SyntaxNode sn in dss.DescendantNodesAndSelf()) { if (sn is BinaryExpressionSyntax) { doWhileLoop.ConditionCount++; } else if (sn is IdentifierNameSyntax) { Variables variable = new Variables(); variable.IsReferenced = true; variable.Name = (sn as IdentifierNameSyntax).Identifier.ValueText; doWhileLoop.AccessedVars.Add(variable); } } foreach (StatementSyntax ss in dbs.Statements) { if (ss is AssignmentStatementSyntax) { //TODO: need to look at more than just then name! Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax); doWhileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables); doWhileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is LocalDeclarationStatementSyntax) { Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax); doWhileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables); doWhileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is SingleLineIfStatementSyntax) { Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true); doWhileLoop.Nested.AddRange(decision.IfStatements); doWhileLoop.Nested.AddRange(decision.ElseStatements); } else if (ss is MultiLineIfBlockSyntax) { Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true); doWhileLoop.Nested.AddRange(decisions.IfStatements); doWhileLoop.Nested.AddRange(decisions.ElseStatements); } else if (ss is ElseStatementSyntax) { doWhileLoop.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true)); } else if (ss is ForBlockSyntax) { Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true); doWhileLoop.Nested.AddRange(tempDecision.IfStatements); doWhileLoop.Nested.AddRange(tempDecision.ElseStatements); doWhileLoop.Nested.AddRange(tempDecision.ForEachStatements); doWhileLoop.Nested.AddRange(tempDecision.ForStatements); doWhileLoop.Nested.AddRange(tempDecision.WhileLoops); doWhileLoop.Nested.AddRange(tempDecision.DoWhileLoops); doWhileLoop.Nested.AddRange(tempDecision.Catches); doWhileLoop.Nested.AddRange(tempDecision.SwitchStatements); } else if (ss is SelectBlockSyntax) { doWhileLoop.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true)); } else if (ss is DoLoopBlockSyntax) { doWhileLoop.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true)); } else if (ss is WhileBlockSyntax) { doWhileLoop.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true)); } else if (ss is CallStatementSyntax) { doWhileLoop.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax)); } else if (ss is ReturnStatementSyntax) { Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax); doWhileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods); doWhileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables); returnCnt++; } } return doWhileLoop; }
/// <summary> /// Constructor that sets all the Types so no lingering null types exist /// </summary> public InvokedMethod() { Attribute = new Variables(); Parameters = new List<Variables>(); Qualifiers = new List<Qualifiers>(); }