langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java
author ksrini
Thu, 18 Feb 2016 12:48:11 -0800
changeset 36045 9643bffe2105
parent 35346 c0614a805fad
child 36526 3b41f1c69604
permissions -rw-r--r--
8150096: Cleanup synthetic JCCompilationUnit for html files Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
     2
 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3149
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3149
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3149
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3149
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3149
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.api;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    28
import java.io.FileNotFoundException;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    29
import java.io.IOException;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    30
import java.text.BreakIterator;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    31
import java.util.HashMap;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    32
import java.util.HashSet;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    33
import java.util.Map;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    34
import java.util.Set;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    35
import java.util.regex.Matcher;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    36
import java.util.regex.Pattern;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
    37
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import javax.annotation.processing.ProcessingEnvironment;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import javax.lang.model.element.AnnotationMirror;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import javax.lang.model.element.AnnotationValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import javax.lang.model.element.Element;
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
    42
import javax.lang.model.element.ElementKind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import javax.lang.model.element.ExecutableElement;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    44
import javax.lang.model.element.Modifier;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    45
import javax.lang.model.element.NestingKind;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    46
import javax.lang.model.element.PackageElement;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import javax.lang.model.element.TypeElement;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
import javax.lang.model.type.DeclaredType;
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
    49
import javax.lang.model.type.TypeKind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import javax.lang.model.type.TypeMirror;
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
    51
import javax.tools.Diagnostic;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    52
import javax.tools.FileObject;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    53
import javax.tools.ForwardingFileObject;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import javax.tools.JavaCompiler;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    55
import javax.tools.JavaFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
import javax.tools.JavaFileObject;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    57
import javax.tools.JavaFileObject.Kind;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    58
import javax.tools.StandardLocation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    60
import com.sun.source.doctree.DocCommentTree;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
    61
import com.sun.source.doctree.DocTree;
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
    62
import com.sun.source.tree.CatchTree;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
import com.sun.source.tree.CompilationUnitTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
import com.sun.source.tree.Scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
import com.sun.source.tree.Tree;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
    66
import com.sun.source.util.DocSourcePositions;
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
    67
import com.sun.source.util.DocTreePath;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
    68
import com.sun.source.util.DocTreeScanner;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    69
import com.sun.source.util.DocTrees;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
    70
import com.sun.source.util.JavacTask;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
import com.sun.source.util.TreePath;
6590
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
    72
import com.sun.tools.javac.code.Flags;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    73
import com.sun.tools.javac.code.Scope.NamedImportScope;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    74
import com.sun.tools.javac.code.Scope.StarImportScope;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    75
import com.sun.tools.javac.code.Scope.WriteableScope;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
    76
import com.sun.tools.javac.code.Symbol;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
import com.sun.tools.javac.code.Symbol.ClassSymbol;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    78
import com.sun.tools.javac.code.Symbol.MethodSymbol;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    79
import com.sun.tools.javac.code.Symbol.PackageSymbol;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
import com.sun.tools.javac.code.Symbol.TypeSymbol;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    81
import com.sun.tools.javac.code.Symbol.VarSymbol;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
    82
import com.sun.tools.javac.code.Symtab;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    83
import com.sun.tools.javac.code.Type;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    84
import com.sun.tools.javac.code.Type.ArrayType;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    85
import com.sun.tools.javac.code.Type.ClassType;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    86
import com.sun.tools.javac.code.Type.ErrorType;
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
    87
import com.sun.tools.javac.code.Type.UnionClassType;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    88
import com.sun.tools.javac.code.Types;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
    89
import com.sun.tools.javac.code.Types.TypeRelation;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
import com.sun.tools.javac.comp.Attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
import com.sun.tools.javac.comp.Enter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
import com.sun.tools.javac.comp.MemberEnter;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
import com.sun.tools.javac.comp.Resolve;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    96
import com.sun.tools.javac.file.BaseFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
import com.sun.tools.javac.model.JavacElements;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    98
import com.sun.tools.javac.parser.DocCommentParser;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
    99
import com.sun.tools.javac.parser.ParserFactory;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   100
import com.sun.tools.javac.parser.Tokens.Comment;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   101
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 13845
diff changeset
   102
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   103
import com.sun.tools.javac.tree.DCTree;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   104
import com.sun.tools.javac.tree.DCTree.DCBlockTag;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   105
import com.sun.tools.javac.tree.DCTree.DCDocComment;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   106
import com.sun.tools.javac.tree.DCTree.DCEndPosTree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   107
import com.sun.tools.javac.tree.DCTree.DCErroneous;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   108
import com.sun.tools.javac.tree.DCTree.DCIdentifier;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   109
import com.sun.tools.javac.tree.DCTree.DCParam;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   110
import com.sun.tools.javac.tree.DCTree.DCReference;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   111
import com.sun.tools.javac.tree.DCTree.DCText;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
   112
import com.sun.tools.javac.tree.DocCommentTable;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   113
import com.sun.tools.javac.tree.DocTreeMaker;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12016
diff changeset
   114
import com.sun.tools.javac.tree.EndPosTable;
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   115
import com.sun.tools.javac.tree.JCTree;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   116
import com.sun.tools.javac.tree.JCTree.JCBlock;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   117
import com.sun.tools.javac.tree.JCTree.JCCatch;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   118
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   119
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   120
import com.sun.tools.javac.tree.JCTree.JCExpression;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   121
import com.sun.tools.javac.tree.JCTree.JCIdent;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   122
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   123
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
import com.sun.tools.javac.tree.TreeCopier;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
import com.sun.tools.javac.tree.TreeInfo;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
import com.sun.tools.javac.tree.TreeMaker;
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   127
import com.sun.tools.javac.util.Abort;
10631
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   128
import com.sun.tools.javac.util.Assert;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
import com.sun.tools.javac.util.Context;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   130
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   131
import com.sun.tools.javac.util.DefinedBy.Api;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   132
import com.sun.tools.javac.util.DiagnosticSource;
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
   133
import com.sun.tools.javac.util.JCDiagnostic;
28455
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 27224
diff changeset
   134
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
import com.sun.tools.javac.util.List;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   136
import com.sun.tools.javac.util.ListBuffer;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
import com.sun.tools.javac.util.Log;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   138
import com.sun.tools.javac.util.Name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   139
import com.sun.tools.javac.util.Names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
import com.sun.tools.javac.util.Pair;
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   141
import com.sun.tools.javac.util.Position;
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   142
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   143
import static com.sun.tools.javac.code.Kinds.Kind.*;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   144
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
 * Provides an implementation of Trees.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
   149
 * <p><b>This is NOT part of any supported API.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
 * If you write code that depends on this, you do so at your own
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
 * risk.  This code and its internal interfaces are subject to change
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
 * or deletion without notice.</b></p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
 */
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   156
public class JavacTrees extends DocTrees {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
6717
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   158
    // in a world of a single context per compilation, these would all be final
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   159
    private Resolve resolve;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   160
    private Enter enter;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   161
    private Log log;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   162
    private MemberEnter memberEnter;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   163
    private Attr attr;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   164
    private TreeMaker treeMaker;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   165
    private JavacElements elements;
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   166
    private JavacTaskImpl javacTaskImpl;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   167
    private Names names;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   168
    private Types types;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   169
    private DocTreeMaker docTreeMaker;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   170
    private BreakIterator breakIterator;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   171
    private JavaFileManager fileManager;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   172
    private ParserFactory parser;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
   173
    private Symtab syms;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
   174
    private Map<JavaFileObject, PackageSymbol> javaFileObjectToPackageMap;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   176
    // called reflectively from Trees.instance(CompilationTask task)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    public static JavacTrees instance(JavaCompiler.CompilationTask task) {
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14541
diff changeset
   178
        if (!(task instanceof BasicJavacTask))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            throw new IllegalArgumentException();
14548
aa687b312c97 8001098: Provide a simple light-weight "plug-in" mechanism for javac
jjg
parents: 14541
diff changeset
   180
        return instance(((BasicJavacTask)task).getContext());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   183
    // called reflectively from Trees.instance(ProcessingEnvironment env)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public static JavacTrees instance(ProcessingEnvironment env) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        if (!(env instanceof JavacProcessingEnvironment))
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        return instance(((JavacProcessingEnvironment)env).getContext());
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public static JavacTrees instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        JavacTrees instance = context.get(JavacTrees.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            instance = new JavacTrees(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
13845
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
   197
    protected JavacTrees(Context context) {
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
   198
        javaFileObjectToPackageMap = new HashMap<>();
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   199
        this.breakIterator = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        context.put(JavacTrees.class, this);
6717
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   201
        init(context);
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   202
    }
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   203
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   204
    public void updateContext(Context context) {
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   205
        init(context);
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   206
    }
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   207
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
   208
    private void init(Context context) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        attr = Attr.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        enter = Enter.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        elements = JavacElements.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        resolve = Resolve.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        treeMaker = TreeMaker.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        memberEnter = MemberEnter.instance(context);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   216
        names = Names.instance(context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   217
        types = Types.instance(context);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   218
        docTreeMaker = DocTreeMaker.instance(context);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   219
        parser = ParserFactory.instance(context);
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
   220
        syms = Symtab.instance(context);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   221
        fileManager = context.get(JavaFileManager.class);
12016
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   222
        JavacTask t = context.get(JavacTask.class);
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   223
        if (t instanceof JavacTaskImpl)
1990493b64db 7093891: support multiple task listeners
jjg
parents: 11055
diff changeset
   224
            javacTaskImpl = (JavacTaskImpl) t;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   227
    @Override @DefinedBy(Api.COMPILER_TREE)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   228
    public BreakIterator getBreakIterator() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   229
        return breakIterator;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   230
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   231
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   232
    @Override @DefinedBy(Api.COMPILER_TREE)
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   233
    public DocSourcePositions getSourcePositions() {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   234
        return new DocSourcePositions() {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   235
                @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                public long getStartPosition(CompilationUnitTree file, Tree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                    return TreeInfo.getStartPos((JCTree) tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   240
                @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                public long getEndPosition(CompilationUnitTree file, Tree tree) {
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   242
                    EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   243
                    return TreeInfo.getEndPos((JCTree) tree, endPosTable);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                }
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   245
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   246
                @Override @DefinedBy(Api.COMPILER_TREE)
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   247
                public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   248
                    return ((DCTree) tree).getSourcePosition((DCDocComment) comment);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   249
                }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   250
                @Override  @DefinedBy(Api.COMPILER_TREE) @SuppressWarnings("fallthrough")
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   251
                public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   252
                    DCDocComment dcComment = (DCDocComment) comment;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   253
                    if (tree instanceof DCEndPosTree) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   254
                        int endPos = ((DCEndPosTree) tree).getEndPos(dcComment);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   255
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   256
                        if (endPos != Position.NOPOS) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   257
                            return endPos;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   258
                        }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   259
                    }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   260
                    int correction = 0;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   261
                    switch (tree.getKind()) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   262
                        case TEXT:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   263
                            DCText text = (DCText) tree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   264
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   265
                            return dcComment.comment.getSourcePos(text.pos + text.text.length());
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   266
                        case ERRONEOUS:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   267
                            DCErroneous err = (DCErroneous) tree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   268
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   269
                            return dcComment.comment.getSourcePos(err.pos + err.body.length());
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   270
                        case IDENTIFIER:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   271
                            DCIdentifier ident = (DCIdentifier) tree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   272
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   273
                            return dcComment.comment.getSourcePos(ident.pos + (ident.name != names.error ? ident.name.length() : 0));
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   274
                        case PARAM:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   275
                            DCParam param = (DCParam) tree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   276
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   277
                            if (param.isTypeParameter && param.getDescription().isEmpty()) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   278
                                correction = 1;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   279
                            }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   280
                        case AUTHOR: case DEPRECATED: case RETURN: case SEE:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   281
                        case SERIAL: case SERIAL_DATA: case SERIAL_FIELD: case SINCE:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   282
                        case THROWS: case UNKNOWN_BLOCK_TAG: case VERSION: {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   283
                            DocTree last = getLastChild(tree);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   284
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   285
                            if (last != null) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   286
                                return getEndPosition(file, comment, last) + correction;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   287
                            }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   288
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   289
                            DCBlockTag block = (DCBlockTag) tree;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   290
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   291
                            return dcComment.comment.getSourcePos(block.pos + block.getTagName().length() + 1);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   292
                        }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   293
                        default:
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   294
                            DocTree last = getLastChild(tree);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   295
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   296
                            if (last != null) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   297
                                return getEndPosition(file, comment, last);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   298
                            }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   299
                            break;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   300
                    }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   301
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   302
                    return Position.NOPOS;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   303
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   307
    @Override @DefinedBy(Api.COMPILER_TREE)
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   308
    public DocTreeMaker getDocTreeFactory() {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   309
        return docTreeMaker;
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   310
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   311
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   312
    private DocTree getLastChild(DocTree tree) {
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   313
        final DocTree[] last = new DocTree[] {null};
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   314
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   315
        tree.accept(new DocTreeScanner<Void, Void>() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   316
            @Override @DefinedBy(Api.COMPILER_TREE)
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   317
            public Void scan(DocTree node, Void p) {
17273
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   318
                if (node != null) last[0] = node;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   319
                return null;
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   320
            }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   321
        }, null);
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   322
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   323
        return last[0];
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   324
    }
d7ec6654aac9 8008174: DocTree API should provide start and end positions for tree nodes
jlahoda
parents: 14952
diff changeset
   325
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   326
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    public JCClassDecl getTree(TypeElement element) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
        return (JCClassDecl) getTree((Element) element);
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   331
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    public JCMethodDecl getTree(ExecutableElement method) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        return (JCMethodDecl) getTree((Element) method);
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   336
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    public JCTree getTree(Element element) {
23122
02c931d49ad2 6411385: Trees.getPath does not work for constructors
jlahoda
parents: 22165
diff changeset
   338
        return getTree(element, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   341
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    public JCTree getTree(Element e, AnnotationMirror a) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        return getTree(e, a, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   346
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    public JCTree getTree(Element e, AnnotationMirror a, AnnotationValue v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        if (treeTopLevel == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        return treeTopLevel.fst;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   354
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    public TreePath getPath(CompilationUnitTree unit, Tree node) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        return TreePath.getPath(unit, node);
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   359
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
    public TreePath getPath(Element e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        return getPath(e, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   364
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
    public TreePath getPath(Element e, AnnotationMirror a) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        return getPath(e, a, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   369
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    public TreePath getPath(Element e, AnnotationMirror a, AnnotationValue v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        final Pair<JCTree, JCCompilationUnit> treeTopLevel = elements.getTreeAndTopLevel(e, a, v);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        if (treeTopLevel == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        return TreePath.getPath(treeTopLevel.snd, treeTopLevel.fst);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   377
    @Override @DefinedBy(Api.COMPILER_TREE)
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   378
    public Symbol getElement(TreePath path) {
6590
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   379
        JCTree tree = (JCTree) path.getLeaf();
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   380
        Symbol sym = TreeInfo.symbolFor(tree);
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   381
        if (sym == null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   382
            if (TreeInfo.isDeclaration(tree)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   383
                for (TreePath p = path; p != null; p = p.getParentPath()) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   384
                    JCTree t = (JCTree) p.getLeaf();
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   385
                    if (t.hasTag(JCTree.Tag.CLASSDEF)) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   386
                        JCClassDecl ct = (JCClassDecl) t;
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   387
                        if (ct.sym != null) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   388
                            if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   389
                                attr.attribClass(ct.pos(), ct.sym);
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   390
                                sym = TreeInfo.symbolFor(tree);
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   391
                            }
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   392
                            break;
6590
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   393
                        }
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   394
                    }
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   395
                }
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   396
            }
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   397
        }
f745e683da2c 6930507: Symbols for anonymous and local classes made too late for use by java tree API
jjg
parents: 5847
diff changeset
   398
        return sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
   401
    @Override @DefinedBy(Api.COMPILER_TREE)
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   402
    public Element getElement(DocTreePath path) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   403
        DocTree forTree = path.getLeaf();
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   404
        if (forTree instanceof DCReference)
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   405
            return attributeDocReference(path.getTreePath(), ((DCReference) forTree));
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   406
        if (forTree instanceof DCIdentifier) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   407
            if (path.getParentPath().getLeaf() instanceof DCParam) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   408
                return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   409
            }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   410
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   411
        return null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   412
    }
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   413
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   414
    @Override @DefinedBy(Api.COMPILER_TREE)
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   415
    public java.util.List<DocTree> getFirstSentence(java.util.List<? extends DocTree> list) {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   416
        return docTreeMaker.getFirstSentence(list);
33360
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   417
    }
d8ef08003d35 8078320: Improve DocTrees parsing.
ksrini
parents: 31751
diff changeset
   418
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   419
    private Symbol attributeDocReference(TreePath path, DCReference ref) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   420
        Env<AttrContext> env = getAttrContext(path);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   421
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   422
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   423
                new Log.DeferredDiagnosticHandler(log);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   424
        try {
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   425
            final TypeSymbol tsym;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   426
            final Name memberName;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   427
            if (ref.qualifierExpression == null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   428
                tsym = env.enclClass.sym;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   429
                memberName = (Name) ref.memberName;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   430
            } else {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   431
                // newSeeTree if the qualifierExpression is a type or package name.
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   432
                // javac does not provide the exact method required, so
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   433
                // we first check if qualifierExpression identifies a type,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   434
                // and if not, then we check to see if it identifies a package.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   435
                Type t = attr.attribType(ref.qualifierExpression, env);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   436
                if (t.isErroneous()) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   437
                    if (ref.memberName == null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   438
                        // Attr/Resolve assume packages exist and create symbols as needed
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   439
                        // so use getPackageElement to restrict search to existing packages
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   440
                        PackageSymbol pck = elements.getPackageElement(ref.qualifierExpression.toString());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   441
                        if (pck != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   442
                            return pck;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   443
                        } else if (ref.qualifierExpression.hasTag(JCTree.Tag.IDENT)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   444
                            // fixup:  allow "identifier" instead of "#identifier"
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   445
                            // for compatibility with javadoc
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   446
                            tsym = env.enclClass.sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   447
                            memberName = ((JCIdent) ref.qualifierExpression).name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   448
                        } else
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   449
                            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   450
                    } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   451
                        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   452
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   453
                } else {
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   454
                    tsym = t.tsym;
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   455
                    memberName = (Name) ref.memberName;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   456
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   457
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   458
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   459
            if (memberName == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   460
                return tsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   461
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   462
            final List<Type> paramTypes;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   463
            if (ref.paramTypes == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   464
                paramTypes = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   465
            else {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 19125
diff changeset
   466
                ListBuffer<Type> lb = new ListBuffer<>();
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   467
                for (List<JCTree> l = (List<JCTree>) ref.paramTypes; l.nonEmpty(); l = l.tail) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   468
                    JCTree tree = l.head;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   469
                    Type t = attr.attribType(tree, env);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   470
                    lb.add(t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   471
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   472
                paramTypes = lb.toList();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   473
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   474
24612
75dc732b45af 8042338: Refactor Types.upperBound to treat wildcards and variables separately
dlsmith
parents: 23122
diff changeset
   475
            ClassSymbol sym = (ClassSymbol) types.cvarUpperBound(tsym.type).tsym;
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   476
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   477
            Symbol msym = (memberName == sym.name)
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   478
                    ? findConstructor(sym, paramTypes)
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   479
                    : findMethod(sym, memberName, paramTypes);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   480
            if (paramTypes != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   481
                // explicit (possibly empty) arg list given, so cannot be a field
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   482
                return msym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   483
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   484
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   485
            VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   486
            // prefer a field over a method with no parameters
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   487
            if (vsym != null &&
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   488
                    (msym == null ||
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   489
                        types.isSubtypeUnchecked(vsym.enclClass().asType(), msym.enclClass().asType()))) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   490
                return vsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   491
            } else {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   492
                return msym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   493
            }
14952
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   494
        } catch (Abort e) { // may be thrown by Check.completionError in case of bad class file
d0022ae20516 8004832: Add new doclint package
jjg
parents: 14548
diff changeset
   495
            return null;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   496
        } finally {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   497
            log.popDiagnosticHandler(deferredDiagnosticHandler);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   498
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   499
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   500
17549
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   501
    private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   502
        Symbol javadocSymbol = getElement(path);
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   503
        if (javadocSymbol == null)
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   504
            return null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   505
        ElementKind kind = javadocSymbol.getKind();
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   506
        List<? extends Symbol> params = List.nil();
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   507
        if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   508
            MethodSymbol ee = (MethodSymbol) javadocSymbol;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   509
            params = ptag.isTypeParameter()
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   510
                    ? ee.getTypeParameters()
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   511
                    : ee.getParameters();
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   512
        } else if (kind.isClass() || kind.isInterface()) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   513
            ClassSymbol te = (ClassSymbol) javadocSymbol;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   514
            params = te.getTypeParameters();
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   515
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   516
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   517
        for (Symbol param : params) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   518
            if (param.getSimpleName() == ptag.getName().getName()) {
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   519
                return param;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   520
            }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   521
        }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   522
        return null;
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   523
    }
65ea6f3b72d9 8009724: Enhance the DocTree API with DocTreePath
jlahoda
parents: 17273
diff changeset
   524
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   525
    /** @see com.sun.tools.javadoc.ClassDocImpl#findField */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   526
    private VarSymbol findField(ClassSymbol tsym, Name fieldName) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   527
        return searchField(tsym, fieldName, new HashSet<>());
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   528
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   529
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   530
    /** @see com.sun.tools.javadoc.ClassDocImpl#searchField */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   531
    private VarSymbol searchField(ClassSymbol tsym, Name fieldName, Set<ClassSymbol> searched) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   532
        if (searched.contains(tsym)) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   533
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   534
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   535
        searched.add(tsym);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   536
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   537
        for (Symbol sym : tsym.members().getSymbolsByName(fieldName)) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   538
            if (sym.kind == VAR) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   539
                return (VarSymbol)sym;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   540
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   541
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   542
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   543
        //### If we found a VarSymbol above, but which did not pass
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   544
        //### the modifier filter, we should return failure here!
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   545
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   546
        ClassSymbol encl = tsym.owner.enclClass();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   547
        if (encl != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   548
            VarSymbol vsym = searchField(encl, fieldName, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   549
            if (vsym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   550
                return vsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   551
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   552
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   553
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   554
        // search superclass
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   555
        Type superclass = tsym.getSuperclass();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   556
        if (superclass.tsym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   557
            VarSymbol vsym = searchField((ClassSymbol) superclass.tsym, fieldName, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   558
            if (vsym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   559
                return vsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   560
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   561
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   562
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   563
        // search interfaces
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   564
        List<Type> intfs = tsym.getInterfaces();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   565
        for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   566
            Type intf = l.head;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   567
            if (intf.isErroneous()) continue;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   568
            VarSymbol vsym = searchField((ClassSymbol) intf.tsym, fieldName, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   569
            if (vsym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   570
                return vsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   571
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   572
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   573
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   574
        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   575
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   576
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   577
    /** @see com.sun.tools.javadoc.ClassDocImpl#findConstructor */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   578
    MethodSymbol findConstructor(ClassSymbol tsym, List<Type> paramTypes) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   579
        for (Symbol sym : tsym.members().getSymbolsByName(names.init)) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   580
            if (sym.kind == MTH) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   581
                if (hasParameterTypes((MethodSymbol) sym, paramTypes)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   582
                    return (MethodSymbol) sym;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   583
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   584
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   585
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   586
        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   587
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   588
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   589
    /** @see com.sun.tools.javadoc.ClassDocImpl#findMethod */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   590
    private MethodSymbol findMethod(ClassSymbol tsym, Name methodName, List<Type> paramTypes) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   591
        return searchMethod(tsym, methodName, paramTypes, new HashSet<>());
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   592
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   593
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   594
    /** @see com.sun.tools.javadoc.ClassDocImpl#searchMethod */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   595
    private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   596
                                       List<Type> paramTypes, Set<ClassSymbol> searched) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   597
        //### Note that this search is not necessarily what the compiler would do!
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   598
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   599
        // do not match constructors
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   600
        if (methodName == names.init)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   601
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   602
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   603
        if (searched.contains(tsym))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   604
            return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   605
        searched.add(tsym);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   606
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   607
        // search current class
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   608
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   609
        //### Using modifier filter here isn't really correct,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   610
        //### but emulates the old behavior.  Instead, we should
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   611
        //### apply the normal rules of visibility and inheritance.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   612
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   613
        if (paramTypes == null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   614
            // If no parameters specified, we are allowed to return
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   615
            // any method with a matching name.  In practice, the old
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   616
            // code returned the first method, which is now the last!
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   617
            // In order to provide textually identical results, we
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   618
            // attempt to emulate the old behavior.
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   619
            MethodSymbol lastFound = null;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   620
            for (Symbol sym : tsym.members().getSymbolsByName(methodName)) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   621
                if (sym.kind == MTH) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   622
                    if (sym.name == methodName) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   623
                        lastFound = (MethodSymbol)sym;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   624
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   625
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   626
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   627
            if (lastFound != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   628
                return lastFound;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   629
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   630
        } else {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   631
            for (Symbol sym : tsym.members().getSymbolsByName(methodName)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   632
                if (sym != null &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   633
                    sym.kind == MTH) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   634
                    if (hasParameterTypes((MethodSymbol) sym, paramTypes)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   635
                        return (MethodSymbol) sym;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   636
                    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   637
                }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   638
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   639
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   640
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   641
        //### If we found a MethodSymbol above, but which did not pass
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   642
        //### the modifier filter, we should return failure here!
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   643
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   644
        // search superclass
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   645
        Type superclass = tsym.getSuperclass();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   646
        if (superclass.tsym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   647
            MethodSymbol msym = searchMethod((ClassSymbol) superclass.tsym, methodName, paramTypes, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   648
            if (msym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   649
                return msym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   650
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   651
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   652
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   653
        // search interfaces
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   654
        List<Type> intfs = tsym.getInterfaces();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   655
        for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   656
            Type intf = l.head;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   657
            if (intf.isErroneous()) continue;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   658
            MethodSymbol msym = searchMethod((ClassSymbol) intf.tsym, methodName, paramTypes, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   659
            if (msym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   660
                return msym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   661
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   662
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   663
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   664
        // search enclosing class
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   665
        ClassSymbol encl = tsym.owner.enclClass();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   666
        if (encl != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   667
            MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   668
            if (msym != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   669
                return msym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   670
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   671
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   672
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   673
        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   674
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   675
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   676
    /** @see com.sun.tools.javadoc.ClassDocImpl */
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   677
    private boolean hasParameterTypes(MethodSymbol method, List<Type> paramTypes) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   678
        if (paramTypes == null)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   679
            return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   680
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   681
        if (method.params().size() != paramTypes.size())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   682
            return false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   683
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   684
        List<Type> methodParamTypes = types.erasureRecursive(method.asType()).getParameterTypes();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   685
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   686
        return (Type.isErroneous(paramTypes))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   687
            ? fuzzyMatch(paramTypes, methodParamTypes)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   688
            : types.isSameTypes(paramTypes, methodParamTypes);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   689
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   690
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   691
    boolean fuzzyMatch(List<Type> paramTypes, List<Type> methodParamTypes) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   692
        List<Type> l1 = paramTypes;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   693
        List<Type> l2 = methodParamTypes;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   694
        while (l1.nonEmpty()) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   695
            if (!fuzzyMatch(l1.head, l2.head))
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   696
                return false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   697
            l1 = l1.tail;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   698
            l2 = l2.tail;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   699
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   700
        return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   701
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   702
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   703
    boolean fuzzyMatch(Type paramType, Type methodParamType) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   704
        Boolean b = fuzzyMatcher.visit(paramType, methodParamType);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   705
        return (b == Boolean.TRUE);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   706
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   707
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   708
    TypeRelation fuzzyMatcher = new TypeRelation() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   709
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   710
        public Boolean visitType(Type t, Type s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   711
            if (t == s)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   712
                return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   713
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   714
            if (s.isPartial())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   715
                return visit(s, t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   716
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   717
            switch (t.getTag()) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   718
            case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   719
            case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE:
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 17557
diff changeset
   720
                return t.hasTag(s.getTag());
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   721
            default:
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   722
                throw new AssertionError("fuzzyMatcher " + t.getTag());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   723
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   724
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   725
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   726
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   727
        public Boolean visitArrayType(ArrayType t, Type s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   728
            if (t == s)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   729
                return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   730
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   731
            if (s.isPartial())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   732
                return visit(s, t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   733
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 17557
diff changeset
   734
            return s.hasTag(ARRAY)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   735
                && visit(t.elemtype, types.elemtype(s));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   736
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   737
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   738
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   739
        public Boolean visitClassType(ClassType t, Type s) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   740
            if (t == s)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   741
                return true;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   742
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   743
            if (s.isPartial())
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   744
                return visit(s, t);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   745
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   746
            return t.tsym == s.tsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   747
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   748
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   749
        @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   750
        public Boolean visitErrorType(ErrorType t, Type s) {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 17557
diff changeset
   751
            return s.hasTag(CLASS)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   752
                    && t.tsym.name == ((ClassType) s).tsym.name;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   753
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   754
    };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   755
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   756
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
    public TypeMirror getTypeMirror(TreePath path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        Tree t = path.getLeaf();
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28455
diff changeset
   759
        Type ty = ((JCTree)t).type;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 28455
diff changeset
   760
        return ty == null ? null : ty.stripMetadataIfNeeded();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   763
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
    public JavacScope getScope(TreePath path) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 25287
diff changeset
   765
        return JavacScope.create(getAttrContext(path));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   768
    @Override @DefinedBy(Api.COMPILER_TREE)
7631
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   769
    public String getDocComment(TreePath path) {
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   770
        CompilationUnitTree t = path.getCompilationUnit();
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12016
diff changeset
   771
        Tree leaf = path.getLeaf();
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12016
diff changeset
   772
        if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
7631
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   773
            JCCompilationUnit cu = (JCCompilationUnit) t;
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   774
            if (cu.docComments != null) {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12016
diff changeset
   775
                return cu.docComments.getCommentText((JCTree) leaf);
7631
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   776
            }
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   777
        }
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   778
        return null;
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   779
    }
57bce845dcee 6985202: no access to doc comments from Tree API
jjg
parents: 7209
diff changeset
   780
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   781
    @Override @DefinedBy(Api.COMPILER_TREE)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   782
    public DocCommentTree getDocCommentTree(TreePath path) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   783
        CompilationUnitTree t = path.getCompilationUnit();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   784
        Tree leaf = path.getLeaf();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   785
        if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   786
            JCCompilationUnit cu = (JCCompilationUnit) t;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   787
            if (cu.docComments != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   788
                return cu.docComments.getCommentTree((JCTree) leaf);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   789
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   790
        }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   791
        return null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   792
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
   793
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   794
    @Override @DefinedBy(Api.COMPILER_TREE)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   795
    public DocCommentTree getDocCommentTree(Element e) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   796
        TreePath path = getPath(e);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   797
        if (path == null) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   798
            return null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   799
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   800
        return getDocCommentTree(path);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   801
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   802
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   803
    @Override @DefinedBy(Api.COMPILER_TREE)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   804
    public DocCommentTree getDocCommentTree(Element e, String relativeFileName) throws IOException {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   805
        PackageElement pkg = elements.getPackageOf(e);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   806
        FileObject fileForInput = fileManager.getFileForInput(StandardLocation.SOURCE_PATH,
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   807
                pkg.getQualifiedName().toString(), relativeFileName);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   808
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   809
        if (fileForInput == null) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   810
            throw new FileNotFoundException(relativeFileName);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   811
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   812
        return getDocCommentTree(fileForInput);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   813
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   814
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   815
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
    public boolean isAccessible(Scope scope, TypeElement type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
        if (scope instanceof JavacScope && type instanceof ClassSymbol) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
            Env<AttrContext> env = ((JavacScope) scope).env;
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 7077
diff changeset
   819
            return resolve.isAccessible(env, (ClassSymbol)type, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   824
    @Override @DefinedBy(Api.COMPILER_TREE)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
    public boolean isAccessible(Scope scope, Element member, DeclaredType type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        if (scope instanceof JavacScope
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
                && member instanceof Symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                && type instanceof com.sun.tools.javac.code.Type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
            Env<AttrContext> env = ((JavacScope) scope).env;
7209
889e80aa1d2e 6598108: com.sun.source.util.Trees.isAccessible incorrect
mcimadamore
parents: 7077
diff changeset
   830
            return resolve.isAccessible(env, (com.sun.tools.javac.code.Type)type, (Symbol)member, true);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
        } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
    private Env<AttrContext> getAttrContext(TreePath path) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
        if (!(path.getLeaf() instanceof JCTree))  // implicit null-check
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
10631
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   839
        // if we're being invoked from a Tree API client via parse/enter/analyze,
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   840
        // we need to make sure all the classes have been entered;
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   841
        // if we're being invoked from JSR 199 or JSR 269, then the classes
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   842
        // will already have been entered.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
        if (javacTaskImpl != null) {
26264
a09fedde76be 8044859: javac duplicates option processing when using Compiler API
jjg
parents: 25874
diff changeset
   844
            javacTaskImpl.enter(null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        JCCompilationUnit unit = (JCCompilationUnit) path.getCompilationUnit();
13845
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
   848
        Copier copier = createCopier(treeMaker.forToplevel(unit));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
        Env<AttrContext> env = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        JCMethodDecl method = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
        JCVariableDecl field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
        List<Tree> l = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
        TreePath p = path;
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        while (p != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            l = l.prepend(p.getLeaf());
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            p = p.getParentPath();
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
        for ( ; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
            Tree tree = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            switch (tree.getKind()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
                case COMPILATION_UNIT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
//                    System.err.println("COMP: " + ((JCCompilationUnit)tree).sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
                    env = enter.getTopLevelEnv((JCCompilationUnit)tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
                    break;
7077
55689b828dc5 6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents: 6717
diff changeset
   868
                case ANNOTATION_TYPE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
                case CLASS:
7077
55689b828dc5 6993304: JavacTrees.getAttrContext not updated to Tree.Kind.{ANNOTATION_TYPE,ENUM,INTERFACE}
jjg
parents: 6717
diff changeset
   870
                case ENUM:
6600
b3bb16faccc2 6985181: Annotations lost from classfile
jjg
parents: 6590
diff changeset
   871
                case INTERFACE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
//                    System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
                    env = enter.getClassEnv(((JCClassDecl)tree).sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
                case METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
//                    System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
                    method = (JCMethodDecl)tree;
19125
db8cab0ecbd9 8020556: doclint does not check type variables for @throws
jjg
parents: 18646
diff changeset
   878
                    env = memberEnter.getMethodEnv(method, env);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
                case VARIABLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
//                    System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
                    field = (JCVariableDecl)tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                case BLOCK: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
//                    System.err.println("BLOCK: ");
10631
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   886
                    if (method != null) {
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   887
                        try {
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   888
                            Assert.check(method.body == tree);
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   889
                            method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   890
                            env = attribStatToTree(method.body, env, copier.leafCopy);
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   891
                        } finally {
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   892
                            method.body = (JCBlock) tree;
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   893
                        }
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   894
                    } else {
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   895
                        JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   896
                        env = attribStatToTree(body, env, copier.leafCopy);
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   897
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                    return env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
//                    System.err.println("DEFAULT: " + tree.getKind());
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
                    if (field != null && field.getInitializer() == tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                        env = memberEnter.getInitEnv(field, env);
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                        JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf());
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
                        env = attribExprToTree(expr, env, copier.leafCopy);
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
                        return env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
        }
10631
d9914010b902 7090249: IllegalStateException from Trees.getScope when called from JSR 199
jjg
parents: 9599
diff changeset
   910
        return (field != null) ? memberEnter.getInitEnv(field, env) : env;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
    private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
            return attr.attribStatToTree(stat, env, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
    private Env<AttrContext> attribExprToTree(JCExpression expr, Env<AttrContext>env, JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
        JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            return attr.attribExprToTree(expr, env, tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            log.useSource(prev);
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   931
    static JavaFileObject asJavaFileObject(FileObject fileObject) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   932
        JavaFileObject jfo = null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   933
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   934
        if (fileObject instanceof JavaFileObject) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   935
            jfo = (JavaFileObject) fileObject;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   936
            checkHtmlKind(fileObject, Kind.HTML);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   937
            return jfo;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   938
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   939
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   940
        checkHtmlKind(fileObject);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   941
        jfo = new HtmlFileObject(fileObject);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   942
        return jfo;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   943
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   944
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   945
    private static void checkHtmlKind(FileObject fileObject) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   946
        checkHtmlKind(fileObject, BaseFileManager.getKind(fileObject.getName()));
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   947
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   948
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
   949
    private static void checkHtmlKind(FileObject fileObject, JavaFileObject.Kind kind) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   950
        if (kind != JavaFileObject.Kind.HTML) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   951
            throw new IllegalArgumentException("HTML file expected:" + fileObject.getName());
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   952
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   953
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   954
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   955
    private static class HtmlFileObject extends ForwardingFileObject<FileObject>
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   956
            implements JavaFileObject {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   957
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   958
        public HtmlFileObject(FileObject fileObject) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   959
            super(fileObject);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   960
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   961
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   962
        @Override @DefinedBy(Api.COMPILER)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   963
        public Kind getKind() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   964
            return BaseFileManager.getKind(fileObject.getName());
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   965
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   966
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   967
        @Override @DefinedBy(Api.COMPILER)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   968
        public boolean isNameCompatible(String simpleName, Kind kind) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   969
            return false;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   970
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   971
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   972
        @Override @DefinedBy(Api.COMPILER)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   973
        public NestingKind getNestingKind() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   974
            return null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   975
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   976
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   977
        @Override @DefinedBy(Api.COMPILER)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   978
        public Modifier getAccessLevel() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   979
            return null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   980
        }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   981
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   982
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   983
    @Override @DefinedBy(Api.COMPILER_TREE)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   984
    public DocCommentTree getDocCommentTree(FileObject fileObject) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   985
        JavaFileObject jfo = asJavaFileObject(fileObject);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   986
        DiagnosticSource diagSource = new DiagnosticSource(jfo, log);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   987
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   988
        final Comment comment = new Comment() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   989
            int offset = 0;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   990
            @Override
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   991
            public String getText() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   992
                try {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   993
                    CharSequence rawDoc = fileObject.getCharContent(true);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   994
                    Pattern bodyPat =
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   995
                            Pattern.compile("(?is).*?<body\\b[^>]*>(.*)</body\\b.*");
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   996
                    Matcher m = bodyPat.matcher(rawDoc);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   997
                    if (m.matches()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   998
                        offset = m.end(1);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
   999
                        return m.group(1);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1000
                    } else {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1001
                        // Assume doclint will do the right thing.
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1002
                        return "";
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1003
                    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1004
                } catch (IOException ignore) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1005
                    // do nothing
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1006
                }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1007
                return "";
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1008
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1009
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1010
            @Override
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1011
            public int getSourcePos(int index) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1012
                return offset + index;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1013
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1014
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1015
            @Override
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1016
            public CommentStyle getStyle() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1017
                throw new UnsupportedOperationException();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1018
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1019
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1020
            @Override
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1021
            public boolean isDeprecated() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1022
                throw new UnsupportedOperationException();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1023
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1024
        };
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1025
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1026
        return new DocCommentParser(parser, diagSource, comment).parse();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1027
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1028
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1029
    @Override @DefinedBy(Api.COMPILER_TREE)
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1030
    public DocTreePath getDocTreePath(FileObject fileObject) {
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1031
        JavaFileObject jfo = asJavaFileObject(fileObject);
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1032
        DocCommentTree docCommentTree = getDocCommentTree(jfo);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1033
        return new DocTreePath(makeTreePath(jfo, docCommentTree), docCommentTree);
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1034
    }
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1035
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1036
    @Override @DefinedBy(Api.COMPILER_TREE)
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1037
    public void setBreakIterator(BreakIterator breakiterator) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1038
        this.breakIterator = breakiterator;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1039
    }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1040
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
     * Makes a copy of a tree, noting the value resulting from copying a particular leaf.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
     **/
13845
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1044
    protected static class Copier extends TreeCopier<JCTree> {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
        JCTree leafCopy = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
13845
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1047
        protected Copier(TreeMaker M) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
            super(M);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
6717
0103d76cfe48 6986246: Trees object is round-specific
jjg
parents: 6600
diff changeset
  1051
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
        public <T extends JCTree> T copy(T t, JCTree leaf) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
            T t2 = super.copy(t, leaf);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            if (t == leaf)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                leafCopy = t2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
            return t2;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
    }
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1059
13845
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1060
    protected Copier createCopier(TreeMaker maker) {
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1061
        return new Copier(maker);
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1062
    }
bbb35ad7a9c1 7192073: (javac) minor refactoring of tree maker to help IDEs
ksrini
parents: 13077
diff changeset
  1063
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1064
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 24612
diff changeset
  1065
     * Returns the original type from the ErrorType object.
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1066
     * @param errorType The errorType for which we want to get the original type.
31751
ec251536a004 8080880: some docs cleanup for langtools
avstepan
parents: 29842
diff changeset
  1067
     * @return TypeMirror corresponding to the original type, replaced by the ErrorType.
ec251536a004 8080880: some docs cleanup for langtools
avstepan
parents: 29842
diff changeset
  1068
     *         noType (type.tag == NONE) is returned if there is no original type.
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1069
     */
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1070
    @Override @DefinedBy(Api.COMPILER_TREE)
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1071
    public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1072
        if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1073
            return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1074
        }
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1075
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1076
        return com.sun.tools.javac.code.Type.noType;
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 10
diff changeset
  1077
    }
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1078
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1079
    /**
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1080
     * Prints a message of the specified kind at the location of the
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1081
     * tree within the provided compilation unit
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1082
     *
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1083
     * @param kind the kind of message
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1084
     * @param msg  the message, or an empty string if none
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1085
     * @param t    the tree to use as a position hint
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1086
     * @param root the compilation unit that contains tree
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1087
     */
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1088
    @Override @DefinedBy(Api.COMPILER_TREE)
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1089
    public void printMessage(Diagnostic.Kind kind, CharSequence msg,
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1090
            com.sun.source.tree.Tree t,
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1091
            com.sun.source.tree.CompilationUnitTree root) {
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1092
        printMessage(kind, msg, ((JCTree) t).pos(), root);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1093
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1094
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1095
    @Override @DefinedBy(Api.COMPILER_TREE)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1096
    public void printMessage(Diagnostic.Kind kind, CharSequence msg,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1097
            com.sun.source.doctree.DocTree t,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1098
            com.sun.source.doctree.DocCommentTree c,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1099
            com.sun.source.tree.CompilationUnitTree root) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1100
        printMessage(kind, msg, ((DCTree) t).pos((DCDocComment) c), root);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1101
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1102
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1103
    private void printMessage(Diagnostic.Kind kind, CharSequence msg,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1104
            JCDiagnostic.DiagnosticPosition pos,
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1105
            com.sun.source.tree.CompilationUnitTree root) {
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1106
        JavaFileObject oldSource = null;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1107
        JavaFileObject newSource = null;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1108
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1109
        newSource = root.getSourceFile();
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1110
        if (newSource == null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1111
            pos = null;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14258
diff changeset
  1112
        } else {
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1113
            oldSource = log.useSource(newSource);
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1114
        }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1115
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1116
        try {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1117
            switch (kind) {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1118
            case ERROR:
28455
41245007c074 8066843: Messager.printMessage cannot print multiple errors for same source position
jlahoda
parents: 27224
diff changeset
  1119
                log.error(DiagnosticFlag.MULTIPLE, pos, "proc.messager", msg.toString());
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1120
                break;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1121
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1122
            case WARNING:
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1123
                log.warning(pos, "proc.messager", msg.toString());
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1124
                break;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1125
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1126
            case MANDATORY_WARNING:
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1127
                log.mandatoryWarning(pos, "proc.messager", msg.toString());
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1128
                break;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1129
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1130
            default:
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1131
                log.note(pos, "proc.messager", msg.toString());
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1132
            }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1133
        } finally {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1134
            if (oldSource != null)
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1135
                log.useSource(oldSource);
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1136
        }
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 1264
diff changeset
  1137
    }
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1138
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 26264
diff changeset
  1139
    @Override @DefinedBy(Api.COMPILER_TREE)
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1140
    public TypeMirror getLub(CatchTree tree) {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1141
        JCCatch ct = (JCCatch) tree;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1142
        JCVariableDecl v = ct.param;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1143
        if (v.type != null && v.type.getKind() == TypeKind.UNION) {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1144
            UnionClassType ut = (UnionClassType) v.type;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1145
            return ut.getLub();
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1146
        } else {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1147
            return v.type;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1148
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 7631
diff changeset
  1149
    }
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1150
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1151
    /**
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1152
     * Register a file object, such as for a package.html, that provides
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1153
     * doc comments for a package.
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1154
     * @param psym the PackageSymbol representing the package.
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1155
     * @param jfo  the JavaFileObject for the given package.
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1156
     */
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1157
    public void putJavaFileObject(PackageSymbol psym, JavaFileObject jfo) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1158
        javaFileObjectToPackageMap.putIfAbsent(jfo, psym);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1159
    }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1160
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1161
    private TreePath makeTreePath(final JavaFileObject jfo, DocCommentTree dcTree) {
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1162
        JCCompilationUnit jcCompilationUnit = new JCCompilationUnit(List.nil()) {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1163
            public int getPos() {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1164
                return Position.FIRSTPOS;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1165
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1166
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1167
            public JavaFileObject getSourcefile() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1168
                return jfo;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1169
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1170
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1171
            @Override @DefinedBy(Api.COMPILER_TREE)
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1172
            public Position.LineMap getLineMap() {
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1173
                try {
35346
c0614a805fad 8146208: Add a public DocTreeFactory to the Compiler Tree API
jjg
parents: 33424
diff changeset
  1174
                    CharSequence content = jfo.getCharContent(true);
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1175
                    String s = content.toString();
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1176
                    return Position.makeLineMap(s.toCharArray(), s.length(), true);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1177
                } catch (IOException ignore) {}
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1178
                return null;
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1179
            }
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1180
        };
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1181
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1182
        PackageSymbol psym = javaFileObjectToPackageMap.getOrDefault(jfo, syms.unnamedPackage);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1183
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1184
        jcCompilationUnit.docComments = new DocCommentTable() {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1185
            @Override
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1186
            public boolean hasComment(JCTree tree) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1187
                return false;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1188
            }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1189
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1190
            @Override
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1191
            public Comment getComment(JCTree tree) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1192
                throw new UnsupportedOperationException();
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1193
            }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1194
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1195
            @Override
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1196
            public String getCommentText(JCTree tree) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1197
                throw new UnsupportedOperationException();
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1198
            }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1199
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1200
            @Override
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1201
            public DCDocComment getCommentTree(JCTree tree) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1202
                return (DCDocComment)dcTree;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1203
            }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1204
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1205
            @Override
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1206
            public void putComment(JCTree tree, Comment c) {
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1207
                throw new UnsupportedOperationException();
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1208
            }
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1209
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1210
        };
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1211
        jcCompilationUnit.lineMap = jcCompilationUnit.getLineMap();
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1212
        jcCompilationUnit.namedImportScope = new NamedImportScope(psym, jcCompilationUnit.toplevelScope);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1213
        jcCompilationUnit.packge = psym;
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1214
        jcCompilationUnit.starImportScope = null;
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1215
        jcCompilationUnit.sourcefile = jfo;
36045
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1216
        jcCompilationUnit.starImportScope = new StarImportScope(psym);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1217
        jcCompilationUnit.toplevelScope = WriteableScope.create(psym);
9643bffe2105 8150096: Cleanup synthetic JCCompilationUnit for html files
ksrini
parents: 35346
diff changeset
  1218
33424
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1219
        return new TreePath(jcCompilationUnit);
e6bd5406e2cf 8132096: Augment the Compiler Tree API to support the new Simplified Doclet API
ksrini
parents: 33360
diff changeset
  1220
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
}