Search in sources :

Example 1 with PerlSubAnnotations

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

the class PerlSubDeclarationElementType method deserialize.

@NotNull
@Override
public PerlSubDeclarationStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
    String packageName = PerlStubSerializationUtil.readString(dataStream);
    String subName = PerlStubSerializationUtil.readString(dataStream);
    PerlSubAnnotations annotations = null;
    if (dataStream.readBoolean()) {
        annotations = PerlSubAnnotations.deserialize(dataStream);
    }
    return new PerlSubDeclarationStub(parentStub, packageName, subName, annotations, this);
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlSubAnnotations

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

the class PerlSubDeclarationElementType method serialize.

@Override
public void serialize(@NotNull PerlSubDeclarationStub stub, @NotNull StubOutputStream dataStream) throws IOException {
    dataStream.writeName(stub.getPackageName());
    dataStream.writeName(stub.getSubName());
    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 3 with PerlSubAnnotations

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

the class PerlCodeGeneratorImpl method getOverrideCodeText.

@Nullable
@Override
public String getOverrideCodeText(PsiElement subBase) {
    if (subBase instanceof PerlSubElement) {
        PerlSubElement perlSubBase = (PerlSubElement) subBase;
        StringBuilder code = new StringBuilder();
        code.append("#@override\n");
        PerlSubAnnotations annotations = perlSubBase.getAnnotations();
        if (annotations != null) {
            if (annotations.isDeprecated()) {
                code.append("#@deprecated\n");
            }
            if (annotations.isAbstract()) {
                code.append("#@abstract\n");
            }
            if (annotations.isMethod() || subBase instanceof PerlMethodDefinition) {
                code.append("#@method\n");
            }
            if (StringUtil.isNotEmpty(annotations.getReturns())) {
                code.append("#@returns ");
                code.append(annotations.getReturns());
                code.append("\n");
            }
        }
        code.append("sub ");
        code.append(perlSubBase.getSubName());
        code.append("{\n");
        List<String> superArgs = new ArrayList<>();
        List<PerlSubArgument> arguments = Collections.emptyList();
        if (perlSubBase instanceof PerlSubDefinitionElement) {
            // noinspection unchecked
            arguments = ((PerlSubDefinitionElement) perlSubBase).getSubArgumentsList();
            if (!arguments.isEmpty()) {
                boolean useShift = false;
                for (PerlSubArgument argument : arguments) {
                    if (StringUtil.isNotEmpty(argument.getVariableClass())) {
                        useShift = true;
                        break;
                    }
                }
                if (useShift) {
                    for (PerlSubArgument argument : arguments) {
                        if (!argument.isEmpty()) {
                            code.append("my ");
                            code.append(argument.getVariableClass());
                            code.append(" ");
                            String superArg = argument.toStringShort();
                            superArgs.add(superArg);
                            code.append(superArg);
                            code.append(" = ");
                        }
                        code.append("shift;\n");
                    }
                } else {
                    code.append("my ");
                    code.append('(');
                    boolean insertComma = false;
                    for (PerlSubArgument argument : arguments) {
                        if (insertComma) {
                            code.append(", ");
                        } else {
                            insertComma = true;
                        }
                        String superArg = argument.toStringShort();
                        superArgs.add(superArg);
                        code.append(superArg);
                    }
                    code.append(") = @_;\n");
                }
            } else {
                code.append("my ($self) = @_;\n");
            }
        }
        if (!superArgs.isEmpty()) {
            superArgs.remove(0);
        }
        if (!arguments.isEmpty() && !arguments.get(0).isEmpty()) {
            // noinspection StringConcatenationInsideStringBufferAppend
            code.append(arguments.get(0).toStringShort() + "->SUPER::" + perlSubBase.getSubName() + "(" + StringUtil.join(superArgs, ", ") + ");\n");
        }
        code.append("}");
        return code.toString();
    }
    return null;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PerlSubElement(com.perl5.lang.perl.psi.PerlSubElement) ArrayList(java.util.ArrayList) PerlMethodDefinition(com.perl5.lang.perl.psi.PerlMethodDefinition) PerlSubDefinitionElement(com.perl5.lang.perl.psi.PerlSubDefinitionElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PerlSubAnnotations

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

the class PerlSubBase method getAnnotations.

@Nullable
@Override
public PerlSubAnnotations getAnnotations() {
    PerlSubAnnotations annotations;
    Stub stub = getStub();
    if (stub != null) {
        annotations = stub.getAnnotations();
    } else {
        // re-parsing
        annotations = getLocalAnnotations();
    }
    if (annotations != null) {
        return annotations;
    }
    return null;
}
Also used : PerlSubAnnotations(com.perl5.lang.perl.psi.utils.PerlSubAnnotations) PerlSubStub(com.perl5.lang.perl.psi.stubs.PerlSubStub) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PerlSubAnnotations

use of com.perl5.lang.perl.psi.utils.PerlSubAnnotations 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)

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