public override void TraverseChildren(IMethodCall methodCall) { string target; if (isNavigationOnBackKeyPressHandler(methodCall, out target)) { ICollection <Tuple <IMethodReference, string> > targets; try { targets = PhoneCodeHelper.instance().BackKeyNavigatingOffenders[typeTraversed]; } catch (KeyNotFoundException) { targets = new HashSet <Tuple <IMethodReference, string> >(); } targets.Add(Tuple.Create <IMethodReference, string>(methodTraversed, "\"" + target + "\"")); PhoneCodeHelper.instance().BackKeyNavigatingOffenders[typeTraversed] = targets; } else if (isCancelOnBackKeyPressHandler(methodCall)) { PhoneCodeHelper.instance().BackKeyCancellingOffenders.Add(Tuple.Create <ITypeReference, string>(typeTraversed, "")); } // re-check whether it is an event cancellation call if (isEventCancellationMethodCall(methodCall)) { PhoneCodeHelper.instance().KnownEventCancellingMethods.Add(methodTraversed); } // check whether it is a NavigationService call IMethodReference methodToCall = methodCall.MethodToCall; ITypeReference callType = methodToCall.ContainingType; if (!callType.ResolvedType.Equals(navigationSvcType.ResolvedType)) { return; } string methodToCallName = methodToCall.Name.Value; if (!PhoneCodeHelper.NAV_CALLS.Contains(methodToCallName)) { return; } navCallFound = true; // TODO check what to do with these if (methodToCallName == "GoForward" || methodToCallName == "StopLoading") { // TODO forward navigation is not supported by the phone // TODO StopLoading is very async, I don't think we may verify this behaviour // TODO possibly log return; } else { currentStaticMode = StaticURIMode.NOT_STATIC; if (methodToCallName == "GoBack") { navCallIsStatic = false; navCallIsBack = true; } else // Navigate() { navCallIsBack = false; // check for different static patterns that we may be able to verify IExpression uriArg = methodCall.Arguments.First(); if (UriHelper.isArgumentURILocallyCreatedStatic(uriArg, host, out unpurifiedFoundURI)) { navCallIsStatic = true; currentStaticMode = StaticURIMode.STATIC_URI_CREATION_ONSITE; } else if (UriHelper.isArgumentURILocallyCreatedStaticRoot(uriArg, host, out unpurifiedFoundURI)) { navCallIsStatic = true; currentStaticMode = StaticURIMode.STATIC_URI_ROOT_CREATION_ONSITE; } else { // get reason //ICreateObjectInstance creationSite = methodCall.Arguments.First() as ICreateObjectInstance; //if (creationSite == null) // notStaticReason = "URI not created at call site"; //else // notStaticReason = "URI not initialized as a static string"; } } if (navCallFound && !navCallIsBack) { // check this method as a navigation method PhoneCodeHelper.instance().KnownNavigatingMethods.Add(methodTraversed); } //Console.Write("Page navigation event found. Target is static? " + (isStatic ? "YES" : "NO")); //if (!isStatic) { // Console.WriteLine(" -- Reason: " + notStaticReason); //} else { // Console.WriteLine(""); //} } }
public override void TraverseChildren(IMethodCall methodCall) { string target; if (isNavigationOnBackKeyPressHandler(methodCall, out target)) { ICollection<Tuple<IMethodReference,string>> targets; try { targets= PhoneCodeHelper.instance().BackKeyNavigatingOffenders[typeTraversed]; } catch (KeyNotFoundException) { targets = new HashSet<Tuple<IMethodReference,string>>(); } targets.Add(Tuple.Create<IMethodReference,string>(methodTraversed, "\"" + target + "\"")); PhoneCodeHelper.instance().BackKeyNavigatingOffenders[typeTraversed]= targets; } else if (isCancelOnBackKeyPressHandler(methodCall)) { PhoneCodeHelper.instance().BackKeyCancellingOffenders.Add(Tuple.Create<ITypeReference, string>(typeTraversed,"")); } // re-check whether it is an event cancellation call if (isEventCancellationMethodCall(methodCall)) { PhoneCodeHelper.instance().KnownEventCancellingMethods.Add(methodTraversed); } // check whether it is a NavigationService call IMethodReference methodToCall= methodCall.MethodToCall; ITypeReference callType= methodToCall.ContainingType; if (!callType.ResolvedType.Equals(navigationSvcType.ResolvedType)) return; string methodToCallName= methodToCall.Name.Value; if (!PhoneCodeHelper.NAV_CALLS.Contains(methodToCallName)) return; navCallFound = true; // TODO check what to do with these if (methodToCallName == "GoForward" || methodToCallName == "StopLoading") { // TODO forward navigation is not supported by the phone // TODO StopLoading is very async, I don't think we may verify this behaviour // TODO possibly log return; } else { currentStaticMode = StaticURIMode.NOT_STATIC; if (methodToCallName == "GoBack") { navCallIsStatic = false; navCallIsBack = true; } else { // Navigate() navCallIsBack = false; // check for different static patterns that we may be able to verify IExpression uriArg = methodCall.Arguments.First(); if (UriHelper.isArgumentURILocallyCreatedStatic(uriArg, host, out unpurifiedFoundURI)) { navCallIsStatic = true; currentStaticMode = StaticURIMode.STATIC_URI_CREATION_ONSITE; } else if (UriHelper.isArgumentURILocallyCreatedStaticRoot(uriArg, host, out unpurifiedFoundURI)) { navCallIsStatic = true; currentStaticMode = StaticURIMode.STATIC_URI_ROOT_CREATION_ONSITE; } else { // get reason //ICreateObjectInstance creationSite = methodCall.Arguments.First() as ICreateObjectInstance; //if (creationSite == null) // notStaticReason = "URI not created at call site"; //else // notStaticReason = "URI not initialized as a static string"; } } if (navCallFound && !navCallIsBack) { // check this method as a navigation method PhoneCodeHelper.instance().KnownNavigatingMethods.Add(methodTraversed); } //Console.Write("Page navigation event found. Target is static? " + (isStatic ? "YES" : "NO")); //if (!isStatic) { // Console.WriteLine(" -- Reason: " + notStaticReason); //} else { // Console.WriteLine(""); //} } }