Search in sources :

Example 11 with PerlValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.

the class PerlSubDefinitionBase method getReturnValueFromCode.

@Override
@NotNull
public PerlValue getReturnValueFromCode() {
    PerlValue returnValue = PerlSubDefinitionElement.super.getReturnValueFromCode();
    if (!returnValue.isUnknown()) {
        return returnValue;
    }
    PerlSubDefinitionStub greenStub = getGreenStub();
    return greenStub != null ? greenStub.getReturnValueFromCode() : myReturnValueFromCode.getValue();
}
Also used : PerlSubDefinitionStub(com.perl5.lang.perl.psi.stubs.subsdefinitions.PerlSubDefinitionStub) PerlValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PerlValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.

the class PerlVariableDeclarationElementMixin method getPsiDeclaredValue.

@NotNull
public PerlValue getPsiDeclaredValue() {
    PerlVariableDeclarationStub stub = getGreenStub();
    if (stub != null) {
        return stub.getDeclaredValue();
    }
    PerlVariableDeclarationExpr declaration = getPerlDeclaration();
    return declaration == null ? UNKNOWN_VALUE : PerlScalarValue.create(declaration.getDeclarationType());
}
Also used : PerlVariableDeclarationStub(com.perl5.lang.perl.psi.stubs.variables.PerlVariableDeclarationStub) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with PerlValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.

the class PerlLightTestCaseBase method doTestPerlValueWithoutInit.

protected void doTestPerlValueWithoutInit(@NotNull PerlValuableEntity element) {
    StringBuilder sb = new StringBuilder();
    PerlValue elementValue = PerlValuesManager.from(element);
    sb.append(getEditorTextWithCaretsAndSelections().trim()).append(SEPARATOR_NEWLINES).append(element.getText()).append("\n").append(serializePsiElement(element)).append("\n").append(elementValue.getPresentableText());
    sb.append(SEPARATOR_NEWLINES).append("Resolved").append(SEPARATOR_NEWLINES).append(elementValue.resolve(element).getPresentableText());
    UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString());
}
Also used : PerlValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue)

Example 14 with PerlValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.

the class PerlLightTestCaseBase method doTestReturnValue.

protected void doTestReturnValue() {
    initWithFileSmart(getTestName(true));
    addVirtualFileFilter();
    PsiElement element = TargetElementUtil.getInstance().getNamedElement(getFile().findElementAt(getEditor().getCaretModel().getOffset()), 0);
    if (element == null) {
        element = getElementAtCaret(PerlSubElement.class);
    }
    assertNotNull(element);
    assertInstanceOf(element, PerlSubElement.class);
    StringBuilder sb = new StringBuilder();
    PerlValue returnValue = ((PerlSubElement) element).getReturnValue();
    sb.append(getEditorTextWithCaretsAndSelections().trim()).append(SEPARATOR_NEWLINES).append(returnValue);
    UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString());
}
Also used : PerlValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue)

Example 15 with PerlValue

use of com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue in project Perl5-IDEA by Camelcade.

the class PerlCodeGeneratorImpl method getOverrideCodeText.

@Override
@Nullable
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");
            }
            PerlValue returnValue = annotations.getReturnValue();
            if (!returnValue.isUnknown()) {
                code.append("#@returns ");
                code.append(returnValue.toCode());
                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) PerlValue(com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue) 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)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)13 PerlValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue)11 PsiElement (com.intellij.psi.PsiElement)8 PerlCallValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlCallValue)3 Instruction (com.intellij.codeInsight.controlflow.Instruction)2 IElementType (com.intellij.psi.tree.IElementType)2 PerlAssignInstruction (com.perl5.lang.perl.idea.codeInsight.controlFlow.PerlAssignInstruction)2 PerlMutationInstruction (com.perl5.lang.perl.idea.codeInsight.controlFlow.PerlMutationInstruction)2 PerlOneOfValue (com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlOneOfValue)2 PerlBuiltInVariable (com.perl5.lang.perl.psi.impl.PerlBuiltInVariable)2 PerlSubCallElement (com.perl5.lang.perl.psi.impl.PerlSubCallElement)2 PerlDelegatingLightNamedElement (com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement)2 PerlLightMethodDefinitionElement (com.perl5.lang.perl.psi.light.PerlLightMethodDefinitionElement)2 PerlContextType (com.perl5.lang.perl.psi.utils.PerlContextType)2 PerlSubAnnotations (com.perl5.lang.perl.psi.utils.PerlSubAnnotations)2 PerlSubArgument (com.perl5.lang.perl.psi.utils.PerlSubArgument)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)1 Application (com.intellij.openapi.application.Application)1