diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java index 65ce640ef761f..67fe710a4bf84 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java @@ -207,7 +207,6 @@ private void prepareCompiler(boolean forParse) { // init JavaCompiler and queues compiler = JavaCompiler.instance(context); compiler.keepComments = true; - compiler.genEndPos = true; notYetEntered = new HashMap<>(); if (forParse) { compiler.initProcessAnnotations(processors, args.getFileObjects(), args.getClassNames()); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java index 22ee2393a023b..6bc5d358b6f28 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java @@ -114,7 +114,6 @@ import com.sun.tools.javac.tree.DCTree.DCReference; import com.sun.tools.javac.tree.DocCommentTable; import com.sun.tools.javac.tree.DocTreeMaker; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCCatch; @@ -240,8 +239,7 @@ public long getStartPosition(CompilationUnitTree file, Tree tree) { @Override @DefinedBy(Api.COMPILER_TREE) public long getEndPosition(CompilationUnitTree file, Tree tree) { - EndPosTable endPosTable = ((JCCompilationUnit) file).endPositions; - return TreeInfo.getEndPos((JCTree) tree, endPosTable); + return TreeInfo.getEndPos((JCTree) tree); } @Override @DefinedBy(Api.COMPILER_TREE) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java index 06caa70d478a6..4f33bb92b4129 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/LintMapper.java @@ -35,7 +35,6 @@ import javax.tools.JavaFileObject; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.TreeInfo; @@ -134,9 +133,9 @@ public Optional lintAt(JavaFileObject sourceFile, DiagnosticPosition pos) * @param sourceFile source file * @param tree top-level declaration (class, package, or module) */ - public void calculateLints(JavaFileObject sourceFile, JCTree tree, EndPosTable endPositions) { + public void calculateLints(JavaFileObject sourceFile, JCTree tree) { Assert.check(rootLint != null); - fileInfoMap.get(sourceFile).afterAttr(tree, endPositions); + fileInfoMap.get(sourceFile).afterAttr(tree); } /** @@ -184,15 +183,15 @@ private static class FileInfo { rootRange = new LintRange(rootLint); for (JCTree decl : tree.defs) { if (isTopLevelDecl(decl)) - unmappedDecls.add(new Span(decl, tree.endPositions)); + unmappedDecls.add(new Span(decl)); } } // After attribution: Discard the span from "unmappedDecls" and populate the declaration's subtree under "rootRange" - void afterAttr(JCTree tree, EndPosTable endPositions) { + void afterAttr(JCTree tree) { for (Iterator i = unmappedDecls.iterator(); i.hasNext(); ) { if (i.next().contains(tree.pos())) { - rootRange.populateSubtree(tree, endPositions); + rootRange.populateSubtree(tree); i.remove(); return; } @@ -225,8 +224,8 @@ private record Span(int startPos, int endPos) { static final Span MAXIMAL = new Span(Integer.MIN_VALUE, Integer.MAX_VALUE); - Span(JCTree tree, EndPosTable endPositions) { - this(TreeInfo.getStartPos(tree), TreeInfo.getEndPos(tree, endPositions)); + Span(JCTree tree) { + this(TreeInfo.getStartPos(tree), TreeInfo.getEndPos(tree)); } boolean contains(DiagnosticPosition pos) { @@ -256,8 +255,8 @@ private record LintRange( } // Create a node representing the given declaration and its corresponding Lint configuration - LintRange(JCTree tree, EndPosTable endPositions, Lint lint) { - this(new Span(tree, endPositions), lint, new LinkedList<>()); + LintRange(JCTree tree, Lint lint) { + this(new Span(tree), lint, new LinkedList<>()); } // Find the most specific node in this tree (including me) that contains the given position, if any @@ -277,7 +276,7 @@ LintRange bestMatch(DiagnosticPosition pos) { // Populate a sparse subtree corresponding to the given nested declaration. // Only when the Lint configuration differs from the parent is a node added. - void populateSubtree(JCTree tree, EndPosTable endPositions) { + void populateSubtree(JCTree tree) { new TreeScanner() { private LintRange currentNode = LintRange.this; @@ -320,7 +319,7 @@ private void scanDecl(T tree, Symbol symbol, Consumer annos = annoType.annotations; @@ -5311,7 +5310,7 @@ public void attrib(Env env) { annotate.flush(); // Now that this tree is attributed, we can calculate the Lint configuration everywhere within it - lintMapper.calculateLints(env.toplevel.sourcefile, env.tree, env.toplevel.endPositions); + lintMapper.calculateLints(env.toplevel.sourcefile, env.tree); } public void attribPackage(DiagnosticPosition pos, PackageSymbol p) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java index 2db3435a3822f..69161fd682c7b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java @@ -48,7 +48,6 @@ import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Target; -import com.sun.tools.javac.tree.EndPosTable; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.BLOCK; @@ -156,10 +155,6 @@ protected Lower(Context context) { */ Env attrEnv; - /** A hash table mapping syntax trees to their ending source positions. - */ - EndPosTable endPosTable; - /* ************************************************************************ * Global mappings *************************************************************************/ @@ -2059,8 +2054,8 @@ public T translate(T tree) { } else { make_at(tree.pos()); T result = super.translate(tree); - if (endPosTable != null && result != tree) { - endPosTable.replaceTree(tree, result); + if (result != null && result != tree) { + result.endpos = tree.endpos; } return result; } @@ -4352,7 +4347,6 @@ public List translateTopLevelClass(Env env, JCTree cdef, Tr try { attrEnv = env; this.make = make; - endPosTable = env.toplevel.endPositions; currentClass = null; currentRestype = null; currentMethodDef = null; @@ -4382,7 +4376,6 @@ public List translateTopLevelClass(Env env, JCTree cdef, Tr // note that recursive invocations of this method fail hard attrEnv = null; this.make = null; - endPosTable = null; currentClass = null; currentRestype = null; currentMethodDef = null; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java index 2cd4142c74858..3092d16469d2d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/CRTable.java @@ -32,7 +32,6 @@ import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.List; import com.sun.tools.javac.tree.JCTree.*; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree.JCSwitchExpression; /** This class contains the CharacterRangeTable for some method @@ -57,10 +56,6 @@ public class CRTable */ private Map positions = new HashMap<>(); - /** The object for ending positions stored in the parser. - */ - private EndPosTable endPosTable; - /** The tree of the method this table is intended for. * We should traverse this tree to get source ranges. */ @@ -68,9 +63,8 @@ public class CRTable /** Constructor */ - public CRTable(JCTree.JCMethodDecl tree, EndPosTable endPosTable) { + public CRTable(JCTree.JCMethodDecl tree) { this.methodTree = tree; - this.endPosTable = endPosTable; } /** Create a new CRTEntry and add it to the entries. @@ -584,7 +578,7 @@ public int startPos(JCTree tree) { */ public int endPos(JCTree tree) { if (tree == null) return Position.NOPOS; - return TreeInfo.getEndPos(tree, endPosTable); + return TreeInfo.getEndPos(tree); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java index e40a2fbfcea78..688ea1bd720b6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -45,7 +45,6 @@ import com.sun.tools.javac.jvm.Code.*; import com.sun.tools.javac.jvm.Items.*; import com.sun.tools.javac.resources.CompilerProperties.Errors; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree.*; import static com.sun.tools.javac.code.Flags.*; @@ -162,11 +161,6 @@ protected Gen(Context context) { */ private int nerrs = 0; - /** An object containing mappings of syntax trees to their - * ending source positions. - */ - EndPosTable endPosTable; - boolean inCondSwitchExpression; Chain switchExpressionTrueChain; Chain switchExpressionFalseChain; @@ -455,7 +449,7 @@ else if ((block.flags & SYNTHETIC) == 0) JCStatement init = make.at(vdef.pos()). Assignment(sym, vdef.init); initCode.append(init); - endPosTable.replaceTree(vdef, init); + init.endpos = vdef.endpos; initTAs.addAll(getAndRemoveNonFieldTAs(sym)); } else if (sym.getConstValue() == null) { // Initialize class (static) variables only if @@ -463,7 +457,7 @@ else if ((block.flags & SYNTHETIC) == 0) JCStatement init = make.at(vdef.pos). Assignment(sym, vdef.init); clinitCode.append(init); - endPosTable.replaceTree(vdef, init); + init.endpos = vdef.endpos; clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); } else { checkStringConstant(vdef.init.pos(), sym.getConstValue()); @@ -1027,8 +1021,7 @@ private int initCode(JCMethodDecl tree, Env env, boolean fatcode) { varDebugInfo, stackMap, debugCode, - genCrt ? new CRTable(tree, env.toplevel.endPositions) - : null, + genCrt ? new CRTable(tree) : null, syms, types, poolWriter); @@ -2478,7 +2471,6 @@ public boolean genClass(Env env, JCClassDecl cdef) { attrEnv = env; ClassSymbol c = cdef.sym; this.toplevel = env.toplevel; - this.endPosTable = toplevel.endPositions; /* method normalizeDefs() can add references to external classes into the constant pool */ cdef.defs = normalizeDefs(cdef.defs, c); @@ -2508,7 +2500,6 @@ public boolean genClass(Env env, JCClassDecl cdef) { attrEnv = null; this.env = null; toplevel = null; - endPosTable = null; nerrs = 0; qualifiedSymbolCache.clear(); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java index 2469dc9e031af..94292d9a348ee 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -438,8 +438,6 @@ public JavaCompiler(Context context) { sourceOutput = options.isSet(PRINTSOURCE); // used to be -s lineDebugInfo = options.isUnset(G_CUSTOM) || options.isSet(G_CUSTOM, "lines"); - genEndPos = options.isSet(XJCOV) || - context.get(DiagnosticListener.class) != null; devVerbose = options.isSet("dev"); processPcks = options.isSet("process.packages"); werrorAny = options.isSet(WERROR) || options.isSet(WERROR_CUSTOM, Option.LINT_CUSTOM_ALL); @@ -504,10 +502,6 @@ public boolean exists() { */ public boolean lineDebugInfo; - /** Switch: should we store the ending positions? - */ - public boolean genEndPos; - /** Switch: should we debug ignored exceptions */ protected boolean devVerbose; @@ -655,9 +649,8 @@ private JCCompilationUnit parse(JavaFileObject filename, CharSequence content, b TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); taskListener.started(e); keepComments = true; - genEndPos = true; } - Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, + Parser parser = parserFactory.newParser(content, keepComments(), lineDebugInfo, filename.isNameCompatible("module-info", Kind.SOURCE)); tree = parser.parseCompilationUnit(); if (verbose) { @@ -697,10 +690,7 @@ public JCTree.JCCompilationUnit parse(String filename) { public JCTree.JCCompilationUnit parse(JavaFileObject filename) { JavaFileObject prev = log.useSource(filename); try { - JCTree.JCCompilationUnit t = parse(filename, readSource(filename)); - if (t.endPositions != null) - log.setEndPosTable(filename, t.endPositions); - return t; + return parse(filename, readSource(filename)); } finally { log.useSource(prev); } @@ -1162,7 +1152,6 @@ public void initProcessAnnotations(Iterable processors, options.put("parameters", "parameters"); reader.saveParameterNames = true; keepComments = true; - genEndPos = true; if (!taskListener.isEmpty()) taskListener.started(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING)); deferredDiagnosticHandler = log.new DeferredDiagnosticHandler(); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index f40cb0fb6b7fa..babe372e7dcb0 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -33,7 +33,6 @@ import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.*; @@ -1215,7 +1214,7 @@ protected BasicComment(CommentStyle cs, UnicodeReader reader, int pos, int endPo this.cs = cs; this.pos = new SimpleDiagnosticPosition(pos) { @Override - public int getEndPosition(EndPosTable endPosTable) { + public int getEndPosition() { return endPos; } }; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index d3539b53541b3..c588059284a22 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -110,8 +110,7 @@ public class JavacParser implements Parser { /** The name table. */ private Names names; - /** End position mappings container */ - protected final AbstractEndPosTable endPosTable; + protected int errorEndPos = Position.NOPOS; /** A map associating "other nearby documentation comments" * with the preferred documentation comment for a declaration. */ @@ -167,9 +166,8 @@ enum BasicErrorRecoveryAction implements ErrorRecoveryAction { protected JavacParser(ParserFactory fac, Lexer S, boolean keepDocComments, - boolean keepLineMap, - boolean keepEndPositions) { - this(fac, S, keepDocComments, keepLineMap, keepEndPositions, false); + boolean keepLineMap) { + this(fac, S, keepDocComments, keepLineMap, false); } /** Construct a parser from a given scanner, tree factory and log. @@ -179,7 +177,6 @@ protected JavacParser(ParserFactory fac, Lexer S, boolean keepDocComments, boolean keepLineMap, - boolean keepEndPositions, boolean parseModuleInfo) { this.S = S; nextToken(); // prime the pump @@ -194,7 +191,6 @@ protected JavacParser(ParserFactory fac, this.docComments = newDocCommentTable(keepDocComments, fac); this.keepLineMap = keepLineMap; this.errorTree = F.Erroneous(); - this.endPosTable = newEndPosTable(keepEndPositions); this.allowYieldStatement = Feature.SWITCH_EXPRESSION.allowedInSource(source); this.allowRecords = Feature.RECORDS.allowedInSource(source); this.allowSealedTypes = Feature.SEALED_CLASSES.allowedInSource(source); @@ -218,19 +214,12 @@ protected JavacParser(JavacParser parser, this.parseModuleInfo = false; this.docComments = parser.docComments; this.errorTree = F.Erroneous(); - this.endPosTable = newEndPosTable(false); this.allowYieldStatement = Feature.SWITCH_EXPRESSION.allowedInSource(source); this.allowRecords = Feature.RECORDS.allowedInSource(source); this.allowSealedTypes = Feature.SEALED_CLASSES.allowedInSource(source); updateUnexpectedTopLevelDefinitionStartError(false); } - protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) { - return keepEndPositions - ? new SimpleEndPosTable() - : new MinimalEndPosTable(); - } - protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) { return keepDocComments ? new LazyDocCommentTable(fac) : null; } @@ -672,7 +661,7 @@ private boolean shebang(Comment c, JCDiagnostic.DiagnosticPosition pos) { var src = log.currentSource(); return c.getStyle() == Comment.CommentStyle.JAVADOC_LINE && c.getPos().getStartPosition() == 0 && - src.getLineNumber(pos.getEndPosition(src.getEndPosTable())) == 1; + src.getLineNumber(pos.getEndPosition()) == 1; } /** @@ -686,23 +675,26 @@ private void ignoreDanglingComments() { /* -------- source positions ------- */ protected void setErrorEndPos(int errPos) { - endPosTable.setErrorEndPos(errPos); + if (errPos > errorEndPos) { + errorEndPos = errPos; + } } /** * Store ending position for a tree, the value of which is the greater of - * last error position in {@link #endPosTable} and the given ending position. + * {@link #errorEndPos} and the given ending position. * @param tree tree node * @param endpos the ending position to associate with {@code tree} * @return {@code tree} */ protected T storeEnd(T tree, int endpos) { - return endPosTable.storeEnd(tree, endpos); + tree.endpos = Math.max(endpos, errorEndPos); + return tree; } /** * Store current token's ending position for a tree, the value of which - * will be the greater of last error position in {@link #endPosTable} + * will be the greater of {@link #errorEndPos} * and the ending position of the current token. * @param tree tree node */ @@ -712,7 +704,7 @@ protected T to(T tree) { /** * Store current token's ending position for a tree, the value of which - * will be the greater of last error position in {@link #endPosTable} + * will be the greater of {@link #errorEndPos} * and the ending position of the previous token. * @param tree tree node */ @@ -738,7 +730,7 @@ public int getStartPos(JCTree tree) { * @param tree The tree node */ public int getEndPos(JCTree tree) { - return endPosTable.getEndPos(tree); + return tree.endpos; } @@ -1274,7 +1266,7 @@ JCExpression term2Rest(JCExpression t, int minprec) { JCAnnotation typeAnno = F.at(decl.pos) .TypeAnnotation(decl.annotationType, decl.args); - endPosTable.replaceTree(decl, typeAnno); + typeAnno.endpos = decl.endpos; return typeAnno; }); type = insertAnnotationsToMostInner(type, typeAnnos, false); @@ -1363,7 +1355,7 @@ boolean merge(ListBuffer litBuf, ListBuffer opStack) { } else { JCExpression t = F.at(litBuf.first().getStartPosition()).Literal(TypeTag.CLASS, litBuf.stream().map(lit -> (String)lit.getValue()).collect(Collectors.joining())); - storeEnd(t, litBuf.last().getEndPosition(endPosTable)); + storeEnd(t, litBuf.last().getEndPosition()); opStack.prepend(t); return true; } @@ -1666,7 +1658,7 @@ protected JCExpression term3() { } // typeArgs saved for next loop iteration. t = toP(F.at(pos).Select(t, ident())); - if (token.pos <= endPosTable.errorEndPos && + if (token.pos <= errorEndPos && token.kind == MONKEYS_AT) { //error recovery, case like: //int i = expr. @@ -1890,7 +1882,7 @@ JCExpression term3Rest(JCExpression t, List typeArgs) { tyannos = typeAnnotationsOpt(); } t = toP(F.at(pos1).Select(t, ident(true))); - if (token.pos <= endPosTable.errorEndPos && + if (token.pos <= errorEndPos && token.kind == MONKEYS_AT) { //error recovery, case like: //int i = expr. @@ -2542,7 +2534,7 @@ JCExpression bracketsSuffix(JCExpression t) { int pos = token.pos; nextToken(); accept(CLASS); - if (token.pos == endPosTable.errorEndPos) { + if (token.pos == errorEndPos) { // error recovery Name name; if (LAX_IDENTIFIER.test(token.kind)) { @@ -2879,7 +2871,7 @@ List blockStatements() { // error recovery if (token.pos == lastErrPos) return stats.toList(); - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { skip(false, true, true, true); lastErrPos = token.pos; } @@ -4057,7 +4049,7 @@ public JCTree.JCCompilationUnit parseCompilationUnit() { boolean firstTypeDecl = true; // have we seen a class, enum, or interface declaration yet? boolean isImplicitClass = false; OUTER: while (token.kind != EOF) { - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery skip(firstTypeDecl, false, false, false); if (token.kind == EOF) @@ -4168,7 +4160,6 @@ public JCTree.JCCompilationUnit parseCompilationUnit() { toplevel.docComments = docComments; if (keepLineMap) toplevel.lineMap = S.getLineMap(); - toplevel.endPositions = this.endPosTable; return toplevel; } @@ -4588,7 +4579,7 @@ List enumBody(Name enumName) { hasStructuralErrors = true; } defs.append(enumeratorDeclaration(enumName)); - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery skip(false, true, true, false); } else { @@ -4611,7 +4602,7 @@ List enumBody(Name enumName) { wasError = false; defs.appendList(classOrInterfaceOrRecordBodyDeclaration(null, enumName, false, false)); - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery skip(false, true, true, false); } @@ -4708,7 +4699,7 @@ List typeList() { */ List classInterfaceOrRecordBody(Name className, boolean isInterface, boolean isRecord) { accept(LBRACE); - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery skip(false, true, false, false); if (token.kind == LBRACE) @@ -4719,7 +4710,7 @@ List classInterfaceOrRecordBody(Name className, boolean isInterface, boo ListBuffer defs = new ListBuffer<>(); while (token.kind != RBRACE && token.kind != EOF) { defs.appendList(classOrInterfaceOrRecordBodyDeclaration(null, className, isInterface, isRecord)); - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery skip(false, true, true, false); } @@ -5079,7 +5070,7 @@ protected JCTree methodDeclaratorRest(int pos, boolean unclosedParameterList; if (!isRecord || name != names.init || token.kind == LPAREN) { params = formalParameters(); - unclosedParameterList = token.pos == endPosTable.errorEndPos; + unclosedParameterList = token.pos == errorEndPos; if (!isVoid) type = bracketsOpt(type); if (token.kind == THROWS) { nextToken(); @@ -5105,7 +5096,7 @@ protected JCTree methodDeclaratorRest(int pos, defaultValue = null; accept(SEMI, tk -> Errors.Expected2(LBRACE, SEMI)); } - if (token.pos <= endPosTable.errorEndPos) { + if (token.pos <= errorEndPos) { // error recovery // look if there is a probable missing opening brace, // and if yes, parse as a block @@ -5643,70 +5634,4 @@ private void updateUnexpectedTopLevelDefinitionStartError(boolean hasPackageDecl unexpectedTopLevelDefinitionStartError = Errors.Expected3(CLASS, INTERFACE, ENUM); } } - - /** - * A straightforward {@link EndPosTable} implementation. - */ - protected static class SimpleEndPosTable extends AbstractEndPosTable { - - private final IntHashTable endPosMap = new IntHashTable(); - - @Override - public T storeEnd(T tree, int endpos) { - endPosMap.put(tree, Math.max(endpos, errorEndPos)); - return tree; - } - - @Override - public int getEndPos(JCTree tree) { - int value = endPosMap.get(tree); - // As long as Position.NOPOS==-1, this just returns value. - return (value == -1) ? Position.NOPOS : value; - } - - @Override - public int replaceTree(JCTree oldTree, JCTree newTree) { - int pos = endPosMap.remove(oldTree); - if (pos != -1 && newTree != null) { - storeEnd(newTree, pos); - } - return pos; - } - } - - /** - * A minimal implementation that only stores what's required. - */ - protected static class MinimalEndPosTable extends SimpleEndPosTable { - - @Override - public T storeEnd(T tree, int endpos) { - switch (tree.getTag()) { - case MODULEDEF: - case PACKAGEDEF: - case CLASSDEF: - case METHODDEF: - case VARDEF: - break; - default: - return tree; - } - return super.storeEnd(tree, endpos); - } - } - - protected abstract static class AbstractEndPosTable implements EndPosTable { - - /** - * Store the last error position. - */ - public int errorEndPos = Position.NOPOS; - - @Override - public void setErrorEndPos(int errPos) { - if (errPos > errorEndPos) { - errorEndPos = errPos; - } - } - } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ParserFactory.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ParserFactory.java index f9e187315ba6e..cbe8daf4cf6f3 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ParserFactory.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/ParserFactory.java @@ -89,13 +89,13 @@ protected ParserFactory(Context context) { this.trees = JavacTrees.instance(context); } - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { - return newParser(input, keepDocComments, keepEndPos, keepLineMap, false); + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap) { + return newParser(input, keepDocComments, keepLineMap, false); } - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap, boolean parseModuleInfo) { + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap, boolean parseModuleInfo) { Lexer lexer = scannerFactory.newScanner(input, keepDocComments); - return new JavacParser(this, lexer, keepDocComments, keepLineMap, keepEndPos, parseModuleInfo); + return new JavacParser(this, lexer, keepDocComments, keepLineMap, parseModuleInfo); } public JavacTrees getTrees() { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java index a999786f1194a..023e5c74b3a8c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DCTree.java @@ -305,7 +305,7 @@ public int getPreferredPosition() { } @Override - public int getEndPosition(EndPosTable endPosTable) { + public int getEndPosition() { return comment.getSourcePos(end); } }; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/EndPosTable.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/EndPosTable.java deleted file mode 100644 index 83fe402c0a78d..0000000000000 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/EndPosTable.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javac.tree; - -import com.sun.tools.javac.util.Position; - -/** - * Specifies the methods to access a mappings of syntax trees to end positions. - * - *

- * Implementations must store end positions for at least these node types: - *

    - *
  • {@link JCTree.JCModuleDecl} - *
  • {@link JCTree.JCPackageDecl} - *
  • {@link JCTree.JCClassDecl} - *
  • {@link JCTree.JCMethodDecl} - *
  • {@link JCTree.JCVariableDecl} - *
- * - *

This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own - * risk. This code and its internal interfaces are subject to change - * or deletion without notice.

- */ -public interface EndPosTable { - - /** - * This method will return the end position of a given tree, otherwise a - * Positions.NOPOS will be returned. - * @param tree JCTree - * @return position of the source tree or Positions.NOPOS for non-existent mapping - */ - int getEndPos(JCTree tree); - - /** - * Store ending position for a tree, the value of which is the greater of - * last error position and the given ending position. - * @param tree The tree. - * @param endpos The ending position to associate with the tree. - * @return the {@code tree} - */ - T storeEnd(T tree, int endpos); - - /** - * Set the error position during the parsing phases, the value of which - * will be set only if it is greater than the last stored error position. - * @param errPos The error position - */ - void setErrorEndPos(int errPos); - - /** - * Give an old tree and a new tree, the old tree will be replaced with - * the new tree, the position of the new tree will be that of the old - * tree. - * @param oldtree a JCTree to be replaced - * @param newtree a JCTree to be replaced with, or null to just remove {@code oldtree} - * @return position of the old tree or Positions.NOPOS for non-existent mapping - */ - int replaceTree(JCTree oldtree, JCTree newtree); -} diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java index 6501fd5d96c92..e0a99a6f1032c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java @@ -431,6 +431,10 @@ public int operatorIndex() { */ public int pos; + /* The (encoded) end position in the source file. @see util.Position. + */ + public int endpos = Position.NOPOS; + /* The type of this node. */ public Type type; @@ -514,8 +518,8 @@ public int getPreferredPosition() { } // for default DiagnosticPosition - public int getEndPosition(EndPosTable endPosTable) { - return noNoPos(TreeInfo.getEndPos(this, endPosTable)); + public int getEndPosition() { + return noNoPos(TreeInfo.getEndPos(this)); } private int noNoPos(int position) { @@ -552,9 +556,6 @@ public static class JCCompilationUnit extends JCTree implements CompilationUnitT /** A table that stores all documentation comments indexed by the tree * nodes they refer to. defined only if option -s is set. */ public DocCommentTable docComments = null; - /* An object encapsulating ending positions of source ranges indexed by - * the tree nodes they belong to. Defined only if option -Xjcov is set. */ - public EndPosTable endPositions = null; protected JCCompilationUnit(List defs) { this.defs = defs; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java index 3f73bfd22969c..c0ea03514a023 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java @@ -31,7 +31,6 @@ import com.sun.source.util.TreePath; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.RecordComponent; -import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; @@ -647,16 +646,11 @@ public static int getStartPos(JCTree tree) { /** The end position of given tree, given a table of end positions generated by the parser */ - public static int getEndPos(JCTree tree, EndPosTable endPosTable) { + public static int getEndPos(JCTree tree) { if (tree == null) return Position.NOPOS; - if (endPosTable == null) { - // fall back on limited info in the tree - return endPos(tree); - } - - int mapPos = endPosTable.getEndPos(tree); + int mapPos = tree.endpos; if (mapPos != Position.NOPOS) return mapPos; @@ -678,57 +672,57 @@ public static int getEndPos(JCTree tree, EndPosTable endPosTable) { case COMPL: case PREINC: case PREDEC: - return getEndPos(((JCOperatorExpression) tree).getOperand(RIGHT), endPosTable); + return getEndPos(((JCOperatorExpression) tree).getOperand(RIGHT)); case CASE: - return getEndPos(((JCCase) tree).stats.last(), endPosTable); + return getEndPos(((JCCase) tree).stats.last()); case CATCH: - return getEndPos(((JCCatch) tree).body, endPosTable); + return getEndPos(((JCCatch) tree).body); case CONDEXPR: - return getEndPos(((JCConditional) tree).falsepart, endPosTable); + return getEndPos(((JCConditional) tree).falsepart); case FORLOOP: - return getEndPos(((JCForLoop) tree).body, endPosTable); + return getEndPos(((JCForLoop) tree).body); case FOREACHLOOP: - return getEndPos(((JCEnhancedForLoop) tree).body, endPosTable); + return getEndPos(((JCEnhancedForLoop) tree).body); case IF: { JCIf node = (JCIf)tree; if (node.elsepart == null) { - return getEndPos(node.thenpart, endPosTable); + return getEndPos(node.thenpart); } else { - return getEndPos(node.elsepart, endPosTable); + return getEndPos(node.elsepart); } } case LABELLED: - return getEndPos(((JCLabeledStatement) tree).body, endPosTable); + return getEndPos(((JCLabeledStatement) tree).body); case MODIFIERS: - return getEndPos(((JCModifiers) tree).annotations.last(), endPosTable); + return getEndPos(((JCModifiers) tree).annotations.last()); case SYNCHRONIZED: - return getEndPos(((JCSynchronized) tree).body, endPosTable); + return getEndPos(((JCSynchronized) tree).body); case TOPLEVEL: - return getEndPos(((JCCompilationUnit) tree).defs.last(), endPosTable); + return getEndPos(((JCCompilationUnit) tree).defs.last()); case TRY: { JCTry node = (JCTry)tree; if (node.finalizer != null) { - return getEndPos(node.finalizer, endPosTable); + return getEndPos(node.finalizer); } else if (!node.catchers.isEmpty()) { - return getEndPos(node.catchers.last(), endPosTable); + return getEndPos(node.catchers.last()); } else { - return getEndPos(node.body, endPosTable); + return getEndPos(node.body); } } case WILDCARD: - return getEndPos(((JCWildcard) tree).inner, endPosTable); + return getEndPos(((JCWildcard) tree).inner); case TYPECAST: - return getEndPos(((JCTypeCast) tree).expr, endPosTable); + return getEndPos(((JCTypeCast) tree).expr); case TYPETEST: - return getEndPos(((JCInstanceOf) tree).pattern, endPosTable); + return getEndPos(((JCInstanceOf) tree).pattern); case WHILELOOP: - return getEndPos(((JCWhileLoop) tree).body, endPosTable); + return getEndPos(((JCWhileLoop) tree).body); case ANNOTATED_TYPE: - return getEndPos(((JCAnnotatedType) tree).underlyingType, endPosTable); + return getEndPos(((JCAnnotatedType) tree).underlyingType); case ERRONEOUS: { JCErroneous node = (JCErroneous)tree; if (node.errs != null && node.errs.nonEmpty()) - return getEndPos(node.errs.last(), endPosTable); + return getEndPos(node.errs.last()); } } return Position.NOPOS; @@ -745,8 +739,8 @@ public static DiagnosticPosition diagEndPos(final JCTree tree) { public JCTree getTree() { return tree; } public int getStartPosition() { return TreeInfo.getStartPos(tree); } public int getPreferredPosition() { return endPos; } - public int getEndPosition(EndPosTable endPosTable) { - return TreeInfo.getEndPos(tree, endPosTable); + public int getEndPosition() { + return TreeInfo.getEndPos(tree); } }; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/DiagnosticSource.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/DiagnosticSource.java index baae310181148..3339900733f36 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/DiagnosticSource.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/DiagnosticSource.java @@ -31,7 +31,6 @@ import javax.tools.JavaFileObject; import com.sun.tools.javac.file.JavacFileManager; -import com.sun.tools.javac.tree.EndPosTable; import static com.sun.tools.javac.util.LayoutCharacters.*; @@ -127,16 +126,6 @@ public String getLine(int pos) { } } - public EndPosTable getEndPosTable() { - return endPosTable; - } - - public void setEndPosTable(EndPosTable t) { - if (endPosTable != null && endPosTable != t) - throw new IllegalStateException("endPosTable already set"); - endPosTable = t; - } - /** Find the line in the buffer that contains the current position * @param pos Character offset into the buffer */ @@ -197,8 +186,6 @@ protected char[] initBuf(JavaFileObject fileObject) throws IOException { /** The underlying file object. */ protected JavaFileObject fileObject; - protected EndPosTable endPosTable; - /** A soft reference to the content of the file object. */ protected SoftReference refBuf; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/IntHashTable.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/IntHashTable.java deleted file mode 100644 index 409dc703d6000..0000000000000 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/IntHashTable.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.javac.util; - -/** - * A hash table that maps Object to int. - * - * This is a custom hash table optimised for the Object {@literal ->} int - * maps. This is done to avoid unnecessary object allocation in the image set. - * - * @author Charles Turner - * @author Per Bothner - */ -public class IntHashTable { - private static final int DEFAULT_INITIAL_SIZE = 64; - protected Object[] objs; // the domain set - protected int[] ints; // the image set - protected int mask; // used to clip int's into the domain - protected int num_bindings; // the number of mappings (including DELETED) - private static final Object DELETED = new Object(); - - /** - * Construct an Object {@literal ->} int hash table. - * - * The default size of the hash table is 64 mappings. - */ - public IntHashTable() { - objs = new Object[DEFAULT_INITIAL_SIZE]; - ints = new int[DEFAULT_INITIAL_SIZE]; - mask = DEFAULT_INITIAL_SIZE - 1; - } - - /** - * Construct an Object {@literal ->} int hash table with a specified amount of mappings. - * @param capacity The number of default mappings in this hash table. - */ - public IntHashTable(int capacity) { - int log2Size = 4; - while (capacity > (1 << log2Size)) { - log2Size++; - } - capacity = 1 << log2Size; - objs = new Object[capacity]; - ints = new int[capacity]; - mask = capacity - 1; - } - - /** - * Compute the hash code of a given object. - * - * @param key The object whose hash code is to be computed. - * @return zero if the object is null, otherwise the identityHashCode - */ - protected int hash(Object key) { - return System.identityHashCode(key); - } - - /** - * Find either the index of a key's value, or the index of an available space. - * - * @param key The key to whose index you want to find. - * @return Either the index of the key's value, or an index pointing to - * unoccupied space. - */ - protected int lookup(Object key) { - Object node; - int hash = hash(key); - int hash1 = hash ^ (hash >>> 15); - int hash2 = (hash ^ (hash << 6)) | 1; //ensure coprimeness - int deleted = -1; - for (int i = hash1 & mask;; i = (i + hash2) & mask) { - node = objs[i]; - if (node == key) - return i; - if (node == null) - return deleted >= 0 ? deleted : i; - if (node == DELETED && deleted < 0) - deleted = i; - } - } - - /** - * Return the value to which the specified key is mapped. - * - * @param key The key to whose value you want to find. - * @return A non-negative integer if the value is found. - * Otherwise, it is -1. - */ - public int get(Object key) { - int index = lookup(key); - Object node = objs[index]; - return node == null || node == DELETED ? -1 : ints[index]; - } - - /** - * Associates the specified key with the specified value in this map. - * - * @param key key with which the specified value is to be associated. - * @param value value to be associated with the specified key. - * @return previous value associated with specified key, or -1 if there was - * no mapping for key. - */ - public int put(Object key, int value) { - int index = lookup(key); - Object old = objs[index]; - if (old == null || old == DELETED) { - objs[index] = key; - ints[index] = value; - if (old != DELETED) - num_bindings++; - if (3 * num_bindings >= 2 * objs.length) - rehash(); - return -1; - } else { // update existing mapping - int oldValue = ints[index]; - ints[index] = value; - return oldValue; - } - } - - /** - * Remove the mapping(key and value) of the specified key. - * - * @param key the key to whose value you want to remove. - * @return the removed value associated with the specified key, - * or -1 if there was no mapping for the specified key. - */ - public int remove(Object key) { - int index = lookup(key); - Object old = objs[index]; - if (old == null || old == DELETED) - return -1; - objs[index] = DELETED; - return ints[index]; - } - - /** - * Expand the hash table when it exceeds the load factor. - * - * Rehash the existing objects. - */ - protected void rehash() { - Object[] oldObjsTable = objs; - int[] oldIntsTable = ints; - int newCapacity = oldObjsTable.length << 1; - objs = new Object[newCapacity]; - ints = new int[newCapacity]; - mask = newCapacity - 1; - num_bindings = 0; // this is recomputed below - Object key; - for (int i = oldIntsTable.length; --i >= 0;) { - key = oldObjsTable[i]; - if (key != null && key != DELETED) - put(key, oldIntsTable[i]); - } - } - - /** - * Removes all mappings from this map. - */ - public void clear() { - for (int i = objs.length; --i >= 0;) { - objs[i] = null; - } - num_bindings = 0; - } -} diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index c9f529eae5524..328183c0cb394 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -38,7 +38,6 @@ import com.sun.tools.javac.api.DiagnosticFormatter; import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.DefinedBy.Api; @@ -364,10 +363,8 @@ public static interface DiagnosticPosition { /** Get the position within the file that most accurately defines the * location for the diagnostic. */ int getPreferredPosition(); - /** If there is a tree node, and if endPositions are available, get - * the end position of the tree node. Otherwise, just returns the - * same as getPreferredPosition(). */ - int getEndPosition(EndPosTable endPosTable); + /** If there is a tree node, get the end position of the tree node. */ + int getEndPosition(); /** Get the position that determines which Lint configuration applies. */ default int getLintPosition() { return getStartPosition(); @@ -389,8 +386,8 @@ public int getPreferredPosition() { return orig.getPreferredPosition(); } @Override - public int getEndPosition(EndPosTable endPosTable) { - return orig.getEndPosition(endPosTable); + public int getEndPosition() { + return orig.getEndPosition(); } @Override public int getLintPosition() { @@ -421,7 +418,7 @@ public int getPreferredPosition() { return pos; } - public int getEndPosition(EndPosTable endPosTable) { + public int getEndPosition() { return pos; } @@ -747,7 +744,7 @@ protected int getIntPosition() { } protected int getIntEndPosition() { - return (position == null ? Position.NOPOS : position.getEndPosition(source.getEndPosTable())); + return (position == null ? Position.NOPOS : position.getEndPosition()); } @DefinedBy(Api.COMPILER) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java index a4109a35ccb80..b061d2283a05c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java @@ -55,7 +55,6 @@ import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.main.Main; import com.sun.tools.javac.main.Option; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.TreeInfo; @@ -594,11 +593,6 @@ public boolean hasDiagnosticListener() { return diagListener != null; } - public void setEndPosTable(JavaFileObject name, EndPosTable endPosTable) { - Assert.checkNonNull(name); - getSource(name).setEndPosTable(endPosTable); - } - /** Return current sourcefile. */ public JavaFileObject currentSourceFile() { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java index 84c32a4c732b0..b3bf1c14cb14f 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/JavadocLog.java @@ -55,7 +55,6 @@ import com.sun.tools.javac.tree.DCTree.DCDocComment; import com.sun.tools.javac.tree.DCTree; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.util.Context.Factory; import com.sun.tools.javac.util.DiagnosticSource; import com.sun.source.tree.CompilationUnitTree; @@ -616,7 +615,7 @@ public int getPreferredPosition() { } @Override - public int getEndPosition(EndPosTable endPosTable) { + public int getEndPosition() { return end; } }; diff --git a/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java b/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java index 0219fa0eaf88e..11fe05fbb9891 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/ReplParser.java @@ -75,9 +75,8 @@ public ReplParser(ReplParserFactory fac, com.sun.tools.javac.parser.Lexer S, boolean keepDocComments, boolean keepLineMap, - boolean keepEndPositions, boolean forceExpression) { - super(fac, S, keepDocComments, keepLineMap, keepEndPositions); + super(fac, S, keepDocComments, keepLineMap); this.forceExpression = forceExpression; this.source = fac.source; } @@ -103,7 +102,7 @@ public JCCompilationUnit parseCompilationUnit() { boolean firstTypeDecl = true; while (token.kind != EOF) { - if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) { + if (token.pos > 0 && token.pos <= errorEndPos) { // error recovery skip(true, false, false, false); if (token.kind == EOF) { @@ -141,7 +140,6 @@ public ReplUnit(List defs) { storeEnd(toplevel, S.prevToken().endPos); } toplevel.lineMap = S.getLineMap(); - toplevel.endPositions = this.endPosTable; return toplevel; } diff --git a/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java b/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java index 5c02561807b93..e4db8b632585b 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/ReplParserFactory.java @@ -60,13 +60,13 @@ protected ReplParserFactory(Context context, boolean forceExpression) { } @Override - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap) { com.sun.tools.javac.parser.Lexer lexer = scannerFactory.newScanner(input, keepDocComments); - return new ReplParser(this, lexer, keepDocComments, keepLineMap, keepEndPos, forceExpression); + return new ReplParser(this, lexer, keepDocComments, keepLineMap, forceExpression); } @Override - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap, boolean parseModuleInfo) { - return newParser(input, keepDocComments, keepEndPos, keepLineMap); + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap, boolean parseModuleInfo) { + return newParser(input, keepDocComments, keepLineMap); } } diff --git a/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java b/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java index 13c07ea32c0df..0de0e27ec0789 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java @@ -819,9 +819,9 @@ public void runPermitIntersectionTypes(Runnable r) { } @Override - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap, boolean parseModuleInfo) { + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap, boolean parseModuleInfo) { com.sun.tools.javac.parser.Lexer lexer = scannerFactory.newScanner(input, keepDocComments); - return new JavacParser(this, lexer, keepDocComments, keepLineMap, keepEndPos, parseModuleInfo) { + return new JavacParser(this, lexer, keepDocComments, keepLineMap, parseModuleInfo) { @Override public JCExpression parseType(boolean allowVar, com.sun.tools.javac.util.List annotations) { int pos = token.pos; diff --git a/test/langtools/tools/javac/6304921/TestLog.java b/test/langtools/tools/javac/6304921/TestLog.java index 8f00a14b9e237..9d0219accf1fe 100644 --- a/test/langtools/tools/javac/6304921/TestLog.java +++ b/test/langtools/tools/javac/6304921/TestLog.java @@ -42,7 +42,6 @@ import com.sun.tools.javac.parser.Parser; import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.resources.CompilerProperties.Warnings; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Context; @@ -96,9 +95,8 @@ static void test(boolean genEndPos) throws Exception { CharSequence cs = fo.getCharContent(true); Parser parser = pfac.newParser(cs, false, genEndPos, false); JCTree.JCCompilationUnit tree = parser.parseCompilationUnit(); - log.setEndPosTable(fo, tree.endPositions); - TreeScanner ts = new LogTester(log, tree.endPositions); + TreeScanner ts = new LogTester(log); ts.scan(tree); check(log.nerrors, 4, "errors"); @@ -117,9 +115,8 @@ private static void check(int found, int expected, String name) { } private static class LogTester extends TreeScanner { - LogTester(Log log, EndPosTable endPosTable) { + LogTester(Log log) { this.log = log; - this.endPosTable = endPosTable; } public void visitIf(JCTree.JCIf tree) { @@ -138,7 +135,6 @@ public void visitIf(JCTree.JCIf tree) { } private Log log; - private EndPosTable endPosTable; } private static class StringJavaFileObject extends SimpleJavaFileObject { diff --git a/test/langtools/tools/javac/api/TestJavacTask_Lock.java b/test/langtools/tools/javac/api/TestJavacTask_Lock.java index 8e7709a5f7fe7..1ff340c3c262b 100644 --- a/test/langtools/tools/javac/api/TestJavacTask_Lock.java +++ b/test/langtools/tools/javac/api/TestJavacTask_Lock.java @@ -69,10 +69,9 @@ void run() throws Exception { comp = ToolProvider.getSystemJavaCompiler(); fm = comp.getStandardFileManager(null, null, null); try { - for (MethodKind first: MethodKind.values()) { - for (MethodKind second: MethodKind.values()) { - test(first, second); - } + MethodKind first = MethodKind.CALL; + for (MethodKind second: MethodKind.values()) { + test(first, second); } if (errors > 0) diff --git a/test/langtools/tools/javac/diags/DiagnosticGetEndPosition.java b/test/langtools/tools/javac/diags/DiagnosticGetEndPosition.java index 1835cd46167cc..cfcb6e22c1bb3 100644 --- a/test/langtools/tools/javac/diags/DiagnosticGetEndPosition.java +++ b/test/langtools/tools/javac/diags/DiagnosticGetEndPosition.java @@ -118,7 +118,7 @@ public class Test { compiler.getTask( null, null, - d -> assertEquals("", //ideally would be "0", but the positions are not fully set yet + d -> assertEquals("0", implCode.substring((int) d.getStartPosition(), (int) d.getEndPosition())), List.of("-sourcepath", src.toString(), "-Xlint:divzero"), diff --git a/test/langtools/tools/javac/failover/CheckAttributedTree.java b/test/langtools/tools/javac/failover/CheckAttributedTree.java index 9b28d2bebd48d..050a302bc6e34 100644 --- a/test/langtools/tools/javac/failover/CheckAttributedTree.java +++ b/test/langtools/tools/javac/failover/CheckAttributedTree.java @@ -92,7 +92,6 @@ import com.sun.source.util.TaskListener; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCBreak; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -367,8 +366,7 @@ void error(String msg) { private class NPETester extends TreeScanner { void test(JCCompilationUnit cut, JCTree tree) { sourcefile = cut.sourcefile; - endPosTable = cut.endPositions; - encl = new Info(tree, endPosTable); + encl = new Info(tree); tree.accept(this); } @@ -379,7 +377,7 @@ public void scan(JCTree tree) { return; } - Info self = new Info(tree, endPosTable); + Info self = new Info(tree); if (mandatoryType(tree)) { check(tree.type != null, "'null' field 'type' found in tree ", self); @@ -454,7 +452,6 @@ public void visitBreak(JCBreak tree) { } JavaFileObject sourcefile; - EndPosTable endPosTable; Info encl; } } @@ -498,12 +495,12 @@ private class Info { end = Integer.MAX_VALUE; } - Info(JCTree tree, EndPosTable endPosTable) { + Info(JCTree tree) { this.tree = tree; tag = tree.getTag(); start = TreeInfo.getStartPos(tree); pos = tree.pos; - end = TreeInfo.getEndPos(tree, endPosTable); + end = TreeInfo.getEndPos(tree); } @Override diff --git a/test/langtools/tools/javac/parser/DeclarationEndPositions.java b/test/langtools/tools/javac/parser/DeclarationEndPositions.java index 226b77769d19e..c61a92e80cd3c 100644 --- a/test/langtools/tools/javac/parser/DeclarationEndPositions.java +++ b/test/langtools/tools/javac/parser/DeclarationEndPositions.java @@ -78,7 +78,7 @@ public Void scan(Tree node, Void aVoid) { throw new AssertionError(String.format( "wrong %s pos %d for \"%s\" in \"%s\"", "start", start, tree, input)); } - int end = TreeInfo.getEndPos(tree, unit.endPositions); + int end = TreeInfo.getEndPos(tree); if (markers.charAt(end - 1) != '>') { throw new AssertionError(String.format( "wrong %s pos %d for \"%s\" in \"%s\"", "end", end, tree, input)); diff --git a/test/langtools/tools/javac/parser/ReversedSourcePositions.java b/test/langtools/tools/javac/parser/ReversedSourcePositions.java index d092d23d8c16c..6596430dca520 100644 --- a/test/langtools/tools/javac/parser/ReversedSourcePositions.java +++ b/test/langtools/tools/javac/parser/ReversedSourcePositions.java @@ -72,7 +72,7 @@ public class ReproFile {} public Void scan(Tree node, Void aVoid) { if (node instanceof JCTree tree) { int start = tree.getStartPosition(); - int end = tree.getEndPosition(unit.endPositions); + int end = tree.getEndPosition(); if (start >= end) { throw new AssertionError( String.format("[%d, %d] %s %s\n", start, end, tree.getKind(), tree)); diff --git a/test/langtools/tools/javac/parser/extend/TrialParser.java b/test/langtools/tools/javac/parser/extend/TrialParser.java index c9a858fbc47ef..ca4e3995bc3c3 100644 --- a/test/langtools/tools/javac/parser/extend/TrialParser.java +++ b/test/langtools/tools/javac/parser/extend/TrialParser.java @@ -66,9 +66,8 @@ class TrialParser extends JavacParser { public TrialParser(ParserFactory fac, com.sun.tools.javac.parser.Lexer S, boolean keepDocComments, - boolean keepLineMap, - boolean keepEndPositions) { - super(fac, S, keepDocComments, keepLineMap, keepEndPositions); + boolean keepLineMap) { + super(fac, S, keepDocComments, keepLineMap); } @Override @@ -102,7 +101,7 @@ public JCCompilationUnit parseCompilationUnit() { boolean firstTypeDecl = true; while (token.kind != EOF) { - if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) { + if (token.pos > 0 && token.pos <= errorEndPos) { // error recovery skip(true, false, false, false); if (token.kind == EOF) { @@ -139,7 +138,6 @@ public TrialUnit(List defs) { storeEnd(toplevel, S.prevToken().endPos); } toplevel.lineMap = S.getLineMap(); - toplevel.endPositions = this.endPosTable; return toplevel; } diff --git a/test/langtools/tools/javac/parser/extend/TrialParserFactory.java b/test/langtools/tools/javac/parser/extend/TrialParserFactory.java index 6ac4c60d2794e..63c50a81c3be5 100644 --- a/test/langtools/tools/javac/parser/extend/TrialParserFactory.java +++ b/test/langtools/tools/javac/parser/extend/TrialParserFactory.java @@ -48,13 +48,13 @@ protected TrialParserFactory(Context context) { } @Override - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap) { com.sun.tools.javac.parser.Lexer lexer = scannerFactory.newScanner(input, keepDocComments); - return new TrialParser(this, lexer, keepDocComments, keepLineMap, keepEndPos); + return new TrialParser(this, lexer, keepDocComments, keepLineMap); } @Override - public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap, boolean parseModuleInfo) { - return newParser(input, keepDocComments, keepEndPos, keepLineMap); + public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepLineMap, boolean parseModuleInfo) { + return newParser(input, keepDocComments, keepLineMap); } } diff --git a/test/langtools/tools/javac/tree/MissingSemicolonTest.java b/test/langtools/tools/javac/tree/MissingSemicolonTest.java index 2c70c4841bea2..cedcf1e5f98bd 100644 --- a/test/langtools/tools/javac/tree/MissingSemicolonTest.java +++ b/test/langtools/tools/javac/tree/MissingSemicolonTest.java @@ -115,7 +115,7 @@ public List gatherTreeSpans(File file, String content) throws IOException public Void scan(Tree tree, Void p) { if (tree != null) { int start = ((JCTree) tree).getStartPosition(); - int end = ((JCTree) tree).getEndPosition(unit.endPositions); + int end = ((JCTree) tree).getEndPosition(); spans.add(new int[] {start, end}); } @@ -134,7 +134,7 @@ public void verifyTreeSpans(File file, List spans, public Void scan(Tree tree, Void p) { if (tree != null) { int start = ((JCTree) tree).getStartPosition(); - int end = ((JCTree) tree).getEndPosition(updated.endPositions); + int end = ((JCTree) tree).getEndPosition(); if (tree.getKind() != Kind.ERRONEOUS) { int[] expected = nextSpan.next(); diff --git a/test/langtools/tools/javac/tree/TreePosTest.java b/test/langtools/tools/javac/tree/TreePosTest.java index 9e6dcf61306b1..ecc0d477cdbb2 100644 --- a/test/langtools/tools/javac/tree/TreePosTest.java +++ b/test/langtools/tools/javac/tree/TreePosTest.java @@ -69,7 +69,6 @@ import com.sun.tools.javac.api.JavacTaskPool; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotatedType; import com.sun.tools.javac.tree.JCTree.JCCase; @@ -347,7 +346,6 @@ private class PosTester extends TreeScanner { private boolean compactSourceFile; void test(JCCompilationUnit tree) { sourcefile = tree.sourcefile; - endPosTable = tree.endPositions; encl = new Info(); List nonImports = tree.defs .stream() @@ -355,7 +353,7 @@ void test(JCCompilationUnit tree) { .toList(); compactSourceFile = nonImports.size() == 1 && nonImports.get(0) instanceof JCClassDecl classDecl && - tree.endPositions.getEndPos(classDecl) == NOPOS; + classDecl.endpos == NOPOS; tree.accept(this); } @@ -364,7 +362,7 @@ public void scan(JCTree tree) { if (tree == null) return; - Info self = new Info(tree, endPosTable); + Info self = new Info(tree); if (check(encl, self)) { // Modifiers nodes are present throughout the tree even where // there is no corresponding source text. @@ -504,7 +502,6 @@ void check(String label, Info encl, Info self, boolean ok) { } JavaFileObject sourcefile; - EndPosTable endPosTable; Info encl; } @@ -521,12 +518,12 @@ private class Info { end = Integer.MAX_VALUE; } - Info(JCTree tree, EndPosTable endPosTable) { + Info(JCTree tree) { this.tree = tree; tag = tree.getTag(); start = TreeInfo.getStartPos(tree); pos = tree.pos; - end = TreeInfo.getEndPos(tree, endPosTable); + end = TreeInfo.getEndPos(tree); } @Override