1313use PHPJava \Kernel \Maps \AccessFlag ;
1414use PHPJava \Kernel \Structures \_Utf8 ;
1515use PHPJava \Utilities \ClassResolver ;
16+ use PHPJava \Utilities \DebugTool ;
1617use PHPJava \Utilities \Formatter ;
1718
1819class JavaClass
@@ -73,6 +74,8 @@ class JavaClass
7374
7475 private $ options = [];
7576
77+ private $ debugTool ;
78+
7679 /**
7780 * JavaClass constructor.
7881 * @param JavaClassReaderInterface $reader
@@ -88,26 +91,43 @@ public function __construct(JavaClassReaderInterface $reader, array $options = [
8891 throw new ValidatorException ($ reader . ' has broken or not Java class. ' );
8992 }
9093
94+ // options
95+ $ this ->options = $ options ;
96+
97+ // Debug tool
98+ $ this ->debugTool = new DebugTool (
99+ $ reader ->getJavaPathName (),
100+ $ options
101+ );
102+
103+ $ this ->debugTool ->getLogger ()->debug ('Start emulation ' );
104+
91105 // read minor version
92106 $ this ->versions ['minor ' ] = $ reader ->getBinaryReader ()->readUnsignedShort ();
93107
108+ $ this ->debugTool ->getLogger ()->debug ('Minor version: ' . $ this ->versions ['minor ' ]);
109+
94110 // read major version
95111 $ this ->versions ['major ' ] = $ reader ->getBinaryReader ()->readUnsignedShort ();
96112
113+ $ this ->debugTool ->getLogger ()->debug ('Major version: ' . $ this ->versions ['minor ' ]);
114+
97115 // read constant pool size
98116 $ this ->constantPool = new ConstantPool (
99117 $ reader ,
100118 $ reader ->getBinaryReader ()->readUnsignedShort ()
101119 );
102120
121+ $ constantPoolEntries = $ this ->constantPool ->getEntries ();
122+
123+ $ this ->debugTool ->getLogger ()->debug ('Constant Pools: ' . count ($ constantPoolEntries ));
124+
103125 // read access flag
104126 $ this ->accessFlag = $ reader ->getBinaryReader ()->readUnsignedShort ();
105127
106128 // read this class
107129 $ this ->thisClass = $ reader ->getBinaryReader ()->readUnsignedShort ();
108130
109- $ constantPoolEntries = $ this ->constantPool ->getEntries ();
110-
111131 $ this ->className = $ constantPoolEntries [$ constantPoolEntries [$ this ->thisClass ]->getClassIndex ()];
112132
113133 // read super class
@@ -132,30 +152,42 @@ public function __construct(JavaClassReaderInterface $reader, array $options = [
132152 $ this ->activeInterfaces = new ActiveInterface (
133153 $ reader ,
134154 $ reader ->getBinaryReader ()->readUnsignedShort (),
135- $ this ->constantPool
155+ $ this ->constantPool ,
156+ $ this ->debugTool
136157 );
137158
159+ $ this ->debugTool ->getLogger ()->debug ('Extracted interfaces: ' . count ($ this ->activeInterfaces ->getEntries ()));
160+
138161 // read fields
139162 $ this ->activeFields = new ActiveFields (
140163 $ reader ,
141164 $ reader ->getBinaryReader ()->readUnsignedShort (),
142- $ this ->constantPool
165+ $ this ->constantPool ,
166+ $ this ->debugTool
143167 );
144168
169+ $ this ->debugTool ->getLogger ()->debug ('Extracted fields: ' . count ($ this ->activeFields ->getEntries ()));
170+
145171 // read methods
146172 $ this ->activeMethods = new ActiveMethods (
147173 $ reader ,
148174 $ reader ->getBinaryReader ()->readUnsignedShort (),
149- $ this ->constantPool
175+ $ this ->constantPool ,
176+ $ this ->debugTool
150177 );
151178
179+ $ this ->debugTool ->getLogger ()->debug ('Extracted methods: ' . count ($ this ->activeMethods ->getEntries ()));
180+
152181 // read Attributes
153182 $ this ->activeAttributes = new ActiveAttributes (
154183 $ reader ,
155184 $ reader ->getBinaryReader ()->readUnsignedShort (),
156- $ this ->constantPool
185+ $ this ->constantPool ,
186+ $ this ->debugTool
157187 );
158188
189+ $ this ->debugTool ->getLogger ()->debug ('Extracted attributes: ' . count ($ this ->activeAttributes ->getEntries ()));
190+
159191 foreach ($ this ->activeAttributes ->getEntries () as $ entry ) {
160192 if ($ entry ->getAttributeData () instanceof InnerClassesAttribute) {
161193 $ this ->innerClasses = array_merge (
@@ -171,17 +203,17 @@ public function __construct(JavaClassReaderInterface $reader, array $options = [
171203 );
172204 }
173205
174- public function __debugInfo ()
175- {
176- return [
177- 'className ' => $ this ->getClassName (),
178- 'superClass ' => get_class ($ this ->getSuperClass ()),
179- 'methods ' => [
180- 'static ' => array_keys ($ this ->invoker ->getStatic ()->getMethods ()->getList ()),
181- 'dynamic ' => array_keys ($ this ->invoker ->getDynamic ()->getMethods ()->getList ()),
182- ],
183- ];
184- }
206+ // public function __debugInfo()
207+ // {
208+ // return [
209+ // 'className' => $this->getClassName(),
210+ // 'superClass' => get_class($this->getSuperClass()),
211+ // 'methods' => [
212+ // 'static' => array_keys($this->invoker->getStatic()->getMethods()->getList()),
213+ // 'dynamic' => array_keys($this->invoker->getDynamic()->getMethods()->getList()),
214+ // ],
215+ // ];
216+ // }
185217
186218 public function getClassName (bool $ shortName = false ): string
187219 {
0 commit comments