8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
Reviewed-by: ksrini
--- 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.*;
--- 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.
--- 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);
--- 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 <code>Type</code>, with useful
- * defaults for the methods in <code>Type</code> (and a couple from
- * <code>ProgramElementDoc</code>).
- *
- * <p><b>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.</b>
- *
- * @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;
- }
-}
--- 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 <code>AnnotatedType</code>, 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<? extends TypeCompound> 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();
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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<Pair<MethodSymbol,Attribute>> vals = annotation.values;
- ElementValuePair res[] = new ElementValuePair[vals.length()];
- int i = 0;
- for (Pair<MethodSymbol,Attribute> 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:
- * <pre>
- * {@code @com.example.foo(name1=val1, name2=val2)}
- * {@code @com.example.foo(val)}
- * {@code @com.example.foo}
- * </pre>
- * 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();
- }
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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<AnnotationTypeElementDoc> 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()]);
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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);
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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:
- * <ul><li> a wrapper class for a primitive type
- * <li> <code>String</code>
- * <li> <code>Type</code> (representing a class literal)
- * <li> <code>FieldDoc</code> (representing an enum constant)
- * <li> <code>AnnotationDesc</code>
- * <li> <code>AnnotationValue[]</code>
- * </ul>
- */
- 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 = "<error>";
- }
- }
-
- /**
- * 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("<error>");
- }
- }
-}
--- 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).
- *
- * <p><b>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.</b>
- *
- * @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.
- * <pre>
- * Examples:
- * for java.util.Hashtable
- * return Hashtable
- * for java.util.Map.Entry
- * return Map.Entry
- * </pre>
- */
- public String name() {
- if (name == null) {
- name = getClassName(tsym, false);
- }
- return name;
- }
-
- private String name;
-
- /**
- * Return the qualified class name as a String.
- * <pre>
- * Example:
- * for java.util.Hashtable
- * return java.util.Hashtable
- * if no qualifier, just return flat name
- * </pre>
- */
- public String qualifiedName() {
- if (qualifiedName == null) {
- qualifiedName = getClassName(tsym, true);
- }
- return qualifiedName;
- }
-
- private String qualifiedName;
-
- /**
- * Return unqualified name of type excluding any dimension information.
- * <p>
- * For example, a two dimensional array of String returns 'String'.
- */
- public String typeName() {
- return name();
- }
-
- /**
- * Return qualified name of type excluding any dimension information.
- *<p>
- * 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
- * <code>ClassDoc</code> or a <code>ParameterizedType</code>.
- */
- 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<ClassDocImpl> 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<FieldDocImpl> 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<MethodDocImpl> 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<ConstructorDocImpl> 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<ClassDocImpl> 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<ClassDocImpl> 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<ClassDocImpl> 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<AttrContext> 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<Type> 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<ClassDocImpl>());
- }
-
- private MethodDocImpl searchMethod(String methodName,
- String[] paramTypes, Set<ClassDocImpl> 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("<init>"))) {
- 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<ClassDocImpl>());
- }
-
- private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> 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<ClassDocImpl> importedClasses = new ListBuffer<>();
-
- Env<AttrContext> 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<PackageDocImpl> 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<AttrContext> 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 <code>java.io.Serializable</code>.
- *
- * Since <code>java.io.Externalizable</code> extends
- * <code>java.io.Serializable</code>,
- * 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
- * <code>java.io.Externalizable</code>.
- */
- 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 <code>MethodDocImpl</code> 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.<p>
- *
- * Return either a list of default fields documented by
- * <code>serial</code> tag<br>
- * or return a single <code>FieldDoc</code> for
- * <code>serialPersistentField</code> member.
- * There should be a <code>serialField</code> tag for
- * each Serializable field defined by an <code>ObjectStreamField</code>
- * array component of <code>serialPersistentField</code>.
- *
- * @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 <code>serialPersistentFields</code>.
- *
- * @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.
- * <p>
- * 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);
- }
-}
--- 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...
- *
- * <p><b>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.</b>
- *
- * @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<Tag> 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:
- * <pre>
- * 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.
- * </pre>
- */
- @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<Tag> 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<ThrowsTag> 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<ParamTag> 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<SeeTag> 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<SerialFieldTag> 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<Tag> 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 <pre> } and {@literal </pre> }. */
- 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;
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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();
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @since 1.4
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (generics)
- */
-public class DocEnv {
- protected static final Context.Key<DocEnv> 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<JCTree, TreePath> 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<PackageSymbol, PackageDocImpl> 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<ClassSymbol, ClassDocImpl> 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<VarSymbol, FieldDocImpl> 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<MethodSymbol, ExecutableMemberDocImpl> 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<ClassType, ParameterizedTypeImpl> parameterizedTypeMap =
-// new HashMap<ClassType, ParameterizedTypeImpl>();
- /**
- * 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<String> opts, Collection<String> customTagNames, String htmlVersion) {
- ArrayList<String> 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<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>();
-
- boolean shouldCheck(CompilationUnitTree unit) {
- return shouldCheck.computeIfAbsent(unit, doclint :: shouldCheck);
- }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Robert Field
- * @author Atul M Dambalkar
- * @author Neal Gafter (rewrite)
- */
-public abstract class DocImpl implements Doc, Comparable<Object> {
-
- /**
- * 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).*<body\\b[^>]*>(.*)</body\\b.*");
- Matcher m = bodyPat.matcher(rawDoc);
- if (m.matches()) {
- return m.group(1);
- } else {
- String key = rawDoc.matches("(?is).*<body\\b.*")
- ? "javadoc.End_body_missing_from_html_file"
- : "javadoc.Body_missing_from_html_file";
- env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key);
- return "";
- }
- }
-
- /**
- * Return the full unprocessed text of the comment. Tags
- * are included as text. Used mainly for store and retrieve
- * operations like internalization.
- */
- public String getRawCommentText() {
- return documentation();
- }
-
- /**
- * Set the full unprocessed text of the comment. Tags
- * are included as text. Used mainly for store and retrieve
- * operations like internalization.
- */
- public void setRawCommentText(String rawDocumentation) {
- treePath = null;
- documentation = rawDocumentation;
- comment = null;
- }
-
- /**
- * Set the full unprocessed text of the comment and tree path.
- */
- void setTreePath(TreePath treePath) {
- this.treePath = treePath;
- documentation = getCommentText(treePath);
- comment = null;
- }
-
- /**
- * return a key for sorting.
- */
- CollationKey key() {
- if (collationkey == null) {
- collationkey = generateKey();
- }
- return collationkey;
- }
-
- /**
- * Generate a key for sorting.
- * <p>
- * 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.
- * <p>
- * 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; }
-}
--- 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.
- *
- * <p><b>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.</b>
- *
- * @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 <code>BreakIterator</code>
- * to compute first sentence.
- */
- private boolean useBreakIterator = false;
-
- /**
- * The HTML sentence terminators.
- */
- static final String[] sentenceTerminators =
- {
- "<p>", "</p>", "<h1>", "<h2>",
- "<h3>", "<h4>", "<h5>", "<h6>",
- "</h1>", "</h2>", "</h3>", "</h4>", "</h5>",
- "</h6>", "<hr>", "<pre>", "</pre>"
- };
-
- /**
- * 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("<!--") && index != -1) {
- return localeSpecificFirstSentence(doc, s.substring(index + 3, s.length()));
- }
- if (useBreakIterator || !locale.getLanguage().equals("en")) {
- sentenceBreaker.setText(s.replace('\n', ' '));
- int start = sentenceBreaker.first();
- int end = sentenceBreaker.next();
- return s.substring(start, end).trim();
- } else {
- return englishLanguageFirstSentence(s).trim();
- }
- }
-
- /**
- * Return the first sentence of a string, where a sentence ends
- * with a period followed be white space.
- */
- private String englishLanguageFirstSentence(String s) {
- if (s == null) {
- return null;
- }
- int len = s.length();
- boolean period = false;
- for (int i = 0 ; i < len ; i++) {
- switch (s.charAt(i)) {
- case '.':
- period = true;
- break;
- case ' ':
- case '\t':
- case '\n':
- case '\r':
- case '\f':
- if (period) {
- return s.substring(0, i);
- }
- break;
- case '<':
- if (i > 0) {
- if (htmlSentenceTerminatorFound(s, i)) {
- return s.substring(0, i);
- }
- }
- break;
- default:
- period = false;
- }
- }
- return s;
- }
-
- /**
- * Find out if there is any HTML tag in the given string. If found
- * return true else return false.
- */
- private boolean htmlSentenceTerminatorFound(String str, int index) {
- for (String terminator : sentenceTerminators) {
- if (str.regionMatches(true, index, terminator,
- 0, terminator.length())) {
- return true;
- }
- }
- return false;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/DocletInvoker.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,439 +0,0 @@
-/*
- * Copyright (c) 1998, 2016, 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.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
-
-import javax.tools.DocumentationTool;
-import javax.tools.JavaFileManager;
-
-import com.sun.javadoc.*;
-import com.sun.tools.javac.util.ClientCodeException;
-import com.sun.tools.javac.util.List;
-
-import static com.sun.javadoc.LanguageVersion.*;
-
-
-/**
- * Class creates, controls and invokes doclets.
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter (rewrite)
- */
-public class DocletInvoker {
-
- private final Class<?> docletClass;
-
- private final String docletClassName;
-
- private final ClassLoader appClassLoader;
-
- private final Messager messager;
-
- /**
- * In API mode, exceptions thrown while calling the doclet are
- * propagated using ClientCodeException.
- */
- private final boolean apiMode;
-
- /**
- * Whether javadoc internal API should be exported to doclets
- * and (indirectly) to taglets
- */
- private final boolean exportInternalAPI;
-
- private static class DocletInvokeException extends Exception {
- private static final long serialVersionUID = 0;
- }
-
- private String appendPath(String path1, String path2) {
- if (path1 == null || path1.length() == 0) {
- return path2 == null ? "." : path2;
- } else if (path2 == null || path2.length() == 0) {
- return path1;
- } else {
- return path1 + File.pathSeparator + path2;
- }
- }
-
- public DocletInvoker(Messager messager, Class<?> docletClass, boolean apiMode, boolean exportInternalAPI) {
- this.messager = messager;
- this.docletClass = docletClass;
- docletClassName = docletClass.getName();
- appClassLoader = null;
- this.apiMode = apiMode;
- this.exportInternalAPI = exportInternalAPI; // for backdoor use by standard doclet for taglets
-
- // this may not be soon enough if the class has already been loaded
- if (exportInternalAPI) {
- exportInternalAPI(docletClass.getClassLoader());
- }
- }
-
- public DocletInvoker(Messager messager, JavaFileManager fileManager,
- String docletClassName, String docletPath,
- ClassLoader docletParentClassLoader,
- boolean apiMode,
- boolean exportInternalAPI) {
- this.messager = messager;
- this.docletClassName = docletClassName;
- this.apiMode = apiMode;
- this.exportInternalAPI = exportInternalAPI; // for backdoor use by standard doclet for taglets
-
- if (fileManager != null && fileManager.hasLocation(DocumentationTool.Location.DOCLET_PATH)) {
- appClassLoader = fileManager.getClassLoader(DocumentationTool.Location.DOCLET_PATH);
- } else {
- // construct class loader
- String cpString = null; // make sure env.class.path defaults to dot
-
- // do prepends to get correct ordering
- cpString = appendPath(System.getProperty("env.class.path"), cpString);
- cpString = appendPath(System.getProperty("java.class.path"), cpString);
- cpString = appendPath(docletPath, cpString);
- URL[] urls = pathToURLs(cpString);
- if (docletParentClassLoader == null)
- appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
- else
- appClassLoader = new URLClassLoader(urls, docletParentClassLoader);
- }
-
- if (exportInternalAPI) {
- exportInternalAPI(appClassLoader);
- }
-
- // attempt to find doclet
- Class<?> dc = null;
- try {
- dc = appClassLoader.loadClass(docletClassName);
- } catch (ClassNotFoundException exc) {
- messager.error(Messager.NOPOS, "main.doclet_class_not_found", docletClassName);
- messager.exit();
- }
- docletClass = dc;
- }
-
- /*
- * Returns the delegation class loader to use when creating
- * appClassLoader (used to load the doclet). The context class
- * loader is the best choice, but legacy behavior was to use the
- * default delegation class loader (aka system class loader).
- *
- * Here we favor using the context class loader. To ensure
- * compatibility with existing apps, we revert to legacy
- * behavior if either or both of the following conditions hold:
- *
- * 1) the doclet is loadable from the system class loader but not
- * from the context class loader,
- *
- * 2) this.getClass() is loadable from the system class loader but not
- * from the context class loader.
- */
- private ClassLoader getDelegationClassLoader(String docletClassName) {
- ClassLoader ctxCL = Thread.currentThread().getContextClassLoader();
- ClassLoader sysCL = ClassLoader.getSystemClassLoader();
- if (sysCL == null)
- return ctxCL;
- if (ctxCL == null)
- return sysCL;
-
- // Condition 1.
- try {
- sysCL.loadClass(docletClassName);
- try {
- ctxCL.loadClass(docletClassName);
- } catch (ClassNotFoundException e) {
- return sysCL;
- }
- } catch (ClassNotFoundException e) {
- }
-
- // Condition 2.
- try {
- if (getClass() == sysCL.loadClass(getClass().getName())) {
- try {
- if (getClass() != ctxCL.loadClass(getClass().getName()))
- return sysCL;
- } catch (ClassNotFoundException e) {
- return sysCL;
- }
- }
- } catch (ClassNotFoundException e) {
- }
-
- return ctxCL;
- }
-
- /**
- * Generate documentation here. Return true on success.
- */
- public boolean start(RootDoc root) {
- Object retVal;
- String methodName = "start";
- Class<?>[] paramTypes = { RootDoc.class };
- Object[] params = { root };
- try {
- retVal = invoke(methodName, null, paramTypes, params);
- } catch (DocletInvokeException exc) {
- return false;
- }
- if (retVal instanceof Boolean) {
- return ((Boolean)retVal);
- } else {
- messager.error(Messager.NOPOS, "main.must_return_boolean",
- docletClassName, methodName);
- return false;
- }
- }
-
- /**
- * Check for doclet added options here. Zero return means
- * option not known. Positive value indicates number of
- * arguments to option. Negative value means error occurred.
- */
- public int optionLength(String option) {
- Object retVal;
- String methodName = "optionLength";
- Class<?>[] paramTypes = { String.class };
- Object[] params = { option };
- try {
- retVal = invoke(methodName, 0, paramTypes, params);
- } catch (DocletInvokeException exc) {
- return -1;
- }
- if (retVal instanceof Integer) {
- return ((Integer)retVal);
- } else {
- messager.error(Messager.NOPOS, "main.must_return_int",
- docletClassName, methodName);
- return -1;
- }
- }
-
- /**
- * Let doclet check that all options are OK. Returning true means
- * options are OK. If method does not exist, assume true.
- */
- public boolean validOptions(List<String[]> optlist) {
- Object retVal;
- String options[][] = optlist.toArray(new String[optlist.length()][]);
- String methodName = "validOptions";
- DocErrorReporter reporter = messager;
- Class<?>[] paramTypes = { String[][].class, DocErrorReporter.class };
- Object[] params = { options, reporter };
- try {
- retVal = invoke(methodName, Boolean.TRUE, paramTypes, params);
- } catch (DocletInvokeException exc) {
- return false;
- }
- if (retVal instanceof Boolean) {
- return ((Boolean)retVal);
- } else {
- messager.error(Messager.NOPOS, "main.must_return_boolean",
- docletClassName, methodName);
- return false;
- }
- }
-
- /**
- * Return the language version supported by this doclet.
- * If the method does not exist in the doclet, assume version 1.1.
- */
- public LanguageVersion languageVersion() {
- try {
- Object retVal;
- String methodName = "languageVersion";
- Class<?>[] paramTypes = new Class<?>[0];
- Object[] params = new Object[0];
- try {
- retVal = invoke(methodName, JAVA_1_1, paramTypes, params);
- } catch (DocletInvokeException exc) {
- return JAVA_1_1;
- }
- if (retVal instanceof LanguageVersion) {
- return (LanguageVersion)retVal;
- } else {
- messager.error(Messager.NOPOS, "main.must_return_languageversion",
- docletClassName, methodName);
- return JAVA_1_1;
- }
- } catch (NoClassDefFoundError ex) { // for boostrapping, no Enum class.
- return null;
- }
- }
-
- /**
- * Utility method for calling doclet functionality
- */
- private Object invoke(String methodName, Object returnValueIfNonExistent,
- Class<?>[] paramTypes, Object[] params)
- throws DocletInvokeException {
- Method meth;
- try {
- meth = docletClass.getMethod(methodName, paramTypes);
- } catch (NoSuchMethodException exc) {
- if (returnValueIfNonExistent == null) {
- messager.error(Messager.NOPOS, "main.doclet_method_not_found",
- docletClassName, methodName);
- throw new DocletInvokeException();
- } else {
- return returnValueIfNonExistent;
- }
- } catch (SecurityException exc) {
- messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
- docletClassName, methodName);
- throw new DocletInvokeException();
- }
- if (!Modifier.isStatic(meth.getModifiers())) {
- messager.error(Messager.NOPOS, "main.doclet_method_must_be_static",
- docletClassName, methodName);
- throw new DocletInvokeException();
- }
- ClassLoader savedCCL =
- Thread.currentThread().getContextClassLoader();
- try {
- if (appClassLoader != null) // will be null if doclet class provided via API
- Thread.currentThread().setContextClassLoader(appClassLoader);
- return meth.invoke(null , params);
- } catch (IllegalArgumentException | NullPointerException exc) {
- messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
- docletClassName, methodName, exc.toString());
- throw new DocletInvokeException();
- } catch (IllegalAccessException exc) {
- messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
- docletClassName, methodName);
- throw new DocletInvokeException();
- }
- catch (InvocationTargetException exc) {
- Throwable err = exc.getTargetException();
- if (apiMode)
- throw new ClientCodeException(err);
- if (err instanceof java.lang.OutOfMemoryError) {
- messager.error(Messager.NOPOS, "main.out.of.memory");
- } else {
- messager.error(Messager.NOPOS, "main.exception_thrown",
- docletClassName, methodName, exc.toString());
- exc.getTargetException().printStackTrace(System.err);
- }
- throw new DocletInvokeException();
- } finally {
- Thread.currentThread().setContextClassLoader(savedCCL);
- }
- }
-
- /**
- * Export javadoc internal API to the unnamed module for a classloader.
- * This is to support continued use of existing non-standard doclets that
- * use the internal toolkit API and related classes.
- * @param cl the classloader
- */
- private void exportInternalAPI(ClassLoader cl) {
- String[] packages = {
- "com.sun.tools.doclets",
- "com.sun.tools.doclets.standard",
- "com.sun.tools.doclets.internal.toolkit",
- "com.sun.tools.doclets.internal.toolkit.taglets",
- "com.sun.tools.doclets.internal.toolkit.builders",
- "com.sun.tools.doclets.internal.toolkit.util",
- "com.sun.tools.doclets.internal.toolkit.util.links",
- "com.sun.tools.doclets.formats.html",
- "com.sun.tools.doclets.formats.html.markup"
- };
-
- try {
- Method getModuleMethod = Class.class.getDeclaredMethod("getModule");
- Object thisModule = getModuleMethod.invoke(getClass());
-
- Class<?> moduleClass = Class.forName("java.lang.reflect.Module");
- Method addExportsMethod = moduleClass.getDeclaredMethod("addExports", String.class, moduleClass);
-
- Method getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule");
- Object target = getUnnamedModuleMethod.invoke(cl);
-
- for (String pack : packages) {
- addExportsMethod.invoke(thisModule, pack, target);
- }
- } catch (Exception e) {
- // do nothing
- }
- }
-
- /**
- * Utility method for converting a search path string to an array of directory and JAR file
- * URLs.
- *
- * Note that this method is called by the DocletInvoker.
- *
- * @param path the search path string
- * @return the resulting array of directory and JAR file URLs
- */
- private static URL[] pathToURLs(String path) {
- java.util.List<URL> urls = new ArrayList<>();
- for (String s: path.split(Pattern.quote(File.pathSeparator))) {
- if (!s.isEmpty()) {
- URL url = fileToURL(Paths.get(s));
- if (url != null) {
- urls.add(url);
- }
- }
- }
- return urls.toArray(new URL[urls.size()]);
- }
-
- /**
- * Returns the directory or JAR file URL corresponding to the specified local file name.
- *
- * @param file the Path object
- * @return the resulting directory or JAR file URL, or null if unknown
- */
- private static URL fileToURL(Path file) {
- Path p;
- try {
- p = file.toRealPath();
- } catch (IOException e) {
- p = file.toAbsolutePath();
- }
- try {
- return p.normalize().toUri().toURL();
- } catch (MalformedURLException e) {
- return null;
- }
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ExecutableMemberDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,288 +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.lang.reflect.Modifier;
-import java.text.CollationKey;
-
-import com.sun.javadoc.*;
-
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
-
-/**
- * Represents a method or constructor of a java class.
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (generics, annotations)
- */
-
-public abstract class ExecutableMemberDocImpl
- extends MemberDocImpl implements ExecutableMemberDoc {
-
- protected final MethodSymbol sym;
-
- /**
- * Constructor.
- */
- public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
- super(env, sym, treePath);
- this.sym = sym;
- }
-
- /**
- * Constructor.
- */
- public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
- this(env, sym, null);
- }
-
- /**
- * Returns the flags in terms of javac's flags
- */
- protected long getFlags() {
- return sym.flags();
- }
-
- /**
- * Identify the containing class
- */
- protected ClassSymbol getContainingClass() {
- return sym.enclClass();
- }
-
- /**
- * Return true if this method is native
- */
- public boolean isNative() {
- return Modifier.isNative(getModifiers());
- }
-
- /**
- * Return true if this method is synchronized
- */
- public boolean isSynchronized() {
- return Modifier.isSynchronized(getModifiers());
- }
-
- /**
- * Return true if this method was declared to take a variable number
- * of arguments.
- */
- public boolean isVarArgs() {
- return ((sym.flags() & Flags.VARARGS) != 0
- && !env.legacyDoclet);
- }
-
- /**
- * Returns true if this field was synthesized by the compiler.
- */
- public boolean isSynthetic() {
- return ((sym.flags() & Flags.SYNTHETIC) != 0);
- }
-
- public boolean isIncluded() {
- return containingClass().isIncluded() && env.shouldDocument(sym);
- }
-
- /**
- * Return the throws tags in this method.
- *
- * @return an array of ThrowTagImpl containing all {@code @exception}
- * and {@code @throws} tags.
- */
- public ThrowsTag[] throwsTags() {
- return comment().throwsTags();
- }
-
- /**
- * Return the param tags in this method, excluding the type
- * parameter tags.
- *
- * @return an array of ParamTagImpl containing all {@code @param} tags.
- */
- public ParamTag[] paramTags() {
- return comment().paramTags();
- }
-
- /**
- * Return the type parameter tags in this method.
- */
- public ParamTag[] typeParamTags() {
- return env.legacyDoclet
- ? new ParamTag[0]
- : comment().typeParamTags();
- }
-
- /**
- * Return exceptions this method or constructor throws.
- *
- * @return an array of ClassDoc[] representing the exceptions
- * thrown by this method.
- */
- public ClassDoc[] thrownExceptions() {
- ListBuffer<ClassDocImpl> l = new ListBuffer<>();
- for (Type ex : sym.type.getThrownTypes()) {
- ex = env.types.erasure(ex);
- //### Will these casts succeed in the face of static semantic
- //### errors in the documented code?
- ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym);
- if (cdi != null) l.append(cdi);
- }
- return l.toArray(new ClassDocImpl[l.length()]);
- }
-
- /**
- * Return exceptions this method or constructor throws.
- * Each array element is either a <code>ClassDoc</code> or a
- * <code>TypeVariable</code>.
- */
- public com.sun.javadoc.Type[] thrownExceptionTypes() {
- return TypeMaker.getTypes(env, sym.type.getThrownTypes());
- }
-
- /**
- * Get argument information.
- *
- * @see ParameterImpl
- *
- * @return an array of ParameterImpl, one element per argument
- * in the order the arguments are present.
- */
- public Parameter[] parameters() {
- // generate the parameters on the fly: they're not cached
- List<VarSymbol> params = sym.params();
- Parameter result[] = new Parameter[params.length()];
-
- int i = 0;
- for (VarSymbol param : params) {
- result[i++] = new ParameterImpl(env, param);
- }
- return result;
- }
-
- /**
- * Get the receiver type of this executable element.
- *
- * @return the receiver type of this executable element.
- * @since 1.8
- */
- public com.sun.javadoc.Type receiverType() {
- Type recvtype = sym.type.asMethodType().recvtype;
- return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null;
- }
-
- /**
- * Return the formal type parameters of this method or constructor.
- * Return an empty array if there are none.
- */
- public TypeVariable[] typeParameters() {
- if (env.legacyDoclet) {
- return new TypeVariable[0];
- }
- TypeVariable res[] = new TypeVariable[sym.type.getTypeArguments().length()];
- TypeMaker.getTypes(env, sym.type.getTypeArguments(), res);
- return res;
- }
-
- /**
- * Get the signature. It is the parameter list, type is qualified.
- * For instance, for a method <code>mymethod(String x, int y)</code>,
- * it will return <code>(java.lang.String,int)</code>.
- */
- public String signature() {
- return makeSignature(true);
- }
-
- /**
- * Get flat signature. All types are not qualified.
- * Return a String, which is the flat signiture of this member.
- * It is the parameter list, type is not qualified.
- * For instance, for a method <code>mymethod(String x, int y)</code>,
- * it will return <code>(String, int)</code>.
- */
- public String flatSignature() {
- return makeSignature(false);
- }
-
- private String makeSignature(boolean full) {
- StringBuilder result = new StringBuilder();
- result.append("(");
- for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {
- Type t = types.head;
- result.append(TypeMaker.getTypeString(env, t, full));
- types = types.tail;
- if (types.nonEmpty()) {
- result.append(", ");
- }
- }
- if (isVarArgs()) {
- int len = result.length();
- result.replace(len - 2, len, "...");
- }
- result.append(")");
- return result.toString();
- }
-
- protected String typeParametersString() {
- return TypeMaker.typeParametersString(env, sym, true);
- }
-
- /**
- * Generate a key for sorting.
- */
- @Override
- CollationKey generateKey() {
- String k = name() + flatSignature() + typeParametersString();
- // ',' and '&' are between '$' and 'a': normalize to spaces.
- k = k.replace(',', ' ').replace('&', ' ');
- // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
- return env.doclocale.collator.getCollationKey(k);
- }
-
- /**
- * Return the source position of the entity, or null if
- * no position is available.
- */
- @Override
- public SourcePosition position() {
- if (sym.enclClass().sourcefile == null) return null;
- return SourcePositionImpl.make(sym.enclClass().sourcefile,
- (tree==null) ? 0 : tree.pos,
- lineMap);
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/FieldDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,279 +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.source.util.TreePath;
-import java.lang.reflect.Modifier;
-
-import com.sun.javadoc.*;
-
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Symbol.VarSymbol;
-
-import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
-
-/**
- * Represents a field in a java class.
- *
- * <p><b>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.</b>
- *
- * @see MemberDocImpl
- *
- * @since 1.2
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (generics, enums, annotations)
- */
-public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
-
- protected final VarSymbol sym;
-
- /**
- * Constructor.
- */
- public FieldDocImpl(DocEnv env, VarSymbol sym, TreePath treePath) {
- super(env, sym, treePath);
- this.sym = sym;
- }
-
- /**
- * Constructor.
- */
- public FieldDocImpl(DocEnv env, VarSymbol sym) {
- this(env, sym, null);
- }
-
- /**
- * Returns the flags in terms of javac's flags
- */
- protected long getFlags() {
- return sym.flags();
- }
-
- /**
- * Identify the containing class
- */
- protected ClassSymbol getContainingClass() {
- return sym.enclClass();
- }
-
- /**
- * Get type of this field.
- */
- public com.sun.javadoc.Type type() {
- return TypeMaker.getType(env, sym.type, false);
- }
-
- /**
- * Get the value of a constant field.
- *
- * @return the value of a constant field. The value is
- * automatically wrapped in an object if it has a primitive type.
- * If the field is not constant, returns null.
- */
- public Object constantValue() {
- Object result = sym.getConstValue();
- if (result != null && sym.type.hasTag(BOOLEAN))
- // javac represents false and true as Integers 0 and 1
- result = Boolean.valueOf(((Integer)result).intValue() != 0);
- return result;
- }
-
- /**
- * Get the value of a constant field.
- *
- * @return the text of a Java language expression whose value
- * is the value of the constant. The expression uses no identifiers
- * other than primitive literals. If the field is
- * not constant, returns null.
- */
- public String constantValueExpression() {
- return constantValueExpression(constantValue());
- }
-
- /**
- * A static version of the above.
- */
- static String constantValueExpression(Object cb) {
- if (cb == null) return null;
- if (cb instanceof Character) return sourceForm(((Character)cb).charValue());
- if (cb instanceof Byte) return sourceForm(((Byte)cb).byteValue());
- if (cb instanceof String) return sourceForm((String)cb);
- if (cb instanceof Double) return sourceForm(((Double)cb).doubleValue(), 'd');
- if (cb instanceof Float) return sourceForm(((Float)cb).doubleValue(), 'f');
- if (cb instanceof Long) return cb + "L";
- return cb.toString(); // covers int, short
- }
- // where
- private static String sourceForm(double v, char suffix) {
- if (Double.isNaN(v))
- return "0" + suffix + "/0" + suffix;
- if (v == Double.POSITIVE_INFINITY)
- return "1" + suffix + "/0" + suffix;
- if (v == Double.NEGATIVE_INFINITY)
- return "-1" + suffix + "/0" + suffix;
- return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : "");
- }
- private static String sourceForm(char c) {
- StringBuilder buf = new StringBuilder(8);
- buf.append('\'');
- sourceChar(c, buf);
- buf.append('\'');
- return buf.toString();
- }
- private static String sourceForm(byte c) {
- return "0x" + Integer.toString(c & 0xff, 16);
- }
- private static String sourceForm(String s) {
- StringBuilder buf = new StringBuilder(s.length() + 5);
- buf.append('\"');
- for (int i=0; i<s.length(); i++) {
- char c = s.charAt(i);
- sourceChar(c, buf);
- }
- buf.append('\"');
- return buf.toString();
- }
- private static void sourceChar(char c, StringBuilder buf) {
- switch (c) {
- case '\b': buf.append("\\b"); return;
- case '\t': buf.append("\\t"); return;
- case '\n': buf.append("\\n"); return;
- case '\f': buf.append("\\f"); return;
- case '\r': buf.append("\\r"); return;
- case '\"': buf.append("\\\""); return;
- case '\'': buf.append("\\\'"); return;
- case '\\': buf.append("\\\\"); return;
- default:
- if (isPrintableAscii(c)) {
- buf.append(c); return;
- }
- unicodeEscape(c, buf);
- return;
- }
- }
- private static void unicodeEscape(char c, StringBuilder buf) {
- final String chars = "0123456789abcdef";
- buf.append("\\u");
- buf.append(chars.charAt(15 & (c>>12)));
- buf.append(chars.charAt(15 & (c>>8)));
- buf.append(chars.charAt(15 & (c>>4)));
- buf.append(chars.charAt(15 & (c>>0)));
- }
- private static boolean isPrintableAscii(char c) {
- return c >= ' ' && c <= '~';
- }
-
- /**
- * Return true if this field is included in the active set.
- */
- public boolean isIncluded() {
- return containingClass().isIncluded() && env.shouldDocument(sym);
- }
-
- /**
- * Is this Doc item a field (but not an enum constant?
- */
- @Override
- public boolean isField() {
- return !isEnumConstant();
- }
-
- /**
- * Is this Doc item an enum constant?
- * (For legacy doclets, return false.)
- */
- @Override
- public boolean isEnumConstant() {
- return (getFlags() & Flags.ENUM) != 0 &&
- !env.legacyDoclet;
- }
-
- /**
- * Return true if this field is transient
- */
- public boolean isTransient() {
- return Modifier.isTransient(getModifiers());
- }
-
- /**
- * Return true if this field is volatile
- */
- public boolean isVolatile() {
- return Modifier.isVolatile(getModifiers());
- }
-
- /**
- * Returns true if this field was synthesized by the compiler.
- */
- public boolean isSynthetic() {
- return (getFlags() & Flags.SYNTHETIC) != 0;
- }
-
- /**
- * Return the serialField tags in this FieldDocImpl item.
- *
- * @return an array of <tt>SerialFieldTagImpl</tt> containing all
- * <code>@serialField</code> tags.
- */
- public SerialFieldTag[] serialFieldTags() {
- return comment().serialFieldTags();
- }
-
- public String name() {
- if (name == null) {
- name = sym.name.toString();
- }
- return name;
- }
-
- private String name;
-
- public String qualifiedName() {
- if (qualifiedName == null) {
- qualifiedName = sym.enclClass().getQualifiedName() + "." + name();
- }
- return qualifiedName;
- }
-
- private String qualifiedName;
-
- /**
- * Return the source position of the entity, or null if
- * no position is available.
- */
- @Override
- public SourcePosition position() {
- if (sym.enclClass().sourcefile == null) return null;
- return SourcePositionImpl.make(sym.enclClass().sourcefile,
- (tree==null) ? 0 : tree.pos,
- lineMap);
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocClassFinder.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) 2001, 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 java.util.EnumSet;
-import javax.tools.JavaFileObject;
-
-import com.sun.tools.javac.code.Symbol.PackageSymbol;
-import com.sun.tools.javac.code.ClassFinder;
-import com.sun.tools.javac.util.Context;
-
-/** Javadoc uses an extended class finder that records package.html entries
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter
- */
-public class JavadocClassFinder extends ClassFinder {
-
- public static JavadocClassFinder instance(Context context) {
- ClassFinder instance = context.get(classFinderKey);
- if (instance == null)
- instance = new JavadocClassFinder(context);
- return (JavadocClassFinder)instance;
- }
-
- public static void preRegister(Context context) {
- context.put(classFinderKey, new Context.Factory<ClassFinder>() {
- public ClassFinder make(Context c) {
- return new JavadocClassFinder(c);
- }
- });
- }
-
- private DocEnv docenv;
- private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,
- JavaFileObject.Kind.SOURCE,
- JavaFileObject.Kind.HTML);
- private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS,
- JavaFileObject.Kind.HTML);
-
- public JavadocClassFinder(Context context) {
- super(context);
- docenv = DocEnv.instance(context);
- preferSource = true;
- }
-
- /**
- * Override getPackageFileKinds to include search for package.html
- */
- @Override
- protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
- return docenv.docClasses ? noSource : all;
- }
-
- /**
- * Override extraFileActions to check for package documentation
- */
- @Override
- protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
- if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))
- docenv.getPackageDoc(pack).setDocPath(fo);
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocEnter.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2001, 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 javax.tools.JavaFileObject;
-
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.comp.Enter;
-import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
-import com.sun.tools.javac.util.List;
-
-import static com.sun.tools.javac.code.Kinds.Kind.*;
-
-/**
- * Javadoc's own enter phase does a few things above and beyond that
- * done by javac.
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter
- */
-public class JavadocEnter extends Enter {
- public static JavadocEnter instance(Context context) {
- Enter instance = context.get(enterKey);
- if (instance == null)
- instance = new JavadocEnter(context);
- return (JavadocEnter)instance;
- }
-
- public static void preRegister(Context context) {
- context.put(enterKey, new Context.Factory<Enter>() {
- public Enter make(Context c) {
- return new JavadocEnter(c);
- }
- });
- }
-
- protected JavadocEnter(Context context) {
- super(context);
- messager = Messager.instance0(context);
- docenv = DocEnv.instance(context);
- }
-
- final Messager messager;
- final DocEnv docenv;
-
- @Override
- public void main(List<JCCompilationUnit> trees) {
- // count all Enter errors as warnings.
- int nerrors = messager.nerrors;
- super.main(trees);
- messager.nwarnings += (messager.nerrors - nerrors);
- messager.nerrors = nerrors;
- }
-
- @Override
- public void visitTopLevel(JCCompilationUnit tree) {
- super.visitTopLevel(tree);
- if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
- JCPackageDecl pd = tree.getPackage();
- TreePath tp = pd == null ? docenv.getTreePath(tree) : docenv.getTreePath(tree, pd);
- docenv.makePackageDoc(tree.packge, tp);
- }
- }
-
- @Override
- public void visitClassDef(JCClassDecl tree) {
- super.visitClassDef(tree);
- if (tree.sym == null) return;
- if (tree.sym.kind == TYP || tree.sym.kind == ERR) {
- ClassSymbol c = tree.sym;
- docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree));
- }
- }
-
- /** Don't complain about a duplicate class. */
- @Override
- protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {}
-
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,209 +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.source.util.TreePath;
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.comp.MemberEnter;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.*;
-import com.sun.tools.javac.util.Context;
-
-import static com.sun.tools.javac.code.Flags.*;
-import static com.sun.tools.javac.code.Kinds.Kind.*;
-
-/**
- * Javadoc's own memberEnter phase does a few things above and beyond that
- * done by javac.
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter
- */
-public class JavadocMemberEnter extends MemberEnter {
- public static JavadocMemberEnter instance0(Context context) {
- MemberEnter instance = context.get(memberEnterKey);
- if (instance == null)
- instance = new JavadocMemberEnter(context);
- return (JavadocMemberEnter)instance;
- }
-
- public static void preRegister(Context context) {
- context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
- public MemberEnter make(Context c) {
- return new JavadocMemberEnter(c);
- }
- });
- }
-
- final DocEnv docenv;
-
- protected JavadocMemberEnter(Context context) {
- super(context);
- docenv = DocEnv.instance(context);
- }
-
- @Override
- public void visitMethodDef(JCMethodDecl tree) {
- super.visitMethodDef(tree);
- MethodSymbol meth = tree.sym;
- if (meth == null || meth.kind != MTH) return;
- TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree);
- if (meth.isConstructor())
- docenv.makeConstructorDoc(meth, treePath);
- else if (isAnnotationTypeElement(meth))
- docenv.makeAnnotationTypeElementDoc(meth, treePath);
- else
- docenv.makeMethodDoc(meth, treePath);
-
- // release resources
- tree.body = null;
- }
-
- @Override
- public void visitVarDef(JCVariableDecl tree) {
- if (tree.init != null) {
- boolean isFinal = (tree.mods.flags & FINAL) != 0
- || (env.enclClass.mods.flags & INTERFACE) != 0;
- if (!isFinal || containsNonConstantExpression(tree.init)) {
- // Avoid unnecessary analysis and release resources.
- // In particular, remove non-constant expressions
- // which may trigger Attr.attribClass, since
- // method bodies are also removed, in visitMethodDef.
- tree.init = null;
- }
- }
- super.visitVarDef(tree);
- if (tree.sym != null &&
- tree.sym.kind == VAR &&
- !isParameter(tree.sym)) {
- docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree));
- }
- }
-
- private static boolean isAnnotationTypeElement(MethodSymbol meth) {
- return ClassDocImpl.isAnnotationType(meth.enclClass());
- }
-
- private static boolean isParameter(VarSymbol var) {
- return (var.flags() & Flags.PARAMETER) != 0;
- }
-
- /**
- * Simple analysis of an expression tree to see if it contains tree nodes
- * for any non-constant expression. This does not include checking references
- * to other fields which may or may not be constant.
- */
- private static boolean containsNonConstantExpression(JCExpression tree) {
- return new MaybeConstantExpressionScanner().containsNonConstantExpression(tree);
- }
-
- /**
- * See JLS 15.18, Constant Expression
- */
- private static class MaybeConstantExpressionScanner extends JCTree.Visitor {
- boolean maybeConstantExpr = true;
-
- public boolean containsNonConstantExpression(JCExpression tree) {
- scan(tree);
- return !maybeConstantExpr;
- }
-
- public void scan(JCTree tree) {
- // short circuit scan when end result is definitely false
- if (maybeConstantExpr && tree != null)
- tree.accept(this);
- }
-
- @Override
- /** default for any non-overridden visit method. */
- public void visitTree(JCTree tree) {
- maybeConstantExpr = false;
- }
-
- @Override
- public void visitBinary(JCBinary tree) {
- switch (tree.getTag()) {
- case MUL: case DIV: case MOD:
- case PLUS: case MINUS:
- case SL: case SR: case USR:
- case LT: case LE: case GT: case GE:
- case EQ: case NE:
- case BITAND: case BITXOR: case BITOR:
- case AND: case OR:
- break;
- default:
- maybeConstantExpr = false;
- }
- }
-
- @Override
- public void visitConditional(JCConditional tree) {
- scan(tree.cond);
- scan(tree.truepart);
- scan(tree.falsepart);
- }
-
- @Override
- public void visitIdent(JCIdent tree) { }
-
- @Override
- public void visitLiteral(JCLiteral tree) { }
-
- @Override
- public void visitParens(JCParens tree) {
- scan(tree.expr);
- }
-
- @Override
- public void visitSelect(JCTree.JCFieldAccess tree) {
- scan(tree.selected);
- }
-
- @Override
- public void visitTypeCast(JCTypeCast tree) {
- scan(tree.clazz);
- scan(tree.expr);
- }
-
- @Override
- public void visitTypeIdent(JCPrimitiveTypeTree tree) { }
-
- @Override
- public void visitUnary(JCUnary tree) {
- switch (tree.getTag()) {
- case POS: case NEG: case COMPL: case NOT:
- break;
- default:
- maybeConstantExpr = false;
- }
- }
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocTodo.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2003, 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 com.sun.tools.javac.comp.*;
-import com.sun.tools.javac.util.*;
-
-/**
- * Javadoc's own todo queue doesn't queue its inputs, as javadoc
- * doesn't perform attribution of method bodies or semantic checking.
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter
- */
-public class JavadocTodo extends Todo {
- public static void preRegister(Context context) {
- context.put(todoKey, new Context.Factory<Todo>() {
- public Todo make(Context c) {
- return new JavadocTodo(c);
- }
- });
- }
-
- protected JavadocTodo(Context context) {
- super(context);
- }
-
- @Override
- public void append(Env<AttrContext> e) {
- // do nothing; Javadoc doesn't perform attribution.
- }
-
- @Override
- public boolean offer(Env<AttrContext> e) {
- return false;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,430 +0,0 @@
-/*
- * Copyright (c) 2001, 2016, 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.util.Collection;
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileManager.Location;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.StandardLocation;
-
-import com.sun.tools.javac.code.ClassFinder;
-import com.sun.tools.javac.code.Symbol.Completer;
-import com.sun.tools.javac.code.Symbol.ModuleSymbol;
-import com.sun.tools.javac.comp.Enter;
-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.util.Abort;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
-
-
-/**
- * This class could be the main entry point for Javadoc when Javadoc is used as a
- * component in a larger software system. It provides operations to
- * construct a new javadoc processor, and to run it on a set of source
- * files.
- *
- * <p><b>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.</b>
- *
- * @author Neal Gafter
- */
-public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
- DocEnv docenv;
-
- final Messager messager;
- final ClassFinder javadocFinder;
- final Enter javadocEnter;
- final Set<JavaFileObject> uniquefiles;
-
- /**
- * Construct a new JavaCompiler processor, using appropriately
- * extended phases of the underlying compiler.
- */
- protected JavadocTool(Context context) {
- super(context);
- messager = Messager.instance0(context);
- javadocFinder = JavadocClassFinder.instance(context);
- javadocEnter = JavadocEnter.instance(context);
- uniquefiles = new HashSet<>();
- }
-
- /**
- * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler.
- */
- @Override
- protected boolean keepComments() {
- return true;
- }
-
- /**
- * Construct a new javadoc tool.
- */
- public static JavadocTool make0(Context context) {
- // force the use of Javadoc's class finder
- JavadocClassFinder.preRegister(context);
-
- // force the use of Javadoc's own enter phase
- JavadocEnter.preRegister(context);
-
- // force the use of Javadoc's own member enter phase
- JavadocMemberEnter.preRegister(context);
-
- // force the use of Javadoc's own todo phase
- JavadocTodo.preRegister(context);
-
- // force the use of Messager as a Log
- Messager.instance0(context);
-
- return new JavadocTool(context);
- }
-
- public RootDocImpl getRootDocImpl(String doclocale,
- String encoding,
- ModifierFilter filter,
- List<String> args,
- List<String[]> options,
- Iterable<? extends JavaFileObject> fileObjects,
- boolean breakiterator,
- List<String> subPackages,
- List<String> excludedPackages,
- boolean docClasses,
- boolean legacyDoclet,
- boolean quiet) throws IOException {
- docenv = DocEnv.instance(context);
- docenv.showAccess = filter;
- docenv.quiet = quiet;
- docenv.breakiterator = breakiterator;
- docenv.setLocale(doclocale);
- docenv.setEncoding(encoding);
- docenv.docClasses = docClasses;
- docenv.legacyDoclet = legacyDoclet;
-
- javadocFinder.sourceCompleter = docClasses ? Completer.NULL_COMPLETER : sourceCompleter;
-
- if (docClasses) {
- // If -Xclasses is set, the args should be a series of class names
- for (String arg: args) {
- if (!isValidPackageName(arg)) // checks
- docenv.error(null, "main.illegal_class_name", arg);
- }
- if (messager.nerrors() != 0) {
- return null;
- }
- return new RootDocImpl(docenv, args, options);
- }
-
- ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<>();
- Set<String> includedPackages = new LinkedHashSet<>();
-
- try {
- StandardJavaFileManager fm = docenv.fileManager instanceof StandardJavaFileManager
- ? (StandardJavaFileManager) docenv.fileManager : null;
- Set<String> packageNames = new LinkedHashSet<>();
- // Normally, the args should be a series of package names or file names.
- // Parse the files and collect the package names.
- for (String arg: args) {
- if (fm != null && arg.endsWith(".java") && new File(arg).exists()) {
- if (new File(arg).getName().equals("module-info.java")) {
- docenv.warning(null, "main.file_ignored", arg);
- } else {
- parse(fm.getJavaFileObjects(arg), classTrees, true);
- }
- } else if (isValidPackageName(arg)) {
- packageNames.add(arg);
- } else if (arg.endsWith(".java")) {
- if (fm == null)
- throw new IllegalArgumentException();
- else
- docenv.error(null, "main.file_not_found", arg);
- } else {
- docenv.error(null, "main.illegal_package_name", arg);
- }
- }
-
- // Parse file objects provide via the DocumentationTool API
- parse(fileObjects, classTrees, true);
- modules.enter(classTrees.toList(), null);
-
- syms.unnamedModule.complete(); // TEMP to force reading all named modules
-
- // Build up the complete list of any packages to be documented
- Location location =
- modules.multiModuleMode && !modules.noModules ? StandardLocation.MODULE_SOURCE_PATH
- : docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH
- : StandardLocation.CLASS_PATH;
-
- PackageTable t = new PackageTable(docenv.fileManager, location)
- .packages(packageNames)
- .subpackages(subPackages, excludedPackages);
-
- includedPackages = t.getIncludedPackages();
-
- // Parse the files in the packages to be documented
- ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
- for (String packageName: includedPackages) {
- List<JavaFileObject> files = t.getFiles(packageName);
- docenv.notice("main.Loading_source_files_for_package", packageName);
-
- if (files.isEmpty())
- messager.warning(Messager.NOPOS, "main.no_source_files_for_package", packageName);
- parse(files, packageTrees, false);
- }
- modules.enter(packageTrees.toList(), null);
-
- if (messager.nerrors() != 0) {
- return null;
- }
-
- // Enter symbols for all files
- docenv.notice("main.Building_tree");
- javadocEnter.main(classTrees.toList().appendList(packageTrees.toList()));
- enterDone = true;
- } catch (Abort ex) {}
-
- if (messager.nerrors() != 0)
- return null;
-
- return new RootDocImpl(docenv, listClasses(classTrees.toList()), List.from(includedPackages), options);
- }
-
- /** Is the given string a valid package name? */
- boolean isValidPackageName(String s) {
- int index;
- while ((index = s.indexOf('.')) != -1) {
- if (!isValidClassName(s.substring(0, index))) return false;
- s = s.substring(index+1);
- }
- return isValidClassName(s);
- }
-
- private void parse(Iterable<? extends JavaFileObject> files, ListBuffer<JCCompilationUnit> trees,
- boolean trace) {
- for (JavaFileObject fo: files) {
- if (uniquefiles.add(fo)) { // ignore duplicates
- if (trace)
- docenv.notice("main.Loading_source_file", fo.getName());
- trees.append(parse(fo));
- }
- }
- }
-
- /** Are surrogates supported?
- */
- final static boolean surrogatesSupported = surrogatesSupported();
- private static boolean surrogatesSupported() {
- try {
- boolean b = Character.isHighSurrogate('a');
- return true;
- } catch (NoSuchMethodError ex) {
- return false;
- }
- }
-
- /**
- * Return true if given file name is a valid class name
- * (including "package-info").
- * @param s the name of the class to check.
- * @return true if given class name is a valid class name
- * and false otherwise.
- */
- public static boolean isValidClassName(String s) {
- if (s.length() < 1) return false;
- if (s.equals("package-info")) return true;
- if (surrogatesSupported) {
- int cp = s.codePointAt(0);
- if (!Character.isJavaIdentifierStart(cp))
- return false;
- for (int j=Character.charCount(cp); j<s.length(); j+=Character.charCount(cp)) {
- cp = s.codePointAt(j);
- if (!Character.isJavaIdentifierPart(cp))
- return false;
- }
- } else {
- if (!Character.isJavaIdentifierStart(s.charAt(0)))
- return false;
- for (int j=1; j<s.length(); j++)
- if (!Character.isJavaIdentifierPart(s.charAt(j)))
- return false;
- }
- return true;
- }
-
- /**
- * From a list of top level trees, return the list of contained class definitions
- */
- List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
- ListBuffer<JCClassDecl> result = new ListBuffer<>();
- for (JCCompilationUnit t : trees) {
- for (JCTree def : t.defs) {
- if (def.hasTag(JCTree.Tag.CLASSDEF))
- result.append((JCClassDecl)def);
- }
- }
- return result.toList();
- }
-
- /**
- * A table to manage included and excluded packages.
- */
- class PackageTable {
- private final Map<String, Entry> entries = new LinkedHashMap<>();
- private final Set<String> includedPackages = new LinkedHashSet<>();
- private final JavaFileManager fm;
- private final Location location;
- private final Set<JavaFileObject.Kind> sourceKinds = EnumSet.of(JavaFileObject.Kind.SOURCE);
-
- /**
- * Creates a table to manage included and excluded packages.
- * @param fm The file manager used to locate source files
- * @param locn the location used to locate source files
- */
- PackageTable(JavaFileManager fm, Location locn) {
- this.fm = fm;
- this.location = locn;
- getEntry("").excluded = false;
- }
-
- PackageTable packages(Collection<String> packageNames) {
- includedPackages.addAll(packageNames);
- return this;
- }
-
- PackageTable subpackages(Collection<String> packageNames, Collection<String> excludePackageNames)
- throws IOException {
- for (String p: excludePackageNames) {
- getEntry(p).excluded = true;
- }
-
- for (String packageName: packageNames) {
- Location packageLocn = getLocation(packageName);
- for (JavaFileObject fo: fm.list(packageLocn, packageName, sourceKinds, true)) {
- String binaryName = fm.inferBinaryName(packageLocn, fo);
- String pn = getPackageName(binaryName);
- String simpleName = getSimpleName(binaryName);
- Entry e = getEntry(pn);
- if (!e.isExcluded() && isValidClassName(simpleName)) {
- includedPackages.add(pn);
- e.files = (e.files == null ? List.of(fo) : e.files.prepend(fo));
- }
- }
- }
- return this;
- }
-
- /**
- * Returns the aggregate set of included packages.
- * @return the aggregate set of included packages
- */
- Set<String> getIncludedPackages() {
- return includedPackages;
- }
-
- /**
- * Returns the set of source files for a package.
- * @param packageName the specified package
- * @return the set of file objects for the specified package
- * @throws IOException if an error occurs while accessing the files
- */
- List<JavaFileObject> getFiles(String packageName) throws IOException {
- Entry e = getEntry(packageName);
- // The files may have been found as a side effect of searching for subpackages
- if (e.files != null)
- return e.files;
-
- ListBuffer<JavaFileObject> lb = new ListBuffer<>();
- Location packageLocn = getLocation(packageName);
- for (JavaFileObject fo: fm.list(packageLocn, packageName, sourceKinds, false)) {
- String binaryName = fm.inferBinaryName(packageLocn, fo);
- String simpleName = getSimpleName(binaryName);
- if (isValidClassName(simpleName)) {
- lb.append(fo);
- }
- }
-
- return lb.toList();
- }
-
- private Location getLocation(String packageName) throws IOException {
- if (location == StandardLocation.MODULE_SOURCE_PATH) {
- // TODO: handle invalid results
- ModuleSymbol msym = syms.inferModule(names.fromString(packageName));
- return fm.getModuleLocation(location, msym.name.toString());
- } else {
- return location;
- }
- }
-
- private Entry getEntry(String name) {
- Entry e = entries.get(name);
- if (e == null)
- entries.put(name, e = new Entry(name));
- return e;
- }
-
- private String getPackageName(String name) {
- int lastDot = name.lastIndexOf(".");
- return (lastDot == -1 ? "" : name.substring(0, lastDot));
- }
-
- private String getSimpleName(String name) {
- int lastDot = name.lastIndexOf(".");
- return (lastDot == -1 ? name : name.substring(lastDot + 1));
- }
-
- class Entry {
- final String name;
- Boolean excluded;
- List<JavaFileObject> files;
-
- Entry(String name) {
- this.name = name;
- }
-
- boolean isExcluded() {
- if (excluded == null)
- excluded = getEntry(getPackageName(name)).isExcluded();
- return excluded;
- }
- }
- }
-
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Main.java Wed Jul 05 21:41:01 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Main.java Mon May 09 16:52:15 2016 -0700
@@ -27,6 +27,8 @@
import java.io.PrintWriter;
+import com.sun.tools.javadoc.main.Start;
+
/**
* Provides external entry points (tool and programmatic)
* for the javadoc program.
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/MemberDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1997, 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 com.sun.javadoc.*;
-
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Symbol;
-
-/**
- * Represents a member of a java class: field, constructor, or method.
- * This is an abstract class dealing with information common to
- * method, constructor and field members. Class members of a class
- * (nested classes) are represented instead by ClassDocImpl.
- *
- * <p><b>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.</b>
- *
- * @see MethodDocImpl
- * @see FieldDocImpl
- * @see ClassDocImpl
- *
- * @author Robert Field
- * @author Neal Gafter
- */
-
-public abstract class MemberDocImpl
- extends ProgramElementDocImpl
- implements MemberDoc {
-
- /**
- * constructor.
- */
- public MemberDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
- super(env, sym, treePath);
- }
-
- /**
- * Returns true if this field was synthesized by the compiler.
- */
- public abstract boolean isSynthetic();
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Messager.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,323 +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.PrintWriter;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-import com.sun.javadoc.*;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.JCDiagnostic;
-import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
-import com.sun.tools.javac.util.JavacMessages;
-import com.sun.tools.javac.util.Log;
-
-/**
- * Utility for integrating with javadoc tools and for localization.
- * Handle Resources. Access to error and warning counts.
- * Message formatting.
- * <br>
- * Also provides implementation for DocErrorReporter.
- *
- * <p><b>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.</b>
- *
- * @see java.util.ResourceBundle
- * @see java.text.MessageFormat
- * @author Neal Gafter (rewrite)
- */
-public class Messager extends Log implements DocErrorReporter {
- public static final SourcePosition NOPOS = null;
-
- /** Get the current messager, which is also the compiler log. */
- public static Messager instance0(Context context) {
- Log instance = context.get(logKey);
- if (instance == null || !(instance instanceof Messager))
- throw new InternalError("no messager instance!");
- return (Messager)instance;
- }
-
- public static void preRegister(Context context,
- final String programName) {
- context.put(logKey, new Context.Factory<Log>() {
- public Log make(Context c) {
- return new Messager(c,
- programName);
- }
- });
- }
- public static void preRegister(Context context,
- final String programName,
- final PrintWriter errWriter,
- final PrintWriter warnWriter,
- final PrintWriter noticeWriter) {
- context.put(logKey, new Context.Factory<Log>() {
- public Log make(Context c) {
- return new Messager(c,
- programName,
- errWriter,
- warnWriter,
- noticeWriter);
- }
- });
- }
-
- public class ExitJavadoc extends Error {
- private static final long serialVersionUID = 0;
- }
-
- final String programName;
-
- private Locale locale;
- private final JavacMessages messages;
- private final JCDiagnostic.Factory javadocDiags;
-
- /** The default writer for diagnostics
- */
- static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
- static final PrintWriter defaultWarnWriter = new PrintWriter(System.err);
- static final PrintWriter defaultNoticeWriter = new PrintWriter(System.out);
-
- /**
- * Constructor
- * @param programName Name of the program (for error messages).
- */
- protected Messager(Context context, String programName) {
- this(context, programName, defaultErrWriter, defaultWarnWriter, defaultNoticeWriter);
- }
-
- /**
- * Constructor
- * @param programName Name of the program (for error messages).
- * @param errWriter Stream for error messages
- * @param warnWriter Stream for warnings
- * @param noticeWriter Stream for other messages
- */
- @SuppressWarnings("deprecation")
- protected Messager(Context context,
- String programName,
- PrintWriter errWriter,
- PrintWriter warnWriter,
- PrintWriter noticeWriter) {
- super(context, errWriter, warnWriter, noticeWriter);
- messages = JavacMessages.instance(context);
- messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc",
- locale));
- javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
- this.programName = programName;
-
- }
-
- public void setLocale(Locale locale) {
- this.locale = locale;
- }
-
- /**
- * get and format message string from resource
- *
- * @param key selects message from resource
- * @param args arguments for the message
- */
- String getText(String key, Object... args) {
- return messages.getLocalizedString(locale, key, args);
- }
-
- /**
- * Print error message, increment error count.
- * Part of DocErrorReporter.
- *
- * @param msg message to print
- */
- public void printError(String msg) {
- printError(null, msg);
- }
-
- /**
- * Print error message, increment error count.
- * Part of DocErrorReporter.
- *
- * @param pos the position where the error occurs
- * @param msg message to print
- */
- public void printError(SourcePosition pos, String msg) {
- if (diagListener != null) {
- report(DiagnosticType.ERROR, pos, msg);
- return;
- }
-
- if (nerrors < MaxErrors) {
- String prefix = (pos == null) ? programName : pos.toString();
- errWriter.println(prefix + ": " + getText("javadoc.error") + " - " + msg);
- errWriter.flush();
- prompt();
- nerrors++;
- }
- }
-
- /**
- * Print warning message, increment warning count.
- * Part of DocErrorReporter.
- *
- * @param msg message to print
- */
- public void printWarning(String msg) {
- printWarning(null, msg);
- }
-
- /**
- * Print warning message, increment warning count.
- * Part of DocErrorReporter.
- *
- * @param pos the position where the error occurs
- * @param msg message to print
- */
- public void printWarning(SourcePosition pos, String msg) {
- if (diagListener != null) {
- report(DiagnosticType.WARNING, pos, msg);
- return;
- }
-
- if (nwarnings < MaxWarnings) {
- String prefix = (pos == null) ? programName : pos.toString();
- warnWriter.println(prefix + ": " + getText("javadoc.warning") +" - " + msg);
- warnWriter.flush();
- nwarnings++;
- }
- }
-
- /**
- * Print a message.
- * Part of DocErrorReporter.
- *
- * @param msg message to print
- */
- public void printNotice(String msg) {
- printNotice(null, msg);
- }
-
- /**
- * Print a message.
- * Part of DocErrorReporter.
- *
- * @param pos the position where the error occurs
- * @param msg message to print
- */
- public void printNotice(SourcePosition pos, String msg) {
- if (diagListener != null) {
- report(DiagnosticType.NOTE, pos, msg);
- return;
- }
-
- if (pos == null)
- noticeWriter.println(msg);
- else
- noticeWriter.println(pos + ": " + msg);
- noticeWriter.flush();
- }
-
- /**
- * Print error message, increment error count.
- *
- * @param key selects message from resource
- */
- public void error(SourcePosition pos, String key, Object... args) {
- printError(pos, getText(key, args));
- }
-
- /**
- * Print warning message, increment warning count.
- *
- * @param key selects message from resource
- */
- public void warning(SourcePosition pos, String key, Object... args) {
- printWarning(pos, getText(key, args));
- }
-
- /**
- * Print a message.
- *
- * @param key selects message from resource
- */
- public void notice(String key, Object... args) {
- printNotice(getText(key, args));
- }
-
- /**
- * Return total number of errors, including those recorded
- * in the compilation log.
- */
- public int nerrors() { return nerrors; }
-
- /**
- * Return total number of warnings, including those recorded
- * in the compilation log.
- */
- public int nwarnings() { return nwarnings; }
-
- /**
- * Print exit message.
- */
- public void exitNotice() {
- if (nerrors > 0) {
- notice((nerrors > 1) ? "main.errors" : "main.error",
- "" + nerrors);
- }
- if (nwarnings > 0) {
- notice((nwarnings > 1) ? "main.warnings" : "main.warning",
- "" + nwarnings);
- }
- }
-
- /**
- * Force program exit, e.g., from a fatal error.
- * <p>
- * TODO: This method does not really belong here.
- */
- public void exit() {
- throw new ExitJavadoc();
- }
-
- private void report(DiagnosticType type, SourcePosition pos, String msg) {
- switch (type) {
- case ERROR:
- case WARNING:
- Object prefix = (pos == null) ? programName : pos;
- report(javadocDiags.create(type, null, null, "msg", prefix, msg));
- break;
-
- case NOTE:
- String key = (pos == null) ? "msg" : "pos.msg";
- report(javadocDiags.create(type, null, null, key, pos, msg));
- break;
-
- default:
- throw new IllegalArgumentException(type.toString());
- }
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/MethodDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,246 +0,0 @@
-/*
- * Copyright (c) 1997, 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 java.lang.reflect.Modifier;
-
-import com.sun.javadoc.*;
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.*;
-import com.sun.tools.javac.code.Symbol.*;
-import com.sun.tools.javac.code.Type;
-import static com.sun.tools.javac.code.TypeTag.CLASS;
-
-/**
- * Represents a method of a java class.
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- */
-
-public class MethodDocImpl
- extends ExecutableMemberDocImpl implements MethodDoc {
-
- /**
- * constructor.
- */
- public MethodDocImpl(DocEnv env, MethodSymbol sym) {
- super(env, sym);
- }
-
- /**
- * constructor.
- */
- public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
- super(env, sym, treePath);
- }
-
- /**
- * Return true if it is a method, which it is.
- * Note: constructors are not methods.
- * This method is overridden by AnnotationTypeElementDocImpl.
- *
- * @return true
- */
- public boolean isMethod() {
- return true;
- }
-
- /**
- * Return true if this method is default
- */
- public boolean isDefault() {
- return (sym.flags() & Flags.DEFAULT) != 0;
- }
-
- /**
- * Return true if this method is abstract
- */
- public boolean isAbstract() {
- return (Modifier.isAbstract(getModifiers()) && !isDefault());
- }
-
- /**
- * Get return type.
- *
- * @return the return type of this method, null if it
- * is a constructor.
- */
- public com.sun.javadoc.Type returnType() {
- return TypeMaker.getType(env, sym.type.getReturnType(), false);
- }
-
- /**
- * Return the class that originally defined the method that
- * is overridden by the current definition, or null if no
- * such class exists.
- *
- * @return a ClassDocImpl representing the superclass that
- * originally defined this method, null if this method does
- * not override a definition in a superclass.
- */
- public ClassDoc overriddenClass() {
- com.sun.javadoc.Type t = overriddenType();
- return (t != null) ? t.asClassDoc() : null;
- }
-
- /**
- * Return the type containing the method that this method overrides.
- * It may be a <code>ClassDoc</code> or a <code>ParameterizedType</code>.
- */
- public com.sun.javadoc.Type overriddenType() {
-
- if ((sym.flags() & Flags.STATIC) != 0) {
- return null;
- }
-
- ClassSymbol origin = (ClassSymbol)sym.owner;
- for (Type t = env.types.supertype(origin.type);
- t.hasTag(CLASS);
- t = env.types.supertype(t)) {
- ClassSymbol c = (ClassSymbol)t.tsym;
- for (Symbol sym2 : membersOf(c).getSymbolsByName(sym.name)) {
- if (sym.overrides(sym2, origin, env.types, true)) {
- return TypeMaker.getType(env, t);
- }
- }
- }
- return null;
- }
-
- /**
- * Return the method that this method overrides.
- *
- * @return a MethodDoc representing a method definition
- * in a superclass this method overrides, null if
- * this method does not override.
- */
- public MethodDoc overriddenMethod() {
-
- // Real overriding only. Static members are simply hidden.
- // Likewise for constructors, but the MethodSymbol.overrides
- // method takes this into account.
- if ((sym.flags() & Flags.STATIC) != 0) {
- return null;
- }
-
- // Derived from com.sun.tools.javac.comp.Check.checkOverride .
-
- ClassSymbol origin = (ClassSymbol)sym.owner;
- for (Type t = env.types.supertype(origin.type);
- t.hasTag(CLASS);
- t = env.types.supertype(t)) {
- ClassSymbol c = (ClassSymbol)t.tsym;
- for (Symbol sym2 : membersOf(c).getSymbolsByName(sym.name)) {
- if (sym.overrides(sym2, origin, env.types, true)) {
- return env.getMethodDoc((MethodSymbol)sym2);
- }
- }
- }
- return null;
- }
-
- /**Retrieve members of c, ignoring any CompletionFailures that occur. */
- private Scope membersOf(ClassSymbol c) {
- try {
- return c.members();
- } catch (CompletionFailure cf) {
- /* 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 membersOf(c);
- }
- }
-
- /**
- * Tests whether this method overrides another.
- * The overridden method may be one declared in a superclass or
- * a superinterface (unlike {@link #overriddenMethod()}).
- *
- * <p> When a non-abstract method overrides an abstract one, it is
- * also said to <i>implement</i> the other.
- *
- * @param meth the other method to examine
- * @return <tt>true</tt> if this method overrides the other
- */
- public boolean overrides(MethodDoc meth) {
- MethodSymbol overridee = ((MethodDocImpl) meth).sym;
- ClassSymbol origin = (ClassSymbol) sym.owner;
-
- return sym.name == overridee.name &&
-
- // not reflexive as per JLS
- sym != overridee &&
-
- // we don't care if overridee is static, though that wouldn't
- // compile
- !sym.isStatic() &&
-
- // sym, whose declaring type is the origin, must be
- // in a subtype of overridee's type
- env.types.asSuper(origin.type, overridee.owner) != null &&
-
- // check access and signatures; don't check return types
- sym.overrides(overridee, origin, env.types, false);
- }
-
-
- public String name() {
- if (name == null) {
- name = sym.name.toString();
- }
- return name;
- }
-
- private String name;
-
- public String qualifiedName() {
- if (qualifiedName == null) {
- qualifiedName = sym.enclClass().getQualifiedName() + "." + sym.name;
- }
- return qualifiedName;
- }
-
- private String qualifiedName;
-
- /**
- * Returns a string representation of this method. Includes the
- * qualified signature, the qualified method name, and any type
- * parameters. Type parameters follow the class name, as they do
- * in the syntax for invoking methods with explicit type parameters.
- */
- public String toString() {
- return sym.enclClass().getQualifiedName() +
- "." + typeParametersString() + name() + signature();
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ModifierFilter.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) 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 static com.sun.tools.javac.code.Flags.*;
-
-/**
- * A class whose instances are filters over Modifier bits.
- * Filtering is done by returning boolean values.
- * Classes, methods and fields can be filtered, or filtering
- * can be done directly on modifier bits.
- *
- * <p><b>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.</b>
- *
- * @see com.sun.tools.javac.code.Flags
- * @author Robert Field
- */
-
-public class ModifierFilter {
-
- /**
- * Package private access.
- * A "pseudo-" modifier bit that can be used in the
- * constructors of this class to specify package private
- * access. This is needed since there is no Modifier.PACKAGE.
- */
- public static final long PACKAGE = 0x8000000000000000L;
-
- /**
- * All access modifiers.
- * A short-hand set of modifier bits that can be used in the
- * constructors of this class to specify all access modifiers,
- * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE.
- */
- public static final long ALL_ACCESS =
- PRIVATE | PROTECTED | PUBLIC | PACKAGE;
-
- private long oneOf;
- private long must;
- private long cannot;
-
- private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC;
-
- /**
- * Constructor - Specify a filter.
- *
- * @param oneOf If zero, everything passes the filter.
- * If non-zero, at least one of the specified
- * bits must be on in the modifier bits to
- * pass the filter.
- */
- public ModifierFilter(long oneOf) {
- this(oneOf, 0, 0);
- }
-
- /**
- * Constructor - Specify a filter.
- * For example, the filter below will only pass synchronized
- * methods that are private or package private access and are
- * not native or static.
- * <pre>
- * ModifierFilter( Modifier.PRIVATE | ModifierFilter.PACKAGE,
- * Modifier.SYNCHRONIZED,
- * Modifier.NATIVE | Modifier.STATIC)
- * </pre><p>
- * Each of the three arguments must either be
- * zero or the or'ed combination of the bits specified in the
- * class Modifier or this class. During filtering, these values
- * are compared against the modifier bits as follows:
- *
- * @param oneOf If zero, ignore this argument.
- * If non-zero, at least one of the bits must be on.
- * @param must All bits specified must be on.
- * @param cannot None of the bits specified can be on.
- */
- public ModifierFilter(long oneOf, long must, long cannot) {
- this.oneOf = oneOf;
- this.must = must;
- this.cannot = cannot;
- }
-
- /**
- * Filter on modifier bits.
- *
- * @param modifierBits Bits as specified in the Modifier class
- *
- * @return Whether the modifierBits pass this filter.
- */
- public boolean checkModifier(int modifierBits) {
- // Add in the "pseudo-" modifier bit PACKAGE, if needed
- long fmod = ((modifierBits & ACCESS_BITS) == 0) ?
- modifierBits | PACKAGE :
- modifierBits;
- return ((oneOf == 0) || ((oneOf & fmod) != 0)) &&
- ((must & fmod) == must) &&
- ((cannot & fmod) == 0);
- }
-
-} // end ModifierFilter
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/PackageDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,389 +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.IOException;
-import java.io.InputStream;
-
-import javax.tools.FileObject;
-
-import com.sun.javadoc.*;
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Attribute;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Symbol.PackageSymbol;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-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.Position;
-
-import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
-
-/**
- * Represents a java package. Provides access to information
- * about the package, the package's comment and tags, and the
- * classes in the package.
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Kaiyang Liu (original)
- * @author Robert Field (rewrite)
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (package-info.java)
- */
-
-public class PackageDocImpl extends DocImpl implements PackageDoc {
-
- public final PackageSymbol sym;
- private JCCompilationUnit tree = null; // for source position
-
- public FileObject docPath = null;
- private boolean foundDoc; // found a doc comment in either
- // package.html or package-info.java
-
- boolean isIncluded = false; // Set in RootDocImpl.
- public boolean setDocPath = false; //Flag to avoid setting doc path multiple times.
-
- /**
- * Constructor
- */
- public PackageDocImpl(DocEnv env, PackageSymbol sym) {
- this(env, sym, null);
- }
-
- /**
- * Constructor
- */
- public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
- super(env, treePath);
- this.sym = sym;
- this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
- foundDoc = (documentation != null);
- }
-
- void setTree(JCTree tree) {
- this.tree = (JCCompilationUnit) tree;
- }
-
- public void setTreePath(TreePath treePath) {
- super.setTreePath(treePath);
- checkDoc();
- }
-
- /**
- * Do lazy initialization of "documentation" string.
- */
- protected String documentation() {
- if (documentation != null)
- return documentation;
- if (docPath != null) {
- // read from file
- try {
- InputStream s = docPath.openInputStream();
- documentation = readHTMLDocumentation(s, docPath);
- } catch (IOException exc) {
- documentation = "";
- env.error(null, "javadoc.File_Read_Error", docPath.getName());
- }
- } else {
- // no doc file to be had
- documentation = "";
- }
- return documentation;
- }
-
- /**
- * Cache of all classes contained in this package, including
- * member classes of those classes, and their member classes, etc.
- * Includes only those classes at the specified protection level
- * and weaker.
- */
- private List<ClassDocImpl> allClassesFiltered = null;
-
- /**
- * Cache of all classes contained in this package, including
- * member classes of those classes, and their member classes, etc.
- */
- private List<ClassDocImpl> allClasses = null;
-
- /**
- * Return a list of all classes contained in this package, including
- * member classes of those classes, and their member classes, etc.
- */
- private List<ClassDocImpl> getClasses(boolean filtered) {
- if (allClasses != null && !filtered) {
- return allClasses;
- }
- if (allClassesFiltered != null && filtered) {
- return allClassesFiltered;
- }
- ListBuffer<ClassDocImpl> classes = new ListBuffer<>();
- for (Symbol enumerated : sym.members().getSymbols(NON_RECURSIVE)) {
- if (enumerated != null) {
- ClassSymbol s = (ClassSymbol)enumerated;
- ClassDocImpl c = env.getClassDoc(s);
- if (c != null && !c.isSynthetic())
- c.addAllClasses(classes, filtered);
- }
- }
- if (filtered)
- return allClassesFiltered = classes.toList();
- else
- return allClasses = classes.toList();
- }
-
- /**
- * Add all included classes (including Exceptions and Errors)
- * and interfaces.
- */
- public void addAllClassesTo(ListBuffer<ClassDocImpl> list) {
- list.appendList(getClasses(true));
- }
-
- /**
- * Get all classes (including Exceptions and Errors)
- * and interfaces.
- * @since J2SE1.4.
- *
- * @return all classes and interfaces in this package, filtered to include
- * only the included classes if filter==true.
- */
- public ClassDoc[] allClasses(boolean filter) {
- List<ClassDocImpl> classes = getClasses(filter);
- return classes.toArray(new ClassDocImpl[classes.length()]);
- }
-
- /**
- * Get all included classes (including Exceptions and Errors)
- * and interfaces. Same as allClasses(true).
- *
- * @return all included classes and interfaces in this package.
- */
- public ClassDoc[] allClasses() {
- return allClasses(true);
- }
-
- /**
- * Get ordinary classes (that is, exclude exceptions, errors,
- * enums, interfaces, and annotation types) in this package.
- *
- * @return included ordinary classes in this package.
- */
- public ClassDoc[] ordinaryClasses() {
- ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isOrdinaryClass()) {
- ret.append(c);
- }
- }
- return ret.toArray(new ClassDocImpl[ret.length()]);
- }
-
- /**
- * Get Exception classes in this package.
- *
- * @return included Exceptions in this package.
- */
- public ClassDoc[] exceptions() {
- ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isException()) {
- ret.append(c);
- }
- }
- return ret.toArray(new ClassDocImpl[ret.length()]);
- }
-
- /**
- * Get Error classes in this package.
- *
- * @return included Errors in this package.
- */
- public ClassDoc[] errors() {
- ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isError()) {
- ret.append(c);
- }
- }
- return ret.toArray(new ClassDocImpl[ret.length()]);
- }
-
- /**
- * Get included enum types in this package.
- *
- * @return included enum types in this package.
- */
- public ClassDoc[] enums() {
- ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isEnum()) {
- ret.append(c);
- }
- }
- return ret.toArray(new ClassDocImpl[ret.length()]);
- }
-
- /**
- * Get included interfaces in this package, omitting annotation types.
- *
- * @return included interfaces in this package.
- */
- public ClassDoc[] interfaces() {
- ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isInterface()) {
- ret.append(c);
- }
- }
- return ret.toArray(new ClassDocImpl[ret.length()]);
- }
-
- /**
- * Get included annotation types in this package.
- *
- * @return included annotation types in this package.
- */
- public AnnotationTypeDoc[] annotationTypes() {
- ListBuffer<AnnotationTypeDocImpl> ret = new ListBuffer<>();
- for (ClassDocImpl c : getClasses(true)) {
- if (c.isAnnotationType()) {
- ret.append((AnnotationTypeDocImpl)c);
- }
- }
- return ret.toArray(new AnnotationTypeDocImpl[ret.length()]);
- }
-
- /**
- * Get the annotations of this package.
- * Return an empty array if there are none.
- */
- public AnnotationDesc[] annotations() {
- AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
- int i = 0;
- for (Attribute.Compound a : sym.getRawAttributes()) {
- res[i++] = new AnnotationDescImpl(env, a);
- }
- return res;
- }
-
-
- /**
- * Lookup for a class within this package.
- *
- * @return ClassDocImpl of found class, or null if not found.
- */
- public ClassDoc findClass(String className) {
- final boolean filtered = true;
- for (ClassDocImpl c : getClasses(filtered)) {
- if (c.name().equals(className)) {
- return c;
- }
- }
- return null;
- }
-
- /**
- * Return true if this package is included in the active set.
- */
- public boolean isIncluded() {
- return isIncluded;
- }
-
- /**
- * Get package name.
- *
- * Note that we do not provide a means of obtaining the simple
- * name of a package -- package names are always returned in their
- * uniquely qualified form.
- */
- public String name() {
- return qualifiedName();
- }
-
- /**
- * Get package name.
- */
- public String qualifiedName() {
- if (qualifiedName == null) {
- Name fullname = sym.getQualifiedName();
- // Some bogus tests depend on the interned "" being returned.
- // See 6457276.
- qualifiedName = fullname.isEmpty() ? "" : fullname.toString();
- }
- return qualifiedName;
- }
-
- private String qualifiedName;
-
- /**
- * set doc path for an unzipped directory
- */
- public void setDocPath(FileObject path) {
- setDocPath = true;
- if (path == null)
- return;
- if (!path.equals(docPath)) {
- docPath = path;
- checkDoc();
- }
- }
-
- // Has checkDoc() sounded off yet?
- private boolean checkDocWarningEmitted = false;
-
- /**
- * Invoked when a source of package doc comments is located.
- * Emits a diagnostic if this is the second one.
- */
- private void checkDoc() {
- if (foundDoc) {
- if (!checkDocWarningEmitted) {
- env.warning(null, "javadoc.Multiple_package_comments", name());
- checkDocWarningEmitted = true;
- }
- } else {
- foundDoc = true;
- }
- }
-
- /**
- * Return the source position of the entity, or null if
- * no position is available.
- */
- public SourcePosition position() {
- return (tree != null)
- ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
- : SourcePositionImpl.make(docPath, Position.NOPOS, null);
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ParamTagImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 1997, 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.util.regex.*;
-
-import com.sun.javadoc.*;
-
-/**
- * Represents an @param documentation tag.
- * Parses and stores the name and comment parts of the parameter tag.
- *
- * <p><b>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.</b>
- *
- * @author Robert Field
- *
- */
-class ParamTagImpl extends TagImpl implements ParamTag {
-
- private static final Pattern typeParamRE = Pattern.compile("<([^<>]+)>");
-
- private final String parameterName;
- private final String parameterComment;
- private final boolean isTypeParameter;
-
- /**
- * Cached inline tags.
- */
- private Tag[] inlineTags;
-
- ParamTagImpl(DocImpl holder, String name, String text) {
- super(holder, name, text);
- String[] sa = divideAtWhite();
-
- Matcher m = typeParamRE.matcher(sa[0]);
- isTypeParameter = m.matches();
- parameterName = isTypeParameter ? m.group(1) : sa[0];
- parameterComment = sa[1];
- }
-
- /**
- * Return the parameter name.
- */
- public String parameterName() {
- return parameterName;
- }
-
- /**
- * Return the parameter comment.
- */
- public String parameterComment() {
- return parameterComment;
- }
-
- /**
- * Return the kind of this tag.
- */
- @Override
- public String kind() {
- return "@param";
- }
-
- /**
- * Return true if this ParamTag corresponds to a type parameter.
- */
- public boolean isTypeParameter() {
- return isTypeParameter;
- }
-
- /**
- * convert this object to a string.
- */
- @Override
- public String toString() {
- return name + ":" + text;
- }
-
- /**
- * For the parameter comment with embedded @link tags return the array of
- * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
- *
- * @return TagImpl[] Array of tags with inline SeeTagImpls.
- * @see TagImpl#inlineTags()
- * @see ThrowsTagImpl#inlineTags()
- */
- @Override
- public Tag[] inlineTags() {
- if (inlineTags == null) {
- inlineTags = Comment.getInlineTags(holder, parameterComment);
- }
- return inlineTags;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ParameterImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 1997, 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 com.sun.javadoc.*;
-
-import com.sun.tools.javac.code.Attribute;
-import com.sun.tools.javac.code.Symbol.VarSymbol;
-
-/**
- * ParameterImpl information.
- * This includes a parameter type and parameter name.
- *
- * <p><b>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.</b>
- *
- * @author Kaiyang Liu (original)
- * @author Robert Field (rewrite)
- * @author Scott Seligman (generics, annotations)
- */
-class ParameterImpl implements Parameter {
-
- private final DocEnv env;
- private final VarSymbol sym;
- private final com.sun.javadoc.Type type;
-
- /**
- * Constructor of parameter info class.
- */
- ParameterImpl(DocEnv env, VarSymbol sym) {
- this.env = env;
- this.sym = sym;
- this.type = TypeMaker.getType(env, sym.type, false);
- }
-
- /**
- * Get the type of this parameter.
- */
- public com.sun.javadoc.Type type() {
- return type;
- }
-
- /**
- * Get local name of this parameter.
- * For example if parameter is the short 'index', returns "index".
- */
- public String name() {
- return sym.toString();
- }
-
- /**
- * Get type name of this parameter.
- * For example if parameter is the short 'index', returns "short".
- */
- public String typeName() {
- return (type instanceof ClassDoc || type instanceof TypeVariable)
- ? type.typeName() // omit formal type params or bounds
- : type.toString();
- }
-
- /**
- * Returns a string representation of the parameter.
- * <p>
- * For example if parameter is the short 'index', returns "short index".
- *
- * @return type name and parameter name of this parameter.
- */
- public String toString() {
- return typeName() + " " + sym;
- }
-
- /**
- * Get the annotations of this parameter.
- * Return an empty array if there are none.
- */
- public AnnotationDesc[] annotations() {
- AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
- int i = 0;
- for (Attribute.Compound a : sym.getRawAttributes()) {
- res[i++] = new AnnotationDescImpl(env, a);
- }
- return res;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ParameterizedTypeImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2003, 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 com.sun.javadoc.*;
-
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.code.Type.ClassType;
-
-import static com.sun.tools.javac.code.TypeTag.CLASS;
-
-
-/**
- * Implementation of <code>ParameterizedType</code>, which
- * represents an invocation of a generic class or interface.
- *
- * <p><b>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.</b>
- *
- * @author Scott Seligman
- * @since 1.5
- */
-public class ParameterizedTypeImpl
- extends AbstractTypeImpl implements ParameterizedType {
-
- ParameterizedTypeImpl(DocEnv env, Type type) {
- super(env, type);
- }
-
- /**
- * Return the generic class or interface that declared this type.
- */
- @Override
- public ClassDoc asClassDoc() {
- return env.getClassDoc((ClassSymbol)type.tsym);
- }
-
- /**
- * Return the actual type arguments of this type.
- */
- public com.sun.javadoc.Type[] typeArguments() {
- return TypeMaker.getTypes(env, type.getTypeArguments());
- }
-
- /**
- * Return the class type that is a direct supertype of this one.
- * Return null if this is an interface type.
- */
- public com.sun.javadoc.Type superclassType() {
- if (asClassDoc().isInterface()) {
- return null;
- }
- Type sup = env.types.supertype(type);
- return TypeMaker.getType(env,
- (sup != type) ? sup : env.syms.objectType);
- }
-
- /**
- * Return the interface types directly implemented by or extended by this
- * parameterized type.
- * Return an empty array if there are no interfaces.
- */
- public com.sun.javadoc.Type[] interfaceTypes() {
- return TypeMaker.getTypes(env, env.types.interfaces(type));
- }
-
- /**
- * Return the type that contains this type as a member.
- * Return null is this is a top-level type.
- */
- public com.sun.javadoc.Type containingType() {
- if (type.getEnclosingType().hasTag(CLASS)) {
- // This is the type of an inner class.
- return TypeMaker.getType(env, type.getEnclosingType());
- }
- ClassSymbol enclosing = type.tsym.owner.enclClass();
- if (enclosing != null) {
- // Nested but not inner. Return the ClassDoc of the enclosing
- // class or interface.
- // See java.lang.reflect.ParameterizedType.getOwnerType().
- return env.getClassDoc(enclosing);
- }
- return null;
- }
-
-
- // Asking for the "name" of a parameterized type doesn't exactly make
- // sense. It's a type expression. Return the name of its generic
- // type.
- @Override
- public String typeName() {
- return TypeMaker.getTypeName(type, false);
- }
-
- @Override
- public ParameterizedType asParameterizedType() {
- return this;
- }
-
- @Override
- public String toString() {
- return parameterizedTypeToString(env, (ClassType)type, true);
- }
-
- static String parameterizedTypeToString(DocEnv env, ClassType cl,
- boolean full) {
- if (env.legacyDoclet) {
- return TypeMaker.getTypeName(cl, full);
- }
- StringBuilder s = new StringBuilder();
- if (!(cl.getEnclosingType().hasTag(CLASS))) { // if not an inner class...
- s.append(TypeMaker.getTypeName(cl, full));
- } else {
- ClassType encl = (ClassType)cl.getEnclosingType();
- s.append(parameterizedTypeToString(env, encl, full))
- .append('.')
- .append(cl.tsym.name.toString());
- }
- s.append(TypeMaker.typeArgumentsString(env, cl, full));
- return s.toString();
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/PrimitiveType.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2001, 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.*;
-
-/**
- * <p><b>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.</b>
- */
-class PrimitiveType implements com.sun.javadoc.Type {
-
- private final String name;
-
- static final PrimitiveType voidType = new PrimitiveType("void");
- static final PrimitiveType booleanType = new PrimitiveType("boolean");
- static final PrimitiveType byteType = new PrimitiveType("byte");
- static final PrimitiveType charType = new PrimitiveType("char");
- static final PrimitiveType shortType = new PrimitiveType("short");
- static final PrimitiveType intType = new PrimitiveType("int");
- static final PrimitiveType longType = new PrimitiveType("long");
- static final PrimitiveType floatType = new PrimitiveType("float");
- static final PrimitiveType doubleType = new PrimitiveType("double");
-
- // error type, should never actually be used
- static final PrimitiveType errorType = new PrimitiveType("");
-
- PrimitiveType(String name) {
- this.name = name;
- }
-
- /**
- * Return unqualified name of type excluding any dimension information.
- * <p>
- * For example, a two dimensional array of String returns 'String'.
- */
- public String typeName() {
- return name;
- }
-
- public com.sun.javadoc.Type getElementType() {
- return null;
- }
-
- /**
- * Return qualified name of type excluding any dimension information.
- *<p>
- * For example, a two dimensional array of String
- * returns 'java.lang.String'.
- */
- public String qualifiedTypeName() {
- return name;
- }
-
- /**
- * Return the simple name of this type.
- */
- public String simpleTypeName() {
- return name;
- }
-
- /**
- * Return the type's dimension information, as a string.
- * <p>
- * For example, a two dimensional array of String returns '[][]'.
- */
- public String dimension() {
- return "";
- }
-
- /**
- * Return this type as a class. Array dimensions are ignored.
- *
- * @return a ClassDocImpl if the type is a Class.
- * Return null if it is a primitive type..
- */
- public ClassDoc asClassDoc() {
- return null;
- }
-
- /**
- * Return null, as this is not an annotation type.
- */
- public AnnotationTypeDoc asAnnotationTypeDoc() {
- return null;
- }
-
- /**
- * Return null, as this is not an 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;
- }
-
- /**
- * Return null, as this is not an annotated type.
- */
- public AnnotatedType asAnnotatedType() {
- return null;
- }
-
- /**
- * Returns a string representation of the type.
- *
- * Return name of type including any dimension information.
- * <p>
- * For example, a two dimensional array of String returns
- * <code>String[][]</code>.
- *
- * @return name of type including any dimension information.
- */
- public String toString() {
- return qualifiedTypeName();
- }
-
- /**
- * Return true if this is a primitive type.
- */
- public boolean isPrimitive() {
- return true;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ProgramElementDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-/*
- * Copyright (c) 1997, 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.lang.reflect.Modifier;
-import java.text.CollationKey;
-
-import com.sun.javadoc.*;
-import com.sun.source.util.TreePath;
-import com.sun.tools.javac.code.Attribute;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-import com.sun.tools.javac.util.Position;
-
-/**
- * Represents a java program element: class, interface, field,
- * constructor, or method.
- * This is an abstract class dealing with information common to
- * these elements.
- *
- * <p><b>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.</b>
- *
- * @see MemberDocImpl
- * @see ClassDocImpl
- *
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- * @author Scott Seligman (generics, enums, annotations)
- */
-public abstract class ProgramElementDocImpl
- extends DocImpl implements ProgramElementDoc {
-
- private final Symbol sym;
-
- // For source position information.
- JCTree tree = null;
- Position.LineMap lineMap = null;
-
-
- // Cache for getModifiers().
- private int modifiers = -1;
-
- protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
- super(env, treePath);
- this.sym = sym;
- if (treePath != null) {
- tree = (JCTree) treePath.getLeaf();
- lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
- }
- }
-
- @Override
- void setTreePath(TreePath treePath) {
- super.setTreePath(treePath);
- this.tree = (JCTree) treePath.getLeaf();
- this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
- }
-
- /**
- * Subclasses override to identify the containing class
- */
- protected abstract ClassSymbol getContainingClass();
-
- /**
- * Returns the flags in terms of javac's flags
- */
- abstract protected long getFlags();
-
- /**
- * Returns the modifier flags in terms of java.lang.reflect.Modifier.
- */
- protected int getModifiers() {
- if (modifiers == -1) {
- modifiers = DocEnv.translateModifiers(getFlags());
- }
- return modifiers;
- }
-
- /**
- * Get the containing class of this program element.
- *
- * @return a ClassDocImpl for this element's containing class.
- * If this is a class with no outer class, return null.
- */
- public ClassDoc containingClass() {
- if (getContainingClass() == null) {
- return null;
- }
- return env.getClassDoc(getContainingClass());
- }
-
- /**
- * Return the package that this member is contained in.
- * Return "" if in unnamed package.
- */
- public PackageDoc containingPackage() {
- return env.getPackageDoc(getContainingClass().packge());
- }
-
- /**
- * Get the modifier specifier integer.
- *
- * @see java.lang.reflect.Modifier
- */
- public int modifierSpecifier() {
- int modifiers = getModifiers();
- if (isMethod() && containingClass().isInterface())
- // Remove the implicit abstract modifier.
- return modifiers & ~Modifier.ABSTRACT;
- return modifiers;
- }
-
- /**
- * Get modifiers string.
- * <pre>
- * Example, for:
- * public abstract int foo() { ... }
- * modifiers() would return:
- * 'public abstract'
- * </pre>
- * Annotations are not included.
- */
- public String modifiers() {
- int modifiers = getModifiers();
- if (isAnnotationTypeElement() ||
- (isMethod() && containingClass().isInterface())) {
- // Remove the implicit abstract modifier.
- return Modifier.toString(modifiers & ~Modifier.ABSTRACT);
- } else {
- return Modifier.toString(modifiers);
- }
- }
-
- /**
- * Get the annotations of this program element.
- * Return an empty array if there are none.
- */
- public AnnotationDesc[] annotations() {
- AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
- int i = 0;
- for (Attribute.Compound a : sym.getRawAttributes()) {
- res[i++] = new AnnotationDescImpl(env, a);
- }
- return res;
- }
-
- /**
- * Return true if this program element is public
- */
- public boolean isPublic() {
- int modifiers = getModifiers();
- return Modifier.isPublic(modifiers);
- }
-
- /**
- * Return true if this program element is protected
- */
- public boolean isProtected() {
- int modifiers = getModifiers();
- return Modifier.isProtected(modifiers);
- }
-
- /**
- * Return true if this program element is private
- */
- public boolean isPrivate() {
- int modifiers = getModifiers();
- return Modifier.isPrivate(modifiers);
- }
-
- /**
- * Return true if this program element is package private
- */
- public boolean isPackagePrivate() {
- return !(isPublic() || isPrivate() || isProtected());
- }
-
- /**
- * Return true if this program element is static
- */
- public boolean isStatic() {
- int modifiers = getModifiers();
- return Modifier.isStatic(modifiers);
- }
-
- /**
- * Return true if this program element is final
- */
- public boolean isFinal() {
- int modifiers = getModifiers();
- return Modifier.isFinal(modifiers);
- }
-
- /**
- * Generate a key for sorting.
- */
- CollationKey generateKey() {
- String k = name();
- // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
- return env.doclocale.collator.getCollationKey(k);
- }
-
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/RootDocImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,394 +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.IOException;
-import java.util.Collection;
-import java.util.Locale;
-
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-
-import com.sun.javadoc.*;
-import com.sun.tools.javac.tree.JCTree.JCClassDecl;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Position;
-
-/**
- * This class holds the information from one run of javadoc.
- * Particularly the packages, classes and options specified
- * by the user.
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Robert Field
- * @author Atul M Dambalkar
- * @author Neal Gafter (rewrite)
- */
-public class RootDocImpl extends DocImpl implements RootDoc {
-
- /**
- * list of classes specified on the command line.
- */
- private List<ClassDocImpl> cmdLineClasses;
-
- /**
- * list of packages specified on the command line.
- */
- private List<PackageDocImpl> cmdLinePackages;
-
- /**
- * a collection of all options.
- */
- private List<String[]> options;
-
- /**
- * Constructor used when reading source files.
- *
- * @param env the documentation environment, state for this javadoc run
- * @param classes list of classes specified on the commandline
- * @param packages list of package names specified on the commandline
- * @param options list of options
- */
- public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages, List<String[]> options) {
- super(env, null);
- this.options = options;
- setPackages(env, packages);
- setClasses(env, classes);
- }
-
- /**
- * Constructor used when reading class files.
- *
- * @param env the documentation environment, state for this javadoc run
- * @param classes list of class names specified on the commandline
- * @param options list of options
- */
- public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) {
- super(env, null);
- this.options = options;
- cmdLinePackages = List.nil();
- ListBuffer<ClassDocImpl> classList = new ListBuffer<>();
- for (String className : classes) {
- ClassDocImpl c = env.loadClass(className);
- if (c == null)
- env.error(null, "javadoc.class_not_found", className);
- else
- classList = classList.append(c);
- }
- cmdLineClasses = classList.toList();
- }
-
- /**
- * Initialize classes information. Those classes are input from
- * command line.
- *
- * @param env the compilation environment
- * @param classes a list of ClassDeclaration
- */
- private void setClasses(DocEnv env, List<JCClassDecl> classes) {
- ListBuffer<ClassDocImpl> result = new ListBuffer<>();
- for (JCClassDecl def : classes) {
- //### Do we want modifier check here?
- if (env.shouldDocument(def.sym)) {
- ClassDocImpl cd = env.getClassDoc(def.sym);
- if (cd != null) {
- cd.isIncluded = true;
- result.append(cd);
- } //else System.out.println(" (classdoc is null)");//DEBUG
- } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
- }
- cmdLineClasses = result.toList();
- }
-
- /**
- * Initialize packages information.
- *
- * @param env the compilation environment
- * @param packages a list of package names (String)
- */
- private void setPackages(DocEnv env, List<String> packages) {
- ListBuffer<PackageDocImpl> packlist = new ListBuffer<>();
- for (String name : packages) {
- PackageDocImpl pkg = env.lookupPackage(name);
- if (pkg != null) {
- pkg.isIncluded = true;
- packlist.append(pkg);
- } else {
- env.warning(null, "main.no_source_files_for_package", name);
- }
- }
- cmdLinePackages = packlist.toList();
- }
-
- /**
- * Command line options.
- *
- * <pre>
- * For example, given:
- * javadoc -foo this that -bar other ...
- *
- * This method will return:
- * options()[0][0] = "-foo"
- * options()[0][1] = "this"
- * options()[0][2] = "that"
- * options()[1][0] = "-bar"
- * options()[1][1] = "other"
- * </pre>
- *
- * @return an array of arrays of String.
- */
- public String[][] options() {
- return options.toArray(new String[options.length()][]);
- }
-
- /**
- * Packages specified on the command line.
- */
- public PackageDoc[] specifiedPackages() {
- return (PackageDoc[])cmdLinePackages
- .toArray(new PackageDocImpl[cmdLinePackages.length()]);
- }
-
- /**
- * Classes and interfaces specified on the command line.
- */
- public ClassDoc[] specifiedClasses() {
- ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>();
- for (ClassDocImpl cd : cmdLineClasses) {
- cd.addAllClasses(classesToDocument, true);
- }
- return (ClassDoc[])classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
- }
-
- /**
- * Return all classes and interfaces (including those inside
- * packages) to be documented.
- */
- public ClassDoc[] classes() {
- ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>();
- for (ClassDocImpl cd : cmdLineClasses) {
- cd.addAllClasses(classesToDocument, true);
- }
- for (PackageDocImpl pd : cmdLinePackages) {
- pd.addAllClassesTo(classesToDocument);
- }
- return classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
- }
-
- /**
- * Return a ClassDoc for the specified class/interface name
- *
- * @param qualifiedName qualified class name
- * (i.e. includes package name).
- *
- * @return a ClassDocImpl holding the specified class, null if
- * this class is not referenced.
- */
- public ClassDoc classNamed(String qualifiedName) {
- return env.lookupClass(qualifiedName);
- }
-
- /**
- * Return a PackageDoc for the specified package name
- *
- * @param name package name
- *
- * @return a PackageDoc holding the specified package, null if
- * this package is not referenced.
- */
- public PackageDoc packageNamed(String name) {
- return env.lookupPackage(name);
- }
-
- /**
- * Return the name of this Doc item.
- *
- * @return the string <code>"*RootDocImpl*"</code>.
- */
- public String name() {
- return "*RootDocImpl*";
- }
-
- /**
- * Return the name of this Doc item.
- *
- * @return the string <code>"*RootDocImpl*"</code>.
- */
- public String qualifiedName() {
- return "*RootDocImpl*";
- }
-
- /**
- * Return true if this Doc is include in the active set.
- * RootDocImpl isn't even a program entity so it is always false.
- */
- public boolean isIncluded() {
- return false;
- }
-
- /**
- * Print error message, increment error count.
- *
- * @param msg message to print
- */
- public void printError(String msg) {
- env.printError(msg);
- }
-
- /**
- * Print error message, increment error count.
- *
- * @param msg message to print
- */
- public void printError(SourcePosition pos, String msg) {
- env.printError(pos, msg);
- }
-
- /**
- * Print warning message, increment warning count.
- *
- * @param msg message to print
- */
- public void printWarning(String msg) {
- env.printWarning(msg);
- }
-
- /**
- * Print warning message, increment warning count.
- *
- * @param msg message to print
- */
- public void printWarning(SourcePosition pos, String msg) {
- env.printWarning(pos, msg);
- }
-
- /**
- * Print a message.
- *
- * @param msg message to print
- */
- public void printNotice(String msg) {
- env.printNotice(msg);
- }
-
- /**
- * Print a message.
- *
- * @param msg message to print
- */
- public void printNotice(SourcePosition pos, String msg) {
- env.printNotice(pos, msg);
- }
-
- /**
- * Return the path of the overview file and null if it does not exist.
- * @return the path of the overview file and null if it does not exist.
- */
- private JavaFileObject getOverviewPath() {
- for (String[] opt : options) {
- if (opt[0].equals("-overview")) {
- if (env.fileManager instanceof StandardJavaFileManager) {
- StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
- return fm.getJavaFileObjects(opt[1]).iterator().next();
- }
- }
- }
- return null;
- }
-
- /**
- * Do lazy initialization of "documentation" string.
- */
- @Override
- protected String documentation() {
- if (documentation == null) {
- JavaFileObject overviewPath = getOverviewPath();
- if (overviewPath == null) {
- // no doc file to be had
- documentation = "";
- } else {
- // read from file
- try {
- documentation = readHTMLDocumentation(
- overviewPath.openInputStream(),
- overviewPath);
- } catch (IOException exc) {
- documentation = "";
- env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
- }
- }
- }
- return documentation;
- }
-
- /**
- * Return the source position of the entity, or null if
- * no position is available.
- */
- @Override
- public SourcePosition position() {
- JavaFileObject path;
- return ((path = getOverviewPath()) == null) ?
- null :
- SourcePositionImpl.make(path, Position.NOPOS, null);
- }
-
- /**
- * Return the locale provided by the user or the default locale value.
- */
- public Locale getLocale() {
- return env.doclocale.locale;
- }
-
- /**
- * Return the current file manager.
- */
- public JavaFileManager getFileManager() {
- return env.fileManager;
- }
-
- public void initDocLint(Collection<String> opts, Collection<String> customTagNames,
- String htmlVersion) {
- env.initDoclint(opts, customTagNames, htmlVersion);
- }
-
- public boolean isFunctionalInterface(AnnotationDesc annotationDesc) {
- return env.source.allowLambda()
- && annotationDesc.annotationType().qualifiedName().equals(
- env.syms.functionalInterfaceType.toString());
- }
-
- public boolean showTagMessages() {
- return env.showTagMessages();
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/SeeTagImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,542 +0,0 @@
-/*
- * Copyright (c) 1997, 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 java.io.File;
-import java.util.Locale;
-
-import com.sun.javadoc.*;
-import com.sun.tools.javac.code.Printer;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Type.CapturedType;
-import com.sun.tools.javac.util.*;
-
-import static com.sun.tools.javac.code.Kinds.Kind.*;
-
-/**
- * Represents a see also documentation tag.
- * The @see tag can be plain text, or reference a class or member.
- *
- * <p><b>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.</b>
- *
- * @author Kaiyang Liu (original)
- * @author Robert Field (rewrite)
- * @author Atul M Dambalkar
- *
- */
-class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
-
- //### TODO: Searching for classes, fields, and methods
- //### should follow the normal rules applied by the compiler.
-
- /**
- * where of where#what - i.e. the class name (may be empty)
- */
- private String where;
-
- /**
- * what of where#what - i.e. the member (may be null)
- */
- private String what;
-
- private PackageDoc referencedPackage;
- private ClassDoc referencedClass;
- private MemberDoc referencedMember;
-
- String label = "";
-
- SeeTagImpl(DocImpl holder, String name, String text) {
- super(holder, name, text);
- parseSeeString();
- if (where != null) {
- ClassDocImpl container = null;
- if (holder instanceof MemberDoc) {
- container =
- (ClassDocImpl)((ProgramElementDoc)holder).containingClass();
- } else if (holder instanceof ClassDoc) {
- container = (ClassDocImpl)holder;
- }
- findReferenced(container);
- if (showRef) showRef();
- }
- }
-
- private static final boolean showRef = false;
-
- private void showRef() {
- Symbol sym;
- if (referencedMember != null) {
- if (referencedMember instanceof MethodDocImpl)
- sym = ((MethodDocImpl) referencedMember).sym;
- else if (referencedMember instanceof FieldDocImpl)
- sym = ((FieldDocImpl) referencedMember).sym;
- else
- sym = ((ConstructorDocImpl) referencedMember).sym;
- } else if (referencedClass != null) {
- sym = ((ClassDocImpl) referencedClass).tsym;
- } else if (referencedPackage != null) {
- sym = ((PackageDocImpl) referencedPackage).sym;
- } else
- return;
-
- final JavacMessages messages = JavacMessages.instance(docenv().context);
- Locale locale = Locale.getDefault();
- Printer printer = new Printer() {
- int count;
- @Override
- protected String localize(Locale locale, String key, Object... args) {
- return messages.getLocalizedString(locale, key, args);
- }
- @Override
- protected String capturedVarId(CapturedType t, Locale locale) {
- return "CAP#" + (++count);
- }
- };
-
- String s = text.replaceAll("\\s+", " "); // normalize white space
- int sp = s.indexOf(" ");
- int lparen = s.indexOf("(");
- int rparen = s.indexOf(")");
- String seetext = (sp == -1) ? s
- : (lparen == -1 || sp < lparen) ? s.substring(0, sp)
- : s.substring(0, rparen + 1);
-
- File file = new File(holder.position().file().getAbsoluteFile().toURI().normalize());
-
- StringBuilder sb = new StringBuilder();
- sb.append("+++ ").append(file).append(": ")
- .append(name()).append(" ").append(seetext).append(": ");
- sb.append(sym.getKind()).append(" ");
- if (sym.kind == MTH || sym.kind == VAR)
- sb.append(printer.visit(sym.owner, locale)).append(".");
- sb.append(printer.visit(sym, locale));
-
- System.err.println(sb);
- }
-
- /**
- * get the class name part of @see, For instance,
- * if the comment is @see String#startsWith(java.lang.String) .
- * This function returns String.
- * Returns null if format was not that of java reference.
- * Return empty string if class name was not specified..
- */
- public String referencedClassName() {
- return where;
- }
-
- /**
- * get the package referenced by @see. For instance,
- * if the comment is @see java.lang
- * This function returns a PackageDocImpl for java.lang
- * Returns null if no known package found.
- */
- public PackageDoc referencedPackage() {
- return referencedPackage;
- }
-
- /**
- * get the class referenced by the class name part of @see, For instance,
- * if the comment is @see String#startsWith(java.lang.String) .
- * This function returns a ClassDocImpl for java.lang.String.
- * Returns null if class is not a class specified on the javadoc command line..
- */
- public ClassDoc referencedClass() {
- return referencedClass;
- }
-
- /**
- * get the name of the member referenced by the prototype part of @see,
- * For instance,
- * if the comment is @see String#startsWith(java.lang.String) .
- * This function returns "startsWith(java.lang.String)"
- * Returns null if format was not that of java reference.
- * Return empty string if member name was not specified..
- */
- public String referencedMemberName() {
- return what;
- }
-
- /**
- * get the member referenced by the prototype part of @see,
- * For instance,
- * if the comment is @see String#startsWith(java.lang.String) .
- * This function returns a MethodDocImpl for startsWith.
- * Returns null if member could not be determined.
- */
- public MemberDoc referencedMember() {
- return referencedMember;
- }
-
-
- /**
- * parse @see part of comment. Determine 'where' and 'what'
- */
- private void parseSeeString() {
- int len = text.length();
- if (len == 0) {
- return;
- }
- switch (text.charAt(0)) {
- case '<':
- if (text.charAt(len-1) != '>') {
- docenv().warning(holder,
- "tag.see.no_close_bracket_on_url",
- name, text);
- }
- return;
- case '"':
- if (len == 1 || text.charAt(len-1) != '"') {
- docenv().warning(holder,
- "tag.see.no_close_quote",
- name, text);
- } else {
-// text = text.substring(1,len-1); // strip quotes
- }
- return;
- }
-
- // check that the text is one word, with possible parentheses
- // this part of code doesn't allow
- // @see <a href=.....>asfd</a>
- // comment it.
-
- // the code assumes that there is no initial white space.
- int parens = 0;
- int commentstart = 0;
- int start = 0;
- int cp;
- for (int i = start; i < len ; i += Character.charCount(cp)) {
- cp = text.codePointAt(i);
- switch (cp) {
- case '(': parens++; break;
- case ')': parens--; break;
- case '[': case ']': case '.': case '#': break;
- case ',':
- if (parens <= 0) {
- docenv().warning(holder,
- "tag.see.malformed_see_tag",
- name, text);
- return;
- }
- break;
- case ' ': case '\t': case '\n': case CR:
- if (parens == 0) { //here onwards the comment starts.
- commentstart = i;
- i = len;
- }
- break;
- default:
- if (!Character.isJavaIdentifierPart(cp)) {
- docenv().warning(holder,
- "tag.see.illegal_character",
- name, ""+cp, text);
- }
- break;
- }
- }
- if (parens != 0) {
- docenv().warning(holder,
- "tag.see.malformed_see_tag",
- name, text);
- return;
- }
-
- String seetext = "";
- String labeltext = "";
-
- if (commentstart > 0) {
- seetext = text.substring(start, commentstart);
- labeltext = text.substring(commentstart + 1);
- // strip off the white space which can be between seetext and the
- // actual label.
- for (int i = 0; i < labeltext.length(); i++) {
- char ch2 = labeltext.charAt(i);
- if (!(ch2 == ' ' || ch2 == '\t' || ch2 == '\n')) {
- label = labeltext.substring(i);
- break;
- }
- }
- } else {
- seetext = text;
- label = "";
- }
-
- int sharp = seetext.indexOf('#');
- if (sharp >= 0) {
- // class#member
- where = seetext.substring(0, sharp);
- what = seetext.substring(sharp + 1);
- } else {
- if (seetext.indexOf('(') >= 0) {
- docenv().warning(holder,
- "tag.see.missing_sharp",
- name, text);
- where = "";
- what = seetext;
- }
- else {
- // no member specified, text names class
- where = seetext;
- what = null;
- }
- }
- }
-
- /**
- * Find what is referenced by the see also. If possible, sets
- * referencedClass and referencedMember.
- *
- * @param containingClass the class containing the comment containing
- * the tag. May be null, if, for example, it is a package comment.
- */
- private void findReferenced(ClassDocImpl containingClass) {
- if (where.length() > 0) {
- if (containingClass != null) {
- referencedClass = containingClass.findClass(where);
- } else {
- referencedClass = docenv().lookupClass(where);
- }
- if (referencedClass == null && holder() instanceof ProgramElementDoc) {
- referencedClass = docenv().lookupClass(
- ((ProgramElementDoc) holder()).containingPackage().name() + "." + where);
- }
-
- if (referencedClass == null) { /* may just not be in this run */
- // check if it's a package name
- referencedPackage = docenv().lookupPackage(where);
- return;
- }
- } else {
- if (containingClass == null) {
- docenv().warning(holder,
- "tag.see.class_not_specified",
- name, text);
- return;
- } else {
- referencedClass = containingClass;
- }
- }
- where = referencedClass.qualifiedName();
-
- if (what == null) {
- return;
- } else {
- int paren = what.indexOf('(');
- String memName = (paren >= 0 ? what.substring(0, paren) : what);
- String[] paramarr;
- if (paren > 0) {
- // has parameter list -- should be method or constructor
- paramarr = new ParameterParseMachine(what.
- substring(paren, what.length())).parseParameters();
- if (paramarr != null) {
- referencedMember = findExecutableMember(memName, paramarr,
- referencedClass);
- } else {
- referencedMember = null;
- }
- } else {
- // no parameter list -- should be field
- referencedMember = findExecutableMember(memName, null,
- referencedClass);
- FieldDoc fd = ((ClassDocImpl)referencedClass).
- findField(memName);
- // when no args given, prefer fields over methods
- if (referencedMember == null ||
- (fd != null &&
- fd.containingClass()
- .subclassOf(referencedMember.containingClass()))) {
- referencedMember = fd;
- }
- }
- if (referencedMember == null) {
- docenv().warning(holder,
- "tag.see.can_not_find_member",
- name, what, where);
- }
- }
- }
-
- private MemberDoc findReferencedMethod(String memName, String[] paramarr,
- ClassDoc referencedClass) {
- MemberDoc meth = findExecutableMember(memName, paramarr, referencedClass);
- if (meth == null) {
- for (ClassDoc nestedClass : referencedClass.innerClasses()) {
- meth = findReferencedMethod(memName, paramarr, nestedClass);
- if (meth != null) {
- return meth;
- }
- }
- }
- return null;
- }
-
- private MemberDoc findExecutableMember(String memName, String[] paramarr,
- ClassDoc referencedClass) {
- String className = referencedClass.name();
- if (memName.equals(className.substring(className.lastIndexOf(".") + 1))) {
- return ((ClassDocImpl)referencedClass).findConstructor(memName,
- paramarr);
- } else { // it's a method.
- return ((ClassDocImpl)referencedClass).findMethod(memName,
- paramarr);
- }
- }
-
- // separate "int, String" from "(int, String)"
- // (int i, String s) ==> [0] = "int", [1] = String
- // (int[][], String[]) ==> [0] = "int[][]" // [1] = "String[]"
- class ParameterParseMachine {
- static final int START = 0;
- static final int TYPE = 1;
- static final int NAME = 2;
- static final int TNSPACE = 3; // space between type and name
- static final int ARRAYDECORATION = 4;
- static final int ARRAYSPACE = 5;
-
- String parameters;
-
- StringBuilder typeId;
-
- ListBuffer<String> paramList;
-
- ParameterParseMachine(String parameters) {
- this.parameters = parameters;
- this.paramList = new ListBuffer<>();
- typeId = new StringBuilder();
- }
-
- public String[] parseParameters() {
- if (parameters.equals("()")) {
- return new String[0];
- } // now strip off '(' and ')'
- int state = START;
- int prevstate = START;
- parameters = parameters.substring(1, parameters.length() - 1);
- int cp;
- for (int index = 0; index < parameters.length(); index += Character.charCount(cp)) {
- cp = parameters.codePointAt(index);
- switch (state) {
- case START:
- if (Character.isJavaIdentifierStart(cp)) {
- typeId.append(Character.toChars(cp));
- state = TYPE;
- }
- prevstate = START;
- break;
- case TYPE:
- if (Character.isJavaIdentifierPart(cp) || cp == '.') {
- typeId.append(Character.toChars(cp));
- } else if (cp == '[') {
- typeId.append('[');
- state = ARRAYDECORATION;
- } else if (Character.isWhitespace(cp)) {
- state = TNSPACE;
- } else if (cp == ',') { // no name, just type
- addTypeToParamList();
- state = START;
- }
- prevstate = TYPE;
- break;
- case TNSPACE:
- if (Character.isJavaIdentifierStart(cp)) { // name
- if (prevstate == ARRAYDECORATION) {
- docenv().warning(holder,
- "tag.missing_comma_space",
- name,
- "(" + parameters + ")");
- return (String[])null;
- }
- addTypeToParamList();
- state = NAME;
- } else if (cp == '[') {
- typeId.append('[');
- state = ARRAYDECORATION;
- } else if (cp == ',') { // just the type
- addTypeToParamList();
- state = START;
- } // consume rest all
- prevstate = TNSPACE;
- break;
- case ARRAYDECORATION:
- if (cp == ']') {
- typeId.append(']');
- state = TNSPACE;
- } else if (!Character.isWhitespace(cp)) {
- docenv().warning(holder,
- "tag.illegal_char_in_arr_dim",
- name,
- "(" + parameters + ")");
- return (String[])null;
- }
- prevstate = ARRAYDECORATION;
- break;
- case NAME:
- if (cp == ',') { // just consume everything till ','
- state = START;
- }
- prevstate = NAME;
- break;
- }
- }
- if (state == ARRAYDECORATION ||
- (state == START && prevstate == TNSPACE)) {
- docenv().warning(holder,
- "tag.illegal_see_tag",
- "(" + parameters + ")");
- }
- if (typeId.length() > 0) {
- paramList.append(typeId.toString());
- }
- return paramList.toArray(new String[paramList.length()]);
- }
-
- void addTypeToParamList() {
- if (typeId.length() > 0) {
- paramList.append(typeId.toString());
- typeId.setLength(0);
- }
- }
- }
-
- /**
- * Return the kind of this tag.
- */
- @Override
- public String kind() {
- return "@see";
- }
-
- /**
- * Return the label of the see tag.
- */
- public String label() {
- return label;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/SerialFieldTagImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,267 +0,0 @@
-/*
- * Copyright (c) 1998, 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 com.sun.javadoc.*;
-
-/**
- * Documents a Serializable field defined by an ObjectStreamField.
- * <pre>
- * The class parses and stores the three serialField tag parameters:
- *
- * - field name
- * - field type name
- * (fully-qualified or visible from the current import context)
- * - description of the valid values for the field
-
- * </pre>
- * This tag is only allowed in the javadoc for the special member
- * serialPersistentFields.
- *
- * <p><b>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.</b>
- *
- * @author Joe Fialli
- * @author Neal Gafter
- *
- * @see java.io.ObjectStreamField
- */
-class SerialFieldTagImpl
- extends TagImpl
- implements SerialFieldTag, Comparable<Object>
-{
- //### These could be final, except that the constructor
- //### does not set them directly.
-
- private String fieldName; // Required Argument 1 of serialField
- private String fieldType; // Required Argument 2 of serialField
- private String description; // Optional Remaining Arguments of serialField
-
- private ClassDoc containingClass; // Class containing serialPersistentField member
- private ClassDoc fieldTypeDoc; // ClassDocImpl of fieldType
- private FieldDocImpl matchingField; // FieldDocImpl with same name as fieldName
-
- /* Constructor. */
- SerialFieldTagImpl(DocImpl holder, String name, String text) {
- super(holder, name, text);
- parseSerialFieldString();
- if (holder instanceof MemberDoc) {
- containingClass = ((MemberDocImpl)holder).containingClass();
- }
- }
-
- /*
- * The serialField tag is composed of three entities.
- *
- * serialField serializableFieldName serisliableFieldType
- * description of field.
- *
- * The fieldName and fieldType must be legal Java Identifiers.
- */
- private void parseSerialFieldString() {
- int len = text.length();
- if (len == 0) {
- return;
- }
-
- // if no white space found
- /* Skip white space. */
- int inx = 0;
- int cp;
- for (; inx < len; inx += Character.charCount(cp)) {
- cp = text.codePointAt(inx);
- if (!Character.isWhitespace(cp)) {
- break;
- }
- }
-
- /* find first word. */
- int first = inx;
- int last = inx;
- cp = text.codePointAt(inx);
- if (! Character.isJavaIdentifierStart(cp)) {
- docenv().warning(holder,
- "tag.serialField.illegal_character",
- new String(Character.toChars(cp)), text);
- return;
- }
-
- for (inx += Character.charCount(cp); inx < len; inx += Character.charCount(cp)) {
- cp = text.codePointAt(inx);
- if (!Character.isJavaIdentifierPart(cp)) {
- break;
- }
- }
-
- if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
- docenv().warning(holder,
- "tag.serialField.illegal_character",
- new String(Character.toChars(cp)), text);
- return;
- }
-
- last = inx;
- fieldName = text.substring(first, last);
-
- /* Skip white space. */
- for (; inx < len; inx += Character.charCount(cp)) {
- cp = text.codePointAt(inx);
- if (!Character.isWhitespace(cp)) {
- break;
- }
- }
-
- /* find second word. */
- first = inx;
- last = inx;
-
- for (; inx < len; inx += Character.charCount(cp)) {
- cp = text.codePointAt(inx);
- if (Character.isWhitespace(cp)) {
- break;
- }
- }
- if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
- docenv().warning(holder,
- "tag.serialField.illegal_character",
- new String(Character.toChars(cp)), text);
- return;
- }
- last = inx;
- fieldType = text.substring(first, last);
-
- /* Skip leading white space. Rest of string is description for serialField.*/
- for (; inx < len; inx += Character.charCount(cp)) {
- cp = text.codePointAt(inx);
- if (!Character.isWhitespace(cp)) {
- break;
- }
- }
- description = text.substring(inx);
- }
-
- /**
- * return a key for sorting.
- */
- String key() {
- return fieldName;
- }
-
- /*
- * Optional. Link this serialField tag to its corrsponding
- * field in the class. Note: there is no requirement that
- * there be a field in the class that matches serialField tag.
- */
- void mapToFieldDocImpl(FieldDocImpl fd) {
- matchingField = fd;
- }
-
- /**
- * Return the serialziable field name.
- */
- public String fieldName() {
- return fieldName;
- }
-
- /**
- * Return the field type string.
- */
- public String fieldType() {
- return fieldType;
- }
-
- /**
- * Return the ClassDocImpl for field type.
- *
- * @returns null if no ClassDocImpl for field type is visible from
- * containingClass context.
- */
- public ClassDoc fieldTypeDoc() {
- if (fieldTypeDoc == null && containingClass != null) {
- fieldTypeDoc = containingClass.findClass(fieldType);
- }
- return fieldTypeDoc;
- }
-
- /**
- * Return the corresponding FieldDocImpl for this SerialFieldTagImpl.
- *
- * @returns null if no matching FieldDocImpl.
- */
- FieldDocImpl getMatchingField() {
- return matchingField;
- }
-
- /**
- * Return the field comment. If there is no serialField comment, return
- * javadoc comment of corresponding FieldDocImpl.
- */
- public String description() {
- if (description.length() == 0 && matchingField != null) {
-
- //check for javadoc comment of corresponding field.
- Comment comment = matchingField.comment();
- if (comment != null) {
- return comment.commentText();
- }
- }
- return description;
- }
-
- /**
- * Return the kind of this tag.
- */
- public String kind() {
- return "@serialField";
- }
-
- /**
- * Convert this object to a string.
- */
- public String toString() {
- return name + ":" + text;
- }
-
- /**
- * 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.
- * <p>
- * Included to make SerialFieldTagImpl items java.lang.Comparable.
- *
- * @param obj the <code>Object</code> 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.
- * @since 1.2
- */
- public int compareTo(Object obj) {
- return key().compareTo(((SerialFieldTagImpl)obj).key());
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/SerializedForm.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,287 +0,0 @@
-/*
- * Copyright (c) 1998, 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.tools.javac.code.*;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Symbol.MethodSymbol;
-import com.sun.tools.javac.code.Symbol.VarSymbol;
-import com.sun.tools.javac.util.*;
-
-import static com.sun.tools.javac.code.Kinds.Kind.*;
-import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
-
-/**
- * The serialized form is the specification of a class' serialization
- * state. <p>
- *
- * It consists of the following information:<p>
- *
- * <pre>
- * 1. Whether class is Serializable or Externalizable.
- * 2. Javadoc for serialization methods.
- * a. For Serializable, the optional readObject, writeObject,
- * readResolve and writeReplace.
- * serialData tag describes, in prose, the sequence and type
- * of optional data written by writeObject.
- * b. For Externalizable, writeExternal and readExternal.
- * serialData tag describes, in prose, the sequence and type
- * of optional data written by writeExternal.
- * 3. Javadoc for serialization data layout.
- * a. For Serializable, the name,type and description
- * of each Serializable fields.
- * b. For Externalizable, data layout is described by 2(b).
- * </pre>
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Joe Fialli
- * @author Neal Gafter (rewrite but not too proud)
- */
-class SerializedForm {
- ListBuffer<MethodDoc> methods = new ListBuffer<>();
-
- /* List of FieldDocImpl - Serializable fields.
- * Singleton list if class defines Serializable fields explicitly.
- * Otherwise, list of default serializable fields.
- * 0 length list for Externalizable.
- */
- private final ListBuffer<FieldDocImpl> fields = new ListBuffer<>();
-
- /* True if class specifies serializable fields explicitly.
- * using special static member, serialPersistentFields.
- */
- private boolean definesSerializableFields = false;
-
- // Specially treated field/method names defined by Serialization.
- private static final String SERIALIZABLE_FIELDS = "serialPersistentFields";
- private static final String READOBJECT = "readObject";
- private static final String WRITEOBJECT = "writeObject";
- private static final String READRESOLVE = "readResolve";
- private static final String WRITEREPLACE = "writeReplace";
- private static final String READOBJECTNODATA = "readObjectNoData";
-
- /**
- * Constructor.
- *
- * Catalog Serializable fields for Serializable class.
- * Catalog serialization methods for Serializable and
- * Externalizable classes.
- */
- SerializedForm(DocEnv env, ClassSymbol def, ClassDocImpl cd) {
- if (cd.isExternalizable()) {
- /* look up required public accessible methods,
- * writeExternal and readExternal.
- */
- String[] readExternalParamArr = { "java.io.ObjectInput" };
- String[] writeExternalParamArr = { "java.io.ObjectOutput" };
- MethodDoc md = cd.findMethod("readExternal", readExternalParamArr);
- if (md != null) {
- methods.append(md);
- }
- md = cd.findMethod("writeExternal", writeExternalParamArr);
- if (md != null) {
- methods.append(md);
- Tag tag[] = md.tags("serialData");
- }
- // } else { // isSerializable() //### ???
- } else if (cd.isSerializable()) {
-
- VarSymbol dsf = getDefinedSerializableFields(def);
- if (dsf != null) {
-
- /* Define serializable fields with array of ObjectStreamField.
- * Each ObjectStreamField should be documented by a
- * serialField tag.
- */
- definesSerializableFields = true;
- //### No modifier filtering applied here.
- FieldDocImpl dsfDoc = env.getFieldDoc(dsf);
- fields.append(dsfDoc);
- mapSerialFieldTagImplsToFieldDocImpls(dsfDoc, env, def);
- } else {
-
- /* Calculate default Serializable fields as all
- * non-transient, non-static fields.
- * Fields should be documented by serial tag.
- */
- computeDefaultSerializableFields(env, def, cd);
- }
-
- /* Check for optional customized readObject, writeObject,
- * readResolve and writeReplace, which can all contain
- * the serialData tag. */
- addMethodIfExist(env, def, READOBJECT);
- addMethodIfExist(env, def, WRITEOBJECT);
- addMethodIfExist(env, def, READRESOLVE);
- addMethodIfExist(env, def, WRITEREPLACE);
- addMethodIfExist(env, def, READOBJECTNODATA);
- }
- }
-
- /*
- * Check for explicit Serializable fields.
- * Check for a private static array of ObjectStreamField with
- * name SERIALIZABLE_FIELDS.
- */
- private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
- Names names = def.name.table.names;
-
- /* SERIALIZABLE_FIELDS can be private,
- * so must lookup by ClassSymbol, not by ClassDocImpl.
- */
- for (Symbol sym : def.members().getSymbolsByName(names.fromString(SERIALIZABLE_FIELDS))) {
- if (sym.kind == VAR) {
- VarSymbol f = (VarSymbol)sym;
- if ((f.flags() & Flags.STATIC) != 0 &&
- (f.flags() & Flags.PRIVATE) != 0) {
- return f;
- }
- }
- }
- return null;
- }
-
- /*
- * Compute default Serializable fields from all members of ClassSymbol.
- *
- * Since the fields of ClassDocImpl might not contain private or
- * package accessible fields, must walk over all members of ClassSymbol.
- */
- private void computeDefaultSerializableFields(DocEnv env,
- ClassSymbol def,
- ClassDocImpl cd) {
- for (Symbol sym : def.members().getSymbols(NON_RECURSIVE)) {
- if (sym != null && sym.kind == VAR) {
- VarSymbol f = (VarSymbol)sym;
- if ((f.flags() & Flags.STATIC) == 0 &&
- (f.flags() & Flags.TRANSIENT) == 0) {
- //### No modifier filtering applied here.
- FieldDocImpl fd = env.getFieldDoc(f);
- //### Add to beginning.
- //### Preserve order used by old 'javadoc'.
- fields.prepend(fd);
- }
- }
- }
- }
-
- /*
- * Catalog Serializable method if it exists in current ClassSymbol.
- * Do not look for method in superclasses.
- *
- * Serialization requires these methods to be non-static.
- *
- * @param method should be an unqualified Serializable method
- * name either READOBJECT, WRITEOBJECT, READRESOLVE
- * or WRITEREPLACE.
- * @param visibility the visibility flag for the given method.
- */
- private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
- Names names = def.name.table.names;
-
- for (Symbol sym : def.members().getSymbolsByName(names.fromString(methodName))) {
- if (sym.kind == MTH) {
- MethodSymbol md = (MethodSymbol)sym;
- if ((md.flags() & Flags.STATIC) == 0) {
- /*
- * WARNING: not robust if unqualifiedMethodName is overloaded
- * method. Signature checking could make more robust.
- * READOBJECT takes a single parameter, java.io.ObjectInputStream.
- * WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
- */
- methods.append(env.getMethodDoc(md));
- }
- }
- }
- }
-
- /*
- * Associate serialField tag fieldName with FieldDocImpl member.
- * Note: A serialField tag does not have to map an existing field
- * of a class.
- */
- private void mapSerialFieldTagImplsToFieldDocImpls(FieldDocImpl spfDoc,
- DocEnv env,
- ClassSymbol def) {
- Names names = def.name.table.names;
- for (SerialFieldTag tag : spfDoc.serialFieldTags()) {
- if (tag.fieldName() == null || tag.fieldType() == null) // ignore malformed @serialField tags
- continue;
-
- Name fieldName = names.fromString(tag.fieldName());
-
- // Look for a FieldDocImpl that is documented by serialFieldTagImpl.
- for (Symbol sym : def.members().getSymbolsByName(fieldName)) {
- if (sym.kind == VAR) {
- VarSymbol f = (VarSymbol) sym;
- FieldDocImpl fdi = env.getFieldDoc(f);
- ((SerialFieldTagImpl) (tag)).mapToFieldDocImpl(fdi);
- break;
- }
- }
- }
- }
-
- /**
- * Return serializable fields in class. <p>
- *
- * Returns either a list of default fields documented by serial tag comment or
- * javadoc comment<p>
- * Or Returns a single FieldDocImpl for serialPersistentField. There is a
- * serialField tag for each serializable field.<p>
- *
- * @return an array of FieldDocImpl for representing the visible
- * fields in this class.
- */
- FieldDoc[] fields() {
- return (FieldDoc[])fields.toArray(new FieldDocImpl[fields.length()]);
- }
-
- /**
- * Return serialization methods in class.
- *
- * @return an array of MethodDocImpl for serialization methods in this class.
- */
- MethodDoc[] methods() {
- return methods.toArray(new MethodDoc[methods.length()]);
- }
-
- /**
- * Returns true if Serializable fields are defined explicitly using
- * member, serialPersistentFields.
- *
- * @see #fields()
- */
- boolean definesSerializableFields() {
- return definesSerializableFields;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2001, 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 javax.tools.FileObject;
-
-import com.sun.javadoc.SourcePosition;
-import com.sun.tools.javac.util.Position;
-
-/**
- * A source position: filename, line number, and column number.
- *
- * <p><b>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.</b>
- *
- * @since J2SE1.4
- * @author Neal M Gafter
- * @author Michael Van De Vanter (position representation changed to char offsets)
- */
-public class SourcePositionImpl implements SourcePosition {
- FileObject filename;
- int position;
- Position.LineMap lineMap;
-
- /** The source file. Returns null if no file information is
- * available. */
- public File file() {
- return (filename == null) ? null : new File(filename.getName());
- }
-
- /** The source file. Returns null if no file information is
- * available. */
- public FileObject fileObject() {
- return filename;
- }
-
- /** The line in the source file. The first line is numbered 1;
- * 0 means no line number information is available. */
- public int line() {
- if (lineMap == null) {
- return 0;
- } else {
- return lineMap.getLineNumber(position);
- }
- }
-
- /** The column in the source file. The first column is
- * numbered 1; 0 means no column information is available.
- * Columns count characters in the input stream; a tab
- * advances the column number to the next 8-column tab stop.
- */
- public int column() {
- if (lineMap == null) {
- return 0;
- }else {
- return lineMap.getColumnNumber(position);
- }
- }
-
- private SourcePositionImpl(FileObject file, int position,
- Position.LineMap lineMap) {
- super();
- this.filename = file;
- this.position = position;
- this.lineMap = lineMap;
- }
-
- public static SourcePosition make(FileObject file, int pos,
- Position.LineMap lineMap) {
- if (file == null) return null;
- return new SourcePositionImpl(file, pos, lineMap);
- }
-
- public String toString() {
- // Backwards compatibility hack. ZipFileObjects use the format
- // zipfile(zipentry) but javadoc has been using zipfile/zipentry
- String fn = filename.getName();
- if (fn.endsWith(")")) {
- int paren = fn.lastIndexOf("(");
- if (paren != -1) {
- int i = paren+1;
- if (fn.charAt(i) == '/')
- i++;
- fn = fn.substring(0, paren)
- + File.separatorChar
- + fn.substring(i, fn.length() - 1);
- }
- }
-
- if (position == Position.NOPOS)
- return fn;
- else
- return fn + ":" + line();
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Start.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,557 +0,0 @@
-/*
- * Copyright (c) 1997, 2016, 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.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Objects;
-
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.StandardLocation;
-
-import com.sun.javadoc.*;
-import com.sun.tools.javac.file.JavacFileManager;
-import com.sun.tools.javac.main.CommandLine;
-import com.sun.tools.javac.main.Option;
-import com.sun.tools.javac.file.BaseFileManager;
-import com.sun.tools.javac.platform.PlatformDescription;
-import com.sun.tools.javac.platform.PlatformUtils;
-import com.sun.tools.javac.util.ClientCodeException;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Log;
-import com.sun.tools.javac.util.Options;
-
-import static com.sun.tools.javac.code.Flags.*;
-
-/**
- * Main program of Javadoc.
- * Previously named "Main".
- *
- * <p><b>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.</b>
- *
- * @since 1.2
- * @author Robert Field
- * @author Neal Gafter (rewrite)
- */
-public class Start extends ToolOption.Helper {
- /** Context for this invocation. */
- private final Context context;
-
- private final String defaultDocletClassName;
- private final ClassLoader docletParentClassLoader;
-
- private static final String javadocName = "javadoc";
-
- private static final String standardDocletClassName =
- "com.sun.tools.doclets.standard.Standard";
-
- private final long defaultFilter = PUBLIC | PROTECTED;
-
- private final Messager messager;
-
- private DocletInvoker docletInvoker;
-
- /**
- * In API mode, exceptions thrown while calling the doclet are
- * propagated using ClientCodeException.
- */
- private boolean apiMode;
-
- private JavaFileManager fileManager;
-
- Start(String programName,
- PrintWriter errWriter,
- PrintWriter warnWriter,
- PrintWriter noticeWriter,
- String defaultDocletClassName) {
- this(programName, errWriter, warnWriter, noticeWriter, defaultDocletClassName, null);
- }
-
- public Start(PrintWriter pw) {
- this(javadocName, pw, pw, pw, standardDocletClassName);
- }
-
- public Start(String programName,
- PrintWriter errWriter,
- PrintWriter warnWriter,
- PrintWriter noticeWriter,
- String defaultDocletClassName,
- ClassLoader docletParentClassLoader) {
- context = new Context();
- messager = new Messager(context, programName, errWriter, warnWriter, noticeWriter);
- this.defaultDocletClassName = defaultDocletClassName;
- this.docletParentClassLoader = docletParentClassLoader;
- }
-
- Start(String programName, String defaultDocletClassName) {
- this(programName, defaultDocletClassName, null);
- }
-
- Start(String programName, String defaultDocletClassName,
- ClassLoader docletParentClassLoader) {
- context = new Context();
- messager = new Messager(context, programName);
- this.defaultDocletClassName = defaultDocletClassName;
- this.docletParentClassLoader = docletParentClassLoader;
- }
-
- Start(String programName, ClassLoader docletParentClassLoader) {
- this(programName, standardDocletClassName, docletParentClassLoader);
- }
-
- Start(String programName) {
- this(programName, standardDocletClassName);
- }
-
- Start(ClassLoader docletParentClassLoader) {
- this(javadocName, docletParentClassLoader);
- }
-
- public Start() {
- this(javadocName);
- }
-
- public Start(Context context) {
- this.context = Objects.requireNonNull(context);
- apiMode = true;
- defaultDocletClassName = standardDocletClassName;
- docletParentClassLoader = null;
-
- Log log = context.get(Log.logKey);
- if (log instanceof Messager)
- messager = (Messager) log;
- else {
- PrintWriter out = context.get(Log.outKey);
- messager = (out == null) ? new Messager(context, javadocName)
- : new Messager(context, javadocName, out, out, out);
- }
- }
-
- /**
- * Usage
- */
- @Override
- void usage() {
- usage(true);
- }
-
- void usage(boolean exit) {
- usage("main.usage", "-help", null, exit);
- }
-
- @Override
- void Xusage() {
- Xusage(true);
- }
-
- void Xusage(boolean exit) {
- usage("main.Xusage", "-X", "main.Xusage.foot", exit);
- }
-
- private void usage(String main, String doclet, String foot, boolean exit) {
- // RFE: it would be better to replace the following with code to
- // write a header, then help for each option, then a footer.
- messager.notice(main);
-
- // let doclet print usage information (does nothing on error)
- if (docletInvoker != null) {
- // RFE: this is a pretty bad way to get the doclet to show
- // help info. Moreover, the output appears on stdout,
- // and <i>not</i> on any of the standard streams passed
- // to javadoc, and in particular, not to the noticeWriter
- // But, to fix this, we need to fix the Doclet API.
- docletInvoker.optionLength(doclet);
- }
-
- if (foot != null)
- messager.notice(foot);
-
- if (exit) exit();
- }
-
- /**
- * Exit
- */
- private void exit() {
- messager.exit();
- }
-
-
- /**
- * Main program - external wrapper
- */
- public int begin(String... argv) {
- boolean ok = begin(null, argv, Collections.<JavaFileObject> emptySet());
- return ok ? 0 : 1;
- }
-
- public boolean begin(Class<?> docletClass, Iterable<String> options, Iterable<? extends JavaFileObject> fileObjects) {
- Collection<String> opts = new ArrayList<>();
- for (String opt: options) opts.add(opt);
- return begin(docletClass, opts.toArray(new String[opts.size()]), fileObjects);
- }
-
- private boolean begin(Class<?> docletClass, String[] options, Iterable<? extends JavaFileObject> fileObjects) {
- boolean failed = false;
-
- try {
- failed = !parseAndExecute(docletClass, options, fileObjects);
- } catch (Messager.ExitJavadoc exc) {
- // ignore, we just exit this way
- } catch (OutOfMemoryError ee) {
- messager.error(Messager.NOPOS, "main.out.of.memory");
- failed = true;
- } catch (ClientCodeException e) {
- // simply rethrow these exceptions, to be caught and handled by JavadocTaskImpl
- throw e;
- } catch (Error ee) {
- ee.printStackTrace(System.err);
- messager.error(Messager.NOPOS, "main.fatal.error");
- failed = true;
- } catch (Exception ee) {
- ee.printStackTrace(System.err);
- messager.error(Messager.NOPOS, "main.fatal.exception");
- failed = true;
- } finally {
- if (fileManager != null
- && fileManager instanceof BaseFileManager
- && ((BaseFileManager) fileManager).autoClose) {
- try {
- fileManager.close();
- } catch (IOException ignore) {
- }
- }
- messager.exitNotice();
- messager.flush();
- }
- failed |= messager.nerrors() > 0;
- failed |= rejectWarnings && messager.nwarnings() > 0;
- return !failed;
- }
-
- /**
- * Main program - internal
- */
- private boolean parseAndExecute(
- Class<?> docletClass,
- String[] argv,
- Iterable<? extends JavaFileObject> fileObjects) throws IOException {
- long tm = System.currentTimeMillis();
-
- ListBuffer<String> javaNames = new ListBuffer<>();
-
- // Preprocess @file arguments
- try {
- argv = CommandLine.parse(argv);
- } catch (FileNotFoundException e) {
- messager.error(Messager.NOPOS, "main.cant.read", e.getMessage());
- exit();
- } catch (IOException e) {
- e.printStackTrace(System.err);
- exit();
- }
-
-
- fileManager = context.get(JavaFileManager.class);
-
- setDocletInvoker(docletClass, fileManager, argv);
-
- compOpts = Options.instance(context);
- // Make sure no obsolete source/target messages are reported
- compOpts.put("-Xlint:-options", "-Xlint:-options");
-
- // Parse arguments
- for (int i = 0 ; i < argv.length ; i++) {
- String arg = argv[i];
-
- ToolOption o = ToolOption.get(arg);
- if (o != null) {
- // hack: this restriction should be removed
- if (o == ToolOption.LOCALE && i > 0)
- usageError("main.locale_first");
-
- if (o.hasArg) {
- oneArg(argv, i++);
- o.process(this, argv[i]);
- } else {
- setOption(arg);
- o.process(this);
- }
- } else if (arg.equals("-XDaccessInternalAPI")) {
- // pass this hidden option down to the doclet, if it wants it
- if (docletInvoker.optionLength("-XDaccessInternalAPI") == 1) {
- setOption(arg);
- }
- } else if (arg.startsWith("-XD")) {
- // hidden javac options
- String s = arg.substring("-XD".length());
- int eq = s.indexOf('=');
- String key = (eq < 0) ? s : s.substring(0, eq);
- String value = (eq < 0) ? s : s.substring(eq+1);
- compOpts.put(key, value);
- }
- // call doclet for its options
- // other arg starts with - is invalid
- else if (arg.startsWith("-")) {
- int optionLength;
- optionLength = docletInvoker.optionLength(arg);
- if (optionLength < 0) {
- // error already displayed
- exit();
- } else if (optionLength == 0) {
- // option not found
- usageError("main.invalid_flag", arg);
- } else {
- // doclet added option
- if ((i + optionLength) > argv.length) {
- usageError("main.requires_argument", arg);
- }
- ListBuffer<String> args = new ListBuffer<>();
- for (int j = 0; j < optionLength-1; ++j) {
- args.append(argv[++i]);
- }
- setOption(arg, args.toList());
- }
- } else {
- javaNames.append(arg);
- }
- }
-
- if (fileManager == null) {
- JavacFileManager.preRegister(context);
- fileManager = context.get(JavaFileManager.class);
- if (fileManager instanceof BaseFileManager) {
- ((BaseFileManager) fileManager).autoClose = true;
- }
- }
- if (fileManager instanceof BaseFileManager) {
- ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
- }
-
- String platformString = compOpts.get("-release");
-
- if (platformString != null) {
- if (compOpts.isSet("-source")) {
- usageError("main.release.bootclasspath.conflict", "-source");
- }
- if (fileManagerOpts.containsKey(Option.BOOTCLASSPATH)) {
- usageError("main.release.bootclasspath.conflict", Option.BOOTCLASSPATH.getText());
- }
-
- PlatformDescription platformDescription =
- PlatformUtils.lookupPlatformDescription(platformString);
-
- if (platformDescription == null) {
- usageError("main.unsupported.release.version", platformString);
- }
-
- compOpts.put(Option.SOURCE, platformDescription.getSourceVersion());
-
- context.put(PlatformDescription.class, platformDescription);
-
- Collection<Path> platformCP = platformDescription.getPlatformPath();
-
- if (platformCP != null) {
- if (fileManager instanceof StandardJavaFileManager) {
- StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
-
- sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
- } else {
- usageError("main.release.not.standard.file.manager", platformString);
- }
- }
- }
-
- compOpts.notifyListeners();
-
- if (javaNames.isEmpty() && subPackages.isEmpty() && isEmpty(fileObjects)) {
- usageError("main.No_packages_or_classes_specified");
- }
-
- if (!docletInvoker.validOptions(options.toList())) {
- // error message already displayed
- exit();
- }
-
- JavadocTool comp = JavadocTool.make0(context);
- if (comp == null) return false;
-
- if (showAccess == null) {
- setFilter(defaultFilter);
- }
-
- LanguageVersion languageVersion = docletInvoker.languageVersion();
- RootDocImpl root = comp.getRootDocImpl(
- docLocale,
- encoding,
- showAccess,
- javaNames.toList(),
- options.toList(),
- fileObjects,
- breakiterator,
- subPackages.toList(),
- excludedPackages.toList(),
- docClasses,
- // legacy?
- languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1,
- quiet);
-
- // release resources
- comp = null;
-
- // pass off control to the doclet
- boolean ok = root != null;
- if (ok) ok = docletInvoker.start(root);
-
- // We're done.
- if (compOpts.get("-verbose") != null) {
- tm = System.currentTimeMillis() - tm;
- messager.notice("main.done_in", Long.toString(tm));
- }
-
- return ok;
- }
-
- private <T> boolean isEmpty(Iterable<T> iter) {
- return !iter.iterator().hasNext();
- }
-
- /**
- * Init the doclet invoker.
- * The doclet class may be given explicitly, or via the -doclet option in
- * argv.
- * If the doclet class is not given explicitly, it will be loaded from
- * the file manager's DOCLET_PATH location, if available, or via the
- * -doclet path option in argv.
- * @param docletClass The doclet class. May be null.
- * @param fileManager The file manager used to get the class loader to load
- * the doclet class if required. May be null.
- * @param argv Args containing -doclet and -docletpath, in case they are required.
- */
- private void setDocletInvoker(Class<?> docletClass, JavaFileManager fileManager, String[] argv) {
- boolean exportInternalAPI = false;
- String docletClassName = null;
- String docletPath = null;
-
- // Parse doclet specifying arguments
- for (int i = 0 ; i < argv.length ; i++) {
- String arg = argv[i];
- if (arg.equals(ToolOption.DOCLET.opt)) {
- oneArg(argv, i++);
- if (docletClassName != null) {
- usageError("main.more_than_one_doclet_specified_0_and_1",
- docletClassName, argv[i]);
- }
- docletClassName = argv[i];
- } else if (arg.equals(ToolOption.DOCLETPATH.opt)) {
- oneArg(argv, i++);
- if (docletPath == null) {
- docletPath = argv[i];
- } else {
- docletPath += File.pathSeparator + argv[i];
- }
- } else if (arg.equals("-XDaccessInternalAPI")) {
- exportInternalAPI = true;
- }
- }
-
- if (docletClass != null) {
- // TODO, check no -doclet, -docletpath
- docletInvoker = new DocletInvoker(messager, docletClass, apiMode, exportInternalAPI);
- } else {
- if (docletClassName == null) {
- docletClassName = defaultDocletClassName;
- }
-
- // attempt to find doclet
- docletInvoker = new DocletInvoker(messager, fileManager,
- docletClassName, docletPath,
- docletParentClassLoader,
- apiMode,
- exportInternalAPI);
- }
- }
-
- /**
- * Set one arg option.
- * Error and exit if one argument is not provided.
- */
- private void oneArg(String[] args, int index) {
- if ((index + 1) < args.length) {
- setOption(args[index], args[index+1]);
- } else {
- usageError("main.requires_argument", args[index]);
- }
- }
-
- @Override
- void usageError(String key, Object... args) {
- messager.error(Messager.NOPOS, key, args);
- usage(true);
- }
-
- /**
- * indicate an option with no arguments was given.
- */
- private void setOption(String opt) {
- String[] option = { opt };
- options.append(option);
- }
-
- /**
- * indicate an option with one argument was given.
- */
- private void setOption(String opt, String argument) {
- String[] option = { opt, argument };
- options.append(option);
- }
-
- /**
- * indicate an option with the specified list of arguments was given.
- */
- private void setOption(String opt, List<String> arguments) {
- String[] args = new String[arguments.length() + 1];
- int k = 0;
- args[k++] = opt;
- for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
- args[k++] = i.head;
- }
- options.append(args);
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/TagImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/*
- * Copyright (c) 1997, 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 com.sun.javadoc.*;
-
-/**
- * Represents a documentation tag, e.g. @since, @author, @version.
- * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since")
- * and tag text (e.g. "1.2"). TagImpls with structure or which require
- * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl,
- * and ThrowsTagImpl
- *
- * <p><b>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.</b>
- *
- * @author Robert Field
- * @author Atul M Dambalkar
- * @author Neal M Gafter
- * @see SeeTagImpl
- * @see ParamTagImpl
- * @see ThrowsTagImpl
- * @see Doc#tags()
- *
- */
-class TagImpl implements Tag {
-
- protected final String text;
- protected final String name;
- protected final DocImpl holder;
-
- /**
- * Cached first sentence.
- */
- private Tag[] firstSentence;
-
- /**
- * Cached inline tags.
- */
- private Tag[] inlineTags;
-
- /**
- * Constructor
- */
- TagImpl(DocImpl holder, String name, String text) {
- this.holder = holder;
- this.name = name;
- this.text = text;
- }
-
- /**
- * Return the name of this tag.
- */
- public String name() {
- return name;
- }
-
- /**
- * Return the containing {@link Doc} of this Tag element.
- */
- public Doc holder() {
- return holder;
- }
-
- /**
- * Return the kind of this tag.
- */
- public String kind() {
- return name;
- }
-
- /**
- * Return the text of this tag, that is, portion beyond tag name.
- */
- public String text() {
- return text;
- }
-
- DocEnv docenv() {
- return holder.env;
- }
-
- /**
- * for use by subclasses which have two part tag text.
- */
- String[] divideAtWhite() {
- String[] sa = new String[2];
- int len = text.length();
- // if no white space found
- sa[0] = text;
- sa[1] = "";
- for (int inx = 0; inx < len; ++inx) {
- char ch = text.charAt(inx);
- if (Character.isWhitespace(ch)) {
- sa[0] = text.substring(0, inx);
- for (; inx < len; ++inx) {
- ch = text.charAt(inx);
- if (!Character.isWhitespace(ch)) {
- sa[1] = text.substring(inx, len);
- break;
- }
- }
- break;
- }
- }
- return sa;
- }
-
- /**
- * convert this object to a string.
- */
- public String toString() {
- return name + ":" + text;
- }
-
- /**
- * For documentation comment with embedded @link tags, return the array of
- * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
- * Within a comment string "This is an example of inline tags for a
- * documentation comment {@link Doc {@link Doc commentlabel}}",
- * where inside the inner braces, the first "Doc" carries exctly the same
- * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html
- * Link, will return an array of TagImpl(s) with first element as TagImpl with
- * comment text "This is an example of inline tags for a documentation
- * comment" and second element as SeeTagImpl with referenced class as "Doc"
- * and the label for the Html Link as "commentlabel".
- *
- * @return TagImpl[] Array of tags with inline SeeTagImpls.
- * @see ParamTagImpl
- * @see ThrowsTagImpl
- */
- public Tag[] inlineTags() {
- if (inlineTags == null) {
- inlineTags = Comment.getInlineTags(holder, text);
- }
- return inlineTags;
- }
-
- /**
- * Return array of tags for the first sentence in the doc comment text.
- */
- public Tag[] firstSentenceTags() {
- if (firstSentence == null) {
- //Parse all sentences first to avoid duplicate warnings.
- inlineTags();
- try {
- docenv().setSilent(true);
- firstSentence = Comment.firstSentenceTags(holder, text);
- } finally {
- docenv().setSilent(false);
- }
- }
- return firstSentence;
- }
-
- /**
- * Return the doc item to which this tag is attached.
- * @return the doc item to which this tag is attached.
- */
- public SourcePosition position() {
- return holder.position();
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ThrowsTagImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 1997, 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 com.sun.javadoc.*;
-
-/**
- * Represents a @throws or @exception documentation tag.
- * Parses and holds the exception name and exception comment.
- * The exception name my be the name of a type variable.
- * Note: @exception is a backwards compatible synonymy for @throws.
- *
- * <p><b>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.</b>
- *
- * @author Robert Field
- * @author Atul M Dambalkar
- * @see ExecutableMemberDocImpl#throwsTags()
- *
- */
-class ThrowsTagImpl extends TagImpl implements ThrowsTag {
-
- private final String exceptionName;
- private final String exceptionComment;
-
- /**
- * Cached inline tags.
- */
- private Tag[] inlineTags;
-
- ThrowsTagImpl(DocImpl holder, String name, String text) {
- super(holder, name, text);
- String[] sa = divideAtWhite();
- exceptionName = sa[0];
- exceptionComment = sa[1];
- }
-
- /**
- * Return the exception name.
- */
- public String exceptionName() {
- return exceptionName;
- }
-
- /**
- * Return the exception comment.
- */
- public String exceptionComment() {
- return exceptionComment;
- }
-
- /**
- * Return the exception as a ClassDocImpl.
- */
- public ClassDoc exception() {
- ClassDocImpl exceptionClass;
- if (!(holder instanceof ExecutableMemberDoc)) {
- exceptionClass = null;
- } else {
- ExecutableMemberDocImpl emd = (ExecutableMemberDocImpl)holder;
- ClassDocImpl con = (ClassDocImpl)emd.containingClass();
- exceptionClass = (ClassDocImpl)con.findClass(exceptionName);
- }
- return exceptionClass;
- }
-
- /**
- * Return the type that represents the exception.
- * This may be a <code>ClassDoc</code> or a <code>TypeVariable</code>.
- */
- public Type exceptionType() {
- //###(gj) TypeVariable not yet supported.
- return exception();
- }
-
-
- /**
- * Return the kind of this tag. Always "@throws" for instances
- * of ThrowsTagImpl.
- */
- @Override
- public String kind() {
- return "@throws";
- }
-
- /**
- * For the exception comment with embedded @link tags return the array of
- * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
- *
- * @return TagImpl[] Array of tags with inline SeeTagImpls.
- * @see TagImpl#inlineTags()
- * @see ParamTagImpl#inlineTags()
- */
- @Override
- public Tag[] inlineTags() {
- if (inlineTags == null) {
- inlineTags = Comment.getInlineTags(holder, exceptionComment());
- }
- return inlineTags;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/ToolOption.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,392 +0,0 @@
-/*
- * Copyright (c) 2012, 2016, 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.LinkedHashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import com.sun.tools.javac.code.Flags;
-import com.sun.tools.javac.main.Option;
-import com.sun.tools.javac.util.ListBuffer;
-import com.sun.tools.javac.util.Options;
-
-
-/**
- * javadoc tool options.
- *
- * <p><b>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.</b>
- */
-public enum ToolOption {
- // ----- options for underlying compiler -----
-
- BOOTCLASSPATH("-bootclasspath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
- }
- },
-
- CLASSPATH("-classpath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.CLASSPATH, arg);
- }
- },
-
- CP("-cp", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.CP, arg);
- }
- },
-
- EXTDIRS("-extdirs", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.EXTDIRS, arg);
- }
- },
-
- SOURCEPATH("-sourcepath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.SOURCEPATH, arg);
- }
- },
-
- SYSCLASSPATH("-sysclasspath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
- }
- },
-
- MODULESOURCEPATH("-modulesourcepath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.MODULESOURCEPATH, arg);
- }
- },
-
- UPGRADEMODULEPATH("-upgrademodulepath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.UPGRADEMODULEPATH, arg);
- }
- },
-
- SYSTEM("-system", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.SYSTEM, arg);
- }
- },
-
- MODULEPATH("-modulepath", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setFileManagerOpt(Option.MODULEPATH, arg);
- }
- },
-
- ADDMODS("-addmods", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- LIMITMODS("-limitmods", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- ENCODING("-encoding", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.encoding = arg;
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- RELEASE("-release", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- SOURCE("-source", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- XMAXERRS("-Xmaxerrs", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- XMAXWARNS("-Xmaxwarns", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.setCompilerOpt(opt, arg);
- }
- },
-
- // ----- doclet options -----
-
- DOCLET("-doclet", true), // handled in setDocletInvoker
-
- DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
-
- // ----- selection options -----
-
- SUBPACKAGES("-subpackages", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.addToList(helper.subPackages, arg);
- }
- },
-
- EXCLUDE("-exclude", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.addToList(helper.excludedPackages, arg);
- }
- },
-
- // ----- filtering options -----
-
- PACKAGE("-package") {
- @Override
- public void process(Helper helper) {
- helper.setFilter(
- Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
- }
- },
-
- PRIVATE("-private") {
- @Override
- public void process(Helper helper) {
- helper.setFilter(ModifierFilter.ALL_ACCESS);
- }
- },
-
- PROTECTED("-protected") {
- @Override
- public void process(Helper helper) {
- helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
- }
- },
-
- PUBLIC("-public") {
- @Override
- public void process(Helper helper) {
- helper.setFilter(Flags.PUBLIC);
- }
- },
-
- // ----- output control options -----
-
- PROMPT("-prompt") {
- @Override
- public void process(Helper helper) {
- helper.compOpts.put("-prompt", "-prompt");
- helper.promptOnError = true;
- }
- },
-
- QUIET("-quiet") {
- @Override
- public void process(Helper helper) {
- helper.quiet = true;
- }
- },
-
- VERBOSE("-verbose") {
- @Override
- public void process(Helper helper) {
- helper.compOpts.put("-verbose", "");
- }
- },
-
- XWERROR("-Xwerror") {
- @Override
- public void process(Helper helper) {
- helper.rejectWarnings = true;
-
- }
- },
-
- // ----- other options -----
-
- BREAKITERATOR("-breakiterator") {
- @Override
- public void process(Helper helper) {
- helper.breakiterator = true;
- }
- },
-
- LOCALE("-locale", true) {
- @Override
- public void process(Helper helper, String arg) {
- helper.docLocale = arg;
- }
- },
-
- OVERVIEW("-overview", true),
-
- XCLASSES("-Xclasses") {
- @Override
- public void process(Helper helper) {
- helper.docClasses = true;
-
- }
- },
-
- // ----- help options -----
-
- HELP("-help") {
- @Override
- public void process(Helper helper) {
- helper.usage();
- }
- },
-
- X("-X") {
- @Override
- public void process(Helper helper) {
- helper.Xusage();
- }
- };
-
- public final String opt;
- public final boolean hasArg;
-
- ToolOption(String opt) {
- this(opt, false);
- }
-
- ToolOption(String opt, boolean hasArg) {
- this.opt = opt;
- this.hasArg = hasArg;
- }
-
- void process(Helper helper, String arg) { }
-
- void process(Helper helper) { }
-
- static ToolOption get(String name) {
- for (ToolOption o: values()) {
- if (name.equals(o.opt))
- return o;
- }
- return null;
- }
-
- static abstract class Helper {
- /** List of decoded options. */
- final ListBuffer<String[]> options = new ListBuffer<>();
-
- /** Selected packages, from -subpackages. */
- final ListBuffer<String> subPackages = new ListBuffer<>();
-
- /** Excluded packages, from -exclude. */
- final ListBuffer<String> excludedPackages = new ListBuffer<>();
-
- // File manager options
- final Map<Option, String> fileManagerOpts = new LinkedHashMap<>();
-
- /** javac options, set by various options. */
- Options compOpts; // = Options.instance(context)
-
- /* Encoding for javac, and files written? set by -encoding. */
- String encoding = null;
-
- /** Set by -breakiterator. */
- boolean breakiterator = false;
-
- /** Set by -quiet. */
- boolean quiet = false;
-
- /** Set by -Xclasses. */
- boolean docClasses = false;
-
- /** Set by -Xwerror. */
- boolean rejectWarnings = false;
-
- /** Set by -prompt. */
- boolean promptOnError;
-
- /** Set by -locale. */
- String docLocale = "";
-
- /** Set by -public, private, -protected, -package. */
- ModifierFilter showAccess = null;
-
- abstract void usage();
- abstract void Xusage();
-
- abstract void usageError(String msg, Object... args);
-
- void addToList(ListBuffer<String> list, String str){
- StringTokenizer st = new StringTokenizer(str, ":");
- String current;
- while(st.hasMoreTokens()){
- current = st.nextToken();
- list.append(current);
- }
- }
-
- void setFilter(long filterBits) {
- if (showAccess != null) {
- usageError("main.incompatible.access.flags");
- }
- showAccess = new ModifierFilter(filterBits);
- }
-
- void setCompilerOpt(String opt, String arg) {
- if (compOpts.get(opt) != null) {
- usageError("main.option.already.seen", opt);
- }
- compOpts.put(opt, arg);
- }
-
- void setFileManagerOpt(Option opt, String arg) {
- fileManagerOpts.put(opt, arg);
- }
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/TypeMaker.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,350 +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.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.Type;
-import com.sun.tools.javac.code.Type.ArrayType;
-import com.sun.tools.javac.code.Type.ClassType;
-import com.sun.tools.javac.code.Type.TypeVar;
-import com.sun.tools.javac.util.List;
-import static com.sun.tools.javac.code.TypeTag.ARRAY;
-
-/**
- * <p><b>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.</b>
- */
-public class TypeMaker {
-
- public static com.sun.javadoc.Type getType(DocEnv env, Type t) {
- return getType(env, t, true);
- }
-
- /**
- * @param errToClassDoc if true, ERROR type results in a ClassDoc;
- * false preserves legacy behavior
- */
- public static com.sun.javadoc.Type getType(DocEnv env, Type t,
- boolean errorToClassDoc) {
- return getType(env, t, errorToClassDoc, true);
- }
-
- public static com.sun.javadoc.Type getType(DocEnv env, Type t,
- boolean errToClassDoc, boolean considerAnnotations) {
- try {
- return getTypeImpl(env, t, errToClassDoc, considerAnnotations);
- } catch (CompletionFailure cf) {
- /* 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 getType(env, t, errToClassDoc, considerAnnotations);
- }
- }
-
- @SuppressWarnings("fallthrough")
- private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t,
- boolean errToClassDoc, boolean considerAnnotations) {
- if (env.legacyDoclet) {
- t = env.types.erasure(t);
- }
-
- if (considerAnnotations && t.isAnnotated()) {
- return new AnnotatedTypeImpl(env, t);
- }
-
- switch (t.getTag()) {
- case CLASS:
- if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
- return env.getParameterizedType((ClassType)t);
- } else {
- return env.getClassDoc((ClassSymbol)t.tsym);
- }
- case WILDCARD:
- Type.WildcardType a = (Type.WildcardType)t;
- return new WildcardTypeImpl(env, a);
- case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
- case ARRAY: return new ArrayTypeImpl(env, t);
- case BYTE: return PrimitiveType.byteType;
- case CHAR: return PrimitiveType.charType;
- case SHORT: return PrimitiveType.shortType;
- case INT: return PrimitiveType.intType;
- case LONG: return PrimitiveType.longType;
- case FLOAT: return PrimitiveType.floatType;
- case DOUBLE: return PrimitiveType.doubleType;
- case BOOLEAN: return PrimitiveType.booleanType;
- case VOID: return PrimitiveType.voidType;
- case ERROR:
- if (errToClassDoc)
- return env.getClassDoc((ClassSymbol)t.tsym);
- // FALLTHRU
- default:
- return new PrimitiveType(t.tsym.getQualifiedName().toString());
- }
- }
-
- /**
- * Convert a list of javac types into an array of javadoc types.
- */
- public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts) {
- return getTypes(env, ts, new com.sun.javadoc.Type[ts.length()]);
- }
-
- /**
- * Like the above version, but use and return the array given.
- */
- public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts,
- com.sun.javadoc.Type res[]) {
- int i = 0;
- for (Type t : ts) {
- res[i++] = getType(env, t);
- }
- return res;
- }
-
- public static String getTypeName(Type t, boolean full) {
- switch (t.getTag()) {
- case ARRAY:
- StringBuilder s = new StringBuilder();
- while (t.hasTag(ARRAY)) {
- s.append("[]");
- t = ((ArrayType)t).elemtype;
- }
- s.insert(0, getTypeName(t, full));
- return s.toString();
- case CLASS:
- return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
- default:
- return t.tsym.getQualifiedName().toString();
- }
- }
-
- /**
- * Return the string representation of a type use. Bounds of type
- * variables are not included; bounds of wildcard types are.
- * Class names are qualified if "full" is true.
- */
- static String getTypeString(DocEnv env, Type t, boolean full) {
- // TODO: should annotations be included here?
- switch (t.getTag()) {
- case ARRAY:
- StringBuilder s = new StringBuilder();
- while (t.hasTag(ARRAY)) {
- s.append("[]");
- t = env.types.elemtype(t);
- }
- s.insert(0, getTypeString(env, t, full));
- return s.toString();
- case CLASS:
- return ParameterizedTypeImpl.
- parameterizedTypeToString(env, (ClassType)t, full);
- case WILDCARD:
- Type.WildcardType a = (Type.WildcardType)t;
- return WildcardTypeImpl.wildcardTypeToString(env, a, full);
- default:
- return t.tsym.getQualifiedName().toString();
- }
- }
-
- /**
- * Return the formal type parameters of a class or method as an
- * angle-bracketed string. Each parameter is a type variable with
- * optional bounds. Class names are qualified if "full" is true.
- * Return "" if there are no type parameters or we're hiding generics.
- */
- static String typeParametersString(DocEnv env, Symbol sym, boolean full) {
- if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
- return "";
- }
- StringBuilder s = new StringBuilder();
- for (Type t : sym.type.getTypeArguments()) {
- s.append(s.length() == 0 ? "<" : ", ");
- s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
- }
- s.append(">");
- return s.toString();
- }
-
- /**
- * Return the actual type arguments of a parameterized type as an
- * angle-bracketed string. Class name are qualified if "full" is true.
- * Return "" if there are no type arguments or we're hiding generics.
- */
- static String typeArgumentsString(DocEnv env, ClassType cl, boolean full) {
- if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
- return "";
- }
- StringBuilder s = new StringBuilder();
- for (Type t : cl.getTypeArguments()) {
- s.append(s.length() == 0 ? "<" : ", ");
- s.append(getTypeString(env, t, full));
- }
- s.append(">");
- return s.toString();
- }
-
-
- private static class ArrayTypeImpl implements com.sun.javadoc.Type {
-
- Type arrayType;
-
- DocEnv env;
-
- ArrayTypeImpl(DocEnv env, Type arrayType) {
- this.env = env;
- this.arrayType = arrayType;
- }
-
- private com.sun.javadoc.Type skipArraysCache = null;
-
- public com.sun.javadoc.Type getElementType() {
- return TypeMaker.getType(env, env.types.elemtype(arrayType));
- }
-
- private com.sun.javadoc.Type skipArrays() {
- if (skipArraysCache == null) {
- Type t;
- for (t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) { }
- skipArraysCache = TypeMaker.getType(env, t);
- }
- return skipArraysCache;
- }
-
- /**
- * Return the type's dimension information, as a string.
- * <p>
- * For example, a two dimensional array of String returns '[][]'.
- */
- public String dimension() {
- StringBuilder dimension = new StringBuilder();
- for (Type t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) {
- dimension.append("[]");
- }
- return dimension.toString();
- }
-
- /**
- * Return unqualified name of type excluding any dimension information.
- * <p>
- * For example, a two dimensional array of String returns 'String'.
- */
- public String typeName() {
- return skipArrays().typeName();
- }
-
- /**
- * Return qualified name of type excluding any dimension information.
- *<p>
- * For example, a two dimensional array of String
- * returns 'java.lang.String'.
- */
- public String qualifiedTypeName() {
- return skipArrays().qualifiedTypeName();
- }
-
- /**
- * Return the simple name of this type excluding any dimension information.
- */
- public String simpleTypeName() {
- return skipArrays().simpleTypeName();
- }
-
- /**
- * Return this type as a class. Array dimensions are ignored.
- *
- * @return a ClassDocImpl if the type is a Class.
- * Return null if it is a primitive type..
- */
- public ClassDoc asClassDoc() {
- return skipArrays().asClassDoc();
- }
-
- /**
- * Return this type as a <code>ParameterizedType</code> if it
- * represents a parameterized type. Array dimensions are ignored.
- */
- public ParameterizedType asParameterizedType() {
- return skipArrays().asParameterizedType();
- }
-
- /**
- * Return this type as a <code>TypeVariable</code> if it represents
- * a type variable. Array dimensions are ignored.
- */
- public TypeVariable asTypeVariable() {
- return skipArrays().asTypeVariable();
- }
-
- /**
- * Return null, as there are no arrays of wildcard types.
- */
- public WildcardType asWildcardType() {
- return null;
- }
-
- /**
- * Return null, as there are no annotations of the type
- */
- public AnnotatedType asAnnotatedType() {
- return null;
- }
-
- /**
- * Return this type as an <code>AnnotationTypeDoc</code> if it
- * represents an annotation type. Array dimensions are ignored.
- */
- public AnnotationTypeDoc asAnnotationTypeDoc() {
- return skipArrays().asAnnotationTypeDoc();
- }
-
- /**
- * Return true if this is an array of a primitive type.
- */
- public boolean isPrimitive() {
- return skipArrays().isPrimitive();
- }
-
- /**
- * Return a string representation of the type.
- *
- * Return name of type including any dimension information.
- * <p>
- * For example, a two dimensional array of String returns
- * <code>String[][]</code>.
- *
- * @return name of type including any dimension information.
- */
- @Override
- public String toString() {
- return qualifiedTypeName() + dimension();
- }
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +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.code.Kinds;
-import com.sun.tools.javac.code.Kinds.KindSelector;
-import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Symbol.MethodSymbol;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.code.Type.TypeVar;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.Name;
-import com.sun.tools.javac.util.Names;
-
-/**
- * Implementation of <code>TypeVariable</code>, which
- * represents a type variable.
- *
- * <p><b>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.</b>
- *
- * @author Scott Seligman
- * @since 1.5
- */
-public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
-
- TypeVariableImpl(DocEnv env, TypeVar type) {
- super(env, type);
- }
-
- /**
- * Return the bounds of this type variable.
- */
- public com.sun.javadoc.Type[] bounds() {
- return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
- }
-
- /**
- * Return the class, interface, method, or constructor within
- * which this type variable is declared.
- */
- public ProgramElementDoc owner() {
- Symbol osym = type.tsym.owner;
- if (osym.kind.matches(KindSelector.TYP)) {
- return env.getClassDoc((ClassSymbol)osym);
- }
- Names names = osym.name.table.names;
- if (osym.name == names.init) {
- return env.getConstructorDoc((MethodSymbol)osym);
- } else {
- return env.getMethodDoc((MethodSymbol)osym);
- }
- }
-
- /**
- * Return the ClassDoc of the erasure of this type variable.
- */
- @Override
- public ClassDoc asClassDoc() {
- return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
- }
-
- @Override
- public TypeVariable asTypeVariable() {
- return this;
- }
-
- @Override
- public String toString() {
- return typeVarToString(env, (TypeVar)type, true);
- }
-
-
- /**
- * Return the string form of a type variable along with any
- * "extends" clause. Class names are qualified if "full" is true.
- */
- static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
- StringBuilder s = new StringBuilder(v.toString());
- List<Type> bounds = getBounds(v, env);
- if (bounds.nonEmpty()) {
- boolean first = true;
- for (Type b : bounds) {
- s.append(first ? " extends " : " & ");
- s.append(TypeMaker.getTypeString(env, b, full));
- first = false;
- }
- }
- return s.toString();
- }
-
- /**
- * Get the bounds of a type variable as listed in the "extends" clause.
- */
- private static List<Type> getBounds(TypeVar v, DocEnv env) {
- final Type upperBound = v.getUpperBound();
- Name boundname = upperBound.tsym.getQualifiedName();
- if (boundname == boundname.table.names.java_lang_Object
- && !upperBound.isAnnotated()) {
- return List.nil();
- } else {
- return env.types.getBounds(v);
- }
- }
-
- /**
- * Get the annotations of this program element.
- * Return an empty array if there are none.
- */
- public AnnotationDesc[] annotations() {
- if (!type.isAnnotated()) {
- return new AnnotationDesc[0];
- }
- List<? extends TypeCompound> tas = type.getAnnotationMirrors();
- AnnotationDesc res[] = new AnnotationDesc[tas.length()];
- int i = 0;
- for (Attribute.Compound a : tas) {
- res[i++] = new AnnotationDescImpl(env, a);
- }
- return res;
- }
-}
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/WildcardTypeImpl.java Wed Jul 05 21:41:01 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2003, 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 com.sun.javadoc.*;
-
-import com.sun.tools.javac.code.Symbol.ClassSymbol;
-import com.sun.tools.javac.code.Type;
-import com.sun.tools.javac.util.List;
-
-
-/**
- * Implementation of <code>WildcardType</code>, which
- * represents a wildcard type.
- *
- * <p><b>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.</b>
- *
- * @author Scott Seligman
- * @since 1.5
- */
-public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
-
- WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
- super(env, type);
- }
-
- /**
- * Return the upper bounds of this wildcard type argument
- * as given by the <i>extends</i> clause.
- * Return an empty array if no such bounds are explicitly given.
- */
- public com.sun.javadoc.Type[] extendsBounds() {
- return TypeMaker.getTypes(env, getExtendsBounds((Type.WildcardType)type));
- }
-
- /**
- * Return the lower bounds of this wildcard type argument
- * as given by the <i>super</i> clause.
- * Return an empty array if no such bounds are explicitly given.
- */
- public com.sun.javadoc.Type[] superBounds() {
- return TypeMaker.getTypes(env, getSuperBounds((Type.WildcardType)type));
- }
-
- /**
- * Return the ClassDoc of the erasure of this wildcard type.
- */
- @Override
- public ClassDoc asClassDoc() {
- return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
- }
-
- @Override
- public WildcardType asWildcardType() {
- return this;
- }
-
- @Override
- public String typeName() { return "?"; }
- @Override
- public String qualifiedTypeName() { return "?"; }
- @Override
- public String simpleTypeName() { return "?"; }
-
- @Override
- public String toString() {
- return wildcardTypeToString(env, (Type.WildcardType)type, true);
- }
-
-
- /**
- * Return the string form of a wildcard type ("?") along with any
- * "extends" or "super" clause. Delimiting brackets are not
- * included. Class names are qualified if "full" is true.
- */
- static String wildcardTypeToString(DocEnv env,
- Type.WildcardType wildThing, boolean full) {
- if (env.legacyDoclet) {
- return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
- }
- StringBuilder s = new StringBuilder("?");
- List<Type> bounds = getExtendsBounds(wildThing);
- if (bounds.nonEmpty()) {
- s.append(" extends ");
- } else {
- bounds = getSuperBounds(wildThing);
- if (bounds.nonEmpty()) {
- s.append(" super ");
- }
- }
- boolean first = true; // currently only one bound is allowed
- for (Type b : bounds) {
- if (!first) {
- s.append(" & ");
- }
- s.append(TypeMaker.getTypeString(env, b, full));
- first = false;
- }
- return s.toString();
- }
-
- private static List<Type> getExtendsBounds(Type.WildcardType wild) {
- return wild.isSuperBound()
- ? List.<Type>nil()
- : List.of(wild.type);
- }
-
- private static List<Type> getSuperBounds(Type.WildcardType wild) {
- return wild.isExtendsBound()
- ? List.<Type>nil()
- : List.of(wild.type);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AbstractTypeImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,115 @@
+/*
+ * 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Type;
+
+
+/**
+ * Abstract implementation of <code>Type</code>, with useful
+ * defaults for the methods in <code>Type</code> (and a couple from
+ * <code>ProgramElementDoc</code>).
+ *
+ * <p><b>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.</b>
+ *
+ * @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;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AnnotatedTypeImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,125 @@
+/*
+ * 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.main;
+
+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 <code>AnnotatedType</code>, 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<? extends TypeCompound> 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();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AnnotationDescImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,177 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @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<Pair<MethodSymbol,Attribute>> vals = annotation.values;
+ ElementValuePair res[] = new ElementValuePair[vals.length()];
+ int i = 0;
+ for (Pair<MethodSymbol,Attribute> 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:
+ * <pre>
+ * {@code @com.example.foo(name1=val1, name2=val2)}
+ * {@code @com.example.foo(val)}
+ * {@code @com.example.foo}
+ * </pre>
+ * 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();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AnnotationTypeDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,106 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @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<AnnotationTypeElementDoc> 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()]);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AnnotationTypeElementDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,90 @@
+/*
+ * 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Symbol.*;
+
+/**
+ * Represents an element of an annotation type.
+ *
+ * <p><b>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.</b>
+ *
+ * @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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/AnnotationValueImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,176 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @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:
+ * <ul><li> a wrapper class for a primitive type
+ * <li> <code>String</code>
+ * <li> <code>Type</code> (representing a class literal)
+ * <li> <code>FieldDoc</code> (representing an enum constant)
+ * <li> <code>AnnotationDesc</code>
+ * <li> <code>AnnotationValue[]</code>
+ * </ul>
+ */
+ 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 = "<error>";
+ }
+ }
+
+ /**
+ * 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("<error>");
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ClassDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,1329 @@
+/*
+ * 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.main;
+
+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).
+ *
+ * <p><b>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.</b>
+ *
+ * @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.
+ * <pre>
+ * Examples:
+ * for java.util.Hashtable
+ * return Hashtable
+ * for java.util.Map.Entry
+ * return Map.Entry
+ * </pre>
+ */
+ public String name() {
+ if (name == null) {
+ name = getClassName(tsym, false);
+ }
+ return name;
+ }
+
+ private String name;
+
+ /**
+ * Return the qualified class name as a String.
+ * <pre>
+ * Example:
+ * for java.util.Hashtable
+ * return java.util.Hashtable
+ * if no qualifier, just return flat name
+ * </pre>
+ */
+ public String qualifiedName() {
+ if (qualifiedName == null) {
+ qualifiedName = getClassName(tsym, true);
+ }
+ return qualifiedName;
+ }
+
+ private String qualifiedName;
+
+ /**
+ * Return unqualified name of type excluding any dimension information.
+ * <p>
+ * For example, a two dimensional array of String returns 'String'.
+ */
+ public String typeName() {
+ return name();
+ }
+
+ /**
+ * Return qualified name of type excluding any dimension information.
+ *<p>
+ * 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
+ * <code>ClassDoc</code> or a <code>ParameterizedType</code>.
+ */
+ 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<ClassDocImpl> 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<FieldDocImpl> 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<MethodDocImpl> 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<ConstructorDocImpl> 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<ClassDocImpl> 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<ClassDocImpl> 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<ClassDocImpl> 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<AttrContext> 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<Type> 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<ClassDocImpl>());
+ }
+
+ private MethodDocImpl searchMethod(String methodName,
+ String[] paramTypes, Set<ClassDocImpl> 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("<init>"))) {
+ 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<ClassDocImpl>());
+ }
+
+ private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> 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<ClassDocImpl> importedClasses = new ListBuffer<>();
+
+ Env<AttrContext> 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<PackageDocImpl> 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<AttrContext> 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 <code>java.io.Serializable</code>.
+ *
+ * Since <code>java.io.Externalizable</code> extends
+ * <code>java.io.Serializable</code>,
+ * 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
+ * <code>java.io.Externalizable</code>.
+ */
+ 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 <code>MethodDocImpl</code> 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.<p>
+ *
+ * Return either a list of default fields documented by
+ * <code>serial</code> tag<br>
+ * or return a single <code>FieldDoc</code> for
+ * <code>serialPersistentField</code> member.
+ * There should be a <code>serialField</code> tag for
+ * each Serializable field defined by an <code>ObjectStreamField</code>
+ * array component of <code>serialPersistentField</code>.
+ *
+ * @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 <code>serialPersistentFields</code>.
+ *
+ * @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.
+ * <p>
+ * 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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Comment.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,460 @@
+/*
+ * 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.main;
+
+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...
+ *
+ * <p><b>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.</b>
+ *
+ * @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<Tag> 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:
+ * <pre>
+ * 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.
+ * </pre>
+ */
+ @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<Tag> 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<ThrowsTag> 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<ParamTag> 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<SeeTag> 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<SerialFieldTag> 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<Tag> 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 <pre> } and {@literal </pre> }. */
+ 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;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ConstructorDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,103 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @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();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocEnv.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,869 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.4
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (generics)
+ */
+public class DocEnv {
+ protected static final Context.Key<DocEnv> 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<JCTree, TreePath> 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<PackageSymbol, PackageDocImpl> 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<ClassSymbol, ClassDocImpl> 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<VarSymbol, FieldDocImpl> 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<MethodSymbol, ExecutableMemberDocImpl> 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<ClassType, ParameterizedTypeImpl> parameterizedTypeMap =
+// new HashMap<ClassType, ParameterizedTypeImpl>();
+ /**
+ * 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<String> opts, Collection<String> customTagNames, String htmlVersion) {
+ ArrayList<String> 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<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>();
+
+ boolean shouldCheck(CompilationUnitTree unit) {
+ return shouldCheck.computeIfAbsent(unit, doclint :: shouldCheck);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,444 @@
+/*
+ * 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.main;
+
+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.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Atul M Dambalkar
+ * @author Neal Gafter (rewrite)
+ */
+public abstract class DocImpl implements Doc, Comparable<Object> {
+
+ /**
+ * 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).*<body\\b[^>]*>(.*)</body\\b.*");
+ Matcher m = bodyPat.matcher(rawDoc);
+ if (m.matches()) {
+ return m.group(1);
+ } else {
+ String key = rawDoc.matches("(?is).*<body\\b.*")
+ ? "javadoc.End_body_missing_from_html_file"
+ : "javadoc.Body_missing_from_html_file";
+ env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key);
+ return "";
+ }
+ }
+
+ /**
+ * Return the full unprocessed text of the comment. Tags
+ * are included as text. Used mainly for store and retrieve
+ * operations like internalization.
+ */
+ public String getRawCommentText() {
+ return documentation();
+ }
+
+ /**
+ * Set the full unprocessed text of the comment. Tags
+ * are included as text. Used mainly for store and retrieve
+ * operations like internalization.
+ */
+ public void setRawCommentText(String rawDocumentation) {
+ treePath = null;
+ documentation = rawDocumentation;
+ comment = null;
+ }
+
+ /**
+ * Set the full unprocessed text of the comment and tree path.
+ */
+ void setTreePath(TreePath treePath) {
+ this.treePath = treePath;
+ documentation = getCommentText(treePath);
+ comment = null;
+ }
+
+ /**
+ * return a key for sorting.
+ */
+ CollationKey key() {
+ if (collationkey == null) {
+ collationkey = generateKey();
+ }
+ return collationkey;
+ }
+
+ /**
+ * Generate a key for sorting.
+ * <p>
+ * 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.
+ * <p>
+ * 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; }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocLocale.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,241 @@
+/*
+ * 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.main;
+
+import java.text.BreakIterator;
+import java.text.Collator;
+import java.util.Locale;
+
+/**
+ * This class holds the information about locales.
+ *
+ * <p><b>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.</b>
+ *
+ * @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 <code>BreakIterator</code>
+ * to compute first sentence.
+ */
+ private boolean useBreakIterator = false;
+
+ /**
+ * The HTML sentence terminators.
+ */
+ static final String[] sentenceTerminators =
+ {
+ "<p>", "</p>", "<h1>", "<h2>",
+ "<h3>", "<h4>", "<h5>", "<h6>",
+ "</h1>", "</h2>", "</h3>", "</h4>", "</h5>",
+ "</h6>", "<hr>", "<pre>", "</pre>"
+ };
+
+ /**
+ * 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("<!--") && index != -1) {
+ return localeSpecificFirstSentence(doc, s.substring(index + 3, s.length()));
+ }
+ if (useBreakIterator || !locale.getLanguage().equals("en")) {
+ sentenceBreaker.setText(s.replace('\n', ' '));
+ int start = sentenceBreaker.first();
+ int end = sentenceBreaker.next();
+ return s.substring(start, end).trim();
+ } else {
+ return englishLanguageFirstSentence(s).trim();
+ }
+ }
+
+ /**
+ * Return the first sentence of a string, where a sentence ends
+ * with a period followed be white space.
+ */
+ private String englishLanguageFirstSentence(String s) {
+ if (s == null) {
+ return null;
+ }
+ int len = s.length();
+ boolean period = false;
+ for (int i = 0 ; i < len ; i++) {
+ switch (s.charAt(i)) {
+ case '.':
+ period = true;
+ break;
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ case '\f':
+ if (period) {
+ return s.substring(0, i);
+ }
+ break;
+ case '<':
+ if (i > 0) {
+ if (htmlSentenceTerminatorFound(s, i)) {
+ return s.substring(0, i);
+ }
+ }
+ break;
+ default:
+ period = false;
+ }
+ }
+ return s;
+ }
+
+ /**
+ * Find out if there is any HTML tag in the given string. If found
+ * return true else return false.
+ */
+ private boolean htmlSentenceTerminatorFound(String str, int index) {
+ for (String terminator : sentenceTerminators) {
+ if (str.regionMatches(true, index, terminator,
+ 0, terminator.length())) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/DocletInvoker.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,439 @@
+/*
+ * Copyright (c) 1998, 2016, 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.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+
+import javax.tools.DocumentationTool;
+import javax.tools.JavaFileManager;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.util.ClientCodeException;
+import com.sun.tools.javac.util.List;
+
+import static com.sun.javadoc.LanguageVersion.*;
+
+
+/**
+ * Class creates, controls and invokes doclets.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter (rewrite)
+ */
+public class DocletInvoker {
+
+ private final Class<?> docletClass;
+
+ private final String docletClassName;
+
+ private final ClassLoader appClassLoader;
+
+ private final Messager messager;
+
+ /**
+ * In API mode, exceptions thrown while calling the doclet are
+ * propagated using ClientCodeException.
+ */
+ private final boolean apiMode;
+
+ /**
+ * Whether javadoc internal API should be exported to doclets
+ * and (indirectly) to taglets
+ */
+ private final boolean exportInternalAPI;
+
+ private static class DocletInvokeException extends Exception {
+ private static final long serialVersionUID = 0;
+ }
+
+ private String appendPath(String path1, String path2) {
+ if (path1 == null || path1.length() == 0) {
+ return path2 == null ? "." : path2;
+ } else if (path2 == null || path2.length() == 0) {
+ return path1;
+ } else {
+ return path1 + File.pathSeparator + path2;
+ }
+ }
+
+ public DocletInvoker(Messager messager, Class<?> docletClass, boolean apiMode, boolean exportInternalAPI) {
+ this.messager = messager;
+ this.docletClass = docletClass;
+ docletClassName = docletClass.getName();
+ appClassLoader = null;
+ this.apiMode = apiMode;
+ this.exportInternalAPI = exportInternalAPI; // for backdoor use by standard doclet for taglets
+
+ // this may not be soon enough if the class has already been loaded
+ if (exportInternalAPI) {
+ exportInternalAPI(docletClass.getClassLoader());
+ }
+ }
+
+ public DocletInvoker(Messager messager, JavaFileManager fileManager,
+ String docletClassName, String docletPath,
+ ClassLoader docletParentClassLoader,
+ boolean apiMode,
+ boolean exportInternalAPI) {
+ this.messager = messager;
+ this.docletClassName = docletClassName;
+ this.apiMode = apiMode;
+ this.exportInternalAPI = exportInternalAPI; // for backdoor use by standard doclet for taglets
+
+ if (fileManager != null && fileManager.hasLocation(DocumentationTool.Location.DOCLET_PATH)) {
+ appClassLoader = fileManager.getClassLoader(DocumentationTool.Location.DOCLET_PATH);
+ } else {
+ // construct class loader
+ String cpString = null; // make sure env.class.path defaults to dot
+
+ // do prepends to get correct ordering
+ cpString = appendPath(System.getProperty("env.class.path"), cpString);
+ cpString = appendPath(System.getProperty("java.class.path"), cpString);
+ cpString = appendPath(docletPath, cpString);
+ URL[] urls = pathToURLs(cpString);
+ if (docletParentClassLoader == null)
+ appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
+ else
+ appClassLoader = new URLClassLoader(urls, docletParentClassLoader);
+ }
+
+ if (exportInternalAPI) {
+ exportInternalAPI(appClassLoader);
+ }
+
+ // attempt to find doclet
+ Class<?> dc = null;
+ try {
+ dc = appClassLoader.loadClass(docletClassName);
+ } catch (ClassNotFoundException exc) {
+ messager.error(Messager.NOPOS, "main.doclet_class_not_found", docletClassName);
+ messager.exit();
+ }
+ docletClass = dc;
+ }
+
+ /*
+ * Returns the delegation class loader to use when creating
+ * appClassLoader (used to load the doclet). The context class
+ * loader is the best choice, but legacy behavior was to use the
+ * default delegation class loader (aka system class loader).
+ *
+ * Here we favor using the context class loader. To ensure
+ * compatibility with existing apps, we revert to legacy
+ * behavior if either or both of the following conditions hold:
+ *
+ * 1) the doclet is loadable from the system class loader but not
+ * from the context class loader,
+ *
+ * 2) this.getClass() is loadable from the system class loader but not
+ * from the context class loader.
+ */
+ private ClassLoader getDelegationClassLoader(String docletClassName) {
+ ClassLoader ctxCL = Thread.currentThread().getContextClassLoader();
+ ClassLoader sysCL = ClassLoader.getSystemClassLoader();
+ if (sysCL == null)
+ return ctxCL;
+ if (ctxCL == null)
+ return sysCL;
+
+ // Condition 1.
+ try {
+ sysCL.loadClass(docletClassName);
+ try {
+ ctxCL.loadClass(docletClassName);
+ } catch (ClassNotFoundException e) {
+ return sysCL;
+ }
+ } catch (ClassNotFoundException e) {
+ }
+
+ // Condition 2.
+ try {
+ if (getClass() == sysCL.loadClass(getClass().getName())) {
+ try {
+ if (getClass() != ctxCL.loadClass(getClass().getName()))
+ return sysCL;
+ } catch (ClassNotFoundException e) {
+ return sysCL;
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ }
+
+ return ctxCL;
+ }
+
+ /**
+ * Generate documentation here. Return true on success.
+ */
+ public boolean start(RootDoc root) {
+ Object retVal;
+ String methodName = "start";
+ Class<?>[] paramTypes = { RootDoc.class };
+ Object[] params = { root };
+ try {
+ retVal = invoke(methodName, null, paramTypes, params);
+ } catch (DocletInvokeException exc) {
+ return false;
+ }
+ if (retVal instanceof Boolean) {
+ return ((Boolean)retVal);
+ } else {
+ messager.error(Messager.NOPOS, "main.must_return_boolean",
+ docletClassName, methodName);
+ return false;
+ }
+ }
+
+ /**
+ * Check for doclet added options here. Zero return means
+ * option not known. Positive value indicates number of
+ * arguments to option. Negative value means error occurred.
+ */
+ public int optionLength(String option) {
+ Object retVal;
+ String methodName = "optionLength";
+ Class<?>[] paramTypes = { String.class };
+ Object[] params = { option };
+ try {
+ retVal = invoke(methodName, 0, paramTypes, params);
+ } catch (DocletInvokeException exc) {
+ return -1;
+ }
+ if (retVal instanceof Integer) {
+ return ((Integer)retVal);
+ } else {
+ messager.error(Messager.NOPOS, "main.must_return_int",
+ docletClassName, methodName);
+ return -1;
+ }
+ }
+
+ /**
+ * Let doclet check that all options are OK. Returning true means
+ * options are OK. If method does not exist, assume true.
+ */
+ public boolean validOptions(List<String[]> optlist) {
+ Object retVal;
+ String options[][] = optlist.toArray(new String[optlist.length()][]);
+ String methodName = "validOptions";
+ DocErrorReporter reporter = messager;
+ Class<?>[] paramTypes = { String[][].class, DocErrorReporter.class };
+ Object[] params = { options, reporter };
+ try {
+ retVal = invoke(methodName, Boolean.TRUE, paramTypes, params);
+ } catch (DocletInvokeException exc) {
+ return false;
+ }
+ if (retVal instanceof Boolean) {
+ return ((Boolean)retVal);
+ } else {
+ messager.error(Messager.NOPOS, "main.must_return_boolean",
+ docletClassName, methodName);
+ return false;
+ }
+ }
+
+ /**
+ * Return the language version supported by this doclet.
+ * If the method does not exist in the doclet, assume version 1.1.
+ */
+ public LanguageVersion languageVersion() {
+ try {
+ Object retVal;
+ String methodName = "languageVersion";
+ Class<?>[] paramTypes = new Class<?>[0];
+ Object[] params = new Object[0];
+ try {
+ retVal = invoke(methodName, JAVA_1_1, paramTypes, params);
+ } catch (DocletInvokeException exc) {
+ return JAVA_1_1;
+ }
+ if (retVal instanceof LanguageVersion) {
+ return (LanguageVersion)retVal;
+ } else {
+ messager.error(Messager.NOPOS, "main.must_return_languageversion",
+ docletClassName, methodName);
+ return JAVA_1_1;
+ }
+ } catch (NoClassDefFoundError ex) { // for boostrapping, no Enum class.
+ return null;
+ }
+ }
+
+ /**
+ * Utility method for calling doclet functionality
+ */
+ private Object invoke(String methodName, Object returnValueIfNonExistent,
+ Class<?>[] paramTypes, Object[] params)
+ throws DocletInvokeException {
+ Method meth;
+ try {
+ meth = docletClass.getMethod(methodName, paramTypes);
+ } catch (NoSuchMethodException exc) {
+ if (returnValueIfNonExistent == null) {
+ messager.error(Messager.NOPOS, "main.doclet_method_not_found",
+ docletClassName, methodName);
+ throw new DocletInvokeException();
+ } else {
+ return returnValueIfNonExistent;
+ }
+ } catch (SecurityException exc) {
+ messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
+ docletClassName, methodName);
+ throw new DocletInvokeException();
+ }
+ if (!Modifier.isStatic(meth.getModifiers())) {
+ messager.error(Messager.NOPOS, "main.doclet_method_must_be_static",
+ docletClassName, methodName);
+ throw new DocletInvokeException();
+ }
+ ClassLoader savedCCL =
+ Thread.currentThread().getContextClassLoader();
+ try {
+ if (appClassLoader != null) // will be null if doclet class provided via API
+ Thread.currentThread().setContextClassLoader(appClassLoader);
+ return meth.invoke(null , params);
+ } catch (IllegalArgumentException | NullPointerException exc) {
+ messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
+ docletClassName, methodName, exc.toString());
+ throw new DocletInvokeException();
+ } catch (IllegalAccessException exc) {
+ messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
+ docletClassName, methodName);
+ throw new DocletInvokeException();
+ }
+ catch (InvocationTargetException exc) {
+ Throwable err = exc.getTargetException();
+ if (apiMode)
+ throw new ClientCodeException(err);
+ if (err instanceof java.lang.OutOfMemoryError) {
+ messager.error(Messager.NOPOS, "main.out.of.memory");
+ } else {
+ messager.error(Messager.NOPOS, "main.exception_thrown",
+ docletClassName, methodName, exc.toString());
+ exc.getTargetException().printStackTrace(System.err);
+ }
+ throw new DocletInvokeException();
+ } finally {
+ Thread.currentThread().setContextClassLoader(savedCCL);
+ }
+ }
+
+ /**
+ * Export javadoc internal API to the unnamed module for a classloader.
+ * This is to support continued use of existing non-standard doclets that
+ * use the internal toolkit API and related classes.
+ * @param cl the classloader
+ */
+ private void exportInternalAPI(ClassLoader cl) {
+ String[] packages = {
+ "com.sun.tools.doclets",
+ "com.sun.tools.doclets.standard",
+ "com.sun.tools.doclets.internal.toolkit",
+ "com.sun.tools.doclets.internal.toolkit.taglets",
+ "com.sun.tools.doclets.internal.toolkit.builders",
+ "com.sun.tools.doclets.internal.toolkit.util",
+ "com.sun.tools.doclets.internal.toolkit.util.links",
+ "com.sun.tools.doclets.formats.html",
+ "com.sun.tools.doclets.formats.html.markup"
+ };
+
+ try {
+ Method getModuleMethod = Class.class.getDeclaredMethod("getModule");
+ Object thisModule = getModuleMethod.invoke(getClass());
+
+ Class<?> moduleClass = Class.forName("java.lang.reflect.Module");
+ Method addExportsMethod = moduleClass.getDeclaredMethod("addExports", String.class, moduleClass);
+
+ Method getUnnamedModuleMethod = ClassLoader.class.getDeclaredMethod("getUnnamedModule");
+ Object target = getUnnamedModuleMethod.invoke(cl);
+
+ for (String pack : packages) {
+ addExportsMethod.invoke(thisModule, pack, target);
+ }
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
+
+ /**
+ * Utility method for converting a search path string to an array of directory and JAR file
+ * URLs.
+ *
+ * Note that this method is called by the DocletInvoker.
+ *
+ * @param path the search path string
+ * @return the resulting array of directory and JAR file URLs
+ */
+ private static URL[] pathToURLs(String path) {
+ java.util.List<URL> urls = new ArrayList<>();
+ for (String s: path.split(Pattern.quote(File.pathSeparator))) {
+ if (!s.isEmpty()) {
+ URL url = fileToURL(Paths.get(s));
+ if (url != null) {
+ urls.add(url);
+ }
+ }
+ }
+ return urls.toArray(new URL[urls.size()]);
+ }
+
+ /**
+ * Returns the directory or JAR file URL corresponding to the specified local file name.
+ *
+ * @param file the Path object
+ * @return the resulting directory or JAR file URL, or null if unknown
+ */
+ private static URL fileToURL(Path file) {
+ Path p;
+ try {
+ p = file.toRealPath();
+ } catch (IOException e) {
+ p = file.toAbsolutePath();
+ }
+ try {
+ return p.normalize().toUri().toURL();
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ExecutableMemberDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,288 @@
+/*
+ * 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.main;
+
+import java.lang.reflect.Modifier;
+import java.text.CollationKey;
+
+import com.sun.javadoc.*;
+
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+
+/**
+ * Represents a method or constructor of a java class.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (generics, annotations)
+ */
+
+public abstract class ExecutableMemberDocImpl
+ extends MemberDocImpl implements ExecutableMemberDoc {
+
+ protected final MethodSymbol sym;
+
+ /**
+ * Constructor.
+ */
+ public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+ super(env, sym, treePath);
+ this.sym = sym;
+ }
+
+ /**
+ * Constructor.
+ */
+ public ExecutableMemberDocImpl(DocEnv env, MethodSymbol sym) {
+ this(env, sym, null);
+ }
+
+ /**
+ * Returns the flags in terms of javac's flags
+ */
+ protected long getFlags() {
+ return sym.flags();
+ }
+
+ /**
+ * Identify the containing class
+ */
+ protected ClassSymbol getContainingClass() {
+ return sym.enclClass();
+ }
+
+ /**
+ * Return true if this method is native
+ */
+ public boolean isNative() {
+ return Modifier.isNative(getModifiers());
+ }
+
+ /**
+ * Return true if this method is synchronized
+ */
+ public boolean isSynchronized() {
+ return Modifier.isSynchronized(getModifiers());
+ }
+
+ /**
+ * Return true if this method was declared to take a variable number
+ * of arguments.
+ */
+ public boolean isVarArgs() {
+ return ((sym.flags() & Flags.VARARGS) != 0
+ && !env.legacyDoclet);
+ }
+
+ /**
+ * Returns true if this field was synthesized by the compiler.
+ */
+ public boolean isSynthetic() {
+ return ((sym.flags() & Flags.SYNTHETIC) != 0);
+ }
+
+ public boolean isIncluded() {
+ return containingClass().isIncluded() && env.shouldDocument(sym);
+ }
+
+ /**
+ * Return the throws tags in this method.
+ *
+ * @return an array of ThrowTagImpl containing all {@code @exception}
+ * and {@code @throws} tags.
+ */
+ public ThrowsTag[] throwsTags() {
+ return comment().throwsTags();
+ }
+
+ /**
+ * Return the param tags in this method, excluding the type
+ * parameter tags.
+ *
+ * @return an array of ParamTagImpl containing all {@code @param} tags.
+ */
+ public ParamTag[] paramTags() {
+ return comment().paramTags();
+ }
+
+ /**
+ * Return the type parameter tags in this method.
+ */
+ public ParamTag[] typeParamTags() {
+ return env.legacyDoclet
+ ? new ParamTag[0]
+ : comment().typeParamTags();
+ }
+
+ /**
+ * Return exceptions this method or constructor throws.
+ *
+ * @return an array of ClassDoc[] representing the exceptions
+ * thrown by this method.
+ */
+ public ClassDoc[] thrownExceptions() {
+ ListBuffer<ClassDocImpl> l = new ListBuffer<>();
+ for (Type ex : sym.type.getThrownTypes()) {
+ ex = env.types.erasure(ex);
+ //### Will these casts succeed in the face of static semantic
+ //### errors in the documented code?
+ ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym);
+ if (cdi != null) l.append(cdi);
+ }
+ return l.toArray(new ClassDocImpl[l.length()]);
+ }
+
+ /**
+ * Return exceptions this method or constructor throws.
+ * Each array element is either a <code>ClassDoc</code> or a
+ * <code>TypeVariable</code>.
+ */
+ public com.sun.javadoc.Type[] thrownExceptionTypes() {
+ return TypeMaker.getTypes(env, sym.type.getThrownTypes());
+ }
+
+ /**
+ * Get argument information.
+ *
+ * @see ParameterImpl
+ *
+ * @return an array of ParameterImpl, one element per argument
+ * in the order the arguments are present.
+ */
+ public Parameter[] parameters() {
+ // generate the parameters on the fly: they're not cached
+ List<VarSymbol> params = sym.params();
+ Parameter result[] = new Parameter[params.length()];
+
+ int i = 0;
+ for (VarSymbol param : params) {
+ result[i++] = new ParameterImpl(env, param);
+ }
+ return result;
+ }
+
+ /**
+ * Get the receiver type of this executable element.
+ *
+ * @return the receiver type of this executable element.
+ * @since 1.8
+ */
+ public com.sun.javadoc.Type receiverType() {
+ Type recvtype = sym.type.asMethodType().recvtype;
+ return (recvtype != null) ? TypeMaker.getType(env, recvtype, false, true) : null;
+ }
+
+ /**
+ * Return the formal type parameters of this method or constructor.
+ * Return an empty array if there are none.
+ */
+ public TypeVariable[] typeParameters() {
+ if (env.legacyDoclet) {
+ return new TypeVariable[0];
+ }
+ TypeVariable res[] = new TypeVariable[sym.type.getTypeArguments().length()];
+ TypeMaker.getTypes(env, sym.type.getTypeArguments(), res);
+ return res;
+ }
+
+ /**
+ * Get the signature. It is the parameter list, type is qualified.
+ * For instance, for a method <code>mymethod(String x, int y)</code>,
+ * it will return <code>(java.lang.String,int)</code>.
+ */
+ public String signature() {
+ return makeSignature(true);
+ }
+
+ /**
+ * Get flat signature. All types are not qualified.
+ * Return a String, which is the flat signiture of this member.
+ * It is the parameter list, type is not qualified.
+ * For instance, for a method <code>mymethod(String x, int y)</code>,
+ * it will return <code>(String, int)</code>.
+ */
+ public String flatSignature() {
+ return makeSignature(false);
+ }
+
+ private String makeSignature(boolean full) {
+ StringBuilder result = new StringBuilder();
+ result.append("(");
+ for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {
+ Type t = types.head;
+ result.append(TypeMaker.getTypeString(env, t, full));
+ types = types.tail;
+ if (types.nonEmpty()) {
+ result.append(", ");
+ }
+ }
+ if (isVarArgs()) {
+ int len = result.length();
+ result.replace(len - 2, len, "...");
+ }
+ result.append(")");
+ return result.toString();
+ }
+
+ protected String typeParametersString() {
+ return TypeMaker.typeParametersString(env, sym, true);
+ }
+
+ /**
+ * Generate a key for sorting.
+ */
+ @Override
+ CollationKey generateKey() {
+ String k = name() + flatSignature() + typeParametersString();
+ // ',' and '&' are between '$' and 'a': normalize to spaces.
+ k = k.replace(',', ' ').replace('&', ' ');
+ // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
+ return env.doclocale.collator.getCollationKey(k);
+ }
+
+ /**
+ * Return the source position of the entity, or null if
+ * no position is available.
+ */
+ @Override
+ public SourcePosition position() {
+ if (sym.enclClass().sourcefile == null) return null;
+ return SourcePositionImpl.make(sym.enclClass().sourcefile,
+ (tree==null) ? 0 : tree.pos,
+ lineMap);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/FieldDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,279 @@
+/*
+ * 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.main;
+
+import com.sun.source.util.TreePath;
+import java.lang.reflect.Modifier;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.VarSymbol;
+
+import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
+
+/**
+ * Represents a field in a java class.
+ *
+ * <p><b>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.</b>
+ *
+ * @see MemberDocImpl
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (generics, enums, annotations)
+ */
+public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
+
+ protected final VarSymbol sym;
+
+ /**
+ * Constructor.
+ */
+ public FieldDocImpl(DocEnv env, VarSymbol sym, TreePath treePath) {
+ super(env, sym, treePath);
+ this.sym = sym;
+ }
+
+ /**
+ * Constructor.
+ */
+ public FieldDocImpl(DocEnv env, VarSymbol sym) {
+ this(env, sym, null);
+ }
+
+ /**
+ * Returns the flags in terms of javac's flags
+ */
+ protected long getFlags() {
+ return sym.flags();
+ }
+
+ /**
+ * Identify the containing class
+ */
+ protected ClassSymbol getContainingClass() {
+ return sym.enclClass();
+ }
+
+ /**
+ * Get type of this field.
+ */
+ public com.sun.javadoc.Type type() {
+ return TypeMaker.getType(env, sym.type, false);
+ }
+
+ /**
+ * Get the value of a constant field.
+ *
+ * @return the value of a constant field. The value is
+ * automatically wrapped in an object if it has a primitive type.
+ * If the field is not constant, returns null.
+ */
+ public Object constantValue() {
+ Object result = sym.getConstValue();
+ if (result != null && sym.type.hasTag(BOOLEAN))
+ // javac represents false and true as Integers 0 and 1
+ result = Boolean.valueOf(((Integer)result).intValue() != 0);
+ return result;
+ }
+
+ /**
+ * Get the value of a constant field.
+ *
+ * @return the text of a Java language expression whose value
+ * is the value of the constant. The expression uses no identifiers
+ * other than primitive literals. If the field is
+ * not constant, returns null.
+ */
+ public String constantValueExpression() {
+ return constantValueExpression(constantValue());
+ }
+
+ /**
+ * A static version of the above.
+ */
+ static String constantValueExpression(Object cb) {
+ if (cb == null) return null;
+ if (cb instanceof Character) return sourceForm(((Character)cb).charValue());
+ if (cb instanceof Byte) return sourceForm(((Byte)cb).byteValue());
+ if (cb instanceof String) return sourceForm((String)cb);
+ if (cb instanceof Double) return sourceForm(((Double)cb).doubleValue(), 'd');
+ if (cb instanceof Float) return sourceForm(((Float)cb).doubleValue(), 'f');
+ if (cb instanceof Long) return cb + "L";
+ return cb.toString(); // covers int, short
+ }
+ // where
+ private static String sourceForm(double v, char suffix) {
+ if (Double.isNaN(v))
+ return "0" + suffix + "/0" + suffix;
+ if (v == Double.POSITIVE_INFINITY)
+ return "1" + suffix + "/0" + suffix;
+ if (v == Double.NEGATIVE_INFINITY)
+ return "-1" + suffix + "/0" + suffix;
+ return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : "");
+ }
+ private static String sourceForm(char c) {
+ StringBuilder buf = new StringBuilder(8);
+ buf.append('\'');
+ sourceChar(c, buf);
+ buf.append('\'');
+ return buf.toString();
+ }
+ private static String sourceForm(byte c) {
+ return "0x" + Integer.toString(c & 0xff, 16);
+ }
+ private static String sourceForm(String s) {
+ StringBuilder buf = new StringBuilder(s.length() + 5);
+ buf.append('\"');
+ for (int i=0; i<s.length(); i++) {
+ char c = s.charAt(i);
+ sourceChar(c, buf);
+ }
+ buf.append('\"');
+ return buf.toString();
+ }
+ private static void sourceChar(char c, StringBuilder buf) {
+ switch (c) {
+ case '\b': buf.append("\\b"); return;
+ case '\t': buf.append("\\t"); return;
+ case '\n': buf.append("\\n"); return;
+ case '\f': buf.append("\\f"); return;
+ case '\r': buf.append("\\r"); return;
+ case '\"': buf.append("\\\""); return;
+ case '\'': buf.append("\\\'"); return;
+ case '\\': buf.append("\\\\"); return;
+ default:
+ if (isPrintableAscii(c)) {
+ buf.append(c); return;
+ }
+ unicodeEscape(c, buf);
+ return;
+ }
+ }
+ private static void unicodeEscape(char c, StringBuilder buf) {
+ final String chars = "0123456789abcdef";
+ buf.append("\\u");
+ buf.append(chars.charAt(15 & (c>>12)));
+ buf.append(chars.charAt(15 & (c>>8)));
+ buf.append(chars.charAt(15 & (c>>4)));
+ buf.append(chars.charAt(15 & (c>>0)));
+ }
+ private static boolean isPrintableAscii(char c) {
+ return c >= ' ' && c <= '~';
+ }
+
+ /**
+ * Return true if this field is included in the active set.
+ */
+ public boolean isIncluded() {
+ return containingClass().isIncluded() && env.shouldDocument(sym);
+ }
+
+ /**
+ * Is this Doc item a field (but not an enum constant?
+ */
+ @Override
+ public boolean isField() {
+ return !isEnumConstant();
+ }
+
+ /**
+ * Is this Doc item an enum constant?
+ * (For legacy doclets, return false.)
+ */
+ @Override
+ public boolean isEnumConstant() {
+ return (getFlags() & Flags.ENUM) != 0 &&
+ !env.legacyDoclet;
+ }
+
+ /**
+ * Return true if this field is transient
+ */
+ public boolean isTransient() {
+ return Modifier.isTransient(getModifiers());
+ }
+
+ /**
+ * Return true if this field is volatile
+ */
+ public boolean isVolatile() {
+ return Modifier.isVolatile(getModifiers());
+ }
+
+ /**
+ * Returns true if this field was synthesized by the compiler.
+ */
+ public boolean isSynthetic() {
+ return (getFlags() & Flags.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return the serialField tags in this FieldDocImpl item.
+ *
+ * @return an array of <tt>SerialFieldTagImpl</tt> containing all
+ * <code>@serialField</code> tags.
+ */
+ public SerialFieldTag[] serialFieldTags() {
+ return comment().serialFieldTags();
+ }
+
+ public String name() {
+ if (name == null) {
+ name = sym.name.toString();
+ }
+ return name;
+ }
+
+ private String name;
+
+ public String qualifiedName() {
+ if (qualifiedName == null) {
+ qualifiedName = sym.enclClass().getQualifiedName() + "." + name();
+ }
+ return qualifiedName;
+ }
+
+ private String qualifiedName;
+
+ /**
+ * Return the source position of the entity, or null if
+ * no position is available.
+ */
+ @Override
+ public SourcePosition position() {
+ if (sym.enclClass().sourcefile == null) return null;
+ return SourcePositionImpl.make(sym.enclClass().sourcefile,
+ (tree==null) ? 0 : tree.pos,
+ lineMap);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocClassFinder.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2001, 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.main;
+
+import java.util.EnumSet;
+import javax.tools.JavaFileObject;
+
+import com.sun.tools.javac.code.Symbol.PackageSymbol;
+import com.sun.tools.javac.code.ClassFinder;
+import com.sun.tools.javac.util.Context;
+
+/** Javadoc uses an extended class finder that records package.html entries
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter
+ */
+public class JavadocClassFinder extends ClassFinder {
+
+ public static JavadocClassFinder instance(Context context) {
+ ClassFinder instance = context.get(classFinderKey);
+ if (instance == null)
+ instance = new JavadocClassFinder(context);
+ return (JavadocClassFinder)instance;
+ }
+
+ public static void preRegister(Context context) {
+ context.put(classFinderKey, new Context.Factory<ClassFinder>() {
+ public ClassFinder make(Context c) {
+ return new JavadocClassFinder(c);
+ }
+ });
+ }
+
+ private DocEnv docenv;
+ private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS,
+ JavaFileObject.Kind.SOURCE,
+ JavaFileObject.Kind.HTML);
+ private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS,
+ JavaFileObject.Kind.HTML);
+
+ public JavadocClassFinder(Context context) {
+ super(context);
+ docenv = DocEnv.instance(context);
+ preferSource = true;
+ }
+
+ /**
+ * Override getPackageFileKinds to include search for package.html
+ */
+ @Override
+ protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
+ return docenv.docClasses ? noSource : all;
+ }
+
+ /**
+ * Override extraFileActions to check for package documentation
+ */
+ @Override
+ protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
+ if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))
+ docenv.getPackageDoc(pack).setDocPath(fo);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocEnter.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2001, 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.main;
+
+import javax.tools.JavaFileObject;
+
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.comp.Enter;
+import com.sun.tools.javac.tree.JCTree.*;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
+import com.sun.tools.javac.util.List;
+
+import static com.sun.tools.javac.code.Kinds.Kind.*;
+
+/**
+ * Javadoc's own enter phase does a few things above and beyond that
+ * done by javac.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter
+ */
+public class JavadocEnter extends Enter {
+ public static JavadocEnter instance(Context context) {
+ Enter instance = context.get(enterKey);
+ if (instance == null)
+ instance = new JavadocEnter(context);
+ return (JavadocEnter)instance;
+ }
+
+ public static void preRegister(Context context) {
+ context.put(enterKey, new Context.Factory<Enter>() {
+ public Enter make(Context c) {
+ return new JavadocEnter(c);
+ }
+ });
+ }
+
+ protected JavadocEnter(Context context) {
+ super(context);
+ messager = Messager.instance0(context);
+ docenv = DocEnv.instance(context);
+ }
+
+ final Messager messager;
+ final DocEnv docenv;
+
+ @Override
+ public void main(List<JCCompilationUnit> trees) {
+ // count all Enter errors as warnings.
+ int nerrors = messager.nerrors;
+ super.main(trees);
+ messager.nwarnings += (messager.nerrors - nerrors);
+ messager.nerrors = nerrors;
+ }
+
+ @Override
+ public void visitTopLevel(JCCompilationUnit tree) {
+ super.visitTopLevel(tree);
+ if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
+ JCPackageDecl pd = tree.getPackage();
+ TreePath tp = pd == null ? docenv.getTreePath(tree) : docenv.getTreePath(tree, pd);
+ docenv.makePackageDoc(tree.packge, tp);
+ }
+ }
+
+ @Override
+ public void visitClassDef(JCClassDecl tree) {
+ super.visitClassDef(tree);
+ if (tree.sym == null) return;
+ if (tree.sym.kind == TYP || tree.sym.kind == ERR) {
+ ClassSymbol c = tree.sym;
+ docenv.makeClassDoc(c, docenv.getTreePath(env.toplevel, tree));
+ }
+ }
+
+ /** Don't complain about a duplicate class. */
+ @Override
+ protected void duplicateClass(DiagnosticPosition pos, ClassSymbol c) {}
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocMemberEnter.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,209 @@
+/*
+ * 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.main;
+
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.comp.MemberEnter;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.*;
+import com.sun.tools.javac.util.Context;
+
+import static com.sun.tools.javac.code.Flags.*;
+import static com.sun.tools.javac.code.Kinds.Kind.*;
+
+/**
+ * Javadoc's own memberEnter phase does a few things above and beyond that
+ * done by javac.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter
+ */
+public class JavadocMemberEnter extends MemberEnter {
+ public static JavadocMemberEnter instance0(Context context) {
+ MemberEnter instance = context.get(memberEnterKey);
+ if (instance == null)
+ instance = new JavadocMemberEnter(context);
+ return (JavadocMemberEnter)instance;
+ }
+
+ public static void preRegister(Context context) {
+ context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
+ public MemberEnter make(Context c) {
+ return new JavadocMemberEnter(c);
+ }
+ });
+ }
+
+ final DocEnv docenv;
+
+ protected JavadocMemberEnter(Context context) {
+ super(context);
+ docenv = DocEnv.instance(context);
+ }
+
+ @Override
+ public void visitMethodDef(JCMethodDecl tree) {
+ super.visitMethodDef(tree);
+ MethodSymbol meth = tree.sym;
+ if (meth == null || meth.kind != MTH) return;
+ TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree);
+ if (meth.isConstructor())
+ docenv.makeConstructorDoc(meth, treePath);
+ else if (isAnnotationTypeElement(meth))
+ docenv.makeAnnotationTypeElementDoc(meth, treePath);
+ else
+ docenv.makeMethodDoc(meth, treePath);
+
+ // release resources
+ tree.body = null;
+ }
+
+ @Override
+ public void visitVarDef(JCVariableDecl tree) {
+ if (tree.init != null) {
+ boolean isFinal = (tree.mods.flags & FINAL) != 0
+ || (env.enclClass.mods.flags & INTERFACE) != 0;
+ if (!isFinal || containsNonConstantExpression(tree.init)) {
+ // Avoid unnecessary analysis and release resources.
+ // In particular, remove non-constant expressions
+ // which may trigger Attr.attribClass, since
+ // method bodies are also removed, in visitMethodDef.
+ tree.init = null;
+ }
+ }
+ super.visitVarDef(tree);
+ if (tree.sym != null &&
+ tree.sym.kind == VAR &&
+ !isParameter(tree.sym)) {
+ docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree));
+ }
+ }
+
+ private static boolean isAnnotationTypeElement(MethodSymbol meth) {
+ return ClassDocImpl.isAnnotationType(meth.enclClass());
+ }
+
+ private static boolean isParameter(VarSymbol var) {
+ return (var.flags() & Flags.PARAMETER) != 0;
+ }
+
+ /**
+ * Simple analysis of an expression tree to see if it contains tree nodes
+ * for any non-constant expression. This does not include checking references
+ * to other fields which may or may not be constant.
+ */
+ private static boolean containsNonConstantExpression(JCExpression tree) {
+ return new MaybeConstantExpressionScanner().containsNonConstantExpression(tree);
+ }
+
+ /**
+ * See JLS 15.18, Constant Expression
+ */
+ private static class MaybeConstantExpressionScanner extends JCTree.Visitor {
+ boolean maybeConstantExpr = true;
+
+ public boolean containsNonConstantExpression(JCExpression tree) {
+ scan(tree);
+ return !maybeConstantExpr;
+ }
+
+ public void scan(JCTree tree) {
+ // short circuit scan when end result is definitely false
+ if (maybeConstantExpr && tree != null)
+ tree.accept(this);
+ }
+
+ @Override
+ /** default for any non-overridden visit method. */
+ public void visitTree(JCTree tree) {
+ maybeConstantExpr = false;
+ }
+
+ @Override
+ public void visitBinary(JCBinary tree) {
+ switch (tree.getTag()) {
+ case MUL: case DIV: case MOD:
+ case PLUS: case MINUS:
+ case SL: case SR: case USR:
+ case LT: case LE: case GT: case GE:
+ case EQ: case NE:
+ case BITAND: case BITXOR: case BITOR:
+ case AND: case OR:
+ break;
+ default:
+ maybeConstantExpr = false;
+ }
+ }
+
+ @Override
+ public void visitConditional(JCConditional tree) {
+ scan(tree.cond);
+ scan(tree.truepart);
+ scan(tree.falsepart);
+ }
+
+ @Override
+ public void visitIdent(JCIdent tree) { }
+
+ @Override
+ public void visitLiteral(JCLiteral tree) { }
+
+ @Override
+ public void visitParens(JCParens tree) {
+ scan(tree.expr);
+ }
+
+ @Override
+ public void visitSelect(JCTree.JCFieldAccess tree) {
+ scan(tree.selected);
+ }
+
+ @Override
+ public void visitTypeCast(JCTypeCast tree) {
+ scan(tree.clazz);
+ scan(tree.expr);
+ }
+
+ @Override
+ public void visitTypeIdent(JCPrimitiveTypeTree tree) { }
+
+ @Override
+ public void visitUnary(JCUnary tree) {
+ switch (tree.getTag()) {
+ case POS: case NEG: case COMPL: case NOT:
+ break;
+ default:
+ maybeConstantExpr = false;
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocTodo.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2003, 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.main;
+
+import com.sun.tools.javac.comp.*;
+import com.sun.tools.javac.util.*;
+
+/**
+ * Javadoc's own todo queue doesn't queue its inputs, as javadoc
+ * doesn't perform attribution of method bodies or semantic checking.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter
+ */
+public class JavadocTodo extends Todo {
+ public static void preRegister(Context context) {
+ context.put(todoKey, new Context.Factory<Todo>() {
+ public Todo make(Context c) {
+ return new JavadocTodo(c);
+ }
+ });
+ }
+
+ protected JavadocTodo(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void append(Env<AttrContext> e) {
+ // do nothing; Javadoc doesn't perform attribution.
+ }
+
+ @Override
+ public boolean offer(Env<AttrContext> e) {
+ return false;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/JavadocTool.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,430 @@
+/*
+ * Copyright (c) 2001, 2016, 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.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileManager.Location;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+
+import com.sun.tools.javac.code.ClassFinder;
+import com.sun.tools.javac.code.Symbol.Completer;
+import com.sun.tools.javac.code.Symbol.ModuleSymbol;
+import com.sun.tools.javac.comp.Enter;
+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.util.Abort;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+
+
+/**
+ * This class could be the main entry point for Javadoc when Javadoc is used as a
+ * component in a larger software system. It provides operations to
+ * construct a new javadoc processor, and to run it on a set of source
+ * files.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Neal Gafter
+ */
+public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
+ DocEnv docenv;
+
+ final Messager messager;
+ final ClassFinder javadocFinder;
+ final Enter javadocEnter;
+ final Set<JavaFileObject> uniquefiles;
+
+ /**
+ * Construct a new JavaCompiler processor, using appropriately
+ * extended phases of the underlying compiler.
+ */
+ protected JavadocTool(Context context) {
+ super(context);
+ messager = Messager.instance0(context);
+ javadocFinder = JavadocClassFinder.instance(context);
+ javadocEnter = JavadocEnter.instance(context);
+ uniquefiles = new HashSet<>();
+ }
+
+ /**
+ * For javadoc, the parser needs to keep comments. Overrides method from JavaCompiler.
+ */
+ @Override
+ protected boolean keepComments() {
+ return true;
+ }
+
+ /**
+ * Construct a new javadoc tool.
+ */
+ public static JavadocTool make0(Context context) {
+ // force the use of Javadoc's class finder
+ JavadocClassFinder.preRegister(context);
+
+ // force the use of Javadoc's own enter phase
+ JavadocEnter.preRegister(context);
+
+ // force the use of Javadoc's own member enter phase
+ JavadocMemberEnter.preRegister(context);
+
+ // force the use of Javadoc's own todo phase
+ JavadocTodo.preRegister(context);
+
+ // force the use of Messager as a Log
+ Messager.instance0(context);
+
+ return new JavadocTool(context);
+ }
+
+ public RootDocImpl getRootDocImpl(String doclocale,
+ String encoding,
+ ModifierFilter filter,
+ List<String> args,
+ List<String[]> options,
+ Iterable<? extends JavaFileObject> fileObjects,
+ boolean breakiterator,
+ List<String> subPackages,
+ List<String> excludedPackages,
+ boolean docClasses,
+ boolean legacyDoclet,
+ boolean quiet) throws IOException {
+ docenv = DocEnv.instance(context);
+ docenv.showAccess = filter;
+ docenv.quiet = quiet;
+ docenv.breakiterator = breakiterator;
+ docenv.setLocale(doclocale);
+ docenv.setEncoding(encoding);
+ docenv.docClasses = docClasses;
+ docenv.legacyDoclet = legacyDoclet;
+
+ javadocFinder.sourceCompleter = docClasses ? Completer.NULL_COMPLETER : sourceCompleter;
+
+ if (docClasses) {
+ // If -Xclasses is set, the args should be a series of class names
+ for (String arg: args) {
+ if (!isValidPackageName(arg)) // checks
+ docenv.error(null, "main.illegal_class_name", arg);
+ }
+ if (messager.nerrors() != 0) {
+ return null;
+ }
+ return new RootDocImpl(docenv, args, options);
+ }
+
+ ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<>();
+ Set<String> includedPackages = new LinkedHashSet<>();
+
+ try {
+ StandardJavaFileManager fm = docenv.fileManager instanceof StandardJavaFileManager
+ ? (StandardJavaFileManager) docenv.fileManager : null;
+ Set<String> packageNames = new LinkedHashSet<>();
+ // Normally, the args should be a series of package names or file names.
+ // Parse the files and collect the package names.
+ for (String arg: args) {
+ if (fm != null && arg.endsWith(".java") && new File(arg).exists()) {
+ if (new File(arg).getName().equals("module-info.java")) {
+ docenv.warning(null, "main.file_ignored", arg);
+ } else {
+ parse(fm.getJavaFileObjects(arg), classTrees, true);
+ }
+ } else if (isValidPackageName(arg)) {
+ packageNames.add(arg);
+ } else if (arg.endsWith(".java")) {
+ if (fm == null)
+ throw new IllegalArgumentException();
+ else
+ docenv.error(null, "main.file_not_found", arg);
+ } else {
+ docenv.error(null, "main.illegal_package_name", arg);
+ }
+ }
+
+ // Parse file objects provide via the DocumentationTool API
+ parse(fileObjects, classTrees, true);
+ modules.enter(classTrees.toList(), null);
+
+ syms.unnamedModule.complete(); // TEMP to force reading all named modules
+
+ // Build up the complete list of any packages to be documented
+ Location location =
+ modules.multiModuleMode && !modules.noModules ? StandardLocation.MODULE_SOURCE_PATH
+ : docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) ? StandardLocation.SOURCE_PATH
+ : StandardLocation.CLASS_PATH;
+
+ PackageTable t = new PackageTable(docenv.fileManager, location)
+ .packages(packageNames)
+ .subpackages(subPackages, excludedPackages);
+
+ includedPackages = t.getIncludedPackages();
+
+ // Parse the files in the packages to be documented
+ ListBuffer<JCCompilationUnit> packageTrees = new ListBuffer<>();
+ for (String packageName: includedPackages) {
+ List<JavaFileObject> files = t.getFiles(packageName);
+ docenv.notice("main.Loading_source_files_for_package", packageName);
+
+ if (files.isEmpty())
+ messager.warning(Messager.NOPOS, "main.no_source_files_for_package", packageName);
+ parse(files, packageTrees, false);
+ }
+ modules.enter(packageTrees.toList(), null);
+
+ if (messager.nerrors() != 0) {
+ return null;
+ }
+
+ // Enter symbols for all files
+ docenv.notice("main.Building_tree");
+ javadocEnter.main(classTrees.toList().appendList(packageTrees.toList()));
+ enterDone = true;
+ } catch (Abort ex) {}
+
+ if (messager.nerrors() != 0)
+ return null;
+
+ return new RootDocImpl(docenv, listClasses(classTrees.toList()), List.from(includedPackages), options);
+ }
+
+ /** Is the given string a valid package name? */
+ boolean isValidPackageName(String s) {
+ int index;
+ while ((index = s.indexOf('.')) != -1) {
+ if (!isValidClassName(s.substring(0, index))) return false;
+ s = s.substring(index+1);
+ }
+ return isValidClassName(s);
+ }
+
+ private void parse(Iterable<? extends JavaFileObject> files, ListBuffer<JCCompilationUnit> trees,
+ boolean trace) {
+ for (JavaFileObject fo: files) {
+ if (uniquefiles.add(fo)) { // ignore duplicates
+ if (trace)
+ docenv.notice("main.Loading_source_file", fo.getName());
+ trees.append(parse(fo));
+ }
+ }
+ }
+
+ /** Are surrogates supported?
+ */
+ final static boolean surrogatesSupported = surrogatesSupported();
+ private static boolean surrogatesSupported() {
+ try {
+ boolean b = Character.isHighSurrogate('a');
+ return true;
+ } catch (NoSuchMethodError ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Return true if given file name is a valid class name
+ * (including "package-info").
+ * @param s the name of the class to check.
+ * @return true if given class name is a valid class name
+ * and false otherwise.
+ */
+ public static boolean isValidClassName(String s) {
+ if (s.length() < 1) return false;
+ if (s.equals("package-info")) return true;
+ if (surrogatesSupported) {
+ int cp = s.codePointAt(0);
+ if (!Character.isJavaIdentifierStart(cp))
+ return false;
+ for (int j=Character.charCount(cp); j<s.length(); j+=Character.charCount(cp)) {
+ cp = s.codePointAt(j);
+ if (!Character.isJavaIdentifierPart(cp))
+ return false;
+ }
+ } else {
+ if (!Character.isJavaIdentifierStart(s.charAt(0)))
+ return false;
+ for (int j=1; j<s.length(); j++)
+ if (!Character.isJavaIdentifierPart(s.charAt(j)))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * From a list of top level trees, return the list of contained class definitions
+ */
+ List<JCClassDecl> listClasses(List<JCCompilationUnit> trees) {
+ ListBuffer<JCClassDecl> result = new ListBuffer<>();
+ for (JCCompilationUnit t : trees) {
+ for (JCTree def : t.defs) {
+ if (def.hasTag(JCTree.Tag.CLASSDEF))
+ result.append((JCClassDecl)def);
+ }
+ }
+ return result.toList();
+ }
+
+ /**
+ * A table to manage included and excluded packages.
+ */
+ class PackageTable {
+ private final Map<String, Entry> entries = new LinkedHashMap<>();
+ private final Set<String> includedPackages = new LinkedHashSet<>();
+ private final JavaFileManager fm;
+ private final Location location;
+ private final Set<JavaFileObject.Kind> sourceKinds = EnumSet.of(JavaFileObject.Kind.SOURCE);
+
+ /**
+ * Creates a table to manage included and excluded packages.
+ * @param fm The file manager used to locate source files
+ * @param locn the location used to locate source files
+ */
+ PackageTable(JavaFileManager fm, Location locn) {
+ this.fm = fm;
+ this.location = locn;
+ getEntry("").excluded = false;
+ }
+
+ PackageTable packages(Collection<String> packageNames) {
+ includedPackages.addAll(packageNames);
+ return this;
+ }
+
+ PackageTable subpackages(Collection<String> packageNames, Collection<String> excludePackageNames)
+ throws IOException {
+ for (String p: excludePackageNames) {
+ getEntry(p).excluded = true;
+ }
+
+ for (String packageName: packageNames) {
+ Location packageLocn = getLocation(packageName);
+ for (JavaFileObject fo: fm.list(packageLocn, packageName, sourceKinds, true)) {
+ String binaryName = fm.inferBinaryName(packageLocn, fo);
+ String pn = getPackageName(binaryName);
+ String simpleName = getSimpleName(binaryName);
+ Entry e = getEntry(pn);
+ if (!e.isExcluded() && isValidClassName(simpleName)) {
+ includedPackages.add(pn);
+ e.files = (e.files == null ? List.of(fo) : e.files.prepend(fo));
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Returns the aggregate set of included packages.
+ * @return the aggregate set of included packages
+ */
+ Set<String> getIncludedPackages() {
+ return includedPackages;
+ }
+
+ /**
+ * Returns the set of source files for a package.
+ * @param packageName the specified package
+ * @return the set of file objects for the specified package
+ * @throws IOException if an error occurs while accessing the files
+ */
+ List<JavaFileObject> getFiles(String packageName) throws IOException {
+ Entry e = getEntry(packageName);
+ // The files may have been found as a side effect of searching for subpackages
+ if (e.files != null)
+ return e.files;
+
+ ListBuffer<JavaFileObject> lb = new ListBuffer<>();
+ Location packageLocn = getLocation(packageName);
+ for (JavaFileObject fo: fm.list(packageLocn, packageName, sourceKinds, false)) {
+ String binaryName = fm.inferBinaryName(packageLocn, fo);
+ String simpleName = getSimpleName(binaryName);
+ if (isValidClassName(simpleName)) {
+ lb.append(fo);
+ }
+ }
+
+ return lb.toList();
+ }
+
+ private Location getLocation(String packageName) throws IOException {
+ if (location == StandardLocation.MODULE_SOURCE_PATH) {
+ // TODO: handle invalid results
+ ModuleSymbol msym = syms.inferModule(names.fromString(packageName));
+ return fm.getModuleLocation(location, msym.name.toString());
+ } else {
+ return location;
+ }
+ }
+
+ private Entry getEntry(String name) {
+ Entry e = entries.get(name);
+ if (e == null)
+ entries.put(name, e = new Entry(name));
+ return e;
+ }
+
+ private String getPackageName(String name) {
+ int lastDot = name.lastIndexOf(".");
+ return (lastDot == -1 ? "" : name.substring(0, lastDot));
+ }
+
+ private String getSimpleName(String name) {
+ int lastDot = name.lastIndexOf(".");
+ return (lastDot == -1 ? name : name.substring(lastDot + 1));
+ }
+
+ class Entry {
+ final String name;
+ Boolean excluded;
+ List<JavaFileObject> files;
+
+ Entry(String name) {
+ this.name = name;
+ }
+
+ boolean isExcluded() {
+ if (excluded == null)
+ excluded = getEntry(getPackageName(name)).isExcluded();
+ return excluded;
+ }
+ }
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/MemberDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Symbol;
+
+/**
+ * Represents a member of a java class: field, constructor, or method.
+ * This is an abstract class dealing with information common to
+ * method, constructor and field members. Class members of a class
+ * (nested classes) are represented instead by ClassDocImpl.
+ *
+ * <p><b>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.</b>
+ *
+ * @see MethodDocImpl
+ * @see FieldDocImpl
+ * @see ClassDocImpl
+ *
+ * @author Robert Field
+ * @author Neal Gafter
+ */
+
+public abstract class MemberDocImpl
+ extends ProgramElementDocImpl
+ implements MemberDoc {
+
+ /**
+ * constructor.
+ */
+ public MemberDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
+ super(env, sym, treePath);
+ }
+
+ /**
+ * Returns true if this field was synthesized by the compiler.
+ */
+ public abstract boolean isSynthetic();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Messager.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,323 @@
+/*
+ * 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.main;
+
+import java.io.PrintWriter;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.JCDiagnostic;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
+import com.sun.tools.javac.util.JavacMessages;
+import com.sun.tools.javac.util.Log;
+
+/**
+ * Utility for integrating with javadoc tools and for localization.
+ * Handle Resources. Access to error and warning counts.
+ * Message formatting.
+ * <br>
+ * Also provides implementation for DocErrorReporter.
+ *
+ * <p><b>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.</b>
+ *
+ * @see java.util.ResourceBundle
+ * @see java.text.MessageFormat
+ * @author Neal Gafter (rewrite)
+ */
+public class Messager extends Log implements DocErrorReporter {
+ public static final SourcePosition NOPOS = null;
+
+ /** Get the current messager, which is also the compiler log. */
+ public static Messager instance0(Context context) {
+ Log instance = context.get(logKey);
+ if (instance == null || !(instance instanceof Messager))
+ throw new InternalError("no messager instance!");
+ return (Messager)instance;
+ }
+
+ public static void preRegister(Context context,
+ final String programName) {
+ context.put(logKey, new Context.Factory<Log>() {
+ public Log make(Context c) {
+ return new Messager(c,
+ programName);
+ }
+ });
+ }
+ public static void preRegister(Context context,
+ final String programName,
+ final PrintWriter errWriter,
+ final PrintWriter warnWriter,
+ final PrintWriter noticeWriter) {
+ context.put(logKey, new Context.Factory<Log>() {
+ public Log make(Context c) {
+ return new Messager(c,
+ programName,
+ errWriter,
+ warnWriter,
+ noticeWriter);
+ }
+ });
+ }
+
+ public class ExitJavadoc extends Error {
+ private static final long serialVersionUID = 0;
+ }
+
+ final String programName;
+
+ private Locale locale;
+ private final JavacMessages messages;
+ private final JCDiagnostic.Factory javadocDiags;
+
+ /** The default writer for diagnostics
+ */
+ static final PrintWriter defaultErrWriter = new PrintWriter(System.err);
+ static final PrintWriter defaultWarnWriter = new PrintWriter(System.err);
+ static final PrintWriter defaultNoticeWriter = new PrintWriter(System.out);
+
+ /**
+ * Constructor
+ * @param programName Name of the program (for error messages).
+ */
+ protected Messager(Context context, String programName) {
+ this(context, programName, defaultErrWriter, defaultWarnWriter, defaultNoticeWriter);
+ }
+
+ /**
+ * Constructor
+ * @param programName Name of the program (for error messages).
+ * @param errWriter Stream for error messages
+ * @param warnWriter Stream for warnings
+ * @param noticeWriter Stream for other messages
+ */
+ @SuppressWarnings("deprecation")
+ protected Messager(Context context,
+ String programName,
+ PrintWriter errWriter,
+ PrintWriter warnWriter,
+ PrintWriter noticeWriter) {
+ super(context, errWriter, warnWriter, noticeWriter);
+ messages = JavacMessages.instance(context);
+ messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc",
+ locale));
+ javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
+ this.programName = programName;
+
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * get and format message string from resource
+ *
+ * @param key selects message from resource
+ * @param args arguments for the message
+ */
+ String getText(String key, Object... args) {
+ return messages.getLocalizedString(locale, key, args);
+ }
+
+ /**
+ * Print error message, increment error count.
+ * Part of DocErrorReporter.
+ *
+ * @param msg message to print
+ */
+ public void printError(String msg) {
+ printError(null, msg);
+ }
+
+ /**
+ * Print error message, increment error count.
+ * Part of DocErrorReporter.
+ *
+ * @param pos the position where the error occurs
+ * @param msg message to print
+ */
+ public void printError(SourcePosition pos, String msg) {
+ if (diagListener != null) {
+ report(DiagnosticType.ERROR, pos, msg);
+ return;
+ }
+
+ if (nerrors < MaxErrors) {
+ String prefix = (pos == null) ? programName : pos.toString();
+ errWriter.println(prefix + ": " + getText("javadoc.error") + " - " + msg);
+ errWriter.flush();
+ prompt();
+ nerrors++;
+ }
+ }
+
+ /**
+ * Print warning message, increment warning count.
+ * Part of DocErrorReporter.
+ *
+ * @param msg message to print
+ */
+ public void printWarning(String msg) {
+ printWarning(null, msg);
+ }
+
+ /**
+ * Print warning message, increment warning count.
+ * Part of DocErrorReporter.
+ *
+ * @param pos the position where the error occurs
+ * @param msg message to print
+ */
+ public void printWarning(SourcePosition pos, String msg) {
+ if (diagListener != null) {
+ report(DiagnosticType.WARNING, pos, msg);
+ return;
+ }
+
+ if (nwarnings < MaxWarnings) {
+ String prefix = (pos == null) ? programName : pos.toString();
+ warnWriter.println(prefix + ": " + getText("javadoc.warning") +" - " + msg);
+ warnWriter.flush();
+ nwarnings++;
+ }
+ }
+
+ /**
+ * Print a message.
+ * Part of DocErrorReporter.
+ *
+ * @param msg message to print
+ */
+ public void printNotice(String msg) {
+ printNotice(null, msg);
+ }
+
+ /**
+ * Print a message.
+ * Part of DocErrorReporter.
+ *
+ * @param pos the position where the error occurs
+ * @param msg message to print
+ */
+ public void printNotice(SourcePosition pos, String msg) {
+ if (diagListener != null) {
+ report(DiagnosticType.NOTE, pos, msg);
+ return;
+ }
+
+ if (pos == null)
+ noticeWriter.println(msg);
+ else
+ noticeWriter.println(pos + ": " + msg);
+ noticeWriter.flush();
+ }
+
+ /**
+ * Print error message, increment error count.
+ *
+ * @param key selects message from resource
+ */
+ public void error(SourcePosition pos, String key, Object... args) {
+ printError(pos, getText(key, args));
+ }
+
+ /**
+ * Print warning message, increment warning count.
+ *
+ * @param key selects message from resource
+ */
+ public void warning(SourcePosition pos, String key, Object... args) {
+ printWarning(pos, getText(key, args));
+ }
+
+ /**
+ * Print a message.
+ *
+ * @param key selects message from resource
+ */
+ public void notice(String key, Object... args) {
+ printNotice(getText(key, args));
+ }
+
+ /**
+ * Return total number of errors, including those recorded
+ * in the compilation log.
+ */
+ public int nerrors() { return nerrors; }
+
+ /**
+ * Return total number of warnings, including those recorded
+ * in the compilation log.
+ */
+ public int nwarnings() { return nwarnings; }
+
+ /**
+ * Print exit message.
+ */
+ public void exitNotice() {
+ if (nerrors > 0) {
+ notice((nerrors > 1) ? "main.errors" : "main.error",
+ "" + nerrors);
+ }
+ if (nwarnings > 0) {
+ notice((nwarnings > 1) ? "main.warnings" : "main.warning",
+ "" + nwarnings);
+ }
+ }
+
+ /**
+ * Force program exit, e.g., from a fatal error.
+ * <p>
+ * TODO: This method does not really belong here.
+ */
+ public void exit() {
+ throw new ExitJavadoc();
+ }
+
+ private void report(DiagnosticType type, SourcePosition pos, String msg) {
+ switch (type) {
+ case ERROR:
+ case WARNING:
+ Object prefix = (pos == null) ? programName : pos;
+ report(javadocDiags.create(type, null, null, "msg", prefix, msg));
+ break;
+
+ case NOTE:
+ String key = (pos == null) ? "msg" : "pos.msg";
+ report(javadocDiags.create(type, null, null, key, pos, msg));
+ break;
+
+ default:
+ throw new IllegalArgumentException(type.toString());
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/MethodDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import java.lang.reflect.Modifier;
+
+import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Type;
+import static com.sun.tools.javac.code.TypeTag.CLASS;
+
+/**
+ * Represents a method of a java class.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ */
+
+public class MethodDocImpl
+ extends ExecutableMemberDocImpl implements MethodDoc {
+
+ /**
+ * constructor.
+ */
+ public MethodDocImpl(DocEnv env, MethodSymbol sym) {
+ super(env, sym);
+ }
+
+ /**
+ * constructor.
+ */
+ public MethodDocImpl(DocEnv env, MethodSymbol sym, TreePath treePath) {
+ super(env, sym, treePath);
+ }
+
+ /**
+ * Return true if it is a method, which it is.
+ * Note: constructors are not methods.
+ * This method is overridden by AnnotationTypeElementDocImpl.
+ *
+ * @return true
+ */
+ public boolean isMethod() {
+ return true;
+ }
+
+ /**
+ * Return true if this method is default
+ */
+ public boolean isDefault() {
+ return (sym.flags() & Flags.DEFAULT) != 0;
+ }
+
+ /**
+ * Return true if this method is abstract
+ */
+ public boolean isAbstract() {
+ return (Modifier.isAbstract(getModifiers()) && !isDefault());
+ }
+
+ /**
+ * Get return type.
+ *
+ * @return the return type of this method, null if it
+ * is a constructor.
+ */
+ public com.sun.javadoc.Type returnType() {
+ return TypeMaker.getType(env, sym.type.getReturnType(), false);
+ }
+
+ /**
+ * Return the class that originally defined the method that
+ * is overridden by the current definition, or null if no
+ * such class exists.
+ *
+ * @return a ClassDocImpl representing the superclass that
+ * originally defined this method, null if this method does
+ * not override a definition in a superclass.
+ */
+ public ClassDoc overriddenClass() {
+ com.sun.javadoc.Type t = overriddenType();
+ return (t != null) ? t.asClassDoc() : null;
+ }
+
+ /**
+ * Return the type containing the method that this method overrides.
+ * It may be a <code>ClassDoc</code> or a <code>ParameterizedType</code>.
+ */
+ public com.sun.javadoc.Type overriddenType() {
+
+ if ((sym.flags() & Flags.STATIC) != 0) {
+ return null;
+ }
+
+ ClassSymbol origin = (ClassSymbol)sym.owner;
+ for (Type t = env.types.supertype(origin.type);
+ t.hasTag(CLASS);
+ t = env.types.supertype(t)) {
+ ClassSymbol c = (ClassSymbol)t.tsym;
+ for (Symbol sym2 : membersOf(c).getSymbolsByName(sym.name)) {
+ if (sym.overrides(sym2, origin, env.types, true)) {
+ return TypeMaker.getType(env, t);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the method that this method overrides.
+ *
+ * @return a MethodDoc representing a method definition
+ * in a superclass this method overrides, null if
+ * this method does not override.
+ */
+ public MethodDoc overriddenMethod() {
+
+ // Real overriding only. Static members are simply hidden.
+ // Likewise for constructors, but the MethodSymbol.overrides
+ // method takes this into account.
+ if ((sym.flags() & Flags.STATIC) != 0) {
+ return null;
+ }
+
+ // Derived from com.sun.tools.javac.comp.Check.checkOverride .
+
+ ClassSymbol origin = (ClassSymbol)sym.owner;
+ for (Type t = env.types.supertype(origin.type);
+ t.hasTag(CLASS);
+ t = env.types.supertype(t)) {
+ ClassSymbol c = (ClassSymbol)t.tsym;
+ for (Symbol sym2 : membersOf(c).getSymbolsByName(sym.name)) {
+ if (sym.overrides(sym2, origin, env.types, true)) {
+ return env.getMethodDoc((MethodSymbol)sym2);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**Retrieve members of c, ignoring any CompletionFailures that occur. */
+ private Scope membersOf(ClassSymbol c) {
+ try {
+ return c.members();
+ } catch (CompletionFailure cf) {
+ /* 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 membersOf(c);
+ }
+ }
+
+ /**
+ * Tests whether this method overrides another.
+ * The overridden method may be one declared in a superclass or
+ * a superinterface (unlike {@link #overriddenMethod()}).
+ *
+ * <p> When a non-abstract method overrides an abstract one, it is
+ * also said to <i>implement</i> the other.
+ *
+ * @param meth the other method to examine
+ * @return <tt>true</tt> if this method overrides the other
+ */
+ public boolean overrides(MethodDoc meth) {
+ MethodSymbol overridee = ((MethodDocImpl) meth).sym;
+ ClassSymbol origin = (ClassSymbol) sym.owner;
+
+ return sym.name == overridee.name &&
+
+ // not reflexive as per JLS
+ sym != overridee &&
+
+ // we don't care if overridee is static, though that wouldn't
+ // compile
+ !sym.isStatic() &&
+
+ // sym, whose declaring type is the origin, must be
+ // in a subtype of overridee's type
+ env.types.asSuper(origin.type, overridee.owner) != null &&
+
+ // check access and signatures; don't check return types
+ sym.overrides(overridee, origin, env.types, false);
+ }
+
+
+ public String name() {
+ if (name == null) {
+ name = sym.name.toString();
+ }
+ return name;
+ }
+
+ private String name;
+
+ public String qualifiedName() {
+ if (qualifiedName == null) {
+ qualifiedName = sym.enclClass().getQualifiedName() + "." + sym.name;
+ }
+ return qualifiedName;
+ }
+
+ private String qualifiedName;
+
+ /**
+ * Returns a string representation of this method. Includes the
+ * qualified signature, the qualified method name, and any type
+ * parameters. Type parameters follow the class name, as they do
+ * in the syntax for invoking methods with explicit type parameters.
+ */
+ public String toString() {
+ return sym.enclClass().getQualifiedName() +
+ "." + typeParametersString() + name() + signature();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ModifierFilter.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,125 @@
+/*
+ * 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.main;
+
+import static com.sun.tools.javac.code.Flags.*;
+
+/**
+ * A class whose instances are filters over Modifier bits.
+ * Filtering is done by returning boolean values.
+ * Classes, methods and fields can be filtered, or filtering
+ * can be done directly on modifier bits.
+ *
+ * <p><b>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.</b>
+ *
+ * @see com.sun.tools.javac.code.Flags
+ * @author Robert Field
+ */
+
+public class ModifierFilter {
+
+ /**
+ * Package private access.
+ * A "pseudo-" modifier bit that can be used in the
+ * constructors of this class to specify package private
+ * access. This is needed since there is no Modifier.PACKAGE.
+ */
+ public static final long PACKAGE = 0x8000000000000000L;
+
+ /**
+ * All access modifiers.
+ * A short-hand set of modifier bits that can be used in the
+ * constructors of this class to specify all access modifiers,
+ * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE.
+ */
+ public static final long ALL_ACCESS =
+ PRIVATE | PROTECTED | PUBLIC | PACKAGE;
+
+ private long oneOf;
+ private long must;
+ private long cannot;
+
+ private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC;
+
+ /**
+ * Constructor - Specify a filter.
+ *
+ * @param oneOf If zero, everything passes the filter.
+ * If non-zero, at least one of the specified
+ * bits must be on in the modifier bits to
+ * pass the filter.
+ */
+ public ModifierFilter(long oneOf) {
+ this(oneOf, 0, 0);
+ }
+
+ /**
+ * Constructor - Specify a filter.
+ * For example, the filter below will only pass synchronized
+ * methods that are private or package private access and are
+ * not native or static.
+ * <pre>
+ * ModifierFilter( Modifier.PRIVATE | ModifierFilter.PACKAGE,
+ * Modifier.SYNCHRONIZED,
+ * Modifier.NATIVE | Modifier.STATIC)
+ * </pre><p>
+ * Each of the three arguments must either be
+ * zero or the or'ed combination of the bits specified in the
+ * class Modifier or this class. During filtering, these values
+ * are compared against the modifier bits as follows:
+ *
+ * @param oneOf If zero, ignore this argument.
+ * If non-zero, at least one of the bits must be on.
+ * @param must All bits specified must be on.
+ * @param cannot None of the bits specified can be on.
+ */
+ public ModifierFilter(long oneOf, long must, long cannot) {
+ this.oneOf = oneOf;
+ this.must = must;
+ this.cannot = cannot;
+ }
+
+ /**
+ * Filter on modifier bits.
+ *
+ * @param modifierBits Bits as specified in the Modifier class
+ *
+ * @return Whether the modifierBits pass this filter.
+ */
+ public boolean checkModifier(int modifierBits) {
+ // Add in the "pseudo-" modifier bit PACKAGE, if needed
+ long fmod = ((modifierBits & ACCESS_BITS) == 0) ?
+ modifierBits | PACKAGE :
+ modifierBits;
+ return ((oneOf == 0) || ((oneOf & fmod) != 0)) &&
+ ((must & fmod) == must) &&
+ ((cannot & fmod) == 0);
+ }
+
+} // end ModifierFilter
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/PackageDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,389 @@
+/*
+ * 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.main;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.tools.FileObject;
+
+import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Attribute;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.PackageSymbol;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+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.Position;
+
+import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
+
+/**
+ * Represents a java package. Provides access to information
+ * about the package, the package's comment and tags, and the
+ * classes in the package.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Kaiyang Liu (original)
+ * @author Robert Field (rewrite)
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (package-info.java)
+ */
+
+public class PackageDocImpl extends DocImpl implements PackageDoc {
+
+ public final PackageSymbol sym;
+ private JCCompilationUnit tree = null; // for source position
+
+ public FileObject docPath = null;
+ private boolean foundDoc; // found a doc comment in either
+ // package.html or package-info.java
+
+ boolean isIncluded = false; // Set in RootDocImpl.
+ public boolean setDocPath = false; //Flag to avoid setting doc path multiple times.
+
+ /**
+ * Constructor
+ */
+ public PackageDocImpl(DocEnv env, PackageSymbol sym) {
+ this(env, sym, null);
+ }
+
+ /**
+ * Constructor
+ */
+ public PackageDocImpl(DocEnv env, PackageSymbol sym, TreePath treePath) {
+ super(env, treePath);
+ this.sym = sym;
+ this.tree = (treePath == null) ? null : (JCCompilationUnit) treePath.getCompilationUnit();
+ foundDoc = (documentation != null);
+ }
+
+ void setTree(JCTree tree) {
+ this.tree = (JCCompilationUnit) tree;
+ }
+
+ public void setTreePath(TreePath treePath) {
+ super.setTreePath(treePath);
+ checkDoc();
+ }
+
+ /**
+ * Do lazy initialization of "documentation" string.
+ */
+ protected String documentation() {
+ if (documentation != null)
+ return documentation;
+ if (docPath != null) {
+ // read from file
+ try {
+ InputStream s = docPath.openInputStream();
+ documentation = readHTMLDocumentation(s, docPath);
+ } catch (IOException exc) {
+ documentation = "";
+ env.error(null, "javadoc.File_Read_Error", docPath.getName());
+ }
+ } else {
+ // no doc file to be had
+ documentation = "";
+ }
+ return documentation;
+ }
+
+ /**
+ * Cache of all classes contained in this package, including
+ * member classes of those classes, and their member classes, etc.
+ * Includes only those classes at the specified protection level
+ * and weaker.
+ */
+ private List<ClassDocImpl> allClassesFiltered = null;
+
+ /**
+ * Cache of all classes contained in this package, including
+ * member classes of those classes, and their member classes, etc.
+ */
+ private List<ClassDocImpl> allClasses = null;
+
+ /**
+ * Return a list of all classes contained in this package, including
+ * member classes of those classes, and their member classes, etc.
+ */
+ private List<ClassDocImpl> getClasses(boolean filtered) {
+ if (allClasses != null && !filtered) {
+ return allClasses;
+ }
+ if (allClassesFiltered != null && filtered) {
+ return allClassesFiltered;
+ }
+ ListBuffer<ClassDocImpl> classes = new ListBuffer<>();
+ for (Symbol enumerated : sym.members().getSymbols(NON_RECURSIVE)) {
+ if (enumerated != null) {
+ ClassSymbol s = (ClassSymbol)enumerated;
+ ClassDocImpl c = env.getClassDoc(s);
+ if (c != null && !c.isSynthetic())
+ c.addAllClasses(classes, filtered);
+ }
+ }
+ if (filtered)
+ return allClassesFiltered = classes.toList();
+ else
+ return allClasses = classes.toList();
+ }
+
+ /**
+ * Add all included classes (including Exceptions and Errors)
+ * and interfaces.
+ */
+ public void addAllClassesTo(ListBuffer<ClassDocImpl> list) {
+ list.appendList(getClasses(true));
+ }
+
+ /**
+ * Get all classes (including Exceptions and Errors)
+ * and interfaces.
+ * @since J2SE1.4.
+ *
+ * @return all classes and interfaces in this package, filtered to include
+ * only the included classes if filter==true.
+ */
+ public ClassDoc[] allClasses(boolean filter) {
+ List<ClassDocImpl> classes = getClasses(filter);
+ return classes.toArray(new ClassDocImpl[classes.length()]);
+ }
+
+ /**
+ * Get all included classes (including Exceptions and Errors)
+ * and interfaces. Same as allClasses(true).
+ *
+ * @return all included classes and interfaces in this package.
+ */
+ public ClassDoc[] allClasses() {
+ return allClasses(true);
+ }
+
+ /**
+ * Get ordinary classes (that is, exclude exceptions, errors,
+ * enums, interfaces, and annotation types) in this package.
+ *
+ * @return included ordinary classes in this package.
+ */
+ public ClassDoc[] ordinaryClasses() {
+ ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isOrdinaryClass()) {
+ ret.append(c);
+ }
+ }
+ return ret.toArray(new ClassDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get Exception classes in this package.
+ *
+ * @return included Exceptions in this package.
+ */
+ public ClassDoc[] exceptions() {
+ ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isException()) {
+ ret.append(c);
+ }
+ }
+ return ret.toArray(new ClassDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get Error classes in this package.
+ *
+ * @return included Errors in this package.
+ */
+ public ClassDoc[] errors() {
+ ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isError()) {
+ ret.append(c);
+ }
+ }
+ return ret.toArray(new ClassDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get included enum types in this package.
+ *
+ * @return included enum types in this package.
+ */
+ public ClassDoc[] enums() {
+ ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isEnum()) {
+ ret.append(c);
+ }
+ }
+ return ret.toArray(new ClassDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get included interfaces in this package, omitting annotation types.
+ *
+ * @return included interfaces in this package.
+ */
+ public ClassDoc[] interfaces() {
+ ListBuffer<ClassDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isInterface()) {
+ ret.append(c);
+ }
+ }
+ return ret.toArray(new ClassDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get included annotation types in this package.
+ *
+ * @return included annotation types in this package.
+ */
+ public AnnotationTypeDoc[] annotationTypes() {
+ ListBuffer<AnnotationTypeDocImpl> ret = new ListBuffer<>();
+ for (ClassDocImpl c : getClasses(true)) {
+ if (c.isAnnotationType()) {
+ ret.append((AnnotationTypeDocImpl)c);
+ }
+ }
+ return ret.toArray(new AnnotationTypeDocImpl[ret.length()]);
+ }
+
+ /**
+ * Get the annotations of this package.
+ * Return an empty array if there are none.
+ */
+ public AnnotationDesc[] annotations() {
+ AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
+ int i = 0;
+ for (Attribute.Compound a : sym.getRawAttributes()) {
+ res[i++] = new AnnotationDescImpl(env, a);
+ }
+ return res;
+ }
+
+
+ /**
+ * Lookup for a class within this package.
+ *
+ * @return ClassDocImpl of found class, or null if not found.
+ */
+ public ClassDoc findClass(String className) {
+ final boolean filtered = true;
+ for (ClassDocImpl c : getClasses(filtered)) {
+ if (c.name().equals(className)) {
+ return c;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return true if this package is included in the active set.
+ */
+ public boolean isIncluded() {
+ return isIncluded;
+ }
+
+ /**
+ * Get package name.
+ *
+ * Note that we do not provide a means of obtaining the simple
+ * name of a package -- package names are always returned in their
+ * uniquely qualified form.
+ */
+ public String name() {
+ return qualifiedName();
+ }
+
+ /**
+ * Get package name.
+ */
+ public String qualifiedName() {
+ if (qualifiedName == null) {
+ Name fullname = sym.getQualifiedName();
+ // Some bogus tests depend on the interned "" being returned.
+ // See 6457276.
+ qualifiedName = fullname.isEmpty() ? "" : fullname.toString();
+ }
+ return qualifiedName;
+ }
+
+ private String qualifiedName;
+
+ /**
+ * set doc path for an unzipped directory
+ */
+ public void setDocPath(FileObject path) {
+ setDocPath = true;
+ if (path == null)
+ return;
+ if (!path.equals(docPath)) {
+ docPath = path;
+ checkDoc();
+ }
+ }
+
+ // Has checkDoc() sounded off yet?
+ private boolean checkDocWarningEmitted = false;
+
+ /**
+ * Invoked when a source of package doc comments is located.
+ * Emits a diagnostic if this is the second one.
+ */
+ private void checkDoc() {
+ if (foundDoc) {
+ if (!checkDocWarningEmitted) {
+ env.warning(null, "javadoc.Multiple_package_comments", name());
+ checkDocWarningEmitted = true;
+ }
+ } else {
+ foundDoc = true;
+ }
+ }
+
+ /**
+ * Return the source position of the entity, or null if
+ * no position is available.
+ */
+ public SourcePosition position() {
+ return (tree != null)
+ ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
+ : SourcePositionImpl.make(docPath, Position.NOPOS, null);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ParamTagImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import java.util.regex.*;
+
+import com.sun.javadoc.*;
+
+/**
+ * Represents an @param documentation tag.
+ * Parses and stores the name and comment parts of the parameter tag.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Robert Field
+ *
+ */
+class ParamTagImpl extends TagImpl implements ParamTag {
+
+ private static final Pattern typeParamRE = Pattern.compile("<([^<>]+)>");
+
+ private final String parameterName;
+ private final String parameterComment;
+ private final boolean isTypeParameter;
+
+ /**
+ * Cached inline tags.
+ */
+ private Tag[] inlineTags;
+
+ ParamTagImpl(DocImpl holder, String name, String text) {
+ super(holder, name, text);
+ String[] sa = divideAtWhite();
+
+ Matcher m = typeParamRE.matcher(sa[0]);
+ isTypeParameter = m.matches();
+ parameterName = isTypeParameter ? m.group(1) : sa[0];
+ parameterComment = sa[1];
+ }
+
+ /**
+ * Return the parameter name.
+ */
+ public String parameterName() {
+ return parameterName;
+ }
+
+ /**
+ * Return the parameter comment.
+ */
+ public String parameterComment() {
+ return parameterComment;
+ }
+
+ /**
+ * Return the kind of this tag.
+ */
+ @Override
+ public String kind() {
+ return "@param";
+ }
+
+ /**
+ * Return true if this ParamTag corresponds to a type parameter.
+ */
+ public boolean isTypeParameter() {
+ return isTypeParameter;
+ }
+
+ /**
+ * convert this object to a string.
+ */
+ @Override
+ public String toString() {
+ return name + ":" + text;
+ }
+
+ /**
+ * For the parameter comment with embedded @link tags return the array of
+ * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
+ *
+ * @return TagImpl[] Array of tags with inline SeeTagImpls.
+ * @see TagImpl#inlineTags()
+ * @see ThrowsTagImpl#inlineTags()
+ */
+ @Override
+ public Tag[] inlineTags() {
+ if (inlineTags == null) {
+ inlineTags = Comment.getInlineTags(holder, parameterComment);
+ }
+ return inlineTags;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ParameterImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Attribute;
+import com.sun.tools.javac.code.Symbol.VarSymbol;
+
+/**
+ * ParameterImpl information.
+ * This includes a parameter type and parameter name.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Kaiyang Liu (original)
+ * @author Robert Field (rewrite)
+ * @author Scott Seligman (generics, annotations)
+ */
+class ParameterImpl implements Parameter {
+
+ private final DocEnv env;
+ private final VarSymbol sym;
+ private final com.sun.javadoc.Type type;
+
+ /**
+ * Constructor of parameter info class.
+ */
+ ParameterImpl(DocEnv env, VarSymbol sym) {
+ this.env = env;
+ this.sym = sym;
+ this.type = TypeMaker.getType(env, sym.type, false);
+ }
+
+ /**
+ * Get the type of this parameter.
+ */
+ public com.sun.javadoc.Type type() {
+ return type;
+ }
+
+ /**
+ * Get local name of this parameter.
+ * For example if parameter is the short 'index', returns "index".
+ */
+ public String name() {
+ return sym.toString();
+ }
+
+ /**
+ * Get type name of this parameter.
+ * For example if parameter is the short 'index', returns "short".
+ */
+ public String typeName() {
+ return (type instanceof ClassDoc || type instanceof TypeVariable)
+ ? type.typeName() // omit formal type params or bounds
+ : type.toString();
+ }
+
+ /**
+ * Returns a string representation of the parameter.
+ * <p>
+ * For example if parameter is the short 'index', returns "short index".
+ *
+ * @return type name and parameter name of this parameter.
+ */
+ public String toString() {
+ return typeName() + " " + sym;
+ }
+
+ /**
+ * Get the annotations of this parameter.
+ * Return an empty array if there are none.
+ */
+ public AnnotationDesc[] annotations() {
+ AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
+ int i = 0;
+ for (Attribute.Compound a : sym.getRawAttributes()) {
+ res[i++] = new AnnotationDescImpl(env, a);
+ }
+ return res;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ParameterizedTypeImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2003, 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.ClassType;
+
+import static com.sun.tools.javac.code.TypeTag.CLASS;
+
+
+/**
+ * Implementation of <code>ParameterizedType</code>, which
+ * represents an invocation of a generic class or interface.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Scott Seligman
+ * @since 1.5
+ */
+public class ParameterizedTypeImpl
+ extends AbstractTypeImpl implements ParameterizedType {
+
+ ParameterizedTypeImpl(DocEnv env, Type type) {
+ super(env, type);
+ }
+
+ /**
+ * Return the generic class or interface that declared this type.
+ */
+ @Override
+ public ClassDoc asClassDoc() {
+ return env.getClassDoc((ClassSymbol)type.tsym);
+ }
+
+ /**
+ * Return the actual type arguments of this type.
+ */
+ public com.sun.javadoc.Type[] typeArguments() {
+ return TypeMaker.getTypes(env, type.getTypeArguments());
+ }
+
+ /**
+ * Return the class type that is a direct supertype of this one.
+ * Return null if this is an interface type.
+ */
+ public com.sun.javadoc.Type superclassType() {
+ if (asClassDoc().isInterface()) {
+ return null;
+ }
+ Type sup = env.types.supertype(type);
+ return TypeMaker.getType(env,
+ (sup != type) ? sup : env.syms.objectType);
+ }
+
+ /**
+ * Return the interface types directly implemented by or extended by this
+ * parameterized type.
+ * Return an empty array if there are no interfaces.
+ */
+ public com.sun.javadoc.Type[] interfaceTypes() {
+ return TypeMaker.getTypes(env, env.types.interfaces(type));
+ }
+
+ /**
+ * Return the type that contains this type as a member.
+ * Return null is this is a top-level type.
+ */
+ public com.sun.javadoc.Type containingType() {
+ if (type.getEnclosingType().hasTag(CLASS)) {
+ // This is the type of an inner class.
+ return TypeMaker.getType(env, type.getEnclosingType());
+ }
+ ClassSymbol enclosing = type.tsym.owner.enclClass();
+ if (enclosing != null) {
+ // Nested but not inner. Return the ClassDoc of the enclosing
+ // class or interface.
+ // See java.lang.reflect.ParameterizedType.getOwnerType().
+ return env.getClassDoc(enclosing);
+ }
+ return null;
+ }
+
+
+ // Asking for the "name" of a parameterized type doesn't exactly make
+ // sense. It's a type expression. Return the name of its generic
+ // type.
+ @Override
+ public String typeName() {
+ return TypeMaker.getTypeName(type, false);
+ }
+
+ @Override
+ public ParameterizedType asParameterizedType() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return parameterizedTypeToString(env, (ClassType)type, true);
+ }
+
+ static String parameterizedTypeToString(DocEnv env, ClassType cl,
+ boolean full) {
+ if (env.legacyDoclet) {
+ return TypeMaker.getTypeName(cl, full);
+ }
+ StringBuilder s = new StringBuilder();
+ if (!(cl.getEnclosingType().hasTag(CLASS))) { // if not an inner class...
+ s.append(TypeMaker.getTypeName(cl, full));
+ } else {
+ ClassType encl = (ClassType)cl.getEnclosingType();
+ s.append(parameterizedTypeToString(env, encl, full))
+ .append('.')
+ .append(cl.tsym.name.toString());
+ }
+ s.append(TypeMaker.typeArgumentsString(env, cl, full));
+ return s.toString();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/PrimitiveType.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2001, 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.main;
+
+import com.sun.javadoc.*;
+
+/**
+ * <p><b>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.</b>
+ */
+class PrimitiveType implements com.sun.javadoc.Type {
+
+ private final String name;
+
+ static final PrimitiveType voidType = new PrimitiveType("void");
+ static final PrimitiveType booleanType = new PrimitiveType("boolean");
+ static final PrimitiveType byteType = new PrimitiveType("byte");
+ static final PrimitiveType charType = new PrimitiveType("char");
+ static final PrimitiveType shortType = new PrimitiveType("short");
+ static final PrimitiveType intType = new PrimitiveType("int");
+ static final PrimitiveType longType = new PrimitiveType("long");
+ static final PrimitiveType floatType = new PrimitiveType("float");
+ static final PrimitiveType doubleType = new PrimitiveType("double");
+
+ // error type, should never actually be used
+ static final PrimitiveType errorType = new PrimitiveType("");
+
+ PrimitiveType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Return unqualified name of type excluding any dimension information.
+ * <p>
+ * For example, a two dimensional array of String returns 'String'.
+ */
+ public String typeName() {
+ return name;
+ }
+
+ public com.sun.javadoc.Type getElementType() {
+ return null;
+ }
+
+ /**
+ * Return qualified name of type excluding any dimension information.
+ *<p>
+ * For example, a two dimensional array of String
+ * returns 'java.lang.String'.
+ */
+ public String qualifiedTypeName() {
+ return name;
+ }
+
+ /**
+ * Return the simple name of this type.
+ */
+ public String simpleTypeName() {
+ return name;
+ }
+
+ /**
+ * Return the type's dimension information, as a string.
+ * <p>
+ * For example, a two dimensional array of String returns '[][]'.
+ */
+ public String dimension() {
+ return "";
+ }
+
+ /**
+ * Return this type as a class. Array dimensions are ignored.
+ *
+ * @return a ClassDocImpl if the type is a Class.
+ * Return null if it is a primitive type..
+ */
+ public ClassDoc asClassDoc() {
+ return null;
+ }
+
+ /**
+ * Return null, as this is not an annotation type.
+ */
+ public AnnotationTypeDoc asAnnotationTypeDoc() {
+ return null;
+ }
+
+ /**
+ * Return null, as this is not an 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;
+ }
+
+ /**
+ * Return null, as this is not an annotated type.
+ */
+ public AnnotatedType asAnnotatedType() {
+ return null;
+ }
+
+ /**
+ * Returns a string representation of the type.
+ *
+ * Return name of type including any dimension information.
+ * <p>
+ * For example, a two dimensional array of String returns
+ * <code>String[][]</code>.
+ *
+ * @return name of type including any dimension information.
+ */
+ public String toString() {
+ return qualifiedTypeName();
+ }
+
+ /**
+ * Return true if this is a primitive type.
+ */
+ public boolean isPrimitive() {
+ return true;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ProgramElementDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import java.lang.reflect.Modifier;
+import java.text.CollationKey;
+
+import com.sun.javadoc.*;
+import com.sun.source.util.TreePath;
+import com.sun.tools.javac.code.Attribute;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.util.Position;
+
+/**
+ * Represents a java program element: class, interface, field,
+ * constructor, or method.
+ * This is an abstract class dealing with information common to
+ * these elements.
+ *
+ * <p><b>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.</b>
+ *
+ * @see MemberDocImpl
+ * @see ClassDocImpl
+ *
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ * @author Scott Seligman (generics, enums, annotations)
+ */
+public abstract class ProgramElementDocImpl
+ extends DocImpl implements ProgramElementDoc {
+
+ private final Symbol sym;
+
+ // For source position information.
+ JCTree tree = null;
+ Position.LineMap lineMap = null;
+
+
+ // Cache for getModifiers().
+ private int modifiers = -1;
+
+ protected ProgramElementDocImpl(DocEnv env, Symbol sym, TreePath treePath) {
+ super(env, treePath);
+ this.sym = sym;
+ if (treePath != null) {
+ tree = (JCTree) treePath.getLeaf();
+ lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
+ }
+ }
+
+ @Override
+ void setTreePath(TreePath treePath) {
+ super.setTreePath(treePath);
+ this.tree = (JCTree) treePath.getLeaf();
+ this.lineMap = ((JCCompilationUnit) treePath.getCompilationUnit()).lineMap;
+ }
+
+ /**
+ * Subclasses override to identify the containing class
+ */
+ protected abstract ClassSymbol getContainingClass();
+
+ /**
+ * Returns the flags in terms of javac's flags
+ */
+ abstract protected long getFlags();
+
+ /**
+ * Returns the modifier flags in terms of java.lang.reflect.Modifier.
+ */
+ protected int getModifiers() {
+ if (modifiers == -1) {
+ modifiers = DocEnv.translateModifiers(getFlags());
+ }
+ return modifiers;
+ }
+
+ /**
+ * Get the containing class of this program element.
+ *
+ * @return a ClassDocImpl for this element's containing class.
+ * If this is a class with no outer class, return null.
+ */
+ public ClassDoc containingClass() {
+ if (getContainingClass() == null) {
+ return null;
+ }
+ return env.getClassDoc(getContainingClass());
+ }
+
+ /**
+ * Return the package that this member is contained in.
+ * Return "" if in unnamed package.
+ */
+ public PackageDoc containingPackage() {
+ return env.getPackageDoc(getContainingClass().packge());
+ }
+
+ /**
+ * Get the modifier specifier integer.
+ *
+ * @see java.lang.reflect.Modifier
+ */
+ public int modifierSpecifier() {
+ int modifiers = getModifiers();
+ if (isMethod() && containingClass().isInterface())
+ // Remove the implicit abstract modifier.
+ return modifiers & ~Modifier.ABSTRACT;
+ return modifiers;
+ }
+
+ /**
+ * Get modifiers string.
+ * <pre>
+ * Example, for:
+ * public abstract int foo() { ... }
+ * modifiers() would return:
+ * 'public abstract'
+ * </pre>
+ * Annotations are not included.
+ */
+ public String modifiers() {
+ int modifiers = getModifiers();
+ if (isAnnotationTypeElement() ||
+ (isMethod() && containingClass().isInterface())) {
+ // Remove the implicit abstract modifier.
+ return Modifier.toString(modifiers & ~Modifier.ABSTRACT);
+ } else {
+ return Modifier.toString(modifiers);
+ }
+ }
+
+ /**
+ * Get the annotations of this program element.
+ * Return an empty array if there are none.
+ */
+ public AnnotationDesc[] annotations() {
+ AnnotationDesc res[] = new AnnotationDesc[sym.getRawAttributes().length()];
+ int i = 0;
+ for (Attribute.Compound a : sym.getRawAttributes()) {
+ res[i++] = new AnnotationDescImpl(env, a);
+ }
+ return res;
+ }
+
+ /**
+ * Return true if this program element is public
+ */
+ public boolean isPublic() {
+ int modifiers = getModifiers();
+ return Modifier.isPublic(modifiers);
+ }
+
+ /**
+ * Return true if this program element is protected
+ */
+ public boolean isProtected() {
+ int modifiers = getModifiers();
+ return Modifier.isProtected(modifiers);
+ }
+
+ /**
+ * Return true if this program element is private
+ */
+ public boolean isPrivate() {
+ int modifiers = getModifiers();
+ return Modifier.isPrivate(modifiers);
+ }
+
+ /**
+ * Return true if this program element is package private
+ */
+ public boolean isPackagePrivate() {
+ return !(isPublic() || isPrivate() || isProtected());
+ }
+
+ /**
+ * Return true if this program element is static
+ */
+ public boolean isStatic() {
+ int modifiers = getModifiers();
+ return Modifier.isStatic(modifiers);
+ }
+
+ /**
+ * Return true if this program element is final
+ */
+ public boolean isFinal() {
+ int modifiers = getModifiers();
+ return Modifier.isFinal(modifiers);
+ }
+
+ /**
+ * Generate a key for sorting.
+ */
+ CollationKey generateKey() {
+ String k = name();
+ // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\"");
+ return env.doclocale.collator.getCollationKey(k);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/RootDocImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,394 @@
+/*
+ * 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.main;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Locale;
+
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.tree.JCTree.JCClassDecl;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Position;
+
+/**
+ * This class holds the information from one run of javadoc.
+ * Particularly the packages, classes and options specified
+ * by the user.
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Atul M Dambalkar
+ * @author Neal Gafter (rewrite)
+ */
+public class RootDocImpl extends DocImpl implements RootDoc {
+
+ /**
+ * list of classes specified on the command line.
+ */
+ private List<ClassDocImpl> cmdLineClasses;
+
+ /**
+ * list of packages specified on the command line.
+ */
+ private List<PackageDocImpl> cmdLinePackages;
+
+ /**
+ * a collection of all options.
+ */
+ private List<String[]> options;
+
+ /**
+ * Constructor used when reading source files.
+ *
+ * @param env the documentation environment, state for this javadoc run
+ * @param classes list of classes specified on the commandline
+ * @param packages list of package names specified on the commandline
+ * @param options list of options
+ */
+ public RootDocImpl(DocEnv env, List<JCClassDecl> classes, List<String> packages, List<String[]> options) {
+ super(env, null);
+ this.options = options;
+ setPackages(env, packages);
+ setClasses(env, classes);
+ }
+
+ /**
+ * Constructor used when reading class files.
+ *
+ * @param env the documentation environment, state for this javadoc run
+ * @param classes list of class names specified on the commandline
+ * @param options list of options
+ */
+ public RootDocImpl(DocEnv env, List<String> classes, List<String[]> options) {
+ super(env, null);
+ this.options = options;
+ cmdLinePackages = List.nil();
+ ListBuffer<ClassDocImpl> classList = new ListBuffer<>();
+ for (String className : classes) {
+ ClassDocImpl c = env.loadClass(className);
+ if (c == null)
+ env.error(null, "javadoc.class_not_found", className);
+ else
+ classList = classList.append(c);
+ }
+ cmdLineClasses = classList.toList();
+ }
+
+ /**
+ * Initialize classes information. Those classes are input from
+ * command line.
+ *
+ * @param env the compilation environment
+ * @param classes a list of ClassDeclaration
+ */
+ private void setClasses(DocEnv env, List<JCClassDecl> classes) {
+ ListBuffer<ClassDocImpl> result = new ListBuffer<>();
+ for (JCClassDecl def : classes) {
+ //### Do we want modifier check here?
+ if (env.shouldDocument(def.sym)) {
+ ClassDocImpl cd = env.getClassDoc(def.sym);
+ if (cd != null) {
+ cd.isIncluded = true;
+ result.append(cd);
+ } //else System.out.println(" (classdoc is null)");//DEBUG
+ } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
+ }
+ cmdLineClasses = result.toList();
+ }
+
+ /**
+ * Initialize packages information.
+ *
+ * @param env the compilation environment
+ * @param packages a list of package names (String)
+ */
+ private void setPackages(DocEnv env, List<String> packages) {
+ ListBuffer<PackageDocImpl> packlist = new ListBuffer<>();
+ for (String name : packages) {
+ PackageDocImpl pkg = env.lookupPackage(name);
+ if (pkg != null) {
+ pkg.isIncluded = true;
+ packlist.append(pkg);
+ } else {
+ env.warning(null, "main.no_source_files_for_package", name);
+ }
+ }
+ cmdLinePackages = packlist.toList();
+ }
+
+ /**
+ * Command line options.
+ *
+ * <pre>
+ * For example, given:
+ * javadoc -foo this that -bar other ...
+ *
+ * This method will return:
+ * options()[0][0] = "-foo"
+ * options()[0][1] = "this"
+ * options()[0][2] = "that"
+ * options()[1][0] = "-bar"
+ * options()[1][1] = "other"
+ * </pre>
+ *
+ * @return an array of arrays of String.
+ */
+ public String[][] options() {
+ return options.toArray(new String[options.length()][]);
+ }
+
+ /**
+ * Packages specified on the command line.
+ */
+ public PackageDoc[] specifiedPackages() {
+ return (PackageDoc[])cmdLinePackages
+ .toArray(new PackageDocImpl[cmdLinePackages.length()]);
+ }
+
+ /**
+ * Classes and interfaces specified on the command line.
+ */
+ public ClassDoc[] specifiedClasses() {
+ ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>();
+ for (ClassDocImpl cd : cmdLineClasses) {
+ cd.addAllClasses(classesToDocument, true);
+ }
+ return (ClassDoc[])classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
+ }
+
+ /**
+ * Return all classes and interfaces (including those inside
+ * packages) to be documented.
+ */
+ public ClassDoc[] classes() {
+ ListBuffer<ClassDocImpl> classesToDocument = new ListBuffer<>();
+ for (ClassDocImpl cd : cmdLineClasses) {
+ cd.addAllClasses(classesToDocument, true);
+ }
+ for (PackageDocImpl pd : cmdLinePackages) {
+ pd.addAllClassesTo(classesToDocument);
+ }
+ return classesToDocument.toArray(new ClassDocImpl[classesToDocument.length()]);
+ }
+
+ /**
+ * Return a ClassDoc for the specified class/interface name
+ *
+ * @param qualifiedName qualified class name
+ * (i.e. includes package name).
+ *
+ * @return a ClassDocImpl holding the specified class, null if
+ * this class is not referenced.
+ */
+ public ClassDoc classNamed(String qualifiedName) {
+ return env.lookupClass(qualifiedName);
+ }
+
+ /**
+ * Return a PackageDoc for the specified package name
+ *
+ * @param name package name
+ *
+ * @return a PackageDoc holding the specified package, null if
+ * this package is not referenced.
+ */
+ public PackageDoc packageNamed(String name) {
+ return env.lookupPackage(name);
+ }
+
+ /**
+ * Return the name of this Doc item.
+ *
+ * @return the string <code>"*RootDocImpl*"</code>.
+ */
+ public String name() {
+ return "*RootDocImpl*";
+ }
+
+ /**
+ * Return the name of this Doc item.
+ *
+ * @return the string <code>"*RootDocImpl*"</code>.
+ */
+ public String qualifiedName() {
+ return "*RootDocImpl*";
+ }
+
+ /**
+ * Return true if this Doc is include in the active set.
+ * RootDocImpl isn't even a program entity so it is always false.
+ */
+ public boolean isIncluded() {
+ return false;
+ }
+
+ /**
+ * Print error message, increment error count.
+ *
+ * @param msg message to print
+ */
+ public void printError(String msg) {
+ env.printError(msg);
+ }
+
+ /**
+ * Print error message, increment error count.
+ *
+ * @param msg message to print
+ */
+ public void printError(SourcePosition pos, String msg) {
+ env.printError(pos, msg);
+ }
+
+ /**
+ * Print warning message, increment warning count.
+ *
+ * @param msg message to print
+ */
+ public void printWarning(String msg) {
+ env.printWarning(msg);
+ }
+
+ /**
+ * Print warning message, increment warning count.
+ *
+ * @param msg message to print
+ */
+ public void printWarning(SourcePosition pos, String msg) {
+ env.printWarning(pos, msg);
+ }
+
+ /**
+ * Print a message.
+ *
+ * @param msg message to print
+ */
+ public void printNotice(String msg) {
+ env.printNotice(msg);
+ }
+
+ /**
+ * Print a message.
+ *
+ * @param msg message to print
+ */
+ public void printNotice(SourcePosition pos, String msg) {
+ env.printNotice(pos, msg);
+ }
+
+ /**
+ * Return the path of the overview file and null if it does not exist.
+ * @return the path of the overview file and null if it does not exist.
+ */
+ private JavaFileObject getOverviewPath() {
+ for (String[] opt : options) {
+ if (opt[0].equals("-overview")) {
+ if (env.fileManager instanceof StandardJavaFileManager) {
+ StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
+ return fm.getJavaFileObjects(opt[1]).iterator().next();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Do lazy initialization of "documentation" string.
+ */
+ @Override
+ protected String documentation() {
+ if (documentation == null) {
+ JavaFileObject overviewPath = getOverviewPath();
+ if (overviewPath == null) {
+ // no doc file to be had
+ documentation = "";
+ } else {
+ // read from file
+ try {
+ documentation = readHTMLDocumentation(
+ overviewPath.openInputStream(),
+ overviewPath);
+ } catch (IOException exc) {
+ documentation = "";
+ env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
+ }
+ }
+ }
+ return documentation;
+ }
+
+ /**
+ * Return the source position of the entity, or null if
+ * no position is available.
+ */
+ @Override
+ public SourcePosition position() {
+ JavaFileObject path;
+ return ((path = getOverviewPath()) == null) ?
+ null :
+ SourcePositionImpl.make(path, Position.NOPOS, null);
+ }
+
+ /**
+ * Return the locale provided by the user or the default locale value.
+ */
+ public Locale getLocale() {
+ return env.doclocale.locale;
+ }
+
+ /**
+ * Return the current file manager.
+ */
+ public JavaFileManager getFileManager() {
+ return env.fileManager;
+ }
+
+ public void initDocLint(Collection<String> opts, Collection<String> customTagNames,
+ String htmlVersion) {
+ env.initDoclint(opts, customTagNames, htmlVersion);
+ }
+
+ public boolean isFunctionalInterface(AnnotationDesc annotationDesc) {
+ return env.source.allowLambda()
+ && annotationDesc.annotationType().qualifiedName().equals(
+ env.syms.functionalInterfaceType.toString());
+ }
+
+ public boolean showTagMessages() {
+ return env.showTagMessages();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/SeeTagImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,542 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import java.io.File;
+import java.util.Locale;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.code.Printer;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Type.CapturedType;
+import com.sun.tools.javac.util.*;
+
+import static com.sun.tools.javac.code.Kinds.Kind.*;
+
+/**
+ * Represents a see also documentation tag.
+ * The @see tag can be plain text, or reference a class or member.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Kaiyang Liu (original)
+ * @author Robert Field (rewrite)
+ * @author Atul M Dambalkar
+ *
+ */
+class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
+
+ //### TODO: Searching for classes, fields, and methods
+ //### should follow the normal rules applied by the compiler.
+
+ /**
+ * where of where#what - i.e. the class name (may be empty)
+ */
+ private String where;
+
+ /**
+ * what of where#what - i.e. the member (may be null)
+ */
+ private String what;
+
+ private PackageDoc referencedPackage;
+ private ClassDoc referencedClass;
+ private MemberDoc referencedMember;
+
+ String label = "";
+
+ SeeTagImpl(DocImpl holder, String name, String text) {
+ super(holder, name, text);
+ parseSeeString();
+ if (where != null) {
+ ClassDocImpl container = null;
+ if (holder instanceof MemberDoc) {
+ container =
+ (ClassDocImpl)((ProgramElementDoc)holder).containingClass();
+ } else if (holder instanceof ClassDoc) {
+ container = (ClassDocImpl)holder;
+ }
+ findReferenced(container);
+ if (showRef) showRef();
+ }
+ }
+
+ private static final boolean showRef = false;
+
+ private void showRef() {
+ Symbol sym;
+ if (referencedMember != null) {
+ if (referencedMember instanceof MethodDocImpl)
+ sym = ((MethodDocImpl) referencedMember).sym;
+ else if (referencedMember instanceof FieldDocImpl)
+ sym = ((FieldDocImpl) referencedMember).sym;
+ else
+ sym = ((ConstructorDocImpl) referencedMember).sym;
+ } else if (referencedClass != null) {
+ sym = ((ClassDocImpl) referencedClass).tsym;
+ } else if (referencedPackage != null) {
+ sym = ((PackageDocImpl) referencedPackage).sym;
+ } else
+ return;
+
+ final JavacMessages messages = JavacMessages.instance(docenv().context);
+ Locale locale = Locale.getDefault();
+ Printer printer = new Printer() {
+ int count;
+ @Override
+ protected String localize(Locale locale, String key, Object... args) {
+ return messages.getLocalizedString(locale, key, args);
+ }
+ @Override
+ protected String capturedVarId(CapturedType t, Locale locale) {
+ return "CAP#" + (++count);
+ }
+ };
+
+ String s = text.replaceAll("\\s+", " "); // normalize white space
+ int sp = s.indexOf(" ");
+ int lparen = s.indexOf("(");
+ int rparen = s.indexOf(")");
+ String seetext = (sp == -1) ? s
+ : (lparen == -1 || sp < lparen) ? s.substring(0, sp)
+ : s.substring(0, rparen + 1);
+
+ File file = new File(holder.position().file().getAbsoluteFile().toURI().normalize());
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("+++ ").append(file).append(": ")
+ .append(name()).append(" ").append(seetext).append(": ");
+ sb.append(sym.getKind()).append(" ");
+ if (sym.kind == MTH || sym.kind == VAR)
+ sb.append(printer.visit(sym.owner, locale)).append(".");
+ sb.append(printer.visit(sym, locale));
+
+ System.err.println(sb);
+ }
+
+ /**
+ * get the class name part of @see, For instance,
+ * if the comment is @see String#startsWith(java.lang.String) .
+ * This function returns String.
+ * Returns null if format was not that of java reference.
+ * Return empty string if class name was not specified..
+ */
+ public String referencedClassName() {
+ return where;
+ }
+
+ /**
+ * get the package referenced by @see. For instance,
+ * if the comment is @see java.lang
+ * This function returns a PackageDocImpl for java.lang
+ * Returns null if no known package found.
+ */
+ public PackageDoc referencedPackage() {
+ return referencedPackage;
+ }
+
+ /**
+ * get the class referenced by the class name part of @see, For instance,
+ * if the comment is @see String#startsWith(java.lang.String) .
+ * This function returns a ClassDocImpl for java.lang.String.
+ * Returns null if class is not a class specified on the javadoc command line..
+ */
+ public ClassDoc referencedClass() {
+ return referencedClass;
+ }
+
+ /**
+ * get the name of the member referenced by the prototype part of @see,
+ * For instance,
+ * if the comment is @see String#startsWith(java.lang.String) .
+ * This function returns "startsWith(java.lang.String)"
+ * Returns null if format was not that of java reference.
+ * Return empty string if member name was not specified..
+ */
+ public String referencedMemberName() {
+ return what;
+ }
+
+ /**
+ * get the member referenced by the prototype part of @see,
+ * For instance,
+ * if the comment is @see String#startsWith(java.lang.String) .
+ * This function returns a MethodDocImpl for startsWith.
+ * Returns null if member could not be determined.
+ */
+ public MemberDoc referencedMember() {
+ return referencedMember;
+ }
+
+
+ /**
+ * parse @see part of comment. Determine 'where' and 'what'
+ */
+ private void parseSeeString() {
+ int len = text.length();
+ if (len == 0) {
+ return;
+ }
+ switch (text.charAt(0)) {
+ case '<':
+ if (text.charAt(len-1) != '>') {
+ docenv().warning(holder,
+ "tag.see.no_close_bracket_on_url",
+ name, text);
+ }
+ return;
+ case '"':
+ if (len == 1 || text.charAt(len-1) != '"') {
+ docenv().warning(holder,
+ "tag.see.no_close_quote",
+ name, text);
+ } else {
+// text = text.substring(1,len-1); // strip quotes
+ }
+ return;
+ }
+
+ // check that the text is one word, with possible parentheses
+ // this part of code doesn't allow
+ // @see <a href=.....>asfd</a>
+ // comment it.
+
+ // the code assumes that there is no initial white space.
+ int parens = 0;
+ int commentstart = 0;
+ int start = 0;
+ int cp;
+ for (int i = start; i < len ; i += Character.charCount(cp)) {
+ cp = text.codePointAt(i);
+ switch (cp) {
+ case '(': parens++; break;
+ case ')': parens--; break;
+ case '[': case ']': case '.': case '#': break;
+ case ',':
+ if (parens <= 0) {
+ docenv().warning(holder,
+ "tag.see.malformed_see_tag",
+ name, text);
+ return;
+ }
+ break;
+ case ' ': case '\t': case '\n': case CR:
+ if (parens == 0) { //here onwards the comment starts.
+ commentstart = i;
+ i = len;
+ }
+ break;
+ default:
+ if (!Character.isJavaIdentifierPart(cp)) {
+ docenv().warning(holder,
+ "tag.see.illegal_character",
+ name, ""+cp, text);
+ }
+ break;
+ }
+ }
+ if (parens != 0) {
+ docenv().warning(holder,
+ "tag.see.malformed_see_tag",
+ name, text);
+ return;
+ }
+
+ String seetext = "";
+ String labeltext = "";
+
+ if (commentstart > 0) {
+ seetext = text.substring(start, commentstart);
+ labeltext = text.substring(commentstart + 1);
+ // strip off the white space which can be between seetext and the
+ // actual label.
+ for (int i = 0; i < labeltext.length(); i++) {
+ char ch2 = labeltext.charAt(i);
+ if (!(ch2 == ' ' || ch2 == '\t' || ch2 == '\n')) {
+ label = labeltext.substring(i);
+ break;
+ }
+ }
+ } else {
+ seetext = text;
+ label = "";
+ }
+
+ int sharp = seetext.indexOf('#');
+ if (sharp >= 0) {
+ // class#member
+ where = seetext.substring(0, sharp);
+ what = seetext.substring(sharp + 1);
+ } else {
+ if (seetext.indexOf('(') >= 0) {
+ docenv().warning(holder,
+ "tag.see.missing_sharp",
+ name, text);
+ where = "";
+ what = seetext;
+ }
+ else {
+ // no member specified, text names class
+ where = seetext;
+ what = null;
+ }
+ }
+ }
+
+ /**
+ * Find what is referenced by the see also. If possible, sets
+ * referencedClass and referencedMember.
+ *
+ * @param containingClass the class containing the comment containing
+ * the tag. May be null, if, for example, it is a package comment.
+ */
+ private void findReferenced(ClassDocImpl containingClass) {
+ if (where.length() > 0) {
+ if (containingClass != null) {
+ referencedClass = containingClass.findClass(where);
+ } else {
+ referencedClass = docenv().lookupClass(where);
+ }
+ if (referencedClass == null && holder() instanceof ProgramElementDoc) {
+ referencedClass = docenv().lookupClass(
+ ((ProgramElementDoc) holder()).containingPackage().name() + "." + where);
+ }
+
+ if (referencedClass == null) { /* may just not be in this run */
+ // check if it's a package name
+ referencedPackage = docenv().lookupPackage(where);
+ return;
+ }
+ } else {
+ if (containingClass == null) {
+ docenv().warning(holder,
+ "tag.see.class_not_specified",
+ name, text);
+ return;
+ } else {
+ referencedClass = containingClass;
+ }
+ }
+ where = referencedClass.qualifiedName();
+
+ if (what == null) {
+ return;
+ } else {
+ int paren = what.indexOf('(');
+ String memName = (paren >= 0 ? what.substring(0, paren) : what);
+ String[] paramarr;
+ if (paren > 0) {
+ // has parameter list -- should be method or constructor
+ paramarr = new ParameterParseMachine(what.
+ substring(paren, what.length())).parseParameters();
+ if (paramarr != null) {
+ referencedMember = findExecutableMember(memName, paramarr,
+ referencedClass);
+ } else {
+ referencedMember = null;
+ }
+ } else {
+ // no parameter list -- should be field
+ referencedMember = findExecutableMember(memName, null,
+ referencedClass);
+ FieldDoc fd = ((ClassDocImpl)referencedClass).
+ findField(memName);
+ // when no args given, prefer fields over methods
+ if (referencedMember == null ||
+ (fd != null &&
+ fd.containingClass()
+ .subclassOf(referencedMember.containingClass()))) {
+ referencedMember = fd;
+ }
+ }
+ if (referencedMember == null) {
+ docenv().warning(holder,
+ "tag.see.can_not_find_member",
+ name, what, where);
+ }
+ }
+ }
+
+ private MemberDoc findReferencedMethod(String memName, String[] paramarr,
+ ClassDoc referencedClass) {
+ MemberDoc meth = findExecutableMember(memName, paramarr, referencedClass);
+ if (meth == null) {
+ for (ClassDoc nestedClass : referencedClass.innerClasses()) {
+ meth = findReferencedMethod(memName, paramarr, nestedClass);
+ if (meth != null) {
+ return meth;
+ }
+ }
+ }
+ return null;
+ }
+
+ private MemberDoc findExecutableMember(String memName, String[] paramarr,
+ ClassDoc referencedClass) {
+ String className = referencedClass.name();
+ if (memName.equals(className.substring(className.lastIndexOf(".") + 1))) {
+ return ((ClassDocImpl)referencedClass).findConstructor(memName,
+ paramarr);
+ } else { // it's a method.
+ return ((ClassDocImpl)referencedClass).findMethod(memName,
+ paramarr);
+ }
+ }
+
+ // separate "int, String" from "(int, String)"
+ // (int i, String s) ==> [0] = "int", [1] = String
+ // (int[][], String[]) ==> [0] = "int[][]" // [1] = "String[]"
+ class ParameterParseMachine {
+ static final int START = 0;
+ static final int TYPE = 1;
+ static final int NAME = 2;
+ static final int TNSPACE = 3; // space between type and name
+ static final int ARRAYDECORATION = 4;
+ static final int ARRAYSPACE = 5;
+
+ String parameters;
+
+ StringBuilder typeId;
+
+ ListBuffer<String> paramList;
+
+ ParameterParseMachine(String parameters) {
+ this.parameters = parameters;
+ this.paramList = new ListBuffer<>();
+ typeId = new StringBuilder();
+ }
+
+ public String[] parseParameters() {
+ if (parameters.equals("()")) {
+ return new String[0];
+ } // now strip off '(' and ')'
+ int state = START;
+ int prevstate = START;
+ parameters = parameters.substring(1, parameters.length() - 1);
+ int cp;
+ for (int index = 0; index < parameters.length(); index += Character.charCount(cp)) {
+ cp = parameters.codePointAt(index);
+ switch (state) {
+ case START:
+ if (Character.isJavaIdentifierStart(cp)) {
+ typeId.append(Character.toChars(cp));
+ state = TYPE;
+ }
+ prevstate = START;
+ break;
+ case TYPE:
+ if (Character.isJavaIdentifierPart(cp) || cp == '.') {
+ typeId.append(Character.toChars(cp));
+ } else if (cp == '[') {
+ typeId.append('[');
+ state = ARRAYDECORATION;
+ } else if (Character.isWhitespace(cp)) {
+ state = TNSPACE;
+ } else if (cp == ',') { // no name, just type
+ addTypeToParamList();
+ state = START;
+ }
+ prevstate = TYPE;
+ break;
+ case TNSPACE:
+ if (Character.isJavaIdentifierStart(cp)) { // name
+ if (prevstate == ARRAYDECORATION) {
+ docenv().warning(holder,
+ "tag.missing_comma_space",
+ name,
+ "(" + parameters + ")");
+ return (String[])null;
+ }
+ addTypeToParamList();
+ state = NAME;
+ } else if (cp == '[') {
+ typeId.append('[');
+ state = ARRAYDECORATION;
+ } else if (cp == ',') { // just the type
+ addTypeToParamList();
+ state = START;
+ } // consume rest all
+ prevstate = TNSPACE;
+ break;
+ case ARRAYDECORATION:
+ if (cp == ']') {
+ typeId.append(']');
+ state = TNSPACE;
+ } else if (!Character.isWhitespace(cp)) {
+ docenv().warning(holder,
+ "tag.illegal_char_in_arr_dim",
+ name,
+ "(" + parameters + ")");
+ return (String[])null;
+ }
+ prevstate = ARRAYDECORATION;
+ break;
+ case NAME:
+ if (cp == ',') { // just consume everything till ','
+ state = START;
+ }
+ prevstate = NAME;
+ break;
+ }
+ }
+ if (state == ARRAYDECORATION ||
+ (state == START && prevstate == TNSPACE)) {
+ docenv().warning(holder,
+ "tag.illegal_see_tag",
+ "(" + parameters + ")");
+ }
+ if (typeId.length() > 0) {
+ paramList.append(typeId.toString());
+ }
+ return paramList.toArray(new String[paramList.length()]);
+ }
+
+ void addTypeToParamList() {
+ if (typeId.length() > 0) {
+ paramList.append(typeId.toString());
+ typeId.setLength(0);
+ }
+ }
+ }
+
+ /**
+ * Return the kind of this tag.
+ */
+ @Override
+ public String kind() {
+ return "@see";
+ }
+
+ /**
+ * Return the label of the see tag.
+ */
+ public String label() {
+ return label;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/SerialFieldTagImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 1998, 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.main;
+
+import com.sun.javadoc.*;
+
+/**
+ * Documents a Serializable field defined by an ObjectStreamField.
+ * <pre>
+ * The class parses and stores the three serialField tag parameters:
+ *
+ * - field name
+ * - field type name
+ * (fully-qualified or visible from the current import context)
+ * - description of the valid values for the field
+
+ * </pre>
+ * This tag is only allowed in the javadoc for the special member
+ * serialPersistentFields.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Joe Fialli
+ * @author Neal Gafter
+ *
+ * @see java.io.ObjectStreamField
+ */
+class SerialFieldTagImpl
+ extends TagImpl
+ implements SerialFieldTag, Comparable<Object>
+{
+ //### These could be final, except that the constructor
+ //### does not set them directly.
+
+ private String fieldName; // Required Argument 1 of serialField
+ private String fieldType; // Required Argument 2 of serialField
+ private String description; // Optional Remaining Arguments of serialField
+
+ private ClassDoc containingClass; // Class containing serialPersistentField member
+ private ClassDoc fieldTypeDoc; // ClassDocImpl of fieldType
+ private FieldDocImpl matchingField; // FieldDocImpl with same name as fieldName
+
+ /* Constructor. */
+ SerialFieldTagImpl(DocImpl holder, String name, String text) {
+ super(holder, name, text);
+ parseSerialFieldString();
+ if (holder instanceof MemberDoc) {
+ containingClass = ((MemberDocImpl)holder).containingClass();
+ }
+ }
+
+ /*
+ * The serialField tag is composed of three entities.
+ *
+ * serialField serializableFieldName serisliableFieldType
+ * description of field.
+ *
+ * The fieldName and fieldType must be legal Java Identifiers.
+ */
+ private void parseSerialFieldString() {
+ int len = text.length();
+ if (len == 0) {
+ return;
+ }
+
+ // if no white space found
+ /* Skip white space. */
+ int inx = 0;
+ int cp;
+ for (; inx < len; inx += Character.charCount(cp)) {
+ cp = text.codePointAt(inx);
+ if (!Character.isWhitespace(cp)) {
+ break;
+ }
+ }
+
+ /* find first word. */
+ int first = inx;
+ int last = inx;
+ cp = text.codePointAt(inx);
+ if (! Character.isJavaIdentifierStart(cp)) {
+ docenv().warning(holder,
+ "tag.serialField.illegal_character",
+ new String(Character.toChars(cp)), text);
+ return;
+ }
+
+ for (inx += Character.charCount(cp); inx < len; inx += Character.charCount(cp)) {
+ cp = text.codePointAt(inx);
+ if (!Character.isJavaIdentifierPart(cp)) {
+ break;
+ }
+ }
+
+ if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
+ docenv().warning(holder,
+ "tag.serialField.illegal_character",
+ new String(Character.toChars(cp)), text);
+ return;
+ }
+
+ last = inx;
+ fieldName = text.substring(first, last);
+
+ /* Skip white space. */
+ for (; inx < len; inx += Character.charCount(cp)) {
+ cp = text.codePointAt(inx);
+ if (!Character.isWhitespace(cp)) {
+ break;
+ }
+ }
+
+ /* find second word. */
+ first = inx;
+ last = inx;
+
+ for (; inx < len; inx += Character.charCount(cp)) {
+ cp = text.codePointAt(inx);
+ if (Character.isWhitespace(cp)) {
+ break;
+ }
+ }
+ if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
+ docenv().warning(holder,
+ "tag.serialField.illegal_character",
+ new String(Character.toChars(cp)), text);
+ return;
+ }
+ last = inx;
+ fieldType = text.substring(first, last);
+
+ /* Skip leading white space. Rest of string is description for serialField.*/
+ for (; inx < len; inx += Character.charCount(cp)) {
+ cp = text.codePointAt(inx);
+ if (!Character.isWhitespace(cp)) {
+ break;
+ }
+ }
+ description = text.substring(inx);
+ }
+
+ /**
+ * return a key for sorting.
+ */
+ String key() {
+ return fieldName;
+ }
+
+ /*
+ * Optional. Link this serialField tag to its corrsponding
+ * field in the class. Note: there is no requirement that
+ * there be a field in the class that matches serialField tag.
+ */
+ void mapToFieldDocImpl(FieldDocImpl fd) {
+ matchingField = fd;
+ }
+
+ /**
+ * Return the serialziable field name.
+ */
+ public String fieldName() {
+ return fieldName;
+ }
+
+ /**
+ * Return the field type string.
+ */
+ public String fieldType() {
+ return fieldType;
+ }
+
+ /**
+ * Return the ClassDocImpl for field type.
+ *
+ * @returns null if no ClassDocImpl for field type is visible from
+ * containingClass context.
+ */
+ public ClassDoc fieldTypeDoc() {
+ if (fieldTypeDoc == null && containingClass != null) {
+ fieldTypeDoc = containingClass.findClass(fieldType);
+ }
+ return fieldTypeDoc;
+ }
+
+ /**
+ * Return the corresponding FieldDocImpl for this SerialFieldTagImpl.
+ *
+ * @returns null if no matching FieldDocImpl.
+ */
+ FieldDocImpl getMatchingField() {
+ return matchingField;
+ }
+
+ /**
+ * Return the field comment. If there is no serialField comment, return
+ * javadoc comment of corresponding FieldDocImpl.
+ */
+ public String description() {
+ if (description.length() == 0 && matchingField != null) {
+
+ //check for javadoc comment of corresponding field.
+ Comment comment = matchingField.comment();
+ if (comment != null) {
+ return comment.commentText();
+ }
+ }
+ return description;
+ }
+
+ /**
+ * Return the kind of this tag.
+ */
+ public String kind() {
+ return "@serialField";
+ }
+
+ /**
+ * Convert this object to a string.
+ */
+ public String toString() {
+ return name + ":" + text;
+ }
+
+ /**
+ * 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.
+ * <p>
+ * Included to make SerialFieldTagImpl items java.lang.Comparable.
+ *
+ * @param obj the <code>Object</code> 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.
+ * @since 1.2
+ */
+ public int compareTo(Object obj) {
+ return key().compareTo(((SerialFieldTagImpl)obj).key());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/SerializedForm.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,287 @@
+/*
+ * Copyright (c) 1998, 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.main;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.code.*;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
+import com.sun.tools.javac.code.Symbol.VarSymbol;
+import com.sun.tools.javac.util.*;
+
+import static com.sun.tools.javac.code.Kinds.Kind.*;
+import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
+
+/**
+ * The serialized form is the specification of a class' serialization
+ * state. <p>
+ *
+ * It consists of the following information:<p>
+ *
+ * <pre>
+ * 1. Whether class is Serializable or Externalizable.
+ * 2. Javadoc for serialization methods.
+ * a. For Serializable, the optional readObject, writeObject,
+ * readResolve and writeReplace.
+ * serialData tag describes, in prose, the sequence and type
+ * of optional data written by writeObject.
+ * b. For Externalizable, writeExternal and readExternal.
+ * serialData tag describes, in prose, the sequence and type
+ * of optional data written by writeExternal.
+ * 3. Javadoc for serialization data layout.
+ * a. For Serializable, the name,type and description
+ * of each Serializable fields.
+ * b. For Externalizable, data layout is described by 2(b).
+ * </pre>
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Joe Fialli
+ * @author Neal Gafter (rewrite but not too proud)
+ */
+class SerializedForm {
+ ListBuffer<MethodDoc> methods = new ListBuffer<>();
+
+ /* List of FieldDocImpl - Serializable fields.
+ * Singleton list if class defines Serializable fields explicitly.
+ * Otherwise, list of default serializable fields.
+ * 0 length list for Externalizable.
+ */
+ private final ListBuffer<FieldDocImpl> fields = new ListBuffer<>();
+
+ /* True if class specifies serializable fields explicitly.
+ * using special static member, serialPersistentFields.
+ */
+ private boolean definesSerializableFields = false;
+
+ // Specially treated field/method names defined by Serialization.
+ private static final String SERIALIZABLE_FIELDS = "serialPersistentFields";
+ private static final String READOBJECT = "readObject";
+ private static final String WRITEOBJECT = "writeObject";
+ private static final String READRESOLVE = "readResolve";
+ private static final String WRITEREPLACE = "writeReplace";
+ private static final String READOBJECTNODATA = "readObjectNoData";
+
+ /**
+ * Constructor.
+ *
+ * Catalog Serializable fields for Serializable class.
+ * Catalog serialization methods for Serializable and
+ * Externalizable classes.
+ */
+ SerializedForm(DocEnv env, ClassSymbol def, ClassDocImpl cd) {
+ if (cd.isExternalizable()) {
+ /* look up required public accessible methods,
+ * writeExternal and readExternal.
+ */
+ String[] readExternalParamArr = { "java.io.ObjectInput" };
+ String[] writeExternalParamArr = { "java.io.ObjectOutput" };
+ MethodDoc md = cd.findMethod("readExternal", readExternalParamArr);
+ if (md != null) {
+ methods.append(md);
+ }
+ md = cd.findMethod("writeExternal", writeExternalParamArr);
+ if (md != null) {
+ methods.append(md);
+ Tag tag[] = md.tags("serialData");
+ }
+ // } else { // isSerializable() //### ???
+ } else if (cd.isSerializable()) {
+
+ VarSymbol dsf = getDefinedSerializableFields(def);
+ if (dsf != null) {
+
+ /* Define serializable fields with array of ObjectStreamField.
+ * Each ObjectStreamField should be documented by a
+ * serialField tag.
+ */
+ definesSerializableFields = true;
+ //### No modifier filtering applied here.
+ FieldDocImpl dsfDoc = env.getFieldDoc(dsf);
+ fields.append(dsfDoc);
+ mapSerialFieldTagImplsToFieldDocImpls(dsfDoc, env, def);
+ } else {
+
+ /* Calculate default Serializable fields as all
+ * non-transient, non-static fields.
+ * Fields should be documented by serial tag.
+ */
+ computeDefaultSerializableFields(env, def, cd);
+ }
+
+ /* Check for optional customized readObject, writeObject,
+ * readResolve and writeReplace, which can all contain
+ * the serialData tag. */
+ addMethodIfExist(env, def, READOBJECT);
+ addMethodIfExist(env, def, WRITEOBJECT);
+ addMethodIfExist(env, def, READRESOLVE);
+ addMethodIfExist(env, def, WRITEREPLACE);
+ addMethodIfExist(env, def, READOBJECTNODATA);
+ }
+ }
+
+ /*
+ * Check for explicit Serializable fields.
+ * Check for a private static array of ObjectStreamField with
+ * name SERIALIZABLE_FIELDS.
+ */
+ private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
+ Names names = def.name.table.names;
+
+ /* SERIALIZABLE_FIELDS can be private,
+ * so must lookup by ClassSymbol, not by ClassDocImpl.
+ */
+ for (Symbol sym : def.members().getSymbolsByName(names.fromString(SERIALIZABLE_FIELDS))) {
+ if (sym.kind == VAR) {
+ VarSymbol f = (VarSymbol)sym;
+ if ((f.flags() & Flags.STATIC) != 0 &&
+ (f.flags() & Flags.PRIVATE) != 0) {
+ return f;
+ }
+ }
+ }
+ return null;
+ }
+
+ /*
+ * Compute default Serializable fields from all members of ClassSymbol.
+ *
+ * Since the fields of ClassDocImpl might not contain private or
+ * package accessible fields, must walk over all members of ClassSymbol.
+ */
+ private void computeDefaultSerializableFields(DocEnv env,
+ ClassSymbol def,
+ ClassDocImpl cd) {
+ for (Symbol sym : def.members().getSymbols(NON_RECURSIVE)) {
+ if (sym != null && sym.kind == VAR) {
+ VarSymbol f = (VarSymbol)sym;
+ if ((f.flags() & Flags.STATIC) == 0 &&
+ (f.flags() & Flags.TRANSIENT) == 0) {
+ //### No modifier filtering applied here.
+ FieldDocImpl fd = env.getFieldDoc(f);
+ //### Add to beginning.
+ //### Preserve order used by old 'javadoc'.
+ fields.prepend(fd);
+ }
+ }
+ }
+ }
+
+ /*
+ * Catalog Serializable method if it exists in current ClassSymbol.
+ * Do not look for method in superclasses.
+ *
+ * Serialization requires these methods to be non-static.
+ *
+ * @param method should be an unqualified Serializable method
+ * name either READOBJECT, WRITEOBJECT, READRESOLVE
+ * or WRITEREPLACE.
+ * @param visibility the visibility flag for the given method.
+ */
+ private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
+ Names names = def.name.table.names;
+
+ for (Symbol sym : def.members().getSymbolsByName(names.fromString(methodName))) {
+ if (sym.kind == MTH) {
+ MethodSymbol md = (MethodSymbol)sym;
+ if ((md.flags() & Flags.STATIC) == 0) {
+ /*
+ * WARNING: not robust if unqualifiedMethodName is overloaded
+ * method. Signature checking could make more robust.
+ * READOBJECT takes a single parameter, java.io.ObjectInputStream.
+ * WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
+ */
+ methods.append(env.getMethodDoc(md));
+ }
+ }
+ }
+ }
+
+ /*
+ * Associate serialField tag fieldName with FieldDocImpl member.
+ * Note: A serialField tag does not have to map an existing field
+ * of a class.
+ */
+ private void mapSerialFieldTagImplsToFieldDocImpls(FieldDocImpl spfDoc,
+ DocEnv env,
+ ClassSymbol def) {
+ Names names = def.name.table.names;
+ for (SerialFieldTag tag : spfDoc.serialFieldTags()) {
+ if (tag.fieldName() == null || tag.fieldType() == null) // ignore malformed @serialField tags
+ continue;
+
+ Name fieldName = names.fromString(tag.fieldName());
+
+ // Look for a FieldDocImpl that is documented by serialFieldTagImpl.
+ for (Symbol sym : def.members().getSymbolsByName(fieldName)) {
+ if (sym.kind == VAR) {
+ VarSymbol f = (VarSymbol) sym;
+ FieldDocImpl fdi = env.getFieldDoc(f);
+ ((SerialFieldTagImpl) (tag)).mapToFieldDocImpl(fdi);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Return serializable fields in class. <p>
+ *
+ * Returns either a list of default fields documented by serial tag comment or
+ * javadoc comment<p>
+ * Or Returns a single FieldDocImpl for serialPersistentField. There is a
+ * serialField tag for each serializable field.<p>
+ *
+ * @return an array of FieldDocImpl for representing the visible
+ * fields in this class.
+ */
+ FieldDoc[] fields() {
+ return (FieldDoc[])fields.toArray(new FieldDocImpl[fields.length()]);
+ }
+
+ /**
+ * Return serialization methods in class.
+ *
+ * @return an array of MethodDocImpl for serialization methods in this class.
+ */
+ MethodDoc[] methods() {
+ return methods.toArray(new MethodDoc[methods.length()]);
+ }
+
+ /**
+ * Returns true if Serializable fields are defined explicitly using
+ * member, serialPersistentFields.
+ *
+ * @see #fields()
+ */
+ boolean definesSerializableFields() {
+ return definesSerializableFields;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/SourcePositionImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2001, 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.main;
+
+import java.io.File;
+import javax.tools.FileObject;
+
+import com.sun.javadoc.SourcePosition;
+import com.sun.tools.javac.util.Position;
+
+/**
+ * A source position: filename, line number, and column number.
+ *
+ * <p><b>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.</b>
+ *
+ * @since J2SE1.4
+ * @author Neal M Gafter
+ * @author Michael Van De Vanter (position representation changed to char offsets)
+ */
+public class SourcePositionImpl implements SourcePosition {
+ FileObject filename;
+ int position;
+ Position.LineMap lineMap;
+
+ /** The source file. Returns null if no file information is
+ * available. */
+ public File file() {
+ return (filename == null) ? null : new File(filename.getName());
+ }
+
+ /** The source file. Returns null if no file information is
+ * available. */
+ public FileObject fileObject() {
+ return filename;
+ }
+
+ /** The line in the source file. The first line is numbered 1;
+ * 0 means no line number information is available. */
+ public int line() {
+ if (lineMap == null) {
+ return 0;
+ } else {
+ return lineMap.getLineNumber(position);
+ }
+ }
+
+ /** The column in the source file. The first column is
+ * numbered 1; 0 means no column information is available.
+ * Columns count characters in the input stream; a tab
+ * advances the column number to the next 8-column tab stop.
+ */
+ public int column() {
+ if (lineMap == null) {
+ return 0;
+ }else {
+ return lineMap.getColumnNumber(position);
+ }
+ }
+
+ private SourcePositionImpl(FileObject file, int position,
+ Position.LineMap lineMap) {
+ super();
+ this.filename = file;
+ this.position = position;
+ this.lineMap = lineMap;
+ }
+
+ public static SourcePosition make(FileObject file, int pos,
+ Position.LineMap lineMap) {
+ if (file == null) return null;
+ return new SourcePositionImpl(file, pos, lineMap);
+ }
+
+ public String toString() {
+ // Backwards compatibility hack. ZipFileObjects use the format
+ // zipfile(zipentry) but javadoc has been using zipfile/zipentry
+ String fn = filename.getName();
+ if (fn.endsWith(")")) {
+ int paren = fn.lastIndexOf("(");
+ if (paren != -1) {
+ int i = paren+1;
+ if (fn.charAt(i) == '/')
+ i++;
+ fn = fn.substring(0, paren)
+ + File.separatorChar
+ + fn.substring(i, fn.length() - 1);
+ }
+ }
+
+ if (position == Position.NOPOS)
+ return fn;
+ else
+ return fn + ":" + line();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/Start.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,557 @@
+/*
+ * Copyright (c) 1997, 2016, 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.main;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+
+import com.sun.javadoc.*;
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.main.CommandLine;
+import com.sun.tools.javac.main.Option;
+import com.sun.tools.javac.file.BaseFileManager;
+import com.sun.tools.javac.platform.PlatformDescription;
+import com.sun.tools.javac.platform.PlatformUtils;
+import com.sun.tools.javac.util.ClientCodeException;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Log;
+import com.sun.tools.javac.util.Options;
+
+import static com.sun.tools.javac.code.Flags.*;
+
+/**
+ * Main program of Javadoc.
+ * Previously named "Main".
+ *
+ * <p><b>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.</b>
+ *
+ * @since 1.2
+ * @author Robert Field
+ * @author Neal Gafter (rewrite)
+ */
+public class Start extends ToolOption.Helper {
+ /** Context for this invocation. */
+ private final Context context;
+
+ private final String defaultDocletClassName;
+ private final ClassLoader docletParentClassLoader;
+
+ private static final String javadocName = "javadoc";
+
+ private static final String standardDocletClassName =
+ "com.sun.tools.doclets.standard.Standard";
+
+ private final long defaultFilter = PUBLIC | PROTECTED;
+
+ private final Messager messager;
+
+ private DocletInvoker docletInvoker;
+
+ /**
+ * In API mode, exceptions thrown while calling the doclet are
+ * propagated using ClientCodeException.
+ */
+ private boolean apiMode;
+
+ private JavaFileManager fileManager;
+
+ public Start(String programName,
+ PrintWriter errWriter,
+ PrintWriter warnWriter,
+ PrintWriter noticeWriter,
+ String defaultDocletClassName) {
+ this(programName, errWriter, warnWriter, noticeWriter, defaultDocletClassName, null);
+ }
+
+ public Start(PrintWriter pw) {
+ this(javadocName, pw, pw, pw, standardDocletClassName);
+ }
+
+ public Start(String programName,
+ PrintWriter errWriter,
+ PrintWriter warnWriter,
+ PrintWriter noticeWriter,
+ String defaultDocletClassName,
+ ClassLoader docletParentClassLoader) {
+ context = new Context();
+ messager = new Messager(context, programName, errWriter, warnWriter, noticeWriter);
+ this.defaultDocletClassName = defaultDocletClassName;
+ this.docletParentClassLoader = docletParentClassLoader;
+ }
+
+ public Start(String programName, String defaultDocletClassName) {
+ this(programName, defaultDocletClassName, null);
+ }
+
+ public Start(String programName, String defaultDocletClassName,
+ ClassLoader docletParentClassLoader) {
+ context = new Context();
+ messager = new Messager(context, programName);
+ this.defaultDocletClassName = defaultDocletClassName;
+ this.docletParentClassLoader = docletParentClassLoader;
+ }
+
+ public Start(String programName, ClassLoader docletParentClassLoader) {
+ this(programName, standardDocletClassName, docletParentClassLoader);
+ }
+
+ public Start(String programName) {
+ this(programName, standardDocletClassName);
+ }
+
+ public Start(ClassLoader docletParentClassLoader) {
+ this(javadocName, docletParentClassLoader);
+ }
+
+ public Start() {
+ this(javadocName);
+ }
+
+ public Start(Context context) {
+ this.context = Objects.requireNonNull(context);
+ apiMode = true;
+ defaultDocletClassName = standardDocletClassName;
+ docletParentClassLoader = null;
+
+ Log log = context.get(Log.logKey);
+ if (log instanceof Messager)
+ messager = (Messager) log;
+ else {
+ PrintWriter out = context.get(Log.outKey);
+ messager = (out == null) ? new Messager(context, javadocName)
+ : new Messager(context, javadocName, out, out, out);
+ }
+ }
+
+ /**
+ * Usage
+ */
+ @Override
+ void usage() {
+ usage(true);
+ }
+
+ void usage(boolean exit) {
+ usage("main.usage", "-help", null, exit);
+ }
+
+ @Override
+ void Xusage() {
+ Xusage(true);
+ }
+
+ void Xusage(boolean exit) {
+ usage("main.Xusage", "-X", "main.Xusage.foot", exit);
+ }
+
+ private void usage(String main, String doclet, String foot, boolean exit) {
+ // RFE: it would be better to replace the following with code to
+ // write a header, then help for each option, then a footer.
+ messager.notice(main);
+
+ // let doclet print usage information (does nothing on error)
+ if (docletInvoker != null) {
+ // RFE: this is a pretty bad way to get the doclet to show
+ // help info. Moreover, the output appears on stdout,
+ // and <i>not</i> on any of the standard streams passed
+ // to javadoc, and in particular, not to the noticeWriter
+ // But, to fix this, we need to fix the Doclet API.
+ docletInvoker.optionLength(doclet);
+ }
+
+ if (foot != null)
+ messager.notice(foot);
+
+ if (exit) exit();
+ }
+
+ /**
+ * Exit
+ */
+ private void exit() {
+ messager.exit();
+ }
+
+
+ /**
+ * Main program - external wrapper
+ */
+ public int begin(String... argv) {
+ boolean ok = begin(null, argv, Collections.<JavaFileObject> emptySet());
+ return ok ? 0 : 1;
+ }
+
+ public boolean begin(Class<?> docletClass, Iterable<String> options, Iterable<? extends JavaFileObject> fileObjects) {
+ Collection<String> opts = new ArrayList<>();
+ for (String opt: options) opts.add(opt);
+ return begin(docletClass, opts.toArray(new String[opts.size()]), fileObjects);
+ }
+
+ private boolean begin(Class<?> docletClass, String[] options, Iterable<? extends JavaFileObject> fileObjects) {
+ boolean failed = false;
+
+ try {
+ failed = !parseAndExecute(docletClass, options, fileObjects);
+ } catch (Messager.ExitJavadoc exc) {
+ // ignore, we just exit this way
+ } catch (OutOfMemoryError ee) {
+ messager.error(Messager.NOPOS, "main.out.of.memory");
+ failed = true;
+ } catch (ClientCodeException e) {
+ // simply rethrow these exceptions, to be caught and handled by JavadocTaskImpl
+ throw e;
+ } catch (Error ee) {
+ ee.printStackTrace(System.err);
+ messager.error(Messager.NOPOS, "main.fatal.error");
+ failed = true;
+ } catch (Exception ee) {
+ ee.printStackTrace(System.err);
+ messager.error(Messager.NOPOS, "main.fatal.exception");
+ failed = true;
+ } finally {
+ if (fileManager != null
+ && fileManager instanceof BaseFileManager
+ && ((BaseFileManager) fileManager).autoClose) {
+ try {
+ fileManager.close();
+ } catch (IOException ignore) {
+ }
+ }
+ messager.exitNotice();
+ messager.flush();
+ }
+ failed |= messager.nerrors() > 0;
+ failed |= rejectWarnings && messager.nwarnings() > 0;
+ return !failed;
+ }
+
+ /**
+ * Main program - internal
+ */
+ private boolean parseAndExecute(
+ Class<?> docletClass,
+ String[] argv,
+ Iterable<? extends JavaFileObject> fileObjects) throws IOException {
+ long tm = System.currentTimeMillis();
+
+ ListBuffer<String> javaNames = new ListBuffer<>();
+
+ // Preprocess @file arguments
+ try {
+ argv = CommandLine.parse(argv);
+ } catch (FileNotFoundException e) {
+ messager.error(Messager.NOPOS, "main.cant.read", e.getMessage());
+ exit();
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ exit();
+ }
+
+
+ fileManager = context.get(JavaFileManager.class);
+
+ setDocletInvoker(docletClass, fileManager, argv);
+
+ compOpts = Options.instance(context);
+ // Make sure no obsolete source/target messages are reported
+ compOpts.put("-Xlint:-options", "-Xlint:-options");
+
+ // Parse arguments
+ for (int i = 0 ; i < argv.length ; i++) {
+ String arg = argv[i];
+
+ ToolOption o = ToolOption.get(arg);
+ if (o != null) {
+ // hack: this restriction should be removed
+ if (o == ToolOption.LOCALE && i > 0)
+ usageError("main.locale_first");
+
+ if (o.hasArg) {
+ oneArg(argv, i++);
+ o.process(this, argv[i]);
+ } else {
+ setOption(arg);
+ o.process(this);
+ }
+ } else if (arg.equals("-XDaccessInternalAPI")) {
+ // pass this hidden option down to the doclet, if it wants it
+ if (docletInvoker.optionLength("-XDaccessInternalAPI") == 1) {
+ setOption(arg);
+ }
+ } else if (arg.startsWith("-XD")) {
+ // hidden javac options
+ String s = arg.substring("-XD".length());
+ int eq = s.indexOf('=');
+ String key = (eq < 0) ? s : s.substring(0, eq);
+ String value = (eq < 0) ? s : s.substring(eq+1);
+ compOpts.put(key, value);
+ }
+ // call doclet for its options
+ // other arg starts with - is invalid
+ else if (arg.startsWith("-")) {
+ int optionLength;
+ optionLength = docletInvoker.optionLength(arg);
+ if (optionLength < 0) {
+ // error already displayed
+ exit();
+ } else if (optionLength == 0) {
+ // option not found
+ usageError("main.invalid_flag", arg);
+ } else {
+ // doclet added option
+ if ((i + optionLength) > argv.length) {
+ usageError("main.requires_argument", arg);
+ }
+ ListBuffer<String> args = new ListBuffer<>();
+ for (int j = 0; j < optionLength-1; ++j) {
+ args.append(argv[++i]);
+ }
+ setOption(arg, args.toList());
+ }
+ } else {
+ javaNames.append(arg);
+ }
+ }
+
+ if (fileManager == null) {
+ JavacFileManager.preRegister(context);
+ fileManager = context.get(JavaFileManager.class);
+ if (fileManager instanceof BaseFileManager) {
+ ((BaseFileManager) fileManager).autoClose = true;
+ }
+ }
+ if (fileManager instanceof BaseFileManager) {
+ ((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
+ }
+
+ String platformString = compOpts.get("-release");
+
+ if (platformString != null) {
+ if (compOpts.isSet("-source")) {
+ usageError("main.release.bootclasspath.conflict", "-source");
+ }
+ if (fileManagerOpts.containsKey(Option.BOOTCLASSPATH)) {
+ usageError("main.release.bootclasspath.conflict", Option.BOOTCLASSPATH.getText());
+ }
+
+ PlatformDescription platformDescription =
+ PlatformUtils.lookupPlatformDescription(platformString);
+
+ if (platformDescription == null) {
+ usageError("main.unsupported.release.version", platformString);
+ }
+
+ compOpts.put(Option.SOURCE, platformDescription.getSourceVersion());
+
+ context.put(PlatformDescription.class, platformDescription);
+
+ Collection<Path> platformCP = platformDescription.getPlatformPath();
+
+ if (platformCP != null) {
+ if (fileManager instanceof StandardJavaFileManager) {
+ StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager;
+
+ sfm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, platformCP);
+ } else {
+ usageError("main.release.not.standard.file.manager", platformString);
+ }
+ }
+ }
+
+ compOpts.notifyListeners();
+
+ if (javaNames.isEmpty() && subPackages.isEmpty() && isEmpty(fileObjects)) {
+ usageError("main.No_packages_or_classes_specified");
+ }
+
+ if (!docletInvoker.validOptions(options.toList())) {
+ // error message already displayed
+ exit();
+ }
+
+ JavadocTool comp = JavadocTool.make0(context);
+ if (comp == null) return false;
+
+ if (showAccess == null) {
+ setFilter(defaultFilter);
+ }
+
+ LanguageVersion languageVersion = docletInvoker.languageVersion();
+ RootDocImpl root = comp.getRootDocImpl(
+ docLocale,
+ encoding,
+ showAccess,
+ javaNames.toList(),
+ options.toList(),
+ fileObjects,
+ breakiterator,
+ subPackages.toList(),
+ excludedPackages.toList(),
+ docClasses,
+ // legacy?
+ languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1,
+ quiet);
+
+ // release resources
+ comp = null;
+
+ // pass off control to the doclet
+ boolean ok = root != null;
+ if (ok) ok = docletInvoker.start(root);
+
+ // We're done.
+ if (compOpts.get("-verbose") != null) {
+ tm = System.currentTimeMillis() - tm;
+ messager.notice("main.done_in", Long.toString(tm));
+ }
+
+ return ok;
+ }
+
+ private <T> boolean isEmpty(Iterable<T> iter) {
+ return !iter.iterator().hasNext();
+ }
+
+ /**
+ * Init the doclet invoker.
+ * The doclet class may be given explicitly, or via the -doclet option in
+ * argv.
+ * If the doclet class is not given explicitly, it will be loaded from
+ * the file manager's DOCLET_PATH location, if available, or via the
+ * -doclet path option in argv.
+ * @param docletClass The doclet class. May be null.
+ * @param fileManager The file manager used to get the class loader to load
+ * the doclet class if required. May be null.
+ * @param argv Args containing -doclet and -docletpath, in case they are required.
+ */
+ private void setDocletInvoker(Class<?> docletClass, JavaFileManager fileManager, String[] argv) {
+ boolean exportInternalAPI = false;
+ String docletClassName = null;
+ String docletPath = null;
+
+ // Parse doclet specifying arguments
+ for (int i = 0 ; i < argv.length ; i++) {
+ String arg = argv[i];
+ if (arg.equals(ToolOption.DOCLET.opt)) {
+ oneArg(argv, i++);
+ if (docletClassName != null) {
+ usageError("main.more_than_one_doclet_specified_0_and_1",
+ docletClassName, argv[i]);
+ }
+ docletClassName = argv[i];
+ } else if (arg.equals(ToolOption.DOCLETPATH.opt)) {
+ oneArg(argv, i++);
+ if (docletPath == null) {
+ docletPath = argv[i];
+ } else {
+ docletPath += File.pathSeparator + argv[i];
+ }
+ } else if (arg.equals("-XDaccessInternalAPI")) {
+ exportInternalAPI = true;
+ }
+ }
+
+ if (docletClass != null) {
+ // TODO, check no -doclet, -docletpath
+ docletInvoker = new DocletInvoker(messager, docletClass, apiMode, exportInternalAPI);
+ } else {
+ if (docletClassName == null) {
+ docletClassName = defaultDocletClassName;
+ }
+
+ // attempt to find doclet
+ docletInvoker = new DocletInvoker(messager, fileManager,
+ docletClassName, docletPath,
+ docletParentClassLoader,
+ apiMode,
+ exportInternalAPI);
+ }
+ }
+
+ /**
+ * Set one arg option.
+ * Error and exit if one argument is not provided.
+ */
+ private void oneArg(String[] args, int index) {
+ if ((index + 1) < args.length) {
+ setOption(args[index], args[index+1]);
+ } else {
+ usageError("main.requires_argument", args[index]);
+ }
+ }
+
+ @Override
+ void usageError(String key, Object... args) {
+ messager.error(Messager.NOPOS, key, args);
+ usage(true);
+ }
+
+ /**
+ * indicate an option with no arguments was given.
+ */
+ private void setOption(String opt) {
+ String[] option = { opt };
+ options.append(option);
+ }
+
+ /**
+ * indicate an option with one argument was given.
+ */
+ private void setOption(String opt, String argument) {
+ String[] option = { opt, argument };
+ options.append(option);
+ }
+
+ /**
+ * indicate an option with the specified list of arguments was given.
+ */
+ private void setOption(String opt, List<String> arguments) {
+ String[] args = new String[arguments.length() + 1];
+ int k = 0;
+ args[k++] = opt;
+ for (List<String> i = arguments; i.nonEmpty(); i=i.tail) {
+ args[k++] = i.head;
+ }
+ options.append(args);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/TagImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import com.sun.javadoc.*;
+
+/**
+ * Represents a documentation tag, e.g. @since, @author, @version.
+ * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since")
+ * and tag text (e.g. "1.2"). TagImpls with structure or which require
+ * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl,
+ * and ThrowsTagImpl
+ *
+ * <p><b>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.</b>
+ *
+ * @author Robert Field
+ * @author Atul M Dambalkar
+ * @author Neal M Gafter
+ * @see SeeTagImpl
+ * @see ParamTagImpl
+ * @see ThrowsTagImpl
+ * @see Doc#tags()
+ *
+ */
+class TagImpl implements Tag {
+
+ protected final String text;
+ protected final String name;
+ protected final DocImpl holder;
+
+ /**
+ * Cached first sentence.
+ */
+ private Tag[] firstSentence;
+
+ /**
+ * Cached inline tags.
+ */
+ private Tag[] inlineTags;
+
+ /**
+ * Constructor
+ */
+ TagImpl(DocImpl holder, String name, String text) {
+ this.holder = holder;
+ this.name = name;
+ this.text = text;
+ }
+
+ /**
+ * Return the name of this tag.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Return the containing {@link Doc} of this Tag element.
+ */
+ public Doc holder() {
+ return holder;
+ }
+
+ /**
+ * Return the kind of this tag.
+ */
+ public String kind() {
+ return name;
+ }
+
+ /**
+ * Return the text of this tag, that is, portion beyond tag name.
+ */
+ public String text() {
+ return text;
+ }
+
+ DocEnv docenv() {
+ return holder.env;
+ }
+
+ /**
+ * for use by subclasses which have two part tag text.
+ */
+ String[] divideAtWhite() {
+ String[] sa = new String[2];
+ int len = text.length();
+ // if no white space found
+ sa[0] = text;
+ sa[1] = "";
+ for (int inx = 0; inx < len; ++inx) {
+ char ch = text.charAt(inx);
+ if (Character.isWhitespace(ch)) {
+ sa[0] = text.substring(0, inx);
+ for (; inx < len; ++inx) {
+ ch = text.charAt(inx);
+ if (!Character.isWhitespace(ch)) {
+ sa[1] = text.substring(inx, len);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return sa;
+ }
+
+ /**
+ * convert this object to a string.
+ */
+ public String toString() {
+ return name + ":" + text;
+ }
+
+ /**
+ * For documentation comment with embedded @link tags, return the array of
+ * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
+ * Within a comment string "This is an example of inline tags for a
+ * documentation comment {@link Doc {@link Doc commentlabel}}",
+ * where inside the inner braces, the first "Doc" carries exctly the same
+ * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html
+ * Link, will return an array of TagImpl(s) with first element as TagImpl with
+ * comment text "This is an example of inline tags for a documentation
+ * comment" and second element as SeeTagImpl with referenced class as "Doc"
+ * and the label for the Html Link as "commentlabel".
+ *
+ * @return TagImpl[] Array of tags with inline SeeTagImpls.
+ * @see ParamTagImpl
+ * @see ThrowsTagImpl
+ */
+ public Tag[] inlineTags() {
+ if (inlineTags == null) {
+ inlineTags = Comment.getInlineTags(holder, text);
+ }
+ return inlineTags;
+ }
+
+ /**
+ * Return array of tags for the first sentence in the doc comment text.
+ */
+ public Tag[] firstSentenceTags() {
+ if (firstSentence == null) {
+ //Parse all sentences first to avoid duplicate warnings.
+ inlineTags();
+ try {
+ docenv().setSilent(true);
+ firstSentence = Comment.firstSentenceTags(holder, text);
+ } finally {
+ docenv().setSilent(false);
+ }
+ }
+ return firstSentence;
+ }
+
+ /**
+ * Return the doc item to which this tag is attached.
+ * @return the doc item to which this tag is attached.
+ */
+ public SourcePosition position() {
+ return holder.position();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ThrowsTagImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 1997, 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.main;
+
+import com.sun.javadoc.*;
+
+/**
+ * Represents a @throws or @exception documentation tag.
+ * Parses and holds the exception name and exception comment.
+ * The exception name my be the name of a type variable.
+ * Note: @exception is a backwards compatible synonymy for @throws.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Robert Field
+ * @author Atul M Dambalkar
+ * @see ExecutableMemberDocImpl#throwsTags()
+ *
+ */
+class ThrowsTagImpl extends TagImpl implements ThrowsTag {
+
+ private final String exceptionName;
+ private final String exceptionComment;
+
+ /**
+ * Cached inline tags.
+ */
+ private Tag[] inlineTags;
+
+ ThrowsTagImpl(DocImpl holder, String name, String text) {
+ super(holder, name, text);
+ String[] sa = divideAtWhite();
+ exceptionName = sa[0];
+ exceptionComment = sa[1];
+ }
+
+ /**
+ * Return the exception name.
+ */
+ public String exceptionName() {
+ return exceptionName;
+ }
+
+ /**
+ * Return the exception comment.
+ */
+ public String exceptionComment() {
+ return exceptionComment;
+ }
+
+ /**
+ * Return the exception as a ClassDocImpl.
+ */
+ public ClassDoc exception() {
+ ClassDocImpl exceptionClass;
+ if (!(holder instanceof ExecutableMemberDoc)) {
+ exceptionClass = null;
+ } else {
+ ExecutableMemberDocImpl emd = (ExecutableMemberDocImpl)holder;
+ ClassDocImpl con = (ClassDocImpl)emd.containingClass();
+ exceptionClass = (ClassDocImpl)con.findClass(exceptionName);
+ }
+ return exceptionClass;
+ }
+
+ /**
+ * Return the type that represents the exception.
+ * This may be a <code>ClassDoc</code> or a <code>TypeVariable</code>.
+ */
+ public Type exceptionType() {
+ //###(gj) TypeVariable not yet supported.
+ return exception();
+ }
+
+
+ /**
+ * Return the kind of this tag. Always "@throws" for instances
+ * of ThrowsTagImpl.
+ */
+ @Override
+ public String kind() {
+ return "@throws";
+ }
+
+ /**
+ * For the exception comment with embedded @link tags return the array of
+ * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
+ *
+ * @return TagImpl[] Array of tags with inline SeeTagImpls.
+ * @see TagImpl#inlineTags()
+ * @see ParamTagImpl#inlineTags()
+ */
+ @Override
+ public Tag[] inlineTags() {
+ if (inlineTags == null) {
+ inlineTags = Comment.getInlineTags(holder, exceptionComment());
+ }
+ return inlineTags;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ToolOption.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,392 @@
+/*
+ * Copyright (c) 2012, 2016, 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.main;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.main.Option;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Options;
+
+
+/**
+ * javadoc tool options.
+ *
+ * <p><b>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.</b>
+ */
+public enum ToolOption {
+ // ----- options for underlying compiler -----
+
+ BOOTCLASSPATH("-bootclasspath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
+ }
+ },
+
+ CLASSPATH("-classpath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.CLASSPATH, arg);
+ }
+ },
+
+ CP("-cp", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.CP, arg);
+ }
+ },
+
+ EXTDIRS("-extdirs", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.EXTDIRS, arg);
+ }
+ },
+
+ SOURCEPATH("-sourcepath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.SOURCEPATH, arg);
+ }
+ },
+
+ SYSCLASSPATH("-sysclasspath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.BOOTCLASSPATH, arg);
+ }
+ },
+
+ MODULESOURCEPATH("-modulesourcepath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.MODULESOURCEPATH, arg);
+ }
+ },
+
+ UPGRADEMODULEPATH("-upgrademodulepath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.UPGRADEMODULEPATH, arg);
+ }
+ },
+
+ SYSTEM("-system", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.SYSTEM, arg);
+ }
+ },
+
+ MODULEPATH("-modulepath", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setFileManagerOpt(Option.MODULEPATH, arg);
+ }
+ },
+
+ ADDMODS("-addmods", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ LIMITMODS("-limitmods", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ ENCODING("-encoding", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.encoding = arg;
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ RELEASE("-release", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ SOURCE("-source", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ XMAXERRS("-Xmaxerrs", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ XMAXWARNS("-Xmaxwarns", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.setCompilerOpt(opt, arg);
+ }
+ },
+
+ // ----- doclet options -----
+
+ DOCLET("-doclet", true), // handled in setDocletInvoker
+
+ DOCLETPATH("-docletpath", true), // handled in setDocletInvoker
+
+ // ----- selection options -----
+
+ SUBPACKAGES("-subpackages", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.addToList(helper.subPackages, arg);
+ }
+ },
+
+ EXCLUDE("-exclude", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.addToList(helper.excludedPackages, arg);
+ }
+ },
+
+ // ----- filtering options -----
+
+ PACKAGE("-package") {
+ @Override
+ public void process(Helper helper) {
+ helper.setFilter(
+ Flags.PUBLIC | Flags.PROTECTED | ModifierFilter.PACKAGE);
+ }
+ },
+
+ PRIVATE("-private") {
+ @Override
+ public void process(Helper helper) {
+ helper.setFilter(ModifierFilter.ALL_ACCESS);
+ }
+ },
+
+ PROTECTED("-protected") {
+ @Override
+ public void process(Helper helper) {
+ helper.setFilter(Flags.PUBLIC | Flags.PROTECTED);
+ }
+ },
+
+ PUBLIC("-public") {
+ @Override
+ public void process(Helper helper) {
+ helper.setFilter(Flags.PUBLIC);
+ }
+ },
+
+ // ----- output control options -----
+
+ PROMPT("-prompt") {
+ @Override
+ public void process(Helper helper) {
+ helper.compOpts.put("-prompt", "-prompt");
+ helper.promptOnError = true;
+ }
+ },
+
+ QUIET("-quiet") {
+ @Override
+ public void process(Helper helper) {
+ helper.quiet = true;
+ }
+ },
+
+ VERBOSE("-verbose") {
+ @Override
+ public void process(Helper helper) {
+ helper.compOpts.put("-verbose", "");
+ }
+ },
+
+ XWERROR("-Xwerror") {
+ @Override
+ public void process(Helper helper) {
+ helper.rejectWarnings = true;
+
+ }
+ },
+
+ // ----- other options -----
+
+ BREAKITERATOR("-breakiterator") {
+ @Override
+ public void process(Helper helper) {
+ helper.breakiterator = true;
+ }
+ },
+
+ LOCALE("-locale", true) {
+ @Override
+ public void process(Helper helper, String arg) {
+ helper.docLocale = arg;
+ }
+ },
+
+ OVERVIEW("-overview", true),
+
+ XCLASSES("-Xclasses") {
+ @Override
+ public void process(Helper helper) {
+ helper.docClasses = true;
+
+ }
+ },
+
+ // ----- help options -----
+
+ HELP("-help") {
+ @Override
+ public void process(Helper helper) {
+ helper.usage();
+ }
+ },
+
+ X("-X") {
+ @Override
+ public void process(Helper helper) {
+ helper.Xusage();
+ }
+ };
+
+ public final String opt;
+ public final boolean hasArg;
+
+ ToolOption(String opt) {
+ this(opt, false);
+ }
+
+ ToolOption(String opt, boolean hasArg) {
+ this.opt = opt;
+ this.hasArg = hasArg;
+ }
+
+ void process(Helper helper, String arg) { }
+
+ void process(Helper helper) { }
+
+ static ToolOption get(String name) {
+ for (ToolOption o: values()) {
+ if (name.equals(o.opt))
+ return o;
+ }
+ return null;
+ }
+
+ static abstract class Helper {
+ /** List of decoded options. */
+ final ListBuffer<String[]> options = new ListBuffer<>();
+
+ /** Selected packages, from -subpackages. */
+ final ListBuffer<String> subPackages = new ListBuffer<>();
+
+ /** Excluded packages, from -exclude. */
+ final ListBuffer<String> excludedPackages = new ListBuffer<>();
+
+ // File manager options
+ final Map<Option, String> fileManagerOpts = new LinkedHashMap<>();
+
+ /** javac options, set by various options. */
+ Options compOpts; // = Options.instance(context)
+
+ /* Encoding for javac, and files written? set by -encoding. */
+ String encoding = null;
+
+ /** Set by -breakiterator. */
+ boolean breakiterator = false;
+
+ /** Set by -quiet. */
+ boolean quiet = false;
+
+ /** Set by -Xclasses. */
+ boolean docClasses = false;
+
+ /** Set by -Xwerror. */
+ boolean rejectWarnings = false;
+
+ /** Set by -prompt. */
+ boolean promptOnError;
+
+ /** Set by -locale. */
+ String docLocale = "";
+
+ /** Set by -public, private, -protected, -package. */
+ ModifierFilter showAccess = null;
+
+ abstract void usage();
+ abstract void Xusage();
+
+ abstract void usageError(String msg, Object... args);
+
+ void addToList(ListBuffer<String> list, String str){
+ StringTokenizer st = new StringTokenizer(str, ":");
+ String current;
+ while(st.hasMoreTokens()){
+ current = st.nextToken();
+ list.append(current);
+ }
+ }
+
+ void setFilter(long filterBits) {
+ if (showAccess != null) {
+ usageError("main.incompatible.access.flags");
+ }
+ showAccess = new ModifierFilter(filterBits);
+ }
+
+ void setCompilerOpt(String opt, String arg) {
+ if (compOpts.get(opt) != null) {
+ usageError("main.option.already.seen", opt);
+ }
+ compOpts.put(opt, arg);
+ }
+
+ void setFileManagerOpt(Option opt, String arg) {
+ fileManagerOpts.put(opt, arg);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/TypeMaker.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,350 @@
+/*
+ * 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.main;
+
+import com.sun.javadoc.*;
+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.Type;
+import com.sun.tools.javac.code.Type.ArrayType;
+import com.sun.tools.javac.code.Type.ClassType;
+import com.sun.tools.javac.code.Type.TypeVar;
+import com.sun.tools.javac.util.List;
+import static com.sun.tools.javac.code.TypeTag.ARRAY;
+
+/**
+ * <p><b>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.</b>
+ */
+public class TypeMaker {
+
+ public static com.sun.javadoc.Type getType(DocEnv env, Type t) {
+ return getType(env, t, true);
+ }
+
+ /**
+ * @param errToClassDoc if true, ERROR type results in a ClassDoc;
+ * false preserves legacy behavior
+ */
+ public static com.sun.javadoc.Type getType(DocEnv env, Type t,
+ boolean errorToClassDoc) {
+ return getType(env, t, errorToClassDoc, true);
+ }
+
+ public static com.sun.javadoc.Type getType(DocEnv env, Type t,
+ boolean errToClassDoc, boolean considerAnnotations) {
+ try {
+ return getTypeImpl(env, t, errToClassDoc, considerAnnotations);
+ } catch (CompletionFailure cf) {
+ /* 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 getType(env, t, errToClassDoc, considerAnnotations);
+ }
+ }
+
+ @SuppressWarnings("fallthrough")
+ private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t,
+ boolean errToClassDoc, boolean considerAnnotations) {
+ if (env.legacyDoclet) {
+ t = env.types.erasure(t);
+ }
+
+ if (considerAnnotations && t.isAnnotated()) {
+ return new AnnotatedTypeImpl(env, t);
+ }
+
+ switch (t.getTag()) {
+ case CLASS:
+ if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
+ return env.getParameterizedType((ClassType)t);
+ } else {
+ return env.getClassDoc((ClassSymbol)t.tsym);
+ }
+ case WILDCARD:
+ Type.WildcardType a = (Type.WildcardType)t;
+ return new WildcardTypeImpl(env, a);
+ case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
+ case ARRAY: return new ArrayTypeImpl(env, t);
+ case BYTE: return PrimitiveType.byteType;
+ case CHAR: return PrimitiveType.charType;
+ case SHORT: return PrimitiveType.shortType;
+ case INT: return PrimitiveType.intType;
+ case LONG: return PrimitiveType.longType;
+ case FLOAT: return PrimitiveType.floatType;
+ case DOUBLE: return PrimitiveType.doubleType;
+ case BOOLEAN: return PrimitiveType.booleanType;
+ case VOID: return PrimitiveType.voidType;
+ case ERROR:
+ if (errToClassDoc)
+ return env.getClassDoc((ClassSymbol)t.tsym);
+ // FALLTHRU
+ default:
+ return new PrimitiveType(t.tsym.getQualifiedName().toString());
+ }
+ }
+
+ /**
+ * Convert a list of javac types into an array of javadoc types.
+ */
+ public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts) {
+ return getTypes(env, ts, new com.sun.javadoc.Type[ts.length()]);
+ }
+
+ /**
+ * Like the above version, but use and return the array given.
+ */
+ public static com.sun.javadoc.Type[] getTypes(DocEnv env, List<Type> ts,
+ com.sun.javadoc.Type res[]) {
+ int i = 0;
+ for (Type t : ts) {
+ res[i++] = getType(env, t);
+ }
+ return res;
+ }
+
+ public static String getTypeName(Type t, boolean full) {
+ switch (t.getTag()) {
+ case ARRAY:
+ StringBuilder s = new StringBuilder();
+ while (t.hasTag(ARRAY)) {
+ s.append("[]");
+ t = ((ArrayType)t).elemtype;
+ }
+ s.insert(0, getTypeName(t, full));
+ return s.toString();
+ case CLASS:
+ return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
+ default:
+ return t.tsym.getQualifiedName().toString();
+ }
+ }
+
+ /**
+ * Return the string representation of a type use. Bounds of type
+ * variables are not included; bounds of wildcard types are.
+ * Class names are qualified if "full" is true.
+ */
+ static String getTypeString(DocEnv env, Type t, boolean full) {
+ // TODO: should annotations be included here?
+ switch (t.getTag()) {
+ case ARRAY:
+ StringBuilder s = new StringBuilder();
+ while (t.hasTag(ARRAY)) {
+ s.append("[]");
+ t = env.types.elemtype(t);
+ }
+ s.insert(0, getTypeString(env, t, full));
+ return s.toString();
+ case CLASS:
+ return ParameterizedTypeImpl.
+ parameterizedTypeToString(env, (ClassType)t, full);
+ case WILDCARD:
+ Type.WildcardType a = (Type.WildcardType)t;
+ return WildcardTypeImpl.wildcardTypeToString(env, a, full);
+ default:
+ return t.tsym.getQualifiedName().toString();
+ }
+ }
+
+ /**
+ * Return the formal type parameters of a class or method as an
+ * angle-bracketed string. Each parameter is a type variable with
+ * optional bounds. Class names are qualified if "full" is true.
+ * Return "" if there are no type parameters or we're hiding generics.
+ */
+ static String typeParametersString(DocEnv env, Symbol sym, boolean full) {
+ if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
+ return "";
+ }
+ StringBuilder s = new StringBuilder();
+ for (Type t : sym.type.getTypeArguments()) {
+ s.append(s.length() == 0 ? "<" : ", ");
+ s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
+ }
+ s.append(">");
+ return s.toString();
+ }
+
+ /**
+ * Return the actual type arguments of a parameterized type as an
+ * angle-bracketed string. Class name are qualified if "full" is true.
+ * Return "" if there are no type arguments or we're hiding generics.
+ */
+ static String typeArgumentsString(DocEnv env, ClassType cl, boolean full) {
+ if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
+ return "";
+ }
+ StringBuilder s = new StringBuilder();
+ for (Type t : cl.getTypeArguments()) {
+ s.append(s.length() == 0 ? "<" : ", ");
+ s.append(getTypeString(env, t, full));
+ }
+ s.append(">");
+ return s.toString();
+ }
+
+
+ private static class ArrayTypeImpl implements com.sun.javadoc.Type {
+
+ Type arrayType;
+
+ DocEnv env;
+
+ ArrayTypeImpl(DocEnv env, Type arrayType) {
+ this.env = env;
+ this.arrayType = arrayType;
+ }
+
+ private com.sun.javadoc.Type skipArraysCache = null;
+
+ public com.sun.javadoc.Type getElementType() {
+ return TypeMaker.getType(env, env.types.elemtype(arrayType));
+ }
+
+ private com.sun.javadoc.Type skipArrays() {
+ if (skipArraysCache == null) {
+ Type t;
+ for (t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) { }
+ skipArraysCache = TypeMaker.getType(env, t);
+ }
+ return skipArraysCache;
+ }
+
+ /**
+ * Return the type's dimension information, as a string.
+ * <p>
+ * For example, a two dimensional array of String returns '[][]'.
+ */
+ public String dimension() {
+ StringBuilder dimension = new StringBuilder();
+ for (Type t = arrayType; t.hasTag(ARRAY); t = env.types.elemtype(t)) {
+ dimension.append("[]");
+ }
+ return dimension.toString();
+ }
+
+ /**
+ * Return unqualified name of type excluding any dimension information.
+ * <p>
+ * For example, a two dimensional array of String returns 'String'.
+ */
+ public String typeName() {
+ return skipArrays().typeName();
+ }
+
+ /**
+ * Return qualified name of type excluding any dimension information.
+ *<p>
+ * For example, a two dimensional array of String
+ * returns 'java.lang.String'.
+ */
+ public String qualifiedTypeName() {
+ return skipArrays().qualifiedTypeName();
+ }
+
+ /**
+ * Return the simple name of this type excluding any dimension information.
+ */
+ public String simpleTypeName() {
+ return skipArrays().simpleTypeName();
+ }
+
+ /**
+ * Return this type as a class. Array dimensions are ignored.
+ *
+ * @return a ClassDocImpl if the type is a Class.
+ * Return null if it is a primitive type..
+ */
+ public ClassDoc asClassDoc() {
+ return skipArrays().asClassDoc();
+ }
+
+ /**
+ * Return this type as a <code>ParameterizedType</code> if it
+ * represents a parameterized type. Array dimensions are ignored.
+ */
+ public ParameterizedType asParameterizedType() {
+ return skipArrays().asParameterizedType();
+ }
+
+ /**
+ * Return this type as a <code>TypeVariable</code> if it represents
+ * a type variable. Array dimensions are ignored.
+ */
+ public TypeVariable asTypeVariable() {
+ return skipArrays().asTypeVariable();
+ }
+
+ /**
+ * Return null, as there are no arrays of wildcard types.
+ */
+ public WildcardType asWildcardType() {
+ return null;
+ }
+
+ /**
+ * Return null, as there are no annotations of the type
+ */
+ public AnnotatedType asAnnotatedType() {
+ return null;
+ }
+
+ /**
+ * Return this type as an <code>AnnotationTypeDoc</code> if it
+ * represents an annotation type. Array dimensions are ignored.
+ */
+ public AnnotationTypeDoc asAnnotationTypeDoc() {
+ return skipArrays().asAnnotationTypeDoc();
+ }
+
+ /**
+ * Return true if this is an array of a primitive type.
+ */
+ public boolean isPrimitive() {
+ return skipArrays().isPrimitive();
+ }
+
+ /**
+ * Return a string representation of the type.
+ *
+ * Return name of type including any dimension information.
+ * <p>
+ * For example, a two dimensional array of String returns
+ * <code>String[][]</code>.
+ *
+ * @return name of type including any dimension information.
+ */
+ @Override
+ public String toString() {
+ return qualifiedTypeName() + dimension();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/TypeVariableImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,152 @@
+/*
+ * 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Attribute;
+import com.sun.tools.javac.code.Attribute.TypeCompound;
+import com.sun.tools.javac.code.Kinds;
+import com.sun.tools.javac.code.Kinds.KindSelector;
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Symbol.MethodSymbol;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.code.Type.TypeVar;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.Name;
+import com.sun.tools.javac.util.Names;
+
+/**
+ * Implementation of <code>TypeVariable</code>, which
+ * represents a type variable.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Scott Seligman
+ * @since 1.5
+ */
+public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
+
+ TypeVariableImpl(DocEnv env, TypeVar type) {
+ super(env, type);
+ }
+
+ /**
+ * Return the bounds of this type variable.
+ */
+ public com.sun.javadoc.Type[] bounds() {
+ return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
+ }
+
+ /**
+ * Return the class, interface, method, or constructor within
+ * which this type variable is declared.
+ */
+ public ProgramElementDoc owner() {
+ Symbol osym = type.tsym.owner;
+ if (osym.kind.matches(KindSelector.TYP)) {
+ return env.getClassDoc((ClassSymbol)osym);
+ }
+ Names names = osym.name.table.names;
+ if (osym.name == names.init) {
+ return env.getConstructorDoc((MethodSymbol)osym);
+ } else {
+ return env.getMethodDoc((MethodSymbol)osym);
+ }
+ }
+
+ /**
+ * Return the ClassDoc of the erasure of this type variable.
+ */
+ @Override
+ public ClassDoc asClassDoc() {
+ return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
+ }
+
+ @Override
+ public TypeVariable asTypeVariable() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return typeVarToString(env, (TypeVar)type, true);
+ }
+
+
+ /**
+ * Return the string form of a type variable along with any
+ * "extends" clause. Class names are qualified if "full" is true.
+ */
+ static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
+ StringBuilder s = new StringBuilder(v.toString());
+ List<Type> bounds = getBounds(v, env);
+ if (bounds.nonEmpty()) {
+ boolean first = true;
+ for (Type b : bounds) {
+ s.append(first ? " extends " : " & ");
+ s.append(TypeMaker.getTypeString(env, b, full));
+ first = false;
+ }
+ }
+ return s.toString();
+ }
+
+ /**
+ * Get the bounds of a type variable as listed in the "extends" clause.
+ */
+ private static List<Type> getBounds(TypeVar v, DocEnv env) {
+ final Type upperBound = v.getUpperBound();
+ Name boundname = upperBound.tsym.getQualifiedName();
+ if (boundname == boundname.table.names.java_lang_Object
+ && !upperBound.isAnnotated()) {
+ return List.nil();
+ } else {
+ return env.types.getBounds(v);
+ }
+ }
+
+ /**
+ * Get the annotations of this program element.
+ * Return an empty array if there are none.
+ */
+ public AnnotationDesc[] annotations() {
+ if (!type.isAnnotated()) {
+ return new AnnotationDesc[0];
+ }
+ List<? extends TypeCompound> tas = type.getAnnotationMirrors();
+ AnnotationDesc res[] = new AnnotationDesc[tas.length()];
+ int i = 0;
+ for (Attribute.Compound a : tas) {
+ res[i++] = new AnnotationDescImpl(env, a);
+ }
+ return res;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/WildcardTypeImpl.java Mon May 09 16:52:15 2016 -0700
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2003, 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.main;
+
+import com.sun.javadoc.*;
+
+import com.sun.tools.javac.code.Symbol.ClassSymbol;
+import com.sun.tools.javac.code.Type;
+import com.sun.tools.javac.util.List;
+
+
+/**
+ * Implementation of <code>WildcardType</code>, which
+ * represents a wildcard type.
+ *
+ * <p><b>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.</b>
+ *
+ * @author Scott Seligman
+ * @since 1.5
+ */
+public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
+
+ WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
+ super(env, type);
+ }
+
+ /**
+ * Return the upper bounds of this wildcard type argument
+ * as given by the <i>extends</i> clause.
+ * Return an empty array if no such bounds are explicitly given.
+ */
+ public com.sun.javadoc.Type[] extendsBounds() {
+ return TypeMaker.getTypes(env, getExtendsBounds((Type.WildcardType)type));
+ }
+
+ /**
+ * Return the lower bounds of this wildcard type argument
+ * as given by the <i>super</i> clause.
+ * Return an empty array if no such bounds are explicitly given.
+ */
+ public com.sun.javadoc.Type[] superBounds() {
+ return TypeMaker.getTypes(env, getSuperBounds((Type.WildcardType)type));
+ }
+
+ /**
+ * Return the ClassDoc of the erasure of this wildcard type.
+ */
+ @Override
+ public ClassDoc asClassDoc() {
+ return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
+ }
+
+ @Override
+ public WildcardType asWildcardType() {
+ return this;
+ }
+
+ @Override
+ public String typeName() { return "?"; }
+ @Override
+ public String qualifiedTypeName() { return "?"; }
+ @Override
+ public String simpleTypeName() { return "?"; }
+
+ @Override
+ public String toString() {
+ return wildcardTypeToString(env, (Type.WildcardType)type, true);
+ }
+
+
+ /**
+ * Return the string form of a wildcard type ("?") along with any
+ * "extends" or "super" clause. Delimiting brackets are not
+ * included. Class names are qualified if "full" is true.
+ */
+ static String wildcardTypeToString(DocEnv env,
+ Type.WildcardType wildThing, boolean full) {
+ if (env.legacyDoclet) {
+ return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
+ }
+ StringBuilder s = new StringBuilder("?");
+ List<Type> bounds = getExtendsBounds(wildThing);
+ if (bounds.nonEmpty()) {
+ s.append(" extends ");
+ } else {
+ bounds = getSuperBounds(wildThing);
+ if (bounds.nonEmpty()) {
+ s.append(" super ");
+ }
+ }
+ boolean first = true; // currently only one bound is allowed
+ for (Type b : bounds) {
+ if (!first) {
+ s.append(" & ");
+ }
+ s.append(TypeMaker.getTypeString(env, b, full));
+ first = false;
+ }
+ return s.toString();
+ }
+
+ private static List<Type> getExtendsBounds(Type.WildcardType wild) {
+ return wild.isSuperBound()
+ ? List.<Type>nil()
+ : List.of(wild.type);
+ }
+
+ private static List<Type> getSuperBounds(Type.WildcardType wild) {
+ return wild.isExtendsBound()
+ ? List.<Type>nil()
+ : List.of(wild.type);
+ }
+}
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java Wed Jul 05 21:41:01 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java Mon May 09 16:52:15 2016 -0700
@@ -283,8 +283,8 @@
}
} else {
if (this.apiMode) {
- com.sun.tools.javadoc.Start ostart
- = new com.sun.tools.javadoc.Start(context);
+ com.sun.tools.javadoc.main.Start ostart
+ = new com.sun.tools.javadoc.main.Start(context);
return ostart.begin(docletClass, options, fileObjects);
}
warn("main.legacy_api");