public bool Delete(Model.Type ty) { TypeInterface ti = td.CreateType(); ti.Del(ty); return(td.SaveChange()); }
public bool Add(Model.Type ty) { TypeInterface ti = td.CreateType(); ti.Add(ty); return(td.SaveChange()); }
public void modifierType(Model.Type type) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) { connection.Execute($"UPDATE Type SET nomType='{type.nomType}', duree='{type.duree}',action= '{type.action}',DUAselon='{type.DUAselon}',Description='{type.Description}' WHERE idType ='{type.idType}'"); } }
public void supprimerType(Model.Type type) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) { connection.Execute($"DELETE FROM Type WHERE idType ='{type.idType}';"); } }
public static bool readTypeData(string strCmd, List <Model.Type> myTypeList) { try { // Tao ket noi conn = new SqlConnection(strConnect); // Mo ket noi if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); } // Doc du lieu SqlCommand myCmd = new SqlCommand(strCmd, conn); SqlDataReader myReader = myCmd.ExecuteReader(); while (myReader.Read()) { string id = myReader[0].ToString(); string name = myReader[1].ToString(); Model.Type u = new Model.Type(id, name); myTypeList.Add(u); } conn.Close(); conn.Dispose(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
public List <Type> Read(string whereCondition) { Console.Clear(); sqlConnection.Open(); string sqlSelect = "select type_id, name, description from type"; List <Model.Type> list = new List <Type>(); using var cmd = new NpgsqlCommand(sqlSelect, sqlConnection); try { using NpgsqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Model.Type type = new Model.Type(connectionString); type.type_id = rdr.GetValue(0); type.name = rdr.GetValue(1); type.description = rdr.GetValue(2); list.Add(type); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } finally { sqlConnection.Close(); } return(list); }
public static bool insertType(Model.Type _u) { try { // Tao ket noi conn = new SqlConnection(strConnect); // Mo ket noi if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); } // Them don vi string strCmd = string.Format("INSERT INTO LOAI_LK VALUES('{0}', '{1}')", _u.IdString, _u.Name); SqlCommand myCmd = new SqlCommand(strCmd, conn); SqlDataReader myReader = myCmd.ExecuteReader(); conn.Close(); conn.Dispose(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); conn.Close(); conn.Dispose(); return(false); } }
public static bool updateType(Model.Type _u) { try { // Tao ket noi conn = new SqlConnection(strConnect); // Mo ket noi if (conn.State != System.Data.ConnectionState.Open) { conn.Open(); } // Them don vi string strCmd = string.Format("UPDATE LOAI_LK set TENLOAI = N'{0}' where MALOAI = '{1}'", _u.Name, _u.IdString); SqlCommand myCmd = new SqlCommand(strCmd, conn); SqlDataReader myReader = myCmd.ExecuteReader(); conn.Close(); conn.Dispose(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); conn.Close(); conn.Dispose(); return(false); } }
public AddTypeControler(View.NewType w) { wind = w; if (contAdd()) { string img = wind.icoPath.Text; e = new Model.Type(wind.IDbox.Text, wind.nameBox.Text.Trim(' '), wind.descBox.Text, img); } else { success = false; return; } if (chckTag()) { addTag(); success = true; GlowingEarth.getInstance().getMaster().notifyChange(); return; } else { wind.Error.Content = "Type with this ID already exists"; success = false; return; } }
private void textBox_TextChanged(object sender, TextChangedEventArgs e) { _selType = null; picpath = ""; if (searchBox.Text.Equals("")) { tyx.Clear(); foreach (Model.Type r in copy) { tyx.Add(r); } return; } if (tyx != null) { ObservableCollection <Model.Type> typez = new ObservableCollection <Model.Type>(); foreach (Model.Type t in refer.getMaster().types) { if (t.getMark().Contains(searchBox.Text)) { typez.Add(t); } } tyx.Clear(); foreach (Model.Type t in typez) { tyx.Add(t); } } }
bool IsSubjectToPipelining(Model.Type type, HashSet <Model.Type> visited) { if (!visited.Add(type)) { return(false); } switch (type.Tag) { case TypeTag.AnyPointer: case TypeTag.CapabilityPointer: case TypeTag.Interface: case TypeTag.ListPointer: case TypeTag.StructPointer: return(true); case TypeTag.List: return(IsSubjectToPipelining(type.ElementType, visited)); case TypeTag.Struct: return(type.Fields.Any(f => IsSubjectToPipelining(f.Type, visited))); default: return(false); } }
public int ajouterType(Model.Type type) { typeDAOSQLServer = TypeDAOSQLServer.getInstance(); int id = typeDAOSQLServer.ajouterType(type); return(id); }
private void btnAdd_Click(object sender, EventArgs e) { Model.Type u = new Model.Type(txtID.Text, txtName.Text); Controller.Connector.updateType(u); MessageBox.Show("Sửa thành công đơn vị " + txtID.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void reset_Click(object sender, RoutedEventArgs e) { selectedResource = null; picpath = ""; filt = null; searchBox.Text = "Search for resources..."; filter.SelectedItem = null; }
public Model.Type getTypeByName(string name) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) { Model.Type type = (Model.Type)connection.Query <Model.Type>($"Select * From Type Where nomType='{name}'"); return(type); } }
/* public void supprimerType(int idType) * { * using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) * { * connection.Execute($"DELETE FROM GestionType WHERE idType ='{idType}';"); * } * }*/ public Model.Type getTypeById(int idType) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) { Model.Type type = connection.QuerySingle <Model.Type>($"Select * From Type Where idType='{idType}'"); return(type); } }
public TypeDialog() { InitializeComponent(); type = new Model.Type(); tbDescription.DataContext = type; tbId.DataContext = type; tbName.DataContext = type; }
public ReflectionListPage(Model.Type postType) { InitializeComponent(); //getReflections = App.Data.GetReflections.Where(x => x.PostType == postType); PostType = postType; Title = postType + " Reflections"; }
public Property() { Encapsulation = new List<Model.Encapsulation>(); Qualifers = new List<Qualifiers>(); Type = new Model.Type(); Getter = new Method(); Setter = new Method(); }
public int ajouterType(Model.Type t) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionHelper.conVal("CalendrierDatabase"))) { String query = $"INSERT INTO Type(nomType,duree,action,DUAselon,Description) values ('{ t.nomType}','{ t.duree}','{t.action}','{t.DUAselon}','{t.Description}');" + "SELECT CAST(SCOPE_IDENTITY() as int)"; int id = connection.Query <int>(query).Single(); return(id); } }
public Model.Type makeType() { if (contAddType()) { Model.Type t = new Model.Type(te.IDbox.Text, te.nameBox.Text.Trim(' '), te.descBox.Text, te.icoPath.Text); return(t); } success = false; return(null); }
public ActionResult Create([Bind("TypeID,CreatedBy,CreatedDate,IsDeleted,TypeName,UpdatedBy,UpdatedDate")] Model.Type @type) { if (ModelState.IsValid) { @type.CreatedBy = "Admin"; @type.CreatedDate = DateTime.Now; _context.Add(@type); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(@type)); }
public PlanView(PlanViewModel pvm, Model.Type unitType) { InitializeComponent(); PVM = pvm; this.DataContext = PVM; SetPlan(); UnitType = unitType; }
public ModifyControler(View.TypeEditor resed) { te = resed; if ((type = makeType()) != null) { for (int i = 0; i < GlowingEarth.getInstance().getMaster().getTypes().Count; i++) { if (type.getMark().Equals(GlowingEarth.getInstance().getMaster().getTypes()[i].getMark())) { GlowingEarth.getInstance().getMaster().getTypes()[i] = type; break; } } } else { success = false; return; } GlowingEarth.getInstance().itemList.Items.Refresh(); ObservableCollection <Model.Resource> temp = GlowingEarth.getInstance().getMaster().getResources(); for (int i = 0; i < temp.Count; i++) { if (GlowingEarth.getInstance().getMaster().getResources()[i].getType().getMark().Equals(type.getMark())) { Model.Resource r = temp[i]; r.setType(type); if (r.getHasTypeImg()) { r.setIcon(type.getImg()); } ObservableCollection <Model.MapItem> mapitems = GlowingEarth.getInstance().getMaster().getMapItems(); for (int j = 0; j < mapitems.Count; j++) { if (mapitems[j].getID().Equals(r.getMark())) { mapitems[j].setPath(r.getIco()); } } GlowingEarth.getInstance().getMaster().setMapItems(mapitems); } } GlowingEarth.getInstance().getMaster().setResources(temp); success = true; GlowingEarth.getInstance().map.Items.Refresh(); GlowingEarth.getInstance().getMaster().notifyChange(); }
public PlanViewModel(ObservableCollection <Model> availableModels, Model.Type unitType) { Plan = new Plan(); Models = availableModels; IsSetEnabled = true; IsModifyEnabled = false; IsDeleteEnabled = false; ModelSelectedIndex = -1; IsSelectionEnabled = true; Plan.UnitType = unitType; }
public Nullability GetDefaultElementTypeNullability(Model.Type type) { switch (type.Tag) { case TypeTag.Data: case TypeTag.Text: case TypeTag.Interface: case TypeTag.List: case TypeTag.ListPointer: case TypeTag.StructPointer: return(Nullability.NullableRef); default: return(Nullability.NonNullable); } }
public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, Model.Type boundType, NameUsage usage = NameUsage.Default) { var name = MakeTypeName(def, usage); if (def.GenericParameters.Count > 0) { return(GenericName(name.Identifier) .AddTypeArgumentListArguments(def .GetLocalTypeParameters() .Select(p => ResolveGenericParameter(p, boundType, def)).ToArray())); } else { return(name.IdentifierName); } }
ExpressionSyntax MakeListSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) { string s = $"_s{type.GetRank().Item1}"; string v = $"_v{type.GetRank().Item1}"; switch (type.ElementType?.Tag) { case TypeTag.List: case TypeTag.ListPointer: case TypeTag.Struct: case TypeTag.Group: case TypeTag.StructPointer: case TypeTag.Data: return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, writer, IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer <int> .Init)))) .AddArgumentListArguments( Argument(domain), Argument( ParenthesizedLambdaExpression( ParameterList( SeparatedList <ParameterSyntax>( new SyntaxNodeOrToken[] { Parameter(Identifier(s)), Token(SyntaxKind.CommaToken), Parameter(Identifier(v)) })), MakeComplexSerializeParticle( type.ElementType, IdentifierName(s), IdentifierName(v)))))); default: return(InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, writer, IdentifierName(nameof(Capnp.ListOfPrimitivesSerializer <int> .Init)))) .AddArgumentListArguments(Argument(domain))); } }
internal NameSyntax GetQName(Model.Type type, TypeDefinition scope) { // FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated // qualified names. Unfortunately the commented approach is too naive. It will fail if // there are multiple objects with identical name up the hierarchy. We will need a more // sophisticated algorithm. var scopeSet = new HashSet <TypeDefinition>(); //while (scope != null) //{ // scopeSet.Add(scope); // scope = scope.DeclaringElement as TypeDefinition; //} if (type.Definition != null) { var stack = new Stack <SimpleNameSyntax>(); var def = type.Definition; stack.Push(MakeGenericTypeName(def, type, NameUsage.Default)); while (def.DeclaringElement is TypeDefinition pdef && !scopeSet.Contains(pdef)) { stack.Push(MakeGenericTypeName(pdef, type, NameUsage.Namespace)); def = pdef; } var qtype = GetNamespaceFor(type.Definition) ?? GetNamespaceFor(scope) ?? TopNamespace; foreach (var name in stack) { qtype = QualifiedName(qtype, name); } return(qtype); } else { return(GetGenericTypeParameter(type.Parameter.Name).IdentifierName); } }
ExpressionSyntax MakeComplexSerializeParticle(Model.Type type, ExpressionSyntax writer, ExpressionSyntax domain) { switch (type.Tag) { case TypeTag.Data: case TypeTag.List: return(MakeListSerializeParticle(type, writer, domain)); case TypeTag.Struct: case TypeTag.Group: return(ConditionalAccessExpression(domain, InvocationExpression(MemberBindingExpression(_names.SerializeMethod.IdentifierName)) .AddArgumentListArguments(Argument(writer)))); default: throw new NotImplementedException(); } }
public static String typeGenerator(Model.Type t) { String s = " <div onclick=\"voirArchives(" + t.idType + ")\" class=\"contentTousType\">\r\n" + " <div class=\"nomTypes\">\r\n" + " " + t.nomType + "\r\n" + " </div>\r\n" + " <div class=\"dateAjouterTypes\">\r\n" + " <label class=\"dateAjout\">DUA</label>\r\n" + " " + t.duree + "\r\n" + " </div>\r\n" + " \r\n" + " <div class=\"mindescriptionTypes\">\r\n" + " <div></div>\r\n" + " <p>cliquez pour voir les Archives conservé après qu'ils ont passé leurs DUA de ce type</p>\r\n" + " </div> \r\n" + " </div> "; return(s); }
//private object TransverseClassTypes(object classType) //{ // object retObj; // if (classType is ClassDeclarationSyntax) // { // retObj = new Class(); // classType = classType as ClassDeclarationSyntax; // } // else if (classType is StructDeclarationSyntax) // { // retObj = new Struct(); // classType = classType as StructDeclarationSyntax; // } // //Class retObj = new Class(); // //Name // (retObj is Class ? retObj as Class : retObj as Struct).Name = (classType is ClassDeclarationSyntax ? (ClassDeclarationSyntax)classType : (StructDeclarationSyntax)classType).Identifier.ValueText; // //encapsulation // foreach (SyntaxToken st in classType.Modifiers) // { // string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); // retObj.Encapsulation.Add((Encapsulation)System.Enum.Parse(typeof(Encapsulation), modifier)); // } // var enums = from aEnu in classType.ChildNodes().OfType<EnumDeclarationSyntax>() select aEnu; // foreach (EnumDeclarationSyntax eds in enums) // { // retObj.Enums.Add(TraverseEnums(eds)); // } // var structs = from aStruct in classType.ChildNodes().OfType<StructDeclarationSyntax>() select aStruct; // foreach (StructDeclarationSyntax sds in structs) // { // retObj.Structs.Add(TransverseStructs(sds)); // } // var methods = from aMethod in classType.ChildNodes().OfType<MethodDeclarationSyntax>() select aMethod; // foreach (MethodDeclarationSyntax mds in methods) // { // retObj.Methods.Add(TransverseMethods(mds)); // } // var fields = from aField in classType.ChildNodes().OfType<FieldDeclarationSyntax>() select aField; // foreach (FieldDeclarationSyntax fds in fields) // { // retObj.Attributes.Add(TransverseVariables(fds)); // } // //var properties = from aProperty in classType.ChildNodes().OfType<PropertyDeclarationSyntax>() select aProperty; // //foreach (PropertyDeclarationSyntax pds in properties) // //{ // // //traverse attributes // //} // var constructors = from aConstructor in classType.ChildNodes().OfType<ConstructorDeclarationSyntax>() select aConstructor; // foreach (ConstructorDeclarationSyntax cods in constructors) // { // retObj.Constructors.Add(TransverseConstructors(cods)); // } // var destructors = from aDestructor in classType.ChildNodes().OfType<DestructorDeclarationSyntax>() select aDestructor; // foreach (DestructorDeclarationSyntax dds in destructors) // { // retObj.Destructors.Add(TransverseDestructors(dds)); // } // var classes = from aClass in classType.ChildNodes().OfType<ClassDeclarationSyntax>() select aClass; // foreach (ClassDeclarationSyntax classType2 in classes) // { // retObj.Classes.Add(TraverseClass(classType2)); // } // return retObj; //} private Method TransverseMethods(MethodDeclarationSyntax mds) { Method retMethod = new Method(); //public int DecisionsCount { get; } //public int ExitPoints { get; set; } //public bool IsFriend { get; } //public bool IsPolymophic { get; } //public bool IsPublic { get; } //public bool IsStatic { get; } //public List<Preprocessor> Preprocessors { get; set; } retMethod.Name = mds.Identifier.ValueText; if (mds.HasLeadingTrivia) { SetOuterComments(retMethod, mds.GetLeadingTrivia().ToFullString()); } if (mds.HasTrailingTrivia) { SetInnerComments(retMethod, mds.GetTrailingTrivia().ToFullString()); } foreach (SyntaxToken st in mds.Modifiers) { string modifier = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(st.ValueText); Encapsulation encap; Qualifiers qual; if (System.Enum.TryParse<Encapsulation>(modifier, out encap)) { retMethod.Encapsulation.Add(encap); } else if (System.Enum.TryParse<Qualifiers>(modifier, out qual)) { retMethod.Qualifiers.Add(qual); } } TypeSyntax ts = mds.ReturnType; Model.Type retType = new Model.Type(); retType.Name = ts.ToString(); retType.IsKnownType = SyntaxFacts.IsKeywordKind(ts.CSharpKind()); retType.IsNotUserDefined = SyntaxFacts.IsKeywordKind(ts.CSharpKind()); //TODO //rettype.generictype retMethod.ReturnType = retType; ParameterListSyntax pls = mds.ParameterList; foreach (ParameterSyntax ps in pls.Parameters) { retMethod.Parameters.Add(TraverseParamaters(ps)); } BlockSyntax bs = mds.Body; if (bs != null) { var labelStatements = from aLabelStatement in bs.ChildNodes().OfType<LabeledStatementSyntax>() select aLabelStatement; foreach (LabeledStatementSyntax lss in labelStatements) { retMethod.LabelStatements.Add(TraverseLabelStatements(lss)); } var goToStatements = from aGoToStatement in bs.ChildNodes().OfType<GotoStatementSyntax>() select aGoToStatement; foreach (GotoStatementSyntax gtss in goToStatements) { GoTo gt = TraverseGoToStatements(gtss); retMethod.GoToStatements.Add(gt); } //Preprocessors = new List<Preprocessor>(); //Base = new List<InvokedMethod>(); //Decisions = new Decisions(); var accessVarsDecl = from aAccessVarsDecl in bs.ChildNodes().OfType<LocalDeclarationStatementSyntax>() select aAccessVarsDecl; foreach (LocalDeclarationStatementSyntax ldss in accessVarsDecl) { Method tempMethod = TransverseAccessVars(ldss); retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables); retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods); } var ifStatements = from aIfStatement in bs.ChildNodes().OfType<IfStatementSyntax>() select aIfStatement; foreach (IfStatementSyntax iss in ifStatements) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = AllDecisions(TraverseIfStatements(iss, ref exitPoints)); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var elseStatements = from aElseStatements in bs.ChildNodes().OfType<ElseClauseSyntax>() select aElseStatements; foreach (ElseClauseSyntax ecs in elseStatements) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseElseClauses(ecs, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var whileLoops = from aWhileLoop in bs.ChildNodes().OfType<WhileStatementSyntax>() select aWhileLoop; foreach (WhileStatementSyntax wss in whileLoops) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseWhileLoops(wss, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var doWhileLoops = from aDoWhileLoop in bs.ChildNodes().OfType<DoStatementSyntax>() select aDoWhileLoop; foreach (DoStatementSyntax dss in doWhileLoops) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseDoStatements(dss, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var forLoops = from aForLoop in bs.ChildNodes().OfType<ForStatementSyntax>() select aForLoop; foreach (ForStatementSyntax fss in forLoops) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseForStatements(fss, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var foreachLoops = from aForeachLoop in bs.ChildNodes().OfType<ForEachStatementSyntax>() select aForeachLoop; foreach (ForEachStatementSyntax fess in foreachLoops) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseForEachStatements(fess, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var switches = from aSwitch in bs.ChildNodes().OfType<SwitchStatementSyntax>() select aSwitch; foreach (SwitchStatementSyntax sss in switches) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseSwitchStatements(sss, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var catches = from aCatch in bs.ChildNodes().OfType<CatchClauseSyntax>() select aCatch; foreach (CatchClauseSyntax ccs in catches) { int exitPoints = retMethod.ExitPoints; Decisions tempDecision = TraverseCatchClauses(ccs, ref exitPoints); retMethod.Decisions.IfStatements.AddRange(tempDecision.IfStatements); retMethod.Decisions.ElseStatements.AddRange(tempDecision.ElseStatements); retMethod.Decisions.ForEachStatements.AddRange(tempDecision.ForEachStatements); retMethod.Decisions.ForStatements.AddRange(tempDecision.ForStatements); retMethod.Decisions.WhileLoops.AddRange(tempDecision.WhileLoops); retMethod.Decisions.DoWhileLoops.AddRange(tempDecision.DoWhileLoops); retMethod.Decisions.Catches.AddRange(tempDecision.Catches); retMethod.Decisions.SwitchStatements.AddRange(tempDecision.SwitchStatements); retMethod.ExitPoints = exitPoints; } var breaks = from aBreak in bs.ChildNodes().OfType<BreakStatementSyntax>() select aBreak; foreach (BreakStatementSyntax bss in breaks) { //TODO get breaks //note that breaks are NOT in retMethod.Decisions } var checks = from aCheck in bs.ChildNodes().OfType<CheckedStatementSyntax>() select aCheck; foreach (CheckedStatementSyntax css in checks) { //TODO get checks //note that checks are NOT in retMethod.Decisions } var continues = from aContinue in bs.ChildNodes().OfType<ContinueStatementSyntax>() select aContinue; foreach (ContinueStatementSyntax css in continues) { //TODO get continues //note that continues are NOT in retMethod.Decisions } var emptys = from aEmpty in bs.ChildNodes().OfType<EmptyStatementSyntax>() select aEmpty; foreach (EmptyStatementSyntax ess in emptys) { //TODO get emptys //note that emptys are NOT in retMethod.Decisions } var exprs = from aExpr in bs.ChildNodes().OfType<ExpressionStatementSyntax>() select aExpr; foreach (ExpressionStatementSyntax ess in exprs) { //TODO get expressions //note that expressions are NOT in retMethod.Decisions } var fixeds = from aFixed in bs.ChildNodes().OfType<FixedStatementSyntax>() select aFixed; foreach (FixedStatementSyntax fss in fixeds) { //TODO get fixed //note that these are NOT in retMethod.Decisions } var locks = from aLock in bs.ChildNodes().OfType<LockStatementSyntax>() select aLock; foreach (LockStatementSyntax lss in locks) { //TODO get lock //note that these are NOT in retMethod.Decisions } var returns = from aReturn in bs.ChildNodes().OfType<ReturnStatementSyntax>() select aReturn; foreach (ReturnStatementSyntax rss in returns) { retMethod.ExitPoints++; } var throws = from aThrow in bs.ChildNodes().OfType<ThrowStatementSyntax>() select aThrow; foreach (ThrowStatementSyntax tss in throws) { //TODO get throws //note that these are NOT in retMethod.Decisions } var trys = from aTry in bs.ChildNodes().OfType<TryStatementSyntax>() select aTry; foreach (TryStatementSyntax tss in trys) { //TODO get trys //note that these are NOT in retMethod.Decisions } var unsafes = from aUnsafe in bs.ChildNodes().OfType<UnsafeStatementSyntax>() select aUnsafe; foreach (UnsafeStatementSyntax uss in unsafes) { //TODO get unsafes //note that these are NOT in retMethod.Decisions } var usings = from aUsing in bs.ChildNodes().OfType<UsingStatementSyntax>() select aUsing; foreach (UsingStatementSyntax uss in usings) { //TODO get usings //note that these are NOT in retMethod.Decisions } var yields = from aYield in bs.ChildNodes().OfType<YieldStatementSyntax>() select aYield; foreach (YieldStatementSyntax yss in yields) { //TODO get yields //note that these are NOT in retMethod.Decisions } var invokedMethods = from aInvokedMethod in bs.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod; foreach (InvocationExpressionSyntax ies in invokedMethods) { Method tempMethod = TraverseInvocationExpression(ies); retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods); retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables); } //InvokedMethods = new List<InvokedMethod>(); } return retMethod; }
private Decisions TraverseElseClauses(ElseClauseSyntax ecs, ref int exitPoints, bool nested = false) { Decisions retDecision = new Decisions(); ElseStatement elseStm = new ElseStatement(); if (ecs.HasLeadingTrivia) { SetOuterComments(elseStm, ecs.GetLeadingTrivia().ToFullString()); } if (ecs.HasTrailingTrivia) { SetInnerComments(elseStm, ecs.GetTrailingTrivia().ToFullString()); } elseStm.IsNested = nested; var binaryExpressions = from aBinaryExpression in ecs.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpression; foreach (BinaryExpressionSyntax bes in binaryExpressions) { Method tempMethod = TraverseBinaryExpression(bes); elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables); elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } var catches = from aCatch in ecs.ChildNodes().OfType<CatchClauseSyntax>() select aCatch; foreach (CatchClauseSyntax ccs in catches) { Decisions tempCatch = TraverseCatchClauses(ccs, ref exitPoints, true); elseStm.Nested.AddRange(tempCatch.Catches); } var elses = from aElse in ecs.ChildNodes().OfType<ElseClauseSyntax>() select aElse; foreach (ElseClauseSyntax ecs2 in elses) { Decisions tempElse = TraverseElseClauses(ecs2, ref exitPoints, true); elseStm.Nested.AddRange(tempElse.ElseStatements); } #region nested stuff var statements = from aStatement in ecs.ChildNodes().OfType<StatementSyntax>() select aStatement; foreach (StatementSyntax ss in statements) { if (ss is DoStatementSyntax) { Decisions dwl = TraverseDoStatements(ss as DoStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(dwl.DoWhileLoops); } else if (ss is ExpressionStatementSyntax) { Method tempMethod = TraverseExpressionStatementSyntax(ss as ExpressionStatementSyntax); elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables); elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is ForEachStatementSyntax) { Decisions fes = TraverseForEachStatements(ss as ForEachStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(fes.ForEachStatements); } else if (ss is ForStatementSyntax) { Decisions fs = TraverseForStatements(ss as ForStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(fs.ForStatements); } else if (ss is IfStatementSyntax) { Decisions decision = TraverseIfStatements(ss as IfStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(decision.IfStatements); } else if (ss is LocalDeclarationStatementSyntax) { Model.Type tempType = new Model.Type(); LocalDeclarationStatementSyntax ldss = ss as LocalDeclarationStatementSyntax; if (ldss.Declaration != null) { VariableDeclarationSyntax vds = ldss.Declaration; tempType.Name = vds.Type.ToString(); tempType.IsKnownType = true; tempType.IsNotUserDefined = true; } Method tempMethod = TransverseAccessVars(ss as LocalDeclarationStatementSyntax); //NOT SURE if this will work but here goes tempMethod.AccessedVariables[0].Type = tempType; elseStm.AccessedVars.AddRange(tempMethod.AccessedVariables); elseStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } else if (ss is ReturnStatementSyntax) { exitPoints++; } else if (ss is SwitchStatementSyntax) { Decisions switchStm = TraverseSwitchStatements(ss as SwitchStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(switchStm.SwitchStatements); } else if (ss is WhileStatementSyntax) { Decisions wl = TraverseWhileLoops(ss as WhileStatementSyntax, ref exitPoints, true); elseStm.Nested.AddRange(wl.WhileLoops); } } #endregion retDecision.ElseStatements.Add(elseStm); return retDecision; }
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 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 Decisions TraverseIfStatements(IfStatementSyntax iss, ref int exitPoints, bool nested = false) { Decisions retDecision = new Decisions(); IfStatement ifStm = new IfStatement(); if (iss.HasLeadingTrivia) { SetOuterComments(ifStm, iss.GetLeadingTrivia().ToFullString()); } if (iss.HasTrailingTrivia) { SetInnerComments(ifStm, iss.GetTrailingTrivia().ToFullString()); } ifStm.IsNested = nested; //public int ExpressionListEndLn { get; set; } //public int ExpressionListStartLn { get; set; } //public bool IsNested { get; set; } ExpressionSyntax es = iss.Condition; var binaryExpressions = from aBinaryExpression in iss.Condition.DescendantNodesAndSelf().OfType<BinaryExpressionSyntax>() select aBinaryExpression; ifStm.ConditionCount = binaryExpressions.Count(); //This area is for the conditions i.e. the stuff in the () of if () foreach (BinaryExpressionSyntax bes in binaryExpressions) { Method tempMethod = TraverseBinaryExpression(bes); ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } //TODO handle catches (if there are even catches inside if statements) var catches = from aCatch in iss.ChildNodes().OfType<CatchClauseSyntax>() select aCatch; foreach (CatchClauseSyntax ccs in catches) { Decisions tempCatch = TraverseCatchClauses(ccs, ref exitPoints, true); ifStm.Nested.AddRange(tempCatch.Catches); } //TODO need to handle else clauses var elses = from aElse in iss.ChildNodes().OfType<ElseClauseSyntax>() select aElse; foreach (ElseClauseSyntax ecs in elses) { //TODO //Traverse ElseClauseSyntax Decisions tempElse = TraverseElseClauses(ecs, ref exitPoints, true); ifStm.Nested.AddRange(tempElse.ElseStatements); #region old code with method return //ifStm.InvokedMethods.AddRange(tempElse.InvokedMethods); //ifStm.AccessedVars.AddRange(tempElse.AccessedVars); //ifStm.Nested.Add(tempElse); //foreach (BaseDecisions bd in ifStm.Nested) //{ // bd.IsNested = true; //} #endregion } //TODO need to find a way to return both nested //and invoked methods / accessedvars to the parent method var statements = from aStatement in iss.Statement.ChildNodes().OfType<StatementSyntax>() select aStatement; List<BaseDecisions> retBd = new List<BaseDecisions>(); List<InvokedMethod> retIm = new List<InvokedMethod>(); #region Nested and Invoked Methods and accessed vars foreach (StatementSyntax ss in statements) { //if (ss is BreakStatementSyntax) //{ //} //else if (ss is CheckedStatementSyntax) //{ //} //else if (ss is ContinueStatementSyntax) //{ //} if (ss is DoStatementSyntax) { Decisions dwl = TraverseDoStatements(ss as DoStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(dwl.DoWhileLoops); //dwl.IsNested = true; //ifStm.Nested.Add(dwl); } //else if (ss is EmptyStatementSyntax) //{ //} else if (ss is ExpressionStatementSyntax) { Method tempMethod = TraverseExpressionStatementSyntax(ss as ExpressionStatementSyntax); ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } //else if (ss is FixedStatementSyntax) //{ //} else if (ss is ForEachStatementSyntax) { Decisions fes = TraverseForEachStatements(ss as ForEachStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(fes.ForEachStatements); //fes.IsNested = true; //ifStm.Nested.Add(fes); } else if (ss is ForStatementSyntax) { Decisions fs = TraverseForStatements(ss as ForStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(fs.ForStatements); //fs.IsNested = true; //ifStm.Nested.Add(fs); } //else if (ss is GotoStatementSyntax) //{ //} else if (ss is IfStatementSyntax) { Decisions decision = TraverseIfStatements(ss as IfStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(decision.IfStatements); } //else if (ss is LabeledStatementSyntax) //{ // BaseDecisions bd = new BaseDecisions(); // bd.IsNested = true; // bd.Nested.Add(TraverseLabelStatements(ss as LabeledStatementSyntax)); // retIf.Nested.Add(bd); //} else if (ss is LocalDeclarationStatementSyntax) { Model.Type tempType = new Model.Type(); LocalDeclarationStatementSyntax ldss = ss as LocalDeclarationStatementSyntax; if (ldss.Declaration != null) { VariableDeclarationSyntax vds = ldss.Declaration; tempType.Name = vds.Type.ToString(); tempType.IsKnownType = true; tempType.IsNotUserDefined = true; } Method tempMethod = TransverseAccessVars(ss as LocalDeclarationStatementSyntax); //NOT SURE if this will work but here goes tempMethod.AccessedVariables[0].Type = tempType; ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables); ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods); } //else if (ss is LockStatementSyntax) //{ //} else if (ss is ReturnStatementSyntax) { exitPoints++; } else if (ss is SwitchStatementSyntax) { Decisions switchStm = TraverseSwitchStatements(ss as SwitchStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(switchStm.SwitchStatements); //switchStm.IsNested = true; //ifStm.Nested.Add(switchStm); } //else if (ss is ThrowStatementSyntax) //{ //} //else if (ss is TryStatementSyntax) //{ //} //else if (ss is UnsafeStatementSyntax) //{ //} //else if (ss is UsingStatementSyntax) //{ // //using list? //} else if (ss is WhileStatementSyntax) { Decisions wl = TraverseWhileLoops(ss as WhileStatementSyntax, ref exitPoints, true); ifStm.Nested.AddRange(wl.WhileLoops); //wl.IsNested = true; //ifStm.Nested.Add(wl); } //else if (ss is YieldStatementSyntax) //{ //} } #endregion retDecision.IfStatements.Add(ifStm); return retDecision; }
private Method TransverseAccessVars(LocalDeclarationStatementSyntax ldss) { Method retMethod = new Method(); if (ldss.HasLeadingTrivia) { SetOuterComments(retMethod, ldss.GetLeadingTrivia().ToFullString()); } if (ldss.HasTrailingTrivia) { SetInnerComments(retMethod, ldss.GetTrailingTrivia().ToFullString()); } 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); } } retMethod.Qualifiers.AddRange(qualifiers); retMethod.Encapsulation.AddRange(accessability); VariableDeclarationSyntax varDecl = ldss.Declaration; Model.Type tempType = new Model.Type(); if(varDecl.Type is PredefinedTypeSyntax) { tempType.Name = varDecl.Type.ToString(); tempType.IsKnownType = true; tempType.IsNotUserDefined = true; } var vars = from aVar in varDecl.ChildNodes().OfType<VariableDeclaratorSyntax>() select aVar; foreach (VariableDeclaratorSyntax vds in vars) { //Variables retVar = new Variables(); Method tempMethod = TraverseVarDeclarators(vds); foreach (Variables vrs in tempMethod.AccessedVariables) { vrs.Type = tempType; } retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables); if (vds.Initializer != null) { var castStatements = from aCastStatement in vds.Initializer.Value.ChildNodes().OfType<CastExpressionSyntax>() select aCastStatement; foreach (CastExpressionSyntax ces in castStatements) { Method retCast = TraverseCastExpressions(ces); retMethod.AccessedVariables.AddRange(retCast.AccessedVariables); retMethod.InvokedMethods.AddRange(retCast.InvokedMethods); } } } return retMethod; }
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 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; }