summaryrefslogtreecommitdiff
path: root/buildscripts/PhpDocumentor/phpDocumentor/Classes.inc
blob: d4f2974530d0848ec4505d85e939d92dfec7ce72 (plain)
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
<?php
//
// +------------------------------------------------------------------------+
// | phpDocumentor                                                          |
// +------------------------------------------------------------------------+
// | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
// | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
// | Web           http://www.phpdoc.org                                    |
// | Mirror        http://phpdocu.sourceforge.net/                          |
// | PEAR          http://pear.php.net/package-info.php?pacid=137           |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at http://www.php.net/license/3_0.txt.               |
// | If you did not receive a copy of the PHP license and are unable to     |
// | obtain it through the world-wide-web, please send a note to            |
// | license@php.net so we can mail you a copy immediately.                 |
// +------------------------------------------------------------------------+
//

/**
 * Intermediate class parsing structure.
 * @package phpDocumentor
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: Classes.inc,v 1.1 2005/10/17 18:36:55 jeichorn Exp $
 */
/**
 * Intermediate class parsing structure.
 *
 * The {@link phpDocumentor_IntermediateParser} class uses this class and its
 * cousin, {@link ProceduralPages} to organize all parsed source code elements.
 * Data is fed to each immediately after it is parsed, and at conversion time,
 * everything is organized.
 *
 * The Classes class is responsible for all inheritance, including resolving
 * name conflicts between classes, determining which classes extend other
 * classes, and is responsible for all inheritance of documentation.
 * {@internal
 * This structure parses classes, vars and methods by file, and then iterates
 * over the class tree to set up inheritance.  The {@link Inherit()}
 * method is the meat of the class, and processes the class trees from root to
 * branch, ensuring that parsing order is unimportant.}}
 * @package phpDocumentor
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: Classes.inc,v 1.1 2005/10/17 18:36:55 jeichorn Exp $
 */
class Classes
{
    /**#@+
     * @access private
     */
    /**
     * file being parsed, used in every add function to match up elements with 
     * the file that contains them
     *
     * This variable is used during parsing to associate class elements added
     * to the data structures that contain them with the file they reside in
     * @see addClass(), addMethod(), addVar(), nextFile()
     * @var string
     */
    var $curfile;
    /**
     * class being parsed, used to match up methods and vars with their parent
     * class
     *
     * This variable is used during parsing to associate class elements added
     * to the data structures that contain them with the file they reside in
     * @see addMethod(), addVar()
     * @var string
     */
    var $curclass;
    
    /**
     * Used when a definite match is made between a parent class and a child
     * class
     *
     * This variable is used in post-parsing.
     *
     * Format: array(parent => array(parentfile => array(child => childfile)))
     * @var array
     */
    var $definitechild;
    /**
     * array of parsed classes organized by the name of the file that contains
     * the class.
     *
     * Format:
     * array(filename => array(classname => {@link parserClass}))
     * @var array
     */
    var $classesbyfile = array();
    /**
     * array of file names organized by classes that are in the file.
     *
     * This structure is designed to handle name conflicts.  Two files can
     * contain classes with the same name, and this array will record both
     * filenames to help control linking and inheritance errors
     *
     * Format:<pre>
     * array(classname => array(name of file containing classname,
     *                          name of file 2 containing classname...)</pre>
     * @var array
     */
    var $classesbynamefile = array();
    /**
     * array of parsed methods organized by the file that contains them.
     *
     * Format:<pre>
     * array(filename => array(classname => array({@link parserMethod} 1, 
     *                                            {@link parserMethod} 2,...))</pre>
     * @var array
     */
    var $methodsbyfile = array();
    /**
     * array of parsed vars organized by the file that contains them.
     *
     * Format:
     * array(filename => array(classname => array({@link parserVar} 1, {@link parserVar} 2,...))
     * @var array
     */
    var $varsbyfile = array();
    /**
     * array of parsed class constants organized by the file that contains them.
     *
     * Format:
     * array(filename => array(classname => array({@link parserConst} 1, {@link parserConst} 2,...))
     * @var array
     */
    var $constsbyfile = array();
    /**
     * keeps track of extend declarations by file, used to find inheritance
     *
     * Format:
     * array(filename => array(classname => parentclassname))
     * @var array
     */
    var $extendsbyfile = array();
    /**
     * Keeps track of child classes by file.
     * Since phpDocumentor can document collections of files that contain name
     * conflicts (PHP would give a fatal error), it
     * is impossible to assume a class that declares "extends foo" necessarily
     * extends the class foo in file X.  It could be an
     * extended class of class foo in file Y.  Because of this, phpDocumentor
     * relies on packaging to resolve the name conflict
     * This array keeps track of the packages of a child class
     *
     * Format:
     * array(parentclassname => array(filename => array(childclassname =>
     *                                      array(packagename, packagename)))
     * @var array
     */
    var $classchildrenbyfile = array();
    /**
     * Keeps track of class packages found in a file.
     * This is used in {@link getParentClass()} to determine the number of
     * packages in a file, in order to resolve inheritance issues
     * Format: array(filename => array(packagename1, packagename2,...))
     * @var array
     */
    var $classpackagebyfile = array();
    /**
     * a tree of class inheritance by name.
     *
     * format:<pre>
     * array(childname => parentname,
     *       childname1 => parentname1,
     *       rootname => 0, ...
     *      )</pre>
     * @var array
     * @see Converter::generateSortedClassTreeFromClass()
     */
    var $classparents = array();
    /**
     * Keeps track of package and subpackage for each class name, organized
     * by package
     *
     * Format:<pre>
     * array(classname => array(path => array(package,subpackage),
     *                          path2 => array(package,subpackage),...))</pre>
     * @var array
     */
    var $classpathpackages = array();
    /**
     * used to delete duplicates in the same package to avoid documentation errors
     *
     * Specifically used in {@link Converter::checkKillClass()}
     */
    var $killclass = array();
    /**
     * array of methods by package and class
     *
     * format:<pre>
     * array(packagename =>
     *         array(classname =>
     *               array(methodname1 => {@link parserMethod} class,
     *                     methodname2 => {@link parserMethod} class,...)
     *                      )
     *              )
     *      )</pre>
     * @var array
     * @see Converter
     */
    var $methods = array();
    
    /**
     * array of class variables by package and class
     *
     * format:<pre>
     * array(packagename =>
     *         array(classname =>
     *                array(variablename1 => {@link parserVar} class,
     *                      variablename2 => {@link parserVar} class,...
     *                     )
     *              )
     *      )</pre>
     * @var array
     * @see Converter
     */
    var $vars = array();
    
    /**
     * array of class variables by package and class
     *
     * format:<pre>
     * array(packagename =>
     *         array(classname =>
     *                array(constname1 => {@link parserConst} class,
     *                      constname2 => {@link parserConst} class,...
     *                     )
     *              )
     *      )</pre>
     * @var array
     * @see Converter
     */
    var $consts = array();
    /**
     * Reverse class_packages_by_file, used to prevent duplicates
     * @var array Format: array(packagename => 1)
     */
    var $revcpbf = array();
    /**
     * All classes with no parents (no extends clause) are tracked in this array
     * by the file that contains them.
     *
     * Format:<pre>
     * array(classname => array(name of file1 that contains root classname,
     *                          name of file2 that contains root classname,...))</pre>
     * @var array
     */
    var $roots = array();
    
    /**
     * array of all files that contain classes with the same name
     * @var array Format: (classname => array(path1, path2,...))
     */
    var $potentialclassconflicts = array();
    
    /**
     * array of all inter-package name conflicts of classes
     *
     * This array allows documentation of PHP namespace conflicts that would
     * occur should a user try to include these files in the same file
     * @var array Format: (classname => array(path1, path2,...))
     */
    var $classconflicts = array();
    /**#@-*/
    /**
     * While parsing, add a class to the list of parsed classes
     *
     * sets up the {@link $classesbyfile, $classesbynamefile, $extendsbyfile},
     * {@link $classchildrenbyfile, $roots} arrays, and sets {@link $curclass}
     * @param parserClass &$element element is a {@link parserClass}
     * @uses addPackageToFile() marks the current class's package as being
     *                          present in a file
     */
    function addClass(&$element)
    {
        $this->curclass = $element->getName();
        $element->curfile = $this->curfile;
        if (isset($this->classesbyfile[$this->curfile][$this->curclass]))
        {
            addWarning(PDERROR_ELEMENT_IGNORED,'class',$this->curclass,$this->curfile);
            $this->curclass = false;
            return;
        }
        $this->classesbyfile[$this->curfile][$this->curclass] = $element;
        $this->classesbynamefile[$this->curclass][] = $this->curfile;
        $this->extendsbyfile[$this->curfile][$this->curclass] = $element->getExtends();
        $this->classchildrenbyfile[$element->getExtends()][$this->curfile][$this->curclass][] = $element->docblock->package;
        if ($element->docblock->getExplicitPackage())
        $this->addPackageToFile($element->docblock->package);
        if (!$element->getExtends())
        {
            $this->roots[$this->curclass][] = $this->curfile;
        }
    }
    
    /**
     * While parsing, add a method to the list of parsed methods
     *
     * sets up the {@link $methodsbyfile} array using {@link $curfile} and
     * {@link $curclass}
     * @param parserMethod &$element element is a {@link parserMethod}
     */
    function addMethod(&$element)
    {
        if (!$this->curclass) return;
        $this->methodsbyfile[$this->curfile][$this->curclass][] = $element;
    }
    
    /**
     * While parsing, add a variable to the list of parsed variables
     *
     * sets up the {@link $varsbyfile} array using {@link $curfile} and {@link $curclass}
     * @param parserVar &$element element is a {@link parserVar}
     */
    function addVar(&$element)
    {
        if (!$this->curclass) return;
        $this->varsbyfile[$this->curfile][$this->curclass][] = $element;
    }
    
    /**
     * While parsing, add a variable to the list of parsed variables
     *
     * sets up the {@link $constsbyfile} array using {@link $curfile} and {@link $curclass}
     * @param parserConst &$element element is a {@link parserConst}
     */
    function addConst(&$element)
    {
        if (!$this->curclass) return;
        $this->constsbyfile[$this->curfile][$this->curclass][] = $element;
    }
    
    /**
     * Prepare to parse a new file
     *
     * sets {@link $curfile} to $file and {@link $curclass} to false (no class being parsed)
     * @param string $file file currently being parsed
     */
    function nextFile($file)
    {
        $this->curfile = $file;
        $this->curclass = false;
    }
    
    /**
     * Mark a package as being used in a class
     *
     * {@source}
     * @param string $package package name
     */
    function addPackageToFile($package)
    {
        if (!isset($this->revcpbf[$this->curfile][$package]))
        $this->classpackagebyfile[$this->curfile][] = $package;
        $this->revcpbf[$this->curfile][$package] = 1;
    }
    
    /**
     * Find the parent class of $class, and set up structures to note this fact
     *
     * Modifies the {@link parserClass} element in {@link $classesbyfile} to use
     * the parent's package, and inherit methods/vars
     * @param string $class child class to find parent class
     * @param string $file file child class is located in
     * @uses $definitechild if a match is made between a parent class and parameter
     *                      $class in file $file, then definitechild is set here
     * @uses getParentClass() to find the parent class
     */
    function setClassParent($class,$file)
    {
        if (is_array($par = $this->getParentClass($class,$file)))
        {
//            phpDocumentor_out("$file class $class extends ".$par[1]." file ".$par[0]."\n");
            $this->classesbyfile[$file][$class]->setParent($par[1],$par[0],$this);
            $this->definitechild[$par[1]][$par[0]][$class] = $file;
        } else
        {
            $this->classesbyfile[$file][$class]->setParentNoClass($par);
        }
    }
    
    /**
     * Main processing engine for setting up class inheritance.
     *
     * This function uses {@link $roots} to traverse the inheritance tree via
     * {@link processChild()} and returns the data structures
     * phpDocumentor_IntermediateParser needs to convert parsed data
     * to output using {@link phpDocumentor_IntermediateParser::Convert()}
     * @param phpDocumentor_IntermediateParser
     * @uses processChild() set up inheritance
     */
    function Inherit(&$render)
    {
        phpDocumentor_out("\nProcessing Class Inheritance\n\n");
        flush();
        phpDocumentor_out("\nProcessing Root Trees\n\n");
        flush();
        foreach($this->roots as $class => $files)
        {
            for ($i=0; $i<count($files); $i++)
            {
                $this->processChild($render,$class,$files[$i]);
            }
        }
        if (0)
        foreach($this->classesbyfile as $i => $j)
        {
            foreach($j as $k => $m)
            {
                var_dump($i,$k);
                if ($i == 'iConverter')
                {
                    var_dump($j);
                }
            }
        }
        phpDocumentor_out("\nProcessing leftover classes (classes that extend root classes not found in the same package)\n");
        flush();
        foreach($this->classesbyfile as $i => $j)
        {
            foreach($j as $k => $m)
            {
                $this->processChild($render,$k,$i,true);
            }
        }
        phpDocumentor_out("done processing leftover classes\n");
        flush();
        $this->setupClassConflicts();
    }
    
    /**
     * Transfers actual conflicts from {@link $potentialClassconflicts} to
     * {@link $classconflicts}
     * @access private
     * @uses $potentialclassconflicts transfers values to {@link $classconflicts}
     */
    function setupClassConflicts()
    {
        foreach($this->potentialclassconflicts as $class => $paths)
        {
            if (count($paths) - 1)
            { //conflict
                $package = array();
                foreach($paths as $path)
                {
                    // create a list of conflicting classes in each package
                    if (isset($this->classpathpackages[$class][$path]))
                    $package[$this->classpathpackages[$class][$path][0]][] = $path;
                }
                foreach($package as $pathpackages)
                {
                    // if at least 2 functions exist in the same package, delete all but the first one and add warnings
                    if (count($pathpackages) - 1)
                    {
                        for($i=1; $i < count($pathpackages); $i++)
                        {
                            if (isset($this->classesbyfile[$pathpackages[$i]]))
                            {
                                addWarning(PDERROR_ELEMENT_IGNORED,'class',$class,$pathpackages[$i]);
                                $this->killClass($class,$pathpackages[$i]);
                                $oth = array_flip($paths);
                                unset($paths[$oth[$pathpackages[$i]]]);
                            }
                        }
                    }
                }
                $this->classconflicts[$class] = $paths;
            }
        }
    }
    
    /**
     * If a package contains two classes with the same name, this function finds
     * that conflict
     *
     * Returns the {@link $classconflicts} entry for class $class, minus its own path
     * @return mixed returns false if no conflicts, or an array of paths containing conflicts
     */
    function getConflicts($class)
    {
        if (!isset($this->classconflicts[$class])) return false;
        $a = array();
        foreach($this->classconflicts[$class] as $conflict)
        {
            $a[$this->classesbyfile[$conflict][$class]->docblock->package] = $this->classesbyfile[$conflict][$class];
        }
        return $a;
    }
    
    /**
     * sets up {@link $killclass} for use by Converter::checkKillClass()
     * @access private
     */
    function killClass($class,$path)
    {
        $this->killclass[$class][$path] = true;
    }
    
    /**
     * This function recursively climbs up the class tree, setting inherited
     * information like package and adds the elements to phpDocumentor_IntermediateParser.
     *
     * Using structures defined in {@link Classes}, the function first sets package information,
     * and then seeks out child classes.
     * It uses 3 tests to determine whether a class is a child class.
     * <ol>
     *    <li>child class is in the same file as the parent class and extends parent class</li>
     *    <li>child class is in a different file and specifies the parent's @package in its docblock</li>
     *    <li>child class is in a different file and is in a different @package, with one possible parent class</li>
     * </ol>
     * @param phpDocumentor_IntermediateParser &$render
     * @param string $class class to process
     * @param string $file name of file $class is located in
     * @param boolean $furb flag used privately to control informational output while parsing
     *                            (used when processing leftover classes in {@link Inherit()}
     * @global    string    default package, usually "default"
     */
    function processChild(&$render,$class,$file,$furb = false)
    {
        global $phpDocumentor_DefaultPackageName;
        if (isset($this->classesbyfile[$file][$class]->processed)) return;
        $this->potentialclassconflicts[$class][] = $file;
        if ($furb) phpDocumentor_out("Processing $class in file $file\n");
        flush();
        $this->classesbyfile[$file][$class]->processed = true;
        $db = $this->classesbyfile[$file][$class];
        $render->addUses($db,$file);
        if (!$render->parsePrivate)
        {
            // if this class has an @access private, and parse private is disabled, remove it
            if ($db->docblock->hasaccess)
            {
                $aaa = $db->docblock->getKeyword('access');
                if (is_object($aaa) && $aaa->getString() == 'private')
                {
                    if (isset($this->varsbyfile[$file]) && isset($this->varsbyfile[$file][$class]))
                    {
                        unset($this->varsbyfile[$file][$class]);
                    }
                    if (isset($this->methodsbyfile[$file]) && isset($this->methodsbyfile[$file][$class]))
                    {
                        unset($this->methodsbyfile[$file][$class]);
                    }
                    if (isset($this->constsbyfile[$file]) && isset($this->constsbyfile[$file][$class]))
                    {
                        unset($this->constsbyfile[$file][$class]);
                    }
                    $this->classesbyfile[$file][$class]->ignore = true;
                    // if this is a root class, remove it from the roots array
                    if (isset($this->roots[$class]))
                    foreach($this->roots[$class] as $i => $files)
                    {
                        // find the file kkey and unset
                        if ($files == $file) unset($this->roots[$class][$i]);
                    }
                    // if this is a child, remove it from the list of child classes of its parent
                    if ($db->getExtends()) unset($this->classchildrenbyfile[$db->getExtends()][$file]);
                    return;
                }
            }
        }
        if ($render->packageoutput)
        {
            if (!in_array($db->docblock->package,$render->packageoutput))
            {
                if (isset($this->varsbyfile[$file]) && isset($this->varsbyfile[$file][$class]))
                {
                    unset($this->varsbyfile[$file][$class]);
                }
                if (isset($this->methodsbyfile[$file]) && isset($this->methodsbyfile[$file][$class]))
                {
                    unset($this->methodsbyfile[$file][$class]);
                }
                if (isset($this->constsbyfile[$file]) && isset($this->constsbyfile[$file][$class]))
                {
                    unset($this->constsbyfile[$file][$class]);
                }
                $this->classesbyfile[$file][$class]->ignore = true;
                if (isset($this->roots[$class]))
                foreach($this->roots[$class] as $i => $files)
                {
                    if ($files == $file) unset($this->roots[$class][$i]);
                }
                if ($db->getExtends()) unset($this->classchildrenbyfile[$db->getExtends()][$file]);
                return;
            }
        }
        $this->setClassParent($class,$file);
        $db = $this->classesbyfile[$file][$class];
        if ($furb && !is_array($db->parent))
        {
//            debug("furb adding $class $file to roots");
            $this->roots[$class][] = $file;
        }
        // fix for 591396
        if (!$db->docblock->getExplicitPackage())
        {
            $a = $render->proceduralpages->pagepackages[$file];
            if ($a[0] != $phpDocumentor_DefaultPackageName)
            {
                // inherit page package
                $this->classesbyfile[$file][$class]->docblock->package = $a[0];
            }
        }
        if ($this->classesbyfile[$file][$class]->docblock->package == $render->proceduralpages->pagepackages[$file][0])
        {
            if ($this->classesbyfile[$file][$class]->docblock->subpackage == '')
                $this->classesbyfile[$file][$class]->docblock->subpackage = $render->proceduralpages->pagepackages[$file][1];
        }
        $db = $this->classesbyfile[$file][$class];
        $render->addPackageParent($db);
        $render->addPageIfNecessary($file, $db);
        if ($access = $db->docblock->getKeyword('access'))
        {
            if (!is_string($access) && is_object($access)) $access = $access->getString();
            if (!is_string($access)) $access = 'public';
            if (($access == 'private') && (!$render->parsePrivate))
            {
                if (isset($this->varsbyfile[$file]) && isset($this->varsbyfile[$file][$class]))
                foreach($this->varsbyfile[$file][$class] as $i => $vr)
                {
                    $vr->docblock->addKeyword('access','private');
                    $this->varsbyfile[$file][$class][$i] = $vr;
                }
                if (isset($this->methodsbyfile[$file]) && isset($this->methodsbyfile[$file][$class]))
                foreach($this->methodsbyfile[$file][$class] as $i => $vr)
                {
                    $vr->docblock->addKeyword('access','private');
                    $this->methodsbyfile[$file][$class][$i] = $vr;
                }
                if (isset($this->constsbyfile[$file]) && isset($this->constsbyfile[$file][$class]))
                foreach($this->constsbyfile[$file][$class] as $i => $vr)
                {
                    $vr->docblock->addKeyword('access','private');
                    $this->constsbyfile[$file][$class][$i] = $vr;
                }
            }
        }
        $this->classpathpackages[$class][$file] = array($db->docblock->package,$db->docblock->subpackage);
        if ($db->docblock->getExplicitPackage())
        $render->proceduralpages->addClassPackageToFile($file,$db->docblock->package,$db->docblock->subpackage);
        $render->addElementToPage($db,$file);
        if (isset($this->varsbyfile[$file]) && isset($this->varsbyfile[$file][$class]))
        foreach($this->varsbyfile[$file][$class] as $i => $vr)
        {
            $vr->docblock->package = $db->docblock->package;
            $vr->docblock->subpackage = $db->docblock->subpackage;
            $render->addElementToPage($vr,$file);
            $render->addUses($vr,$file);
            $this->varsbyfile[$file][$class][$i] = $vr;
            $this->vars[$db->docblock->package][$class][$vr->getName()] = $vr;
        }
        if (isset($this->methodsbyfile[$file]) && isset($this->methodsbyfile[$file][$class]))
        foreach($this->methodsbyfile[$file][$class] as $i => $vr)
        {
            $vr->docblock->package = $db->docblock->package;
            $vr->docblock->subpackage = $db->docblock->subpackage;
            $render->addElementToPage($vr,$file);
            $render->addUses($vr,$file);
            $this->methodsbyfile[$file][$class][$i] = $vr;
            $this->methods[$db->docblock->package][$class][$vr->getName()] = $vr;
        }
        if (isset($this->constsbyfile[$file]) && isset($this->constsbyfile[$file][$class]))
        foreach($this->constsbyfile[$file][$class] as $i => $vr)
        {
            $vr->docblock->package = $db->docblock->package;
            $vr->docblock->subpackage = $db->docblock->subpackage;
            $render->addElementToPage($vr,$file);
            $render->addUses($vr,$file);
            $this->constsbyfile[$file][$class][$i] = $vr;
            $this->methods[$db->docblock->package][$class][$vr->getName()] = $vr;
        }
        $this->classpackages[$class][] = array($db->docblock->package,$db->docblock->subpackage);
        if (is_array($db->parent))
        $this->classparents[$db->docblock->package][$class] = $db->parent[1];
        else
        $this->classparents[$db->docblock->package][$class] = $db->getExtends();
        if (is_array($db->parent))
        {
            $z = $this->getClass($db->parent[1],$db->parent[0]);
            $this->classchildren[$z->docblock->package][$db->parent[1]][] = $db;
        }
        if (isset($this->classchildrenbyfile[$class]))
        {
            foreach($this->classchildrenbyfile[$class] as $childfile => $other)
            {
                // test 1, inherits in same file (must be same package)
                if ($childfile == $file)
                {
                    foreach($other as $child => $packages)
                    {
//                        debug("parent $class same file $child");
                        $this->processChild($render,$child,$childfile);
                        $x = $this->getClass($child,$childfile);
                        if ($x->docblock->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
                        {
                            // child package need root for class trees
                            if ($x->docblock->package != $db->docblock->package)
                            {
//                            debug("adding $child in $childfile 1");
                                $this->roots[$child][] = $childfile;
                            }
                        }
                    }
                } else
                {
                // test 2, different file, same package
                    foreach($other as $child => $packages)
                    {
                        for($j=0; $j<count($packages); $j++)
                        {
                            if ($this->classesbyfile[$file][$class]->docblock->package == $packages[$j])
                            {
                                $this->processChild($render,$child,$childfile);
//                                debug("$childfile diff file $child, parent $class, same package ".$packages[$j]);
                            } else
                            {
                                // test 3, different file, different package, only 1 parent is possible
                                if (isset($this->classesbynamefile[$child]))
                                {
                                    // 1 possible parent
                                    if (count($this->classesbynamefile[$class]) == 1)
                                    {
//                                        debug("$childfile diff file $child, diff package, 1 possible parent root $class");
                                        $this->processChild($render,$child,$childfile);
                                        $x = $this->getClass($child,$childfile);
                                        if ($x->docblock->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
                                        {
                                            // child package need root for class trees
                                            if ($x->docblock->package != $db->docblock->package)
                                            {
//                                                debug("adding roots $child in $childfile 2");
                                                $this->roots[$child][] = $childfile;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    /**
     * Get the parserClass representation of a class from its name and file
     * @return parserClass
     * @param string $class classname
     * @param string $file file classname is located in
     */
    function &getClass($class, $file)
    {
//        debug("getClass called with class $class file $file");
        return $this->classesbyfile[$file][$class];
    }
    
    /**
     * Used by {@link parserData::getClasses()} to retrieve classes defined in file $path
     *
     * retrieves the array entry from {@link $classesbyfile} for $path
     * @param string $path full path to filename
     * @return mixed returns false if no classes defined in the file, otherwise returns an array of {@link parserClass}es
     */
    function getClassesInPath($path)
    {
        if (!isset($this->classesbyfile[$path])) return false;
        return $this->classesbyfile[$path];
    }
    
    /**
     * called by {@link parserClass::hasMethods()}.  Should not be directly called
     * @access private
     * @param string $file
     * @param string $class
     */
    function hasMethods($file,$class)
    {
        return isset($this->methodsbyfile[$file][$class]);
    }
    
    /**
     * called by {@link parserClass::hasConsts()}.  Should not be directly called
     * @access private
     * @param string $file
     * @param string $class
     */
    function hasConsts($file,$class)
    {
        return isset($this->constsbyfile[$file][$class]);
    }
    
    /**
     * called by {@link parserClass::hasVars()}.  Should not be directly called
     * @access private
     * @param string $file
     * @param string $class
     */
    function hasVars($file, $class)
    {
        return isset($this->varsbyfile[$file][$class]);
    }
    
    /**
     * called by {@link parserClass::hasMethod()}.  Should not be directly called
     * @param string $file
     * @param string $class
     * @param string $name method name
     * @access private
     */
    function hasMethod($class, $file, $name)
    {
        if (!$this->hasMethods($file, $class)) return false;
        for($i=0; $i<count($this->methodsbyfile[$file][$class]); $i++)
        {
            if ($this->methodsbyfile[$file][$class][$i]->getName() == $name) return true;
        }
        return false;
    }
    
    /**
     * called by {@link parserClass::hasVar()}.  Should not be directly called
     * @param string $file
     * @param string $class
     * @param string $name var name
     * @access private
     */
    function hasVar($class, $file, $name)
    {
        if (!$this->hasVars($file, $class)) return false;
        for($i=0; $i<count($this->varsbyfile[$file][$class]); $i++)
        {
            if ($this->varsbyfile[$file][$class][$i]->getName() == $name) return true;
        }
        return false;
    }
    
    /**
     * called by {@link parserClass::hasConst()}.  Should not be directly called
     * @param string $file
     * @param string $class
     * @param string $name var name
     * @access private
     */
    function hasConst($class, $file, $name)
    {
        if (!$this->hasConsts($file, $class)) return false;
        for($i=0; $i<count($this->constsbyfile[$file][$class]); $i++)
        {
            if ($this->constsbyfile[$file][$class][$i]->getName() == $name) return true;
        }
        return false;
    }
    
    /**
     * called by {@link parserClass::getMethods()}.  Should not be directly called
     * @access private
     * @param string $class
     * @param string $file
     */
    function &getMethods($class, $file)
    {
        if (!isset($this->methodsbyfile[$file][$class])) return false;
        return $this->methodsbyfile[$file][$class];
    }
    
    /**
     * called by {@link parserClass::getVars()}.  Should not be directly called
     * @access private
     * @param string $class
     * @param string $file
     */
    function &getVars($class, $file)
    {
        if (!isset($this->varsbyfile[$file][$class])) return false;
        return $this->varsbyfile[$file][$class];
    }
    
    /**
     * called by {@link parserClass::getConsts()}.  Should not be directly called
     * @access private
     * @param string $class
     * @param string $file
     */
    function &getConsts($class, $file)
    {
        if (!isset($this->constsbyfile[$file][$class])) return false;
        return $this->constsbyfile[$file][$class];
    }
    
    /**
     * called by {@link parserClass::getMethod()}.  Should not be directly called
     * @param string $class
     * @param string $file
     * @param string $name method name
     * @access private
     */
    function getMethod($class, $file, $name)
    {
        if (!$this->hasMethod($class, $file, $name)) return false;
        for($i=0; $i<count($this->methodsbyfile[$file][$class]); $i++)
        {
            if ($this->methodsbyfile[$file][$class][$i]->getName() == $name) return $this->methodsbyfile[$file][$class][$i];
        }
    }
    
    /**
     * called by {@link parserClass::getVar()}.  Should not be directly called
     * @param string $class
     * @param string $file
     * @param string $name var name
     * @access private
     */
    function getVar($class, $file, $name)
    {
        if (!$this->hasVar($class, $file, $name)) return false;
        for($i=0; $i<count($this->varsbyfile[$file][$class]); $i++)
        {
            if ($this->varsbyfile[$file][$class][$i]->getName() == $name) return $this->varsbyfile[$file][$class][$i];
        }
    }
    
    /**
     * called by {@link parserClass::getConst()}.  Should not be directly called
     * @param string $class
     * @param string $file
     * @param string $name var name
     * @access private
     */
    function getConst($class, $file, $name)
    {
        if (!$this->hasConst($class, $file, $name)) return false;
        for($i=0; $i<count($this->constsbyfile[$file][$class]); $i++)
        {
            if ($this->constsbyfile[$file][$class][$i]->getName() == $name) return $this->constsbyfile[$file][$class][$i];
        }
    }
    
    /**
     * Search for a class in a package
     * @return mixed returns false if no class in $package, otherwise returns a {@link parserClass}
     * @param string $class classname
     * @param string $package package classname is in
     */
    function &getClassByPackage($class,$package)
    {
        if (!isset($this->classesbynamefile[$class]))
        {
//            addWarning(PDERROR_CLASS_NOT_IN_PACKAGE,$class,$package); // removed, too many warnings, not very useful
            return false;
        }
        for($i=0; $i < count($this->classesbynamefile[$class]); $i++)
        {
						$cls = $this->classesbyfile[$this->classesbynamefile[$class][$i]][$class];
						$pkg = $cls->getPackage();
            if ($pkg == $package)
								return $cls;
        }
//        addWarning(PDERROR_CLASS_NOT_IN_PACKAGE,$class,$package);
        return false;
    }
    
    /**
     * Find the parent class of a class in file $file
     * uses 3 tests to find the parent classname:
     * <ol>
     *    <li>only one class with the parent classname</li>
     *    <li>more than one class, but only one in the same file as the child</li>
     *    <li>only one parent class in the same package as the child</li>
     * </ol>
     * @return mixed false if no parent class, a string if no parent class found by that name,
     *                and an array(file parentclass is in,parentclassname)
     */
    function getParentClass($class,$file)
    {
        if (!isset($this->classesbyfile[$file][$class]))
        {
            return false;
        }
        $element = $this->classesbyfile[$file][$class];
        if (!($ex = $element->getExtends())) return false;
        // first check to see if there is one and only one class with the parent class's name
        if (isset($this->classesbynamefile[$ex]))
        {
            if (count($this->classesbynamefile[$ex]) == 1)
            {
                if ($this->classesbyfile[$this->classesbynamefile[$ex][0]][$ex]->ignore) return $ex;
                return array($this->classesbynamefile[$ex][0],$ex);
            } else
            {
                // next check to see if there is a parent class in the same file
                if (isset($this->classesbyfile[$file][$ex]))
                {
                    if ($this->classesbyfile[$file][$ex]->ignore) return $ex;
                    return array($file,$ex);
                }
                // next check to see if there is only one package used in the file, try to resolve it that way
                if (isset($this->classpackagebyfile[$file]))
                {
                    if (count($this->classpackagebyfile[$file]) == 1)
                    {
                        for($i=0;$i<count($this->classesbynamefile[$ex]);$i++)
                        {
                            if ($this->classesbyfile[$this->classesbynamefile[$ex][$i]][$ex]->getPackage() == $this->classpackagebyfile[$file][0])
                            {
                                if ($this->classesbyfile[$this->classesbynamefile[$ex][$i]][$ex]->ignore) return $ex;
                                return array($this->classesbynamefile[$ex][$i],$ex);
                            }
                        }
                    }
                }
                // name conflict
                addWarning(PDERROR_INHERITANCE_CONFLICT, $class, $file, $ex);
                return $ex;
            }
        } else
        {
            addWarning(PDERROR_PARENT_NOT_FOUND, $class, $ex);
            return $ex;
        }
    }
    
    /**
     * Get a list of all root classes indexed by package.  Used to generate
     * class trees by {@link Converter}
     * @return array array(package => array(rootclassname, rootclassname,...),...)
     */
    function getRoots()
    {
        $roots = array();
        foreach($this->roots as $class => $files)
        {
            if (count($files))
            {
                foreach($files as $i => $boofou)
                {
                    $x = $this->getClass($class,$files[$i]);
                    $roots[$x->getPackage()][] = $class;
                }
            }
        }
        foreach($roots as $package => $root)
        {
            usort($roots[$package],"strnatcasecmp");
        }
        return $roots;
    }
    
    /**
     * Get all classes confirmed in parsing to be descended class $parclass in file $file
     * @return mixed either false if no children, or array of format
     *         array(childname => childfile,childname2 => childfile2,...)
     * @param string $parclass name of parent class
     * @param string $file file parent class is found in
     * @see parserClass::getChildClassList()
     * @uses $definitechild
     */
    function getDefiniteChildren($parclass,$file)
    {
        if (isset($this->definitechild[$parclass][$file])) return $this->definitechild[$parclass][$file];
        return false;
    }
}
?>