Search in sources :

Example 1 with PerlCallValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue in project Perl5-IDEA by Camelcade.

the class PerlNameSuggestionProvider method suggestAndGetForCall.

private static String suggestAndGetForCall(@NotNull PerlSubCallElement subCall, @NotNull Set<String> result, String recommendation) {
    PsiPerlMethod method = subCall.getMethod();
    if (method == null) {
        return recommendation;
    }
    PerlCallValue callValue = PerlCallValue.from(method);
    if (callValue == null) {
        return recommendation;
    }
    PerlValue subNameValue = callValue.getSubNameValue();
    if (subNameValue.canRepresentSubName("new")) {
        PerlValue namespaceNameValue = callValue.getNamespaceNameValue();
        Collection<String> variantsFromObjectClass = getVariantsFromPerlValueNamespaces(method, namespaceNameValue);
        result.addAll(variantsFromObjectClass);
        if (!variantsFromObjectClass.isEmpty()) {
            recommendation = variantsFromObjectClass.iterator().next();
        }
    } else {
        Ref<String> recommendationRef = Ref.create(recommendation);
        for (String subName : subNameValue.resolve(method).getSubNames()) {
            String normalizedName = join(subName.replaceAll("^(_+|get_*|set_*)", ""));
            if (StringUtil.isNotEmpty(normalizedName)) {
                result.add(normalizedName);
                recommendationRef.set(normalizedName);
            }
        }
        recommendation = recommendationRef.get();
        result.addAll(getVariantsFromEntityValueNamespaces(subCall));
    }
    return recommendation;
}
Also used : PerlValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue) PerlCallValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue)

Example 2 with PerlCallValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue in project Perl5-IDEA by Camelcade.

the class PerlSubCallCompletionProvider method addCompletions.

@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet) {
    PsiElement position = parameters.getPosition();
    PsiElement method = position.getParent();
    assert method instanceof PsiPerlMethod;
    PerlCallValue perlValue = PerlCallValue.from(method);
    if (perlValue == null) {
        return;
    }
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, resultSet, position);
    PerlTimeLogger logger = PerlTimeLogger.create(LOG);
    if (perlValue instanceof PerlCallStaticValue && !((PerlCallStaticValue) perlValue).hasExplicitNamespace()) {
        PerlSubCompletionUtil.processBuiltInSubsLookupElements(completionProcessor);
        logger.debug("Processed built-in subs");
    }
    PerlSubCompletionUtil.processSubsCompletionsForCallValue(completionProcessor, perlValue, perlValue instanceof PerlCallStaticValue);
    logger.debug("Processed subs for call value");
    completionProcessor.logStatus(getClass());
}
Also used : PerlCallStaticValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallStaticValue) PsiPerlMethod(com.perl5.lang.perl.psi.PsiPerlMethod) PerlCallValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue) PerlTimeLogger(com.perl5.lang.perl.util.PerlTimeLogger) PerlSimpleCompletionProcessor(com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PerlCallValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue in project Perl5-IDEA by Camelcade.

the class PerlSubReference method resolveInner.

@Override
@NotNull
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PsiElement element = getElement();
    assert element instanceof PerlSubNameElement;
    PsiElement parent = element.getParent();
    PerlCallValue perlValue = null;
    if (parent instanceof PerlMethod) {
        perlValue = PerlCallValue.from(parent);
    } else {
        var parentElementType = PsiUtilCore.getElementType(parent);
        if (MODIFIER_DECLARATIONS_TOKENSET.contains(parentElementType) || MooseTokenSets.MOOSE_STATEMENTS.contains(parentElementType)) {
            perlValue = PerlCallObjectValue.create(PerlPackageUtil.getContextNamespaceName(myElement), myElement.getText(), Collections.emptyList());
        }
    }
    if (perlValue == null) {
        return ResolveResult.EMPTY_ARRAY;
    }
    List<PsiElement> relatedItems = new ArrayList<>();
    perlValue.processCallTargets(element, relatedItems::add);
    return getResolveResults(relatedItems).toArray(ResolveResult.EMPTY_ARRAY);
}
Also used : PerlSubNameElement(com.perl5.lang.perl.psi.PerlSubNameElement) PerlMethod(com.perl5.lang.perl.psi.PerlMethod) PerlCallValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PerlCallValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue)3 PsiElement (com.intellij.psi.PsiElement)2 PerlCallStaticValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallStaticValue)1 PerlValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue)1 PerlSimpleCompletionProcessor (com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor)1 PerlMethod (com.perl5.lang.perl.psi.PerlMethod)1 PerlSubNameElement (com.perl5.lang.perl.psi.PerlSubNameElement)1 PsiPerlMethod (com.perl5.lang.perl.psi.PsiPerlMethod)1 PerlTimeLogger (com.perl5.lang.perl.util.PerlTimeLogger)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1