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;
}
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());
}
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);
}
Aggregations