Search in sources :

Example 6 with PerlSubAnnotations

use of com.perl5.lang.perl.psi.utils.PerlSubAnnotations in project Perl5-IDEA by Camelcade.

the class PerlSubDefinitionElementType method serialize.

@Override
public void serialize(@NotNull PerlSubDefinitionStub stub, @NotNull StubOutputStream dataStream) throws IOException {
    dataStream.writeName(stub.getPackageName());
    dataStream.writeName(stub.getSubName());
    PerlSubArgument.serializeList(dataStream, stub.getSubArgumentsList());
    PerlSubAnnotations subAnnotations = stub.getAnnotations();
    if (subAnnotations == null) {
        dataStream.writeBoolean(false);
    } else {
        dataStream.writeBoolean(true);
        subAnnotations.serialize(dataStream);
    }
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations)

Example 7 with PerlSubAnnotations

use of com.perl5.lang.perl.psi.utils.PerlSubAnnotations in project Perl5-IDEA by Camelcade.

the class PerlClassAccessorWrapper method calcLightElementsFromPsi.

@NotNull
@Override
public List<PerlDelegatingLightNamedElement> calcLightElementsFromPsi() {
    String packageName = PerlPackageUtil.getContextPackageName(this);
    if (StringUtil.isEmpty(packageName)) {
        return Collections.emptyList();
    }
    List<PsiElement> listElements = getCallArgumentsList();
    if (listElements.isEmpty()) {
        return Collections.emptyList();
    }
    List<PerlDelegatingLightNamedElement> result = new ArrayList<>();
    for (PsiElement listElement : listElements) {
        if (!isAcceptableIdentifierElement(listElement)) {
            continue;
        }
        String baseName = ElementManipulators.getValueText(listElement);
        PerlSubAnnotations subAnnotations = computeSubAnnotations(this, listElement);
        for (Function<String, String> computation : getNamesComputations()) {
            result.add(new PerlClassAccessorMethod(this, baseName, computation, CLASS_ACCESSOR_METHOD, listElement, packageName, subAnnotations));
        }
    }
    return result;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlDelegatingLightNamedElement(com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PerlSubAnnotations

use of com.perl5.lang.perl.psi.utils.PerlSubAnnotations in project Perl5-IDEA by Camelcade.

the class PerlSub method getReturns.

/**
 * Calculates type of 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 null
 */
@Nullable
default String getReturns(@Nullable String contextPackage, @NotNull List<PsiElement> arguments) {
    PerlSubAnnotations subAnnotations = getAnnotations();
    if (subAnnotations == null) {
        return null;
    }
    String returns = subAnnotations.getReturns();
    return PACKAGE_ANY.equals(returns) ? contextPackage : returns;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PerlSubAnnotations (com.perl5.lang.perl.psi.utils.PerlSubAnnotations)8 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PerlSubArgument (com.perl5.lang.perl.psi.utils.PerlSubArgument)2 ArrayList (java.util.ArrayList)2 PsiElement (com.intellij.psi.PsiElement)1 PerlMethodDefinition (com.perl5.lang.perl.psi.PerlMethodDefinition)1 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)1 PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)1 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)1 PerlSubStub (com.perl5.lang.perl.psi.stubs.PerlSubStub)1