Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#getResolvedParameter()
The following examples show how to use
fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#getResolvedParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShopwareApiResourcesTypeProvider.java From idea-php-shopware-plugin with MIT License | 4 votes |
@Override public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) { // get back our original call // since phpstorm 7.1.2 we need to validate this int endIndex = expression.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return Collections.emptySet(); } String originalSignature = expression.substring(0, endIndex); String parameter = expression.substring(endIndex + 1); // search for called method PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> phpNamedElementCollections = phpIndex.getBySignature(originalSignature, null, 0); if(phpNamedElementCollections.size() == 0) { return Collections.emptySet(); } // get first matched item PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next(); if(!(phpNamedElement instanceof Method)) { return Collections.emptySet(); } parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter); if(parameter == null) { return Collections.emptySet(); } // finally search the classes if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Shopware\\Components\\Api\\Manager", "getResource")) { PhpClass phpClass = ShopwareUtil.getResourceClass(project, parameter); if(phpClass != null) { return Collections.singletonList(phpClass); } } return phpNamedElementCollections; }
Example 2
Source File: ObjectRepositoryTypeProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) { // get back our original call int endIndex = expression.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return Collections.emptySet(); } String originalSignature = expression.substring(0, endIndex); String parameter = expression.substring(endIndex + 1); // search for called method PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature); if(phpNamedElementCollections.size() == 0) { return Collections.emptySet(); } PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next(); if(!(phpNamedElement instanceof Method)) { return phpNamedElementCollections; } if (!PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, GET_REPOSITORIES_SIGNATURES)) { return phpNamedElementCollections; } // we can also pipe php references signatures and resolve them here // overwrite parameter to get string value parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter); if(parameter == null) { return phpNamedElementCollections; } PhpClass phpClass = EntityHelper.getEntityRepositoryClass(project, parameter); if(phpClass == null) { // self add :) return phpNamedElementCollections; } return PhpTypeProviderUtil.mergeSignatureResults(phpNamedElementCollections, phpClass); }
Example 3
Source File: ObjectManagerFindTypeProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) { // get back our original call int endIndex = expression.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return Collections.emptySet(); } String originalSignature = expression.substring(0, endIndex); String parameter = expression.substring(endIndex + 1); // search for called method PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature); if(phpNamedElementCollections.size() == 0) { return Collections.emptySet(); } PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next(); if(!(phpNamedElement instanceof Method)) { return Collections.emptySet(); } if (!( PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Common\\Persistence\\ObjectManager", "find") || PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Persistence\\ObjectManager", "find") )) { return Collections.emptySet(); } parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter); if(parameter == null) { return Collections.emptySet(); } PhpClass phpClass = EntityHelper.resolveShortcutName(project, parameter); if(phpClass == null) { return Collections.emptySet(); } return PhpTypeProviderUtil.mergeSignatureResults(phpNamedElementCollections, phpClass); }
Example 4
Source File: ObjectRepositoryResultTypeProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Nullable @Override public PhpType complete(String s, Project project) { int endIndex = s.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return null; } String originalSignature = s.substring(0, endIndex); String parameter = s.substring(endIndex + 1); parameter = PhpTypeProviderUtil.getResolvedParameter(PhpIndex.getInstance(project), parameter); if(parameter == null) { return null; } PhpClass phpClass = EntityHelper.resolveShortcutName(project, parameter); if(phpClass == null) { return null; } PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> typeSignature = getTypeSignatureMagic(phpIndex, originalSignature); // ->getRepository(SecondaryMarket::class)->findAll() => "findAll", but only if its a instance of this method; // so non Doctrine method are already filtered Set<String> resolveMethods = getObjectRepositoryCall(typeSignature).stream() .map(PhpNamedElement::getName) .collect(Collectors.toSet()); if (resolveMethods.isEmpty()) { return null; } PhpType phpType = new PhpType(); resolveMethods.stream() .map(name -> name.equals("findAll") || name.startsWith("findBy") ? phpClass.getFQN() + "[]" : phpClass.getFQN()) .collect(Collectors.toSet()) .forEach(phpType::add); return phpType; }
Example 5
Source File: MethodSignatureTypeProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) { // get back our original call int endIndex = expression.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return null; } String originalSignature = expression.substring(0, endIndex); String parameter = expression.substring(endIndex + 1); PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature); if(phpNamedElementCollections.size() == 0) { return null; } // get first matched item PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next(); if(!(phpNamedElement instanceof Method)) { return null; } Collection<MethodSignatureSetting> signatures = getSignatureSettings(phpNamedElement); if(signatures.size() == 0) { return null; } parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter); if(parameter == null) { return null; } Collection<PhpNamedElement> phpNamedElements = new ArrayList<>(); for(MethodSignatureSetting matchedSignature: signatures) { for(PhpTypeSignatureInterface signatureTypeProvider: PhpTypeSignatureTypes.DEFAULT_PROVIDER) { if( signatureTypeProvider.getName().equals(matchedSignature.getReferenceProviderName()) && PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, matchedSignature.getCallTo(), matchedSignature.getMethodName())) { Collection<? extends PhpNamedElement> namedElements = signatureTypeProvider.getByParameter(project, parameter); if(namedElements != null) { phpNamedElements.addAll(namedElements); } } } } // not good but we need return any previous types: null clears all types return new ArrayList<>(phpNamedElements); }
Example 6
Source File: SymfonyContainerTypeProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) { // get back our original call // since phpstorm 7.1.2 we need to validate this int endIndex = expression.lastIndexOf(TRIM_KEY); if(endIndex == -1) { return Collections.emptySet(); } String originalSignature = expression.substring(0, endIndex); String parameter = expression.substring(endIndex + 1); // search for called method PhpIndex phpIndex = PhpIndex.getInstance(project); Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature); if(phpNamedElementCollections.size() == 0) { return Collections.emptySet(); } // get first matched item PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next(); if(!(phpNamedElement instanceof Method)) { return phpNamedElementCollections; } parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter); if(parameter == null) { return phpNamedElementCollections; } // finally search the classes if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) { ContainerService containerService = ContainerCollectionResolver.getService(project, parameter); if(containerService != null) { Collection<PhpNamedElement> phpClasses = new HashSet<>(); for (String s : containerService.getClassNames()) { phpClasses.addAll(PhpIndex.getInstance(project).getAnyByFQN(s)); } return phpClasses; } } return phpNamedElementCollections; }