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 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); }