Search in sources :

Example 1 with TYPO3ServiceDefinition

use of com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition in project idea-php-typo3-plugin by cedricziel.

the class GeneralUtilityServiceTypeProvider method getBySignature.

@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {
    Collection<PhpNamedElement> phpNamedElementCollections = new ArrayList<>();
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    CoreServiceParser serviceParser = new CoreServiceParser();
    serviceParser.collect(project);
    List<TYPO3ServiceDefinition> resolvedServices = serviceParser.resolve(project, expression);
    if (resolvedServices == null || resolvedServices.isEmpty()) {
        return phpNamedElementCollections;
    }
    resolvedServices.forEach(serviceDefinition -> {
        Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(serviceDefinition.getClassName());
        phpNamedElementCollections.addAll(classesByFQN);
    });
    return phpNamedElementCollections;
}
Also used : TYPO3ServiceDefinition(com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition) PhpNamedElement(com.jetbrains.php.lang.psi.elements.PhpNamedElement) PhpIndex(com.jetbrains.php.PhpIndex) PhpClass(com.jetbrains.php.lang.psi.elements.PhpClass) ArrayList(java.util.ArrayList) CoreServiceParser(com.cedricziel.idea.typo3.container.CoreServiceParser)

Example 2 with TYPO3ServiceDefinition

use of com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition in project idea-php-typo3-plugin by cedricziel.

the class CoreServiceDefinitionParserVisitor method visitServiceCreation.

private void visitServiceCreation(PsiElement element) {
    MethodReference methodReference = (MethodReference) element;
    // A service definition should contain at least 4 arguments
    if (methodReference.getParameters().length < 4) {
        return;
    }
    // Extension name
    PsiElement extensionNameParam = methodReference.getParameters()[0];
    // Service name
    PsiElement serviceNameParam = methodReference.getParameters()[1];
    // Implementing Class (may be short name)
    PsiElement classNameParam = methodReference.getParameters()[2];
    // Array parameters
    PsiElement optionsArrayParam = methodReference.getParameters()[3];
    String serviceId;
    if (serviceNameParam instanceof StringLiteralExpression) {
        StringLiteralExpression name = (StringLiteralExpression) serviceNameParam;
        serviceId = name.getContents();
    } else {
        serviceId = serviceNameParam.getText();
    }
    ArrayList<TYPO3ServiceDefinition> serviceMap;
    if (!map.containsKey(serviceId)) {
        serviceMap = new ArrayList<>();
        map.put(serviceId, serviceMap);
    }
    serviceMap = map.get(serviceId);
    TYPO3ServiceDefinition serviceDefinition = new TYPO3ServiceDefinition(serviceId);
    serviceDefinition.setExtensionName(extensionNameParam.getText());
    if (classNameParam instanceof ClassConstantReference) {
        PhpExpression classReference = ((ClassConstantReference) classNameParam).getClassReference();
        if (classReference instanceof PhpReference) {
            serviceDefinition.setClass(((PhpReference) classReference).getFQN());
            PhpReference ref = (PhpReference) classReference;
            serviceDefinition.setSignature(ref.getSignature());
        }
        if (optionsArrayParam instanceof ArrayCreationExpression) {
            ArrayCreationExpression arrayExpression = (ArrayCreationExpression) optionsArrayParam;
            mapOptionsArrayParam(serviceDefinition, arrayExpression.getHashElements());
        }
        serviceMap.add(serviceDefinition);
    }
    map.put(serviceId, serviceMap);
}
Also used : TYPO3ServiceDefinition(com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition) PsiElement(com.intellij.psi.PsiElement)

Aggregations

TYPO3ServiceDefinition (com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition)2 CoreServiceParser (com.cedricziel.idea.typo3.container.CoreServiceParser)1 PsiElement (com.intellij.psi.PsiElement)1 PhpIndex (com.jetbrains.php.PhpIndex)1 PhpClass (com.jetbrains.php.lang.psi.elements.PhpClass)1 PhpNamedElement (com.jetbrains.php.lang.psi.elements.PhpNamedElement)1 ArrayList (java.util.ArrayList)1