public MethodCall(SrcMLArchive archive, CallData data) { this.Archive = archive; this.Data = data; this.firstMatchIsValid = false; this.hasMatches = false; this.hasNoMatches = false; this.isExternal = false; this.Location = data.Location; //TODO fix this once new type hierarchy is in place //this.FullName = data.ParentScope.GetParentScopesAndSelf<NamedScope>().First().GetFullName(); this.Id = DataHelpers.GetLocation(data.Location); this.Path = this.Location.SourceFileName; this.numberOfValidMatches = 0; this.SourceCode = GetSourceCode(); PossibleMatches = new ObservableCollection<MethodDefinition>(GetMatches()); StartMonitoringDefinitions(); }
public MethodCall(SrcMLArchive archive, CallData data) { this.Archive = archive; this.Data = data; this.firstMatchIsValid = false; this.hasMatches = false; this.hasNoMatches = false; this.isExternal = false; this.Location = data.Location; //TODO fix this once new type hierarchy is in place //this.FullName = data.ParentScope.GetParentScopesAndSelf<NamedScope>().First().GetFullName(); this.Id = DataHelpers.GetLocation(data.Location); this.Path = this.Location.SourceFileName; this.numberOfValidMatches = 0; this.SourceCode = GetSourceCode(); PossibleMatches = new ObservableCollection <MethodDefinition>(GetMatches()); StartMonitoringDefinitions(); }
/// <summary> /// Find MethodDefinition matching from MethodCall /// </summary> /// <param name="mc"></param> /// <returns></returns> public static MethodDefinition FindMatchedMd(MethodCall mc) { INamedEntity match = null; try { match = mc.FindMatches().FirstOrDefault(); } catch (Exception e) { Console.WriteLine("{0}:{1}:{2}: Call Exception {3}", mc.Location.SourceFileName, mc.Location.StartingLineNumber, mc.Location.StartingColumnNumber, e); } if (null != match) { //Console.WriteLine("match : {0} ", match); if (match is MethodDefinition) { //Console.WriteLine("method Definition"); MethodDefinition md = (MethodDefinition)match; //Console.WriteLine("md full name :" + md.GetFullName()); return md; } } return null; }
private MethodDeclarationNode FromMethodCallToSWUM(MethodCall mcall, NamespaceDefinition globalNamespace, DataProject<CompleteWorkingSet> dataProject) { var mdef = globalNamespace.GetDescendants<MethodDefinition>().Where(decl => mcall.SignatureMatches(decl)); if (mdef.Count() > 0) { var mdefXml = DataHelpers.GetElement(dataProject.SourceArchive, mdef.First().PrimaryLocation); MethodContext mc = ContextBuilder.BuildMethodContext(mdefXml); MethodDeclarationNode mdn = new MethodDeclarationNode(mcall.Name, mc); BaseVerbRule rule = new BaseVerbRule(posData, tagger, splitter); if (rule.InClass(mdn)) { rule.ConstructSwum(mdn); return mdn; } else { return null; } } else { Console.WriteLine(mcall.Name + " could not be found"); return null; } }
/// <summary> /// /// </summary> /// <param name="mc"></param> private void UpdateMethodCall(MethodCall mc) { var args = mc.Arguments.ToList(); var md = mc.FindMatches().FirstOrDefault() as MethodDefinition; if(md != null && IsLocalMethod(md)) { //local method InvokedLocalMethods.Add(md); } else { //external method InvokedExternalMethods.Add(md); } foreach(var arg in args) { UpdateByExpression(arg); } }
private void detach_CallsToMethod(MethodCall entity) { this.SendPropertyChanging(); entity.CalleeDefinition = null; }
private void attach_CallsFromMethod(MethodCall entity) { this.SendPropertyChanging(); entity.CallerDefinition = this; }
partial void DeleteMethodCall(MethodCall instance);
partial void UpdateMethodCall(MethodCall instance);
partial void InsertMethodCall(MethodCall instance);
/// <summary> /// Creates a method call object /// </summary> /// <param name="callElement">The XML element to parse</param> /// <param name="context">The parser context</param> /// <returns>A method call for <paramref name="callElement"/></returns> public virtual MethodCall ParseCallElement(XElement callElement, ParserContext context) { string name = String.Empty; bool isConstructor = false; bool isDestructor = false; IEnumerable<XElement> callingObjectNames = Enumerable.Empty<XElement>(); var nameElement = callElement.Element(SRC.Name); if(null != nameElement) { name = NameHelper.GetLastName(nameElement); callingObjectNames = NameHelper.GetNameElementsExceptLast(nameElement); } var precedingElements = callElement.ElementsBeforeSelf(); foreach(var pe in precedingElements) { if(pe.Name == OP.Operator && pe.Value == "new") { isConstructor = true; } else if(pe.Name == OP.Operator && pe.Value == "~") { isDestructor = true; } } var methodCall = new MethodCall() { Name = name, IsConstructor = isConstructor, IsDestructor = isDestructor, ParentScope = context.CurrentScope, Location = context.CreateLocation(callElement), }; var arguments = from argument in callElement.Element(SRC.ArgumentList).Elements(SRC.Argument) select CreateResolvableUse(argument, context); methodCall.Arguments = new Collection<IResolvesToType>(arguments.ToList<IResolvesToType>()); IResolvesToType current = methodCall; // This foreach block gets all of the name elements included in the actual <call> element // this is done primarily in C# and Java where they can reliably be included there foreach(var callingObjectName in callingObjectNames.Reverse()) { var callingObject = this.CreateVariableUse(callingObjectName, context); current.CallingObject = callingObject; current = callingObject; } // after getting those, we look at the name elements that appear *before* a call // we keep taking name elements as long as they are preceded by "." or "->" // we want to accept get 'a', 'b', and 'c' from "a.b->c" only 'b' and 'c' from // "a + b->c" var elementsBeforeCall = callElement.ElementsBeforeSelf().ToArray(); int i = elementsBeforeCall.Length - 1; while(i > 0 && elementsBeforeCall[i].Name == OP.Operator && (elementsBeforeCall[i].Value == "." || elementsBeforeCall[i].Value == "->")) { i--; if(i >= 0 && elementsBeforeCall[i].Name == SRC.Name) { var callingObject = CreateVariableUse(elementsBeforeCall[i], context); current.CallingObject = callingObject; current = callingObject; } i--; } if(methodCall.CallingObject == null) { methodCall.AddAliases(context.Aliases); } // TODO can we add aliases to calling object? return methodCall; }