diff --git a/access-modifier-checker/src/it/own-members/invoker.properties b/access-modifier-checker/src/it/own-members/invoker.properties
new file mode 100644
index 0000000..fff78ee
--- /dev/null
+++ b/access-modifier-checker/src/it/own-members/invoker.properties
@@ -0,0 +1 @@
+invoker.goals=clean package
diff --git a/access-modifier-checker/src/it/own-members/pom.xml b/access-modifier-checker/src/it/own-members/pom.xml
new file mode 100644
index 0000000..ad7ddae
--- /dev/null
+++ b/access-modifier-checker/src/it/own-members/pom.xml
@@ -0,0 +1,36 @@
+
+
+ 4.0.0
+ test
+ this-instance-impl
+ 1.0-SNAPSHOT
+ jar
+
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+ org.kohsuke
+ access-modifier-annotation
+ @project.version@
+
+
+
+
+
+ org.kohsuke
+ access-modifier-checker
+ @project.version@
+
+
+
+ enforce
+
+
+
+
+
+
+
diff --git a/access-modifier-checker/src/it/own-members/src/main/java/Outer.java b/access-modifier-checker/src/it/own-members/src/main/java/Outer.java
new file mode 100644
index 0000000..826eba5
--- /dev/null
+++ b/access-modifier-checker/src/it/own-members/src/main/java/Outer.java
@@ -0,0 +1,11 @@
+import org.kohsuke.accmod.Restricted;
+import org.kohsuke.accmod.restrictions.DoNotUse;
+
+class Outer {
+ @Restricted(DoNotUse.class)
+ static class Middle {
+ static class Inner {
+ static {new Middle();}
+ }
+ }
+}
\ No newline at end of file
diff --git a/access-modifier-checker/src/it/own-members/src/main/java/SomeClass.java b/access-modifier-checker/src/it/own-members/src/main/java/SomeClass.java
new file mode 100644
index 0000000..98165d9
--- /dev/null
+++ b/access-modifier-checker/src/it/own-members/src/main/java/SomeClass.java
@@ -0,0 +1,18 @@
+import org.kohsuke.accmod.Restricted;
+import org.kohsuke.accmod.restrictions.DoNotUse;
+
+@Restricted(DoNotUse.class)
+public class SomeClass {
+ private int foo;
+
+ public SomeClass() {
+ foo = 12;
+ }
+
+ public int getFoo() {
+ doSomething();
+ return foo;
+ }
+
+ private void doSomething() {}
+}
diff --git a/access-modifier-checker/src/main/java/org/kohsuke/accmod/impl/Checker.java b/access-modifier-checker/src/main/java/org/kohsuke/accmod/impl/Checker.java
index 42160c8..6b8f0e6 100644
--- a/access-modifier-checker/src/main/java/org/kohsuke/accmod/impl/Checker.java
+++ b/access-modifier-checker/src/main/java/org/kohsuke/accmod/impl/Checker.java
@@ -339,7 +339,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
return null;
}
- return new RestrictedMethodVisitor(currentLocation, annotationVisitor.getSkippedTypes());
+ return new RestrictedMethodVisitor(currentLocation, className, annotationVisitor.getSkippedTypes());
}
@Override
@@ -383,11 +383,24 @@ public String getProperty(String key) {
};
}
+ private static String topLevelClass(String a) {
+ int i = a.indexOf('$');
+ if (i == -1) {
+ return a;
+ }
+ return a.substring(0, i);
+ }
+
+ private static boolean sameClassFile(String currentClass, String owner) {
+ return topLevelClass(currentClass).equals(topLevelClass(owner));
+ }
+
private class RestrictedMethodVisitor extends MethodVisitor {
private final Set skippedTypesFromParent;
private Location currentLocation;
private RestrictedAnnotationVisitor annotationVisitor = new RestrictedAnnotationVisitor();
+ private final String currentClass;
private Set getSkippedTypes() {
Set allSkippedTypes = new HashSet<>(skippedTypesFromParent);
@@ -395,12 +408,13 @@ private Set getSkippedTypes() {
return allSkippedTypes;
}
- public RestrictedMethodVisitor(Location currentLocation, Set skippedTypes) {
+ public RestrictedMethodVisitor(Location currentLocation, String currentClass, Set skippedTypes) {
super(Opcodes.ASM5);
log.debug(String.format("New method visitor at %s#%s",
currentLocation.getClassName(), currentLocation.getMethodName()));
this.currentLocation = currentLocation;
this.skippedTypesFromParent = skippedTypes;
+ this.currentClass = currentClass;
}
@Override
@@ -411,6 +425,10 @@ public void visitLineNumber(int _line, Label start) {
public void visitTypeInsn(int opcode, String type) {
switch (opcode) {
case Opcodes.NEW:
+ if (sameClassFile(currentClass, type)) {
+ return;
+ }
+
for (Restrictions r : getRestrictions(type, getSkippedTypes())) {
r.instantiated(currentLocation, errorListener);
}
@@ -420,6 +438,11 @@ public void visitTypeInsn(int opcode, String type) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
log.debug(String.format("Visiting method %s#%s", owner, name));
+
+ if (sameClassFile(currentClass, owner)) {
+ return;
+ }
+
for (Restrictions r : getRestrictions(owner + '.' + name + desc, getSkippedTypes())) {
r.invoked(currentLocation, errorListener);
}
@@ -429,6 +452,10 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
log.debug(String.format("Visiting field '%s %s' in type %s", desc, name, owner));
+ if (sameClassFile(currentClass, owner)) {
+ return;
+ }
+
Iterable rs = getRestrictions(owner + '.' + name, getSkippedTypes());
switch (opcode) {
case Opcodes.GETSTATIC:
@@ -444,7 +471,6 @@ public void visitFieldInsn(int opcode, String owner, String name, String desc) {
}
break;
}
- super.visitFieldInsn(opcode, owner, name, desc);
}
@Override