private void toolStripMenuItem1_Click(object sender, EventArgs e) { NewClass nc = new NewClass(tabControl2.SelectedTab.Name); nc.ShowDialog(); if (nc.Successful) { ClassInfo ci = new ClassInfo(); ci.FileName = nc.Contents + ".java"; ci.ClassName = nc.Contents; ci.Access = "public"; ci.Type = "class"; if (nc.HasConstructor) { Method m = new Method(); m.Name = ci.ClassName; m.Access = "public"; ci.AddMethod(m); } if (nc.HasMain) { Method m = new Method(); m.Name = "main"; m.Access = "public"; m.Attributes = new String[1] { "static" }; m.ReturnType = "void"; Variable v = new Variable(); v.Name = "args"; v.Type = "String[]"; //edit dimension here v.Method = m.Name; m.AddParameter(v); ci.AddMethod(m); } InsertTemplate(ci); } }
private void toolStripMenuItem2_Click(object sender, EventArgs e) { ClassInfo ci = new ClassInfo(); ci.FileName = "HelloWorldExample.java"; ci.ClassName = "HelloWorldExample"; ci.Access = "public"; ci.Type = "class"; Method m = new Method(); m.Name = "main"; m.Access = "public"; m.Attributes = new String[1] { "static" }; m.ReturnType = "void"; Variable v = new Variable(); v.Name = "args"; v.Type = "String[]";//edit dimension here m.AddParameter(v); m.Code = "System.out.println(\"Hello World!\");"; ci.AddMethod(m); InsertTemplate(ci); }
public void EditMethod(Method m) { Method old = GetMethod(m.Name); if(old != null) { methods.Remove(old); methods.Add(m); } }
public bool AddMethod(Method m) { String[] paramTypes = new String[m.Parameters.Count]; Object[] var = m.Parameters.ToArray(); for(int i = 0 ; i < paramTypes.Length; i++) { Variable v = (Variable)var[i]; paramTypes[i] = v.Type; } if (GetMethod(m.Name, paramTypes) == null) { methods.Add(m); return true; } else { return false; } }
private void GenerateButton_Click(object sender, EventArgs e) { if (GenerateButton.Text == "Generate Code") { PreviewText.Rtf = conditions.Rtf; GenerateButton.Text = "Insert Code"; } else { m = ci.GetMethod((String)MethodCombo.SelectedItem); if (m == null) { MessageBox.Show("The method you have selected does not seem to exist. Please verify spelling or name of method.", "Unknown Method"); } else { if (isDefault) { String[] lines = PreviewText.Lines; for (int i = 0; i < lines.Length; i++) { m.Code = m.Code + @"\line"; lines[i] = lines[i].Replace("{", @"\{"); lines[i] = lines[i].Replace("}", @"\}"); lines[i] = " " + lines[i]; m.Code = m.Code + lines[i]; } ci.EditMethod(m); } this.Close(); } } }
private void CreateMethod() { String access = ""; if (PublicRadio.Checked) { access = "public"; } else if (PrivateRadio.Checked) { access = "private"; } else if (ProtectedRadio.Checked) { access = "protected"; } ArrayList attributes = new ArrayList(); if (FinalCheck.Checked) { attributes.Add("final"); MethodName.Text = MethodName.Text.ToUpper(); } if (AbstractCheck.Checked) { attributes.Add("abstract"); } if (StaticCheck.Checked) { attributes.Add("static"); } if (SynchronizedCheck.Checked) { attributes.Add("synchronized"); } String[] attr = ToStringArray(attributes.ToArray()); Method m = new Method(); m.Name = MethodName.Text; if (ReturnType.Text == "boolean") { m.ReturnType = "bool"; } else if (ReturnType.Text == "character") { m.ReturnType = "char"; } else if (ReturnType.Text == "integer") { m.ReturnType = "int"; } else { m.ReturnType = ReturnType.Text; } m.Access = access; m.Attributes = attr; m.Parameters = parameters; m.Comments = Comments.Text; m.Code = Code.Text; ClassInfo ci = ClassFiles.GetClassInfo(ClassName + ".java"); if (ci.AddMethod(m)) { ClassFiles.Add(ci); successful = true; Close(); } else { MessageBox.Show("Method of same name and parameter types exists.", "Improper Method Overloading"); successful = false; } }
public static void InitializeContents() { instance = new ArrayList(); local = new ArrayList(); classes = new ArrayList(); ci = new ClassInfo(); m = new Method(); ci.ClassName = "Object"; m.Name = "toString"; m.Access = "public"; m.Attributes = null; m.ReturnType = "String"; m.Parameters = new ArrayList(); ci.AddMethod(m); classes.Add(ci); ci = new ClassInfo(); ci.ClassName = "Character"; m = new Method(); m.Name = "isUpperCase"; m.Access = "public"; m.Attributes = new String[1]{"static"}; m.ReturnType = "boolean"; m.Parameters = new ArrayList(); v = new Variable(); v.Name = "ch"; v.Type = "char"; m.Parameters.Add(v); ci.AddMethod(m); m = new Method(); m.Name = "isDigit"; m.Access = "public"; m.Attributes = new String[1]{"static"}; m.ReturnType = "boolean"; m.Parameters = new ArrayList(); v = new Variable(); v.Name = "ch"; v.Type = "char"; m.Parameters.Add(v); ci.AddMethod(m); classes.Add(ci); }