8004834: Add doclint support into javadoc

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2013-01-10 19:38:57 -08:00
parent 80a7fb0bb4
commit 7518dede81
25 changed files with 401 additions and 54 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,8 +33,10 @@ import javax.tools.JavaFileManager;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.*;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
import com.sun.tools.doclint.DocLint;
import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context;
import com.sun.tools.javadoc.RootDocImpl;
/** /**
* Configure the output based on the command line options. * Configure the output based on the command line options.
@ -171,6 +173,11 @@ public class ConfigurationImpl extends Configuration {
*/ */
public boolean createoverview = false; public boolean createoverview = false;
/**
* Collected set of doclint options
*/
public Set<String> doclintOpts = new LinkedHashSet<String>();
/** /**
* Unique Resource Handler for this package. * Unique Resource Handler for this package.
*/ */
@ -255,6 +262,10 @@ public class ConfigurationImpl extends Configuration {
nooverview = true; nooverview = true;
} else if (opt.equals("-overview")) { } else if (opt.equals("-overview")) {
overview = true; overview = true;
} else if (opt.equals("-xdoclint")) {
doclintOpts.add(null);
} else if (opt.startsWith("-xdoclint:")) {
doclintOpts.add(opt.substring(opt.indexOf(":") + 1));
} }
} }
if (root.specifiedClasses().length > 0) { if (root.specifiedClasses().length > 0) {
@ -270,6 +281,10 @@ public class ConfigurationImpl extends Configuration {
} }
setCreateOverview(); setCreateOverview();
setTopFile(root); setTopFile(root);
if (root instanceof RootDocImpl) {
((RootDocImpl) root).initDocLint(doclintOpts);
}
} }
/** /**
@ -303,7 +318,9 @@ public class ConfigurationImpl extends Configuration {
option.equals("-serialwarn") || option.equals("-serialwarn") ||
option.equals("-use") || option.equals("-use") ||
option.equals("-nonavbar") || option.equals("-nonavbar") ||
option.equals("-nooverview")) { option.equals("-nooverview") ||
option.equals("-xdoclint") ||
option.startsWith("-xdoclint:")) {
return 1; return 1;
} else if (option.equals("-help")) { } else if (option.equals("-help")) {
System.out.println(getText("doclet.usage")); System.out.println(getText("doclet.usage"));
@ -410,6 +427,16 @@ public class ConfigurationImpl extends Configuration {
return false; return false;
} }
noindex = true; noindex = true;
} else if (opt.startsWith("-xdoclint:")) {
if (opt.contains("/")) {
reporter.printError(getText("doclet.Option_doclint_no_qualifiers"));
return false;
}
if (!DocLint.isValidOption(
opt.replace("-xdoclint:", DocLint.XMSGS_CUSTOM_PREFIX))) {
reporter.printError(getText("doclet.Option_doclint_invalid_arg"));
return false;
}
} }
} }
return true; return true;
@ -506,8 +533,8 @@ public class ConfigurationImpl extends Configuration {
*/ */
@Override @Override
public Locale getLocale() { public Locale getLocale() {
if (root instanceof com.sun.tools.javadoc.RootDocImpl) if (root instanceof RootDocImpl)
return ((com.sun.tools.javadoc.RootDocImpl)root).getLocale(); return ((RootDocImpl)root).getLocale();
else else
return Locale.getDefault(); return Locale.getDefault();
} }
@ -518,8 +545,8 @@ public class ConfigurationImpl extends Configuration {
@Override @Override
public JavaFileManager getFileManager() { public JavaFileManager getFileManager() {
if (fileManager == null) { if (fileManager == null) {
if (root instanceof com.sun.tools.javadoc.RootDocImpl) if (root instanceof RootDocImpl)
fileManager = ((com.sun.tools.javadoc.RootDocImpl)root).getFileManager(); fileManager = ((RootDocImpl) root).getFileManager();
else else
fileManager = new JavacFileManager(new Context(), false, null); fileManager = new JavacFileManager(new Context(), false, null);
} }
@ -527,4 +554,12 @@ public class ConfigurationImpl extends Configuration {
} }
private JavaFileManager fileManager; private JavaFileManager fileManager;
@Override
public boolean showMessage(SourcePosition pos, String key) {
if (root instanceof RootDocImpl) {
return pos == null || ((RootDocImpl) root).showTagMessages();
}
return true;
}
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -781,4 +781,6 @@ public abstract class Configuration {
sourcetab = n; sourcetab = n;
tabSpaces = String.format("%" + n + "s", ""); tabSpaces = String.format("%" + n + "s", "");
} }
public abstract boolean showMessage(SourcePosition pos, String key);
} }

View file

@ -11,6 +11,8 @@ doclet.Class_0_implements_serializable=Class {0} implements Serializable
doclet.Class_0_extends_implements_serializable=Class {0} extends {1} implements Serializable doclet.Class_0_extends_implements_serializable=Class {0} extends {1} implements Serializable
doclet.Option_conflict=Option {0} conflicts with {1} doclet.Option_conflict=Option {0} conflicts with {1}
doclet.Option_reuse=Option reused: {0} doclet.Option_reuse=Option reused: {0}
doclet.Option_doclint_no_qualifiers=Access qualifiers not permitted for -Xdoclint arguments
doclet.Option_doclint_invalid_arg=Invalid argument for -Xdoclint option
doclet.exception_encountered= {0} encountered \n\ doclet.exception_encountered= {0} encountered \n\
\twhile attempting to create file: {1} \twhile attempting to create file: {1}
doclet.perform_copy_exception_encountered= {0} encountered while \n\ doclet.perform_copy_exception_encountered= {0} encountered while \n\

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -60,9 +60,9 @@ public class MessageRetriever {
private ResourceBundle messageRB; private ResourceBundle messageRB;
/** /**
* Initilize the ResourceBundle with the given resource. * Initialize the ResourceBundle with the given resource.
* *
* @param rb the esource bundle to read. * @param rb the resource bundle to read.
*/ */
public MessageRetriever(ResourceBundle rb) { public MessageRetriever(ResourceBundle rb) {
this.configuration = null; this.configuration = null;
@ -71,7 +71,7 @@ public class MessageRetriever {
} }
/** /**
* Initilize the ResourceBundle with the given resource. * Initialize the ResourceBundle with the given resource.
* *
* @param configuration the configuration * @param configuration the configuration
* @param resourcelocation Resource. * @param resourcelocation Resource.
@ -189,6 +189,7 @@ public class MessageRetriever {
* @param args arguments to be replaced in the message. * @param args arguments to be replaced in the message.
*/ */
public void warning(SourcePosition pos, String key, Object... args) { public void warning(SourcePosition pos, String key, Object... args) {
if (configuration.showMessage(pos, key))
printWarning(pos, getText(key, args)); printWarning(pos, getText(key, args));
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -131,7 +131,11 @@ public class Enter extends JCTree.Visitor {
predefClassDef = make.ClassDef( predefClassDef = make.ClassDef(
make.Modifiers(PUBLIC), make.Modifiers(PUBLIC),
syms.predefClass.name, null, null, null, null); syms.predefClass.name,
List.<JCTypeParameter>nil(),
null,
List.<JCExpression>nil(),
List.<JCTree>nil());
predefClassDef.sym = syms.predefClass; predefClassDef.sym = syms.predefClass;
todo = Todo.instance(context); todo = Todo.instance(context);
fileManager = context.get(JavaFileManager.class); fileManager = context.get(JavaFileManager.class);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,8 +31,10 @@ import java.util.*;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TreePath; import com.sun.source.util.TreePath;
import com.sun.tools.javac.api.JavacTrees; 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.*;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
@ -105,6 +107,7 @@ public class DocEnv {
Types types; Types types;
JavaFileManager fileManager; JavaFileManager fileManager;
Context context; Context context;
DocLint doclint;
WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>(); WeakHashMap<JCTree, TreePath> treePaths = new WeakHashMap<JCTree, TreePath>();
@ -400,6 +403,9 @@ public class DocEnv {
public void warning(DocImpl doc, String key, String a1) { public void warning(DocImpl doc, String key, String a1) {
if (silent) if (silent)
return; 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); messager.warning(doc==null ? null : doc.position(), key, a1);
} }
@ -732,9 +738,15 @@ public class DocEnv {
return p; return p;
} }
TreePath getTreePath(JCCompilationUnit toplevel, JCTree tree) { TreePath getTreePath(JCCompilationUnit toplevel, JCClassDecl tree) {
// don't bother to cache paths for classes and members TreePath p = treePaths.get(tree);
return new TreePath(getTreePath(toplevel), 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);
} }
/** /**
@ -781,4 +793,25 @@ public class DocEnv {
result |= Modifier.VOLATILE; result |= Modifier.VOLATILE;
return result; return result;
} }
void initDoclint(Collection<String> opts) {
ArrayList<String> doclintOpts = new ArrayList<String>();
for (String opt: opts) {
doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
}
if (doclintOpts.size() == 1
&& doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
return;
}
JavacTask t = BasicJavacTask.instance(context);
doclint = new DocLint();
doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
boolean showTagMessages() {
return (doclint == null);
}
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -126,7 +126,13 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
*/ */
Comment comment() { Comment comment() {
if (comment == null) { if (comment == null) {
comment = new Comment(this, documentation()); String d = documentation();
if (env.doclint != null
&& treePath != null
&& d.equals(getCommentText(treePath))) {
env.doclint.scan(treePath);
}
comment = new Comment(this, d);
} }
return comment; return comment;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -72,7 +72,7 @@ public class JavadocMemberEnter extends MemberEnter {
super.visitMethodDef(tree); super.visitMethodDef(tree);
MethodSymbol meth = tree.sym; MethodSymbol meth = tree.sym;
if (meth == null || meth.kind != Kinds.MTH) return; if (meth == null || meth.kind != Kinds.MTH) return;
TreePath treePath = docenv.getTreePath(env.toplevel, tree); TreePath treePath = docenv.getTreePath(env.toplevel, env.enclClass, tree);
if (meth.isConstructor()) if (meth.isConstructor())
docenv.makeConstructorDoc(meth, treePath); docenv.makeConstructorDoc(meth, treePath);
else if (isAnnotationTypeElement(meth)) else if (isAnnotationTypeElement(meth))
@ -90,7 +90,7 @@ public class JavadocMemberEnter extends MemberEnter {
if (tree.sym != null && if (tree.sym != null &&
tree.sym.kind == Kinds.VAR && tree.sym.kind == Kinds.VAR &&
!isParameter(tree.sym)) { !isParameter(tree.sym)) {
docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, tree)); docenv.makeFieldDoc(tree.sym, docenv.getTreePath(env.toplevel, env.enclClass, tree));
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,13 +26,14 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.Locale; import java.util.Locale;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.ListBuffer;
@ -375,4 +376,12 @@ public class RootDocImpl extends DocImpl implements RootDoc {
public JavaFileManager getFileManager() { public JavaFileManager getFileManager() {
return env.fileManager; return env.fileManager;
} }
public void initDocLint(Collection<String> opts) {
env.initDoclint(opts);
}
public boolean showTagMessages() {
return env.showTagMessages();
}
} }

View file

@ -36,7 +36,7 @@ public class T5093723 extends JavadocTester {
private static final String BUG_ID = "5093723"; private static final String BUG_ID = "5093723";
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID + ".out", "-source", "5", "-d", BUG_ID + ".out", "-source", "5", "-Xdoclint:none",
SRC_DIR + "/DocumentedClass.java", SRC_DIR + "/DocumentedClass.java",
SRC_DIR + "/UndocumentedClass.java" SRC_DIR + "/UndocumentedClass.java"
}; };

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ public class TestBadSourceFile extends JavadocTester {
//Javadoc arguments. //Javadoc arguments.
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, SRC_DIR + FS + "C2.java" "-Xdoclint:none", "-d", BUG_ID, SRC_DIR + FS + "C2.java"
}; };
//Input for string search tests. //Input for string search tests.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -222,19 +222,19 @@ public class TestHtmlDefinitionListTag extends JavadocTester {
private static final String[] ARGS1 = private static final String[] ARGS1 =
new String[] { new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"}; "-Xdoclint:none", "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg1"};
private static final String[] ARGS2 = private static final String[] ARGS2 =
new String[] { new String[] {
"-d", BUG_ID, "-nocomment", "-sourcepath", SRC_DIR, "pkg1"}; "-Xdoclint:none", "-d", BUG_ID, "-nocomment", "-sourcepath", SRC_DIR, "pkg1"};
private static final String[] ARGS3 = private static final String[] ARGS3 =
new String[] { new String[] {
"-d", BUG_ID, "-nodeprecated", "-sourcepath", SRC_DIR, "pkg1"}; "-Xdoclint:none", "-d", BUG_ID, "-nodeprecated", "-sourcepath", SRC_DIR, "pkg1"};
private static final String[] ARGS4 = private static final String[] ARGS4 =
new String[] { new String[] {
"-d", BUG_ID, "-nocomment", "-nodeprecated", "-sourcepath", SRC_DIR, "pkg1"}; "-Xdoclint:none", "-d", BUG_ID, "-nocomment", "-nodeprecated", "-sourcepath", SRC_DIR, "pkg1"};
/** /**
* The entry point of the test. * The entry point of the test.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ public class TestNewLanguageFeatures extends JavadocTester {
//Javadoc arguments. //Javadoc arguments.
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-use", "-source", "1.5", "-sourcepath", SRC_DIR, "pkg", "pkg1", "pkg2" "-Xdoclint:none", "-d", BUG_ID, "-use", "-source", "1.5", "-sourcepath", SRC_DIR, "pkg", "pkg1", "pkg2"
}; };
//Input for string search tests. //Input for string search tests.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ public class TestReturnTag extends JavadocTester {
//Javadoc arguments. //Javadoc arguments.
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, SRC_DIR + FS + "TestReturnTag.java" "-Xdoclint:none", "-d", BUG_ID, "-sourcepath", SRC_DIR, SRC_DIR + FS + "TestReturnTag.java"
}; };
//Input for string search tests. //Input for string search tests.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -36,7 +36,7 @@ public class TestTagInheritence extends JavadocTester {
private static final String BUG_ID = "4496223-4496270-4618686-4720974-4812240-6253614-6253604"; private static final String BUG_ID = "4496223-4496270-4618686-4720974-4812240-6253614-6253604";
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", "firstSentence", "firstSentence2" "-Xdoclint:none", "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", "firstSentence", "firstSentence2"
}; };
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -42,7 +42,7 @@ public class TestTagMisuse extends JavadocTester {
}; };
private static final String[][] NEGATED_TEST = NO_TEST; private static final String[][] NEGATED_TEST = NO_TEST;
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, SRC_DIR + FS + "TestTagMisuse.java" "-Xdoclint:none", "-d", BUG_ID, SRC_DIR + FS + "TestTagMisuse.java"
}; };
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -41,6 +41,7 @@ public class TestValueTag extends JavadocTester {
//Javadoc arguments. //Javadoc arguments.
private static final String[] ARGS = private static final String[] ARGS =
new String[] { new String[] {
"-Xdoclint:none",
"-d", BUG_ID, "-sourcepath", SRC_DIR, "-tag", "-d", BUG_ID, "-sourcepath", SRC_DIR, "-tag",
"todo", "pkg1", "pkg2" "todo", "pkg1", "pkg2"
}; };

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,7 +43,7 @@ public class TestWarnBadParamNames extends JavadocTester {
}; };
private static final String[][] NEGATED_TEST = NO_TEST; private static final String[][] NEGATED_TEST = NO_TEST;
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, SRC_DIR + FS + "C.java" "-Xdoclint:none", "-d", BUG_ID, SRC_DIR + FS + "C.java"
}; };
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -43,11 +43,11 @@ public class TestWarnings extends JavadocTester {
//Javadoc arguments. //Javadoc arguments.
private static final String[] ARGS = new String[] { private static final String[] ARGS = new String[] {
"-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg" "-Xdoclint:none", "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg"
}; };
private static final String[] ARGS2 = new String[] { private static final String[] ARGS2 = new String[] {
"-d", BUG_ID, "-private", "-sourcepath", SRC_DIR, "pkg" "-Xdoclint:none", "-d", BUG_ID, "-private", "-sourcepath", SRC_DIR, "pkg"
}; };
//Input for string search tests. //Input for string search tests.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,6 +61,7 @@ public class Test {
// Force en_US locale in lieu of something like -XDrawDiagnostics. // Force en_US locale in lieu of something like -XDrawDiagnostics.
// For some reason, this must be the first option when used. // For some reason, this must be the first option when used.
opts.addAll(list("-locale", "en_US")); opts.addAll(list("-locale", "en_US"));
opts.add("-Xdoclint:none");
opts.addAll(list("-classpath", System.getProperty("test.src"))); opts.addAll(list("-classpath", System.getProperty("test.src")));
opts.addAll(list("-d", testOutDir.getPath())); opts.addAll(list("-d", testOutDir.getPath()));
opts.addAll(testOpts); opts.addAll(testOpts);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,7 @@ public class Test {
void javadoc(String path, String expect) { void javadoc(String path, String expect) {
File testSrc = new File(System.getProperty("test.src")); File testSrc = new File(System.getProperty("test.src"));
String[] args = { String[] args = {
"-Xdoclint:none",
"-source", "1.4", // enables certain Parser warnings "-source", "1.4", // enables certain Parser warnings
"-bootclasspath", System.getProperty("sun.boot.class.path"), "-bootclasspath", System.getProperty("sun.boot.class.path"),
"-classpath", ".", "-classpath", ".",

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,6 +57,7 @@ public class TestStdDoclet {
Process p = new ProcessBuilder() Process p = new ProcessBuilder()
.command(javadoc.getPath(), .command(javadoc.getPath(),
"-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"), "-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"),
"-Xdoclint:none",
"-package", "-package",
new File(testSrc, thisClassName + ".java").getPath()) new File(testSrc, thisClassName + ".java").getPath())
.redirectErrorStream(true) .redirectErrorStream(true)

View file

@ -74,7 +74,7 @@ public class MaxWarns {
String javadoc(File f) { String javadoc(File f) {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
String[] args = { "-d", "api", f.getPath() }; String[] args = { "-Xdoclint:none", "-d", "api", f.getPath() };
int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw,
com.sun.tools.doclets.standard.Standard.class.getName(), args); com.sun.tools.doclets.standard.Standard.class.getName(), args);
pw.flush(); pw.flush();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,7 +46,7 @@ public class T6551367 extends com.sun.tools.doclets.standard.Standard {
File source = new File(testSrc, file); File source = new File(testSrc, file);
int rc = execute("javadoc", "T6551367", int rc = execute("javadoc", "T6551367",
T6551367.class.getClassLoader(), T6551367.class.getClassLoader(),
new String[]{source.getPath(), "-d", destDir.getAbsolutePath()}); new String[]{"-Xdoclint:none", source.getPath(), "-d", destDir.getAbsolutePath()});
if (rc != 0) if (rc != 0)
throw new Error("unexpected exit from javadoc: " + rc); throw new Error("unexpected exit from javadoc: " + rc);
} }

View file

@ -0,0 +1,251 @@
/*
* Copyright (c) 2012, 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.
*
* 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.
*/
/*
* @test
* @bug 8004834
* @summary Add doclint support into javadoc
*/
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.tools.Diagnostic;
import javax.tools.DocumentationTool;
import javax.tools.DocumentationTool.DocumentationTask;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
import static javax.tools.Diagnostic.Kind.*;
import com.sun.tools.javac.main.Main;
public class DocLintTest {
public static void main(String... args) throws Exception {
new DocLintTest().run();
}
DocumentationTool javadoc;
StandardJavaFileManager fm;
JavaFileObject file;
final String code =
/* 01 */ "/** Class comment. */\n" +
/* 02 */ "public class Test {\n" +
/* 03 */ " /** Method comment. */\n" +
/* 04 */ " public void method() { }\n" +
/* 05 */ "\n" +
/* 06 */ " /** Syntax < error. */\n" +
/* 07 */ " private void syntaxError() { }\n" +
/* 08 */ "\n" +
/* 09 */ " /** @see DoesNotExist */\n" +
/* 10 */ " protected void referenceError() { }\n" +
/* 11 */ "\n" +
/* 12 */ " /** @return */\n" +
/* 13 */ " public int emptyReturn() { return 0; }\n" +
/* 14 */ "}\n";
private final String rawDiags = "-XDrawDiagnostics";
private enum Message {
// doclint messages
DL_ERR6(ERROR, "Test.java:6:16: compiler.err.proc.messager: malformed HTML"),
DL_ERR9(ERROR, "Test.java:9:14: compiler.err.proc.messager: reference not found"),
DL_WRN12(WARNING, "Test.java:12:9: compiler.warn.proc.messager: no description for @return"),
// doclint messages when -XDrawDiagnostics is not in effect
DL_ERR9A(ERROR, "Test.java:9: error: reference not found"),
DL_WRN12A(WARNING, "Test.java:12: warning: no description for @return"),
// javadoc messages about bad content: these should only appear when doclint is disabled
JD_WRN10(WARNING, "Test.java:10: warning - Tag @see: reference not found: DoesNotExist"),
JD_WRN13(WARNING, "Test.java:13: warning - @return tag has no arguments."),
// javadoc messages for bad options
OPT_BADARG(ERROR, "javadoc: error - Invalid argument for -Xdoclint option"),
OPT_BADQUAL(ERROR, "javadoc: error - Access qualifiers not permitted for -Xdoclint arguments");
final Diagnostic.Kind kind;
final String text;
static Message get(String text) {
for (Message m: values()) {
if (m.text.equals(text))
return m;
}
return null;
}
Message(Diagnostic.Kind kind, String text) {
this.kind = kind;
this.text = text;
}
@Override
public String toString() {
return "[" + kind + ",\"" + text + "\"]";
}
}
void run() throws Exception {
javadoc = ToolProvider.getSystemDocumentationTool();
fm = javadoc.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncoding) {
return code;
}
};
test(Collections.<String>emptyList(),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9A, Message.DL_WRN12A));
test(Arrays.asList(rawDiags),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
test(Arrays.asList("-Xdoclint:none"),
Main.Result.OK,
EnumSet.of(Message.JD_WRN10, Message.JD_WRN13));
test(Arrays.asList(rawDiags, "-Xdoclint"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
Main.Result.ERROR,
EnumSet.of(Message.OPT_BADQUAL));
test(Arrays.asList(rawDiags, "-Xdoclint:all", "-public"),
Main.Result.OK,
EnumSet.of(Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
Main.Result.OK,
EnumSet.of(Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:syntax", "-private"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9));
test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
Main.Result.ERROR,
EnumSet.of(Message.OPT_BADARG));
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
System.err.println("test: " + opts);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
List<JavaFileObject> files = Arrays.asList(file);
try {
DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files);
boolean ok = t.call();
pw.close();
String out = sw.toString().replaceAll("[\r\n]+", "\n");
if (!out.isEmpty())
System.err.println(out);
if (ok && expectResult != Main.Result.OK) {
error("Compilation succeeded unexpectedly");
} else if (!ok && expectResult != Main.Result.ERROR) {
error("Compilation failed unexpectedly");
} else
check(out, expectMessages);
} catch (IllegalArgumentException e) {
System.err.println(e);
String expectOut = expectMessages.iterator().next().text;
if (expectResult != Main.Result.CMDERR)
error("unexpected exception caught");
else if (!e.getMessage().equals(expectOut)) {
error("unexpected exception message: "
+ e.getMessage()
+ " expected: " + expectOut);
}
}
// if (errors > 0)
// throw new Error("stop");
}
private void check(String out, Set<Message> expect) {
Pattern ignore = Pattern.compile("^(Building|Constructing|Generating|Loading|Standard|Starting| ) .*");
Pattern stats = Pattern.compile("^([1-9]+) (error|warning)(s?)");
Set<Message> found = EnumSet.noneOf(Message.class);
int e = 0, w = 0;
for (String line: out.split("[\r\n]+")) {
if (ignore.matcher(line).matches())
continue;
Matcher s = stats.matcher(line);
if (s.matches()) {
int i = Integer.valueOf(s.group(1));
if (s.group(2).equals("error"))
e++;
else
w++;
continue;
}
Message m = Message.get(line);
if (m == null)
error("Unexpected line: " + line);
else
found.add(m);
}
for (Message m: expect) {
if (!found.contains(m))
error("expected message not found: " + m.text);
}
for (Message m: found) {
if (!expect.contains(m))
error("unexpected message found: " + m.text);
}
}
void error(String msg) {
System.err.println("Error: " + msg);
errors++;
}
int errors;
}