/usr/share/php/PHP/Depend/Builder/Default.php is in pdepend 1.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 | <?php
/**
* This file is part of PHP_Depend.
*
* PHP Version 5
*
* Copyright (c) 2008-2012, Manuel Pichler <mapi@pdepend.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Manuel Pichler nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category QualityAssurance
* @package PHP_Depend
* @subpackage Builder
* @author Manuel Pichler <mapi@pdepend.org>
* @copyright 2008-2012 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link http://pdepend.org/
*/
/**
* Default code tree builder implementation.
*
* @category QualityAssurance
* @package PHP_Depend
* @subpackage Builder
* @author Manuel Pichler <mapi@pdepend.org>
* @copyright 2008-2012 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.1.4
* @link http://pdepend.org/
*/
class PHP_Depend_Builder_Default implements PHP_Depend_BuilderI
{
/**
* The internal used cache instance.
*
* @var PHP_Depend_Util_Cache_Driver
* @since 0.10.0
*/
protected $cache = null;
/**
* The ast builder context.
*
* @var PHP_Depend_Builder_Context
* @since 0.10.0
*/
protected $context = null;
/**
* This property holds all packages found during the parsing phase.
*
* @param PHP_Depend_Code_Package[]
* @since 0.9.12
*/
private $preparedPackages = null;
/**
* Default package which contains all functions and classes with an unknown
* scope.
*
* @var PHP_Depend_Code_Package
*/
protected $defaultPackage = null;
/**
* Default source file that acts as a dummy.
*
* @var PHP_Depend_Code_File
*/
protected $defaultFile = null;
/**
* All generated {@link PHP_Depend_Code_Trait} objects
*
* @var array
*/
private $traits = array();
/**
* All generated {@link PHP_Depend_Code_Class} objects
*
* @var PHP_Depend_Code_Class[]
*/
private $classes = array();
/**
* All generated {@link PHP_Depend_Code_Interface} instances.
*
* @var PHP_Depend_Code_Interface[]
*/
private $interfaces = array();
/**
* All generated {@link PHP_Depend_Code_Package} objects
*
* @var PHP_Depend_Code_Package[]
*/
private $packages = array();
/**
* Internal status flag used to check that a build request is internal.
*
* @var boolean
*/
private $internal = false;
/**
* Internal used flag that marks the parsing process as frozen.
*
* @var boolean
*/
private $frozen = false;
/**
* Cache of all traits created during the regular parsing process.
*
* @var array
*/
private $frozenTraits = array();
/**
* Cache of all classes created during the regular parsing process.
*
* @var PHP_Depend_Code_Class[]
*/
private $frozenClasses = array();
/**
* Cache of all interfaces created during the regular parsing process.
*
* @var PHP_Depend_Code_Interface[]
*/
private $frozenInterfaces = array();
/**
* Constructs a new builder instance.
*/
public function __construct()
{
$this->defaultPackage = new PHP_Depend_Code_Package(self::DEFAULT_PACKAGE);
$this->defaultFile = new PHP_Depend_Code_File(null);
$this->packages[self::DEFAULT_PACKAGE] = $this->defaultPackage;
$this->context = new PHP_Depend_Builder_Context_GlobalStatic($this);
}
/**
* Setter method for the currently used token cache.
*
* @param PHP_Depend_Util_Cache_Driver $cache Used token cache instance.
*
* @return PHP_Depend_Builder_Default
* @since 0.10.0
*/
public function setCache(PHP_Depend_Util_Cache_Driver $cache)
{
$this->cache = $cache;
return $this;
}
/**
* Builds a new code type reference instance.
*
* @param string $qualifiedName The qualified name of the referenced type.
*
* @return PHP_Depend_Code_ASTClassOrInterfaceReference
* @since 0.9.5
*/
public function buildAstClassOrInterfaceReference($qualifiedName)
{
$this->checkBuilderState();
// Debug method creation
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_ASTClassOrInterfaceReference(' .
$qualifiedName .
')'
);
return new PHP_Depend_Code_ASTClassOrInterfaceReference(
$this->context,
$qualifiedName
);
}
/**
* This method will try to find an already existing instance for the given
* qualified name. It will create a new {@link PHP_Depend_Code_Class}
* instance when no matching type exists.
*
* @param string $qualifiedName The full qualified type identifier.
*
* @return PHP_Depend_Code_AbstractClassOrInterface
* @since 0.9.5
*/
public function getClassOrInterface($qualifiedName)
{
$classOrInterface = $this->findClass($qualifiedName);
if ($classOrInterface !== null) {
return $classOrInterface;
}
$classOrInterface = $this->findInterface($qualifiedName);
if ($classOrInterface !== null) {
return $classOrInterface;
}
return $this->buildClassInternal($qualifiedName);
}
/**
* Builds a new php trait instance.
*
* @param string $qualifiedName The full qualified trait name.
*
* @return PHP_Depend_Code_Trait
* @since 1.0.0
*/
public function buildTrait($qualifiedName)
{
$this->checkBuilderState();
$trait = new PHP_Depend_Code_Trait($this->extractTypeName($qualifiedName));
$trait->setCache($this->cache)
->setContext($this->context)
->setSourceFile($this->defaultFile);
return $trait;
}
/**
* This method will try to find an already existing instance for the given
* qualified name. It will create a new {@link PHP_Depend_Code_Trait}
* instance when no matching type exists.
*
* @param string $qualifiedName The full qualified type identifier.
*
* @return PHP_Depend_Code_Trait
* @since 1.0.0
*/
public function getTrait($qualifiedName)
{
$trait = $this->findTrait($qualifiedName);
if ($trait === null) {
$trait = $this->buildTraitInternal($qualifiedName);
}
return $trait;
}
/**
* Builds a new trait reference node.
*
* @param string $qualifiedName The full qualified trait name.
*
* @return PHP_Depend_Code_ASTTraitReference
* @since 1.0.0
*/
public function buildAstTraitReference($qualifiedName)
{
$this->checkBuilderState();
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_ASTTraitReference(' . $qualifiedName . ')'
);
return new PHP_Depend_Code_ASTTraitReference($this->context, $qualifiedName);
}
/**
* Builds a new class instance or reuses a previous created class.
*
* Where possible you should give a qualified class name, that is prefixed
* with the package identifier.
*
* <code>
* $builder->buildClass('php::depend::Parser');
* </code>
*
* To determine the correct class, this method implements the following
* algorithm.
*
* <ol>
* <li>Check for an exactly matching instance and reuse it.</li>
* <li>Check for a class instance that belongs to the default package. If
* such an instance exists, reuse it and replace the default package with
* the newly given package information.</li>
* <li>Check that the requested class is in the default package, if this
* is true, reuse the first class instance and ignore the default package.
* </li>
* <li>Create a new instance for the specified package.</li>
* </ol>
*
* @param string $name The class name.
*
* @return PHP_Depend_Code_Class The created class object.
*/
public function buildClass($name)
{
$this->checkBuilderState();
$class = new PHP_Depend_Code_Class($this->extractTypeName($name));
$class->setCache($this->cache)
->setContext($this->context)
->setSourceFile($this->defaultFile);
return $class;
}
/**
* This method will try to find an already existing instance for the given
* qualified name. It will create a new {@link PHP_Depend_Code_Class}
* instance when no matching type exists.
*
* @param string $qualifiedName The full qualified type identifier.
*
* @return PHP_Depend_Code_Class
* @since 0.9.5
*/
public function getClass($qualifiedName)
{
$class = $this->findClass($qualifiedName);
if ($class === null) {
$class = $this->buildClassInternal($qualifiedName);
}
return $class;
}
/**
* Builds a new code type reference instance.
*
* @param string $qualifiedName The qualified name of the referenced type.
*
* @return PHP_Depend_Code_ASTClassReference
* @since 0.9.5
*/
public function buildAstClassReference($qualifiedName)
{
$this->checkBuilderState();
// Debug method creation
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_ASTClassReference(' . $qualifiedName . ')'
);
return new PHP_Depend_Code_ASTClassReference($this->context, $qualifiedName);
}
/**
* Builds a new new interface instance.
*
* If there is an existing class instance for the given name, this method
* checks if this class is part of the default namespace. If this is the
* case this method will update all references to the new interface and it
* removes the class instance. Otherwise it creates new interface instance.
*
* Where possible you should give a qualified interface name, that is
* prefixed with the package identifier.
*
* <code>
* $builder->buildInterface('php::depend::Parser');
* </code>
*
* To determine the correct interface, this method implements the following
* algorithm.
*
* <ol>
* <li>Check for an exactly matching instance and reuse it.</li>
* <li>Check for a interface instance that belongs to the default package.
* If such an instance exists, reuse it and replace the default package
* with the newly given package information.</li>
* <li>Check that the requested interface is in the default package, if
* this is true, reuse the first interface instance and ignore the default
* package.
* </li>
* <li>Create a new instance for the specified package.</li>
* </ol>
*
* @param string $name The interface name.
*
* @return PHP_Depend_Code_Interface The created interface object.
*/
public function buildInterface($name)
{
$this->checkBuilderState();
$interface = new PHP_Depend_Code_Interface($this->extractTypeName($name));
$interface->setCache($this->cache)
->setContext($this->context)
->setSourceFile($this->defaultFile);
return $interface;
}
/**
* This method will try to find an already existing instance for the given
* qualified name. It will create a new {@link PHP_Depend_Code_Interface}
* instance when no matching type exists.
*
* @param string $qualifiedName The full qualified type identifier.
*
* @return PHP_Depend_Code_Interface
* @since 0.9.5
*/
public function getInterface($qualifiedName)
{
$interface = $this->findInterface($qualifiedName);
if ($interface === null) {
$interface = $this->buildInterfaceInternal($qualifiedName);
}
return $interface;
}
/**
* Builds a new method instance.
*
* @param string $name The method name.
*
* @return PHP_Depend_Code_Method The created class method object.
*/
public function buildMethod($name)
{
$this->checkBuilderState();
// Debug method creation
PHP_Depend_Util_Log::debug("Creating: PHP_Depend_Code_Method({$name})");
// Create a new method instance
$method = new PHP_Depend_Code_Method($name);
$method->setCache($this->cache);
return $method;
}
/**
* Builds a new package instance.
*
* @param string $name The package name.
*
* @return PHP_Depend_Code_Package The created package object.
*/
public function buildPackage($name)
{
if (!isset($this->packages[$name])) {
// Debug package creation
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_Package(' . $name . ')'
);
$this->packages[$name] = new PHP_Depend_Code_Package($name);
}
return $this->packages[$name];
}
/**
* Builds a new function instance.
*
* @param string $name The function name.
*
* @return PHP_Depend_Code_Function The function instance.
*/
public function buildFunction($name)
{
$this->checkBuilderState();
// Debug function creation
PHP_Depend_Util_Log::debug("Creating: PHP_Depend_Code_Function({$name})");
// Create new function
$function = new PHP_Depend_Code_Function($name);
$function->setCache($this->cache)
->setContext($this->context)
->setSourceFile($this->defaultFile);
return $function;
}
/**
* Builds a new self reference instance.
*
* @param PHP_Depend_Code_AbstractClassOrInterface $type The type instance
* that reference the concrete target of self.
*
* @return PHP_Depend_Code_ASTSelfReference
* @since 0.9.6
*/
public function buildAstSelfReference(
PHP_Depend_Code_AbstractClassOrInterface $type
) {
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_ASTSelfReference(' . $type->getName() . ')'
);
return new PHP_Depend_Code_ASTSelfReference($this->context, $type);
}
/**
* Builds a new parent reference instance.
*
* @param PHP_Depend_Code_ASTClassOrInterfaceReference $reference The type
* instance that reference the concrete target of parent.
*
* @return PHP_Depend_Code_ASTParentReference
* @since 0.9.6
*/
public function buildAstParentReference(
PHP_Depend_Code_ASTClassOrInterfaceReference $reference
) {
include_once 'PHP/Depend/Code/ASTParentReference.php';
PHP_Depend_Util_Log::debug(
'Creating: PHP_Depend_Code_ASTParentReference()'
);
return new PHP_Depend_Code_ASTParentReference($reference);
}
/**
* Builds a new static reference instance.
*
* @param PHP_Depend_Code_AbstractClassOrInterface $owner The owning instance
* that reference the concrete target of static.
*
* @return PHP_Depend_Code_ASTStaticReference
* @since 0.9.6
*/
public function buildAstStaticReference(
PHP_Depend_Code_AbstractClassOrInterface $owner
) {
PHP_Depend_Util_Log::debug('Creating: PHP_Depend_Code_ASTStaticReference()');
return new PHP_Depend_Code_ASTStaticReference($this->context, $owner);
}
/**
* Builds a new field declaration node.
*
* @return PHP_Depend_Code_ASTFieldDeclaration
* @since 0.9.6
*/
public function buildAstFieldDeclaration()
{
return $this->buildAstNodeInstance('ASTFieldDeclaration');
}
/**
* Builds a new variable declarator node.
*
* @param string $image The source image for the variable declarator.
*
* @return PHP_Depend_Code_ASTVariableDeclarator
* @since 0.9.6
*/
public function buildAstVariableDeclarator($image)
{
return $this->buildAstNodeInstance('ASTVariableDeclarator', $image);
}
/**
* Builds a new static variable declaration node.
*
* @param string $image The source image for the statuc declaration.
*
* @return PHP_Depend_Code_ASTStaticVariableDeclaration
* @since 0.9.6
*/
public function buildAstStaticVariableDeclaration($image)
{
return $this->buildAstNodeInstance('ASTStaticVariableDeclaration', $image);
}
/**
* Builds a new constant node.
*
* @param string $image The source image for the constant.
*
* @return PHP_Depend_Code_ASTConstant
* @since 0.9.6
*/
public function buildAstConstant($image)
{
return $this->buildAstNodeInstance('ASTConstant', $image);
}
/**
* Builds a new variable node.
*
* @param string $image The source image for the variable.
*
* @return PHP_Depend_Code_ASTVariable
* @since 0.9.6
*/
public function buildAstVariable($image)
{
return $this->buildAstNodeInstance('ASTVariable', $image);
}
/**
* Builds a new variable variable node.
*
* @param string $image The source image for the variable variable.
*
* @return PHP_Depend_Code_ASTVariableVariable
* @since 0.9.6
*/
public function buildAstVariableVariable($image)
{
return $this->buildAstNodeInstance('ASTVariableVariable', $image);
}
/**
* Builds a new compound variable node.
*
* @param string $image The source image for the compound variable.
*
* @return PHP_Depend_Code_ASTCompoundVariable
* @since 0.9.6
*/
public function buildAstCompoundVariable($image)
{
return $this->buildAstNodeInstance('ASTCompoundVariable', $image);
}
/**
* Builds a new compound expression node.
*
* @return PHP_Depend_Code_ASTCompoundExpression
* @since 0.9.6
*/
public function buildAstCompoundExpression()
{
return $this->buildAstNodeInstance('ASTCompoundExpression');
}
/**
* Builds a new closure node.
*
* @return PHP_Depend_Code_ASTClosure
* @since 0.9.12
*/
public function buildAstClosure()
{
return $this->buildAstNodeInstance('ASTClosure');
}
/**
* Builds a new formal parameters node.
*
* @return PHP_Depend_Code_ASTFormalParameters
* @since 0.9.6
*/
public function buildAstFormalParameters()
{
return $this->buildAstNodeInstance('ASTFormalParameters');
}
/**
* Builds a new formal parameter node.
*
* @return PHP_Depend_Code_ASTFormalParameter
* @since 0.9.6
*/
public function buildAstFormalParameter()
{
return $this->buildAstNodeInstance('ASTFormalParameter');
}
/**
* Builds a new expression node.
*
* @return PHP_Depend_Code_ASTExpression
* @since 0.9.8
*/
public function buildAstExpression()
{
return $this->buildAstNodeInstance('ASTExpression');
}
/**
* Builds a new assignment expression node.
*
* @param string $image The assignment operator.
*
* @return PHP_Depend_Code_ASTAssignmentExpression
* @since 0.9.8
*/
public function buildAstAssignmentExpression($image)
{
return $this->buildAstNodeInstance('ASTAssignmentExpression', $image);
}
/**
* Builds a new allocation expression node.
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTAllocationExpression
* @since 0.9.6
*/
public function buildAstAllocationExpression($image)
{
return $this->buildAstNodeInstance('ASTAllocationExpression', $image);
}
/**
* Builds a new eval-expression node.
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTEvalExpression
* @since 0.9.12
*/
public function buildAstEvalExpression($image)
{
return $this->buildAstNodeInstance('ASTEvalExpression', $image);
}
/**
* Builds a new exit-expression instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTExitExpression
* @since 0.9.12
*/
public function buildAstExitExpression($image)
{
return $this->buildAstNodeInstance('ASTExitExpression', $image);
}
/**
* Builds a new clone-expression node.
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTCloneExpression
* @since 0.9.12
*/
public function buildAstCloneExpression($image)
{
return $this->buildAstNodeInstance('ASTCloneExpression', $image);
}
/**
* Builds a new list-expression node.
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTListExpression
* @author Joey Mazzarelli
* @since 0.9.12
*/
public function buildAstListExpression($image)
{
return $this->buildAstNodeInstance('ASTListExpression', $image);
}
/**
* Builds a new include- or include_once-expression.
*
* @return PHP_Depend_Code_ASTIncludeExpression
* @since 0.9.12
*/
public function buildAstIncludeExpression()
{
return $this->buildAstNodeInstance('ASTIncludeExpression');
}
/**
* Builds a new require- or require_once-expression.
*
* @return PHP_Depend_Code_ASTRequireExpression
* @since 0.9.12
*/
public function buildAstRequireExpression()
{
return $this->buildAstNodeInstance('ASTRequireExpression');
}
/**
* Builds a new array-expression node.
*
* @return PHP_Depend_Code_ASTArrayIndexExpression
* @since 0.9.12
*/
public function buildAstArrayIndexExpression()
{
return $this->buildAstNodeInstance('ASTArrayIndexExpression');
}
/**
* Builds a new string-expression node.
*
* <code>
* // --------
* $string{$index}
* // --------
* </code>
*
* @return PHP_Depend_Code_ASTStringIndexExpression
* @since 0.9.12
*/
public function buildAstStringIndexExpression()
{
return $this->buildAstNodeInstance('ASTStringIndexExpression');
}
/**
* Builds a new php array node.
*
* @return PHP_Depend_Code_ASTArray
* @since 1.0.0
*/
public function buildAstArray()
{
return $this->buildAstNodeInstance('ASTArray');
}
/**
* Builds a new array element node.
*
* @return PHP_Depend_Code_ASTArrayElement
* @since 1.0.0
*/
public function buildAstArrayElement()
{
return $this->buildAstNodeInstance('ASTArrayElement');
}
/**
* Builds a new instanceof expression node.
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTInstanceOfExpression
* @since 0.9.6
*/
public function buildAstInstanceOfExpression($image)
{
return $this->buildAstNodeInstance('ASTInstanceOfExpression', $image);
}
/**
* Builds a new isset-expression node.
*
* <code>
* // -----------
* if (isset($foo)) {
* // -----------
* }
*
* // -----------------------
* if (isset($foo, $bar, $baz)) {
* // -----------------------
* }
* </code>
*
* @return PHP_Depend_Code_ASTIssetExpression
* @since 0.9.12
*/
public function buildAstIssetExpression()
{
return $this->buildAstNodeInstance('ASTIssetExpression');
}
/**
* Builds a new boolean conditional-expression.
*
* <code>
* --------------
* $bar = ($foo ? 42 : 23);
* --------------
* </code>
*
* @return PHP_Depend_Code_ASTConditionalExpression
* @since 0.9.8
*/
public function buildAstConditionalExpression()
{
return $this->buildAstNodeInstance('ASTConditionalExpression', '?');
}
/**
* Build a new shift left expression.
*
* @return PHP_Depend_Code_ASTShiftLeftExpression
* @since 1.0.1
*/
public function buildAstShiftLeftExpression()
{
return $this->buildAstNodeInstance('ASTShiftLeftExpression');
}
/**
* Build a new shift right expression.
*
* @return PHP_Depend_Code_ASTShiftRightExpression
* @since 1.0.1
*/
public function buildAstShiftRightExpression()
{
return $this->buildAstNodeInstance('ASTShiftRightExpression');
}
/**
* Builds a new boolean and-expression.
*
* @return PHP_Depend_Code_ASTBooleanAndExpression
* @since 0.9.8
*/
public function buildAstBooleanAndExpression()
{
return $this->buildAstNodeInstance('ASTBooleanAndExpression', '&&');
}
/**
* Builds a new boolean or-expression.
*
* @return PHP_Depend_Code_ASTBooleanOrExpression
* @since 0.9.8
*/
public function buildAstBooleanOrExpression()
{
return $this->buildAstNodeInstance('ASTBooleanOrExpression', '||');
}
/**
* Builds a new logical <b>and</b>-expression.
*
* @return PHP_Depend_Code_ASTLogicalAndExpression
* @since 0.9.8
*/
public function buildAstLogicalAndExpression()
{
return $this->buildAstNodeInstance('ASTLogicalAndExpression', 'and');
}
/**
* Builds a new logical <b>or</b>-expression.
*
* @return PHP_Depend_Code_ASTLogicalOrExpression
* @since 0.9.8
*/
public function buildAstLogicalOrExpression()
{
return $this->buildAstNodeInstance('ASTLogicalOrExpression', 'or');
}
/**
* Builds a new logical <b>xor</b>-expression.
*
* @return PHP_Depend_Code_ASTLogicalXorExpression
* @since 0.9.8
*/
public function buildAstLogicalXorExpression()
{
return $this->buildAstNodeInstance('ASTLogicalXorExpression', 'xor');
}
/**
* Builds a new trait use-statement node.
*
* @return PHP_Depend_Code_ASTTraitUseStatement
* @since 1.0.0
*/
public function buildAstTraitUseStatement()
{
return $this->buildAstNodeInstance('ASTTraitUseStatement');
}
/**
* Builds a new trait adaptation scope
*
* @return PHP_Depend_Code_ASTTraitAdaptation
* @since 1.0.0
*/
public function buildAstTraitAdaptation()
{
return $this->buildAstNodeInstance('ASTTraitAdaptation');
}
/**
* Builds a new trait adaptation alias statement.
*
* @param string $image The trait method name.
*
* @return PHP_Depend_Code_ASTTraitAdaptationAlias
* @since 1.0.0
*/
public function buildAstTraitAdaptationAlias($image)
{
return $this->buildAstNodeInstance('ASTTraitAdaptationAlias', $image);
}
/**
* Builds a new trait adaptation precedence statement.
*
* @param string $image The trait method name.
*
* @return PHP_Depend_Code_ASTTraitAdaptationPrecedence
* @since 1.0.0
*/
public function buildAstTraitAdaptationPrecedence($image)
{
return $this->buildAstNodeInstance('ASTTraitAdaptationPrecedence', $image);
}
/**
* Builds a new switch-statement-node.
*
* @return PHP_Depend_Code_ASTSwitchStatement
* @since 0.9.8
*/
public function buildAstSwitchStatement()
{
return $this->buildAstNodeInstance('ASTSwitchStatement');
}
/**
* Builds a new switch-label node.
*
* @param string $image The source image of this label.
*
* @return PHP_Depend_Code_ASTSwitchLabel
* @since 0.9.8
*/
public function buildAstSwitchLabel($image)
{
return $this->buildAstNodeInstance('ASTSwitchLabel', $image);
}
/**
* Builds a new global-statement instance.
*
* @return PHP_Depend_Code_ASTGlobalStatement
* @since 0.9.12
*/
public function buildAstGlobalStatement()
{
return $this->buildAstNodeInstance('ASTGlobalStatement');
}
/**
* Builds a new unset-statement instance.
*
* @return PHP_Depend_Code_ASTUnsetStatement
* @since 0.9.12
*/
public function buildAstUnsetStatement()
{
return $this->buildAstNodeInstance('ASTUnsetStatement');
}
/**
* Builds a new catch-statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTCatchStatement
* @since 0.9.8
*/
public function buildAstCatchStatement($image)
{
return $this->buildAstNodeInstance('ASTCatchStatement', $image);
}
/**
* Builds a new if statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTIfStatement
* @since 0.9.8
*/
public function buildAstIfStatement($image)
{
return $this->buildAstNodeInstance('ASTIfStatement', $image);
}
/**
* Builds a new elseif statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTElseIfStatement
* @since 0.9.8
*/
public function buildAstElseIfStatement($image)
{
return $this->buildAstNodeInstance('ASTElseIfStatement', $image);
}
/**
* Builds a new for statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTForStatement
* @since 0.9.8
*/
public function buildAstForStatement($image)
{
return $this->buildAstNodeInstance('ASTForStatement', $image);
}
/**
* Builds a new for-init node.
*
* <code>
* ------------------------
* for ($x = 0, $y = 23, $z = 42; $x < $y; ++$x) {}
* ------------------------
* </code>
*
* @return PHP_Depend_Code_ASTForInit
* @since 0.9.8
*/
public function buildAstForInit()
{
return $this->buildAstNodeInstance('ASTForInit');
}
/**
* Builds a new for-update node.
*
* <code>
* -------------------------------
* for ($x = 0, $y = 23, $z = 42; $x < $y; ++$x, $y = $x + 1, $z = $x + 2) {}
* -------------------------------
* </code>
*
* @return PHP_Depend_Code_ASTForUpdate
* @since 0.9.12
*/
public function buildAstForUpdate()
{
return $this->buildAstNodeInstance('ASTForUpdate');
}
/**
* Builds a new foreach-statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTForeachStatement
* @since 0.9.8
*/
public function buildAstForeachStatement($image)
{
return $this->buildAstNodeInstance('ASTForeachStatement', $image);
}
/**
* Builds a new while-statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTWhileStatement
* @since 0.9.8
*/
public function buildAstWhileStatement($image)
{
return $this->buildAstNodeInstance('ASTWhileStatement', $image);
}
/**
* Builds a new do/while-statement node.
*
* @param string $image The source image of this statement.
*
* @return PHP_Depend_Code_ASTDoWhileStatement
* @since 0.9.12
*/
public function buildAstDoWhileStatement($image)
{
return $this->buildAstNodeInstance('ASTDoWhileStatement', $image);
}
/**
* Builds a new declare-statement node.
*
* <code>
* -------------------------------
* declare(encoding='ISO-8859-1');
* -------------------------------
*
* -------------------
* declare(ticks=42) {
* // ...
* }
* -
*
* ------------------
* declare(ticks=42):
* // ...
* enddeclare;
* -----------
* </code>
*
* @return PHP_Depend_Code_ASTDeclareStatement
* @since 0.10.0
*/
public function buildAstDeclareStatement()
{
return $this->buildAstNodeInstance('ASTDeclareStatement');
}
/**
* Builds a new member primary expression node.
*
* <code>
* //--------
* Foo::bar();
* //--------
*
* //---------
* Foo::$bar();
* //---------
*
* //---------
* $obj->bar();
* //---------
*
* //----------
* $obj->$bar();
* //----------
* </code>
*
* @param string $image The source image of this expression.
*
* @return PHP_Depend_Code_ASTMemberPrimaryPrefix
* @since 0.9.6
*/
public function buildAstMemberPrimaryPrefix($image)
{
return $this->buildAstNodeInstance('ASTMemberPrimaryPrefix', $image);
}
/**
* Builds a new identifier node.
*
* @param string $image The image of this identifier.
*
* @return PHP_Depend_Code_ASTIdentifier
* @since 0.9.6
*/
public function buildAstIdentifier($image)
{
return $this->buildAstNodeInstance('ASTIdentifier', $image);
}
/**
* Builds a new function postfix expression.
*
* <code>
* //-------
* foo($bar);
* //-------
*
* //--------
* $foo($bar);
* //--------
* </code>
*
* @param string $image The image of this node.
*
* @return PHP_Depend_Code_ASTFunctionPostfix
* @since 0.9.6
*/
public function buildAstFunctionPostfix($image)
{
return $this->buildAstNodeInstance('ASTFunctionPostfix', $image);
}
/**
* Builds a new method postfix expression.
*
* <code>
* // ---------
* Foo::bar($baz);
* // ---------
*
* // ----------
* Foo::$bar($baz);
* // ----------
* </code>
*
* @param string $image The image of this node.
*
* @return PHP_Depend_Code_ASTMethodPostfix
* @since 0.9.6
*/
public function buildAstMethodPostfix($image)
{
return $this->buildAstNodeInstance('ASTMethodPostfix', $image);
}
/**
* Builds a new constant postfix expression.
*
* <code>
* // ---
* Foo::BAR;
* // ---
* </code>
*
* @param string $image The image of this node.
*
* @return PHP_Depend_Code_ASTConstantPostfix
* @since 0.9.6
*/
public function buildAstConstantPostfix($image)
{
return $this->buildAstNodeInstance('ASTConstantPostfix', $image);
}
/**
* Builds a new property postfix expression.
*
* <code>
* // ----
* Foo::$bar;
* // ----
*
* // ---
* $object->bar;
* // ---
* </code>
*
* @param string $image The image of this node.
*
* @return PHP_Depend_Code_ASTPropertyPostfix
* @since 0.9.6
*/
public function buildAstPropertyPostfix($image)
{
return $this->buildAstNodeInstance('ASTPropertyPostfix', $image);
}
/**
* Builds a new arguments list.
*
* <code>
* // ------------
* Foo::bar($x, $y, $z);
* // ------------
*
* // ------------
* $foo->bar($x, $y, $z);
* // ------------
* </code>
*
* @return PHP_Depend_Code_ASTArguments
* @since 0.9.6
*/
public function buildAstArguments()
{
return $this->buildAstNodeInstance('ASTArguments');
}
/**
* Builds a new array type node.
*
* @return PHP_Depend_Code_ASTTypeArray
* @since 0.9.6
*/
public function buildAstTypeArray()
{
return $this->buildAstNodeInstance('ASTTypeArray');
}
/**
* Builds a new node for the callable type.
*
* @return PHP_Depend_Code_ASTTypeCallable
* @since 1.0.0
*/
public function buildAstTypeCallable()
{
return $this->buildAstNodeInstance('ASTTypeCallable');
}
/**
* Builds a new primitive type node.
*
* @param string $image The source image for the primitive type.
*
* @return PHP_Depend_Code_ASTPrimitiveType
* @since 0.9.6
*/
public function buildAstPrimitiveType($image)
{
return $this->buildAstNodeInstance('ASTPrimitiveType', $image);
}
/**
* Builds a new literal node.
*
* @param string $image The source image for the literal node.
*
* @return PHP_Depend_Code_ASTLiteral
* @since 0.9.6
*/
public function buildAstLiteral($image)
{
return $this->buildAstNodeInstance('ASTLiteral', $image);
}
/**
* Builds a new php string node.
*
* <code>
* $string = "Manuel $Pichler <{$email}>";
*
* // PHP_Depend_Code_ASTString
* // |-- ASTLiteral - "Manuel ")
* // |-- ASTVariable - $Pichler
* // |-- ASTLiteral - " <"
* // |-- ASTCompoundExpression - {...}
* // | |-- ASTVariable - $email
* // |-- ASTLiteral - ">"
* </code>
*
* @return PHP_Depend_Code_ASTString
* @since 0.9.10
*/
public function buildAstString()
{
return $this->buildAstNodeInstance('ASTString');
}
/**
* Builds a new heredoc node.
*
* @return PHP_Depend_Code_ASTHeredoc
* @since 0.9.12
*/
public function buildAstHeredoc()
{
return $this->buildAstNodeInstance('ASTHeredoc');
}
/**
* Builds a new constant definition node.
*
* <code>
* class Foo
* {
* // ------------------------
* const FOO = 42, BAR = 23;
* // ------------------------
* }
* </code>
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTConstantDefinition
* @since 0.9.6
*/
public function buildAstConstantDefinition($image)
{
return $this->buildAstNodeInstance('ASTConstantDefinition', $image);
}
/**
* Builds a new constant declarator node.
*
* <code>
* class Foo
* {
* // --------
* const BAR = 42;
* // --------
* }
* </code>
*
* Or in a comma separated constant defintion:
*
* <code>
* class Foo
* {
* // --------
* const BAR = 42,
* // --------
*
* // --------------
* const BAZ = 'Foobar',
* // --------------
*
* // ----------
* const FOO = 3.14;
* // ----------
* }
* </code>
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTConstantDeclarator
* @since 0.9.6
*/
public function buildAstConstantDeclarator($image)
{
return $this->buildAstNodeInstance('ASTConstantDeclarator', $image);
}
/**
* Builds a new comment node instance.
*
* @param string $cdata The comment text.
*
* @return PHP_Depend_Code_ASTComment
* @since 0.9.8
*/
public function buildAstComment($cdata)
{
return $this->buildAstNodeInstance('ASTComment', $cdata);
}
/**
* Builds a new unary expression node instance.
*
* @param string $image The unary expression image/character.
*
* @return PHP_Depend_Code_ASTUnaryExpression
* @since 0.9.11
*/
public function buildAstUnaryExpression($image)
{
return $this->buildAstNodeInstance('ASTUnaryExpression', $image);
}
/**
* Builds a new cast-expression node instance.
*
* @param string $image The cast-expression image/character.
*
* @return PHP_Depend_Code_ASTCastExpression
* @since 0.10.0
*/
public function buildAstCastExpression($image)
{
return $this->buildAstNodeInstance('ASTCastExpression', $image);
}
/**
* Builds a new postfix-expression node instance.
*
* @param string $image The postfix-expression image/character.
*
* @return PHP_Depend_Code_ASTPostfixExpression
* @since 0.10.0
*/
public function buildAstPostfixExpression($image)
{
return $this->buildAstNodeInstance('ASTPostfixExpression', $image);
}
/**
* Builds a new pre-increment-expression node instance.
*
* @return PHP_Depend_Code_ASTPreIncrementExpression
* @since 0.10.0
*/
public function buildAstPreIncrementExpression()
{
return $this->buildAstNodeInstance('ASTPreIncrementExpression');
}
/**
* Builds a new pre-decrement-expression node instance.
*
* @return PHP_Depend_Code_ASTPreDecrementExpression
* @since 0.10.0
*/
public function buildAstPreDecrementExpression()
{
return $this->buildAstNodeInstance('ASTPreDecrementExpression');
}
/**
* Builds a new function/method scope instance.
*
* @return PHP_Depend_Code_ASTScope
* @since 0.9.12
*/
public function buildAstScope()
{
return $this->buildAstNodeInstance('ASTScope');
}
/**
* Builds a new statement instance.
*
* @return PHP_Depend_Code_ASTStatement
* @since 0.9.12
*/
public function buildAstStatement()
{
return $this->buildAstNodeInstance('ASTStatement');
}
/**
* Builds a new return statement node instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTReturnStatement
* @since 0.9.12
*/
public function buildAstReturnStatement($image)
{
return $this->buildAstNodeInstance('ASTReturnStatement', $image);
}
/**
* Builds a new break-statement node instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTBreakStatement
* @since 0.9.12
*/
public function buildAstBreakStatement($image)
{
return $this->buildAstNodeInstance('ASTBreakStatement', $image);
}
/**
* Builds a new continue-statement node instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTContinueStatement
* @since 0.9.12
*/
public function buildAstContinueStatement($image)
{
return $this->buildAstNodeInstance('ASTContinueStatement', $image);
}
/**
* Builds a new scope-statement instance.
*
* @return PHP_Depend_Code_ASTScopeStatement
* @since 0.9.12
*/
public function buildAstScopeStatement()
{
return $this->buildAstNodeInstance('ASTScopeStatement');
}
/**
* Builds a new try-statement instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTTryStatement
* @since 0.9.12
*/
public function buildAstTryStatement($image)
{
return $this->buildAstNodeInstance('ASTTryStatement', $image);
}
/**
* Builds a new throw-statement instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTThrowStatement
* @since 0.9.12
*/
public function buildAstThrowStatement($image)
{
return $this->buildAstNodeInstance('ASTThrowStatement', $image);
}
/**
* Builds a new goto-statement instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTGotoStatement
* @since 0.9.12
*/
public function buildAstGotoStatement($image)
{
return $this->buildAstNodeInstance('ASTGotoStatement', $image);
}
/**
* Builds a new label-statement instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTLabelStatement
* @since 0.9.12
*/
public function buildAstLabelStatement($image)
{
return $this->buildAstNodeInstance('ASTLabelStatement', $image);
}
/**
* Builds a new exit-statement instance.
*
* @param string $image The source code image for this node.
*
* @return PHP_Depend_Code_ASTEchoStatement
* @since 0.9.12
*/
public function buildAstEchoStatement($image)
{
return $this->buildAstNodeInstance('ASTEchoStatement', $image);
}
/**
* Returns an iterator with all generated {@link PHP_Depend_Code_Package}
* objects.
*
* @return PHP_Depend_Code_NodeIterator
*/
public function getIterator()
{
return $this->getPackages();
}
/**
* Returns an iterator with all generated {@link PHP_Depend_Code_Package}
* objects.
*
* @return PHP_Depend_Code_NodeIterator
*/
public function getPackages()
{
if ($this->preparedPackages === null) {
$this->preparedPackages = $this->getPreparedPackages();
}
return new PHP_Depend_Code_NodeIterator($this->preparedPackages);
}
/**
* Returns an iterator with all generated {@link PHP_Depend_Code_Package}
* objects.
*
* @return PHP_Depend_Code_NodeIterator
* @since 0.9.12
*/
private function getPreparedPackages()
{
// Create a package array copy
$packages = $this->packages;
// Remove default package if empty
if ($this->defaultPackage->getTypes()->count() === 0
&& $this->defaultPackage->getFunctions()->count() === 0
) {
unset($packages[self::DEFAULT_PACKAGE]);
}
return $packages;
}
/**
* Builds a new trait instance or reuses a previous created trait.
*
* Where possible you should give a qualified trait name, that is prefixed
* with the package identifier.
*
* <code>
* $builder->buildTrait('php::depend::Parser');
* </code>
*
* To determine the correct trait, this method implements the following
* algorithm.
*
* <ol>
* <li>Check for an exactly matching instance and reuse it.</li>
* <li>Check for a class instance that belongs to the default package. If
* such an instance exists, reuse it and replace the default package with
* the newly given package information.</li>
* <li>Check that the requested trait is in the default package, if this
* is true, reuse the first trait instance and ignore the default package.
* </li>
* <li>Create a new instance for the specified package.</li>
* </ol>
*
* @param string $qualifiedName The qualified trait name.
*
* @return PHP_Depend_Code_Trait
* @since 0.9.5
*/
protected function buildTraitInternal($qualifiedName)
{
$this->internal = true;
$trait = $this->buildTrait($qualifiedName);
$trait->setPackage(
$this->buildPackage($this->extractPackageName($qualifiedName))
);
$this->restoreTrait($trait);
return $trait;
}
/**
* This method tries to find a trait instance matching for the given
* qualified name in all scopes already processed. It will return the best
* matching instance or <b>null</b> if no match exists.
*
* @param string $qualifiedName The qualified trait name.
*
* @return PHP_Depend_Code_Trait
* @since 0.9.5
*/
protected function findTrait($qualifiedName)
{
$this->freeze();
$trait = $this->findType(
$this->frozenTraits,
$qualifiedName
);
if ($trait === null) {
$trait = $this->findType($this->traits, $qualifiedName);
}
return $trait;
}
/**
* Builds a new new interface instance.
*
* If there is an existing interface instance for the given name, this method
* checks if this interface is part of the default namespace. If this is the
* case this method will update all references to the new interface and it
* removes the class instance. Otherwise it creates new interface instance.
*
* Where possible you should give a qualified interface name, that is
* prefixed with the package identifier.
*
* <code>
* $builder->buildInterface('php::depend::Parser');
* </code>
*
* To determine the correct interface, this method implements the following
* algorithm.
*
* <ol>
* <li>Check for an exactly matching instance and reuse it.</li>
* <li>Check for a interface instance that belongs to the default package.
* If such an instance exists, reuse it and replace the default package
* with the newly given package information.</li>
* <li>Check that the requested interface is in the default package, if
* this is true, reuse the first interface instance and ignore the default
* package.
* </li>
* <li>Create a new instance for the specified package.</li>
* </ol>
*
* @param string $qualifiedName The full qualified interface name.
*
* @return PHP_Depend_Code_Interface
* @since 0.9.5
*/
protected function buildInterfaceInternal($qualifiedName)
{
$this->internal = true;
$interface = $this->buildInterface($qualifiedName);
$interface->setPackage(
$this->buildPackage($this->extractPackageName($qualifiedName))
);
$this->restoreInterface($interface);
return $interface;
}
/**
* This method tries to find an interface instance matching for the given
* qualified name in all scopes already processed. It will return the best
* matching instance or <b>null</b> if no match exists.
*
* @param string $qualifiedName The qualified interface name.
*
* @return PHP_Depend_Code_Interface
* @since 0.9.5
*/
protected function findInterface($qualifiedName)
{
$this->freeze();
$interface = $this->findType(
$this->frozenInterfaces,
$qualifiedName
);
if ($interface === null) {
$interface = $this->findType(
$this->interfaces,
$qualifiedName
);
}
return $interface;
}
/**
* Builds a new class instance or reuses a previous created class.
*
* Where possible you should give a qualified class name, that is prefixed
* with the package identifier.
*
* <code>
* $builder->buildClass('php::depend::Parser');
* </code>
*
* To determine the correct class, this method implements the following
* algorithm.
*
* <ol>
* <li>Check for an exactly matching instance and reuse it.</li>
* <li>Check for a class instance that belongs to the default package. If
* such an instance exists, reuse it and replace the default package with
* the newly given package information.</li>
* <li>Check that the requested class is in the default package, if this
* is true, reuse the first class instance and ignore the default package.
* </li>
* <li>Create a new instance for the specified package.</li>
* </ol>
*
* @param string $qualifiedName The qualified class name.
*
* @return PHP_Depend_Code_Class
* @since 0.9.5
*/
protected function buildClassInternal($qualifiedName)
{
$this->internal = true;
$class = $this->buildClass($qualifiedName);
$class->setPackage(
$this->buildPackage($this->extractPackageName($qualifiedName))
);
$this->restoreClass($class);
return $class;
}
/**
* This method tries to find a class instance matching for the given
* qualified name in all scopes already processed. It will return the best
* matching instance or <b>null</b> if no match exists.
*
* @param string $qualifiedName The qualified class name.
*
* @return PHP_Depend_Code_Class
* @since 0.9.5
*/
protected function findClass($qualifiedName)
{
$this->freeze();
$class = $this->findType(
$this->frozenClasses,
$qualifiedName
);
if ($class === null) {
$class = $this->findType($this->classes, $qualifiedName);
}
return $class;
}
/**
* This method tries to find an interface or class instance matching for the
* given qualified name in all scopes already processed. It will return the
* best matching instance or <b>null</b> if no match exists.
*
* @param array $instances Map of already created instances.
* @param string $qualifiedName The qualified interface or class name.
*
* @return PHP_Depend_Code_AbstractType
* @since 0.9.5
*/
protected function findType(array $instances, $qualifiedName)
{
$classOrInterfaceName = $this->extractTypeName($qualifiedName);
$packageName = $this->extractPackageName($qualifiedName);
$caseInsensitiveName = strtolower($classOrInterfaceName);
if (!isset($instances[$caseInsensitiveName])) {
return null;
}
// Check for exact match and return first matching instance
if (isset($instances[$caseInsensitiveName][$packageName])) {
return reset($instances[$caseInsensitiveName][$packageName]);
}
if (!$this->isDefault($packageName)) {
return null;
}
$classesOrInterfaces = reset($instances[$caseInsensitiveName]);
return reset($classesOrInterfaces);
}
/**
* This method will freeze the actual builder state and create a second
* runtime scope.
*
* @return void
* @since 0.9.5
*/
protected function freeze()
{
if ($this->frozen === true) {
return;
}
$this->frozen = true;
$this->frozenTraits = $this->copyTypesWithPackage($this->traits);
$this->frozenClasses = $this->copyTypesWithPackage($this->classes);
$this->frozenInterfaces = $this->copyTypesWithPackage($this->interfaces);
$this->traits = array();
$this->classes = array();
$this->interfaces = array();
}
/**
* Creates a copy of the given input array, but skips all types that do not
* contain a parent package.
*
* @param array $originalTypes The original types created during the parsing
* process.
*
* @return array
*/
private function copyTypesWithPackage(array $originalTypes)
{
$copiedTypes = array();
foreach ($originalTypes as $typeName => $packages) {
foreach ($packages as $package => $types) {
foreach ($types as $index => $type) {
if (is_object($type->getPackage())) {
$copiedTypes[$typeName][$package][$index] = $type;
}
}
}
}
return $copiedTypes;
}
/**
* Restores a function within the internal type scope.
*
* @param PHP_Depend_Code_Function $function A function instance.
*
* @return void
* @since 0.10.0
*/
public function restoreFunction(PHP_Depend_Code_Function $function)
{
$this->buildPackage($function->getPackageName())
->addFunction($function);
}
/**
* Restores a trait within the internal type scope.
*
* @param PHP_Depend_Code_Trait $trait A trait instance.
*
* @return void
* @since 0.10.0
*/
public function restoreTrait(PHP_Depend_Code_Trait $trait)
{
$this->storeTrait(
$trait->getName(),
$trait->getPackageName(),
$trait
);
}
/**
* Restores a class within the internal type scope.
*
* @param PHP_Depend_Code_Class $class A class instance.
*
* @return void
* @since 0.10.0
*/
public function restoreClass(PHP_Depend_Code_Class $class)
{
$this->storeClass(
$class->getName(),
$class->getPackageName(),
$class
);
}
/**
* Restores an interface within the internal type scope.
*
* @param PHP_Depend_Code_Interface $interface An interface instance.
*
* @return void
* @since 0.10.0
*/
public function restoreInterface(PHP_Depend_Code_Interface $interface)
{
$this->storeInterface(
$interface->getName(),
$interface->getPackageName(),
$interface
);
}
/**
* This method will persist a trait instance for later reuse.
*
* @param string $traitName The local trait name.
* @param string $packageName The package name
* @param PHP_Depend_Code_Trait $trait The context trait.
*
* @return void
* @@since 1.0.0
*/
protected function storeTrait(
$traitName, $packageName, PHP_Depend_Code_Trait $trait
) {
$traitName = strtolower($traitName);
if (!isset($this->traits[$traitName][$packageName])) {
$this->traits[$traitName][$packageName] = array();
}
$this->traits[$traitName][$packageName][$trait->getUuid()] = $trait;
$package = $this->buildPackage($packageName);
$package->addType($trait);
}
/**
* This method will persist a class instance for later reuse.
*
* @param string $className The local class name.
* @param string $packageName The package name
* @param PHP_Depend_Code_Class $class The context class.
*
* @return void
* @@since 0.9.5
*/
protected function storeClass(
$className, $packageName, PHP_Depend_Code_Class $class
) {
$className = strtolower($className);
if (!isset($this->classes[$className][$packageName])) {
$this->classes[$className][$packageName] = array();
}
$this->classes[$className][$packageName][$class->getUuid()] = $class;
$package = $this->buildPackage($packageName);
$package->addType($class);
}
/**
* This method will persist an interface instance for later reuse.
*
* @param string $interfaceName The local interface name.
* @param string $packageName The package name
* @param PHP_Depend_Code_Interface $interface The context interface.
*
* @return void
* @@since 0.9.5
*/
protected function storeInterface(
$interfaceName, $packageName, PHP_Depend_Code_Interface $interface
) {
$interfaceName = strtolower($interfaceName);
if (!isset($this->interfaces[$interfaceName][$packageName])) {
$this->interfaces[$interfaceName][$packageName] = array();
}
$this->interfaces[$interfaceName][$packageName][$interface->getUuid()]
= $interface;
$package = $this->buildPackage($packageName);
$package->addType($interface);
}
/**
* Checks that the parser is not frozen or a request is flagged as internal.
*
* @param boolean $internal The new internal flag value.
*
* @return void
* @since 0.9.5
*/
protected function checkBuilderState($internal = false)
{
if ($this->frozen === true && $this->internal === false) {
throw new BadMethodCallException(
'Cannot create new nodes, when internal state is frozen.'
);
}
$this->internal = $internal;
}
/**
* Returns <b>true</b> if the given package is the default package.
*
* @param string $packageName The package name.
*
* @return boolean
*/
protected function isDefault($packageName)
{
return ($packageName === self::DEFAULT_PACKAGE);
}
/**
* Extracts the type name of a qualified PHP 5.3 type identifier.
*
* <code>
* $typeName = $this->extractTypeName('foo\bar\foobar');
* var_dump($typeName);
* // Results in:
* // string(6) "foobar"
* </code>
*
* @param string $qualifiedName The qualified PHP 5.3 type identifier.
*
* @return string
*/
protected function extractTypeName($qualifiedName)
{
if (($pos = strrpos($qualifiedName, '\\')) !== false) {
return substr($qualifiedName, $pos + 1);
}
return $qualifiedName;
}
/**
* Extracts the package name of a qualified PHP 5.3 class identifier.
*
* If the class name doesn't contain a package identifier this method will
* return the default identifier.
*
* <code>
* $packageName = $this->extractPackageName('foo\bar\foobar');
* var_dump($packageName);
* // Results in:
* // string(8) "foo\bar"
*
* $packageName = $this->extractPackageName('foobar');
* var_dump($packageName);
* // Results in:
* // string(6) "+global"
* </code>
*
* @param string $qualifiedName The qualified PHP 5.3 class identifier.
*
* @return string
*/
protected function extractPackageName($qualifiedName)
{
if (($pos = strrpos($qualifiedName, '\\')) !== false) {
return ltrim(substr($qualifiedName, 0, $pos), '\\');
} else if (PHP_Depend_Util_Type::isInternalType($qualifiedName)) {
return PHP_Depend_Util_Type::getTypePackage($qualifiedName);
}
return self::DEFAULT_PACKAGE;
}
/**
* Creates a {@link PHP_Depend_Code_ASTNode} instance.
*
* @param string $className Local name of the ast node class.
* @param string $image Optional image for the created ast node.
*
* @return PHP_Depend_Code_ASTNode
* @since 0.9.12
*/
private function buildAstNodeInstance($className, $image = null)
{
$fileName = "PHP/Depend/Code/{$className}.php";
$className = "PHP_Depend_Code_{$className}";
include_once $fileName;
PHP_Depend_Util_Log::debug("Creating: {$className}({$image})");
return new $className($image);
}
}
|