From 6aba40a1ace9f31b3df0f98f41c70c754f3383b0 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 10 Aug 2015 14:17:22 +0100 Subject: Workaround for breaking change in OpenJDK 8 javadoc This should only affect behavior when using the OpenJDK 8 version of javadoc. ConstructorDoc.name() is supposed to return the unqualified name for a constructor. It is left ambiguous as to what this means for constructors of inner classes. e.g. package foo; class Bar { static class Baz { public Baz() {} } } For OpenJDK 7, the method returns "Bar.Baz" as the name of the constructor. i.e. it is qualified with the name of the outer class, but not the package For OpenJDK 8, the method returns "Baz" as the name of the constructor. i.e. it is not qualified at all In Android this affects both what doclava is willing to accept in @link tags, but also the content of the API files like current.txt. This change retains the old behavior under both OpenJDK 7 and OpenJDK 8. If later Android wants to adopt the new semantics that can be done once OpenJDK 7 is no longer supported. Bug: 18051133 Change-Id: Ic753a8d308e5d773cca13bd44ba3463481881779 --- src/com/google/doclava/Converter.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/google/doclava/Converter.java b/src/com/google/doclava/Converter.java index 3153b41..555fc39 100644 --- a/src/com/google/doclava/Converter.java +++ b/src/com/google/doclava/Converter.java @@ -439,9 +439,23 @@ public class Converter { return result; } else { ConstructorDoc m = (ConstructorDoc) o; + // Workaround for a JavaDoc behavior change introduced in OpenJDK 8 that breaks + // links in documentation and the content of API files like current.txt. + // http://b/18051133. + String name = m.name(); + ClassDoc containingClass = m.containingClass(); + if (containingClass.containingClass() != null) { + // This should detect the new behavior and be bypassed otherwise. + if (!name.contains(".")) { + // Constructors of inner classes do not contain the name of the enclosing class + // with OpenJDK 8. This simulates the old behavior: + name = containingClass.name(); + } + } + // End of workaround. MethodInfo result = - new MethodInfo(m.getRawCommentText(), new ArrayList(Arrays.asList(Converter.convertTypes(m.typeParameters()))), m - .name(), m.signature(), Converter.obtainClass(m.containingClass()), Converter + new MethodInfo(m.getRawCommentText(), new ArrayList(Arrays.asList(Converter.convertTypes(m.typeParameters()))), + name, m.signature(), Converter.obtainClass(m.containingClass()), Converter .obtainClass(m.containingClass()), m.isPublic(), m.isProtected(), m .isPackagePrivate(), m.isPrivate(), m.isFinal(), m.isStatic(), m.isSynthetic(), false, m.isSynchronized(), m.isNative(), false, "constructor", m.flatSignature(), -- cgit v1.2.3