mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
7174143: encapsulate doc comment table
Reviewed-by: ksrini, mcimadamore
This commit is contained in:
parent
288480e312
commit
f2cefcbfad
24 changed files with 252 additions and 113 deletions
|
@ -60,7 +60,7 @@ import com.sun.tools.javac.comp.Env;
|
||||||
import com.sun.tools.javac.comp.MemberEnter;
|
import com.sun.tools.javac.comp.MemberEnter;
|
||||||
import com.sun.tools.javac.comp.Resolve;
|
import com.sun.tools.javac.comp.Resolve;
|
||||||
import com.sun.tools.javac.model.JavacElements;
|
import com.sun.tools.javac.model.JavacElements;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
|
@ -240,10 +240,11 @@ public class JavacTrees extends Trees {
|
||||||
|
|
||||||
public String getDocComment(TreePath path) {
|
public String getDocComment(TreePath path) {
|
||||||
CompilationUnitTree t = path.getCompilationUnit();
|
CompilationUnitTree t = path.getCompilationUnit();
|
||||||
if (t instanceof JCTree.JCCompilationUnit) {
|
Tree leaf = path.getLeaf();
|
||||||
|
if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
|
||||||
JCCompilationUnit cu = (JCCompilationUnit) t;
|
JCCompilationUnit cu = (JCCompilationUnit) t;
|
||||||
if (cu.docComments != null) {
|
if (cu.docComments != null) {
|
||||||
return cu.docComments.get(path.getLeaf());
|
return cu.docComments.getCommentText((JCTree) leaf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -312,7 +312,7 @@ public class Enter extends JCTree.Visitor {
|
||||||
tree.packge);
|
tree.packge);
|
||||||
if (addEnv || (tree0.packageAnnotations.isEmpty() &&
|
if (addEnv || (tree0.packageAnnotations.isEmpty() &&
|
||||||
tree.docComments != null &&
|
tree.docComments != null &&
|
||||||
tree.docComments.get(tree) != null)) {
|
tree.docComments.hasComment(tree))) {
|
||||||
typeEnvs.put(tree.packge, topEnv);
|
typeEnvs.put(tree.packge, topEnv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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 @@ import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.code.Type.*;
|
import com.sun.tools.javac.code.Type.*;
|
||||||
|
|
||||||
import com.sun.tools.javac.jvm.Target;
|
import com.sun.tools.javac.jvm.Target;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
|
|
||||||
import static com.sun.tools.javac.code.Flags.*;
|
import static com.sun.tools.javac.code.Flags.*;
|
||||||
import static com.sun.tools.javac.code.Flags.BLOCK;
|
import static com.sun.tools.javac.code.Flags.BLOCK;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2012, 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,7 +31,7 @@ import com.sun.tools.javac.tree.*;
|
||||||
import com.sun.tools.javac.util.*;
|
import com.sun.tools.javac.util.*;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
|
|
||||||
/** This class contains the CharacterRangeTable for some method
|
/** This class contains the CharacterRangeTable for some method
|
||||||
* and the hashtable for mapping trees or lists of trees to their
|
* and the hashtable for mapping trees or lists of trees to their
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -37,7 +37,7 @@ import com.sun.tools.javac.code.Symbol.*;
|
||||||
import com.sun.tools.javac.code.Type.*;
|
import com.sun.tools.javac.code.Type.*;
|
||||||
import com.sun.tools.javac.jvm.Code.*;
|
import com.sun.tools.javac.jvm.Code.*;
|
||||||
import com.sun.tools.javac.jvm.Items.*;
|
import com.sun.tools.javac.jvm.Items.*;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
|
|
||||||
import static com.sun.tools.javac.code.Flags.*;
|
import static com.sun.tools.javac.code.Flags.*;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2012, 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
|
||||||
|
@ -28,11 +28,14 @@ package com.sun.tools.javac.model;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.Inherited;
|
import java.lang.annotation.Inherited;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.util.Elements;
|
import javax.lang.model.util.Elements;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
import static javax.lang.model.util.ElementFilter.methodsIn;
|
||||||
|
|
||||||
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.TypeTags;
|
import com.sun.tools.javac.code.TypeTags;
|
||||||
|
@ -47,9 +50,7 @@ import com.sun.tools.javac.tree.TreeInfo;
|
||||||
import com.sun.tools.javac.tree.TreeScanner;
|
import com.sun.tools.javac.tree.TreeScanner;
|
||||||
import com.sun.tools.javac.util.*;
|
import com.sun.tools.javac.util.*;
|
||||||
import com.sun.tools.javac.util.Name;
|
import com.sun.tools.javac.util.Name;
|
||||||
|
|
||||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||||
import static javax.lang.model.util.ElementFilter.methodsIn;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for operating on program elements.
|
* Utility methods for operating on program elements.
|
||||||
|
@ -361,7 +362,7 @@ public class JavacElements implements Elements {
|
||||||
JCCompilationUnit toplevel = treeTop.snd;
|
JCCompilationUnit toplevel = treeTop.snd;
|
||||||
if (toplevel.docComments == null)
|
if (toplevel.docComments == null)
|
||||||
return null;
|
return null;
|
||||||
return toplevel.docComments.get(tree);
|
return toplevel.docComments.getCommentText(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageElement getPackageOf(Element e) {
|
public PackageElement getPackageOf(Element e) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -571,7 +571,7 @@ public class JavaTokenizer {
|
||||||
reader.scanCommentChar();
|
reader.scanCommentChar();
|
||||||
} while (reader.ch != CR && reader.ch != LF && reader.bp < reader.buflen);
|
} while (reader.ch != CR && reader.ch != LF && reader.bp < reader.buflen);
|
||||||
if (reader.bp < reader.buflen) {
|
if (reader.bp < reader.buflen) {
|
||||||
comments = addDocReader(comments, processComment(pos, reader.bp, CommentStyle.LINE));
|
comments = addComment(comments, processComment(pos, reader.bp, CommentStyle.LINE));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (reader.ch == '*') {
|
} else if (reader.ch == '*') {
|
||||||
|
@ -597,7 +597,7 @@ public class JavaTokenizer {
|
||||||
}
|
}
|
||||||
if (reader.ch == '/') {
|
if (reader.ch == '/') {
|
||||||
reader.scanChar();
|
reader.scanChar();
|
||||||
comments = addDocReader(comments, processComment(pos, reader.bp, style));
|
comments = addComment(comments, processComment(pos, reader.bp, style));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
lexError(pos, "unclosed.comment");
|
lexError(pos, "unclosed.comment");
|
||||||
|
@ -693,10 +693,10 @@ public class JavaTokenizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//where
|
//where
|
||||||
List<Comment> addDocReader(List<Comment> docReaders, Comment docReader) {
|
List<Comment> addComment(List<Comment> comments, Comment comment) {
|
||||||
return docReaders == null ?
|
return comments == null ?
|
||||||
List.of(docReader) :
|
List.of(comment) :
|
||||||
docReaders.prepend(docReader);
|
comments.prepend(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the position where a lexical error occurred;
|
/** Return the position where a lexical error occurred;
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class JavacParser implements Parser {
|
||||||
this.allowMethodReferences = source.allowMethodReferences() &&
|
this.allowMethodReferences = source.allowMethodReferences() &&
|
||||||
fac.options.isSet("allowMethodReferences");
|
fac.options.isSet("allowMethodReferences");
|
||||||
this.keepDocComments = keepDocComments;
|
this.keepDocComments = keepDocComments;
|
||||||
docComments = keepDocComments ? new HashMap<JCTree,String>() : null;
|
docComments = newDocCommentTable(keepDocComments);
|
||||||
this.keepLineMap = keepLineMap;
|
this.keepLineMap = keepLineMap;
|
||||||
this.errorTree = F.Erroneous();
|
this.errorTree = F.Erroneous();
|
||||||
endPosTable = newEndPosTable(keepEndPositions);
|
endPosTable = newEndPosTable(keepEndPositions);
|
||||||
|
@ -128,6 +128,11 @@ public class JavacParser implements Parser {
|
||||||
? new SimpleEndPosTable()
|
? new SimpleEndPosTable()
|
||||||
: new EmptyEndPosTable();
|
: new EmptyEndPosTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DocCommentTable newDocCommentTable(boolean keepDocComments) {
|
||||||
|
return keepDocComments ? new SimpleDocCommentTable() : null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Switch: Should generics be recognized?
|
/** Switch: Should generics be recognized?
|
||||||
*/
|
*/
|
||||||
boolean allowGenerics;
|
boolean allowGenerics;
|
||||||
|
@ -417,21 +422,21 @@ public class JavacParser implements Parser {
|
||||||
|
|
||||||
/* ---------- doc comments --------- */
|
/* ---------- doc comments --------- */
|
||||||
|
|
||||||
/** A hashtable to store all documentation comments
|
/** A table to store all documentation comments
|
||||||
* indexed by the tree nodes they refer to.
|
* indexed by the tree nodes they refer to.
|
||||||
* defined only if option flag keepDocComment is set.
|
* defined only if option flag keepDocComment is set.
|
||||||
*/
|
*/
|
||||||
private final Map<JCTree, String> docComments;
|
private final DocCommentTable docComments;
|
||||||
|
|
||||||
/** Make an entry into docComments hashtable,
|
/** Make an entry into docComments hashtable,
|
||||||
* provided flag keepDocComments is set and given doc comment is non-null.
|
* provided flag keepDocComments is set and given doc comment is non-null.
|
||||||
* @param tree The tree to be used as index in the hashtable
|
* @param tree The tree to be used as index in the hashtable
|
||||||
* @param dc The doc comment to associate with the tree, or null.
|
* @param dc The doc comment to associate with the tree, or null.
|
||||||
*/
|
*/
|
||||||
void attach(JCTree tree, String dc) {
|
void attach(JCTree tree, Comment dc) {
|
||||||
if (keepDocComments && dc != null) {
|
if (keepDocComments && dc != null) {
|
||||||
// System.out.println("doc comment = ");System.out.println(dc);//DEBUG
|
// System.out.println("doc comment = ");System.out.println(dc);//DEBUG
|
||||||
docComments.put(tree, dc);
|
docComments.putComment(tree, dc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1858,7 +1863,7 @@ public class JavacParser implements Parser {
|
||||||
return List.of(parseStatement());
|
return List.of(parseStatement());
|
||||||
case MONKEYS_AT:
|
case MONKEYS_AT:
|
||||||
case FINAL: {
|
case FINAL: {
|
||||||
String dc = token.comment(CommentStyle.JAVADOC);
|
Comment dc = token.comment(CommentStyle.JAVADOC);
|
||||||
JCModifiers mods = modifiersOpt();
|
JCModifiers mods = modifiersOpt();
|
||||||
if (token.kind == INTERFACE ||
|
if (token.kind == INTERFACE ||
|
||||||
token.kind == CLASS ||
|
token.kind == CLASS ||
|
||||||
|
@ -1875,13 +1880,13 @@ public class JavacParser implements Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ABSTRACT: case STRICTFP: {
|
case ABSTRACT: case STRICTFP: {
|
||||||
String dc = token.comment(CommentStyle.JAVADOC);
|
Comment dc = token.comment(CommentStyle.JAVADOC);
|
||||||
JCModifiers mods = modifiersOpt();
|
JCModifiers mods = modifiersOpt();
|
||||||
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
|
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
|
||||||
}
|
}
|
||||||
case INTERFACE:
|
case INTERFACE:
|
||||||
case CLASS:
|
case CLASS:
|
||||||
String dc = token.comment(CommentStyle.JAVADOC);
|
Comment dc = token.comment(CommentStyle.JAVADOC);
|
||||||
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
|
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
|
||||||
case ENUM:
|
case ENUM:
|
||||||
case ASSERT:
|
case ASSERT:
|
||||||
|
@ -2418,7 +2423,7 @@ public class JavacParser implements Parser {
|
||||||
JCExpression type,
|
JCExpression type,
|
||||||
Name name,
|
Name name,
|
||||||
boolean reqInit,
|
boolean reqInit,
|
||||||
String dc,
|
Comment dc,
|
||||||
T vdefs)
|
T vdefs)
|
||||||
{
|
{
|
||||||
vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc));
|
vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc));
|
||||||
|
@ -2434,7 +2439,7 @@ public class JavacParser implements Parser {
|
||||||
/** VariableDeclarator = Ident VariableDeclaratorRest
|
/** VariableDeclarator = Ident VariableDeclaratorRest
|
||||||
* ConstantDeclarator = Ident ConstantDeclaratorRest
|
* ConstantDeclarator = Ident ConstantDeclaratorRest
|
||||||
*/
|
*/
|
||||||
JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, String dc) {
|
JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, Comment dc) {
|
||||||
return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc);
|
return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2445,7 +2450,7 @@ public class JavacParser implements Parser {
|
||||||
* @param dc The documentation comment for the variable declarations, or null.
|
* @param dc The documentation comment for the variable declarations, or null.
|
||||||
*/
|
*/
|
||||||
JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name,
|
JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name,
|
||||||
boolean reqInit, String dc) {
|
boolean reqInit, Comment dc) {
|
||||||
type = bracketsOpt(type);
|
type = bracketsOpt(type);
|
||||||
JCExpression init = null;
|
JCExpression init = null;
|
||||||
if (token.kind == EQ) {
|
if (token.kind == EQ) {
|
||||||
|
@ -2539,7 +2544,7 @@ public class JavacParser implements Parser {
|
||||||
seenImport = true;
|
seenImport = true;
|
||||||
defs.append(importDeclaration());
|
defs.append(importDeclaration());
|
||||||
} else {
|
} else {
|
||||||
String docComment = token.comment(CommentStyle.JAVADOC);
|
Comment docComment = token.comment(CommentStyle.JAVADOC);
|
||||||
if (firstTypeDecl && !seenImport && !seenPackage) {
|
if (firstTypeDecl && !seenImport && !seenPackage) {
|
||||||
docComment = firstToken.comment(CommentStyle.JAVADOC);
|
docComment = firstToken.comment(CommentStyle.JAVADOC);
|
||||||
consumedToplevelDoc = true;
|
consumedToplevelDoc = true;
|
||||||
|
@ -2597,7 +2602,7 @@ public class JavacParser implements Parser {
|
||||||
/** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration
|
/** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration
|
||||||
* | ";"
|
* | ";"
|
||||||
*/
|
*/
|
||||||
JCTree typeDeclaration(JCModifiers mods, String docComment) {
|
JCTree typeDeclaration(JCModifiers mods, Comment docComment) {
|
||||||
int pos = token.pos;
|
int pos = token.pos;
|
||||||
if (mods == null && token.kind == SEMI) {
|
if (mods == null && token.kind == SEMI) {
|
||||||
nextToken();
|
nextToken();
|
||||||
|
@ -2612,7 +2617,7 @@ public class JavacParser implements Parser {
|
||||||
* @param mods Any modifiers starting the class or interface declaration
|
* @param mods Any modifiers starting the class or interface declaration
|
||||||
* @param dc The documentation comment for the class, or null.
|
* @param dc The documentation comment for the class, or null.
|
||||||
*/
|
*/
|
||||||
JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, String dc) {
|
JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, Comment dc) {
|
||||||
if (token.kind == CLASS) {
|
if (token.kind == CLASS) {
|
||||||
return classDeclaration(mods, dc);
|
return classDeclaration(mods, dc);
|
||||||
} else if (token.kind == INTERFACE) {
|
} else if (token.kind == INTERFACE) {
|
||||||
|
@ -2656,7 +2661,7 @@ public class JavacParser implements Parser {
|
||||||
* @param mods The modifiers starting the class declaration
|
* @param mods The modifiers starting the class declaration
|
||||||
* @param dc The documentation comment for the class, or null.
|
* @param dc The documentation comment for the class, or null.
|
||||||
*/
|
*/
|
||||||
protected JCClassDecl classDeclaration(JCModifiers mods, String dc) {
|
protected JCClassDecl classDeclaration(JCModifiers mods, Comment dc) {
|
||||||
int pos = token.pos;
|
int pos = token.pos;
|
||||||
accept(CLASS);
|
accept(CLASS);
|
||||||
Name name = ident();
|
Name name = ident();
|
||||||
|
@ -2685,7 +2690,7 @@ public class JavacParser implements Parser {
|
||||||
* @param mods The modifiers starting the interface declaration
|
* @param mods The modifiers starting the interface declaration
|
||||||
* @param dc The documentation comment for the interface, or null.
|
* @param dc The documentation comment for the interface, or null.
|
||||||
*/
|
*/
|
||||||
protected JCClassDecl interfaceDeclaration(JCModifiers mods, String dc) {
|
protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) {
|
||||||
int pos = token.pos;
|
int pos = token.pos;
|
||||||
accept(INTERFACE);
|
accept(INTERFACE);
|
||||||
Name name = ident();
|
Name name = ident();
|
||||||
|
@ -2708,7 +2713,7 @@ public class JavacParser implements Parser {
|
||||||
* @param mods The modifiers starting the enum declaration
|
* @param mods The modifiers starting the enum declaration
|
||||||
* @param dc The documentation comment for the enum, or null.
|
* @param dc The documentation comment for the enum, or null.
|
||||||
*/
|
*/
|
||||||
protected JCClassDecl enumDeclaration(JCModifiers mods, String dc) {
|
protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) {
|
||||||
int pos = token.pos;
|
int pos = token.pos;
|
||||||
accept(ENUM);
|
accept(ENUM);
|
||||||
Name name = ident();
|
Name name = ident();
|
||||||
|
@ -2767,7 +2772,7 @@ public class JavacParser implements Parser {
|
||||||
/** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ]
|
/** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ]
|
||||||
*/
|
*/
|
||||||
JCTree enumeratorDeclaration(Name enumName) {
|
JCTree enumeratorDeclaration(Name enumName) {
|
||||||
String dc = token.comment(CommentStyle.JAVADOC);
|
Comment dc = token.comment(CommentStyle.JAVADOC);
|
||||||
int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM;
|
int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM;
|
||||||
if (token.deprecatedFlag()) {
|
if (token.deprecatedFlag()) {
|
||||||
flags |= Flags.DEPRECATED;
|
flags |= Flags.DEPRECATED;
|
||||||
|
@ -2856,7 +2861,7 @@ public class JavacParser implements Parser {
|
||||||
nextToken();
|
nextToken();
|
||||||
return List.<JCTree>nil();
|
return List.<JCTree>nil();
|
||||||
} else {
|
} else {
|
||||||
String dc = token.comment(CommentStyle.JAVADOC);
|
Comment dc = token.comment(CommentStyle.JAVADOC);
|
||||||
int pos = token.pos;
|
int pos = token.pos;
|
||||||
JCModifiers mods = modifiersOpt();
|
JCModifiers mods = modifiersOpt();
|
||||||
if (token.kind == CLASS ||
|
if (token.kind == CLASS ||
|
||||||
|
@ -2936,7 +2941,7 @@ public class JavacParser implements Parser {
|
||||||
Name name,
|
Name name,
|
||||||
List<JCTypeParameter> typarams,
|
List<JCTypeParameter> typarams,
|
||||||
boolean isInterface, boolean isVoid,
|
boolean isInterface, boolean isVoid,
|
||||||
String dc) {
|
Comment dc) {
|
||||||
List<JCVariableDecl> params = formalParameters();
|
List<JCVariableDecl> params = formalParameters();
|
||||||
if (!isVoid) type = bracketsOpt(type);
|
if (!isVoid) type = bracketsOpt(type);
|
||||||
List<JCExpression> thrown = List.nil();
|
List<JCExpression> thrown = List.nil();
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 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.javac.parser;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||||
|
import com.sun.tools.javac.tree.DocCommentTable;
|
||||||
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <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 SimpleDocCommentTable implements DocCommentTable {
|
||||||
|
Map<JCTree, Comment> table;
|
||||||
|
|
||||||
|
SimpleDocCommentTable() {
|
||||||
|
table = new HashMap<JCTree, Comment>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasComment(JCTree tree) {
|
||||||
|
return table.containsKey(tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comment getComment(JCTree tree) {
|
||||||
|
return table.get(tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommentText(JCTree tree) {
|
||||||
|
Comment c = getComment(tree);
|
||||||
|
return (c == null) ? null : c.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putComment(JCTree tree, Comment c) {
|
||||||
|
table.put(tree, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -371,11 +371,11 @@ public class Tokens {
|
||||||
* Preserve classic semantics - if multiple javadocs are found on the token
|
* Preserve classic semantics - if multiple javadocs are found on the token
|
||||||
* the last one is returned
|
* the last one is returned
|
||||||
*/
|
*/
|
||||||
public String comment(Comment.CommentStyle style) {
|
public Comment comment(Comment.CommentStyle style) {
|
||||||
List<Comment> readers = getReaders(Comment.CommentStyle.JAVADOC);
|
List<Comment> comments = getComments(Comment.CommentStyle.JAVADOC);
|
||||||
return readers.isEmpty() ?
|
return comments.isEmpty() ?
|
||||||
null :
|
null :
|
||||||
readers.head.getText();
|
comments.head;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,22 +383,22 @@ public class Tokens {
|
||||||
* javadoc comment attached to this token contains the '@deprecated' string
|
* javadoc comment attached to this token contains the '@deprecated' string
|
||||||
*/
|
*/
|
||||||
public boolean deprecatedFlag() {
|
public boolean deprecatedFlag() {
|
||||||
for (Comment r : getReaders(Comment.CommentStyle.JAVADOC)) {
|
for (Comment c : getComments(Comment.CommentStyle.JAVADOC)) {
|
||||||
if (r.isDeprecated()) {
|
if (c.isDeprecated()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Comment> getReaders(Comment.CommentStyle style) {
|
private List<Comment> getComments(Comment.CommentStyle style) {
|
||||||
if (comments == null) {
|
if (comments == null) {
|
||||||
return List.nil();
|
return List.nil();
|
||||||
} else {
|
} else {
|
||||||
ListBuffer<Comment> buf = ListBuffer.lb();
|
ListBuffer<Comment> buf = ListBuffer.lb();
|
||||||
for (Comment r : comments) {
|
for (Comment c : comments) {
|
||||||
if (r.getStyle() == style) {
|
if (c.getStyle() == style) {
|
||||||
buf.add(r);
|
buf.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buf.toList();
|
return buf.toList();
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 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.javac.tree;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A table giving the doc comment, if any, for any tree node.
|
||||||
|
*
|
||||||
|
* <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 interface DocCommentTable {
|
||||||
|
/**
|
||||||
|
* Check if a tree node has a corresponding doc comment.
|
||||||
|
*/
|
||||||
|
public boolean hasComment(JCTree tree);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Comment token containing the doc comment, if any, for a tree node.
|
||||||
|
*/
|
||||||
|
public Comment getComment(JCTree tree);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the plain text of the doc comment, if any, for a tree node.
|
||||||
|
*/
|
||||||
|
public String getCommentText(JCTree tree);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Comment to be associated with a tree node.
|
||||||
|
*/
|
||||||
|
public void putComment(JCTree tree, Comment c);
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2012, 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
|
||||||
|
@ -22,9 +22,8 @@
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
package com.sun.tools.javac.parser;
|
|
||||||
|
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
package com.sun.tools.javac.tree;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the methods to access a mappings of syntax trees to end positions.
|
* Specifies the methods to access a mappings of syntax trees to end positions.
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -25,25 +25,23 @@
|
||||||
|
|
||||||
package com.sun.tools.javac.tree;
|
package com.sun.tools.javac.tree;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.*;
|
|
||||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
|
||||||
import com.sun.tools.javac.util.List;
|
|
||||||
import com.sun.tools.javac.code.*;
|
|
||||||
import com.sun.tools.javac.code.Scope.*;
|
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
|
||||||
import com.sun.source.tree.*;
|
import com.sun.source.tree.*;
|
||||||
import com.sun.source.tree.LambdaExpressionTree.BodyKind;
|
import com.sun.source.tree.LambdaExpressionTree.BodyKind;
|
||||||
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
|
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
|
||||||
|
import com.sun.tools.javac.code.*;
|
||||||
|
import com.sun.tools.javac.code.Scope.*;
|
||||||
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
|
import com.sun.tools.javac.util.*;
|
||||||
|
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||||
|
import com.sun.tools.javac.util.List;
|
||||||
import static com.sun.tools.javac.code.BoundKind.*;
|
import static com.sun.tools.javac.code.BoundKind.*;
|
||||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||||
|
|
||||||
|
@ -491,7 +489,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||||
public ImportScope namedImportScope;
|
public ImportScope namedImportScope;
|
||||||
public StarImportScope starImportScope;
|
public StarImportScope starImportScope;
|
||||||
public Position.LineMap lineMap = null;
|
public Position.LineMap lineMap = null;
|
||||||
public Map<JCTree, String> docComments = null;
|
public DocCommentTable docComments = null;
|
||||||
public EndPosTable endPositions = null;
|
public EndPosTable endPositions = null;
|
||||||
protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
|
protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
|
||||||
JCExpression pid,
|
JCExpression pid,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -29,14 +29,12 @@ import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
|
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
|
||||||
|
import com.sun.tools.javac.code.*;
|
||||||
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
|
import com.sun.tools.javac.parser.Tokens.Comment;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.*;
|
import com.sun.tools.javac.util.*;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.code.*;
|
|
||||||
|
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
|
||||||
|
|
||||||
import static com.sun.tools.javac.code.Flags.*;
|
import static com.sun.tools.javac.code.Flags.*;
|
||||||
import static com.sun.tools.javac.code.Flags.ANNOTATION;
|
import static com.sun.tools.javac.code.Flags.ANNOTATION;
|
||||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||||
|
@ -78,10 +76,10 @@ public class Pretty extends JCTree.Visitor {
|
||||||
*/
|
*/
|
||||||
Name enclClassName;
|
Name enclClassName;
|
||||||
|
|
||||||
/** A hashtable mapping trees to their documentation comments
|
/** A table mapping trees to their documentation comments
|
||||||
* (can be null)
|
* (can be null)
|
||||||
*/
|
*/
|
||||||
Map<JCTree, String> docComments = null;
|
DocCommentTable docComments = null;
|
||||||
|
|
||||||
/** Align code to be indented to left margin.
|
/** Align code to be indented to left margin.
|
||||||
*/
|
*/
|
||||||
|
@ -233,7 +231,7 @@ public class Pretty extends JCTree.Visitor {
|
||||||
*/
|
*/
|
||||||
public void printDocComment(JCTree tree) throws IOException {
|
public void printDocComment(JCTree tree) throws IOException {
|
||||||
if (docComments != null) {
|
if (docComments != null) {
|
||||||
String dc = docComments.get(tree);
|
String dc = docComments.getCommentText(tree);
|
||||||
if (dc != null) {
|
if (dc != null) {
|
||||||
print("/**"); println();
|
print("/**"); println();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -480,7 +478,7 @@ public class Pretty extends JCTree.Visitor {
|
||||||
|
|
||||||
public void visitVarDef(JCVariableDecl tree) {
|
public void visitVarDef(JCVariableDecl tree) {
|
||||||
try {
|
try {
|
||||||
if (docComments != null && docComments.get(tree) != null) {
|
if (docComments != null && docComments.hasComment(tree)) {
|
||||||
println(); align();
|
println(); align();
|
||||||
}
|
}
|
||||||
printDocComment(tree);
|
printDocComment(tree);
|
||||||
|
|
|
@ -25,15 +25,14 @@
|
||||||
|
|
||||||
package com.sun.tools.javac.tree;
|
package com.sun.tools.javac.tree;
|
||||||
|
|
||||||
|
|
||||||
import com.sun.source.tree.Tree;
|
import com.sun.source.tree.Tree;
|
||||||
|
import com.sun.tools.javac.code.*;
|
||||||
import com.sun.tools.javac.comp.AttrContext;
|
import com.sun.tools.javac.comp.AttrContext;
|
||||||
import com.sun.tools.javac.comp.Env;
|
import com.sun.tools.javac.comp.Env;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.*;
|
import com.sun.tools.javac.util.*;
|
||||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||||
import com.sun.tools.javac.code.*;
|
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
|
||||||
|
|
||||||
import static com.sun.tools.javac.code.Flags.*;
|
import static com.sun.tools.javac.code.Flags.*;
|
||||||
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
import static com.sun.tools.javac.tree.JCTree.Tag.*;
|
||||||
import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
|
import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
|
||||||
|
@ -282,6 +281,13 @@ public class TreeInfo {
|
||||||
return (lit.typetag == TypeTags.BOT);
|
return (lit.typetag == TypeTags.BOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCommentText(Env<?> env, JCTree tree) {
|
||||||
|
DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL))
|
||||||
|
? ((JCCompilationUnit) tree).docComments
|
||||||
|
: env.toplevel.docComments;
|
||||||
|
return docComments.getCommentText(tree);
|
||||||
|
}
|
||||||
|
|
||||||
/** The position of the first statement in a block, or the position of
|
/** The position of the first statement in a block, or the position of
|
||||||
* the block itself if it is empty.
|
* the block itself if it is empty.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
import com.sun.tools.javac.file.JavacFileManager;
|
import com.sun.tools.javac.file.JavacFileManager;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
||||||
import static com.sun.tools.javac.util.LayoutCharacters.*;
|
import static com.sun.tools.javac.util.LayoutCharacters.*;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2012, 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
|
||||||
|
@ -35,7 +35,7 @@ import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
import com.sun.tools.javac.api.DiagnosticFormatter;
|
import com.sun.tools.javac.api.DiagnosticFormatter;
|
||||||
import com.sun.tools.javac.code.Lint.LintCategory;
|
import com.sun.tools.javac.code.Lint.LintCategory;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
||||||
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
|
import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2012, 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
|
||||||
|
@ -37,7 +37,7 @@ import javax.tools.JavaFileObject;
|
||||||
import com.sun.tools.javac.api.DiagnosticFormatter;
|
import com.sun.tools.javac.api.DiagnosticFormatter;
|
||||||
import com.sun.tools.javac.main.Main;
|
import com.sun.tools.javac.main.Main;
|
||||||
import com.sun.tools.javac.main.Option;
|
import com.sun.tools.javac.main.Option;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
|
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2012, 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
|
||||||
|
@ -25,14 +25,17 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.Context;
|
|
||||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
import javax.tools.JavaFileObject;
|
||||||
import com.sun.tools.javac.util.List;
|
|
||||||
import com.sun.tools.javac.code.Kinds;
|
import com.sun.tools.javac.code.Kinds;
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
import com.sun.tools.javac.comp.Enter;
|
import com.sun.tools.javac.comp.Enter;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import javax.tools.JavaFileObject;
|
import com.sun.tools.javac.tree.TreeInfo;
|
||||||
|
import com.sun.tools.javac.util.Context;
|
||||||
|
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
|
||||||
|
import com.sun.tools.javac.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Javadoc's own enter phase does a few things above and beyond that
|
* Javadoc's own enter phase does a few things above and beyond that
|
||||||
|
@ -77,7 +80,7 @@ public class JavadocEnter extends Enter {
|
||||||
public void visitTopLevel(JCCompilationUnit tree) {
|
public void visitTopLevel(JCCompilationUnit tree) {
|
||||||
super.visitTopLevel(tree);
|
super.visitTopLevel(tree);
|
||||||
if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
|
if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) {
|
||||||
String comment = tree.docComments.get(tree);
|
String comment = TreeInfo.getCommentText(env, tree);
|
||||||
docenv.makePackageDoc(tree.packge, comment, tree);
|
docenv.makePackageDoc(tree.packge, comment, tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +90,7 @@ public class JavadocEnter extends Enter {
|
||||||
super.visitClassDef(tree);
|
super.visitClassDef(tree);
|
||||||
if (tree.sym == null) return;
|
if (tree.sym == null) return;
|
||||||
if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) {
|
if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) {
|
||||||
String comment = env.toplevel.docComments.get(tree);
|
String comment = TreeInfo.getCommentText(env, tree);
|
||||||
ClassSymbol c = tree.sym;
|
ClassSymbol c = tree.sym;
|
||||||
docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap);
|
docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2012, 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
|
||||||
|
@ -25,13 +25,14 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.Context;
|
|
||||||
import com.sun.tools.javac.util.Position;
|
|
||||||
import com.sun.tools.javac.code.Flags;
|
import com.sun.tools.javac.code.Flags;
|
||||||
import com.sun.tools.javac.code.Kinds;
|
import com.sun.tools.javac.code.Kinds;
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
import com.sun.tools.javac.comp.MemberEnter;
|
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.tree.TreeInfo;
|
||||||
|
import com.sun.tools.javac.util.Context;
|
||||||
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Javadoc's own memberEnter phase does a few things above and beyond that
|
* Javadoc's own memberEnter phase does a few things above and beyond that
|
||||||
|
@ -61,11 +62,12 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||||
docenv = DocEnv.instance(context);
|
docenv = DocEnv.instance(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void visitMethodDef(JCMethodDecl tree) {
|
public void visitMethodDef(JCMethodDecl tree) {
|
||||||
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;
|
||||||
String docComment = env.toplevel.docComments.get(tree);
|
String docComment = TreeInfo.getCommentText(env, tree);
|
||||||
Position.LineMap lineMap = env.toplevel.lineMap;
|
Position.LineMap lineMap = env.toplevel.lineMap;
|
||||||
if (meth.isConstructor())
|
if (meth.isConstructor())
|
||||||
docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
|
docenv.makeConstructorDoc(meth, docComment, tree, lineMap);
|
||||||
|
@ -75,12 +77,13 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||||
docenv.makeMethodDoc(meth, docComment, tree, lineMap);
|
docenv.makeMethodDoc(meth, docComment, tree, lineMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void visitVarDef(JCVariableDecl tree) {
|
public void visitVarDef(JCVariableDecl tree) {
|
||||||
super.visitVarDef(tree);
|
super.visitVarDef(tree);
|
||||||
if (tree.sym != null &&
|
if (tree.sym != null &&
|
||||||
tree.sym.kind == Kinds.VAR &&
|
tree.sym.kind == Kinds.VAR &&
|
||||||
!isParameter(tree.sym)) {
|
!isParameter(tree.sym)) {
|
||||||
String docComment = env.toplevel.docComments.get(tree);
|
String docComment = TreeInfo.getCommentText(env, tree);
|
||||||
Position.LineMap lineMap = env.toplevel.lineMap;
|
Position.LineMap lineMap = env.toplevel.lineMap;
|
||||||
docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
|
docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2012, 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,9 +33,9 @@ import java.net.URI;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
import javax.tools.SimpleJavaFileObject;
|
import javax.tools.SimpleJavaFileObject;
|
||||||
import com.sun.tools.javac.file.JavacFileManager;
|
import com.sun.tools.javac.file.JavacFileManager;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
|
||||||
import com.sun.tools.javac.parser.Parser;
|
import com.sun.tools.javac.parser.Parser;
|
||||||
import com.sun.tools.javac.parser.ParserFactory;
|
import com.sun.tools.javac.parser.ParserFactory;
|
||||||
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.TreeScanner;
|
import com.sun.tools.javac.tree.TreeScanner;
|
||||||
import com.sun.tools.javac.util.Context;
|
import com.sun.tools.javac.util.Context;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2010, 2012, 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
|
||||||
|
@ -68,7 +68,7 @@ import com.sun.source.util.TaskListener;
|
||||||
import com.sun.tools.javac.api.JavacTool;
|
import com.sun.tools.javac.api.JavacTool;
|
||||||
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;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCImport;
|
import com.sun.tools.javac.tree.JCTree.JCImport;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2012, 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
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
import com.sun.source.tree.*;
|
import com.sun.source.tree.*;
|
||||||
import com.sun.source.util.*;
|
import com.sun.source.util.*;
|
||||||
|
import com.sun.tools.javac.tree.DocCommentTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -137,16 +138,16 @@ public class DocCommentToplevelTest {
|
||||||
|
|
||||||
new TreeScanner<ClassTree,Void>() {
|
new TreeScanner<ClassTree,Void>() {
|
||||||
|
|
||||||
Map<JCTree, String> docComments;
|
DocCommentTable docComments;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) {
|
public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) {
|
||||||
docComments = ((JCTree.JCCompilationUnit)node).docComments;
|
docComments = ((JCTree.JCCompilationUnit)node).docComments;
|
||||||
boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
|
boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
|
||||||
(pk != PackageKind.NO_PKG || ik != ImportKind.ZERO);
|
(pk != PackageKind.NO_PKG || ik != ImportKind.ZERO);
|
||||||
boolean foundComment = docComments.get(node) != null;
|
boolean foundComment = docComments.hasComment((JCTree) node);
|
||||||
if (expectedComment != foundComment) {
|
if (expectedComment != foundComment) {
|
||||||
error("Unexpected comment " + docComments.get(node) + " on toplevel");
|
error("Unexpected comment " + docComments.getComment((JCTree) node) + " on toplevel");
|
||||||
}
|
}
|
||||||
return super.visitCompilationUnit(node, null);
|
return super.visitCompilationUnit(node, null);
|
||||||
}
|
}
|
||||||
|
@ -156,9 +157,9 @@ public class DocCommentToplevelTest {
|
||||||
boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
|
boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
|
||||||
pk == PackageKind.NO_PKG && ik == ImportKind.ZERO &&
|
pk == PackageKind.NO_PKG && ik == ImportKind.ZERO &&
|
||||||
node.getSimpleName().toString().equals("First");
|
node.getSimpleName().toString().equals("First");
|
||||||
boolean foundComment = docComments.get(node) != null;
|
boolean foundComment = docComments.hasComment((JCTree) node);
|
||||||
if (expectedComment != foundComment) {
|
if (expectedComment != foundComment) {
|
||||||
error("Unexpected comment " + docComments.get(node) + " on class " + node.getSimpleName());
|
error("Unexpected comment " + docComments.getComment((JCTree) node) + " on class " + node.getSimpleName());
|
||||||
}
|
}
|
||||||
return super.visitClass(node, unused);
|
return super.visitClass(node, unused);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2010, 2012, 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
|
||||||
|
@ -73,7 +73,7 @@ import com.sun.source.tree.CompilationUnitTree;
|
||||||
import com.sun.source.util.JavacTask;
|
import com.sun.source.util.JavacTask;
|
||||||
import com.sun.tools.javac.api.JavacTool;
|
import com.sun.tools.javac.api.JavacTool;
|
||||||
import com.sun.tools.javac.code.Flags;
|
import com.sun.tools.javac.code.Flags;
|
||||||
import com.sun.tools.javac.parser.EndPosTable;
|
import com.sun.tools.javac.tree.EndPosTable;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
import com.sun.tools.javac.tree.JCTree.JCNewClass;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue