Skip to content

Commit

Permalink
Fix corner case for Opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate committed Sep 7, 2024
1 parent de17ecf commit 56ff615
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,23 @@ public class ExporterInfo implements Processor<PsiElement> {
private final @NotNull List<String> EXPORT_OK = new ArrayList<>();
private final @NotNull Map<String, List<String>> EXPORT_TAGS = Collections.emptyMap();

// Deals with the following cases:
// use subs our @EXPORT_OK = qw( a b c );
public PsiElement findAssignExpr(PsiElement element) {
PsiElement target = element.getFirstChild();
while (target != null && !(target instanceof PsiPerlAssignExpr)) {
target = target.getNextSibling();
}
return target;
}

public void extractExport(PsiElement element, String exportName, List<String> target) {

Check warning

Code scanning / QDJVMC

Can use bounded wildcard Warning

Can generalize to ? super String

Check warning on line 264 in plugin/core/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.java

View workflow job for this annotation

GitHub Actions / Qodana / Analyze

Can use bounded wildcard

Can generalize to `? super String`
PsiElement rightSide = element.getFirstChild().getLastChild();
String variableName = element.getFirstChild().getFirstChild().getText();
PsiElement assignExpr = findAssignExpr(element);
PsiElement leftSide = assignExpr.getFirstChild();
PsiElement rightSide = assignExpr.getLastChild();
String variableName = leftSide instanceof PerlVariableDeclarationExpr ?
leftSide.getLastChild().getText() :
leftSide.getText();

// @EXPORT or @{namespace}::EXPORT
// @EXPORT_OK or @{namespace}::EXPORT_OK
Expand Down
1 change: 1 addition & 0 deletions plugin/src/test/java/unit/perl/ExporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected String getBaseDataPath() {
public void testExport() {
doTest("export.pl", "Foo", new String[]{"this", "is", "the", "end"}, new String[]{});
doTest("boolean.pl", "boolean", new String[]{"true", "false", "boolean"}, new String[]{"isTrue", "isFalse", "isBoolean"});
doTest("Opcode.pm", "Opcode", new String[]{}, new String[]{"opset", "opset_to_hex", "opdump"});
}

@Test
Expand Down
14 changes: 14 additions & 0 deletions plugin/src/test/resources/unit/perl/exporter/Opcode.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Opcode 1.64;

use strict;

use Carp;
use Exporter 'import';
use XSLoader;

sub opset (;@);
sub opset_to_hex ($);
sub opdump (;$);
use subs our @EXPORT_OK = qw(
opset opset_to_hex opdump
);

0 comments on commit 56ff615

Please sign in to comment.