public static API_IKVMC_Java_Metadata javaMetadata(this string file)
        {
            API_IKVMC_Java_Metadata javaMetadata = null;

            try
            {
                javaMetadata = (API_IKVMC_Java_Metadata)O2LiveObjects.get(file);                        // try first to get a cached version of this file
            }
            catch
            {}
            if (javaMetadata.isNull() && file.fileExists())
            {
                "Cached version not found, loading from disk".info();
                if (file.extension(".xml"))
                {
                    javaMetadata = file.load <API_IKVMC_Java_Metadata>();
                }
                else
                {
                    javaMetadata = new API_IKVMC().create_JavaMetadata(file);
                }
                O2LiveObjects.set(file, javaMetadata);
            }
            return(javaMetadata);
        }
        public static Dictionary <string, Java_Method> methods_IndexedBySignature(this API_IKVMC_Java_Metadata javaMetadata)
        {
            var methodsBySignature = new Dictionary <string, Java_Method>();

            foreach (var _class in javaMetadata.Classes)
            {
                foreach (var item in _class.Methods.indexedBySignature())
                {
                    methodsBySignature.Add(item.Key, item.Value);
                }
            }
            return(methodsBySignature);
        }
        public static Dictionary <string, string> methods_MappedTo_EnclosingMethod(this API_IKVMC_Java_Metadata javaMetadata)
        {
            var enclosingMethods = new Dictionary <string, string>();

            foreach (var _class in javaMetadata.Classes)
            {
                if (_class.EnclosingMethod.notNull())
                {
                    foreach (var method in _class.Methods)
                    {
                        enclosingMethods.add(method.Signature, _class.EnclosingMethod);
                    }
                }
            }
            return(enclosingMethods);
        }
        public static API_IKVMC_Java_Metadata create_JavaMetadata(this API_IKVMC ikvmc, string fileToProcess)
        {
            var o2Timer      = new O2Timer("Created JavaData for {0}".format(fileToProcess)).start();
            var javaMetaData = new API_IKVMC_Java_Metadata();

            javaMetaData.FileProcessed = fileToProcess;
            var classes = ikvmc.getRawClassesData_FromFile_ClassesOrJar(fileToProcess);

            foreach (DictionaryEntry item in classes)
            {
                var name      = item.Key.str();
                var bytes     = (byte[])item.Value.field("data");
                var classFile = ikvmc.createClassFile(bytes, 1);                                        // value of 1 gets the local variables
                var javaClass = new Java_Class {
                    Signature   = name,
                    Name        = name.contains(".") ? name.split(".").last() : name,
                    SourceFile  = classFile.prop("SourceFileAttribute").str(),
                    IsAbstract  = classFile.prop("IsAbstract").str().toBool(),
                    IsInterface = classFile.prop("IsInterface").str().toBool(),
                    IsInternal  = classFile.prop("IsInternal").str().toBool(),
                    IsPublic    = classFile.prop("IsPublic").str().toBool(),
                    SuperClass  = classFile.prop("SuperClass").str()
                };

                if (classFile.prop("GenericSignature").notNull())
                {
                    javaClass.GenericSignature = classFile.prop("GenericSignature").str();
                }

                javaClass.ConstantsPool = classFile.getConstantPoolEntries();
                javaClass.map_Annotations(classFile)
                .map_Interfaces(classFile)
                .map_Fields(classFile)
                .map_Methods(classFile)
                .map_EnclosingMethod(classFile);

                javaClass.map_LineNumbers(ikvmc.createClassFile(bytes, 2));                // for this we need to call createClassFile with the value of 2 (to get the source code references)

                javaMetaData.Classes.Add(javaClass);
                //break; //
            }
            o2Timer.stop();
            return(javaMetaData);
        }
 public static JavaMetadata_XRefs get_XRefs(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return(javaMetadata.map_JavaMetadata_XRefs());
 }
 public JavaMetadata_XRefs(API_IKVMC_Java_Metadata javaMetadata)
 {
     JavaMetadata = javaMetadata;
     this.map_JavaMetadata_XRefs();
 }
		public static Action<string> viewJavaMappings(this Control control, API_IKVMC_Java_Metadata javaMappings)			
		{	
			control.clear();
			Dictionary<string, Java_Class> classes_bySignature = null;
			Dictionary<string, Java_Method> methods_bySignature = null;
			Dictionary<string, List<Java_Class>> classes_MappedTo_Implementations = null;
			
			var showFullClassNames = false;
			var openSourceCodeReference = false;
			var classFilter = "";
			Action refresh = null;
			API_IKVMC_Java_Metadata currentJavaMetaData = null;
			var treeView = control.add_TreeView_with_PropertyGrid();
			var codeEditor = control.insert_Right().add_SourceCodeEditor();
			var configPanel = control.insert_Below(40,"Config");
			
			treeView.insert_Above(20).add_TextBox("Class Filter","")
									 .onEnter((text) => { 
											 				classFilter = text ;
											 				refresh();
											 			});
			
			configPanel.add_CheckBox("Show Full Class names", 0,0, 
							(value)=>{
										showFullClassNames = value;
										treeView.collapse();
									 }).autoSize()
					   .append_Control<CheckBox>().set_Text("Open SourceCode Reference")
					   							  .autoSize()					   							  
					   							  .onChecked((value)=> openSourceCodeReference=value)
					   							  .check();
			//BeforeExpand Events
			Action<TreeNode, List<Java_Class>> add_Classes = 
				(treeNode, classes)=>{
										treeNode.add_Nodes(classes.Where((_class)=> classFilter.inValid() || _class.Signature.regEx(classFilter))
																  .OrderBy((_class)=>_class.Name),
														   (_class)=> (showFullClassNames)
														   					? _class.Signature
														   					: _class.Name ,
							 							   (_class)=> true,
														   (_class)=> (_class.IsInterface) 
														   					? Color.DarkRed 
														   					: Color.DarkOrange);
									 };
									 
			treeView.beforeExpand<API_IKVMC_Java_Metadata>(
				(treeNode, javaMetadata)=>{												
												add_Classes(treeNode, javaMetadata.Classes);
										  });
					 					  
			treeView.beforeExpand<Java_Class>(   
				(treeNode, _class)=>{
										if(classes_MappedTo_Implementations.hasKey(_class.Signature))
										{
											add_Classes(treeNode.add_Node("_Implementations"), 
														classes_MappedTo_Implementations[_class.Signature]);
										}
										
										
										treeNode.add_ConstantsPool(_class)
												.add_Annotations(true, _class.Annotations);
										treeNode.add_Nodes(_class.Methods.OrderBy((item)=>item.Name),
														   (method)=> method.str(),
														   (method)=> method.IsAbstract.isFalse(),
													 	   (method)=> (method.IsAbstract)
													 	   					? Color.DarkRed
													 	   					: Color.DarkBlue);
									});
										    
			treeView.beforeExpand<Java_Method>( 
				(treeNode, method)=>{  																						
										treeNode.add_ConstantsPool(method,classes_bySignature[method.ClassName])
												.add_Annotations(true, method.Annotations)
											    .add_Variables(method);

										treeNode.add_Node("_Instructions")  											    
												.add_Instructions(method,classes_bySignature[method.ClassName]); 
																		
									}); 
									
			treeView.beforeExpand<object[]>(     
				(treeNode, annotations)=>{
											treeNode.add_Annotations(false, annotations);
										});		
			
			treeView.beforeExpand<List<ConstantPool>>(
				(treeNode, constantsPool)=>{
											treeNode.add_Nodes(constantsPool.OrderBy((item)=>item.str()),
															   (constant)=> constant.str(),
														       (constant)=> false,
													 	       (constant)=> methods_bySignature.hasKey(constant.Value)
													 	       					? Color.Green
													 	       					: Color.Sienna);
										});												
			//AfterSelect Events
						  
			treeView.afterSelect<Java_Class>(  
				(_class) => { 
								if (openSourceCodeReference)
								{
									codeEditor.showInCodeEditor(classes_bySignature[_class.Signature], _class.Methods.first());	
									treeView.focus();  
								}
							});
			 
			treeView.afterSelect<Java_Method>(
				(method) => {
								if (openSourceCodeReference)
								{
									codeEditor.showInCodeEditor(classes_bySignature[method.ClassName], method); 
									treeView.focus();  
								}
							});
							
			treeView.afterSelect<Java_Instruction>(
				(instruction) => {	
									if (openSourceCodeReference)
									{
										codeEditor.gotoLine(instruction.Line_Number,4); 
										treeView.focus();  
									}
							});				
			treeView.afterSelect<ConstantPool>(			
				(constantPool)=> {
									if (methods_bySignature.hasKey(constantPool.Value))
									{
										var method = methods_bySignature[constantPool.Value];
										codeEditor.showInCodeEditor(classes_bySignature[method.ClassName], method); 									
										treeView.focus();
									}
								});
			//Other events						
			
			refresh = ()=>{
								if(currentJavaMetaData.notNull())
								{
									treeView.clear();
									classes_bySignature				 = currentJavaMetaData.classes_IndexedBySignature();    			
									methods_bySignature 			 = currentJavaMetaData.methods_IndexedBySignature();    										
									classes_MappedTo_Implementations = currentJavaMetaData.classes_MappedTo_Implementations(); 									
									treeView.add_Node(currentJavaMetaData.str(), currentJavaMetaData, true); 				
									treeView.nodes().first().expand();
									//treeView.focus();
								}
									else
										treeView.add_Node("Drop Jar/Zip or class file to view its contents");		
							};
			
			Action<API_IKVMC_Java_Metadata> loadJavaMappings =
				(_javaMappings)=>{		
									currentJavaMetaData = _javaMappings;
									refresh();									
								 };
								 
			Action<string> loadFile = 
				(file)=>{
							treeView.azure();
							O2Thread.mtaThread(
								()=>{
										if(file.extension(".xml"))
											loadJavaMappings(file.load<API_IKVMC_Java_Metadata>());
										else
											loadJavaMappings(new API_IKVMC().create_JavaMetadata(file));
										treeView.white();
									});
						};
					
			treeView.onDrop(loadFile);
			
			loadJavaMappings(javaMappings);			
		
			return loadFile;
		}
		public static API_IKVMC_Java_Metadata create_JavaMetadata(this API_IKVMC ikvmc, string fileToProcess)
		{
			var o2Timer = new O2Timer("Created JavaData for {0}".format(fileToProcess)).start();
			var javaMetaData = new API_IKVMC_Java_Metadata();
			javaMetaData.FileProcessed = fileToProcess;
			var classes = ikvmc.getRawClassesData_FromFile_ClassesOrJar(fileToProcess);
			foreach(DictionaryEntry item in classes)
			{
				var name = item.Key.str();
				var bytes = (byte[])item.Value.field("data");
				var classFile = ikvmc.createClassFile(bytes,1);				// value of 1 gets the local variables
				var javaClass = new Java_Class {
													Signature = name,													
													Name = name.contains(".") ? name.split(".").last() : name,
													SourceFile = classFile.prop("SourceFileAttribute").str(),
							 						IsAbstract = classFile.prop("IsAbstract").str().toBool(),
													IsInterface = classFile.prop("IsInterface").str().toBool(),
													IsInternal = classFile.prop("IsInternal").str().toBool(),
													IsPublic = classFile.prop("IsPublic").str().toBool(),
													SuperClass = classFile.prop("SuperClass").str()
											   };
				
				if (classFile.prop("GenericSignature").notNull())
					javaClass.GenericSignature = classFile.prop("GenericSignature").str();
					
				javaClass.ConstantsPool = classFile.getConstantPoolEntries();
				javaClass.map_Annotations(classFile)
						 .map_Interfaces(classFile)
						 .map_Fields(classFile)
						 .map_Methods(classFile)
						 .map_EnclosingMethod(classFile);								
						 				
				javaClass.map_LineNumbers(ikvmc.createClassFile(bytes,2)); // for this we need to call createClassFile with the value of 2 (to get the source code references)
				
				javaMetaData.Classes.Add(javaClass);												
				//break; // 
			}
			o2Timer.stop();
			return javaMetaData;
		}
 public static List <Java_Method> java_Methods_Abstract(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return((from method in javaMetadata.java_Methods()
             where method.IsAbstract
             select method).toList());
 }
 public static Dictionary <string, Java_Class> classes_IndexedBySignature(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return(javaMetadata.Classes.indexedBySignature());
 }
 public static List <Java_Class> java_Classes(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return(javaMetadata.Classes);
 }
        public static Dictionary <string, List <Java_Class> > classes_MappedTo_EnclosingMethod(this API_IKVMC_Java_Metadata javaMetadata)
        {
            var enclosingMethods = new Dictionary <string, List <Java_Class> >();

            foreach (var _class in javaMetadata.Classes)
            {
                if (_class.EnclosingMethod.notNull())
                {
                    enclosingMethods.add(_class.EnclosingMethod, _class);
                }
            }
            return(enclosingMethods);
        }
        public static Dictionary <string, List <Java_Class> > classes_MappedTo_Implementations(this API_IKVMC_Java_Metadata javaMetadata)
        {
            //next map the Interfaces
            var implementations = new Dictionary <string, List <Java_Class> >();

            foreach (var _class in javaMetadata.Classes)
            {
                foreach (var _interface in _class.Interfaces)
                {
                    implementations.add(_interface, _class);
                }
            }


            //next map the SuperClasses
            var classes_bySignature = javaMetadata.classes_IndexedBySignature();

            foreach (var _class in javaMetadata.Classes)
            {
                if (_class.SuperClass.valid() && classes_bySignature.hasKey(_class.SuperClass))
                {
                    implementations.add(_class.SuperClass, _class);                    //.Signature, classes_bySignature[_class.SuperClass]);
                }
            }
            return(implementations);
        }
 public static List <Java_Class> classes_ThatAre_Interfaces(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return((from _class in javaMetadata.Classes
             where _class.IsInterface
             select _class).toList());
 }
 public static JavaMetadata_XRefs map_JavaMetadata_XRefs(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return(new JavaMetadata_XRefs(javaMetadata).map_JavaMetadata_XRefs());
 }
示例#16
0
		public JavaMetadata_XRefs(API_IKVMC_Java_Metadata javaMetadata)
		{
			JavaMetadata = javaMetadata;
			this.map_JavaMetadata_XRefs();
		}		
 public static List <Java_Class> java_Classes_with_EnclosingMethod(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return((from _class in javaMetadata.java_Classes()
             where _class.EnclosingMethod.notNull()
             select _class).toList());
 }
示例#18
0
        public static Action <string> viewJavaMappings(this Control control, API_IKVMC_Java_Metadata javaMappings)
        {
            control.clear();
            Dictionary <string, Java_Class>         classes_bySignature = null;
            Dictionary <string, Java_Method>        methods_bySignature = null;
            Dictionary <string, List <Java_Class> > classes_MappedTo_Implementations = null;

            var    showFullClassNames      = false;
            var    openSourceCodeReference = false;
            var    classFilter             = "";
            Action refresh = null;
            API_IKVMC_Java_Metadata currentJavaMetaData = null;
            var treeView    = control.add_TreeView_with_PropertyGrid();
            var codeEditor  = control.insert_Right().add_SourceCodeEditor();
            var configPanel = control.insert_Below(40, "Config");

            treeView.insert_Above(20).add_TextBox("Class Filter", "")
            .onEnter((text) => {
                classFilter = text;
                refresh();
            });

            configPanel.add_CheckBox("Show Full Class names", 0, 0,
                                     (value) => {
                showFullClassNames = value;
                treeView.collapse();
            }).autoSize()
            .append_Control <CheckBox>().set_Text("Open SourceCode Reference")
            .autoSize()
            .onChecked((value) => openSourceCodeReference = value)
            .check();
            //BeforeExpand Events
            Action <TreeNode, List <Java_Class> > add_Classes =
                (treeNode, classes) => {
                treeNode.add_Nodes(classes.Where((_class) => classFilter.inValid() || _class.Signature.regEx(classFilter))
                                   .OrderBy((_class) => _class.Name),
                                   (_class) => (showFullClassNames)
                                                                                                                                                        ? _class.Signature
                                                                                                                                                        : _class.Name,
                                   (_class) => true,
                                   (_class) => (_class.IsInterface)
                                                                                                                                                        ? Color.DarkRed
                                                                                                                                                        : Color.DarkOrange);
            };

            treeView.beforeExpand <API_IKVMC_Java_Metadata>(
                (treeNode, javaMetadata) => {
                add_Classes(treeNode, javaMetadata.Classes);
            });

            treeView.beforeExpand <Java_Class>(
                (treeNode, _class) => {
                if (classes_MappedTo_Implementations.hasKey(_class.Signature))
                {
                    add_Classes(treeNode.add_Node("_Implementations"),
                                classes_MappedTo_Implementations[_class.Signature]);
                }


                treeNode.add_ConstantsPool(_class)
                .add_Annotations(true, _class.Annotations);
                treeNode.add_Nodes(_class.Methods.OrderBy((item) => item.Name),
                                   (method) => method.str(),
                                   (method) => method.IsAbstract.isFalse(),
                                   (method) => (method.IsAbstract)
                                                                                                                                                        ? Color.DarkRed
                                                                                                                                                        : Color.DarkBlue);
            });

            treeView.beforeExpand <Java_Method>(
                (treeNode, method) => {
                treeNode.add_ConstantsPool(method, classes_bySignature[method.ClassName])
                .add_Annotations(true, method.Annotations)
                .add_Variables(method);

                treeNode.add_Node("_Instructions")
                .add_Instructions(method, classes_bySignature[method.ClassName]);
            });

            treeView.beforeExpand <object[]>(
                (treeNode, annotations) => {
                treeNode.add_Annotations(false, annotations);
            });

            treeView.beforeExpand <List <ConstantPool> >(
                (treeNode, constantsPool) => {
                treeNode.add_Nodes(constantsPool.OrderBy((item) => item.str()),
                                   (constant) => constant.str(),
                                   (constant) => false,
                                   (constant) => methods_bySignature.hasKey(constant.Value)
                                                                                                                                                        ? Color.Green
                                                                                                                                                        : Color.Sienna);
            });
            //AfterSelect Events

            treeView.afterSelect <Java_Class>(
                (_class) => {
                if (openSourceCodeReference)
                {
                    codeEditor.showInCodeEditor(classes_bySignature[_class.Signature], _class.Methods.first());
                    treeView.focus();
                }
            });

            treeView.afterSelect <Java_Method>(
                (method) => {
                if (openSourceCodeReference)
                {
                    codeEditor.showInCodeEditor(classes_bySignature[method.ClassName], method);
                    treeView.focus();
                }
            });

            treeView.afterSelect <Java_Instruction>(
                (instruction) => {
                if (openSourceCodeReference)
                {
                    codeEditor.gotoLine(instruction.Line_Number, 4);
                    treeView.focus();
                }
            });
            treeView.afterSelect <ConstantPool>(
                (constantPool) => {
                if (methods_bySignature.hasKey(constantPool.Value))
                {
                    var method = methods_bySignature[constantPool.Value];
                    codeEditor.showInCodeEditor(classes_bySignature[method.ClassName], method);
                    treeView.focus();
                }
            });
            //Other events

            refresh = () => {
                if (currentJavaMetaData.notNull())
                {
                    treeView.clear();
                    classes_bySignature = currentJavaMetaData.classes_IndexedBySignature();
                    methods_bySignature = currentJavaMetaData.methods_IndexedBySignature();
                    classes_MappedTo_Implementations = currentJavaMetaData.classes_MappedTo_Implementations();
                    treeView.add_Node(currentJavaMetaData.str(), currentJavaMetaData, true);
                    treeView.nodes().first().expand();
                    //treeView.focus();
                }
                else
                {
                    treeView.add_Node("Drop Jar/Zip or class file to view its contents");
                }
            };

            Action <API_IKVMC_Java_Metadata> loadJavaMappings =
                (_javaMappings) => {
                currentJavaMetaData = _javaMappings;
                refresh();
            };

            Action <string> loadFile =
                (file) => {
                treeView.azure();
                O2Thread.mtaThread(
                    () => {
                    if (file.extension(".xml"))
                    {
                        loadJavaMappings(file.load <API_IKVMC_Java_Metadata>());
                    }
                    else
                    {
                        loadJavaMappings(new API_IKVMC().create_JavaMetadata(file));
                    }
                    treeView.white();
                });
            };

            treeView.onDrop(loadFile);

            loadJavaMappings(javaMappings);

            return(loadFile);
        }
 public static List <Java_Method> java_Methods(this API_IKVMC_Java_Metadata javaMetadata)
 {
     return((from _class in javaMetadata.Classes
             from method in _class.Methods
             select method).toList());
 }