Skip to content

Commit

Permalink
Merge pull request #71 from LoiNguyenCS/primitive-array
Browse files Browse the repository at this point in the history
add codes and tests for primitive array
  • Loading branch information
kelloggm authored Dec 8, 2023
2 parents f7dd867 + cfad22e commit 93c1d4e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,11 @@ public Visitable visit(FieldAccessExpr expr, Void p) {
usedMembers.add(fullNameOfClass + "#" + expr.getName().asString());
usedClass.add(fullNameOfClass);
usedClass.add(expr.resolve().getType().describe());
}
// when the type is a primitive array, we will have an UnsupportedOperationException
catch (UnsolvedSymbolException | UnsupportedOperationException e) {
} catch (UnsolvedSymbolException | UnsupportedOperationException e) {
// when the type is a primitive array, we will have an UnsupportedOperationException
if (e instanceof UnsupportedOperationException) {
updateUsedElementWithPotentialFieldNameExpr(expr.getScope().asNameExpr());
}
// if the a field is accessed in the form of a fully-qualified path, such as
// org.example.A.b, then other components in the path apart from the class name and field
// name, such as org and org.example, will also be considered as FieldAccessExpr.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.checkerframework.specimin;

import org.junit.Test;

import java.io.IOException;

/**
* This test checks if Specimin can handle fields of type primitive array.
*/
public class PrimitiveArrayTest {
@Test
public void runTest() throws IOException {
SpeciminTestExecutor.runTestWithoutJarPaths(
"primitivearray",
new String[] {"com/example/Simple.java"},
new String[] {"com.example.Simple#bar()"});
}
}
10 changes: 10 additions & 0 deletions src/test/resources/primitivearray/expected/com/example/Simple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

class Simple {

static final byte[] VALUES = null;

void bar() {
int length = VALUES.length;
}
}
10 changes: 10 additions & 0 deletions src/test/resources/primitivearray/input/com/example/Simple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

class Simple {

static final byte[] VALUES = new byte[];
// Target method.
void bar() {
int length = VALUES.length;
}
}

0 comments on commit 93c1d4e

Please sign in to comment.