public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectClass"); int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int indexEN = semi.Contains("enum"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // local semiExp with tokens for type and name local.displayNewLines = false; if (semi[index] == "class" || semi[index] == "interface" || semi[index] == "struct" || semi[index] == "enum") { local.Add(semi[index]).Add(semi[index + 1]); } else { local.Add(semi[index]).Add(semi[index + 2]); } doActions(local); return(true); } return(false); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectPublicDeclar"); int index = semi.Contains(";"); if (index != -1) { index = semi.Contains("public"); if (index == -1) { return(true); } CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add("public " + semi[index + 1]).Add(semi[index + 2]); index = semi.Contains("="); if (index != -1) { doActions(local); return(true); } index = semi.Contains("("); if (index == -1) { doActions(local); return(true); } } return(false); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectClass"); int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // local semiExp with tokens for type and name local.displayNewLines = false; //check for inheritance if (semi.Contains(":") != -1) { local.userInheritance = true; local.Add(semi[index]).Add(semi[index + 1]).Add(semi[semi.Contains(":") + 1]); } else { local.Add(semi[index]).Add(semi[index + 1]); } doActions(local); return(true); } return(false); }
public override bool test(CSsemi.CSemiExp semi) { HashSet <string> definedSet = UserType.getUserDefinedSet(); Display.displayRules(actionDelegate, "rule Detect Inheritance"); int classIndex = semi.Contains("class"); if (classIndex != -1) { //check for inheritance int inheritanceIndex = semi.Contains(":"); if (inheritanceIndex != -1) { string inheritedClass = semi[inheritanceIndex + 1]; if (definedSet.Contains(inheritedClass)) { //do some action Console.Write("inheritance found: " + inheritedClass + "\n"); doActions(semi); return(true); } } } return(false); }
public int indexOfType(CSsemi.CSemiExp semi) { int indexCL = semi.Contains("class"); int indexIF = semi.Contains("interface"); int indexST = semi.Contains("struct"); int indexEN = semi.Contains("enum"); int indexDE = semi.Contains("delegate"); int index = Math.Max(indexCL, indexIF); index = Math.Max(index, indexST); index = Math.Max(index, indexEN); index = Math.Max(index, indexDE); return(index); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetecAlias"); int indexF = semi.Contains("using"); int indexS = semi.Contains("="); if (indexF != -1 && indexS != -1 && (indexS - indexF) == 2) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); local.displayNewLines = false; local.Add("Alias").Add(semi[indexF + 1]); doActions(local); return(true); } return(false); }
public override void doAction(CSsemi.CSemiExp semi) { Display.displayActions(actionDelegate, "action PushStack"); ++repo_.scopeCount; Elem elem = new Elem(); elem.type = semi[0]; // expects type elem.name = semi[1]; // expects name elem.beginLine = repo_.semi.lineCount - 1; elem.endLine = 0; elem.beginScopeCount = repo_.scopeCount; elem.endScopeCount = 0; elem.cohesion = 0; elem.coupling = 0; //keep track of the current class and function scope if (elem.name != "anonymous") { if (elem.type.Equals("class") || elem.type.Equals("struct") || elem.type.Equals("interface")) { repo_.currentClassScope = elem.name; //set the current class name } else if (elem.type.Equals("function")) { repo_.currentFunctionScope = elem.name; } } repo_.stack.push(elem); if (AAction.displayStack) { repo_.stack.display(); } if (AAction.displaySemi) { Console.Write("\n line# {0,-5}", repo_.semi.lineCount - 1); Console.Write("entering "); string indent = new string(' ', 2 * repo_.stack.count); Console.Write("{0}", indent); this.display(semi); // defined in abstract action } if (elem.type == "control" || elem.name == "anonymous") { return; } repo_.locations.Add(elem); //update coupling base on class inhertiance on use if (semi.Contains("class") != -1) { inheritCoupling(semi); } else { userCoupling(semi); } }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectLeavingScope"); int index = semi.Contains("}"); if (index != -1) { doActions(semi); return(true); } return(false); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectAnonymousScope"); int index = semi.Contains("{"); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add("control").Add("anonymous"); doActions(local); return(true); } return(false); }
public override bool test(CSsemi.CSemiExp semi) { Display.displayRules(actionDelegate, "rule DetectNamespace"); int index = semi.Contains("namespace"); if (index != -1) { CSsemi.CSemiExp local = new CSsemi.CSemiExp(); // create local semiExp with tokens for type and name local.displayNewLines = false; local.Add(semi[index]).Add(semi[index + 1]); doActions(local); return(true); } return(false); }