Search in sources :

Example 6 with PerlSubArgument

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

the class PerlSubDefinitionMixin method processSignatureElement.

@Override
protected boolean processSignatureElement(PsiElement signatureElement, List<PerlSubArgument> arguments) {
    if (!super.processSignatureElement(signatureElement, arguments)) {
        if (signatureElement instanceof PsiPerlSubSignatureElementIgnore) {
            PerlSubArgument newArgument = PerlSubArgument.empty();
            // has elements inside, means optional
            newArgument.setOptional(signatureElement.getFirstChild() != signatureElement.getLastChild());
            arguments.add(newArgument);
        } else if (signatureElement.getNode().getElementType() == PerlElementTypes.OPERATOR_ASSIGN && arguments.size() > 0) {
            // setting last element as optional
            arguments.get(arguments.size() - 1).setOptional(true);
        } else {
            return false;
        }
    }
    return true;
}
Also used : PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PsiPerlSubSignatureElementIgnore(com.perl5.lang.perl.psi.PsiPerlSubSignatureElementIgnore)

Example 7 with PerlSubArgument

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

the class PerlSubDefinitionElementType method deserialize.

@NotNull
@Override
public PerlSubDefinitionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
    // noinspection ConstantConditions
    String packageName = dataStream.readName().getString();
    // noinspection ConstantConditions
    String functionName = dataStream.readName().getString();
    List<PerlSubArgument> arguments = PerlSubArgument.deserializeList(dataStream);
    PerlSubAnnotations annotations = null;
    if (dataStream.readBoolean()) {
        annotations = PerlSubAnnotations.deserialize(dataStream);
    }
    return createStubElement(parentStub, packageName, functionName, arguments, annotations);
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PerlSubArgument

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

the class PerlBuiltInSubsService method readArguments.

@NotNull
private List<PerlSubArgument> readArguments(@Nullable Element argumentsElement, @NotNull String subName) {
    if (argumentsElement == null) {
        return Collections.emptyList();
    }
    List<Element> mandatoryElements = argumentsElement.getChildren(ARGUMENT_ELEMENT);
    List<Element> optionalElements;
    Element optionalElement = argumentsElement.getChild(OPTIONAL_ELEMENT);
    if (optionalElement == null) {
        optionalElements = Collections.emptyList();
    } else {
        optionalElements = optionalElement.getChildren(ARGUMENT_ELEMENT);
    }
    if (mandatoryElements.isEmpty() && optionalElements.isEmpty()) {
        return Collections.emptyList();
    }
    List<PerlSubArgument> result = new ArrayList<>();
    mandatoryElements.stream().map(element -> readArgument(element, false, subName)).filter(Objects::nonNull).forEach(result::add);
    optionalElements.stream().map(element -> readArgument(element, true, subName)).filter(Objects::nonNull).forEach(result::add);
    return result;
}
Also used : PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) Element(org.jdom.Element) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PerlSubArgument

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

the class PerlExceptionClassWrapper method processExceptionElement.

private void processExceptionElement(@NotNull List<PsiElement> listElements, int currentIndex, @NotNull List<PerlDelegatingLightNamedElement> result) {
    PsiElement listElement = listElements.get(currentIndex);
    if (!isAcceptableIdentifierElement(listElement)) {
        return;
    }
    String namespaceName = ElementManipulators.getValueText(listElement);
    if (StringUtil.isEmpty(namespaceName)) {
        return;
    }
    Map<String, PerlHashEntry> exceptionSettings = listElements.size() > currentIndex + 1 ? PerlHashUtil.collectHashMap(listElements.get(currentIndex + 1)) : Collections.emptyMap();
    // Building fields
    Set<PerlSubArgument> throwArguments = Collections.emptySet();
    PerlHashEntry fieldsEntry = exceptionSettings.get("fields");
    if (fieldsEntry != null && fieldsEntry.isComplete()) {
        PsiElement fieldsContainer = fieldsEntry.getNonNullValueElement();
        if (fieldsContainer instanceof PsiPerlAnonArray) {
            fieldsContainer = ((PsiPerlAnonArray) fieldsContainer).getExpr();
        }
        List<PsiElement> elements = PerlArrayUtil.collectListElements(fieldsContainer);
        if (!elements.isEmpty()) {
            // Fields method
            result.add(new PerlLightMethodDefinitionElement<>(this, FIELDS_METHOD_NAME, LIGHT_METHOD_DEFINITION, fieldsEntry.keyElement, namespaceName, Collections.emptyList(), null));
            // fields themselves
            throwArguments = new LinkedHashSet<>();
            for (PsiElement fieldElement : elements) {
                if (isAcceptableIdentifierElement(fieldElement)) {
                    String fieldName = PerlScalarUtil.getStringContent(fieldElement);
                    if (StringUtil.isNotEmpty(fieldName)) {
                        throwArguments.add(PerlSubArgument.mandatoryScalar(fieldName));
                        result.add(new PerlLightMethodDefinitionElement<>(this, fieldName, LIGHT_METHOD_DEFINITION, fieldElement, namespaceName, Collections.emptyList(), null));
                    }
                }
            }
        }
    }
    // making exception class
    PerlHashEntry isaEntry = exceptionSettings.get("isa");
    String parentClass = "Exception::Class::Base";
    if (isaEntry != null && isaEntry.isComplete()) {
        String manualIsa = isaEntry.getValueString();
        if (manualIsa != null) {
            parentClass = manualIsa;
        }
    }
    result.add(new PerlLightExceptionClassDefinition(this, namespaceName, LIGHT_NAMESPACE_DEFINITION, listElement, PerlMroType.DFS, Collections.singletonList(parentClass), PerlNamespaceAnnotations.tryToFindAnnotations(listElement, getParent()), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap()));
    // making alias
    PerlHashEntry aliasEntry = exceptionSettings.get("alias");
    if (aliasEntry != null && aliasEntry.isComplete()) {
        if (isAcceptableIdentifierElement(aliasEntry.valueElement)) {
            String aliasName = aliasEntry.getValueString();
            if (StringUtils.isNotEmpty(aliasName)) {
                result.add(new PerlLightSubDefinitionElement<>(this, aliasName, LIGHT_SUB_DEFINITION, aliasEntry.getNonNullValueElement(), PerlPackageUtil.getContextPackageName(this), new ArrayList<>(throwArguments), PerlSubAnnotations.tryToFindAnnotations(aliasEntry.keyElement, aliasEntry.valueElement)));
            }
        }
    }
}
Also used : PerlLightExceptionClassDefinition(com.perl5.lang.perl.parser.Exception.Class.psi.light.PerlLightExceptionClassDefinition) PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PsiPerlAnonArray(com.perl5.lang.perl.psi.PsiPerlAnonArray) PsiElement(com.intellij.psi.PsiElement)

Example 10 with PerlSubArgument

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

the class HTMLMasonArgsBlockImpl method getArgumentsListHeavy.

@NotNull
protected List<PerlSubArgument> getArgumentsListHeavy() {
    List<PerlSubArgument> result = new ArrayList<>();
    PsiElement run = getFirstChild();
    while (run != null) {
        if (run instanceof PerlVariableDeclarationElement) {
            PerlVariable variable = ((PerlVariableDeclarationElement) run).getVariable();
            if (variable != null) {
                PsiElement nextSibling = PerlPsiUtil.getNextSignificantSibling(run);
                result.add(PerlSubArgument.create(variable.getActualType(), variable.getName(), nextSibling != null && nextSibling.getNode().getElementType() == FAT_COMMA));
            }
        }
        run = run.getNextSibling();
    }
    return result;
}
Also used : PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) ArrayList(java.util.ArrayList) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PerlSubArgument (com.perl5.lang.perl.psi.utils.PerlSubArgument)9 NotNull (org.jetbrains.annotations.NotNull)4 PsiElement (com.intellij.psi.PsiElement)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 PerlSubDefinitionElement (com.perl5.lang.perl.psi.PerlSubDefinitionElement)2 PerlSubAnnotations (com.perl5.lang.perl.psi.utils.PerlSubAnnotations)2 PerlLightExceptionClassDefinition (com.perl5.lang.perl.parser.Exception.Class.psi.light.PerlLightExceptionClassDefinition)1 PerlMethodDefinition (com.perl5.lang.perl.psi.PerlMethodDefinition)1 PerlSubElement (com.perl5.lang.perl.psi.PerlSubElement)1 PerlVariable (com.perl5.lang.perl.psi.PerlVariable)1 PerlVariableDeclarationElement (com.perl5.lang.perl.psi.PerlVariableDeclarationElement)1 PsiPerlAnonArray (com.perl5.lang.perl.psi.PsiPerlAnonArray)1 PsiPerlSubSignatureElementIgnore (com.perl5.lang.perl.psi.PsiPerlSubSignatureElementIgnore)1 PerlSubDefinitionStub (com.perl5.lang.perl.psi.stubs.subsdefinitions.PerlSubDefinitionStub)1 PerlVariableType (com.perl5.lang.perl.psi.utils.PerlVariableType)1 Element (org.jdom.Element)1