Returns a non-empty error message if the next header is out of order. This function also updates the internal state to be ready to check the next include. Args: header_type: One of the _XXX_HEADER constants defined above. Returns: The empty stri
(self, header_type)
| 1367 | ) |
| 1368 | |
| 1369 | def CheckNextIncludeOrder(self, header_type): |
| 1370 | """Returns a non-empty error message if the next header is out of order. |
| 1371 | |
| 1372 | This function also updates the internal state to be ready to check |
| 1373 | the next include. |
| 1374 | |
| 1375 | Args: |
| 1376 | header_type: One of the _XXX_HEADER constants defined above. |
| 1377 | |
| 1378 | Returns: |
| 1379 | The empty string if the header is in the right order, or an |
| 1380 | error message describing what's wrong. |
| 1381 | |
| 1382 | """ |
| 1383 | error_message = ( |
| 1384 | f"Found {self._TYPE_NAMES[header_type]} after {self._SECTION_NAMES[self._section]}" |
| 1385 | ) |
| 1386 | |
| 1387 | last_section = self._section |
| 1388 | |
| 1389 | if header_type == _C_SYS_HEADER: |
| 1390 | if self._section <= self._C_SECTION: |
| 1391 | self._section = self._C_SECTION |
| 1392 | else: |
| 1393 | self._last_header = "" |
| 1394 | return error_message |
| 1395 | elif header_type == _CPP_SYS_HEADER: |
| 1396 | if self._section <= self._CPP_SECTION: |
| 1397 | self._section = self._CPP_SECTION |
| 1398 | else: |
| 1399 | self._last_header = "" |
| 1400 | return error_message |
| 1401 | elif header_type == _OTHER_SYS_HEADER: |
| 1402 | if self._section <= self._OTHER_SYS_SECTION: |
| 1403 | self._section = self._OTHER_SYS_SECTION |
| 1404 | else: |
| 1405 | self._last_header = "" |
| 1406 | return error_message |
| 1407 | elif header_type == _LIKELY_MY_HEADER: |
| 1408 | if self._section <= self._MY_H_SECTION: |
| 1409 | self._section = self._MY_H_SECTION |
| 1410 | else: |
| 1411 | self._section = self._OTHER_H_SECTION |
| 1412 | elif header_type == _POSSIBLE_MY_HEADER: |
| 1413 | if self._section <= self._MY_H_SECTION: |
| 1414 | self._section = self._MY_H_SECTION |
| 1415 | else: |
| 1416 | # This will always be the fallback because we're not sure |
| 1417 | # enough that the header is associated with this file. |
| 1418 | self._section = self._OTHER_H_SECTION |
| 1419 | else: |
| 1420 | assert header_type == _OTHER_HEADER |
| 1421 | self._section = self._OTHER_H_SECTION |
| 1422 | |
| 1423 | if last_section != self._section: |
| 1424 | self._last_header = "" |
| 1425 | |
| 1426 | return "" |