MCPcopy Create free account
hub / github.com/Tencent/CodeAnalysis / __get_issues_from_file

Method __get_issues_from_file

client/tool/androidlint.py:199–231  ·  view source on GitHub ↗
(self, file_path, source_dir)

Source from the content-addressed store, hash-verified

197 return log
198
199 def __get_issues_from_file(self, file_path, source_dir):
200 items = []
201 lint_proj_dir = os.environ.get(PROJECT_DIR_ENV)
202 if not os.path.exists(file_path) or os.stat(file_path).st_size == 0:
203 return items
204 warning_data = ET.ElementTree(file=file_path)
205 for bug in warning_data.iter(tag="issue"):
206 rule = bug.attrib.get("id")
207 msg = bug.attrib.get("message")
208 if rule == "LintError":
209 LogPrinter.warning("Lint Error msg: %s" % msg)
210 continue
211 if len(bug) == 0:
212 LogPrinter.warning("The rule %s doesn't find the location" % rule)
213 continue
214 locations = bug.getchildren() # 旧方法只获取最后一个文件行号,此方法获取所有行号
215 for location in locations:
216 if not location.tag == "location":
217 continue
218 path = location.get("file")
219 if not location.get("line"):
220 if path.endswith(".java") or path.endswith(".class"):
221 LogPrinter.warning("%s: can't find the accurate source position" % path)
222 continue
223 line = 1 # 图片文件或资源文件若无行号,则给一个1.
224 else:
225 line = int(location.get("line"))
226 if os.path.isabs(path):
227 path = os.path.relpath(path, source_dir)
228 if lint_proj_dir:
229 path = os.path.join(lint_proj_dir, path)
230 items.append({"path": path, "rule": rule, "msg": msg, "line": line})
231 return items
232
233
234tool = AndroidLint

Callers 2

analyzeMethod · 0.95
gradle_mode_analyzeMethod · 0.95

Calls 2

warningMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected