Skip to content

Commit

Permalink
Merge pull request #35 from LoiNguyenCS/inner-to-nested
Browse files Browse the repository at this point in the history
Fix bugs with static nested classes
  • Loading branch information
kelloggm authored Nov 2, 2023
2 parents 10a7407 + 763642c commit 3a33207
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Set<String> getTargetMethods() {

@Override
public Visitable visit(ClassOrInterfaceDeclaration decl, Void p) {
if (decl.isInnerClass()) {
if (decl.isNestedType()) {
this.classFQName += "." + decl.getName().toString();
} else {
if (!this.classFQName.equals("")) {
Expand All @@ -144,7 +144,7 @@ public Visitable visit(ClassOrInterfaceDeclaration decl, Void p) {
this.classFQName = decl.getFullyQualifiedName().orElseThrow();
}
Visitable result = super.visit(decl, p);
if (decl.isInnerClass()) {
if (decl.isNestedType()) {
this.classFQName = this.classFQName.substring(0, this.classFQName.lastIndexOf('.'));
} else {
this.classFQName = "";
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/checkerframework/specimin/StaticNestedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.checkerframework.specimin;

import java.io.IOException;
import org.junit.Test;

/**
* This test checks that if Specimin will work properly where there are static nested classes in the
* input code
*/
public class StaticNestedClass {
@Test
public void runTest() throws IOException {
SpeciminTestExecutor.runTestWithoutJarPaths(
"staticnestedclass",
new String[] {"com/example/OuterFamily.java"},
new String[] {
"com.example.OuterFamily#getLastName()",
"com.example.OuterFamily.InnerFamily#getLastName()"
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example;

public class Maternal {

public String maternalLastName = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example;

class OuterFamily extends Maternal {

static class InnerFamily extends Paternal {

public String getLastName() {
return paternalLastName;
}
}

public String getLastName() {
return maternalLastName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example;

public class Paternal {

public String paternalLastName = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example;

class OuterFamily extends Maternal {
static class InnerFamily extends Paternal {
public String getLastName() {
return paternalLastName;
}
}
// point A
public String getLastName() {
return maternalLastName;
}
}

0 comments on commit 3a33207

Please sign in to comment.