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();
}
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());
}
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());
}
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());
}
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;
}
Aggregations