# HG changeset patch # User jjg # Date 1462837935 25200 # Node ID 42baa89d2156c657a4fb657413be5bb29719c571 # Parent 7c04fcb12bd4a31570a238e663fa846dfa5ec3b8 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API. Reviewed-by: ksrini diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ClassWriterImpl.java Mon May 09 16:52:15 2016 -0700 @@ -28,7 +28,7 @@ import java.util.*; import com.sun.javadoc.*; -import com.sun.tools.javadoc.RootDocImpl; +import com.sun.tools.javadoc.main.RootDocImpl; import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.builders.*; diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Mon May 09 16:52:15 2016 -0700 @@ -40,7 +40,7 @@ import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.StringUtils; -import com.sun.tools.javadoc.RootDocImpl; +import com.sun.tools.javadoc.main.RootDocImpl; /** * Configure the output based on the command line options. diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java Wed Jul 05 21:41:01 2017 +0200 +++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java Mon May 09 16:52:15 2016 -0700 @@ -149,8 +149,8 @@ return; Reader r; // temp hack until we can update SourcePosition API. - if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) { - FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject(); + if (sp instanceof com.sun.tools.javadoc.main.SourcePositionImpl) { + FileObject fo = ((com.sun.tools.javadoc.main.SourcePositionImpl) sp).fileObject(); if (fo == null) return; r = fo.openReader(true); diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AbstractTypeImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AbstractTypeImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.tools.javac.code.Type; - - -/** - * Abstract implementation of Type, with useful - * defaults for the methods in Type (and a couple from - * ProgramElementDoc). - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Scott Seligman - * @since 1.5 - */ -abstract class AbstractTypeImpl implements com.sun.javadoc.Type { - - protected final DocEnv env; - protected final Type type; - - protected AbstractTypeImpl(DocEnv env, Type type) { - this.env = env; - this.type = type; - } - - public String typeName() { - return type.tsym.name.toString(); - } - - public String qualifiedTypeName() { - return type.tsym.getQualifiedName().toString(); - } - - public com.sun.javadoc.Type getElementType() { - return null; - } - - public String simpleTypeName() { - return type.tsym.name.toString(); - } - - public String name() { - return typeName(); - } - - public String qualifiedName() { - return qualifiedTypeName(); - } - - public String toString() { - return qualifiedTypeName(); - } - - public String dimension() { - return ""; - } - - public boolean isPrimitive() { - return false; - } - - public ClassDoc asClassDoc() { - return null; - } - - public TypeVariable asTypeVariable() { - return null; - } - - public WildcardType asWildcardType() { - return null; - } - - public ParameterizedType asParameterizedType() { - return null; - } - - public AnnotationTypeDoc asAnnotationTypeDoc() { - return null; - } - - public AnnotatedType asAnnotatedType() { - return null; - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotatedTypeImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; -import com.sun.tools.javac.code.Attribute; -import com.sun.tools.javac.code.Attribute.TypeCompound; -import com.sun.tools.javac.util.List; - -/** - * Implementation of AnnotatedType, which - * represents an annotated type. - * - * @author Mahmood Ali - * @since 1.8 - */ -public class AnnotatedTypeImpl - extends AbstractTypeImpl implements AnnotatedType { - - AnnotatedTypeImpl(DocEnv env, com.sun.tools.javac.code.Type type) { - super(env, type); - } - - /** - * Get the annotations of this program element. - * Return an empty array if there are none. - */ - @Override - public AnnotationDesc[] annotations() { - List tas = type.getAnnotationMirrors(); - if (tas == null || - tas.isEmpty()) { - return new AnnotationDesc[0]; - } - AnnotationDesc res[] = new AnnotationDesc[tas.length()]; - int i = 0; - for (Attribute.Compound a : tas) { - res[i++] = new AnnotationDescImpl(env, a); - } - return res; - } - - @Override - public com.sun.javadoc.Type underlyingType() { - return TypeMaker.getType(env, type, true, false); - } - - @Override - public AnnotatedType asAnnotatedType() { - return this; - } - - @Override - public String toString() { - return typeName(); - } - - @Override - public String typeName() { - return this.underlyingType().typeName(); - } - - @Override - public String qualifiedTypeName() { - return this.underlyingType().qualifiedTypeName(); - } - - @Override - public String simpleTypeName() { - return this.underlyingType().simpleTypeName(); - } - - @Override - public String dimension() { - return this.underlyingType().dimension(); - } - - @Override - public boolean isPrimitive() { - return this.underlyingType().isPrimitive(); - } - - @Override - public ClassDoc asClassDoc() { - return this.underlyingType().asClassDoc(); - } - - @Override - public TypeVariable asTypeVariable() { - return this.underlyingType().asTypeVariable(); - } - - @Override - public WildcardType asWildcardType() { - return this.underlyingType().asWildcardType(); - } - - @Override - public ParameterizedType asParameterizedType() { - return this.underlyingType().asParameterizedType(); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationDescImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationDescImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.tools.javac.code.Attribute; -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.Pair; - - -/** - * Represents an annotation. - * An annotation associates a value with each element of an annotation type. - * Sure it ought to be called "Annotation", but that clashes with - * java.lang.annotation.Annotation. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Scott Seligman - * @since 1.5 - */ - -public class AnnotationDescImpl implements AnnotationDesc { - - private final DocEnv env; - private final Attribute.Compound annotation; - - - AnnotationDescImpl(DocEnv env, Attribute.Compound annotation) { - this.env = env; - this.annotation = annotation; - } - - /** - * Returns the annotation type of this annotation. - */ - public AnnotationTypeDoc annotationType() { - ClassSymbol atsym = (ClassSymbol)annotation.type.tsym; - if (annotation.type.isErroneous()) { - env.warning(null, "javadoc.class_not_found", annotation.type.toString()); - return new AnnotationTypeDocImpl(env, atsym); - } else { - return (AnnotationTypeDoc)env.getClassDoc(atsym); - } - } - - /** - * Returns this annotation's elements and their values. - * Only those explicitly present in the annotation are - * included, not those assuming their default values. - * Returns an empty array if there are none. - */ - public ElementValuePair[] elementValues() { - List> vals = annotation.values; - ElementValuePair res[] = new ElementValuePair[vals.length()]; - int i = 0; - for (Pair val : vals) { - res[i++] = new ElementValuePairImpl(env, val.fst, val.snd); - } - return res; - } - - /** - * Check for the synthesized bit on the annotation. - * - * @return true if the annotation is synthesized. - */ - public boolean isSynthesized() { - return annotation.isSynthesized(); - } - - /** - * Returns a string representation of this annotation. - * String is of one of the forms: - *

-     *     {@code @com.example.foo(name1=val1, name2=val2)}
-     *     {@code @com.example.foo(val)}
-     *     {@code @com.example.foo}
-     * 
- * Omit parens for marker annotations, and omit "value=" when allowed. - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder("@"); - sb.append(annotation.type.tsym); - - ElementValuePair vals[] = elementValues(); - if (vals.length > 0) { // omit parens for marker annotation - sb.append('('); - boolean first = true; - for (ElementValuePair val : vals) { - if (!first) { - sb.append(", "); - } - first = false; - - String name = val.element().name(); - if (vals.length == 1 && name.equals("value")) { - sb.append(val.value()); - } else { - sb.append(val); - } - } - sb.append(')'); - } - return sb.toString(); - } - - - /** - * Represents an association between an annotation type element - * and one of its values. - */ - public static class ElementValuePairImpl implements ElementValuePair { - - private final DocEnv env; - private final MethodSymbol meth; - private final Attribute value; - - ElementValuePairImpl(DocEnv env, MethodSymbol meth, Attribute value) { - this.env = env; - this.meth = meth; - this.value = value; - } - - /** - * Returns the annotation type element. - */ - public AnnotationTypeElementDoc element() { - return env.getAnnotationTypeElementDoc(meth); - } - - /** - * Returns the value associated with the annotation type element. - */ - public AnnotationValue value() { - return new AnnotationValueImpl(env, value); - } - - /** - * Returns a string representation of this pair - * of the form "name=value". - */ - @Override - public String toString() { - return meth.name + "=" + value(); - } - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationTypeDocImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.util.List; - -import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; - -import static com.sun.tools.javac.code.Kinds.Kind.*; - -/** - * Represents an annotation type. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Scott Seligman - * @since 1.5 - */ - -public class AnnotationTypeDocImpl - extends ClassDocImpl implements AnnotationTypeDoc { - - public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym) { - this(env, sym, null); - } - - public AnnotationTypeDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - /** - * Returns true, as this is an annotation type. - * (For legacy doclets, return false.) - */ - public boolean isAnnotationType() { - return !isInterface(); - } - - /** - * Returns false. Though technically an interface, an annotation - * type is not considered an interface for this purpose. - * (For legacy doclets, returns true.) - */ - public boolean isInterface() { - return env.legacyDoclet; - } - - /** - * Returns an empty array, as all methods are annotation type elements. - * (For legacy doclets, returns the elements.) - * @see #elements() - */ - public MethodDoc[] methods(boolean filter) { - return env.legacyDoclet - ? (MethodDoc[])elements() - : new MethodDoc[0]; - } - - /** - * Returns the elements of this annotation type. - * Returns an empty array if there are none. - * Elements are always public, so no need to filter them. - */ - public AnnotationTypeElementDoc[] elements() { - List elements = List.nil(); - for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null && sym.kind == MTH) { - MethodSymbol s = (MethodSymbol)sym; - elements = elements.prepend(env.getAnnotationTypeElementDoc(s)); - } - } - return - elements.toArray(new AnnotationTypeElementDoc[elements.length()]); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationTypeElementDocImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Symbol.*; - -/** - * Represents an element of an annotation type. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Scott Seligman - * @since 1.5 - */ - -public class AnnotationTypeElementDocImpl - extends MethodDocImpl implements AnnotationTypeElementDoc { - - public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym) { - super(env, sym); - } - - public AnnotationTypeElementDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - /** - * Returns true, as this is an annotation type element. - * (For legacy doclets, return false.) - */ - public boolean isAnnotationTypeElement() { - return !isMethod(); - } - - /** - * Returns false. Although this is technically a method, we don't - * consider it one for this purpose. - * (For legacy doclets, return true.) - */ - public boolean isMethod() { - return env.legacyDoclet; - } - - /** - * Returns false, even though this is indeed abstract. See - * MethodDocImpl.isAbstract() for the (il)logic behind this. - */ - public boolean isAbstract() { - return false; - } - - /** - * Returns the default value of this element. - * Returns null if this element has no default. - */ - public AnnotationValue defaultValue() { - return (sym.defaultValue == null) - ? null - : new AnnotationValueImpl(env, sym.defaultValue); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/AnnotationValueImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.tools.javac.code.Attribute; - -import static com.sun.tools.javac.code.TypeTag.BOOLEAN; - -/** - * Represents a value of an annotation type element. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Scott Seligman - * @since 1.5 - */ - -public class AnnotationValueImpl implements AnnotationValue { - - private final DocEnv env; - private final Attribute attr; - - - AnnotationValueImpl(DocEnv env, Attribute attr) { - this.env = env; - this.attr = attr; - } - - /** - * Returns the value. - * The type of the returned object is one of the following: - *

- */ - public Object value() { - ValueVisitor vv = new ValueVisitor(); - attr.accept(vv); - return vv.value; - } - - private class ValueVisitor implements Attribute.Visitor { - public Object value; - - public void visitConstant(Attribute.Constant c) { - if (c.type.hasTag(BOOLEAN)) { - // javac represents false and true as integers 0 and 1 - value = Boolean.valueOf( - ((Integer)c.value).intValue() != 0); - } else { - value = c.value; - } - } - - public void visitClass(Attribute.Class c) { - value = TypeMaker.getType(env, - env.types.erasure(c.classType)); - } - - public void visitEnum(Attribute.Enum e) { - value = env.getFieldDoc(e.value); - } - - public void visitCompound(Attribute.Compound c) { - value = new AnnotationDescImpl(env, c); - } - - public void visitArray(Attribute.Array a) { - AnnotationValue vals[] = new AnnotationValue[a.values.length]; - for (int i = 0; i < vals.length; i++) { - vals[i] = new AnnotationValueImpl(env, a.values[i]); - } - value = vals; - } - - public void visitError(Attribute.Error e) { - value = ""; - } - } - - /** - * Returns a string representation of the value. - * - * @return the text of a Java language annotation value expression - * whose value is the value of this annotation type element. - */ - @Override - public String toString() { - ToStringVisitor tv = new ToStringVisitor(); - attr.accept(tv); - return tv.toString(); - } - - private class ToStringVisitor implements Attribute.Visitor { - private final StringBuilder sb = new StringBuilder(); - - @Override - public String toString() { - return sb.toString(); - } - - public void visitConstant(Attribute.Constant c) { - if (c.type.hasTag(BOOLEAN)) { - // javac represents false and true as integers 0 and 1 - sb.append(((Integer)c.value).intValue() != 0); - } else { - sb.append(FieldDocImpl.constantValueExpression(c.value)); - } - } - - public void visitClass(Attribute.Class c) { - sb.append(c); - } - - public void visitEnum(Attribute.Enum e) { - sb.append(e); - } - - public void visitCompound(Attribute.Compound c) { - sb.append(new AnnotationDescImpl(env, c)); - } - - public void visitArray(Attribute.Array a) { - // Omit braces from singleton. - if (a.values.length != 1) sb.append('{'); - - boolean first = true; - for (Attribute elem : a.values) { - if (first) { - first = false; - } else { - sb.append(", "); - } - elem.accept(this); - } - // Omit braces from singleton. - if (a.values.length != 1) sb.append('}'); - } - - public void visitError(Attribute.Error e) { - sb.append(""); - } - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ClassDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ClassDocImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1329 +0,0 @@ -/* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Modifier; -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import javax.tools.FileObject; -import javax.tools.JavaFileManager.Location; -import javax.tools.StandardJavaFileManager; -import javax.tools.StandardLocation; - -import com.sun.javadoc.*; -import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Kinds.KindSelector; -import com.sun.tools.javac.code.Scope; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.Type.ClassType; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.comp.AttrContext; -import com.sun.tools.javac.comp.Env; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.JCTree.JCFieldAccess; -import com.sun.tools.javac.tree.JCTree.JCImport; -import com.sun.tools.javac.tree.TreeInfo; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.ListBuffer; -import com.sun.tools.javac.util.Name; -import com.sun.tools.javac.util.Names; -import com.sun.tools.javac.util.Position; -import static com.sun.tools.javac.code.Kinds.Kind.*; -import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; -import static com.sun.tools.javac.code.TypeTag.CLASS; -import static com.sun.tools.javac.tree.JCTree.Tag.*; - -/** - * Represents a java class and provides access to information - * about the class, the class' comment and tags, and the - * members of the class. A ClassDocImpl only exists if it was - * processed in this run of javadoc. References to classes - * which may or may not have been processed in this run are - * referred to using Type (which can be converted to ClassDocImpl, - * if possible). - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @see Type - * - * @since 1.2 - * @author Robert Field - * @author Neal Gafter (rewrite) - * @author Scott Seligman (generics, enums, annotations) - */ - -public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { - - public final ClassType type; // protected->public for debugging - public final ClassSymbol tsym; - - boolean isIncluded = false; // Set in RootDocImpl - - private SerializedForm serializedForm; - - /** - * Constructor - */ - public ClassDocImpl(DocEnv env, ClassSymbol sym) { - this(env, sym, null); - } - - /** - * Constructor - */ - public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) { - super(env, sym, treePath); - this.type = (ClassType)sym.type; - this.tsym = sym; - } - - public com.sun.javadoc.Type getElementType() { - return null; - } - - /** - * Returns the flags in terms of javac's flags - */ - protected long getFlags() { - return getFlags(tsym); - } - - /** - * Returns the flags of a ClassSymbol in terms of javac's flags - */ - static long getFlags(ClassSymbol clazz) { - try { - return clazz.flags(); - } catch (CompletionFailure ex) { - /* Quietly ignore completion failures and try again - the type - * for which the CompletionFailure was thrown shouldn't be completed - * again by the completer that threw the CompletionFailure. - */ - return getFlags(clazz); - } - } - - /** - * Is a ClassSymbol an annotation type? - */ - static boolean isAnnotationType(ClassSymbol clazz) { - return (getFlags(clazz) & Flags.ANNOTATION) != 0; - } - - /** - * Identify the containing class - */ - protected ClassSymbol getContainingClass() { - return tsym.owner.enclClass(); - } - - /** - * Return true if this is a class, not an interface. - */ - @Override - public boolean isClass() { - return !Modifier.isInterface(getModifiers()); - } - - /** - * Return true if this is a ordinary class, - * not an enumeration, exception, an error, or an interface. - */ - @Override - public boolean isOrdinaryClass() { - if (isEnum() || isInterface() || isAnnotationType()) { - return false; - } - for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { - if (t.tsym == env.syms.errorType.tsym || - t.tsym == env.syms.exceptionType.tsym) { - return false; - } - } - return true; - } - - /** - * Return true if this is an enumeration. - * (For legacy doclets, return false.) - */ - @Override - public boolean isEnum() { - return (getFlags() & Flags.ENUM) != 0 - && - !env.legacyDoclet; - } - - /** - * Return true if this is an interface, but not an annotation type. - * Overridden by AnnotationTypeDocImpl. - */ - @Override - public boolean isInterface() { - return Modifier.isInterface(getModifiers()); - } - - /** - * Return true if this is an exception class - */ - @Override - public boolean isException() { - if (isEnum() || isInterface() || isAnnotationType()) { - return false; - } - for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { - if (t.tsym == env.syms.exceptionType.tsym) { - return true; - } - } - return false; - } - - /** - * Return true if this is an error class - */ - @Override - public boolean isError() { - if (isEnum() || isInterface() || isAnnotationType()) { - return false; - } - for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { - if (t.tsym == env.syms.errorType.tsym) { - return true; - } - } - return false; - } - - /** - * Return true if this is a throwable class - */ - public boolean isThrowable() { - if (isEnum() || isInterface() || isAnnotationType()) { - return false; - } - for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) { - if (t.tsym == env.syms.throwableType.tsym) { - return true; - } - } - return false; - } - - /** - * Return true if this class is abstract - */ - public boolean isAbstract() { - return Modifier.isAbstract(getModifiers()); - } - - /** - * Returns true if this class was synthesized by the compiler. - */ - public boolean isSynthetic() { - return (getFlags() & Flags.SYNTHETIC) != 0; - } - - /** - * Return true if this class is included in the active set. - * A ClassDoc is included iff either it is specified on the - * commandline, or if it's containing package is specified - * on the command line, or if it is a member class of an - * included class. - */ - - public boolean isIncluded() { - if (isIncluded) { - return true; - } - if (env.shouldDocument(tsym)) { - // Class is nameable from top-level and - // the class and all enclosing classes - // pass the modifier filter. - if (containingPackage().isIncluded()) { - return isIncluded=true; - } - ClassDoc outer = containingClass(); - if (outer != null && outer.isIncluded()) { - return isIncluded=true; - } - } - return false; - } - - /** - * Return the package that this class is contained in. - */ - @Override - public PackageDoc containingPackage() { - PackageDocImpl p = env.getPackageDoc(tsym.packge()); - if (p.setDocPath == false) { - FileObject docPath; - try { - Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH) - ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; - - docPath = env.fileManager.getFileForInput( - location, p.qualifiedName(), "package.html"); - } catch (IOException e) { - docPath = null; - } - - if (docPath == null) { - // fall back on older semantics of looking in same directory as - // source file for this class - SourcePosition po = position(); - if (env.fileManager instanceof StandardJavaFileManager && - po instanceof SourcePositionImpl) { - URI uri = ((SourcePositionImpl) po).filename.toUri(); - if ("file".equals(uri.getScheme())) { - File f = new File(uri); - File dir = f.getParentFile(); - if (dir != null) { - File pf = new File(dir, "package.html"); - if (pf.exists()) { - StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager; - docPath = sfm.getJavaFileObjects(pf).iterator().next(); - } - } - - } - } - } - - p.setDocPath(docPath); - } - return p; - } - - /** - * Return the class name without package qualifier - but with - * enclosing class qualifier - as a String. - *

-     * Examples:
-     *  for java.util.Hashtable
-     *  return Hashtable
-     *  for java.util.Map.Entry
-     *  return Map.Entry
-     * 
- */ - public String name() { - if (name == null) { - name = getClassName(tsym, false); - } - return name; - } - - private String name; - - /** - * Return the qualified class name as a String. - *
-     * Example:
-     *  for java.util.Hashtable
-     *  return java.util.Hashtable
-     *  if no qualifier, just return flat name
-     * 
- */ - public String qualifiedName() { - if (qualifiedName == null) { - qualifiedName = getClassName(tsym, true); - } - return qualifiedName; - } - - private String qualifiedName; - - /** - * Return unqualified name of type excluding any dimension information. - *

- * For example, a two dimensional array of String returns 'String'. - */ - public String typeName() { - return name(); - } - - /** - * Return qualified name of type excluding any dimension information. - *

- * For example, a two dimensional array of String - * returns 'java.lang.String'. - */ - public String qualifiedTypeName() { - return qualifiedName(); - } - - /** - * Return the simple name of this type. - */ - public String simpleTypeName() { - if (simpleTypeName == null) { - simpleTypeName = tsym.name.toString(); - } - return simpleTypeName; - } - - private String simpleTypeName; - - /** - * Return the qualified name and any type parameters. - * Each parameter is a type variable with optional bounds. - */ - @Override - public String toString() { - return classToString(env, tsym, true); - } - - /** - * Return the class name as a string. If "full" is true the name is - * qualified, otherwise it is qualified by its enclosing class(es) only. - */ - static String getClassName(ClassSymbol c, boolean full) { - if (full) { - return c.getQualifiedName().toString(); - } else { - String n = ""; - for ( ; c != null; c = c.owner.enclClass()) { - n = c.name + (n.equals("") ? "" : ".") + n; - } - return n; - } - } - - /** - * Return the class name with any type parameters as a string. - * Each parameter is a type variable with optional bounds. - * If "full" is true all names are qualified, otherwise they are - * qualified by their enclosing class(es) only. - */ - static String classToString(DocEnv env, ClassSymbol c, boolean full) { - StringBuilder s = new StringBuilder(); - if (!c.isInner()) { // if c is not an inner class - s.append(getClassName(c, full)); - } else { - // c is an inner class, so include type params of outer. - ClassSymbol encl = c.owner.enclClass(); - s.append(classToString(env, encl, full)) - .append('.') - .append(c.name); - } - s.append(TypeMaker.typeParametersString(env, c, full)); - return s.toString(); - } - - /** - * Is this class (or any enclosing class) generic? That is, does - * it have type parameters? - */ - static boolean isGeneric(ClassSymbol c) { - return c.type.allparams().nonEmpty(); - } - - /** - * Return the formal type parameters of this class or interface. - * Return an empty array if there are none. - */ - public TypeVariable[] typeParameters() { - if (env.legacyDoclet) { - return new TypeVariable[0]; - } - TypeVariable res[] = new TypeVariable[type.getTypeArguments().length()]; - TypeMaker.getTypes(env, type.getTypeArguments(), res); - return res; - } - - /** - * Return the type parameter tags of this class or interface. - */ - public ParamTag[] typeParamTags() { - return (env.legacyDoclet) - ? new ParamTag[0] - : comment().typeParamTags(); - } - - /** - * Return the modifier string for this class. If it's an interface - * exclude 'abstract' keyword from the modifier string - */ - @Override - public String modifiers() { - return Modifier.toString(modifierSpecifier()); - } - - @Override - public int modifierSpecifier() { - int modifiers = getModifiers(); - return (isInterface() || isAnnotationType()) - ? modifiers & ~Modifier.ABSTRACT - : modifiers; - } - - /** - * Return the superclass of this class - * - * @return the ClassDocImpl for the superclass of this class, null - * if there is no superclass. - */ - public ClassDoc superclass() { - if (isInterface() || isAnnotationType()) return null; - if (tsym == env.syms.objectType.tsym) return null; - ClassSymbol c = (ClassSymbol)env.types.supertype(type).tsym; - if (c == null || c == tsym) c = (ClassSymbol)env.syms.objectType.tsym; - return env.getClassDoc(c); - } - - /** - * Return the superclass of this class. Return null if this is an - * interface. A superclass is represented by either a - * ClassDoc or a ParameterizedType. - */ - public com.sun.javadoc.Type superclassType() { - if (isInterface() || isAnnotationType() || - (tsym == env.syms.objectType.tsym)) - return null; - Type sup = env.types.supertype(type); - return TypeMaker.getType(env, - (sup.hasTag(TypeTag.NONE)) ? env.syms.objectType : sup); - } - - /** - * Test whether this class is a subclass of the specified class. - * - * @param cd the candidate superclass. - * @return true if cd is a superclass of this class. - */ - public boolean subclassOf(ClassDoc cd) { - return tsym.isSubClass(((ClassDocImpl)cd).tsym, env.types); - } - - /** - * Return interfaces implemented by this class or interfaces - * extended by this interface. - * - * @return An array of ClassDocImpl representing the interfaces. - * Return an empty array if there are no interfaces. - */ - public ClassDoc[] interfaces() { - ListBuffer ta = new ListBuffer<>(); - for (Type t : env.types.interfaces(type)) { - ta.append(env.getClassDoc((ClassSymbol)t.tsym)); - } - //### Cache ta here? - return ta.toArray(new ClassDocImpl[ta.length()]); - } - - /** - * Return interfaces implemented by this class or interfaces extended - * by this interface. Includes only directly-declared interfaces, not - * inherited interfaces. - * Return an empty array if there are no interfaces. - */ - public com.sun.javadoc.Type[] interfaceTypes() { - //### Cache result here? - return TypeMaker.getTypes(env, env.types.interfaces(type)); - } - - /** - * Return fields in class. - * @param filter include only the included fields if filter==true - */ - public FieldDoc[] fields(boolean filter) { - return fields(filter, false); - } - - /** - * Return included fields in class. - */ - public FieldDoc[] fields() { - return fields(true, false); - } - - /** - * Return the enum constants if this is an enum type. - */ - public FieldDoc[] enumConstants() { - return fields(false, true); - } - - /** - * Return fields in class. - * @param filter if true, return only the included fields - * @param enumConstants if true, return the enum constants instead - */ - private FieldDoc[] fields(boolean filter, boolean enumConstants) { - List fields = List.nil(); - for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null && sym.kind == VAR) { - VarSymbol s = (VarSymbol)sym; - boolean isEnum = ((s.flags() & Flags.ENUM) != 0) && - !env.legacyDoclet; - if (isEnum == enumConstants && - (!filter || env.shouldDocument(s))) { - fields = fields.prepend(env.getFieldDoc(s)); - } - } - } - return fields.toArray(new FieldDocImpl[fields.length()]); - } - - /** - * Return methods in class. - * This method is overridden by AnnotationTypeDocImpl. - * - * @param filter include only the included methods if filter==true - * @return an array of MethodDocImpl for representing the visible - * methods in this class. Does not include constructors. - */ - public MethodDoc[] methods(boolean filter) { - Names names = tsym.name.table.names; - List methods = List.nil(); - for (Symbol sym :tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null - && sym.kind == MTH - && sym.name != names.init - && sym.name != names.clinit) { - MethodSymbol s = (MethodSymbol)sym; - if (!filter || env.shouldDocument(s)) { - methods = methods.prepend(env.getMethodDoc(s)); - } - } - } - //### Cache methods here? - return methods.toArray(new MethodDocImpl[methods.length()]); - } - - /** - * Return included methods in class. - * - * @return an array of MethodDocImpl for representing the visible - * methods in this class. Does not include constructors. - */ - public MethodDoc[] methods() { - return methods(true); - } - - /** - * Return constructors in class. - * - * @param filter include only the included constructors if filter==true - * @return an array of ConstructorDocImpl for representing the visible - * constructors in this class. - */ - public ConstructorDoc[] constructors(boolean filter) { - Names names = tsym.name.table.names; - List constructors = List.nil(); - for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null && - sym.kind == MTH && sym.name == names.init) { - MethodSymbol s = (MethodSymbol)sym; - if (!filter || env.shouldDocument(s)) { - constructors = constructors.prepend(env.getConstructorDoc(s)); - } - } - } - //### Cache constructors here? - return constructors.toArray(new ConstructorDocImpl[constructors.length()]); - } - - /** - * Return included constructors in class. - * - * @return an array of ConstructorDocImpl for representing the visible - * constructors in this class. - */ - public ConstructorDoc[] constructors() { - return constructors(true); - } - - /** - * Adds all inner classes of this class, and their - * inner classes recursively, to the list l. - */ - void addAllClasses(ListBuffer l, boolean filtered) { - try { - if (isSynthetic()) return; - // sometimes synthetic classes are not marked synthetic - if (!JavadocTool.isValidClassName(tsym.name.toString())) return; - if (filtered && !env.shouldDocument(tsym)) return; - if (l.contains(this)) return; - l.append(this); - List more = List.nil(); - for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null && sym.kind == TYP) { - ClassSymbol s = (ClassSymbol)sym; - ClassDocImpl c = env.getClassDoc(s); - if (c.isSynthetic()) continue; - if (c != null) more = more.prepend(c); - } - } - // this extra step preserves the ordering from oldjavadoc - for (; more.nonEmpty(); more=more.tail) { - more.head.addAllClasses(l, filtered); - } - } catch (CompletionFailure e) { - // quietly ignore completion failures - } - } - - /** - * Return inner classes within this class. - * - * @param filter include only the included inner classes if filter==true. - * @return an array of ClassDocImpl for representing the visible - * classes defined in this class. Anonymous and local classes - * are not included. - */ - public ClassDoc[] innerClasses(boolean filter) { - ListBuffer innerClasses = new ListBuffer<>(); - for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) { - if (sym != null && sym.kind == TYP) { - ClassSymbol s = (ClassSymbol)sym; - if ((s.flags_field & Flags.SYNTHETIC) != 0) continue; - if (!filter || env.isVisible(s)) { - innerClasses.prepend(env.getClassDoc(s)); - } - } - } - //### Cache classes here? - return innerClasses.toArray(new ClassDocImpl[innerClasses.length()]); - } - - /** - * Return included inner classes within this class. - * - * @return an array of ClassDocImpl for representing the visible - * classes defined in this class. Anonymous and local classes - * are not included. - */ - public ClassDoc[] innerClasses() { - return innerClasses(true); - } - - /** - * Find a class within the context of this class. - * Search order: qualified name, in this class (inner), - * in this package, in the class imports, in the package - * imports. - * Return the ClassDocImpl if found, null if not found. - */ - //### The specified search order is not the normal rule the - //### compiler would use. Leave as specified or change it? - public ClassDoc findClass(String className) { - ClassDoc searchResult = searchClass(className); - if (searchResult == null) { - ClassDocImpl enclosingClass = (ClassDocImpl)containingClass(); - //Expand search space to include enclosing class. - while (enclosingClass != null && enclosingClass.containingClass() != null) { - enclosingClass = (ClassDocImpl)enclosingClass.containingClass(); - } - searchResult = enclosingClass == null ? - null : enclosingClass.searchClass(className); - } - return searchResult; - } - - private ClassDoc searchClass(String className) { - Names names = tsym.name.table.names; - - // search by qualified name first - ClassDoc cd = env.lookupClass(className); - if (cd != null) { - return cd; - } - - // search inner classes - //### Add private entry point to avoid creating array? - //### Replicate code in innerClasses here to avoid consing? - for (ClassDoc icd : innerClasses()) { - if (icd.name().equals(className) || - //### This is from original javadoc but it looks suspicious to me... - //### I believe it is attempting to compensate for the confused - //### convention of including the nested class qualifiers in the - //### 'name' of the inner class, rather than the true simple name. - icd.name().endsWith("." + className)) { - return icd; - } else { - ClassDoc innercd = ((ClassDocImpl) icd).searchClass(className); - if (innercd != null) { - return innercd; - } - } - } - - // check in this package - cd = containingPackage().findClass(className); - if (cd != null) { - return cd; - } - - // make sure that this symbol has been completed - tsym.complete(); - - // search imports - - if (tsym.sourcefile != null) { - - //### This information is available only for source classes. - - Env compenv = env.enter.getEnv(tsym); - if (compenv == null) return null; - - Scope s = compenv.toplevel.namedImportScope; - for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { - if (sym.kind == TYP) { - ClassDoc c = env.getClassDoc((ClassSymbol)sym); - return c; - } - } - - s = compenv.toplevel.starImportScope; - for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { - if (sym.kind == TYP) { - ClassDoc c = env.getClassDoc((ClassSymbol)sym); - return c; - } - } - } - - return null; // not found - } - - - private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) { - - if (argTypes == null) { - // wildcard - return true; - } - - int i = 0; - List types = method.type.getParameterTypes(); - - if (argTypes.length != types.length()) { - return false; - } - - for (Type t : types) { - String argType = argTypes[i++]; - // For vararg method, "T..." matches type T[]. - if (i == argTypes.length) { - argType = argType.replace("...", "[]"); - } - if (!hasTypeName(env.types.erasure(t), argType)) { //###(gj) - return false; - } - } - return true; - } - // where - private boolean hasTypeName(Type t, String name) { - return - name.equals(TypeMaker.getTypeName(t, true)) - || - name.equals(TypeMaker.getTypeName(t, false)) - || - (qualifiedName() + "." + name).equals(TypeMaker.getTypeName(t, true)); - } - - - - /** - * Find a method in this class scope. - * Search order: this class, interfaces, superclasses, outerclasses. - * Note that this is not necessarily what the compiler would do! - * - * @param methodName the unqualified name to search for. - * @param paramTypes the array of Strings for method parameter types. - * @return the first MethodDocImpl which matches, null if not found. - */ - public MethodDocImpl findMethod(String methodName, String[] paramTypes) { - // Use hash table 'searched' to avoid searching same class twice. - //### It is not clear how this could happen. - return searchMethod(methodName, paramTypes, new HashSet()); - } - - private MethodDocImpl searchMethod(String methodName, - String[] paramTypes, Set searched) { - //### Note that this search is not necessarily what the compiler would do! - - Names names = tsym.name.table.names; - // do not match constructors - if (names.init.contentEquals(methodName)) { - return null; - } - - ClassDocImpl cdi; - MethodDocImpl mdi; - - if (searched.contains(this)) { - return null; - } - searched.add(this); - - //DEBUG - /*---------------------------------* - System.out.print("searching " + this + " for " + methodName); - if (paramTypes == null) { - System.out.println("()"); - } else { - System.out.print("("); - for (int k=0; k < paramTypes.length; k++) { - System.out.print(paramTypes[k]); - if ((k + 1) < paramTypes.length) { - System.out.print(", "); - } - } - System.out.println(")"); - } - *---------------------------------*/ - - // search current class - - //### Using modifier filter here isn't really correct, - //### but emulates the old behavior. Instead, we should - //### apply the normal rules of visibility and inheritance. - - if (paramTypes == null) { - // If no parameters specified, we are allowed to return - // any method with a matching name. In practice, the old - // code returned the first method, which is now the last! - // In order to provide textually identical results, we - // attempt to emulate the old behavior. - MethodSymbol lastFound = null; - for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) { - if (sym.kind == MTH) { - //### Should intern methodName as Name. - if (sym.name.toString().equals(methodName)) { - lastFound = (MethodSymbol)sym; - } - } - } - if (lastFound != null) { - return env.getMethodDoc(lastFound); - } - } else { - for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) { - if (sym != null && - sym.kind == MTH) { - //### Should intern methodName as Name. - if (hasParameterTypes((MethodSymbol)sym, paramTypes)) { - return env.getMethodDoc((MethodSymbol)sym); - } - } - } - } - - //### If we found a MethodDoc above, but which did not pass - //### the modifier filter, we should return failure here! - - // search superclass - cdi = (ClassDocImpl)superclass(); - if (cdi != null) { - mdi = cdi.searchMethod(methodName, paramTypes, searched); - if (mdi != null) { - return mdi; - } - } - - // search interfaces - for (ClassDoc intf : interfaces()) { - cdi = (ClassDocImpl) intf; - mdi = cdi.searchMethod(methodName, paramTypes, searched); - if (mdi != null) { - return mdi; - } - } - - // search enclosing class - cdi = (ClassDocImpl)containingClass(); - if (cdi != null) { - mdi = cdi.searchMethod(methodName, paramTypes, searched); - if (mdi != null) { - return mdi; - } - } - - //###(gj) As a temporary measure until type variables are better - //### handled, try again without the parameter types. - //### This should most often find the right method, and occassionally - //### find the wrong one. - //if (paramTypes != null) { - // return findMethod(methodName, null); - //} - - return null; - } - - /** - * Find constructor in this class. - * - * @param constrName the unqualified name to search for. - * @param paramTypes the array of Strings for constructor parameters. - * @return the first ConstructorDocImpl which matches, null if not found. - */ - public ConstructorDoc findConstructor(String constrName, - String[] paramTypes) { - Names names = tsym.name.table.names; - for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(""))) { - if (sym.kind == MTH) { - if (hasParameterTypes((MethodSymbol)sym, paramTypes)) { - return env.getConstructorDoc((MethodSymbol)sym); - } - } - } - - //###(gj) As a temporary measure until type variables are better - //### handled, try again without the parameter types. - //### This will often find the right constructor, and occassionally - //### find the wrong one. - //if (paramTypes != null) { - // return findConstructor(constrName, null); - //} - - return null; - } - - /** - * Find a field in this class scope. - * Search order: this class, outerclasses, interfaces, - * superclasses. IMP: If see tag is defined in an inner class, - * which extends a super class and if outerclass and the super - * class have a visible field in common then Java compiler cribs - * about the ambiguity, but the following code will search in the - * above given search order. - * - * @param fieldName the unqualified name to search for. - * @return the first FieldDocImpl which matches, null if not found. - */ - public FieldDoc findField(String fieldName) { - return searchField(fieldName, new HashSet()); - } - - private FieldDocImpl searchField(String fieldName, Set searched) { - Names names = tsym.name.table.names; - if (searched.contains(this)) { - return null; - } - searched.add(this); - - for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(fieldName))) { - if (sym.kind == VAR) { - //### Should intern fieldName as Name. - return env.getFieldDoc((VarSymbol)sym); - } - } - - //### If we found a FieldDoc above, but which did not pass - //### the modifier filter, we should return failure here! - - ClassDocImpl cdi = (ClassDocImpl)containingClass(); - if (cdi != null) { - FieldDocImpl fdi = cdi.searchField(fieldName, searched); - if (fdi != null) { - return fdi; - } - } - - // search superclass - cdi = (ClassDocImpl)superclass(); - if (cdi != null) { - FieldDocImpl fdi = cdi.searchField(fieldName, searched); - if (fdi != null) { - return fdi; - } - } - - // search interfaces - for (ClassDoc intf : interfaces()) { - cdi = (ClassDocImpl) intf; - FieldDocImpl fdi = cdi.searchField(fieldName, searched); - if (fdi != null) { - return fdi; - } - } - - return null; - } - - /** - * Get the list of classes declared as imported. - * These are called "single-type-import declarations" in the JLS. - * This method is deprecated in the ClassDoc interface. - * - * @return an array of ClassDocImpl representing the imported classes. - * - * @deprecated Import declarations are implementation details that - * should not be exposed here. In addition, not all imported - * classes are imported through single-type-import declarations. - */ - @Deprecated - public ClassDoc[] importedClasses() { - // information is not available for binary classfiles - if (tsym.sourcefile == null) return new ClassDoc[0]; - - ListBuffer importedClasses = new ListBuffer<>(); - - Env compenv = env.enter.getEnv(tsym); - if (compenv == null) return new ClassDocImpl[0]; - - Name asterisk = tsym.name.table.names.asterisk; - for (JCTree t : compenv.toplevel.defs) { - if (t.hasTag(IMPORT)) { - JCTree imp = ((JCImport) t).qualid; - if ((TreeInfo.name(imp) != asterisk) && - imp.type.tsym.kind.matches(KindSelector.TYP)) { - importedClasses.append( - env.getClassDoc((ClassSymbol)imp.type.tsym)); - } - } - } - - return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]); - } - - /** - * Get the list of packages declared as imported. - * These are called "type-import-on-demand declarations" in the JLS. - * This method is deprecated in the ClassDoc interface. - * - * @return an array of PackageDocImpl representing the imported packages. - * - * ###NOTE: the syntax supports importing all inner classes from a class as well. - * @deprecated Import declarations are implementation details that - * should not be exposed here. In addition, this method's - * return type does not allow for all type-import-on-demand - * declarations to be returned. - */ - @Deprecated - public PackageDoc[] importedPackages() { - // information is not available for binary classfiles - if (tsym.sourcefile == null) return new PackageDoc[0]; - - ListBuffer importedPackages = new ListBuffer<>(); - - //### Add the implicit "import java.lang.*" to the result - Names names = tsym.name.table.names; - importedPackages.append(env.getPackageDoc(env.syms.enterPackage(env.syms.java_base, names.java_lang))); - - Env compenv = env.enter.getEnv(tsym); - if (compenv == null) return new PackageDocImpl[0]; - - for (JCTree t : compenv.toplevel.defs) { - if (t.hasTag(IMPORT)) { - JCTree imp = ((JCImport) t).qualid; - if (TreeInfo.name(imp) == names.asterisk) { - JCFieldAccess sel = (JCFieldAccess)imp; - Symbol s = sel.selected.type.tsym; - PackageDocImpl pdoc = env.getPackageDoc(s.packge()); - if (!importedPackages.contains(pdoc)) - importedPackages.append(pdoc); - } - } - } - - return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]); - } - - /** - * Return the type's dimension information. - * Always return "", as this is not an array type. - */ - public String dimension() { - return ""; - } - - /** - * Return this type as a class, which it already is. - */ - public ClassDoc asClassDoc() { - return this; - } - - /** - * Return null (unless overridden), as this is not an annotation type. - */ - public AnnotationTypeDoc asAnnotationTypeDoc() { - return null; - } - - /** - * Return null, as this is not a class instantiation. - */ - public ParameterizedType asParameterizedType() { - return null; - } - - /** - * Return null, as this is not a type variable. - */ - public TypeVariable asTypeVariable() { - return null; - } - - /** - * Return null, as this is not a wildcard type. - */ - public WildcardType asWildcardType() { - return null; - } - - /** - * Returns null, as this is not an annotated type. - */ - public AnnotatedType asAnnotatedType() { - return null; - } - - /** - * Return false, as this is not a primitive type. - */ - public boolean isPrimitive() { - return false; - } - - //--- Serialization --- - - //### These methods ignore modifier filter. - - /** - * Return true if this class implements java.io.Serializable. - * - * Since java.io.Externalizable extends - * java.io.Serializable, - * Externalizable objects are also Serializable. - */ - public boolean isSerializable() { - try { - return env.types.isSubtype(type, env.syms.serializableType); - } catch (CompletionFailure ex) { - // quietly ignore completion failures - return false; - } - } - - /** - * Return true if this class implements - * java.io.Externalizable. - */ - public boolean isExternalizable() { - try { - return env.types.isSubtype(type, env.externalizableSym.type); - } catch (CompletionFailure ex) { - // quietly ignore completion failures - return false; - } - } - - /** - * Return the serialization methods for this class. - * - * @return an array of MethodDocImpl that represents - * the serialization methods for this class. - */ - public MethodDoc[] serializationMethods() { - if (serializedForm == null) { - serializedForm = new SerializedForm(env, tsym, this); - } - //### Clone this? - return serializedForm.methods(); - } - - /** - * Return the Serializable fields of class.

- * - * Return either a list of default fields documented by - * serial tag
- * or return a single FieldDoc for - * serialPersistentField member. - * There should be a serialField tag for - * each Serializable field defined by an ObjectStreamField - * array component of serialPersistentField. - * - * @return an array of {@code FieldDoc} for the Serializable fields - * of this class. - * - * @see #definesSerializableFields() - * @see SerialFieldTagImpl - */ - public FieldDoc[] serializableFields() { - if (serializedForm == null) { - serializedForm = new SerializedForm(env, tsym, this); - } - //### Clone this? - return serializedForm.fields(); - } - - /** - * Return true if Serializable fields are explicitly defined with - * the special class member serialPersistentFields. - * - * @see #serializableFields() - * @see SerialFieldTagImpl - */ - public boolean definesSerializableFields() { - if (!isSerializable() || isExternalizable()) { - return false; - } else { - if (serializedForm == null) { - serializedForm = new SerializedForm(env, tsym, this); - } - //### Clone this? - return serializedForm.definesSerializableFields(); - } - } - - /** - * Determine if a class is a RuntimeException. - *

- * Used only by ThrowsTagImpl. - */ - boolean isRuntimeException() { - return tsym.isSubClass(env.syms.runtimeExceptionType.tsym, env.types); - } - - /** - * Return the source position of the entity, or null if - * no position is available. - */ - @Override - public SourcePosition position() { - if (tsym.sourcefile == null) return null; - return SourcePositionImpl.make(tsym.sourcefile, - (tree==null) ? Position.NOPOS : tree.pos, - lineMap); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Comment.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Comment.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,460 +0,0 @@ -/* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import com.sun.javadoc.*; -import com.sun.tools.javac.util.ListBuffer; - -/** - * Comment contains all information in comment part. - * It allows users to get first sentence of this comment, get - * comment for different tags... - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @author Kaiyang Liu (original) - * @author Robert Field (rewrite) - * @author Atul M Dambalkar - * @author Neal Gafter (rewrite) - */ -class Comment { - - /** - * sorted comments with different tags. - */ - private final ListBuffer tagList = new ListBuffer<>(); - - /** - * text minus any tags. - */ - private String text; - - /** - * Doc environment - */ - private final DocEnv docenv; - - /** - * constructor of Comment. - */ - Comment(final DocImpl holder, final String commentString) { - this.docenv = holder.env; - - /** - * Separate the comment into the text part and zero to N tags. - * Simple state machine is in one of three states: - *

-         * IN_TEXT: parsing the comment text or tag text.
-         * TAG_NAME: parsing the name of a tag.
-         * TAG_GAP: skipping through the gap between the tag name and
-         * the tag text.
-         * 
- */ - @SuppressWarnings("fallthrough") - class CommentStringParser { - /** - * The entry point to the comment string parser - */ - void parseCommentStateMachine() { - final int IN_TEXT = 1; - final int TAG_GAP = 2; - final int TAG_NAME = 3; - int state = TAG_GAP; - boolean newLine = true; - String tagName = null; - int tagStart = 0; - int textStart = 0; - int lastNonWhite = -1; - int len = commentString.length(); - for (int inx = 0; inx < len; ++inx) { - char ch = commentString.charAt(inx); - boolean isWhite = Character.isWhitespace(ch); - switch (state) { - case TAG_NAME: - if (isWhite) { - tagName = commentString.substring(tagStart, inx); - state = TAG_GAP; - } - break; - case TAG_GAP: - if (isWhite) { - break; - } - textStart = inx; - state = IN_TEXT; - /* fall thru */ - case IN_TEXT: - if (newLine && ch == '@') { - parseCommentComponent(tagName, textStart, - lastNonWhite+1); - tagStart = inx; - state = TAG_NAME; - } - break; - } - if (ch == '\n') { - newLine = true; - } else if (!isWhite) { - lastNonWhite = inx; - newLine = false; - } - } - // Finish what's currently being processed - switch (state) { - case TAG_NAME: - tagName = commentString.substring(tagStart, len); - /* fall thru */ - case TAG_GAP: - textStart = len; - /* fall thru */ - case IN_TEXT: - parseCommentComponent(tagName, textStart, lastNonWhite+1); - break; - } - } - - /** - * Save away the last parsed item. - */ - void parseCommentComponent(String tagName, - int from, int upto) { - String tx = upto <= from ? "" : commentString.substring(from, upto); - if (tagName == null) { - text = tx; - } else { - TagImpl tag; - switch (tagName) { - case "@exception": - case "@throws": - warnIfEmpty(tagName, tx); - tag = new ThrowsTagImpl(holder, tagName, tx); - break; - case "@param": - warnIfEmpty(tagName, tx); - tag = new ParamTagImpl(holder, tagName, tx); - break; - case "@see": - warnIfEmpty(tagName, tx); - tag = new SeeTagImpl(holder, tagName, tx); - break; - case "@serialField": - warnIfEmpty(tagName, tx); - tag = new SerialFieldTagImpl(holder, tagName, tx); - break; - case "@return": - warnIfEmpty(tagName, tx); - tag = new TagImpl(holder, tagName, tx); - break; - case "@author": - warnIfEmpty(tagName, tx); - tag = new TagImpl(holder, tagName, tx); - break; - case "@version": - warnIfEmpty(tagName, tx); - tag = new TagImpl(holder, tagName, tx); - break; - default: - tag = new TagImpl(holder, tagName, tx); - break; - } - tagList.append(tag); - } - } - - void warnIfEmpty(String tagName, String tx) { - if (tx.length() == 0) { - docenv.warning(holder, "tag.tag_has_no_arguments", tagName); - } - } - - } - - new CommentStringParser().parseCommentStateMachine(); - } - - /** - * Return the text of the comment. - */ - String commentText() { - return text; - } - - /** - * Return all tags in this comment. - */ - Tag[] tags() { - return tagList.toArray(new Tag[tagList.length()]); - } - - /** - * Return tags of the specified kind in this comment. - */ - Tag[] tags(String tagname) { - ListBuffer found = new ListBuffer<>(); - String target = tagname; - if (target.charAt(0) != '@') { - target = "@" + target; - } - for (Tag tag : tagList) { - if (tag.kind().equals(target)) { - found.append(tag); - } - } - return found.toArray(new Tag[found.length()]); - } - - /** - * Return throws tags in this comment. - */ - ThrowsTag[] throwsTags() { - ListBuffer found = new ListBuffer<>(); - for (Tag next : tagList) { - if (next instanceof ThrowsTag) { - found.append((ThrowsTag)next); - } - } - return found.toArray(new ThrowsTag[found.length()]); - } - - /** - * Return param tags (excluding type param tags) in this comment. - */ - ParamTag[] paramTags() { - return paramTags(false); - } - - /** - * Return type param tags in this comment. - */ - ParamTag[] typeParamTags() { - return paramTags(true); - } - - /** - * Return param tags in this comment. If typeParams is true - * include only type param tags, otherwise include only ordinary - * param tags. - */ - private ParamTag[] paramTags(boolean typeParams) { - ListBuffer found = new ListBuffer<>(); - for (Tag next : tagList) { - if (next instanceof ParamTag) { - ParamTag p = (ParamTag)next; - if (typeParams == p.isTypeParameter()) { - found.append(p); - } - } - } - return found.toArray(new ParamTag[found.length()]); - } - - /** - * Return see also tags in this comment. - */ - SeeTag[] seeTags() { - ListBuffer found = new ListBuffer<>(); - for (Tag next : tagList) { - if (next instanceof SeeTag) { - found.append((SeeTag)next); - } - } - return found.toArray(new SeeTag[found.length()]); - } - - /** - * Return serialField tags in this comment. - */ - SerialFieldTag[] serialFieldTags() { - ListBuffer found = new ListBuffer<>(); - for (Tag next : tagList) { - if (next instanceof SerialFieldTag) { - found.append((SerialFieldTag)next); - } - } - return found.toArray(new SerialFieldTag[found.length()]); - } - - /** - * Return array of tags with text and inline See Tags for a Doc comment. - */ - static Tag[] getInlineTags(DocImpl holder, String inlinetext) { - ListBuffer taglist = new ListBuffer<>(); - int delimend = 0, textstart = 0, len = inlinetext.length(); - boolean inPre = false; - DocEnv docenv = holder.env; - - if (len == 0) { - return taglist.toArray(new Tag[taglist.length()]); - } - while (true) { - int linkstart; - if ((linkstart = inlineTagFound(holder, inlinetext, - textstart)) == -1) { - taglist.append(new TagImpl(holder, "Text", - inlinetext.substring(textstart))); - break; - } else { - inPre = scanForPre(inlinetext, textstart, linkstart, inPre); - int seetextstart = linkstart; - for (int i = linkstart; i < inlinetext.length(); i++) { - char c = inlinetext.charAt(i); - if (Character.isWhitespace(c) || - c == '}') { - seetextstart = i; - break; - } - } - String linkName = inlinetext.substring(linkstart+2, seetextstart); - if (!(inPre && (linkName.equals("code") || linkName.equals("literal")))) { - //Move past the white space after the inline tag name. - while (Character.isWhitespace(inlinetext. - charAt(seetextstart))) { - if (inlinetext.length() <= seetextstart) { - taglist.append(new TagImpl(holder, "Text", - inlinetext.substring(textstart, seetextstart))); - docenv.warning(holder, - "tag.Improper_Use_Of_Link_Tag", - inlinetext); - return taglist.toArray(new Tag[taglist.length()]); - } else { - seetextstart++; - } - } - } - taglist.append(new TagImpl(holder, "Text", - inlinetext.substring(textstart, linkstart))); - textstart = seetextstart; // this text is actually seetag - if ((delimend = findInlineTagDelim(inlinetext, textstart)) == -1) { - //Missing closing '}' character. - // store the text as it is with the {@link. - taglist.append(new TagImpl(holder, "Text", - inlinetext.substring(textstart))); - docenv.warning(holder, - "tag.End_delimiter_missing_for_possible_SeeTag", - inlinetext); - return taglist.toArray(new Tag[taglist.length()]); - } else { - //Found closing '}' character. - if (linkName.equals("see") - || linkName.equals("link") - || linkName.equals("linkplain")) { - taglist.append( new SeeTagImpl(holder, "@" + linkName, - inlinetext.substring(textstart, delimend))); - } else { - taglist.append( new TagImpl(holder, "@" + linkName, - inlinetext.substring(textstart, delimend))); - } - textstart = delimend + 1; - } - } - if (textstart == inlinetext.length()) { - break; - } - } - return taglist.toArray(new Tag[taglist.length()]); - } - - /** regex for case-insensitive match for {@literal
 } and  {@literal 
}. */ - private static final Pattern prePat = Pattern.compile("(?i)<(/?)pre>"); - - private static boolean scanForPre(String inlinetext, int start, int end, boolean inPre) { - Matcher m = prePat.matcher(inlinetext).region(start, end); - while (m.find()) { - inPre = m.group(1).isEmpty(); - } - return inPre; - } - - /** - * Recursively find the index of the closing '}' character for an inline tag - * and return it. If it can't be found, return -1. - * @param inlineText the text to search in. - * @param searchStart the index of the place to start searching at. - * @return the index of the closing '}' character for an inline tag. - * If it can't be found, return -1. - */ - private static int findInlineTagDelim(String inlineText, int searchStart) { - int delimEnd, nestedOpenBrace; - if ((delimEnd = inlineText.indexOf("}", searchStart)) == -1) { - return -1; - } else if (((nestedOpenBrace = inlineText.indexOf("{", searchStart)) != -1) && - nestedOpenBrace < delimEnd){ - //Found a nested open brace. - int nestedCloseBrace = findInlineTagDelim(inlineText, nestedOpenBrace + 1); - return (nestedCloseBrace != -1) ? - findInlineTagDelim(inlineText, nestedCloseBrace + 1) : - -1; - } else { - return delimEnd; - } - } - - /** - * Recursively search for the characters '{', '@', followed by - * name of inline tag and white space, - * if found - * return the index of the text following the white space. - * else - * return -1. - */ - private static int inlineTagFound(DocImpl holder, String inlinetext, int start) { - DocEnv docenv = holder.env; - int linkstart = inlinetext.indexOf("{@", start); - if (start == inlinetext.length() || linkstart == -1) { - return -1; - } else if (inlinetext.indexOf('}', linkstart) == -1) { - //Missing '}'. - docenv.warning(holder, "tag.Improper_Use_Of_Link_Tag", - inlinetext.substring(linkstart, inlinetext.length())); - return -1; - } else { - return linkstart; - } - } - - - /** - * Return array of tags for the locale specific first sentence in the text. - */ - static Tag[] firstSentenceTags(DocImpl holder, String text) { - DocLocale doclocale = holder.env.doclocale; - return getInlineTags(holder, - doclocale.localeSpecificFirstSentence(holder, text)); - } - - /** - * Return text for this Doc comment. - */ - @Override - public String toString() { - return text; - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ConstructorDocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ConstructorDocImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import com.sun.javadoc.*; - -import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.code.Symbol.MethodSymbol; - -/** - * Represents a constructor of a java class. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @since 1.2 - * @author Robert Field - * @author Neal Gafter (rewrite) - */ - -public class ConstructorDocImpl - extends ExecutableMemberDocImpl implements ConstructorDoc { - - /** - * constructor. - */ - public ConstructorDocImpl(DocEnv env, MethodSymbol sym) { - super(env, sym); - } - - /** - * constructor. - */ - public ConstructorDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) { - super(env, sym, treePath); - } - - /** - * Return true if it is a constructor, which it is. - * - * @return true - */ - public boolean isConstructor() { - return true; - } - - /** - * Get the name. - * - * @return the name of the member. - */ - public String name() { - ClassSymbol c = sym.enclClass(); - return c.name.toString(); - } - - /** - * Get the name. - * - * @return the qualified name of the member. - */ - public String qualifiedName() { - return sym.enclClass().getQualifiedName().toString(); - } - - /** - * Returns a string representation of this constructor. Includes the - * qualified signature and any type parameters. - * Type parameters precede the class name, as they do in the syntax - * for invoking constructors with explicit type parameters using "new". - * (This is unlike the syntax for invoking methods with explicit type - * parameters.) - */ - public String toString() { - return typeParametersString() + qualifiedName() + signature(); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocEnv.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocEnv.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,869 +0,0 @@ -/* - * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import java.lang.reflect.Modifier; -import java.util.*; - -import javax.tools.JavaFileManager; - -import com.sun.javadoc.*; -import com.sun.source.tree.CompilationUnitTree; -import com.sun.source.util.JavacTask; -import com.sun.source.util.TreePath; -import com.sun.tools.doclint.DocLint; -import com.sun.tools.javac.api.BasicJavacTask; -import com.sun.tools.javac.code.*; -import com.sun.tools.javac.code.Symbol.*; -import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.code.Symbol.CompletionFailure; -import com.sun.tools.javac.code.Symbol.MethodSymbol; -import com.sun.tools.javac.code.Symbol.PackageSymbol; -import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.Type.ClassType; -import com.sun.tools.javac.comp.Check; -import com.sun.tools.javac.comp.Enter; -import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.JCTree.JCClassDecl; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import com.sun.tools.javac.tree.JCTree.JCPackageDecl; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.Convert; -import com.sun.tools.javac.util.Name; -import com.sun.tools.javac.util.Names; - -/** - * Holds the environment for a run of javadoc. - * Holds only the information needed throughout the - * run and not the compiler info that could be GC'ed - * or ported. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @since 1.4 - * @author Robert Field - * @author Neal Gafter (rewrite) - * @author Scott Seligman (generics) - */ -public class DocEnv { - protected static final Context.Key docEnvKey = new Context.Key<>(); - - public static DocEnv instance(Context context) { - DocEnv instance = context.get(docEnvKey); - if (instance == null) - instance = new DocEnv(context); - return instance; - } - - DocLocale doclocale; - - private final Messager messager; - - /** Predefined symbols known to the compiler. */ - final Symtab syms; - - /** Referenced directly in RootDocImpl. */ - private final ClassFinder finder; - - /** Javadoc's own version of the compiler's enter phase. */ - final Enter enter; - - /** The name table. */ - private Names names; - - /** The encoding name. */ - private String encoding; - - final Symbol externalizableSym; - - /** Access filter (public, protected, ...). */ - protected ModifierFilter showAccess; - - /** True if we are using a sentence BreakIterator. */ - boolean breakiterator; - - /** - * True if we do not want to print any notifications at all. - */ - boolean quiet = false; - - Check chk; - Types types; - JavaFileManager fileManager; - Context context; - DocLint doclint; - - WeakHashMap treePaths = new WeakHashMap<>(); - - /** Allow documenting from class files? */ - boolean docClasses = false; - - /** Does the doclet only expect pre-1.5 doclet API? */ - protected boolean legacyDoclet = true; - - /** - * Set this to true if you would like to not emit any errors, warnings and - * notices. - */ - private boolean silent = false; - - /** - * The source language version. - */ - protected Source source; - - /** - * Constructor - * - * @param context Context for this javadoc instance. - */ - protected DocEnv(Context context) { - context.put(docEnvKey, this); - this.context = context; - - messager = Messager.instance0(context); - syms = Symtab.instance(context); - finder = JavadocClassFinder.instance(context); - enter = JavadocEnter.instance(context); - names = Names.instance(context); - externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable")); - chk = Check.instance(context); - types = Types.instance(context); - fileManager = context.get(JavaFileManager.class); - if (fileManager instanceof JavacFileManager) { - ((JavacFileManager)fileManager).setSymbolFileEnabled(false); - } - - // Default. Should normally be reset with setLocale. - this.doclocale = new DocLocale(this, "", breakiterator); - source = Source.instance(context); - } - - public void setSilent(boolean silent) { - this.silent = silent; - } - - /** - * Look up ClassDoc by qualified name. - */ - public ClassDocImpl lookupClass(String name) { - ClassSymbol c = getClassSymbol(name); - if (c != null) { - return getClassDoc(c); - } else { - return null; - } - } - - /** - * Load ClassDoc by qualified name. - */ - public ClassDocImpl loadClass(String name) { - try { - Name nameImpl = names.fromString(name); - ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl)); - ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl); - return getClassDoc(c); - } catch (CompletionFailure ex) { - chk.completionError(null, ex); - return null; - } - } - - /** - * Look up PackageDoc by qualified name. - */ - public PackageDocImpl lookupPackage(String name) { - //### Jing alleges that class check is needed - //### to avoid a compiler bug. Most likely - //### instead a dummy created for error recovery. - //### Should investigate this. - Name nameImpl = names.fromString(name); - ModuleSymbol mod = syms.inferModule(nameImpl); - PackageSymbol p = mod != null ? syms.getPackage(mod, nameImpl) : null; - ClassSymbol c = getClassSymbol(name); - if (p != null && c == null) { - return getPackageDoc(p); - } else { - return null; - } - } - // where - /** Retrieve class symbol by fully-qualified name. - */ - ClassSymbol getClassSymbol(String name) { - // Name may contain nested class qualification. - // Generate candidate flatnames with successively shorter - // package qualifiers and longer nested class qualifiers. - int nameLen = name.length(); - char[] nameChars = name.toCharArray(); - int idx = name.length(); - for (;;) { - Name nameImpl = names.fromChars(nameChars, 0, nameLen); - ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl)); - ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null; - if (s != null) - return s; // found it! - idx = name.substring(0, idx).lastIndexOf('.'); - if (idx < 0) break; - nameChars[idx] = '$'; - } - return null; - } - - /** - * Set the locale. - */ - public void setLocale(String localeName) { - // create locale specifics - doclocale = new DocLocale(this, localeName, breakiterator); - // update Messager if locale has changed. - messager.setLocale(doclocale.locale); - } - - /** Check whether this member should be documented. */ - public boolean shouldDocument(VarSymbol sym) { - long mod = sym.flags(); - - if ((mod & Flags.SYNTHETIC) != 0) { - return false; - } - - return showAccess.checkModifier(translateModifiers(mod)); - } - - /** Check whether this member should be documented. */ - public boolean shouldDocument(MethodSymbol sym) { - long mod = sym.flags(); - - if ((mod & Flags.SYNTHETIC) != 0) { - return false; - } - - return showAccess.checkModifier(translateModifiers(mod)); - } - - /** check whether this class should be documented. */ - public boolean shouldDocument(ClassSymbol sym) { - return - (sym.flags_field&Flags.SYNTHETIC) == 0 && // no synthetics - (docClasses || getClassDoc(sym).tree != null) && - isVisible(sym); - } - - //### Comment below is inaccurate wrt modifier filter testing - /** - * Check the visibility if this is an nested class. - * if this is not a nested class, return true. - * if this is an static visible nested class, - * return true. - * if this is an visible nested class - * if the outer class is visible return true. - * else return false. - * IMPORTANT: This also allows, static nested classes - * to be defined inside an nested class, which is not - * allowed by the compiler. So such an test case will - * not reach upto this method itself, but if compiler - * allows it, then that will go through. - */ - protected boolean isVisible(ClassSymbol sym) { - long mod = sym.flags_field; - if (!showAccess.checkModifier(translateModifiers(mod))) { - return false; - } - ClassSymbol encl = sym.owner.enclClass(); - return (encl == null || (mod & Flags.STATIC) != 0 || isVisible(encl)); - } - - //---------------- print forwarders ----------------// - - /** - * Print error message, increment error count. - * - * @param msg message to print. - */ - public void printError(String msg) { - if (silent) - return; - messager.printError(msg); - } - - /** - * Print error message, increment error count. - * - * @param key selects message from resource - */ - public void error(DocImpl doc, String key) { - if (silent) - return; - messager.error(doc==null ? null : doc.position(), key); - } - - /** - * Print error message, increment error count. - * - * @param key selects message from resource - */ - public void error(SourcePosition pos, String key) { - if (silent) - return; - messager.error(pos, key); - } - - /** - * Print error message, increment error count. - * - * @param msg message to print. - */ - public void printError(SourcePosition pos, String msg) { - if (silent) - return; - messager.printError(pos, msg); - } - - /** - * Print error message, increment error count. - * - * @param key selects message from resource - * @param a1 first argument - */ - public void error(DocImpl doc, String key, String a1) { - if (silent) - return; - messager.error(doc==null ? null : doc.position(), key, a1); - } - - /** - * Print error message, increment error count. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - */ - public void error(DocImpl doc, String key, String a1, String a2) { - if (silent) - return; - messager.error(doc==null ? null : doc.position(), key, a1, a2); - } - - /** - * Print error message, increment error count. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - * @param a3 third argument - */ - public void error(DocImpl doc, String key, String a1, String a2, String a3) { - if (silent) - return; - messager.error(doc==null ? null : doc.position(), key, a1, a2, a3); - } - - /** - * Print warning message, increment warning count. - * - * @param msg message to print. - */ - public void printWarning(String msg) { - if (silent) - return; - messager.printWarning(msg); - } - - /** - * Print warning message, increment warning count. - * - * @param key selects message from resource - */ - public void warning(DocImpl doc, String key) { - if (silent) - return; - messager.warning(doc==null ? null : doc.position(), key); - } - - /** - * Print warning message, increment warning count. - * - * @param msg message to print. - */ - public void printWarning(SourcePosition pos, String msg) { - if (silent) - return; - messager.printWarning(pos, msg); - } - - /** - * Print warning message, increment warning count. - * - * @param key selects message from resource - * @param a1 first argument - */ - public void warning(DocImpl doc, String key, String a1) { - if (silent) - return; - // suppress messages that have (probably) been covered by doclint - if (doclint != null && doc != null && key.startsWith("tag")) - return; - messager.warning(doc==null ? null : doc.position(), key, a1); - } - - /** - * Print warning message, increment warning count. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - */ - public void warning(DocImpl doc, String key, String a1, String a2) { - if (silent) - return; - messager.warning(doc==null ? null : doc.position(), key, a1, a2); - } - - /** - * Print warning message, increment warning count. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - * @param a3 third argument - */ - public void warning(DocImpl doc, String key, String a1, String a2, String a3) { - if (silent) - return; - messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3); - } - - /** - * Print warning message, increment warning count. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - * @param a3 third argument - */ - public void warning(DocImpl doc, String key, String a1, String a2, String a3, - String a4) { - if (silent) - return; - messager.warning(doc==null ? null : doc.position(), key, a1, a2, a3, a4); - } - - /** - * Print a message. - * - * @param msg message to print. - */ - public void printNotice(String msg) { - if (silent || quiet) - return; - messager.printNotice(msg); - } - - - /** - * Print a message. - * - * @param key selects message from resource - */ - public void notice(String key) { - if (silent || quiet) - return; - messager.notice(key); - } - - /** - * Print a message. - * - * @param msg message to print. - */ - public void printNotice(SourcePosition pos, String msg) { - if (silent || quiet) - return; - messager.printNotice(pos, msg); - } - - /** - * Print a message. - * - * @param key selects message from resource - * @param a1 first argument - */ - public void notice(String key, String a1) { - if (silent || quiet) - return; - messager.notice(key, a1); - } - - /** - * Print a message. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - */ - public void notice(String key, String a1, String a2) { - if (silent || quiet) - return; - messager.notice(key, a1, a2); - } - - /** - * Print a message. - * - * @param key selects message from resource - * @param a1 first argument - * @param a2 second argument - * @param a3 third argument - */ - public void notice(String key, String a1, String a2, String a3) { - if (silent || quiet) - return; - messager.notice(key, a1, a2, a3); - } - - /** - * Exit, reporting errors and warnings. - */ - public void exit() { - // Messager should be replaced by a more general - // compilation environment. This can probably - // subsume DocEnv as well. - messager.exit(); - } - - protected Map packageMap = new HashMap<>(); - /** - * Return the PackageDoc of this package symbol. - */ - public PackageDocImpl getPackageDoc(PackageSymbol pack) { - PackageDocImpl result = packageMap.get(pack); - if (result != null) return result; - result = new PackageDocImpl(this, pack); - packageMap.put(pack, result); - return result; - } - - /** - * Create the PackageDoc (or a subtype) for a package symbol. - */ - void makePackageDoc(PackageSymbol pack, TreePath treePath) { - PackageDocImpl result = packageMap.get(pack); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - } else { - result = new PackageDocImpl(this, pack, treePath); - packageMap.put(pack, result); - } - } - - - protected Map classMap = new HashMap<>(); - /** - * Return the ClassDoc (or a subtype) of this class symbol. - */ - public ClassDocImpl getClassDoc(ClassSymbol clazz) { - ClassDocImpl result = classMap.get(clazz); - if (result != null) return result; - if (isAnnotationType(clazz)) { - result = new AnnotationTypeDocImpl(this, clazz); - } else { - result = new ClassDocImpl(this, clazz); - } - classMap.put(clazz, result); - return result; - } - - /** - * Create the ClassDoc (or a subtype) for a class symbol. - */ - protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) { - ClassDocImpl result = classMap.get(clazz); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - return; - } - if (isAnnotationType((JCClassDecl) treePath.getLeaf())) { // flags of clazz may not yet be set - result = new AnnotationTypeDocImpl(this, clazz, treePath); - } else { - result = new ClassDocImpl(this, clazz, treePath); - } - classMap.put(clazz, result); - } - - protected static boolean isAnnotationType(ClassSymbol clazz) { - return ClassDocImpl.isAnnotationType(clazz); - } - - protected static boolean isAnnotationType(JCClassDecl tree) { - return (tree.mods.flags & Flags.ANNOTATION) != 0; - } - - protected Map fieldMap = new HashMap<>(); - /** - * Return the FieldDoc of this var symbol. - */ - public FieldDocImpl getFieldDoc(VarSymbol var) { - FieldDocImpl result = fieldMap.get(var); - if (result != null) return result; - result = new FieldDocImpl(this, var); - fieldMap.put(var, result); - return result; - } - /** - * Create a FieldDoc for a var symbol. - */ - protected void makeFieldDoc(VarSymbol var, TreePath treePath) { - FieldDocImpl result = fieldMap.get(var); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - } else { - result = new FieldDocImpl(this, var, treePath); - fieldMap.put(var, result); - } - } - - protected Map methodMap = new HashMap<>(); - /** - * Create a MethodDoc for this MethodSymbol. - * Should be called only on symbols representing methods. - */ - protected void makeMethodDoc(MethodSymbol meth, TreePath treePath) { - MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - } else { - result = new MethodDocImpl(this, meth, treePath); - methodMap.put(meth, result); - } - } - - /** - * Return the MethodDoc for a MethodSymbol. - * Should be called only on symbols representing methods. - */ - public MethodDocImpl getMethodDoc(MethodSymbol meth) { - assert !meth.isConstructor() : "not expecting a constructor symbol"; - MethodDocImpl result = (MethodDocImpl)methodMap.get(meth); - if (result != null) return result; - result = new MethodDocImpl(this, meth); - methodMap.put(meth, result); - return result; - } - - /** - * Create the ConstructorDoc for a MethodSymbol. - * Should be called only on symbols representing constructors. - */ - protected void makeConstructorDoc(MethodSymbol meth, TreePath treePath) { - ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - } else { - result = new ConstructorDocImpl(this, meth, treePath); - methodMap.put(meth, result); - } - } - - /** - * Return the ConstructorDoc for a MethodSymbol. - * Should be called only on symbols representing constructors. - */ - public ConstructorDocImpl getConstructorDoc(MethodSymbol meth) { - assert meth.isConstructor() : "expecting a constructor symbol"; - ConstructorDocImpl result = (ConstructorDocImpl)methodMap.get(meth); - if (result != null) return result; - result = new ConstructorDocImpl(this, meth); - methodMap.put(meth, result); - return result; - } - - /** - * Create the AnnotationTypeElementDoc for a MethodSymbol. - * Should be called only on symbols representing annotation type elements. - */ - protected void makeAnnotationTypeElementDoc(MethodSymbol meth, TreePath treePath) { - AnnotationTypeElementDocImpl result = - (AnnotationTypeElementDocImpl)methodMap.get(meth); - if (result != null) { - if (treePath != null) result.setTreePath(treePath); - } else { - result = - new AnnotationTypeElementDocImpl(this, meth, treePath); - methodMap.put(meth, result); - } - } - - /** - * Return the AnnotationTypeElementDoc for a MethodSymbol. - * Should be called only on symbols representing annotation type elements. - */ - public AnnotationTypeElementDocImpl getAnnotationTypeElementDoc( - MethodSymbol meth) { - - AnnotationTypeElementDocImpl result = - (AnnotationTypeElementDocImpl)methodMap.get(meth); - if (result != null) return result; - result = new AnnotationTypeElementDocImpl(this, meth); - methodMap.put(meth, result); - return result; - } - -// private Map parameterizedTypeMap = -// new HashMap(); - /** - * Return the ParameterizedType of this instantiation. -// * ### Could use Type.sameTypeAs() instead of equality matching in hashmap -// * ### to avoid some duplication. - */ - ParameterizedTypeImpl getParameterizedType(ClassType t) { - return new ParameterizedTypeImpl(this, t); -// ParameterizedTypeImpl result = parameterizedTypeMap.get(t); -// if (result != null) return result; -// result = new ParameterizedTypeImpl(this, t); -// parameterizedTypeMap.put(t, result); -// return result; - } - - TreePath getTreePath(JCCompilationUnit tree) { - TreePath p = treePaths.get(tree); - if (p == null) - treePaths.put(tree, p = new TreePath(tree)); - return p; - } - - TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) { - TreePath p = treePaths.get(tree); - if (p == null) - treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree)); - return p; - } - - TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) { - TreePath p = treePaths.get(tree); - if (p == null) - treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree)); - return p; - } - - TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl cdecl, JCTree tree) { - return new TreePath(getTreePath(toplevel, cdecl), tree); - } - - /** - * Set the encoding. - */ - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - /** - * Get the encoding. - */ - public String getEncoding() { - return encoding; - } - - /** - * Convert modifier bits from private coding used by - * the compiler to that of java.lang.reflect.Modifier. - */ - static int translateModifiers(long flags) { - int result = 0; - if ((flags & Flags.ABSTRACT) != 0) - result |= Modifier.ABSTRACT; - if ((flags & Flags.FINAL) != 0) - result |= Modifier.FINAL; - if ((flags & Flags.INTERFACE) != 0) - result |= Modifier.INTERFACE; - if ((flags & Flags.NATIVE) != 0) - result |= Modifier.NATIVE; - if ((flags & Flags.PRIVATE) != 0) - result |= Modifier.PRIVATE; - if ((flags & Flags.PROTECTED) != 0) - result |= Modifier.PROTECTED; - if ((flags & Flags.PUBLIC) != 0) - result |= Modifier.PUBLIC; - if ((flags & Flags.STATIC) != 0) - result |= Modifier.STATIC; - if ((flags & Flags.SYNCHRONIZED) != 0) - result |= Modifier.SYNCHRONIZED; - if ((flags & Flags.TRANSIENT) != 0) - result |= Modifier.TRANSIENT; - if ((flags & Flags.VOLATILE) != 0) - result |= Modifier.VOLATILE; - return result; - } - - void initDoclint(Collection opts, Collection customTagNames, String htmlVersion) { - ArrayList doclintOpts = new ArrayList<>(); - boolean msgOptionSeen = false; - - for (String opt : opts) { - if (opt.startsWith(DocLint.XMSGS_OPTION)) { - if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) - return; - msgOptionSeen = true; - } - doclintOpts.add(opt); - } - - if (!msgOptionSeen) { - doclintOpts.add(DocLint.XMSGS_OPTION); - } - - String sep = ""; - StringBuilder customTags = new StringBuilder(); - for (String customTag : customTagNames) { - customTags.append(sep); - customTags.append(customTag); - sep = DocLint.SEPARATOR; - } - doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); - doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion); - - JavacTask t = BasicJavacTask.instance(context); - doclint = new DocLint(); - // standard doclet normally generates H1, H2 - doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); - doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); - } - - boolean showTagMessages() { - return (doclint == null); - } - - Map shouldCheck = new HashMap<>(); - - boolean shouldCheck(CompilationUnitTree unit) { - return shouldCheck.computeIfAbsent(unit, doclint :: shouldCheck); - } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocImpl.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocImpl.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,444 +0,0 @@ -/* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.text.CollationKey; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.tools.FileObject; - -import com.sun.javadoc.*; -import com.sun.source.util.TreePath; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; -import com.sun.tools.javac.util.Position; - -/** - * abstract base class of all Doc classes. Doc item's are representations - * of java language constructs (class, package, method,...) which have - * comments and have been processed by this run of javadoc. All Doc items - * are unique, that is, they are == comparable. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @since 1.2 - * @author Robert Field - * @author Atul M Dambalkar - * @author Neal Gafter (rewrite) - */ -public abstract class DocImpl implements Doc, Comparable { - - /** - * Doc environment - */ - protected final DocEnv env; //### Rename this everywhere to 'docenv' ? - - /** - * Back pointer to the tree node for this doc item. - * May be null if there is no associated tree. - */ - protected TreePath treePath; - - /** - * The complex comment object, lazily initialized. - */ - private Comment comment; - - /** - * The cached sort key, to take care of Natural Language Text sorting. - */ - private CollationKey collationkey = null; - - /** - * Raw documentation string. - */ - protected String documentation; // Accessed in PackageDocImpl, RootDocImpl - - /** - * Cached first sentence. - */ - private Tag[] firstSentence; - - /** - * Cached inline tags. - */ - private Tag[] inlineTags; - - /** - * Constructor. - */ - DocImpl(DocEnv env, TreePath treePath) { - this.treePath = treePath; - this.documentation = getCommentText(treePath); - this.env = env; - } - - private static String getCommentText(TreePath p) { - if (p == null) - return null; - - JCCompilationUnit topLevel = (JCCompilationUnit) p.getCompilationUnit(); - JCTree tree = (JCTree) p.getLeaf(); - return topLevel.docComments.getCommentText(tree); - } - - /** - * So subclasses have the option to do lazy initialization of - * "documentation" string. - */ - protected String documentation() { - if (documentation == null) documentation = ""; - return documentation; - } - - /** - * For lazy initialization of comment. - */ - Comment comment() { - if (comment == null) { - String d = documentation(); - if (env.doclint != null - && treePath != null - && env.shouldCheck(treePath.getCompilationUnit()) - && d.equals(getCommentText(treePath))) { - env.doclint.scan(treePath); - } - comment = new Comment(this, d); - } - return comment; - } - - /** - * Return the text of the comment for this doc item. - * TagImpls have been removed. - */ - public String commentText() { - return comment().commentText(); - } - - /** - * Return all tags in this Doc item. - * - * @return an array of TagImpl containing all tags on this Doc item. - */ - public Tag[] tags() { - return comment().tags(); - } - - /** - * Return tags of the specified kind in this Doc item. - * - * @param tagname name of the tag kind to search for. - * @return an array of TagImpl containing all tags whose 'kind()' - * matches 'tagname'. - */ - public Tag[] tags(String tagname) { - return comment().tags(tagname); - } - - /** - * Return the see also tags in this Doc item. - * - * @return an array of SeeTag containing all @see tags. - */ - public SeeTag[] seeTags() { - return comment().seeTags(); - } - - public Tag[] inlineTags() { - if (inlineTags == null) { - inlineTags = Comment.getInlineTags(this, commentText()); - } - return inlineTags; - } - - public Tag[] firstSentenceTags() { - if (firstSentence == null) { - //Parse all sentences first to avoid duplicate warnings. - inlineTags(); - try { - env.setSilent(true); - firstSentence = Comment.firstSentenceTags(this, commentText()); - } finally { - env.setSilent(false); - } - } - return firstSentence; - } - - /** - * Utility for subclasses which read HTML documentation files. - */ - String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { - byte[] filecontents = new byte[input.available()]; - try { - DataInputStream dataIn = new DataInputStream(input); - dataIn.readFully(filecontents); - } finally { - input.close(); - } - String encoding = env.getEncoding(); - String rawDoc = (encoding!=null) - ? new String(filecontents, encoding) - : new String(filecontents); - Pattern bodyPat = Pattern.compile("(?is).*]*>(.*) - * Default is name(). - */ - CollationKey generateKey() { - String k = name(); - // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); - return env.doclocale.collator.getCollationKey(k); - } - - /** - * Returns a string representation of this Doc item. - */ - @Override - public String toString() { - return qualifiedName(); - } - - /** - * Returns the name of this Doc item. - * - * @return the name - */ - public abstract String name(); - - /** - * Returns the qualified name of this Doc item. - * - * @return the name - */ - public abstract String qualifiedName(); - - /** - * Compares this Object with the specified Object for order. Returns a - * negative integer, zero, or a positive integer as this Object is less - * than, equal to, or greater than the given Object. - *

- * Included so that Doc item are java.lang.Comparable. - * - * @param obj the {@code Object} to be compared. - * @return a negative integer, zero, or a positive integer as this Object - * is less than, equal to, or greater than the given Object. - * @exception ClassCastException the specified Object's type prevents it - * from being compared to this Object. - */ - public int compareTo(Object obj) { - // System.out.println("COMPARE \"" + this + "\" to \"" + obj + "\" = " + key().compareTo(((DocImpl)obj).key())); - return key().compareTo(((DocImpl)obj).key()); - } - - /** - * Is this Doc item a field? False until overridden. - * - * @return true if it represents a field - */ - public boolean isField() { - return false; - } - - /** - * Is this Doc item an enum constant? False until overridden. - * - * @return true if it represents an enum constant - */ - public boolean isEnumConstant() { - return false; - } - - /** - * Is this Doc item a constructor? False until overridden. - * - * @return true if it represents a constructor - */ - public boolean isConstructor() { - return false; - } - - /** - * Is this Doc item a method (but not a constructor or annotation - * type element)? - * False until overridden. - * - * @return true if it represents a method - */ - public boolean isMethod() { - return false; - } - - /** - * Is this Doc item an annotation type element? - * False until overridden. - * - * @return true if it represents an annotation type element - */ - public boolean isAnnotationTypeElement() { - return false; - } - - /** - * Is this Doc item a interface (but not an annotation type)? - * False until overridden. - * - * @return true if it represents a interface - */ - public boolean isInterface() { - return false; - } - - /** - * Is this Doc item a exception class? False until overridden. - * - * @return true if it represents a exception - */ - public boolean isException() { - return false; - } - - /** - * Is this Doc item a error class? False until overridden. - * - * @return true if it represents a error - */ - public boolean isError() { - return false; - } - - /** - * Is this Doc item an enum type? False until overridden. - * - * @return true if it represents an enum type - */ - public boolean isEnum() { - return false; - } - - /** - * Is this Doc item an annotation type? False until overridden. - * - * @return true if it represents an annotation type - */ - public boolean isAnnotationType() { - return false; - } - - /** - * Is this Doc item an ordinary class (i.e. not an interface, - * annotation type, enumeration, exception, or error)? - * False until overridden. - * - * @return true if it represents an ordinary class - */ - public boolean isOrdinaryClass() { - return false; - } - - /** - * Is this Doc item a class - * (and not an interface or annotation type)? - * This includes ordinary classes, enums, errors and exceptions. - * False until overridden. - * - * @return true if it represents a class - */ - public boolean isClass() { - return false; - } - - /** - * return true if this Doc is include in the active set. - */ - public abstract boolean isIncluded(); - - /** - * Return the source position of the entity, or null if - * no position is available. - */ - public SourcePosition position() { return null; } -} diff -r 7c04fcb12bd4 -r 42baa89d2156 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocLocale.java --- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocLocale.java Wed Jul 05 21:41:01 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javadoc; - -import java.text.BreakIterator; -import java.text.Collator; -import java.util.Locale; - -/** - * This class holds the information about locales. - * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice. - * - * @since 1.4 - * @author Robert Field - */ -class DocLocale { - - /** - * The locale name will be set by Main, if option is provided on the - * command line. - */ - final String localeName; - - /** - * The locale to be used. If user doesn't provide this, - * then set it to default locale value. - */ - final Locale locale; - - /** - * The collator for this application. This is to take care of Locale - * Specific or Natural Language Text sorting. - */ - final Collator collator; - - /** - * Enclosing DocEnv - */ - private final DocEnv docenv; - - /** - * Sentence instance from the BreakIterator. - */ - private final BreakIterator sentenceBreaker; - - /** - * True is we should use BreakIterator - * to compute first sentence. - */ - private boolean useBreakIterator = false; - - /** - * The HTML sentence terminators. - */ - static final String[] sentenceTerminators = - { - "

", "

", "

", "

", - "

", "

", "

", "
", - "
", "", "", "", "", - "", "
", "
", "
" - }; - - /** - * Constructor - */ - DocLocale(DocEnv docenv, String localeName, boolean useBreakIterator) { - this.docenv = docenv; - this.localeName = localeName; - this.useBreakIterator = useBreakIterator; - locale = getLocale(); - if (locale == null) { - docenv.exit(); - } else { - Locale.setDefault(locale); // NOTE: updating global state - } - collator = Collator.getInstance(locale); - sentenceBreaker = BreakIterator.getSentenceInstance(locale); - } - - /** - * Get the locale if specified on the command line - * else return null and if locale option is not used - * then return default locale. - */ - private Locale getLocale() { - Locale userlocale = null; - if (localeName.length() > 0) { - int firstuscore = localeName.indexOf('_'); - int seconduscore = -1; - String language = null; - String country = null; - String variant = null; - if (firstuscore == 2) { - language = localeName.substring(0, firstuscore); - seconduscore = localeName.indexOf('_', firstuscore + 1); - if (seconduscore > 0) { - if (seconduscore != firstuscore + 3 || - localeName.length() <= seconduscore + 1) { - docenv.error(null, "main.malformed_locale_name", localeName); - return null; - } - country = localeName.substring(firstuscore + 1, - seconduscore); - variant = localeName.substring(seconduscore + 1); - } else if (localeName.length() == firstuscore + 3) { - country = localeName.substring(firstuscore + 1); - } else { - docenv.error(null, "main.malformed_locale_name", localeName); - return null; - } - } else if (firstuscore == -1 && localeName.length() == 2) { - language = localeName; - } else { - docenv.error(null, "main.malformed_locale_name", localeName); - return null; - } - userlocale = searchLocale(language, country, variant); - if (userlocale == null) { - docenv.error(null, "main.illegal_locale_name", localeName); - return null; - } else { - return userlocale; - } - } else { - return Locale.getDefault(); - } - } - - /** - * Search the locale for specified language, specified country and - * specified variant. - */ - private Locale searchLocale(String language, String country, - String variant) { - for (Locale loc : Locale.getAvailableLocales()) { - if (loc.getLanguage().equals(language) && - (country == null || loc.getCountry().equals(country)) && - (variant == null || loc.getVariant().equals(variant))) { - return loc; - } - } - return null; - } - - String localeSpecificFirstSentence(DocImpl doc, String s) { - if (s == null || s.length() == 0) { - return ""; - } - int index = s.indexOf("-->"); - if(s.trim().startsWith(""); + if(s.trim().startsWith("