Java Code Examples for com.jetbrains.php.lang.psi.elements.PhpClass#getConstructor()

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpClass#getConstructor() . 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: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@NotNull
private Method[] getExpectedMethods(@NotNull Project project, @NotNull String ClassInterfaceName, @NotNull String methodName) {
    Set<Method> methods = new HashSet<>();

    for (PhpClass phpClass : PhpIndex.getInstance(project).getAnyByFQN(ClassInterfaceName)) {

        // handle constructor as string
        if(methodName.equalsIgnoreCase("__construct")) {
            Method constructor = phpClass.getConstructor();
            if(constructor != null) {
                methods.add(constructor);
            }
            continue;
        }

        Method method = phpClass.findMethodByName(methodName);
        if(method != null) {
            methods.add(method);
        }
    }
    
    return methods.toArray(new Method[methods.size()]);
}
 
Example 2
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@NotNull
private Method[] getExpectedMethods(@NotNull Project project, @NotNull String ClassInterfaceName, @NotNull String methodName) {
    Set<Method> methods = new HashSet<>();

    for (PhpClass phpClass : PhpIndex.getInstance(project).getAnyByFQN(ClassInterfaceName)) {

        // handle constructor as string
        if(methodName.equalsIgnoreCase("__construct")) {
            Method constructor = phpClass.getConstructor();
            if(constructor != null) {
                methods.add(constructor);
            }
            continue;
        }

        Method method = phpClass.findMethodByName(methodName);
        if(method != null) {
            methods.add(method);
        }
    }
    
    return methods.toArray(new Method[methods.size()]);
}
 
Example 3
Source File: ServiceArgumentParameterHintsProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
private Pair<String, Method> getParamater(@NotNull Project project, @NotNull String aClass, @NotNull java.util.function.Function<Void, Integer> function) {
    if(StringUtils.isNotBlank(aClass)) {
        PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(project, aClass);
        if(phpClass != null) {
            Method constructor = phpClass.getConstructor();
            if(constructor != null) {
                Integer argumentIndex = function.apply(null);
                if(argumentIndex >= 0) {
                    String s = attachMethodInstances(constructor, argumentIndex);
                    if(s == null) {
                        return null;
                    }

                    return Pair.create(s, constructor);
                }
            }
        }
    }

    return null;
}
 
Example 4
Source File: ServiceActionUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public static List<String> getXmlMissingArgumentTypes(@NotNull XmlTag xmlTag, boolean collectOptionalParameter, @NotNull ContainerCollectionResolver.LazyServiceCollector collector) {
    PhpClass resolvedClassDefinition = getPhpClassFromXmlTag(xmlTag, collector);
    if (resolvedClassDefinition == null) {
        return Collections.emptyList();
    }

    Method constructor = resolvedClassDefinition.getConstructor();
    if(constructor == null) {
        return Collections.emptyList();
    }

    int serviceArguments = 0;

    for (XmlTag tag : xmlTag.getSubTags()) {
        if("argument".equals(tag.getName())) {
            serviceArguments++;
        }
    }

    Parameter[] parameters = collectOptionalParameter ? constructor.getParameters() : PhpElementsUtil.getFunctionRequiredParameter(constructor);
    if(parameters.length <= serviceArguments) {
        return Collections.emptyList();
    }

    final List<String> args = new ArrayList<>();

    for (int i = serviceArguments; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        String s = parameter.getDeclaredType().toString();
        args.add(s);
    }

    return args;
}
 
Example 5
Source File: ServiceBuilderTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<MethodParameter.MethodModelParameter> getMethodModelParameters() {
    PhpClass anyByFQN = PhpIndex.getInstance(getProject()).getAnyByFQN("\\Foo\\Bar").iterator().next();

    Method constructor = anyByFQN.getConstructor();
    assertNotNull(constructor);

    Parameter parameter = constructor.getParameters()[0];

    return Collections.singletonList(
        new MethodParameter.MethodModelParameter(constructor, parameter, 0, new HashSet<>(Collections.singletonList("foobar")), "foobar")
    );
}
 
Example 6
Source File: ServiceActionUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
public static List<String> getYamlMissingArgumentTypes(Project project, ServiceActionUtil.ServiceYamlContainer container, boolean collectOptionalParameter, @NotNull ContainerCollectionResolver.LazyServiceCollector collector) {
    PhpClass resolvedClassDefinition = ServiceUtil.getResolvedClassDefinition(project, container.getClassName(), collector);
    if(resolvedClassDefinition == null) {
        return Collections.emptyList();
    }

    Method constructor = resolvedClassDefinition.getConstructor();
    if(constructor == null) {
        return Collections.emptyList();
    }

    int serviceArguments = -1;
    if(container.getArgument() != null) {
        PsiElement yamlCompoundValue = container.getArgument().getValue();

        if(yamlCompoundValue instanceof YAMLCompoundValue) {
            List<PsiElement> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
            if(yamlArrayOnSequenceOrArrayElements != null) {
                serviceArguments = yamlArrayOnSequenceOrArrayElements.size();
            }
        }

    } else {
        serviceArguments = 0;
    }

    if(serviceArguments == -1) {
        return Collections.emptyList();
    }

    Parameter[] parameters = collectOptionalParameter ? constructor.getParameters() : PhpElementsUtil.getFunctionRequiredParameter(constructor);
    if(parameters.length <= serviceArguments) {
        return Collections.emptyList();
    }

    final List<String> args = new ArrayList<>();

    for (int i = serviceArguments; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        String s = parameter.getDeclaredType().toString();
        args.add(s);
    }

    return args;
}