Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,9 +133,9 @@ public Optional<Lint> 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);
}

/**
Expand Down Expand Up @@ -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<Span> i = unmappedDecls.iterator(); i.hasNext(); ) {
if (i.next().contains(tree.pos())) {
rootRange.populateSubtree(tree, endPositions);
rootRange.populateSubtree(tree);
i.remove();
return;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -320,7 +319,7 @@ private <T extends JCTree> void scanDecl(T tree, Symbol symbol, Consumer<? super

// Add a new node here and proceed
final LintRange previousNode = currentNode;
currentNode = new LintRange(tree, endPositions, newLint);
currentNode = new LintRange(tree, newLint);
previousNode.children.add(currentNode);
try {
recursor.accept(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2762,8 +2762,7 @@ public void visitNewClass(final JCNewClass tree) {
clazzid1 = make.at(clazz.pos).Select(make.Type(encltype),
((JCIdent) clazzid).name);

EndPosTable endPosTable = this.env.toplevel.endPositions;
endPosTable.storeEnd(clazzid1, clazzid.getEndPosition(endPosTable));
clazzid1.endpos = clazzid.getEndPosition();
if (clazz.hasTag(ANNOTATED_TYPE)) {
JCAnnotatedType annoType = (JCAnnotatedType) clazz;
List<JCAnnotation> annos = annoType.annotations;
Expand Down Expand Up @@ -5311,7 +5310,7 @@ public void attrib(Env<AttrContext> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -156,10 +155,6 @@ protected Lower(Context context) {
*/
Env<AttrContext> attrEnv;

/** A hash table mapping syntax trees to their ending source positions.
*/
EndPosTable endPosTable;

/* ************************************************************************
* Global mappings
*************************************************************************/
Expand Down Expand Up @@ -2059,8 +2054,8 @@ public <T extends JCTree> 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;
}
Expand Down Expand Up @@ -4352,7 +4347,6 @@ public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, Tr
try {
attrEnv = env;
this.make = make;
endPosTable = env.toplevel.endPositions;
currentClass = null;
currentRestype = null;
currentMethodDef = null;
Expand Down Expand Up @@ -4382,7 +4376,6 @@ public List<JCTree> translateTopLevelClass(Env<AttrContext> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,20 +56,15 @@ public class CRTable
*/
private Map<Object,SourceRange> 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.
*/
JCTree.JCMethodDecl methodTree;

/** 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.
Expand Down Expand Up @@ -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);
}
}

Expand Down
15 changes: 3 additions & 12 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -455,15 +449,15 @@ 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
// they are not compile-time constants.
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());
Expand Down Expand Up @@ -1027,8 +1021,7 @@ private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) {
varDebugInfo,
stackMap,
debugCode,
genCrt ? new CRTable(tree, env.toplevel.endPositions)
: null,
genCrt ? new CRTable(tree) : null,
syms,
types,
poolWriter);
Expand Down Expand Up @@ -2478,7 +2471,6 @@ public boolean genClass(Env<AttrContext> 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);
Expand Down Expand Up @@ -2508,7 +2500,6 @@ public boolean genClass(Env<AttrContext> env, JCClassDecl cdef) {
attrEnv = null;
this.env = null;
toplevel = null;
endPosTable = null;
nerrs = 0;
qualifiedSymbolCache.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1162,7 +1152,6 @@ public void initProcessAnnotations(Iterable<? extends Processor> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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;
}
};
Expand Down
Loading