use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.
the class PerlImplicitDeclarationsService method registerAnonSub.
@NotNull
public PerlImplicitSubDefinition registerAnonSub(@NotNull String namespaceName, @NotNull String baseName, @Nullable PerlValue returnValue) {
PerlImplicitSubDefinition subDefinition = new PerlImplicitSubDefinition(myPsiManager, baseName, namespaceName, Collections.emptyList(), returnValue, true);
doRegister(mySubsMap, subDefinition);
return subDefinition;
}
use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.
the class PerlMooseAttributeHandler method createMojoAttributes.
@NotNull
private List<PerlDelegatingLightNamedElement<?>> createMojoAttributes(@NotNull PerlSubCallElement subCallElement, @NotNull Pair<List<PsiElement>, List<PsiElement>> lists) {
List<PsiElement> arguments = lists.second.subList(1, lists.second.size());
PsiElement argument = ContainerUtil.getFirstItem(arguments);
PerlSubExpr subExpr = ObjectUtils.tryCast(argument, PerlSubExpr.class);
List<PerlDelegatingLightNamedElement<?>> result = new ArrayList<>();
String namespaceName = PerlPackageUtil.getContextNamespaceName(subCallElement);
for (PsiElement identifier : lists.first) {
AtomicNotNullLazyValue<PerlValue> valueProvider = AtomicNotNullLazyValue.createValue(() -> PerlSmartGetterValue.create(subExpr != null ? PerlResolveUtil.computeReturnValueFromControlFlow(subExpr) : argument != null ? PerlValuesManager.from(argument) : PerlScalarValue.create(namespaceName)));
PerlLightMethodDefinitionElement<PerlSubCallElement> newMethod = new PerlLightMethodDefinitionElement<>(subCallElement, ElementManipulators.getValueText(identifier), LIGHT_METHOD_DEFINITION, identifier, namespaceName, Arrays.asList(PerlSubArgument.self(), PerlSubArgument.optionalScalar(PerlSubArgument.NEW_VALUE_VALUE)), PerlSubAnnotations.tryToFindAnnotations(identifier, subCallElement.getParent()), valueProvider, subExpr == null ? null : subExpr.getBlock());
result.add(newMethod);
}
return result;
}
use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.
the class PerlSub method getReturnValue.
/**
* Calculates return value. By default - checks annotations
*
* @param contextPackage package this sub been invoked from, useful to return $self
* @param arguments invocation arguments
* @return type of return value if can be calculated, or {@link PerlValues#UNKNOWN_VALUE}
*/
@NotNull
default PerlValue getReturnValue() {
PerlValue valueFromCode = getReturnValueFromCode();
PerlValue annotationsValue = getReturnValueFromAnnotations();
if (valueFromCode.isUnknown()) {
return annotationsValue;
}
if (annotationsValue.isUnknown()) {
return valueFromCode;
}
return PerlOneOfValue.builder().addVariant(valueFromCode).addVariant(annotationsValue).build();
}
use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.
the class PerlValuesManager method from.
@NotNull
public static PerlValue from(@NotNull PsiElement target, @Nullable PerlAssignExpression.PerlAssignValueDescriptor assignValueDescriptor) {
if (assignValueDescriptor == null) {
return UNKNOWN_VALUE;
}
List<PsiElement> elements = assignValueDescriptor.getElements();
PerlContextType targetContextType = PerlContextType.from(target);
if (targetContextType == PerlContextType.SCALAR) {
int startIndex = assignValueDescriptor.getStartIndex();
if (elements.size() == 1 && (PerlContextType.isScalar(elements.get(0)) || startIndex == -1)) {
return PerlScalarContextValue.create(from(elements.get(0)));
} else if (elements.size() > 1 || PerlContextType.isList(ContainerUtil.getFirstItem(elements))) {
return PerlArrayElementValue.create(PerlArrayValue.builder().addPsiElements(elements).build(), PerlScalarValue.create(startIndex));
}
} else if (targetContextType == PerlContextType.LIST && assignValueDescriptor.getStartIndex() == 0) {
IElementType elementType = PsiUtilCore.getElementType(target);
if (elementType == HASH_VARIABLE || elementType == HASH_CAST_EXPR) {
return PerlMapValue.builder().addPsiElements(elements).build();
}
return PerlArrayValue.builder().addPsiElements(elements).build();
}
return UNKNOWN_VALUE;
}
use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.
the class PerlOneOfValue method getContextType.
@Override
@Nullable
protected PerlContextType getContextType() {
if (myVariants.isEmpty()) {
return null;
}
PerlContextType contextType = null;
boolean first = true;
for (PerlValue variant : myVariants) {
if (first) {
contextType = variant.getContextType();
first = false;
continue;
}
if (contextType != variant.getContextType()) {
return null;
}
}
return contextType;
}
Aggregations