1616import com .jetbrains .php .lang .psi .elements .Field ;
1717import com .jetbrains .php .lang .psi .elements .Method ;
1818import com .jetbrains .php .lang .psi .elements .PhpClass ;
19- import com .jetbrains .php .lang .psi .resolve .types .PhpType ;
2019import org .jetbrains .annotations .NotNull ;
2120import org .jetbrains .annotations .Nullable ;
22- import org .nette .latte .psi .*;
23- import org .nette .latte .psi .elements .*;
2421
2522import java .util .ArrayList ;
2623import java .util .Collection ;
@@ -159,11 +156,17 @@ private static class Detector {
159156 return customFunction == null ? NettePhpType .MIXED : NettePhpType .create (customFunction .getFunctionReturnType ());
160157 }
161158
162- List <PhpType > types = new ArrayList <>();
159+ List <String > types = new ArrayList <>();
163160 for (PhpClass phpClass : phpClasses ) {
164161 for (Method phpMethod : phpClass .getMethods ()) {
165162 if (phpMethod .getName ().equals (name )) {
166- types .add (phpMethod .getType ());
163+ String foundType = phpMethod .getType ().toString ();
164+ for (String text : phpMethod .getType ().getTypesWithParametrisedParts ()) {
165+ if (text .contains ("<" )) {
166+ foundType = text ;
167+ }
168+ }
169+ types .add (foundType );
167170 }
168171 }
169172 }
@@ -175,11 +178,17 @@ private static class Detector {
175178 Collection <PhpClass > phpClasses = type .getPhpClasses (project );
176179 String name = property .getPropertyName ();
177180
178- List <PhpType > types = new ArrayList <>();
181+ List <String > types = new ArrayList <>();
179182 for (PhpClass phpClass : phpClasses ) {
180183 for (Field field : phpClass .getFields ()) {
181184 if (!field .isConstant () && !field .getModifier ().isStatic () && field .getModifier ().isPublic () && field .getName ().equals (name )) {
182- types .add (field .getType ());
185+ String foundType = field .getType ().toString ();
186+ for (String text : field .getType ().getTypesWithParametrisedParts ()) {
187+ if (text .contains ("<" )) {
188+ foundType = text ;
189+ }
190+ }
191+ types .add (foundType );
183192 }
184193 }
185194 }
@@ -191,11 +200,17 @@ private static class Detector {
191200 Collection <PhpClass > phpClasses = type .getPhpClasses (project );
192201 String name = property .getVariableName ();
193202
194- List <PhpType > types = new ArrayList <>();
203+ List <String > types = new ArrayList <>();
195204 for (PhpClass phpClass : phpClasses ) {
196205 for (Field field : phpClass .getFields ()) {
197206 if (!field .isConstant () && field .getModifier ().isStatic () && field .getModifier ().isPublic () && field .getName ().equals (name )) {
198- types .add (field .getType ());
207+ String foundType = field .getType ().toString ();
208+ for (String text : field .getType ().getTypesWithParametrisedParts ()) {
209+ if (text .contains ("<" )) {
210+ foundType = text ;
211+ }
212+ }
213+ types .add (foundType );
199214 }
200215 }
201216 }
@@ -207,11 +222,17 @@ private static class Detector {
207222 Collection <PhpClass > phpClasses = type .getPhpClasses (project );
208223 String name = constant .getConstantName ();
209224
210- List <PhpType > types = new ArrayList <>();
225+ List <String > types = new ArrayList <>();
211226 for (PhpClass phpClass : phpClasses ) {
212227 for (Field field : phpClass .getFields ()) {
213228 if (field .isConstant () && field .getModifier ().isPublic () && field .getName ().equals (name )) {
214- types .add (field .getType ());
229+ String foundType = field .getType ().toString ();
230+ for (String text : field .getType ().getTypesWithParametrisedParts ()) {
231+ if (text .contains ("<" )) {
232+ foundType = text ;
233+ }
234+ }
235+ types .add (foundType );
215236 }
216237 }
217238 }
@@ -257,7 +278,15 @@ public NettePhpType detectVariableTypeFromTemplateType(@NotNull LattePhpCachedVa
257278 for (PhpClass phpClass : classes ) {
258279 for (Field field : phpClass .getFields ()) {
259280 if (!field .isConstant () && field .getModifier ().isPublic () && variableName .equals (field .getName ())) {
260- return NettePhpType .create (field .getName (), field .getType ().toString (), LattePhpUtil .isNullable (field .getType ()));
281+ String type = field .getType ().toString ();
282+
283+ for (String text : field .getType ().getTypesWithParametrisedParts ()) {
284+ if (text .contains ("<" )) {
285+ type = text ;
286+ }
287+ }
288+
289+ return NettePhpType .create (field .getName (), type , LattePhpUtil .isNullable (field .getType ()));
261290 }
262291 }
263292 }
0 commit comments