|
12 | 12 | import com.jetbrains.php.PhpIndex;
|
13 | 13 | import com.jetbrains.php.lang.psi.elements.Field;
|
14 | 14 | import com.jetbrains.php.lang.psi.elements.Method;
|
| 15 | +import com.jetbrains.php.lang.psi.elements.Parameter; |
15 | 16 | import com.jetbrains.php.lang.psi.elements.PhpClass;
|
16 | 17 | import fr.adrienbrault.idea.symfony2plugin.config.xml.XmlHelper;
|
17 | 18 | import fr.adrienbrault.idea.symfony2plugin.dic.attribute.value.AttributeValueInterface;
|
@@ -289,51 +290,76 @@ public static ServiceTypeHint getYamlConstructorTypeHint(@NotNull PsiElement psi
|
289 | 290 | */
|
290 | 291 | @Nullable
|
291 | 292 | public static ServiceTypeHint getYamlConstructorTypeHint(@NotNull YAMLScalar yamlScalar, @NotNull ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {
|
292 |
| - PsiElement context = yamlScalar.getContext(); |
293 |
| - if(!(context instanceof YAMLSequenceItem)) { |
294 |
| - return null; |
295 |
| - } |
296 |
| - |
297 |
| - final YAMLSequenceItem sequenceItem = (YAMLSequenceItem) context; |
298 |
| - if (!(sequenceItem.getContext() instanceof YAMLSequence)) { |
299 |
| - return null; |
300 |
| - } |
301 |
| - |
302 |
| - final YAMLSequence yamlArray = (YAMLSequence) sequenceItem.getContext(); |
303 |
| - if(!(yamlArray.getContext() instanceof YAMLKeyValue)) { |
304 |
| - return null; |
305 |
| - } |
306 |
| - |
307 |
| - final YAMLKeyValue yamlKeyValue = (YAMLKeyValue) yamlArray.getContext(); |
308 |
| - if(!yamlKeyValue.getKeyText().equals("arguments")) { |
309 |
| - return null; |
310 |
| - } |
311 |
| - |
312 |
| - YAMLMapping parentMapping = yamlKeyValue.getParentMapping(); |
313 |
| - if(parentMapping == null) { |
314 |
| - return null; |
315 |
| - } |
316 |
| - |
317 |
| - String serviceId = getServiceClassFromServiceMapping(parentMapping); |
318 |
| - if(StringUtils.isBlank(serviceId)) { |
319 |
| - return null; |
320 |
| - } |
| 293 | + // arguments: ['$foobar': '@foo'] |
321 | 294 |
|
322 |
| - PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlScalar.getProject(), serviceId, lazyServiceCollector); |
323 |
| - if(serviceClass == null) { |
324 |
| - return null; |
| 295 | + PsiElement context = yamlScalar.getContext(); |
| 296 | + if(context instanceof YAMLKeyValue) { |
| 297 | + String key = ((YAMLKeyValue) context).getKeyText(); |
| 298 | + if(key.startsWith("$")) { |
| 299 | + PsiElement yamlMapping = context.getParent(); |
| 300 | + if(yamlMapping instanceof YAMLMapping) { |
| 301 | + PsiElement yamlKeyValue = yamlMapping.getParent(); |
| 302 | + if(yamlKeyValue instanceof YAMLKeyValue) { |
| 303 | + String keyText = ((YAMLKeyValue) yamlKeyValue).getKeyText(); |
| 304 | + if(keyText.equals("arguments")) { |
| 305 | + YAMLMapping parentMapping = ((YAMLKeyValue) yamlKeyValue).getParentMapping(); |
| 306 | + if(parentMapping != null) { |
| 307 | + String serviceId = getServiceClassFromServiceMapping(parentMapping); |
| 308 | + if(StringUtils.isNotBlank(serviceId)) { |
| 309 | + PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlScalar.getProject(), serviceId, lazyServiceCollector); |
| 310 | + if(serviceClass != null) { |
| 311 | + Method constructor = serviceClass.getConstructor(); |
| 312 | + if(constructor != null) { |
| 313 | + Parameter[] parameters = constructor.getParameters(); |
| 314 | + for (int i = 0; i < parameters.length; i++) { |
| 315 | + Parameter parameter = parameters[i]; |
| 316 | + if (key.equals("$" + parameter.getName())) { |
| 317 | + return new ServiceTypeHint(constructor, i, yamlScalar); |
| 318 | + } |
| 319 | + } |
| 320 | + } |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | + } |
| 327 | + } |
325 | 328 | }
|
326 | 329 |
|
327 |
| - Method constructor = serviceClass.getConstructor(); |
328 |
| - if(constructor == null) { |
329 |
| - return null; |
| 330 | + // arguments: ['@foobar'] |
| 331 | + if(context instanceof YAMLSequenceItem) { |
| 332 | + YAMLSequenceItem sequenceItem = (YAMLSequenceItem) context; |
| 333 | + PsiElement yamlSequenceItem = sequenceItem.getContext(); |
| 334 | + if (yamlSequenceItem instanceof YAMLSequence) { |
| 335 | + YAMLSequence yamlArray = (YAMLSequence) sequenceItem.getContext(); |
| 336 | + PsiElement yamlKeyValue = yamlArray.getContext(); |
| 337 | + if(yamlKeyValue instanceof YAMLKeyValue) { |
| 338 | + YAMLKeyValue yamlKeyValueArguments = (YAMLKeyValue) yamlKeyValue; |
| 339 | + if(yamlKeyValueArguments.getKeyText().equals("arguments")) { |
| 340 | + YAMLMapping parentMapping = yamlKeyValueArguments.getParentMapping(); |
| 341 | + if(parentMapping != null) { |
| 342 | + String serviceId = getServiceClassFromServiceMapping(parentMapping); |
| 343 | + if(StringUtils.isNotBlank(serviceId)) { |
| 344 | + PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlScalar.getProject(), serviceId, lazyServiceCollector); |
| 345 | + if(serviceClass != null) { |
| 346 | + Method constructor = serviceClass.getConstructor(); |
| 347 | + if(constructor != null) { |
| 348 | + return new ServiceTypeHint( |
| 349 | + constructor, |
| 350 | + PsiElementUtils.getPrevSiblingsOfType(sequenceItem, PlatformPatterns.psiElement(YAMLSequenceItem.class)).size(), |
| 351 | + yamlScalar |
| 352 | + ); |
| 353 | + } |
| 354 | + } |
| 355 | + } |
| 356 | + } |
| 357 | + } |
| 358 | + } |
| 359 | + } |
330 | 360 | }
|
331 | 361 |
|
332 |
| - return new ServiceTypeHint( |
333 |
| - constructor, |
334 |
| - PsiElementUtils.getPrevSiblingsOfType(sequenceItem, PlatformPatterns.psiElement(YAMLSequenceItem.class)).size(), |
335 |
| - yamlScalar |
336 |
| - ); |
| 362 | + return null; |
337 | 363 | }
|
338 | 364 |
|
339 | 365 | /**
|
|
0 commit comments