public static TreeView add_CallMappings(this TreeView treeView,
                                                JavaMetadata_XRefs javaXRefs,
                                                string filter,
                                                bool show_CallsTo,
                                                bool show_IsCalledBy,
                                                bool show_ImplementedBy,
                                                bool show_Implements,
                                                bool show_EnclosingMethod)
        {
            Func <Method_CallMapping, bool> hasChildNodes =
                (value) => {
                return((show_CallsTo && javaXRefs.CallMappings.hasMapping_CallsTo(value.Signature)) ||
                       (show_IsCalledBy && javaXRefs.CallMappings.hasMapping_IsCalledBy(value.Signature)) ||
                       (show_ImplementedBy && javaXRefs.CallMappings.hasMapping_ImplementedBy(value.Signature)) ||
                       (show_Implements && javaXRefs.CallMappings.hasMapping_Implements(value.Signature)) ||
                       (show_EnclosingMethod && javaXRefs.hasMapping_EnclosingMethod(value.Signature)));
            };
            var filteredValues = javaXRefs.CallMappings
                                 .Values
                                 .OrderBy((value) => value.Signature)
                                 .Where((value) => hasChildNodes(value) &&
                                        (filter.inValid() ||
                                         value.Signature.regEx(filter) ||
                                         value.Signature.contains(filter)
                                        )).toList();

            treeView.add_Nodes(filteredValues,
                               (value) => value.Signature,
                               (value) => value,
                               (value) => hasChildNodes(value),
                               (value) => value.Signature.treeNodeColor(javaXRefs.Methods_by_Signature));
            return(treeView);
        }
/*		public static TreeNode add_InterfaceImplementations(this TreeNode treeNode, Method_CallMapping callMapping, Dictionary<string, Method_CallMapping> callMappings , Dictionary<string, Java_Method> methods_bySignature, Dictionary<string, List<Java_Class>> classes_MappedTo_Implementations)
 *              {
 *                      if (methods_bySignature.hasKey(callMapping.Signature))
 *                      {
 *                              var method = methods_bySignature[callMapping.Signature];
 *                              if (method.IsAbstract)
 *                              {
 *                                      var implementations = method.implementations(classes_MappedTo_Implementations);
 *                                      var implementationsNode = treeNode.add_Node("_Implementations");
 *                                      if (implementations.size()==0)
 *                                              implementationsNode.add_Node("..no implementations found..");
 *                                      else
 *                                              foreach(var implementation in implementations)
 *                                                      if (callMappings.hasKey(implementation.Signature))
 *                                                      {
 *                                                              var callMappingImplementation = callMappings[implementation.Signature];
 *                                                              implementationsNode.add_Node(callMappingImplementation.str(), callMappingImplementation, true)
 *                                                                                                 .color(Color.Sienna);
 *                                                      }
 *                                                      else
 *                                                              implementationsNode.add_Node(implementation.Signature);
 *
 *                              }
 *                      }
 *                      return treeNode;
 *              }
 */

        public static JavaMetadata_XRefs showInCodeViewer(this JavaMetadata_XRefs xRefs, ascx_SourceCodeViewer codeViewer, string signature)
        {
            if (xRefs.Methods_by_Signature.hasKey(signature))
            {
                var method = xRefs.Methods_by_Signature[signature];
                var _class = xRefs.Classes_by_Signature[method.ClassName];
                codeViewer.showInCodeViewer(_class, method);
            }
            return(xRefs);
        }
        public static JavaMetadata_XRefs map_JavaMetadata_XRefs(this JavaMetadata_XRefs xRefs)
        {
            xRefs.CallMappings                     = new Dictionary <string, Method_CallMapping>();
            xRefs.Classes_by_Signature             = xRefs.JavaMetadata.classes_IndexedBySignature();
            xRefs.Methods_by_Signature             = xRefs.JavaMetadata.methods_IndexedBySignature();
            xRefs.Classes_MappedTo_Implementations = xRefs.JavaMetadata.classes_MappedTo_Implementations();
            xRefs.Classes_by_EnclosingMethod       = xRefs.JavaMetadata.classes_MappedTo_EnclosingMethod();
            xRefs.Method_by_EnclosingMethod        = xRefs.JavaMetadata.methods_MappedTo_EnclosingMethod();

            foreach (var _class in xRefs.JavaMetadata.Classes)
            {
                foreach (var method in _class.Methods)
                {
                    var callMapping = xRefs.CallMappings.add_Method(method.Signature);

                    //CallsTo and IsCalledBy
                    foreach (var methodCalled in method.methodRefs(_class))
                    {
                        callMapping.CallsTo.Add(methodCalled);
                        var methodCalled_CallMapping = xRefs.CallMappings.add_Method(methodCalled.Signature);

                        methodCalled_CallMapping.IsCalledBy.Add(
                            new MethodCall {
                            Signature   = method.Signature,
                            AtLocations = methodCalled.AtLocations
                        });
                    }
                    //ImplementedBy

                    foreach (var implementedMethod in method.implementations(xRefs.Classes_MappedTo_Implementations))
                    {
                        if (implementedMethod.IsAbstract)
                        {
                            callMapping.ImplementedBy.Add(implementedMethod.Signature.methodCall());
                        }

                        if (method.IsAbstract)
                        {
                            var implementsCallMapping = xRefs.CallMappings.add_Method(implementedMethod.Signature);
                            implementsCallMapping.Implements.Add(method.Signature.methodCall());
                        }
                    }
                }
            }
            xRefs.resolveMethodImplementations();
            return(xRefs);
        }
        // this will add extra mappings that handle the cases where a classA extends classB and then method X(...) (that is implemented in class B)
        // is called using the convension classA.X(...)
        public static JavaMetadata_XRefs resolveMethodImplementations(this JavaMetadata_XRefs xRefs)
        {
            foreach (var _class in xRefs.Classes_MappedTo_Implementations)
            {
                var baseClass = _class.Key;
                foreach (var implementedClass in _class.Value)
                {
                    if (xRefs.Classes_by_Signature.hasKey(baseClass))
                    {
                        foreach (var method in xRefs.Classes_by_Signature[baseClass].Methods)
                        {
                            var rootClassMethod = method.Signature;
                            var methodToFind    = rootClassMethod.replace(method.ClassName, implementedClass.Signature);

                            if (xRefs.CallMappings.hasKey(methodToFind))
                            {
                                if (xRefs.CallMappings[methodToFind].Implements.signatures().contains(rootClassMethod).isFalse())
                                {
                                    xRefs.CallMappings[methodToFind].ImplementedBy.Add(rootClassMethod.methodCall());
                                }
                            }
                            if (xRefs.CallMappings.hasKey(rootClassMethod))
                            {
                                if (method.IsAbstract.isFalse())
                                {
                                    xRefs.CallMappings[rootClassMethod].Implements.Add(methodToFind.methodCall());
                                }
                                else
                                {
                                    //if (xRefs.CallMappings[rootClassMethod].Implements.signatures().contains(methodToFind).isFalse())
                                    xRefs.CallMappings[rootClassMethod].ImplementedBy.Add(methodToFind.methodCall());
                                }
                            }
                        }
                    }
                }
            }
            return(xRefs);
        }
Exemplo n.º 5
0
		public static TreeNode add_EnclosingMethod(this TreeNode treeNode, Method_CallMapping callMapping,JavaMetadata_XRefs xRefs, bool showStubTreeNode)
		{
			if (xRefs.Classes_by_EnclosingMethod.hasKey(callMapping.Signature))
			{
				var enclosedMethodNode = (showStubTreeNode) 
											? treeNode.add_Node("_EnclosedClass (i.e. class by EnclosedMethod)")
											: treeNode;	
				foreach(var _class in xRefs.Classes_by_EnclosingMethod[callMapping.Signature])
				{
					enclosedMethodNode.add_Node(_class.Signature, _class)
									  .add_Nodes(_class.Methods,
									  			 (method)=> method.Signature,
									  			 (method) => xRefs.CallMappings[method.Signature],
											   	 (method) => true, //callMappings.hasMapping_ImplementedBy(implementedBy.Signature), 
											   	 (method) => method.Signature.treeNodeColor(xRefs.Methods_by_Signature));
				}
			}
			
			if (xRefs.Method_by_EnclosingMethod.hasKey(callMapping.Signature))
			{
				var enclosedMethodNode = (showStubTreeNode) 
											? treeNode.add_Node("_EnclosedMethod").color(Color.Gray)
											: treeNode;	
				var enclosedMethod = xRefs.Method_by_EnclosingMethod[callMapping.Signature];
				
				enclosedMethodNode.add_Node(enclosedMethod, 
											xRefs.CallMappings[enclosedMethod],
											true)
								  .color(enclosedMethod.treeNodeColor(xRefs.Methods_by_Signature));
			}
			
			//enclosedMethodNode.add_Nodes(xRefs.Classes_by_EnclosingMethod[callMapping.Signature].OrderBy((enclosedMethod)=>enclosedMethod.Signature));
			/*EnclosedMethodNode.add_Nodes(xRefs.Classes_by_EnclosingMethod[callMapping.Signature].OrderBy((enclosedMethod)=>enclosedMethod.Signature),
									   	(enclosedMethod) => enclosedMethod.Signature,
									   	(enclosedMethod) => xRefs.CallMappings[enclosedMethod.Signature],
									   	(enclosedMethod) => true, //callMappings.hasMapping_ImplementedBy(implementedBy.Signature), 
									   	(enclosedMethod) => enclosedMethod.Signature.treeNodeColor(xRefs.Methods_by_Signature));
			*/
			
			return treeNode;
		}
Exemplo n.º 6
0
		public static TreeView add_CallMappings(this TreeView treeView, 
												JavaMetadata_XRefs javaXRefs,
												string filter, 
												bool show_CallsTo,
												bool show_IsCalledBy,
												bool show_ImplementedBy,
												bool show_Implements,
												bool show_EnclosingMethod)
		{
			Func<Method_CallMapping, bool> hasChildNodes = 
				(value)=>{	
							return (show_CallsTo    		&& javaXRefs.CallMappings.hasMapping_CallsTo(value.Signature)) || 
								   (show_IsCalledBy 		&& javaXRefs.CallMappings.hasMapping_IsCalledBy(value.Signature)) ||
								   (show_ImplementedBy 		&& javaXRefs.CallMappings.hasMapping_ImplementedBy(value.Signature)) ||
								   (show_Implements 		&& javaXRefs.CallMappings.hasMapping_Implements(value.Signature)) ||								   
								   (show_EnclosingMethod    && javaXRefs.hasMapping_EnclosingMethod(value.Signature));
						 };
			var filteredValues = javaXRefs.CallMappings
										  .Values
										  .OrderBy((value)=>value.Signature)
										  .Where((value)=> hasChildNodes(value) &&
													   	   (filter.inValid() ||
													   		value.Signature.regEx(filter) ||
													   		value.Signature.contains(filter)
													   	   )).toList();

			treeView.add_Nodes(filteredValues,
							   (value) => value.Signature,
							   (value) => value,
							   (value) => hasChildNodes(value),
							   (value) => value.Signature.treeNodeColor(javaXRefs.Methods_by_Signature));
			return treeView;
		}
        public static TreeNode add_EnclosingMethod(this TreeNode treeNode, Method_CallMapping callMapping, JavaMetadata_XRefs xRefs, bool showStubTreeNode)
        {
            if (xRefs.Classes_by_EnclosingMethod.hasKey(callMapping.Signature))
            {
                var enclosedMethodNode = (showStubTreeNode)
                                                                                        ? treeNode.add_Node("_EnclosedClass (i.e. class by EnclosedMethod)")
                                                                                        : treeNode;
                foreach (var _class in xRefs.Classes_by_EnclosingMethod[callMapping.Signature])
                {
                    enclosedMethodNode.add_Node(_class.Signature, _class)
                    .add_Nodes(_class.Methods,
                               (method) => method.Signature,
                               (method) => xRefs.CallMappings[method.Signature],
                               (method) => true,                                                                   //callMappings.hasMapping_ImplementedBy(implementedBy.Signature),
                               (method) => method.Signature.treeNodeColor(xRefs.Methods_by_Signature));
                }
            }

            if (xRefs.Method_by_EnclosingMethod.hasKey(callMapping.Signature))
            {
                var enclosedMethodNode = (showStubTreeNode)
                                                                                        ? treeNode.add_Node("_EnclosedMethod").color(Color.Gray)
                                                                                        : treeNode;
                var enclosedMethod = xRefs.Method_by_EnclosingMethod[callMapping.Signature];

                enclosedMethodNode.add_Node(enclosedMethod,
                                            xRefs.CallMappings[enclosedMethod],
                                            true)
                .color(enclosedMethod.treeNodeColor(xRefs.Methods_by_Signature));
            }

            //enclosedMethodNode.add_Nodes(xRefs.Classes_by_EnclosingMethod[callMapping.Signature].OrderBy((enclosedMethod)=>enclosedMethod.Signature));

            /*EnclosedMethodNode.add_Nodes(xRefs.Classes_by_EnclosingMethod[callMapping.Signature].OrderBy((enclosedMethod)=>enclosedMethod.Signature),
             *                                                      (enclosedMethod) => enclosedMethod.Signature,
             *                                                      (enclosedMethod) => xRefs.CallMappings[enclosedMethod.Signature],
             *                                                      (enclosedMethod) => true, //callMappings.hasMapping_ImplementedBy(implementedBy.Signature),
             *                                                      (enclosedMethod) => enclosedMethod.Signature.treeNodeColor(xRefs.Methods_by_Signature));
             */

            return(treeNode);
        }
 public static bool hasMapping_EnclosingMethod(this JavaMetadata_XRefs javaXRefs, string signature)
 {
     return(javaXRefs.Classes_by_EnclosingMethod.hasKey(signature) ||
            javaXRefs.Method_by_EnclosingMethod.hasKey(signature));
 }
Exemplo n.º 9
0
		public static TreeView add_TreeView_For_CommandClasses_Visualization(this Control control, JavaMetadata_XRefs xRefs)
		{
			var treeView = control.add_TreeView();   

			var showHttpName = false; 
			var configPanel = control.insert_Below(30);
			configPanel.add_CheckBox("Show Http Variable Name",0,0,(value)=> showHttpName = value)
					   .autoSize(); 
			
			Func<Java_Method,string> getMethodNodeText =
				(method) => {
								if (showHttpName)
									return method.Name
												 .subString(3)
												 .lowerCaseFirstLetter();
									
								return "{0}   {1}".format(method.Name, method.returnType());
								//.GenericSignature.isNull()
								//											? method.ParametersAndReturnType
								//											: method.GenericSignature.returnType());
							};
			Action<TreeNode, string> add_Getters = 
				(treeNode, className)=> {
											if (xRefs.Classes_by_Signature.hasKey(className))
											{									
												var _class = xRefs.Classes_by_Signature[className];  
												var getters = _class.java_Methods_Getters_Public().with_Primitive_ReturnType(false); 
												
												treeNode.add_Nodes( getters.Where((method)=>method.returnType()!="java.lang.String"),   
																	(method)=> getMethodNodeText(method),
																	//(method)=> method.str(),
																	(method)=> method.returnType(), 
																	(method)=> true, 
																	(method)=> Color.DarkBlue);
			
											}
											else
												treeNode.add_Node("[Getters] ... class not found: {0}".format(className))
														.color(Color.DarkRed);
										}; 
			  
			Action<TreeNode, string> add_Setters =  
				(treeNode, className)=> { 
											if (xRefs.Classes_by_Signature.hasKey(className))
											{									 
												var _class = xRefs.Classes_by_Signature[className];     
												var setters = _class.java_Methods_Setters_Public().with_Primitive_Parameter(true);  
												
												treeNode.add_Nodes( setters, 
																	//(method)=> "{0}   {1}".format(method.Name, method.ParametersAndReturnType), 
																	(method)=> getMethodNodeText(method),
																	(method)=> method ,
																	(method)=> false,
																	(method)=> Color.DarkGreen);
			
											}
											else
												treeNode.add_Node("[Setters] ... class not found: {0}".format(className))
														.color(Color.DarkRed);
										};
										
			
			treeView.beforeExpand<string>(
				(treeNode, returnType)=>{	
											var className = (returnType.starts("L"))
																? returnType.removeFirstChar().removeLastChar()
																: returnType;
											add_Getters(treeNode, className);
											add_Setters(treeNode, className);								
											//if (xRefs.Classes_by_Signature.hasKey(className))
											//	treeNode.add_Node("FOUND Class!!!");
											//else
											//	treeNode.add_Node(returnType);					
							  			});
			return treeView;							  			
		}
Exemplo n.º 10
0
    	public static SpringMvcController mapCommandClass(this SpringMvcController controller, string javaClass, JavaMetadata_XRefs xRefs)
    	{
    		if (controller.CommandClass.isNull() && controller.JavaClass.valid()) 
			{ 		 
				 var _class = xRefs.JavaMetadata.java_Classes().signature(javaClass);				 
				 if (_class.notNull()) 
				 {
				 	if (controller.CommandName.isNull())
				 	{
				 		var initMethod = _class.java_Methods().name("<init>"); 		 	
						foreach(var methodRef in initMethod.methodRefs(_class))
							if (methodRef.Signature.contains("setCommandName"))
							{
								var location = methodRef.AtLocations[0];
								var instructions_byPc = initMethod.instructions_byPc(); 
								var targetIndex = instructions_byPc[location.Pc -2].Target_Index;					
								controller.CommandName =  _class.constantsPool_byIndex()[targetIndex].str();
								"resolved command name for {0} = {1}".info(controller.JavaClass, controller.CommandName);
								break;
							}
					}
					if (controller.CommandClass.isNull())
					{										
						var formBackingObject = _class.java_Methods().name("formBackingObject"); 
						if (formBackingObject.notNull())
						{
							var numberOfInstructions = formBackingObject.Instructions.size();
							if (formBackingObject.Instructions[numberOfInstructions-3].OpCode == "__aload" && 
								formBackingObject.Instructions[numberOfInstructions-2].OpCode == "__areturn")
							{
								
								var variablesByIndex = formBackingObject.variables_byIndex(); 
								var variableIndex = formBackingObject.Instructions[numberOfInstructions-3].Target_Index;
								if (variablesByIndex[variableIndex].size() > 0)	
								{
									controller.CommandClass = variablesByIndex[variableIndex].last().Descriptor.removeFirstChar().removeLastChar();
									"resolved CommandClass for CommandName {0} -> {1}".info(controller.CommandName, controller.CommandClass);
								}								
							}
						}											
					}						
				}		 				 
			}		
			return controller;
 	   }
Exemplo n.º 11
0
 	public static SpringMvcController mapCommandClass(this SpringMvcController controller, JavaMetadata_XRefs xRefs)
 	{
 		return controller.mapCommandClass(controller.JavaClass, xRefs);
 	}
Exemplo n.º 12
0
    	public static SpringMvcMappings mapCommandClass_using_XRefs(this SpringMvcMappings mvcMappings, JavaMetadata_XRefs xRefs)
    	{    		  
			var controllers_by_JavaClass = mvcMappings.controllers_by_JavaClass(); 
			
			foreach(var controller in mvcMappings.Controllers)
			{
				controller.mapCommandClass(xRefs);	
				if(controller.CommandName.notNull() && controller.CommandClass.isNull())
				{
					"CommandClass not found but CommandName exists: {0}".debug(controller);
					if (xRefs.Classes_by_Signature.hasKey(controller.JavaClass))
					{
						"Found XRefs for Class: {0}".debug(controller.JavaClass);
						var javaClass = xRefs.Classes_by_Signature[controller.JavaClass];
						controller.mapCommandClass(javaClass.SuperClass,xRefs);			
					}
				}
			}
    		return mvcMappings;	
    	}
Exemplo n.º 13
0
		public static TreeView add_TreeView_For_CommandClasses_Visualization(this Control control, JavaMetadata_XRefs xRefs)
		{
			return control.add_TreeView_For_CommandClasses_Visualization(xRefs,null, null);
		}