def actionGoto(self): cursor = self.textCursor() start = cursor.selectionStart() end = cursor.selectionEnd() selection = cursor.selectedText() androconf.debug("Goto asked for '%s' (%d, %d)" % (selection, start, end)) if start not in self.doc.binding.keys(): self.mainwin.showStatus("Goto not available. No info for: '%s'." % selection) return t = self.doc.binding[start] if t[0] == 'NAME_METHOD_INVOKE': class_, method_ = t[2].split(' -> ') if class_ == 'this': class_ = self.path else: class_ = classdot2class(class_) else: self.mainwin.showStatus("Goto not available. Info ok: '%s' but object not supported." % selection) return androconf.debug("Found corresponding method: %s -> %s in source file: %s" % (class_, method_, self.path)) if not self.mainwin.doesClassExist(class_): self.mainwin.showStatus("Goto not available. Class: %s not in database." % class_) return self.mainwin.openSourceWindow(class_, method=method_)
def renameElement(self, oldname, newname, info): '''Called back after a user chose a new name for an element. ''' androconf.debug("Renaming %s into %s in %s" % (oldname, newname, self.current_filename)) start, end = info try: t = self.doc.binding[start] except: self.mainwin.showStatus("Unexpected error in renameElement") return # Determine type of the to-be-renamed element and Androguard internal objects type_ = None if t[0] == 'NAME_METHOD_PROTOTYPE': # method definition in a class method_ = t[1] if method_ == self.title: method_ = 'init' proto_ = t[2].method.proto androconf.debug("Found: class=%s, method=%s, proto=%s" % (self.current_class, method_, proto_)) type_ = "METHOD" elif t[0] == 'NAME_METHOD_INVOKE': # method call in a method class_, method_ = t[2].split(' -> ') class_ = classdot2class(class_) if class_ == 'this': class_ = self.path proto_ = proto2methodprotofunc("".join(t[3]) + t[4]) androconf.debug("Found: class=%s, method=%s, proto=%s" % (class_, method_, proto_)) type_ = "METHOD" elif t[0] == 'NAME_PROTOTYPE': # class definition on top of a class class_ = t[2] + '.' + t[1] package_ = t[2] androconf.debug("Found: package=%s, class=%s" % (package_, class_)) type_ = "CLASS" elif t[0] == 'NAME_FIELD': field_item = t[3] type_ = "FIELD" else: self.mainwin.showStatus("Rename not available. Info found: '%s' but object not supported." % selection) return # Do the actual renaming if type_ == "METHOD": if self.method_name_exist(newname): self.mainwin.showStatus("Method name already exist") return method_class_name = self.current_class.get_name() method_name = method_ method_proto = proto_ current_analysis = self.session.get_analysis(self.current_class) method_item = current_analysis.get_method_by_name(method_class_name, method_name, method_proto) if not method_item: self.mainwin.showStatus("Impossible to find the method") return method_item.set_name(str(newname)) #unicode to ascii elif type_ == "CLASS": newname_class = classdot2class(package_ + '.' + newname) self.mainwin.showStatus("New name: %s" % newname_class) class_item = self.current_class #getattr(self.mainwin.d, classdot2func(class_)) class_item.set_name(str(newname_class)) #unicode to ascii self.mainwin.updateDockWithTree() elif type_ == 'FIELD': if self.field_name_exist(newname): self.mainwin.showStatus("Field name already exist") return field_item.set_name(str(newname)) else: self.mainwin.showStatus("Unsupported type: %s" % str(type_)) return self.reload_java_sources()