From 392176bfc9523e60e7038a4797f1a349511b56ab Mon Sep 17 00:00:00 2001 From: uschindler Date: Thu, 17 Apr 2014 20:44:39 +0000 Subject: [PATCH] Fix version number on branch, backport issue #27 and workaround for ANT bug --- build.xml | 15 +++- .../de/thetaphi/forbiddenapis/Checker.java | 68 +++++++++--------- .../antunit/Java8Annotations$FooBar.class | Bin 502 -> 499 bytes ...8Annotations$InnerClassWithCtorParam.class | Bin 0 -> 1010 bytes src/test/antunit/Java8Annotations.class | Bin 1303 -> 1399 bytes src/test/antunit/Java8Annotations.java | 11 ++- src/test/antunit/TestAnnotations.xml | 4 +- 7 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 src/test/antunit/Java8Annotations$InnerClassWithCtorParam.class diff --git a/build.xml b/build.xml index bbf159ed..e847a4bd 100644 --- a/build.xml +++ b/build.xml @@ -45,10 +45,21 @@ + + + + + + + + + + + - + @@ -63,7 +74,7 @@ - + diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index 83b200e4..e13ae678 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -469,14 +469,14 @@ boolean checkDescriptor(String desc) { return checkType(Type.getType(desc)); } - private void reportClassViolation(boolean violation) { + private void reportClassViolation(boolean violation, String where) { if (violation) { violations[0]++; final StringBuilder sb = new StringBuilder(" in ").append(className); if (source != null) { - new Formatter(sb, Locale.ENGLISH).format(" (%s, class declaration)", source).flush(); + new Formatter(sb, Locale.ENGLISH).format(" (%s, %s)", source, where).flush(); } else { - sb.append(" (class declaration)"); + new Formatter(sb, Locale.ENGLISH).format(" (%s)", where).flush(); } logError(sb.toString()); } @@ -484,7 +484,7 @@ private void reportClassViolation(boolean violation) { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - reportClassViolation(checkClassDefinition(superName, interfaces)); + reportClassViolation(checkClassDefinition(superName, interfaces), "class declaration"); } @Override @@ -494,13 +494,13 @@ public void visitSource(String source, String debug) { @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - reportClassViolation(checkDescriptor(desc)); + if (visible) reportClassViolation(checkDescriptor(desc), "annotation on class declaration"); return null; } @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { - reportClassViolation(checkDescriptor(desc)); + if (visible) reportClassViolation(checkDescriptor(desc), "type annotation on class declaration"); return null; } @@ -510,30 +510,30 @@ public FieldVisitor visitField(final int access, final String name, final String { // only check signature, if field is not synthetic if ((access & Opcodes.ACC_SYNTHETIC) == 0) { - reportFieldViolation(checkDescriptor(desc)); + reportFieldViolation(checkDescriptor(desc), "field declaration"); } } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - reportFieldViolation(checkDescriptor(desc)); + if (visible) reportFieldViolation(checkDescriptor(desc), "annotation on field declaration"); return null; } @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { - reportFieldViolation(checkDescriptor(desc)); + if (visible) reportFieldViolation(checkDescriptor(desc), "type annotation on field declaration"); return null; } - private void reportFieldViolation(boolean violation) { + private void reportFieldViolation(boolean violation, String where) { if (violation) { violations[0]++; final StringBuilder sb = new StringBuilder(" in ").append(className); if (source != null) { - new Formatter(sb, Locale.ENGLISH).format(" (%s, field declaration of '%s')", source, name).flush(); + new Formatter(sb, Locale.ENGLISH).format(" (%s, %s of '%s')", source, where, name).flush(); } else { - new Formatter(sb, Locale.ENGLISH).format(" (field declaration of '%s')", name).flush(); + new Formatter(sb, Locale.ENGLISH).format(" (%s of '%s')", where, name).flush(); } logError(sb.toString()); } @@ -549,7 +549,7 @@ public MethodVisitor visitMethod(final int access, final String name, final Stri { // only check signature, if method is not synthetic if ((access & Opcodes.ACC_SYNTHETIC) == 0) { - reportMethodViolation(checkDescriptor(desc)); + reportMethodViolation(checkDescriptor(desc), "method declaration"); } } @@ -637,72 +637,72 @@ private boolean checkConstant(Object cst) { @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { - reportMethodViolation(checkMethodAccess(owner, new Method(name, desc))); + reportMethodViolation(checkMethodAccess(owner, new Method(name, desc)), "method body"); } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { - reportMethodViolation(checkFieldAccess(owner, name)); + reportMethodViolation(checkFieldAccess(owner, name), "method body"); } @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); + if (visible) reportMethodViolation(checkDescriptor(desc), "annotation on method declaration"); + return null; + } + + @Override + public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { + if (visible) reportMethodViolation(checkDescriptor(desc), "parameter annotation on method declaration"); return null; } @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); + if (visible) reportMethodViolation(checkDescriptor(desc), "type annotation on method declaration"); return null; } @Override public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); + if (visible) reportMethodViolation(checkDescriptor(desc), "annotation in method body"); return null; } @Override public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); + if (visible) reportMethodViolation(checkDescriptor(desc), "annotation in method body"); return null; } @Override public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); + if (visible) reportMethodViolation(checkDescriptor(desc), "annotation in method body"); return null; } - @Override - public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { - reportMethodViolation(checkDescriptor(desc)); - return null; - } - @Override public void visitTypeInsn(int opcode, String type) { if (opcode == Opcodes.ANEWARRAY) { - reportMethodViolation(checkType(Type.getObjectType(type))); + reportMethodViolation(checkType(Type.getObjectType(type)), "method body"); } } @Override public void visitMultiANewArrayInsn(String desc, int dims) { - reportMethodViolation(checkDescriptor(desc)); + reportMethodViolation(checkDescriptor(desc), "method body"); } @Override public void visitLdcInsn(Object cst) { - reportMethodViolation(checkConstant(cst)); + reportMethodViolation(checkConstant(cst), "method body"); } @Override public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) { - reportMethodViolation(checkHandle(bsm)); + reportMethodViolation(checkHandle(bsm), "method body"); for (final Object cst : bsmArgs) { - reportMethodViolation(checkConstant(cst)); + reportMethodViolation(checkConstant(cst), "method body"); } } @@ -719,7 +719,7 @@ private String getHumanReadableMethodSignature() { return sb.toString(); } - private void reportMethodViolation(boolean violation) { + private void reportMethodViolation(boolean violation, String where) { if (violation) { violations[0]++; final StringBuilder sb = new StringBuilder(" in ").append(className); @@ -727,10 +727,10 @@ private void reportMethodViolation(boolean violation) { if (lineNo >= 0) { new Formatter(sb, Locale.ENGLISH).format(" (%s:%d)", source, lineNo).flush(); } else { - new Formatter(sb, Locale.ENGLISH).format(" (%s, method declaration of '%s')", source, getHumanReadableMethodSignature()).flush(); + new Formatter(sb, Locale.ENGLISH).format(" (%s, %s of '%s')", source, where, getHumanReadableMethodSignature()).flush(); } } else { - new Formatter(sb, Locale.ENGLISH).format(" (method declaration of '%s')", getHumanReadableMethodSignature()).flush(); + new Formatter(sb, Locale.ENGLISH).format(" (%s of '%s')", where, getHumanReadableMethodSignature()).flush(); } logError(sb.toString()); } diff --git a/src/test/antunit/Java8Annotations$FooBar.class b/src/test/antunit/Java8Annotations$FooBar.class index 9c8884f751b473c05bcc5781a9aa1b0f3bab30db..4e7b6eaf4dd7e9cd99da6e85ab39ab2a888a14b4 100644 GIT binary patch delta 24 gcmeyy{F!;eDh~FbP`?mQU)PBnf*3g`b1=RG0CC|6ga7~l delta 27 jcmey&{Ed0SDmGSUAIIR}iJOAh_(CEBT;nIRGQI-5WoCw+1|pKT31nGLb&!nhzQL>xiI> zl~ft!>kBhbs(xWK$q}S0Whl;;b2+*ysh*-ZI5}+|)^6r;D9+$@~# z^$%lZO2&}yL}T3-N79aa zb$*>SyDlFt7JYcAxTyNr!@i4}k2)GIo-u^;pqr-4P?+C7Z83$uYRw7lFs2}#%h(87 zuM>?8)jC;_jOxc)D$_Aq@F8`*l5otr8QhV*G*E;K)0<6*<_kfColMb;N&;E=pmseT8m{6yv(oazr`N$ipMN-+mM{R2V(6~b0gpaGV!kK5$gnBcL5 zJ7iI&goh?Td6fNc$EAf6R)i! QLp^O{nXLOHA8arF1KR!j#Q*>R literal 0 HcmV?d00001 diff --git a/src/test/antunit/Java8Annotations.class b/src/test/antunit/Java8Annotations.class index 46327604a8881dbfc4509381d7d696df0ebc917c..c16741746f6154190c8776232fd7da592a623e23 100644 GIT binary patch delta 647 zcmZ`#OHUI~7(Mse_O{chmbb-LN_jskDsL2Mg#^>2#01^AnUV<%DKp8;z?NSi3CzOZ z;F1-Ag+D+y{u_73a|=XF^d{e&bI*MDxEY6cy18=5Fg_vdhj@^%dSKb{Q~*u zlgK9(mP{;TB|4S)+A9;Uv8u3UVjUHM?16P`m7A8kSFSe>?A=gc^ev@@d)9;h$r*i@ zUrrt&%LTM?F+e*j0f7#pKqvnQbde_^D0P!b79k!=tKF+P3?aY6C`z5MEp0tLjl z#3y9tO%w9efTw>cnLb{V;JAn*cOIJ)z0rKE??k^V(yt9^lrTW19S0dnp8|$3OxF=| z1-Y#dPq&h`L%z`s%v!m{f6S(5;?#N|RyRk`bd;5mbme8|2DptesuJUvXyN2NH$A3) ar?;gYQ+>C6mP{Ivdi%No0r*k^K$!XIpOo delta 574 zcmZut$xZ@66s&HPfniWY#T69<7hG`PS6mVjjmD$5!A#5;9HN6j!V2FRuXRu%$!Cn1*p35@YI_&@dTB9#a~obIvxnV>wS kTO$Xhei$RZ9sQ>@$Bf#Zs#jYJ`?7u4psUj*Aw-5kU#&7ek^lez diff --git a/src/test/antunit/Java8Annotations.java b/src/test/antunit/Java8Annotations.java index 365a4dcc..404004e2 100644 --- a/src/test/antunit/Java8Annotations.java +++ b/src/test/antunit/Java8Annotations.java @@ -38,13 +38,20 @@ static void test(@FooBar int param1, @FooBar long param2) { } } + final class InnerClassWithCtorParam { + public InnerClassWithCtorParam(@FooBar X param) { + System.out.println(Java8Annotations.this); + System.out.println(param); + } + } + @Deprecated public int testField1; @FooBar public int testField2; - @Retention(value=RetentionPolicy.CLASS) - @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER, ElementType.METHOD, ElementType.TYPE}) + @Retention(value=RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD, ElementType.TYPE}) static @interface FooBar {} } diff --git a/src/test/antunit/TestAnnotations.xml b/src/test/antunit/TestAnnotations.xml index 589efec7..1af7d4d0 100644 --- a/src/test/antunit/TestAnnotations.xml +++ b/src/test/antunit/TestAnnotations.xml @@ -19,14 +19,14 @@ - + Java8Annotations$FooBar @ Forbidden annotation java.lang.Deprecated @ Deprecated annotation - + \ No newline at end of file