DocumentationTools/APIGenerator.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1342
30226d5a7ffb
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
7 Module implementing the builtin API generator. 7 Module implementing the builtin API generator.
8 8
9 """ 9 """
10 10
11 from QScintilla.Editor import Editor 11 from QScintilla.Editor import Editor
12
12 13
13 class APIGenerator(object): 14 class APIGenerator(object):
14 """ 15 """
15 Class implementing the builtin documentation generator. 16 Class implementing the builtin documentation generator.
16 """ 17 """
24 25
25 def genAPI(self, newStyle, basePackage, includePrivate): 26 def genAPI(self, newStyle, basePackage, includePrivate):
26 """ 27 """
27 Method to generate the source code documentation. 28 Method to generate the source code documentation.
28 29
29 @param newStyle flag indicating the api generation for QScintilla 1.7 and 30 @param newStyle flag indicating the api generation for QScintilla 1.7 and
30 newer (boolean) (ignored) 31 newer (boolean) (ignored)
31 @param basePackage name of the base package (string) 32 @param basePackage name of the base package (string)
32 @param includePrivate flag indicating to include 33 @param includePrivate flag indicating to include
33 private methods/functions (boolean) 34 private methods/functions (boolean)
34 @return The API information. (string) 35 @return The API information. (string)
35 """ 36 """
36 self.includePrivate = includePrivate 37 self.includePrivate = includePrivate
37 modulePath = self.module.name.split('.') 38 modulePath = self.module.name.split('.')
56 private = obj.isPrivate() and not self.includePrivate 57 private = obj.isPrivate() and not self.includePrivate
57 return private 58 return private
58 59
59 def __addGlobalsAPI(self): 60 def __addGlobalsAPI(self):
60 """ 61 """
61 Private method to generate the api section for global variables. 62 Private method to generate the api section for global variables.
62 """ 63 """
63 moduleNameStr = "{0}".format(self.moduleName) 64 moduleNameStr = "{0}".format(self.moduleName)
64 65
65 for globalName in sorted(self.module.globals.keys()): 66 for globalName in sorted(self.module.globals.keys()):
66 if not self.__isPrivate(self.module.globals[globalName]): 67 if not self.__isPrivate(self.module.globals[globalName]):
97 elif _class.isProtected(): 98 elif _class.isProtected():
98 id = Editor.ClassProtectedID 99 id = Editor.ClassProtectedID
99 else: 100 else:
100 id = Editor.ClassPrivateID 101 id = Editor.ClassPrivateID
101 self.api.append('{0}{1}?{2:d}({3})'.format( 102 self.api.append('{0}{1}?{2:d}({3})'.format(
102 self.moduleName, _class.name, id, 103 self.moduleName, _class.name, id,
103 ', '.join(_class.methods['__init__'].parameters[1:]))) 104 ', '.join(_class.methods['__init__'].parameters[1:])))
104 105
105 classNameStr = "{0}{1}.".format(self.moduleName, className) 106 classNameStr = "{0}{1}.".format(self.moduleName, className)
106 for method in methods: 107 for method in methods:
107 if not self.__isPrivate(_class.methods[method]): 108 if not self.__isPrivate(_class.methods[method]):
108 if _class.methods[method].isPublic(): 109 if _class.methods[method].isPublic():
109 id = Editor.MethodID 110 id = Editor.MethodID
110 elif _class.methods[method].isProtected(): 111 elif _class.methods[method].isProtected():
111 id = Editor.MethodProtectedID 112 id = Editor.MethodProtectedID
112 else: 113 else:
113 id = Editor.MethodPrivateID 114 id = Editor.MethodPrivateID
114 self.api.append('{0}{1}?{2:d}({3})'.format( 115 self.api.append('{0}{1}?{2:d}({3})'.format(
115 classNameStr, method, id, 116 classNameStr, method, id,
116 ', '.join(_class.methods[method].parameters[1:]))) 117 ', '.join(_class.methods[method].parameters[1:])))
117 118
118 def __addClassVariablesAPI(self, className): 119 def __addClassVariablesAPI(self, className):
119 """ 120 """
120 Private method to generate class api section for class variables. 121 Private method to generate class api section for class variables.
122 @param classname Name of the class containing the class variables. (string) 123 @param classname Name of the class containing the class variables. (string)
123 """ 124 """
124 _class = self.module.classes[className] 125 _class = self.module.classes[className]
125 classNameStr = "{0}{1}.".format(self.moduleName, className) 126 classNameStr = "{0}{1}.".format(self.moduleName, className)
126 for variable in sorted(_class.globals.keys()): 127 for variable in sorted(_class.globals.keys()):
127 if not self.__isPrivate(_class.globals[variable]): 128 if not self.__isPrivate(_class.globals[variable]):
128 if _class.globals[variable].isPublic(): 129 if _class.globals[variable].isPublic():
129 id = Editor.AttributeID 130 id = Editor.AttributeID
130 elif _class.globals[variable].isProtected(): 131 elif _class.globals[variable].isProtected():
131 id = Editor.AttributeProtectedID 132 id = Editor.AttributeProtectedID
132 else: 133 else:
137 """ 138 """
138 Private method to generate the api section for functions. 139 Private method to generate the api section for functions.
139 """ 140 """
140 funcNames = sorted(list(self.module.functions.keys())) 141 funcNames = sorted(list(self.module.functions.keys()))
141 for funcName in funcNames: 142 for funcName in funcNames:
142 if not self.__isPrivate(self.module.functions[funcName]): 143 if not self.__isPrivate(self.module.functions[funcName]):
143 if self.module.functions[funcName].isPublic(): 144 if self.module.functions[funcName].isPublic():
144 id = Editor.MethodID 145 id = Editor.MethodID
145 elif self.module.functions[funcName].isProtected(): 146 elif self.module.functions[funcName].isProtected():
146 id = Editor.MethodProtectedID 147 id = Editor.MethodProtectedID
147 else: 148 else:
148 id = Editor.MethodPrivateID 149 id = Editor.MethodPrivateID
149 self.api.append('{0}{1}?{2:d}({3})'.format( 150 self.api.append('{0}{1}?{2:d}({3})'.format(
150 self.moduleName, self.module.functions[funcName].name, id, 151 self.moduleName, self.module.functions[funcName].name, id,
151 ', '.join(self.module.functions[funcName].parameters))) 152 ', '.join(self.module.functions[funcName].parameters)))

eric ide

mercurial