8181370: Convert anonymous inner classes into lambdas/method references
Reviewed-by: jjg, rfield, mchung
This commit is contained in:
parent
5a0691c4e4
commit
c4e8276376
@ -203,14 +203,11 @@ public class SelectToolTask extends Task {
|
||||
if (toolName != null) {
|
||||
toolChoice.setSelectedItem(tool);
|
||||
}
|
||||
toolChoice.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
ToolChoices tool = (ToolChoices)e.getItem();
|
||||
argsField.setText(getDefaultArgsForTool(props, tool));
|
||||
if (toolProperty != null)
|
||||
okButton.setEnabled(tool != ToolChoices.NONE);
|
||||
}
|
||||
toolChoice.addItemListener(e -> {
|
||||
ToolChoices tool1 = (ToolChoices)e.getItem();
|
||||
argsField.setText(getDefaultArgsForTool(props, tool1));
|
||||
if (toolProperty != null)
|
||||
okButton.setEnabled(tool1 != ToolChoices.NONE);
|
||||
});
|
||||
fc.anchor = GridBagConstraints.EAST;
|
||||
|
||||
@ -248,12 +245,9 @@ public class SelectToolTask extends Task {
|
||||
final JOptionPane p = new JOptionPane(body);
|
||||
okButton = new JButton("OK");
|
||||
okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
|
||||
d.setVisible(false);
|
||||
}
|
||||
okButton.addActionListener(e -> {
|
||||
JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
|
||||
d.setVisible(false);
|
||||
});
|
||||
p.setOptions(new Object[] { okButton });
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class PropertiesParser {
|
||||
}
|
||||
|
||||
public static boolean run(String[] args, PrintStream out) {
|
||||
PropertiesParser pp = new PropertiesParser(msg -> out.println(msg));
|
||||
PropertiesParser pp = new PropertiesParser(out::println);
|
||||
return pp.run(args);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class PropertiesParser {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
optionsMap.forEach((propfile, outfile) -> compilePropertyFile(propfile, outfile));
|
||||
optionsMap.forEach(this::compilePropertyFile);
|
||||
return true;
|
||||
} catch (RuntimeException ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -315,12 +315,7 @@ public class Messages {
|
||||
*/
|
||||
private static class Table {
|
||||
|
||||
private static final Comparator<Integer> DECREASING = new Comparator<Integer>() {
|
||||
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
};
|
||||
private static final Comparator<Integer> DECREASING = (o1, o2) -> o2.compareTo(o1);
|
||||
private final TreeMap<Integer, Set<String>> map = new TreeMap<>(DECREASING);
|
||||
|
||||
void put(String label, int n) {
|
||||
|
@ -97,15 +97,12 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
/* Internal version of call exposing Main.Result. */
|
||||
public Main.Result doCall() {
|
||||
try {
|
||||
return handleExceptions(new Callable<Main.Result>() {
|
||||
@Override
|
||||
public Main.Result call() throws Exception {
|
||||
prepareCompiler(false);
|
||||
if (compiler.errorCount() > 0)
|
||||
return Main.Result.ERROR;
|
||||
compiler.compile(args.getFileObjects(), args.getClassNames(), processors);
|
||||
return (compiler.errorCount() > 0) ? Main.Result.ERROR : Main.Result.OK; // FIXME?
|
||||
}
|
||||
return handleExceptions(() -> {
|
||||
prepareCompiler(false);
|
||||
if (compiler.errorCount() > 0)
|
||||
return Main.Result.ERROR;
|
||||
compiler.compile(args.getFileObjects(), args.getClassNames(), processors);
|
||||
return (compiler.errorCount() > 0) ? Main.Result.ERROR : Main.Result.OK; // FIXME?
|
||||
}, Main.Result.SYSERR, Main.Result.ABNORMAL);
|
||||
} finally {
|
||||
try {
|
||||
@ -228,12 +225,7 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Iterable<? extends CompilationUnitTree> parse() {
|
||||
return handleExceptions(new Callable<Iterable<? extends CompilationUnitTree>>() {
|
||||
@Override
|
||||
public Iterable<? extends CompilationUnitTree> call() {
|
||||
return parseInternal();
|
||||
}
|
||||
}, List.<CompilationUnitTree>nil(), List.<CompilationUnitTree>nil());
|
||||
return handleExceptions(this::parseInternal, List.<CompilationUnitTree>nil(), List.<CompilationUnitTree>nil());
|
||||
}
|
||||
|
||||
private Iterable<? extends CompilationUnitTree> parseInternal() {
|
||||
@ -360,12 +352,7 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Iterable<? extends Element> analyze() {
|
||||
return handleExceptions(new Callable<Iterable<? extends Element>>() {
|
||||
@Override
|
||||
public Iterable<? extends Element> call() {
|
||||
return analyze(null);
|
||||
}
|
||||
}, List.<Element>nil(), List.<Element>nil());
|
||||
return handleExceptions(() -> analyze(null), List.<Element>nil(), List.<Element>nil());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -427,12 +414,7 @@ public class JavacTaskImpl extends BasicJavacTask {
|
||||
|
||||
@Override @DefinedBy(Api.COMPILER_TREE)
|
||||
public Iterable<? extends JavaFileObject> generate() {
|
||||
return handleExceptions(new Callable<Iterable<? extends JavaFileObject>>() {
|
||||
@Override
|
||||
public Iterable<? extends JavaFileObject> call() {
|
||||
return generate(null);
|
||||
}
|
||||
}, List.<JavaFileObject>nil(), List.<JavaFileObject>nil());
|
||||
return handleExceptions(() -> generate(null), List.<JavaFileObject>nil(), List.<JavaFileObject>nil());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,12 +163,7 @@ public class ClassFinder {
|
||||
/**
|
||||
* Completer that delegates to the complete-method of this class.
|
||||
*/
|
||||
private final Completer thisCompleter = new Completer() {
|
||||
@Override
|
||||
public void complete(Symbol sym) throws CompletionFailure {
|
||||
ClassFinder.this.complete(sym);
|
||||
}
|
||||
};
|
||||
private final Completer thisCompleter = this::complete;
|
||||
|
||||
public Completer getCompleter() {
|
||||
return thisCompleter;
|
||||
@ -516,7 +511,7 @@ public class ClassFinder {
|
||||
|
||||
ModuleSymbol msym = p.modle;
|
||||
|
||||
Assert.checkNonNull(msym, () -> p.toString());
|
||||
Assert.checkNonNull(msym, p::toString);
|
||||
|
||||
msym.complete();
|
||||
|
||||
|
@ -143,12 +143,7 @@ public abstract class Scope {
|
||||
/** Returns true iff the given Symbol is in this scope, optionally checking outward scopes.
|
||||
*/
|
||||
public boolean includes(final Symbol sym, LookupKind lookupKind) {
|
||||
return getSymbolsByName(sym.name, new Filter<Symbol>() {
|
||||
@Override
|
||||
public boolean accepts(Symbol t) {
|
||||
return t == sym;
|
||||
}
|
||||
}, lookupKind).iterator().hasNext();
|
||||
return getSymbolsByName(sym.name, t -> t == sym, lookupKind).iterator().hasNext();
|
||||
}
|
||||
|
||||
/** Returns true iff this scope does not contain any Symbol. Does not inspect outward scopes.
|
||||
@ -574,64 +569,56 @@ public abstract class Scope {
|
||||
|
||||
public Iterable<Symbol> getSymbols(final Filter<Symbol> sf,
|
||||
final LookupKind lookupKind) {
|
||||
return new Iterable<Symbol>() {
|
||||
public Iterator<Symbol> iterator() {
|
||||
return new Iterator<Symbol>() {
|
||||
private ScopeImpl currScope = ScopeImpl.this;
|
||||
private Scope.Entry currEntry = elems;
|
||||
private int seenRemoveCount = currScope.removeCount;
|
||||
{
|
||||
update();
|
||||
}
|
||||
return () -> new Iterator<Symbol>() {
|
||||
private ScopeImpl currScope = ScopeImpl.this;
|
||||
private Entry currEntry = elems;
|
||||
private int seenRemoveCount = currScope.removeCount;
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
if (seenRemoveCount != currScope.removeCount &&
|
||||
currEntry != null &&
|
||||
!currEntry.scope.includes(currEntry.sym)) {
|
||||
doNext(); //skip entry that is no longer in the Scope
|
||||
seenRemoveCount = currScope.removeCount;
|
||||
}
|
||||
return currEntry != null;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
if (seenRemoveCount != currScope.removeCount &&
|
||||
currEntry != null &&
|
||||
!currEntry.scope.includes(currEntry.sym)) {
|
||||
doNext(); //skip entry that is no longer in the Scope
|
||||
seenRemoveCount = currScope.removeCount;
|
||||
}
|
||||
return currEntry != null;
|
||||
}
|
||||
|
||||
public Symbol next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
public Symbol next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return doNext();
|
||||
}
|
||||
private Symbol doNext() {
|
||||
Symbol sym = (currEntry == null ? null : currEntry.sym);
|
||||
if (currEntry != null) {
|
||||
currEntry = currEntry.sibling;
|
||||
}
|
||||
update();
|
||||
return sym;
|
||||
}
|
||||
return doNext();
|
||||
}
|
||||
private Symbol doNext() {
|
||||
Symbol sym = (currEntry == null ? null : currEntry.sym);
|
||||
if (currEntry != null) {
|
||||
currEntry = currEntry.sibling;
|
||||
}
|
||||
update();
|
||||
return sym;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private void update() {
|
||||
private void update() {
|
||||
skipToNextMatchingEntry();
|
||||
if (lookupKind == RECURSIVE) {
|
||||
while (currEntry == null && currScope.next != null) {
|
||||
currScope = currScope.next;
|
||||
currEntry = currScope.elems;
|
||||
seenRemoveCount = currScope.removeCount;
|
||||
skipToNextMatchingEntry();
|
||||
if (lookupKind == RECURSIVE) {
|
||||
while (currEntry == null && currScope.next != null) {
|
||||
currScope = currScope.next;
|
||||
currEntry = currScope.elems;
|
||||
seenRemoveCount = currScope.removeCount;
|
||||
skipToNextMatchingEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void skipToNextMatchingEntry() {
|
||||
while (currEntry != null && sf != null && !sf.accepts(currEntry.sym)) {
|
||||
currEntry = currEntry.sibling;
|
||||
}
|
||||
}
|
||||
};
|
||||
void skipToNextMatchingEntry() {
|
||||
while (currEntry != null && sf != null && !sf.accepts(currEntry.sym)) {
|
||||
currEntry = currEntry.sibling;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -639,40 +626,36 @@ public abstract class Scope {
|
||||
public Iterable<Symbol> getSymbolsByName(final Name name,
|
||||
final Filter<Symbol> sf,
|
||||
final LookupKind lookupKind) {
|
||||
return new Iterable<Symbol>() {
|
||||
public Iterator<Symbol> iterator() {
|
||||
return new Iterator<Symbol>() {
|
||||
Scope.Entry currentEntry = lookup(name, sf);
|
||||
int seenRemoveCount = currentEntry.scope != null ?
|
||||
currentEntry.scope.removeCount : -1;
|
||||
return () -> new Iterator<Symbol>() {
|
||||
Entry currentEntry = lookup(name, sf);
|
||||
int seenRemoveCount = currentEntry.scope != null ?
|
||||
currentEntry.scope.removeCount : -1;
|
||||
|
||||
public boolean hasNext() {
|
||||
if (currentEntry.scope != null &&
|
||||
seenRemoveCount != currentEntry.scope.removeCount &&
|
||||
!currentEntry.scope.includes(currentEntry.sym)) {
|
||||
doNext(); //skip entry that is no longer in the Scope
|
||||
}
|
||||
return currentEntry.scope != null &&
|
||||
(lookupKind == RECURSIVE ||
|
||||
currentEntry.scope == ScopeImpl.this);
|
||||
}
|
||||
public Symbol next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return doNext();
|
||||
}
|
||||
private Symbol doNext() {
|
||||
Scope.Entry prevEntry = currentEntry;
|
||||
currentEntry = currentEntry.next(sf);
|
||||
return prevEntry.sym;
|
||||
}
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
public boolean hasNext() {
|
||||
if (currentEntry.scope != null &&
|
||||
seenRemoveCount != currentEntry.scope.removeCount &&
|
||||
!currentEntry.scope.includes(currentEntry.sym)) {
|
||||
doNext(); //skip entry that is no longer in the Scope
|
||||
}
|
||||
return currentEntry.scope != null &&
|
||||
(lookupKind == RECURSIVE ||
|
||||
currentEntry.scope == ScopeImpl.this);
|
||||
}
|
||||
public Symbol next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return doNext();
|
||||
}
|
||||
private Symbol doNext() {
|
||||
Entry prevEntry = currentEntry;
|
||||
currentEntry = currentEntry.next(sf);
|
||||
return prevEntry.sym;
|
||||
}
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Scope getOrigin(Symbol s) {
|
||||
|
@ -1549,11 +1549,7 @@ public abstract class Symbol extends AnnoConstruct implements Element {
|
||||
final Attr attr,
|
||||
final JCVariableDecl variable)
|
||||
{
|
||||
setData(new Callable<Object>() {
|
||||
public Object call() {
|
||||
return attr.attribLazyConstantValue(env, variable, type);
|
||||
}
|
||||
});
|
||||
setData((Callable<Object>)() -> attr.attribLazyConstantValue(env, variable, type));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1856,12 +1852,8 @@ public abstract class Symbol extends AnnoConstruct implements Element {
|
||||
return implementation(origin, types, checkResult, implementation_filter);
|
||||
}
|
||||
// where
|
||||
public static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
|
||||
public boolean accepts(Symbol s) {
|
||||
return s.kind == MTH &&
|
||||
(s.flags() & SYNTHETIC) == 0;
|
||||
}
|
||||
};
|
||||
public static final Filter<Symbol> implementation_filter = s ->
|
||||
s.kind == MTH && (s.flags() & SYNTHETIC) == 0;
|
||||
|
||||
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
|
||||
MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
|
||||
|
@ -590,7 +590,7 @@ public class Symtab {
|
||||
arrayClass.members().enter(arrayCloneMethod);
|
||||
|
||||
if (java_base != noModule)
|
||||
java_base.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues
|
||||
java_base.completer = moduleCompleter::complete; //bootstrap issues
|
||||
|
||||
}
|
||||
|
||||
@ -624,7 +624,7 @@ public class Symtab {
|
||||
}
|
||||
|
||||
public ClassSymbol getClass(ModuleSymbol msym, Name flatName) {
|
||||
Assert.checkNonNull(msym, () -> flatName.toString());
|
||||
Assert.checkNonNull(msym, flatName::toString);
|
||||
return classes.getOrDefault(flatName, Collections.emptyMap()).get(msym);
|
||||
}
|
||||
|
||||
@ -757,7 +757,8 @@ public class Symtab {
|
||||
}
|
||||
};
|
||||
unnamedPackage.modle = module;
|
||||
unnamedPackage.completer = sym -> initialCompleter.complete(sym);
|
||||
//we cannot use a method reference below, as initialCompleter might be null now
|
||||
unnamedPackage.completer = s -> initialCompleter.complete(s);
|
||||
module.unnamedPackage = unnamedPackage;
|
||||
}
|
||||
|
||||
@ -770,7 +771,7 @@ public class Symtab {
|
||||
if (msym == null) {
|
||||
msym = ModuleSymbol.create(name, names.module_info);
|
||||
addRootPackageFor(msym);
|
||||
msym.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues
|
||||
msym.completer = s -> moduleCompleter.complete(s); //bootstrap issues
|
||||
modules.put(name, msym);
|
||||
}
|
||||
return msym;
|
||||
|
@ -2138,11 +2138,9 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
|
||||
UndetVarListener prevListener = listener;
|
||||
try {
|
||||
//setup new listener for keeping track of changed bounds
|
||||
listener = new UndetVarListener() {
|
||||
public void varBoundChanged(UndetVar uv, InferenceBound ib, Type t, boolean _ignored) {
|
||||
Assert.check(uv == UndetVar.this);
|
||||
boundsChanged.add(new Pair<>(ib, t));
|
||||
}
|
||||
listener = (uv, ib, t, _ignored) -> {
|
||||
Assert.check(uv == UndetVar.this);
|
||||
boundsChanged.add(new Pair<>(ib, t));
|
||||
};
|
||||
for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
|
||||
InferenceBound ib = _entry.getKey();
|
||||
|
@ -2651,12 +2651,8 @@ public class Attr extends JCTree.Visitor {
|
||||
private void checkAccessibleTypes(final DiagnosticPosition pos, final Env<AttrContext> env,
|
||||
final InferenceContext inferenceContext, final List<Type> ts) {
|
||||
if (inferenceContext.free(ts)) {
|
||||
inferenceContext.addFreeTypeListener(ts, new FreeTypeListener() {
|
||||
@Override
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
checkAccessibleTypes(pos, env, inferenceContext, inferenceContext.asInstTypes(ts));
|
||||
}
|
||||
});
|
||||
inferenceContext.addFreeTypeListener(ts,
|
||||
solvedContext -> checkAccessibleTypes(pos, env, solvedContext, solvedContext.asInstTypes(ts)));
|
||||
} else {
|
||||
for (Type t : ts) {
|
||||
rs.checkAccessibleType(env, t);
|
||||
@ -3094,12 +3090,9 @@ public class Attr extends JCTree.Visitor {
|
||||
private void setFunctionalInfo(final Env<AttrContext> env, final JCFunctionalExpression fExpr,
|
||||
final Type pt, final Type descriptorType, final Type primaryTarget, final CheckContext checkContext) {
|
||||
if (checkContext.inferenceContext().free(descriptorType)) {
|
||||
checkContext.inferenceContext().addFreeTypeListener(List.of(pt, descriptorType), new FreeTypeListener() {
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
setFunctionalInfo(env, fExpr, pt, inferenceContext.asInstType(descriptorType),
|
||||
inferenceContext.asInstType(primaryTarget), checkContext);
|
||||
}
|
||||
});
|
||||
checkContext.inferenceContext().addFreeTypeListener(List.of(pt, descriptorType),
|
||||
inferenceContext -> setFunctionalInfo(env, fExpr, pt, inferenceContext.asInstType(descriptorType),
|
||||
inferenceContext.asInstType(primaryTarget), checkContext));
|
||||
} else {
|
||||
ListBuffer<Type> targets = new ListBuffer<>();
|
||||
if (pt.hasTag(CLASS)) {
|
||||
@ -4574,13 +4567,8 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
public static final Filter<Symbol> anyNonAbstractOrDefaultMethod = new Filter<Symbol>() {
|
||||
@Override
|
||||
public boolean accepts(Symbol s) {
|
||||
return s.kind == MTH &&
|
||||
(s.flags() & (DEFAULT | ABSTRACT)) != ABSTRACT;
|
||||
}
|
||||
};
|
||||
public static final Filter<Symbol> anyNonAbstractOrDefaultMethod = s ->
|
||||
s.kind == MTH && (s.flags() & (DEFAULT | ABSTRACT)) != ABSTRACT;
|
||||
|
||||
/** get a diagnostic position for an attribute of Type t, or null if attribute missing */
|
||||
private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) {
|
||||
|
@ -565,12 +565,8 @@ public class Check {
|
||||
Type checkType(final DiagnosticPosition pos, final Type found, final Type req, final CheckContext checkContext) {
|
||||
final InferenceContext inferenceContext = checkContext.inferenceContext();
|
||||
if (inferenceContext.free(req) || inferenceContext.free(found)) {
|
||||
inferenceContext.addFreeTypeListener(List.of(req, found), new FreeTypeListener() {
|
||||
@Override
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
checkType(pos, inferenceContext.asInstType(found), inferenceContext.asInstType(req), checkContext);
|
||||
}
|
||||
});
|
||||
inferenceContext.addFreeTypeListener(List.of(req, found),
|
||||
solvedContext -> checkType(pos, solvedContext.asInstType(found), solvedContext.asInstType(req), checkContext));
|
||||
}
|
||||
if (req.hasTag(ERROR))
|
||||
return req;
|
||||
@ -614,13 +610,10 @@ public class Check {
|
||||
&& types.isSameType(tree.expr.type, tree.clazz.type)
|
||||
&& !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
|
||||
&& !is292targetTypeCast(tree)) {
|
||||
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
|
||||
@Override
|
||||
public void report() {
|
||||
if (lint.isEnabled(Lint.LintCategory.CAST))
|
||||
log.warning(Lint.LintCategory.CAST,
|
||||
tree.pos(), "redundant.cast", tree.clazz.type);
|
||||
}
|
||||
deferredLintHandler.report(() -> {
|
||||
if (lint.isEnabled(LintCategory.CAST))
|
||||
log.warning(LintCategory.CAST,
|
||||
tree.pos(), "redundant.cast", tree.clazz.type);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -953,11 +946,8 @@ public class Check {
|
||||
// System.out.println("method : " + owntype);
|
||||
// System.out.println("actuals: " + argtypes);
|
||||
if (inferenceContext.free(mtype)) {
|
||||
inferenceContext.addFreeTypeListener(List.of(mtype), new FreeTypeListener() {
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
checkMethod(inferenceContext.asInstType(mtype), sym, env, argtrees, argtypes, useVarargs, inferenceContext);
|
||||
}
|
||||
});
|
||||
inferenceContext.addFreeTypeListener(List.of(mtype),
|
||||
solvedContext -> checkMethod(solvedContext.asInstType(mtype), sym, env, argtrees, argtypes, useVarargs, solvedContext));
|
||||
return mtype;
|
||||
}
|
||||
Type owntype = mtype;
|
||||
@ -2070,13 +2060,8 @@ public class Check {
|
||||
}
|
||||
}
|
||||
|
||||
private Filter<Symbol> equalsHasCodeFilter = new Filter<Symbol>() {
|
||||
public boolean accepts(Symbol s) {
|
||||
return MethodSymbol.implementation_filter.accepts(s) &&
|
||||
(s.flags() & BAD_OVERRIDE) == 0;
|
||||
|
||||
}
|
||||
};
|
||||
private Filter<Symbol> equalsHasCodeFilter = s -> MethodSymbol.implementation_filter.accepts(s) &&
|
||||
(s.flags() & BAD_OVERRIDE) == 0;
|
||||
|
||||
public void checkClassOverrideEqualsAndHashIfNeeded(DiagnosticPosition pos,
|
||||
ClassSymbol someClass) {
|
||||
@ -3266,12 +3251,7 @@ public class Check {
|
||||
if ( (s.isDeprecatedForRemoval()
|
||||
|| s.isDeprecated() && !other.isDeprecated())
|
||||
&& (s.outermostClass() != other.outermostClass() || s.outermostClass() == null)) {
|
||||
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
|
||||
@Override
|
||||
public void report() {
|
||||
warnDeprecated(pos, s);
|
||||
}
|
||||
});
|
||||
deferredLintHandler.report(() -> warnDeprecated(pos, s));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3410,12 +3390,7 @@ public class Check {
|
||||
int opc = ((OperatorSymbol)operator).opcode;
|
||||
if (opc == ByteCodes.idiv || opc == ByteCodes.imod
|
||||
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
|
||||
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
|
||||
@Override
|
||||
public void report() {
|
||||
warnDivZero(pos);
|
||||
}
|
||||
});
|
||||
deferredLintHandler.report(() -> warnDivZero(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3892,12 +3867,9 @@ public class Check {
|
||||
|
||||
void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
|
||||
if (msym.kind != MDL) {
|
||||
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
|
||||
@Override
|
||||
public void report() {
|
||||
if (lint.isEnabled(Lint.LintCategory.MODULE))
|
||||
log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
|
||||
}
|
||||
deferredLintHandler.report(() -> {
|
||||
if (lint.isEnabled(LintCategory.MODULE))
|
||||
log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -507,12 +507,10 @@ public class DeferredAttr extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
DeferredAttrDiagHandler(Log log, JCTree newTree) {
|
||||
super(log, new Filter<JCDiagnostic>() {
|
||||
public boolean accepts(JCDiagnostic d) {
|
||||
PosScanner posScanner = new PosScanner(d.getDiagnosticPosition());
|
||||
posScanner.scan(newTree);
|
||||
return posScanner.found;
|
||||
}
|
||||
super(log, d -> {
|
||||
PosScanner posScanner = new PosScanner(d.getDiagnosticPosition());
|
||||
posScanner.scan(newTree);
|
||||
return posScanner.found;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1008,11 +1006,7 @@ public class DeferredAttr extends JCTree.Visitor {
|
||||
final Filter<JCTree> treeFilter;
|
||||
|
||||
FilterScanner(final Set<JCTree.Tag> validTags) {
|
||||
this.treeFilter = new Filter<JCTree>() {
|
||||
public boolean accepts(JCTree t) {
|
||||
return validTags.contains(t.getTag());
|
||||
}
|
||||
};
|
||||
this.treeFilter = t -> validTags.contains(t.getTag());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,7 +415,7 @@ public class Enter extends JCTree.Visitor {
|
||||
if (c.owner != owner) {
|
||||
//anonymous class loaded from a classfile may be recreated from source (see below)
|
||||
//if this class is a member of such an anonymous class, fix the owner:
|
||||
Assert.check(owner.owner.kind != TYP, () -> owner.toString());
|
||||
Assert.check(owner.owner.kind != TYP, owner::toString);
|
||||
Assert.check(c.owner.kind == TYP, () -> c.owner.toString());
|
||||
ClassSymbol cowner = (ClassSymbol) c.owner;
|
||||
if (cowner.members_field != null) {
|
||||
|
@ -123,11 +123,7 @@ public class InferenceContext {
|
||||
* inference context
|
||||
*/
|
||||
List<Type> restvars() {
|
||||
return filterVars(new Filter<UndetVar>() {
|
||||
public boolean accepts(UndetVar uv) {
|
||||
return uv.getInst() == null;
|
||||
}
|
||||
});
|
||||
return filterVars(uv -> uv.getInst() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,11 +131,7 @@ public class InferenceContext {
|
||||
* inference context
|
||||
*/
|
||||
List<Type> instvars() {
|
||||
return filterVars(new Filter<UndetVar>() {
|
||||
public boolean accepts(UndetVar uv) {
|
||||
return uv.getInst() != null;
|
||||
}
|
||||
});
|
||||
return filterVars(uv -> uv.getInst() != null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,13 +139,9 @@ public class InferenceContext {
|
||||
* declared bounds).
|
||||
*/
|
||||
final List<Type> boundedVars() {
|
||||
return filterVars(new Filter<UndetVar>() {
|
||||
public boolean accepts(UndetVar uv) {
|
||||
return uv.getBounds(InferenceBound.UPPER)
|
||||
.diff(uv.getDeclaredBounds())
|
||||
.appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty();
|
||||
}
|
||||
});
|
||||
return filterVars(uv -> uv.getBounds(InferenceBound.UPPER)
|
||||
.diff(uv.getDeclaredBounds())
|
||||
.appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty());
|
||||
}
|
||||
|
||||
/* Returns the corresponding inference variables.
|
||||
@ -341,11 +329,7 @@ public class InferenceContext {
|
||||
//set up listeners to notify original inference contexts as
|
||||
//propagated vars are inferred in new context
|
||||
for (Type t : inferencevars) {
|
||||
that.freeTypeListeners.put(new FreeTypeListener() {
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
InferenceContext.this.notifyChange();
|
||||
}
|
||||
}, List.of(t));
|
||||
that.freeTypeListeners.put(inferenceContext -> InferenceContext.this.notifyChange(), List.of(t));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2254,25 +2254,15 @@ public class Lower extends TreeTranslator {
|
||||
final JCFieldAccess s = (JCFieldAccess)lval;
|
||||
Symbol lid = TreeInfo.symbol(s.selected);
|
||||
if (lid != null && lid.kind == TYP) return builder.build(lval);
|
||||
return abstractRval(s.selected, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression selected) {
|
||||
return builder.build(make.Select(selected, s.sym));
|
||||
}
|
||||
});
|
||||
return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));
|
||||
}
|
||||
case INDEXED: {
|
||||
final JCArrayAccess i = (JCArrayAccess)lval;
|
||||
return abstractRval(i.indexed, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression indexed) {
|
||||
return abstractRval(i.index, syms.intType, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression index) {
|
||||
JCExpression newLval = make.Indexed(indexed, index);
|
||||
newLval.setType(i.type);
|
||||
return builder.build(newLval);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return abstractRval(i.indexed, indexed -> abstractRval(i.index, syms.intType, index -> {
|
||||
JCExpression newLval = make.Indexed(indexed, index);
|
||||
newLval.setType(i.type);
|
||||
return builder.build(newLval);
|
||||
}));
|
||||
}
|
||||
case TYPECAST: {
|
||||
return abstractLval(((JCTypeCast)lval).expr, builder);
|
||||
@ -2283,11 +2273,7 @@ public class Lower extends TreeTranslator {
|
||||
|
||||
// evaluate and discard the first expression, then evaluate the second.
|
||||
JCExpression makeComma(final JCExpression expr1, final JCExpression expr2) {
|
||||
return abstractRval(expr1, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression discarded) {
|
||||
return expr2;
|
||||
}
|
||||
});
|
||||
return abstractRval(expr1, discarded -> expr2);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@ -3195,33 +3181,31 @@ public class Lower extends TreeTranslator {
|
||||
// boxing required; need to rewrite as x = (unbox typeof x)(x op y);
|
||||
// or if x == (typeof x)z then z = (unbox typeof x)((typeof x)z op y)
|
||||
// (but without recomputing x)
|
||||
JCTree newTree = abstractLval(tree.lhs, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression lhs) {
|
||||
JCTree.Tag newTag = tree.getTag().noAssignOp();
|
||||
// Erasure (TransTypes) can change the type of
|
||||
// tree.lhs. However, we can still get the
|
||||
// unerased type of tree.lhs as it is stored
|
||||
// in tree.type in Attr.
|
||||
OperatorSymbol newOperator = operators.resolveBinary(tree,
|
||||
newTag,
|
||||
tree.type,
|
||||
tree.rhs.type);
|
||||
//Need to use the "lhs" at two places, once on the future left hand side
|
||||
//and once in the future binary operator. But further processing may change
|
||||
//the components of the tree in place (see visitSelect for e.g. <Class>.super.<ident>),
|
||||
//so cloning the tree to avoid interference between the uses:
|
||||
JCExpression expr = (JCExpression) lhs.clone();
|
||||
if (expr.type != tree.type)
|
||||
expr = make.TypeCast(tree.type, expr);
|
||||
JCBinary opResult = make.Binary(newTag, expr, tree.rhs);
|
||||
opResult.operator = newOperator;
|
||||
opResult.type = newOperator.type.getReturnType();
|
||||
JCExpression newRhs = boxingReq ?
|
||||
make.TypeCast(types.unboxedType(tree.type), opResult) :
|
||||
opResult;
|
||||
return make.Assign(lhs, newRhs).setType(tree.type);
|
||||
}
|
||||
});
|
||||
JCTree newTree = abstractLval(tree.lhs, lhs -> {
|
||||
Tag newTag = tree.getTag().noAssignOp();
|
||||
// Erasure (TransTypes) can change the type of
|
||||
// tree.lhs. However, we can still get the
|
||||
// unerased type of tree.lhs as it is stored
|
||||
// in tree.type in Attr.
|
||||
OperatorSymbol newOperator = operators.resolveBinary(tree,
|
||||
newTag,
|
||||
tree.type,
|
||||
tree.rhs.type);
|
||||
//Need to use the "lhs" at two places, once on the future left hand side
|
||||
//and once in the future binary operator. But further processing may change
|
||||
//the components of the tree in place (see visitSelect for e.g. <Class>.super.<ident>),
|
||||
//so cloning the tree to avoid interference between the uses:
|
||||
JCExpression expr = (JCExpression) lhs.clone();
|
||||
if (expr.type != tree.type)
|
||||
expr = make.TypeCast(tree.type, expr);
|
||||
JCBinary opResult = make.Binary(newTag, expr, tree.rhs);
|
||||
opResult.operator = newOperator;
|
||||
opResult.type = newOperator.type.getReturnType();
|
||||
JCExpression newRhs = boxingReq ?
|
||||
make.TypeCast(types.unboxedType(tree.type), opResult) :
|
||||
opResult;
|
||||
return make.Assign(lhs, newRhs).setType(tree.type);
|
||||
});
|
||||
result = translate(newTree);
|
||||
return;
|
||||
}
|
||||
@ -3287,28 +3271,22 @@ public class Lower extends TreeTranslator {
|
||||
// translate to tmp1=lval(e); tmp2=tmp1; (typeof tree)tmp1 OP 1; tmp2
|
||||
// where OP is += or -=
|
||||
final boolean cast = TreeInfo.skipParens(tree.arg).hasTag(TYPECAST);
|
||||
return abstractLval(tree.arg, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression tmp1) {
|
||||
return abstractRval(tmp1, tree.arg.type, new TreeBuilder() {
|
||||
public JCExpression build(final JCExpression tmp2) {
|
||||
JCTree.Tag opcode = (tree.hasTag(POSTINC))
|
||||
? PLUS_ASG : MINUS_ASG;
|
||||
//"tmp1" and "tmp2" may refer to the same instance
|
||||
//(for e.g. <Class>.super.<ident>). But further processing may
|
||||
//change the components of the tree in place (see visitSelect),
|
||||
//so cloning the tree to avoid interference between the two uses:
|
||||
JCExpression lhs = (JCExpression)tmp1.clone();
|
||||
lhs = cast
|
||||
? make.TypeCast(tree.arg.type, lhs)
|
||||
: lhs;
|
||||
JCExpression update = makeAssignop(opcode,
|
||||
lhs,
|
||||
make.Literal(1));
|
||||
return makeComma(update, tmp2);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return abstractLval(tree.arg, tmp1 -> abstractRval(tmp1, tree.arg.type, tmp2 -> {
|
||||
Tag opcode = (tree.hasTag(POSTINC))
|
||||
? PLUS_ASG : MINUS_ASG;
|
||||
//"tmp1" and "tmp2" may refer to the same instance
|
||||
//(for e.g. <Class>.super.<ident>). But further processing may
|
||||
//change the components of the tree in place (see visitSelect),
|
||||
//so cloning the tree to avoid interference between the two uses:
|
||||
JCExpression lhs = (JCExpression)tmp1.clone();
|
||||
lhs = cast
|
||||
? make.TypeCast(tree.arg.type, lhs)
|
||||
: lhs;
|
||||
JCExpression update = makeAssignop(opcode,
|
||||
lhs,
|
||||
make.Literal(1));
|
||||
return makeComma(update, tmp2);
|
||||
}));
|
||||
}
|
||||
|
||||
public void visitUnary(JCUnary tree) {
|
||||
|
@ -424,12 +424,7 @@ public class Modules extends JCTree.Visitor {
|
||||
checkNoAllModulePath();
|
||||
defaultModule.complete();
|
||||
// Question: why not do completeModule here?
|
||||
defaultModule.completer = new Completer() {
|
||||
@Override
|
||||
public void complete(Symbol sym) throws CompletionFailure {
|
||||
completeModule((ModuleSymbol) sym);
|
||||
}
|
||||
};
|
||||
defaultModule.completer = sym -> completeModule((ModuleSymbol) sym);
|
||||
}
|
||||
rootModules.add(defaultModule);
|
||||
break;
|
||||
@ -1522,7 +1517,7 @@ public class Modules extends JCTree.Visitor {
|
||||
current.complete();
|
||||
if ((current.flags() & Flags.ACYCLIC) != 0)
|
||||
continue;
|
||||
Assert.checkNonNull(current.requires, () -> current.toString());
|
||||
Assert.checkNonNull(current.requires, current::toString);
|
||||
for (RequiresDirective dep : current.requires) {
|
||||
if (!dep.flags.contains(RequiresFlag.EXTRA))
|
||||
queue = queue.prepend(dep.module);
|
||||
|
@ -296,7 +296,7 @@ public class Operators {
|
||||
*/
|
||||
private OperatorSymbol[] initOperators() {
|
||||
OperatorSymbol[] operators = operatorSuppliers.stream()
|
||||
.map(op -> op.get())
|
||||
.map(Supplier::get)
|
||||
.toArray(OperatorSymbol[]::new);
|
||||
alternatives = Optional.of(operators);
|
||||
operatorSuppliers = null; //let GC do its work
|
||||
|
@ -881,12 +881,8 @@ public class Resolve {
|
||||
*/
|
||||
private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) {
|
||||
if (inferenceContext.free(t)) {
|
||||
inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() {
|
||||
@Override
|
||||
public void typesInferred(InferenceContext inferenceContext) {
|
||||
varargsAccessible(env, inferenceContext.asInstType(t), inferenceContext);
|
||||
}
|
||||
});
|
||||
inferenceContext.addFreeTypeListener(List.of(t),
|
||||
solvedContext -> varargsAccessible(env, solvedContext.asInstType(t), solvedContext));
|
||||
} else {
|
||||
if (!isAccessible(env, types.erasure(t))) {
|
||||
Symbol location = env.enclClass.sym;
|
||||
@ -1851,47 +1847,43 @@ public class Resolve {
|
||||
* errors if some of the not-needed supertypes are missing/ill-formed).
|
||||
*/
|
||||
Iterable<TypeSymbol> superclasses(final Type intype) {
|
||||
return new Iterable<TypeSymbol>() {
|
||||
public Iterator<TypeSymbol> iterator() {
|
||||
return new Iterator<TypeSymbol>() {
|
||||
return () -> new Iterator<TypeSymbol>() {
|
||||
|
||||
List<TypeSymbol> seen = List.nil();
|
||||
TypeSymbol currentSym = symbolFor(intype);
|
||||
TypeSymbol prevSym = null;
|
||||
List<TypeSymbol> seen = List.nil();
|
||||
TypeSymbol currentSym = symbolFor(intype);
|
||||
TypeSymbol prevSym = null;
|
||||
|
||||
public boolean hasNext() {
|
||||
if (currentSym == syms.noSymbol) {
|
||||
currentSym = symbolFor(types.supertype(prevSym.type));
|
||||
}
|
||||
return currentSym != null;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
if (currentSym == syms.noSymbol) {
|
||||
currentSym = symbolFor(types.supertype(prevSym.type));
|
||||
}
|
||||
return currentSym != null;
|
||||
}
|
||||
|
||||
public TypeSymbol next() {
|
||||
prevSym = currentSym;
|
||||
currentSym = syms.noSymbol;
|
||||
Assert.check(prevSym != null || prevSym != syms.noSymbol);
|
||||
return prevSym;
|
||||
}
|
||||
public TypeSymbol next() {
|
||||
prevSym = currentSym;
|
||||
currentSym = syms.noSymbol;
|
||||
Assert.check(prevSym != null || prevSym != syms.noSymbol);
|
||||
return prevSym;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
TypeSymbol symbolFor(Type t) {
|
||||
if (!t.hasTag(CLASS) &&
|
||||
!t.hasTag(TYPEVAR)) {
|
||||
return null;
|
||||
}
|
||||
t = types.skipTypeVars(t, false);
|
||||
if (seen.contains(t.tsym)) {
|
||||
//degenerate case in which we have a circular
|
||||
//class hierarchy - because of ill-formed classfiles
|
||||
return null;
|
||||
}
|
||||
seen = seen.prepend(t.tsym);
|
||||
return t.tsym;
|
||||
}
|
||||
};
|
||||
TypeSymbol symbolFor(Type t) {
|
||||
if (!t.hasTag(CLASS) &&
|
||||
!t.hasTag(TYPEVAR)) {
|
||||
return null;
|
||||
}
|
||||
t = types.skipTypeVars(t, false);
|
||||
if (seen.contains(t.tsym)) {
|
||||
//degenerate case in which we have a circular
|
||||
//class hierarchy - because of ill-formed classfiles
|
||||
return null;
|
||||
}
|
||||
seen = seen.prepend(t.tsym);
|
||||
return t.tsym;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
|
||||
/**
|
||||
* Caching implementation of FSInfo.
|
||||
@ -47,13 +48,11 @@ public class CacheFSInfo extends FSInfo {
|
||||
* Register a Context.Factory to create a CacheFSInfo.
|
||||
*/
|
||||
public static void preRegister(Context context) {
|
||||
context.put(FSInfo.class, new Context.Factory<FSInfo>() {
|
||||
public FSInfo make(Context c) {
|
||||
context.put(FSInfo.class, (Factory<FSInfo>)c -> {
|
||||
FSInfo instance = new CacheFSInfo();
|
||||
c.put(FSInfo.class, instance);
|
||||
return instance;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
|
@ -71,6 +71,7 @@ import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
|
||||
import com.sun.tools.javac.file.RelativePath.RelativeFile;
|
||||
import com.sun.tools.javac.util.Assert;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
import com.sun.tools.javac.util.DefinedBy;
|
||||
import com.sun.tools.javac.util.DefinedBy.Api;
|
||||
import com.sun.tools.javac.util.List;
|
||||
@ -134,12 +135,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
* Register a Context.Factory to create a JavacFileManager.
|
||||
*/
|
||||
public static void preRegister(Context context) {
|
||||
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
|
||||
@Override
|
||||
public JavaFileManager make(Context c) {
|
||||
return new JavacFileManager(c, true, null);
|
||||
}
|
||||
});
|
||||
context.put(JavaFileManager.class,
|
||||
(Factory<JavaFileManager>)c -> new JavacFileManager(c, true, null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,7 +272,7 @@ public class Locations {
|
||||
}
|
||||
|
||||
try (Stream<Path> s = Files.list(dir)) {
|
||||
s.filter(dirEntry -> isArchive(dirEntry))
|
||||
s.filter(Locations.this::isArchive)
|
||||
.forEach(dirEntry -> addFile(dirEntry, warn));
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
@ -946,7 +946,7 @@ public class Locations {
|
||||
if (searchPath == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
return () -> new ModulePathIterator();
|
||||
return ModulePathIterator::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -365,16 +365,8 @@ public class Pool {
|
||||
Assert.check(!refSym.owner.isInterface() || interfaceOwner);
|
||||
}
|
||||
//where
|
||||
Filter<Name> nonInitFilter = new Filter<Name>() {
|
||||
public boolean accepts(Name n) {
|
||||
return n != n.table.names.init && n != n.table.names.clinit;
|
||||
}
|
||||
};
|
||||
Filter<Name> nonInitFilter = n -> (n != n.table.names.init && n != n.table.names.clinit);
|
||||
|
||||
Filter<Name> initFilter = new Filter<Name>() {
|
||||
public boolean accepts(Name n) {
|
||||
return n == n.table.names.init;
|
||||
}
|
||||
};
|
||||
Filter<Name> initFilter = n -> n == n.table.names.init;
|
||||
}
|
||||
}
|
||||
|
@ -337,12 +337,7 @@ public class JavaCompiler {
|
||||
* SourceCompleter that delegates to the readSourceFile method of this class.
|
||||
*/
|
||||
protected final Symbol.Completer sourceCompleter =
|
||||
new Symbol.Completer() {
|
||||
@Override
|
||||
public void complete(Symbol sym) throws CompletionFailure {
|
||||
readSourceFile((ClassSymbol) sym);
|
||||
}
|
||||
};
|
||||
sym -> readSourceFile((ClassSymbol) sym);
|
||||
|
||||
protected final ModuleFinder.ModuleInfoSourceFileCompleter moduleInfoSourceFileCompleter =
|
||||
fo -> (ModuleSymbol) readSourceFile(parseImplicitFile(fo), null, tl -> {
|
||||
|
@ -71,11 +71,7 @@ public class FilteredMemberList extends AbstractList<Symbol> {
|
||||
|
||||
// A more efficient implementation than AbstractList's.
|
||||
public Iterator<Symbol> iterator() {
|
||||
return scope.getSymbols(new Filter<Symbol>() {
|
||||
public boolean accepts(Symbol t) {
|
||||
return !unwanted(t);
|
||||
}
|
||||
}, NON_RECURSIVE).iterator();
|
||||
return scope.getSymbols(t -> !unwanted(t), NON_RECURSIVE).iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1718,11 +1718,7 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
|
||||
/** Accepts all identifier-like tokens */
|
||||
protected Filter<TokenKind> LAX_IDENTIFIER = new Filter<TokenKind>() {
|
||||
public boolean accepts(TokenKind t) {
|
||||
return t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
|
||||
}
|
||||
};
|
||||
protected Filter<TokenKind> LAX_IDENTIFIER = t -> t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
|
||||
|
||||
enum ParensResult {
|
||||
CAST,
|
||||
|
@ -324,7 +324,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||
if (platformProvider != null) {
|
||||
platformProcessors = platformProvider.getAnnotationProcessors()
|
||||
.stream()
|
||||
.map(ap -> ap.getPlugin())
|
||||
.map(PluginInfo::getPlugin)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
List<Iterator<? extends Processor>> iterators = List.of(processorIterator,
|
||||
|
@ -73,11 +73,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
|
||||
final Options options = Options.instance(context);
|
||||
initOptions(options);
|
||||
options.addListener(new Runnable() {
|
||||
public void run() {
|
||||
initOptions(options);
|
||||
}
|
||||
});
|
||||
options.addListener(() -> initOptions(options));
|
||||
}
|
||||
|
||||
private void initOptions(Options options) {
|
||||
|
@ -557,8 +557,8 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
|
||||
*/
|
||||
public static <Z> Collector<Z, ListBuffer<Z>, List<Z>> collector() {
|
||||
return Collector.of(ListBuffer::new,
|
||||
(buf, el)->buf.add(el),
|
||||
ListBuffer::add,
|
||||
(buf1, buf2)-> { buf1.addAll(buf2); return buf1; },
|
||||
buf->buf.toList());
|
||||
ListBuffer::toList);
|
||||
}
|
||||
}
|
||||
|
@ -364,12 +364,7 @@ public class Log extends AbstractLog {
|
||||
|
||||
final Options options = Options.instance(context);
|
||||
initOptions(options);
|
||||
options.addListener(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initOptions(options);
|
||||
}
|
||||
});
|
||||
options.addListener(() -> initOptions(options));
|
||||
}
|
||||
// where
|
||||
private void initOptions(Options options) {
|
||||
|
@ -310,15 +310,12 @@ public class JavahTask implements NativeHeaderTool.NativeHeaderTask {
|
||||
|
||||
private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
|
||||
final PrintWriter pw = getPrintWriterForWriter(w);
|
||||
return new DiagnosticListener<JavaFileObject> () {
|
||||
@DefinedBy(Api.COMPILER)
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
|
||||
pw.print(getMessage("err.prefix"));
|
||||
pw.print(" ");
|
||||
}
|
||||
pw.println(diagnostic.getMessage(null));
|
||||
return diagnostic -> {
|
||||
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
|
||||
pw.print(getMessage("err.prefix"));
|
||||
pw.print(" ");
|
||||
}
|
||||
pw.println(diagnostic.getMessage(null));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ public class JavacState {
|
||||
Set<String> deps = pkg.typeDependencies()
|
||||
.values()
|
||||
.stream()
|
||||
.flatMap(s -> s.stream())
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
for (String dep : deps) {
|
||||
String depPkg = ":" + dep.substring(0, dep.lastIndexOf('.'));
|
||||
|
@ -53,6 +53,7 @@ import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileManager;
|
||||
@ -240,7 +241,7 @@ public abstract class JavadocHelper implements AutoCloseable {
|
||||
List<String> throwsList =
|
||||
executableElement.getThrownTypes()
|
||||
.stream()
|
||||
.map(exc -> exc.toString())
|
||||
.map(TypeMirror::toString)
|
||||
.collect(Collectors.toList());
|
||||
Set<String> missingParams = new HashSet<>(parameters);
|
||||
Set<String> missingThrows = new HashSet<>(throwsList);
|
||||
|
@ -31,6 +31,7 @@ import javax.tools.JavaFileObject;
|
||||
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
||||
import com.sun.tools.javac.code.ClassFinder;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
|
||||
/** Javadoc uses an extended class finder that records package.html entries
|
||||
*
|
||||
@ -52,11 +53,7 @@ public class JavadocClassFinder extends ClassFinder {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(classFinderKey, new Context.Factory<ClassFinder>() {
|
||||
public ClassFinder make(Context c) {
|
||||
return new JavadocClassFinder(c);
|
||||
}
|
||||
});
|
||||
context.put(classFinderKey, (Factory<ClassFinder>)JavadocClassFinder::new);
|
||||
}
|
||||
|
||||
private DocEnv docenv;
|
||||
|
@ -58,11 +58,7 @@ public class JavadocEnter extends Enter {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(enterKey, new Context.Factory<Enter>() {
|
||||
public Enter make(Context c) {
|
||||
return new JavadocEnter(c);
|
||||
}
|
||||
});
|
||||
context.put(enterKey, (Context.Factory<Enter>)JavadocEnter::new);
|
||||
}
|
||||
|
||||
protected JavadocEnter(Context context) {
|
||||
|
@ -57,11 +57,7 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
|
||||
public MemberEnter make(Context c) {
|
||||
return new JavadocMemberEnter(c);
|
||||
}
|
||||
});
|
||||
context.put(memberEnterKey, (Context.Factory<MemberEnter>)JavadocMemberEnter::new);
|
||||
}
|
||||
|
||||
final DocEnv docenv;
|
||||
|
@ -27,6 +27,7 @@ package com.sun.tools.javadoc.main;
|
||||
|
||||
import com.sun.tools.javac.comp.*;
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
|
||||
/**
|
||||
* Javadoc's own todo queue doesn't queue its inputs, as javadoc
|
||||
@ -42,11 +43,7 @@ import com.sun.tools.javac.util.*;
|
||||
@Deprecated
|
||||
public class JavadocTodo extends Todo {
|
||||
public static void preRegister(Context context) {
|
||||
context.put(todoKey, new Context.Factory<Todo>() {
|
||||
public Todo make(Context c) {
|
||||
return new JavadocTodo(c);
|
||||
}
|
||||
});
|
||||
context.put(todoKey, (Factory<Todo>)JavadocTodo::new);
|
||||
}
|
||||
|
||||
protected JavadocTodo(Context context) {
|
||||
|
@ -31,6 +31,7 @@ import java.util.ResourceBundle;
|
||||
|
||||
import com.sun.javadoc.*;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
|
||||
import com.sun.tools.javac.util.JavacMessages;
|
||||
@ -66,27 +67,18 @@ public class Messager extends Log implements DocErrorReporter {
|
||||
|
||||
public static void preRegister(Context context,
|
||||
final String programName) {
|
||||
context.put(logKey, new Context.Factory<Log>() {
|
||||
public Log make(Context c) {
|
||||
return new Messager(c,
|
||||
programName);
|
||||
}
|
||||
});
|
||||
context.put(logKey, (Factory<Log>)c -> new Messager(c, programName));
|
||||
}
|
||||
public static void preRegister(Context context,
|
||||
final String programName,
|
||||
final PrintWriter errWriter,
|
||||
final PrintWriter warnWriter,
|
||||
final PrintWriter noticeWriter) {
|
||||
context.put(logKey, new Context.Factory<Log>() {
|
||||
public Log make(Context c) {
|
||||
return new Messager(c,
|
||||
programName,
|
||||
errWriter,
|
||||
warnWriter,
|
||||
noticeWriter);
|
||||
}
|
||||
});
|
||||
context.put(logKey, (Factory<Log>)c -> new Messager(c,
|
||||
programName,
|
||||
errWriter,
|
||||
warnWriter,
|
||||
noticeWriter));
|
||||
}
|
||||
|
||||
public class ExitJavadoc extends Error {
|
||||
|
@ -258,7 +258,7 @@ public abstract class AbstractMemberWriter {
|
||||
}
|
||||
}
|
||||
if (!set.isEmpty()) {
|
||||
String mods = set.stream().map(m -> m.toString()).collect(Collectors.joining(" "));
|
||||
String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
|
||||
htmltree.addContent(mods);
|
||||
htmltree.addContent(Contents.SPACE);
|
||||
}
|
||||
|
@ -263,9 +263,7 @@ public abstract class AbstractDoclet implements Doclet {
|
||||
generateClassFiles(classtree);
|
||||
SortedSet<PackageElement> packages = new TreeSet<>(utils.makePackageComparator());
|
||||
packages.addAll(configuration.getSpecifiedPackageElements());
|
||||
configuration.modulePackages.values().stream().forEach(pset -> {
|
||||
packages.addAll(pset);
|
||||
});
|
||||
configuration.modulePackages.values().stream().forEach(packages::addAll);
|
||||
for (PackageElement pkg : packages) {
|
||||
generateClassFiles(utils.getAllClasses(pkg), classtree);
|
||||
}
|
||||
|
@ -529,9 +529,7 @@ public class MemberSummaryBuilder extends AbstractMemberBuilder {
|
||||
buildInheritedSummary(writer, visibleMemberMap, summaryTreeList);
|
||||
if (!summaryTreeList.isEmpty()) {
|
||||
Content memberTree = writer.getMemberSummaryHeader(typeElement, memberSummaryTree);
|
||||
summaryTreeList.stream().forEach((aSummaryTreeList) -> {
|
||||
memberTree.addContent(aSummaryTreeList);
|
||||
});
|
||||
summaryTreeList.stream().forEach(memberTree::addContent);
|
||||
writer.addMemberTree(memberSummaryTree, memberTree);
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
void addModifers(Set<Modifier> modifiers) {
|
||||
String s = set.stream().map(m -> m.toString()).collect(Collectors.joining(" "));
|
||||
String s = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
|
||||
sb.append(s);
|
||||
if (!s.isEmpty())
|
||||
sb.append(" ");
|
||||
|
@ -255,13 +255,9 @@ public abstract class LinkFactory {
|
||||
vars.add(t.asType());
|
||||
});
|
||||
} else if (linkInfo.type != null && utils.isDeclaredType(linkInfo.type)) {
|
||||
((DeclaredType)linkInfo.type).getTypeArguments().stream().forEach((t) -> {
|
||||
vars.add(t);
|
||||
});
|
||||
((DeclaredType)linkInfo.type).getTypeArguments().stream().forEach(vars::add);
|
||||
} else if (ctype != null && utils.isDeclaredType(ctype)) {
|
||||
((DeclaredType)ctype).getTypeArguments().stream().forEach((t) -> {
|
||||
vars.add(t);
|
||||
});
|
||||
((DeclaredType)ctype).getTypeArguments().stream().forEach(vars::add);
|
||||
} else if (linkInfo.typeElement != null) {
|
||||
linkInfo.typeElement.getTypeParameters().stream().forEach((t) -> {
|
||||
vars.add(t.asType());
|
||||
|
@ -373,7 +373,7 @@ public class ElementsTable {
|
||||
// scan for modules with qualified subpackages
|
||||
((List<String>)opts.computeIfAbsent(ToolOption.SUBPACKAGES, v -> Collections.EMPTY_LIST))
|
||||
.stream()
|
||||
.map((packageName) -> new ModulePackage(packageName))
|
||||
.map(ModulePackage::new)
|
||||
.forEachOrdered((mpkg) -> {
|
||||
subPackages.add(mpkg);
|
||||
if (mpkg.hasModule()) {
|
||||
@ -420,7 +420,7 @@ public class ElementsTable {
|
||||
*/
|
||||
ElementsTable packages(Collection<String> packageNames) {
|
||||
packageNames.stream()
|
||||
.map((packageName) -> new ModulePackage(packageName))
|
||||
.map(ModulePackage::new)
|
||||
.forEachOrdered((mpkg) -> cmdLinePackages.add(mpkg));
|
||||
return this;
|
||||
}
|
||||
@ -443,7 +443,7 @@ public class ElementsTable {
|
||||
private void computeSubpackages() throws ToolException {
|
||||
((List<String>) opts.computeIfAbsent(ToolOption.EXCLUDE, v -> Collections.EMPTY_LIST))
|
||||
.stream()
|
||||
.map((packageName) -> new ModulePackage(packageName))
|
||||
.map(ModulePackage::new)
|
||||
.forEachOrdered((mpkg) -> excludePackages.add(mpkg));
|
||||
|
||||
excludePackages.forEach((p) -> {
|
||||
|
@ -33,6 +33,7 @@ import com.sun.tools.javac.api.JavacTrees;
|
||||
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
||||
import com.sun.tools.javac.code.ClassFinder;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
|
||||
/** Javadoc uses an extended class finder that records package.html entries
|
||||
*
|
||||
@ -53,11 +54,7 @@ public class JavadocClassFinder extends ClassFinder {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(classFinderKey, new Context.Factory<ClassFinder>() {
|
||||
public ClassFinder make(Context c) {
|
||||
return new JavadocClassFinder(c);
|
||||
}
|
||||
});
|
||||
context.put(classFinderKey, (Factory<ClassFinder>)JavadocClassFinder::new);
|
||||
}
|
||||
|
||||
private ToolEnvironment toolEnv;
|
||||
|
@ -57,11 +57,7 @@ public class JavadocEnter extends Enter {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(enterKey, new Context.Factory<Enter>() {
|
||||
public Enter make(Context c) {
|
||||
return new JavadocEnter(c);
|
||||
}
|
||||
});
|
||||
context.put(enterKey, (Context.Factory<Enter>)JavadocEnter::new);
|
||||
}
|
||||
|
||||
protected JavadocEnter(Context context) {
|
||||
|
@ -56,11 +56,7 @@ public class JavadocMemberEnter extends MemberEnter {
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
|
||||
public MemberEnter make(Context c) {
|
||||
return new JavadocMemberEnter(c);
|
||||
}
|
||||
});
|
||||
context.put(memberEnterKey, (Context.Factory<MemberEnter>)JavadocMemberEnter::new);
|
||||
}
|
||||
|
||||
final ToolEnvironment toolEnv;
|
||||
|
@ -27,6 +27,7 @@ package jdk.javadoc.internal.tool;
|
||||
|
||||
import com.sun.tools.javac.comp.*;
|
||||
import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
|
||||
/**
|
||||
* Javadoc's own todo queue doesn't queue its inputs, as javadoc
|
||||
@ -41,11 +42,7 @@ import com.sun.tools.javac.util.*;
|
||||
*/
|
||||
public class JavadocTodo extends Todo {
|
||||
public static void preRegister(Context context) {
|
||||
context.put(todoKey, new Context.Factory<Todo>() {
|
||||
public Todo make(Context c) {
|
||||
return new JavadocTodo(c);
|
||||
}
|
||||
});
|
||||
context.put(todoKey, (Factory<Todo>)JavadocTodo::new);
|
||||
}
|
||||
|
||||
protected JavadocTodo(Context context) {
|
||||
|
@ -33,6 +33,7 @@ import java.util.ResourceBundle;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import com.sun.tools.javac.util.Context.Factory;
|
||||
import jdk.javadoc.doclet.Reporter;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.DocSourcePositions;
|
||||
@ -73,20 +74,12 @@ public class Messager extends Log implements Reporter {
|
||||
|
||||
public static void preRegister(Context context,
|
||||
final String programName) {
|
||||
context.put(logKey, new Context.Factory<Log>() {
|
||||
public Log make(Context c) {
|
||||
return new Messager(c, programName);
|
||||
}
|
||||
});
|
||||
context.put(logKey, (Factory<Log>)c -> new Messager(c, programName));
|
||||
}
|
||||
|
||||
public static void preRegister(Context context, final String programName,
|
||||
final PrintWriter outWriter, final PrintWriter errWriter) {
|
||||
context.put(logKey, new Context.Factory<Log>() {
|
||||
public Log make(Context c) {
|
||||
return new Messager(c, programName, outWriter, errWriter);
|
||||
}
|
||||
});
|
||||
context.put(logKey, (Factory<Log>)c -> new Messager(c, programName, outWriter, errWriter));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,7 +211,7 @@ public class Start extends ToolOption.Helper {
|
||||
Stream.of(ToolOption.values())
|
||||
.filter(opt -> opt.kind == kind)
|
||||
.sorted(comp)
|
||||
.forEach(opt -> showToolOption(opt));
|
||||
.forEach(this::showToolOption);
|
||||
}
|
||||
|
||||
void showToolOption(ToolOption option) {
|
||||
@ -241,7 +241,7 @@ public class Start extends ToolOption.Helper {
|
||||
doclet.getSupportedOptions().stream()
|
||||
.filter(opt -> opt.getKind() == kind)
|
||||
.sorted(comp)
|
||||
.forEach(opt -> showDocletOption(opt));
|
||||
.forEach(this::showDocletOption);
|
||||
}
|
||||
|
||||
void showDocletOption(Doclet.Option option) {
|
||||
|
@ -103,35 +103,30 @@ public class Code_attribute extends Attribute {
|
||||
}
|
||||
|
||||
public Iterable<Instruction> getInstructions() {
|
||||
return new Iterable<Instruction>() {
|
||||
public Iterator<Instruction> iterator() {
|
||||
return new Iterator<Instruction>() {
|
||||
return () -> new Iterator<Instruction>() {
|
||||
|
||||
public boolean hasNext() {
|
||||
return (next != null);
|
||||
}
|
||||
|
||||
public Instruction next() {
|
||||
if (next == null)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
current = next;
|
||||
pc += current.length();
|
||||
next = (pc < code.length ? new Instruction(code, pc) : null);
|
||||
return current;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
Instruction current = null;
|
||||
int pc = 0;
|
||||
Instruction next = new Instruction(code, pc);
|
||||
|
||||
};
|
||||
public boolean hasNext() {
|
||||
return (next != null);
|
||||
}
|
||||
|
||||
public Instruction next() {
|
||||
if (next == null)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
current = next;
|
||||
pc += current.length();
|
||||
next = (pc < code.length ? new Instruction(code, pc) : null);
|
||||
return current;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
Instruction current = null;
|
||||
int pc = 0;
|
||||
Instruction next = new Instruction(code, pc);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -313,36 +313,32 @@ public class ConstantPool {
|
||||
}
|
||||
|
||||
public Iterable<CPInfo> entries() {
|
||||
return new Iterable<CPInfo>() {
|
||||
public Iterator<CPInfo> iterator() {
|
||||
return new Iterator<CPInfo>() {
|
||||
return () -> new Iterator<CPInfo>() {
|
||||
|
||||
public boolean hasNext() {
|
||||
return next < pool.length;
|
||||
}
|
||||
|
||||
public CPInfo next() {
|
||||
current = pool[next];
|
||||
switch (current.getTag()) {
|
||||
case CONSTANT_Double:
|
||||
case CONSTANT_Long:
|
||||
next += 2;
|
||||
break;
|
||||
default:
|
||||
next += 1;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private CPInfo current;
|
||||
private int next = 1;
|
||||
|
||||
};
|
||||
public boolean hasNext() {
|
||||
return next < pool.length;
|
||||
}
|
||||
|
||||
public CPInfo next() {
|
||||
current = pool[next];
|
||||
switch (current.getTag()) {
|
||||
case CONSTANT_Double:
|
||||
case CONSTANT_Long:
|
||||
next += 2;
|
||||
break;
|
||||
default:
|
||||
next += 1;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private CPInfo current;
|
||||
private int next = 1;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -248,11 +248,7 @@ public class Dependencies {
|
||||
boolean transitiveClosure)
|
||||
throws ClassFileNotFoundException {
|
||||
final Set<Dependency> results = new HashSet<>();
|
||||
Recorder r = new Recorder() {
|
||||
public void addDependency(Dependency d) {
|
||||
results.add(d);
|
||||
}
|
||||
};
|
||||
Recorder r = results::add;
|
||||
findAllDependencies(classFinder, rootClassNames, transitiveClosure, r);
|
||||
return results;
|
||||
}
|
||||
@ -565,7 +561,7 @@ public class Dependencies {
|
||||
private Map<String,Location> locations = new ConcurrentHashMap<>();
|
||||
|
||||
Location getLocation(String className) {
|
||||
return locations.computeIfAbsent(className, cn -> new SimpleLocation(cn));
|
||||
return locations.computeIfAbsent(className, SimpleLocation::new);
|
||||
}
|
||||
|
||||
class Visitor implements ConstantPool.Visitor<Void,Void>, Type.Visitor<Void, Void> {
|
||||
|
@ -408,22 +408,20 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
|
||||
|
||||
private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
|
||||
final PrintWriter pw = getPrintWriterForWriter(w);
|
||||
return new DiagnosticListener<JavaFileObject> () {
|
||||
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||
switch (diagnostic.getKind()) {
|
||||
case ERROR:
|
||||
pw.print(getMessage("err.prefix"));
|
||||
break;
|
||||
case WARNING:
|
||||
pw.print(getMessage("warn.prefix"));
|
||||
break;
|
||||
case NOTE:
|
||||
pw.print(getMessage("note.prefix"));
|
||||
break;
|
||||
}
|
||||
pw.print(" ");
|
||||
pw.println(diagnostic.getMessage(null));
|
||||
return diagnostic -> {
|
||||
switch (diagnostic.getKind()) {
|
||||
case ERROR:
|
||||
pw.print(getMessage("err.prefix"));
|
||||
break;
|
||||
case WARNING:
|
||||
pw.print(getMessage("warn.prefix"));
|
||||
break;
|
||||
case NOTE:
|
||||
pw.print(getMessage("note.prefix"));
|
||||
break;
|
||||
}
|
||||
pw.print(" ");
|
||||
pw.println(diagnostic.getMessage(null));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -147,11 +147,7 @@ public class ClassFileReader implements Closeable {
|
||||
}
|
||||
|
||||
public Iterable<ClassFile> getClassFiles() throws IOException {
|
||||
return new Iterable<ClassFile>() {
|
||||
public Iterator<ClassFile> iterator() {
|
||||
return new FileIterator();
|
||||
}
|
||||
};
|
||||
return FileIterator::new;
|
||||
}
|
||||
|
||||
protected ClassFile readClassFile(Path p) throws IOException {
|
||||
@ -232,7 +228,7 @@ public class ClassFileReader implements Closeable {
|
||||
protected Set<String> scan() {
|
||||
try (Stream<Path> stream = Files.walk(path, Integer.MAX_VALUE)) {
|
||||
return stream.filter(ClassFileReader::isClass)
|
||||
.map(f -> path.relativize(f))
|
||||
.map(path::relativize)
|
||||
.map(Path::toString)
|
||||
.map(p -> p.replace(File.separatorChar, '/'))
|
||||
.collect(Collectors.toSet());
|
||||
@ -264,11 +260,7 @@ public class ClassFileReader implements Closeable {
|
||||
|
||||
public Iterable<ClassFile> getClassFiles() throws IOException {
|
||||
final Iterator<ClassFile> iter = new DirectoryIterator();
|
||||
return new Iterable<ClassFile>() {
|
||||
public Iterator<ClassFile> iterator() {
|
||||
return iter;
|
||||
}
|
||||
};
|
||||
return () -> iter;
|
||||
}
|
||||
|
||||
class DirectoryIterator implements Iterator<ClassFile> {
|
||||
@ -387,11 +379,7 @@ public class ClassFileReader implements Closeable {
|
||||
|
||||
public Iterable<ClassFile> getClassFiles() throws IOException {
|
||||
final Iterator<ClassFile> iter = new JarFileIterator(this, jarfile);
|
||||
return new Iterable<ClassFile>() {
|
||||
public Iterator<ClassFile> iterator() {
|
||||
return iter;
|
||||
}
|
||||
};
|
||||
return () -> iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ import com.sun.tools.classfile.AccessFlags;
|
||||
import com.sun.tools.classfile.ClassFile;
|
||||
import com.sun.tools.classfile.ConstantPoolException;
|
||||
import com.sun.tools.classfile.Dependencies;
|
||||
import com.sun.tools.classfile.Dependencies.ClassFileError;
|
||||
import com.sun.tools.classfile.Dependency;
|
||||
import com.sun.tools.classfile.Dependency.Location;
|
||||
|
||||
@ -172,43 +173,41 @@ class DependencyFinder {
|
||||
parsedArchives.get(finder).add(archive);
|
||||
|
||||
trace("parsing %s %s%n", archive.getName(), archive.path());
|
||||
FutureTask<Set<Location>> task = new FutureTask<>(new Callable<>() {
|
||||
public Set<Location> call() throws Exception {
|
||||
Set<Location> targets = new HashSet<>();
|
||||
for (ClassFile cf : archive.reader().getClassFiles()) {
|
||||
if (cf.access_flags.is(AccessFlags.ACC_MODULE))
|
||||
continue;
|
||||
FutureTask<Set<Location>> task = new FutureTask<>(() -> {
|
||||
Set<Location> targets = new HashSet<>();
|
||||
for (ClassFile cf : archive.reader().getClassFiles()) {
|
||||
if (cf.access_flags.is(AccessFlags.ACC_MODULE))
|
||||
continue;
|
||||
|
||||
String classFileName;
|
||||
try {
|
||||
classFileName = cf.getName();
|
||||
} catch (ConstantPoolException e) {
|
||||
throw new Dependencies.ClassFileError(e);
|
||||
}
|
||||
|
||||
// filter source class/archive
|
||||
String cn = classFileName.replace('/', '.');
|
||||
if (!finder.accept(archive, cn, cf.access_flags))
|
||||
continue;
|
||||
|
||||
// tests if this class matches the -include
|
||||
if (!filter.matches(cn))
|
||||
continue;
|
||||
|
||||
for (Dependency d : finder.findDependencies(cf)) {
|
||||
if (filter.accepts(d)) {
|
||||
archive.addClass(d.getOrigin(), d.getTarget());
|
||||
targets.add(d.getTarget());
|
||||
} else {
|
||||
// ensure that the parsed class is added the archive
|
||||
archive.addClass(d.getOrigin());
|
||||
}
|
||||
parsedClasses.putIfAbsent(d.getOrigin(), archive);
|
||||
}
|
||||
String classFileName;
|
||||
try {
|
||||
classFileName = cf.getName();
|
||||
} catch (ConstantPoolException e) {
|
||||
throw new ClassFileError(e);
|
||||
}
|
||||
|
||||
return targets;
|
||||
// filter source class/archive
|
||||
String cn = classFileName.replace('/', '.');
|
||||
if (!finder.accept(archive, cn, cf.access_flags))
|
||||
continue;
|
||||
|
||||
// tests if this class matches the -include
|
||||
if (!filter.matches(cn))
|
||||
continue;
|
||||
|
||||
for (Dependency d : finder.findDependencies(cf)) {
|
||||
if (filter.accepts(d)) {
|
||||
archive.addClass(d.getOrigin(), d.getTarget());
|
||||
targets.add(d.getTarget());
|
||||
} else {
|
||||
// ensure that the parsed class is added the archive
|
||||
archive.addClass(d.getOrigin());
|
||||
}
|
||||
parsedClasses.putIfAbsent(d.getOrigin(), archive);
|
||||
}
|
||||
}
|
||||
|
||||
return targets;
|
||||
});
|
||||
tasks.add(task);
|
||||
pool.submit(task);
|
||||
|
@ -209,7 +209,7 @@ public final class Graph<T> {
|
||||
visited.add(node);
|
||||
edges.get(node).stream()
|
||||
.filter(e -> includeAdjacent || !node.equals(u) || !e.equals(v))
|
||||
.forEach(e -> stack.push(e));
|
||||
.forEach(stack::push);
|
||||
}
|
||||
}
|
||||
assert !visited.contains(v);
|
||||
|
@ -394,25 +394,20 @@ public class JdepsConfiguration implements AutoCloseable {
|
||||
ModuleDescriptor descriptor = dropHashes(ModuleDescriptor.read(bin));
|
||||
String mn = descriptor.name();
|
||||
URI uri = URI.create("jrt:/" + path.getFileName().toString());
|
||||
Supplier<ModuleReader> readerSupplier = new Supplier<>() {
|
||||
Supplier<ModuleReader> readerSupplier = () -> new ModuleReader() {
|
||||
@Override
|
||||
public ModuleReader get() {
|
||||
return new ModuleReader() {
|
||||
@Override
|
||||
public Optional<URI> find(String name) throws IOException {
|
||||
return name.equals(mn)
|
||||
? Optional.of(uri) : Optional.empty();
|
||||
}
|
||||
public Optional<URI> find(String name) throws IOException {
|
||||
return name.equals(mn)
|
||||
? Optional.of(uri) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> list() {
|
||||
return Stream.empty();
|
||||
}
|
||||
@Override
|
||||
public Stream<String> list() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -889,15 +889,11 @@ class JdepsTask {
|
||||
if (!ok && !options.nowarning) {
|
||||
reportError("err.missing.dependences");
|
||||
builder.visitMissingDeps(
|
||||
new Analyzer.Visitor() {
|
||||
@Override
|
||||
public void visitDependence(String origin, Archive originArchive,
|
||||
String target, Archive targetArchive) {
|
||||
(origin, originArchive, target, targetArchive) -> {
|
||||
if (builder.notFound(targetArchive))
|
||||
log.format(" %-50s -> %-50s %s%n",
|
||||
origin, target, targetArchive.getName());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -69,21 +69,16 @@ public class ModuleExportsAnalyzer extends DepsAnalyzer {
|
||||
|
||||
// A visitor to record the module-level dependences as well as
|
||||
// use of JDK internal APIs
|
||||
Analyzer.Visitor visitor = new Analyzer.Visitor() {
|
||||
@Override
|
||||
public void visitDependence(String origin, Archive originArchive,
|
||||
String target, Archive targetArchive)
|
||||
{
|
||||
Set<String> jdkInternals =
|
||||
deps.computeIfAbsent(originArchive, _k -> new HashMap<>())
|
||||
.computeIfAbsent(targetArchive, _k -> new HashSet<>());
|
||||
Analyzer.Visitor visitor = (origin, originArchive, target, targetArchive) -> {
|
||||
Set<String> jdkInternals =
|
||||
deps.computeIfAbsent(originArchive, _k -> new HashMap<>())
|
||||
.computeIfAbsent(targetArchive, _k -> new HashSet<>());
|
||||
|
||||
Module module = targetArchive.getModule();
|
||||
if (originArchive.getModule() != module &&
|
||||
module.isJDK() && !module.isExported(target)) {
|
||||
// use of JDK internal APIs
|
||||
jdkInternals.add(target);
|
||||
}
|
||||
Module module = targetArchive.getModule();
|
||||
if (originArchive.getModule() != module &&
|
||||
module.isJDK() && !module.isExported(target)) {
|
||||
// use of JDK internal APIs
|
||||
jdkInternals.add(target);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -150,6 +150,6 @@ enum Profile {
|
||||
}
|
||||
System.out.println("All JDK modules:-");
|
||||
JDK.stream().sorted(Comparator.comparing(Module::name))
|
||||
.forEach(m -> System.out.println(m));
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
@ -139,7 +141,7 @@ class ArgTokenizer {
|
||||
*/
|
||||
int optionCount() {
|
||||
return (int) options.entrySet().stream()
|
||||
.filter(e -> e.getValue())
|
||||
.filter(Entry::getValue)
|
||||
.count();
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ class ConsoleIOContext extends IOContext {
|
||||
|
||||
boolean smart = allowSmart &&
|
||||
suggestions.stream()
|
||||
.anyMatch(s -> s.matchesType());
|
||||
.anyMatch(Suggestion::matchesType);
|
||||
|
||||
lastTest = test;
|
||||
lastCursor = cursor;
|
||||
@ -133,16 +133,16 @@ class ConsoleIOContext extends IOContext {
|
||||
|
||||
suggestions.stream()
|
||||
.filter(s -> !smart || s.matchesType())
|
||||
.map(s -> s.continuation())
|
||||
.map(Suggestion::continuation)
|
||||
.forEach(result::add);
|
||||
|
||||
boolean onlySmart = suggestions.stream()
|
||||
.allMatch(s -> s.matchesType());
|
||||
.allMatch(Suggestion::matchesType);
|
||||
|
||||
if (smart && !onlySmart) {
|
||||
Optional<String> prefix =
|
||||
suggestions.stream()
|
||||
.map(s -> s.continuation())
|
||||
.map(Suggestion::continuation)
|
||||
.reduce(ConsoleIOContext::commonPrefix);
|
||||
|
||||
String prefixStr = prefix.orElse("").substring(cursor - anchor[0]);
|
||||
@ -281,7 +281,7 @@ class ConsoleIOContext extends IOContext {
|
||||
term.isAnsiSupported());
|
||||
Function<Documentation, String> convertor;
|
||||
if (firstInvocation) {
|
||||
convertor = d -> d.signature();
|
||||
convertor = Documentation::signature;
|
||||
} else {
|
||||
convertor = d -> formatter.formatJavadoc(d.signature(), d.javadoc()) +
|
||||
(d.javadoc() == null ? repl.messageFormat("jshell.console.no.javadoc")
|
||||
|
@ -38,10 +38,8 @@ import jdk.jshell.SourceCodeAnalysis.Suggestion;
|
||||
|
||||
class ContinuousCompletionProvider implements CompletionProvider {
|
||||
|
||||
static final BiPredicate<String, String> STARTSWITH_MATCHER =
|
||||
(word, input) -> word.startsWith(input);
|
||||
static final BiPredicate<String, String> PERFECT_MATCHER =
|
||||
(word, input) -> word.equals(input);
|
||||
static final BiPredicate<String, String> STARTSWITH_MATCHER = String::startsWith;
|
||||
static final BiPredicate<String, String> PERFECT_MATCHER = String::equals;
|
||||
|
||||
private final Supplier<Map<String, CompletionProvider>> wordCompletionProviderSupplier;
|
||||
private final BiPredicate<String, String> matcher;
|
||||
|
@ -882,7 +882,7 @@ class Feedback {
|
||||
|
||||
void showTruncationSettings(Mode sm) {
|
||||
if (sm == null) {
|
||||
modeMap.values().forEach(m -> showTruncationSettings(m));
|
||||
modeMap.values().forEach(this::showTruncationSettings);
|
||||
} else {
|
||||
List<Mode.Setting> trunc = sm.cases.get(TRUNCATION_FIELD);
|
||||
if (trunc != null) {
|
||||
@ -897,7 +897,7 @@ class Feedback {
|
||||
|
||||
void showPromptSettings(Mode sm) {
|
||||
if (sm == null) {
|
||||
modeMap.values().forEach(m -> showPromptSettings(m));
|
||||
modeMap.values().forEach(this::showPromptSettings);
|
||||
} else {
|
||||
hard("/set prompt %s %s %s",
|
||||
sm.name,
|
||||
@ -908,7 +908,7 @@ class Feedback {
|
||||
|
||||
void showModeSettings(String umode, String msg) {
|
||||
if (umode == null) {
|
||||
modeMap.values().forEach(n -> showModeSettings(n));
|
||||
modeMap.values().forEach(this::showModeSettings);
|
||||
} else {
|
||||
Mode m;
|
||||
String retained = retainedMap.get(umode);
|
||||
@ -1272,7 +1272,7 @@ class Feedback {
|
||||
return null;
|
||||
}
|
||||
if (at.isQuoted() ||
|
||||
!id.codePoints().allMatch(cp -> Character.isJavaIdentifierPart(cp))) {
|
||||
!id.codePoints().allMatch(Character::isJavaIdentifierPart)) {
|
||||
errorat(err, id);
|
||||
return null;
|
||||
}
|
||||
@ -1307,8 +1307,8 @@ class Feedback {
|
||||
// Failing an exact match, go searching
|
||||
Mode[] matches = modeMap.entrySet().stream()
|
||||
.filter(e -> e.getKey().startsWith(umode))
|
||||
.map(e -> e.getValue())
|
||||
.toArray(size -> new Mode[size]);
|
||||
.map(Entry::getValue)
|
||||
.toArray(Mode[]::new);
|
||||
if (matches.length == 1) {
|
||||
return matches[0];
|
||||
} else {
|
||||
|
@ -452,7 +452,7 @@ public class JShellTool implements MessageHandler {
|
||||
<T> void hardPairs(Stream<T> stream, Function<T, String> a, Function<T, String> b) {
|
||||
Map<String, String> a2b = stream.collect(toMap(a, b,
|
||||
(m1, m2) -> m1,
|
||||
() -> new LinkedHashMap<>()));
|
||||
LinkedHashMap::new));
|
||||
for (Entry<String, String> e : a2b.entrySet()) {
|
||||
hard("%s", e.getKey());
|
||||
rawout(prefix(e.getValue(), feedback.getPre() + "\t", feedback.getPost()));
|
||||
@ -953,7 +953,7 @@ public class JShellTool implements MessageHandler {
|
||||
.stream()
|
||||
.filter(filter)
|
||||
.filter(command -> command.command.startsWith(cmd))
|
||||
.toArray(size -> new Command[size]);
|
||||
.toArray(Command[]::new);
|
||||
}
|
||||
|
||||
private static Path toPathResolvingUserHome(String pathString) {
|
||||
@ -1125,7 +1125,7 @@ public class JShellTool implements MessageHandler {
|
||||
? Stream.of(String.valueOf(k.id()) + " ", ((DeclarationSnippet) k).name() + " ")
|
||||
: Stream.of(String.valueOf(k.id()) + " "))
|
||||
.filter(k -> k.startsWith(argPrefix))
|
||||
.map(k -> new ArgSuggestion(k))
|
||||
.map(ArgSuggestion::new)
|
||||
.collect(Collectors.toList());
|
||||
};
|
||||
}
|
||||
@ -1154,7 +1154,7 @@ public class JShellTool implements MessageHandler {
|
||||
result = new FixedCompletionProvider(commands.values().stream()
|
||||
.filter(cmd -> cmd.kind.showInHelp || cmd.kind == CommandKind.HELP_SUBJECT)
|
||||
.map(c -> c.command + " ")
|
||||
.toArray(size -> new String[size]))
|
||||
.toArray(String[]::new))
|
||||
.completionSuggestions(code, cursor, anchor);
|
||||
} else if (code.startsWith("/se")) {
|
||||
result = new FixedCompletionProvider(SET_SUBCOMMANDS)
|
||||
@ -1264,33 +1264,33 @@ public class JShellTool implements MessageHandler {
|
||||
|
||||
{
|
||||
registerCommand(new Command("/list",
|
||||
arg -> cmdList(arg),
|
||||
this::cmdList,
|
||||
snippetWithOptionCompletion(SNIPPET_HISTORY_OPTION_COMPLETION_PROVIDER,
|
||||
this::allSnippets)));
|
||||
registerCommand(new Command("/edit",
|
||||
arg -> cmdEdit(arg),
|
||||
this::cmdEdit,
|
||||
snippetWithOptionCompletion(SNIPPET_OPTION_COMPLETION_PROVIDER,
|
||||
this::allSnippets)));
|
||||
registerCommand(new Command("/drop",
|
||||
arg -> cmdDrop(arg),
|
||||
this::cmdDrop,
|
||||
snippetCompletion(this::dropableSnippets),
|
||||
CommandKind.REPLAY));
|
||||
registerCommand(new Command("/save",
|
||||
arg -> cmdSave(arg),
|
||||
this::cmdSave,
|
||||
saveCompletion()));
|
||||
registerCommand(new Command("/open",
|
||||
arg -> cmdOpen(arg),
|
||||
this::cmdOpen,
|
||||
FILE_COMPLETION_PROVIDER));
|
||||
registerCommand(new Command("/vars",
|
||||
arg -> cmdVars(arg),
|
||||
this::cmdVars,
|
||||
snippetWithOptionCompletion(SNIPPET_OPTION_COMPLETION_PROVIDER,
|
||||
this::allVarSnippets)));
|
||||
registerCommand(new Command("/methods",
|
||||
arg -> cmdMethods(arg),
|
||||
this::cmdMethods,
|
||||
snippetWithOptionCompletion(SNIPPET_OPTION_COMPLETION_PROVIDER,
|
||||
this::allMethodSnippets)));
|
||||
registerCommand(new Command("/types",
|
||||
arg -> cmdTypes(arg),
|
||||
this::cmdTypes,
|
||||
snippetWithOptionCompletion(SNIPPET_OPTION_COMPLETION_PROVIDER,
|
||||
this::allTypeSnippets)));
|
||||
registerCommand(new Command("/imports",
|
||||
@ -1303,24 +1303,24 @@ public class JShellTool implements MessageHandler {
|
||||
arg -> cmdReset(),
|
||||
EMPTY_COMPLETION_PROVIDER));
|
||||
registerCommand(new Command("/reload",
|
||||
arg -> cmdReload(arg),
|
||||
this::cmdReload,
|
||||
reloadCompletion()));
|
||||
registerCommand(new Command("/classpath",
|
||||
arg -> cmdClasspath(arg),
|
||||
this::cmdClasspath,
|
||||
classPathCompletion(),
|
||||
CommandKind.REPLAY));
|
||||
registerCommand(new Command("/history",
|
||||
arg -> cmdHistory(),
|
||||
EMPTY_COMPLETION_PROVIDER));
|
||||
registerCommand(new Command("/debug",
|
||||
arg -> cmdDebug(arg),
|
||||
this::cmdDebug,
|
||||
EMPTY_COMPLETION_PROVIDER,
|
||||
CommandKind.HIDDEN));
|
||||
registerCommand(new Command("/help",
|
||||
arg -> cmdHelp(arg),
|
||||
this::cmdHelp,
|
||||
helpCompletion()));
|
||||
registerCommand(new Command("/set",
|
||||
arg -> cmdSet(arg),
|
||||
this::cmdSet,
|
||||
new ContinuousCompletionProvider(Map.of(
|
||||
// need more completion for format for usability
|
||||
"format", feedback.modeCompletions(),
|
||||
@ -1335,7 +1335,7 @@ public class JShellTool implements MessageHandler {
|
||||
STARTSWITH_MATCHER)));
|
||||
registerCommand(new Command("/?",
|
||||
"help.quest",
|
||||
arg -> cmdHelp(arg),
|
||||
this::cmdHelp,
|
||||
helpCompletion(),
|
||||
CommandKind.NORMAL));
|
||||
registerCommand(new Command("/!",
|
||||
@ -1450,7 +1450,7 @@ public class JShellTool implements MessageHandler {
|
||||
}
|
||||
String[] matches = Arrays.stream(subs)
|
||||
.filter(s -> s.startsWith(sub))
|
||||
.toArray(size -> new String[size]);
|
||||
.toArray(String[]::new);
|
||||
if (matches.length == 0) {
|
||||
// There are no matching sub-commands
|
||||
errormsg("jshell.err.arg", cmd, sub);
|
||||
@ -1784,7 +1784,7 @@ public class JShellTool implements MessageHandler {
|
||||
if (subject != null) {
|
||||
Command[] matches = commands.values().stream()
|
||||
.filter(c -> c.command.startsWith(subject))
|
||||
.toArray(size -> new Command[size]);
|
||||
.toArray(Command[]::new);
|
||||
if (matches.length == 1) {
|
||||
String cmd = matches[0].command;
|
||||
if (cmd.equals("/set")) {
|
||||
@ -2414,7 +2414,7 @@ public class JShellTool implements MessageHandler {
|
||||
*/
|
||||
List<Diag> errorsOnly(List<Diag> diagnostics) {
|
||||
return diagnostics.stream()
|
||||
.filter(d -> d.isError())
|
||||
.filter(Diag::isError)
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
|
@ -51,36 +51,33 @@ public final class StopDetectingInputStream extends InputStream {
|
||||
throw new IllegalStateException("Already initialized.");
|
||||
initialized = true;
|
||||
|
||||
Thread reader = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int read;
|
||||
while (true) {
|
||||
//to support external terminal editors, the "cmdin.read" must not run when
|
||||
//an external editor is running. At the same time, it needs to run while the
|
||||
//user's code is running (so Ctrl-C is detected). Hence waiting here until
|
||||
//there is a confirmed need for input.
|
||||
StopDetectingInputStream.State currentState = waitInputNeeded();
|
||||
if (currentState == StopDetectingInputStream.State.CLOSED) {
|
||||
break;
|
||||
}
|
||||
if ((read = input.read()) == (-1)) {
|
||||
break;
|
||||
}
|
||||
if (read == 3 && currentState == StopDetectingInputStream.State.BUFFER) {
|
||||
stop.run();
|
||||
} else {
|
||||
write(read);
|
||||
}
|
||||
Thread reader = new Thread(() -> {
|
||||
try {
|
||||
int read;
|
||||
while (true) {
|
||||
//to support external terminal editors, the "cmdin.read" must not run when
|
||||
//an external editor is running. At the same time, it needs to run while the
|
||||
//user's code is running (so Ctrl-C is detected). Hence waiting here until
|
||||
//there is a confirmed need for input.
|
||||
State currentState = waitInputNeeded();
|
||||
if (currentState == State.CLOSED) {
|
||||
break;
|
||||
}
|
||||
if ((read = input.read()) == (-1)) {
|
||||
break;
|
||||
}
|
||||
if (read == 3 && currentState == State.BUFFER) {
|
||||
stop.run();
|
||||
} else {
|
||||
write(read);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
errorHandler.accept(ex);
|
||||
} finally {
|
||||
shutdown();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
errorHandler.accept(ex);
|
||||
} finally {
|
||||
shutdown();
|
||||
}
|
||||
};
|
||||
});
|
||||
reader.setDaemon(true);
|
||||
reader.start();
|
||||
|
||||
|
@ -126,6 +126,6 @@ class ClassTracker {
|
||||
|
||||
// Lookup the ClassInfo by class name, create if it does not exist.
|
||||
ClassInfo get(String className) {
|
||||
return map.computeIfAbsent(className, k -> new ClassInfo(k));
|
||||
return map.computeIfAbsent(className, ClassInfo::new);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ final class DiagList extends ArrayList<Diag> {
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Diag> c) {
|
||||
return c.stream().filter(d -> add(d)).count() > 0;
|
||||
return c.stream().filter(this::add).count() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,7 +110,7 @@ final class DiagList extends ArrayList<Diag> {
|
||||
Snippet snn = d.snippetOrNull();
|
||||
return snn == u.snippet();
|
||||
})
|
||||
.collect(Collectors.toCollection(() -> new DiagList()));
|
||||
.collect(Collectors.toCollection(DiagList::new));
|
||||
}
|
||||
|
||||
boolean hasErrors() {
|
||||
|
@ -635,7 +635,7 @@ class Eval {
|
||||
while (true) {
|
||||
state.debug(DBG_GEN, "compileAndLoad %s\n", ins);
|
||||
|
||||
ins.stream().forEach(u -> u.initialize());
|
||||
ins.stream().forEach(Unit::initialize);
|
||||
ins.stream().forEach(u -> u.setWrap(ins, ins));
|
||||
AnalyzeTask at = state.taskFactory.new AnalyzeTask(outerWrapSet(ins));
|
||||
ins.stream().forEach(u -> u.setDiagnostics(at));
|
||||
@ -654,7 +654,7 @@ class Eval {
|
||||
boolean success;
|
||||
while (true) {
|
||||
List<Unit> legit = ins.stream()
|
||||
.filter(u -> u.isDefined())
|
||||
.filter(Unit::isDefined)
|
||||
.collect(toList());
|
||||
state.debug(DBG_GEN, "compileAndLoad ins = %s -- legit = %s\n",
|
||||
ins, legit);
|
||||
@ -693,7 +693,7 @@ class Eval {
|
||||
// loop by replacing all that have been replaced
|
||||
if (!toReplace.isEmpty()) {
|
||||
replaced.addAll(toReplace);
|
||||
replaced.stream().forEach(u -> u.markForReplacement());
|
||||
replaced.stream().forEach(Unit::markForReplacement);
|
||||
}
|
||||
|
||||
success = toReplace.isEmpty();
|
||||
@ -703,7 +703,7 @@ class Eval {
|
||||
|
||||
// add any new dependencies to the working set
|
||||
List<Unit> newDependencies = ins.stream()
|
||||
.flatMap(u -> u.effectedDependents())
|
||||
.flatMap(Unit::effectedDependents)
|
||||
.collect(toList());
|
||||
state.debug(DBG_GEN, "compileAndLoad %s -- deps: %s success: %s\n",
|
||||
ins, newDependencies, success);
|
||||
@ -711,7 +711,7 @@ class Eval {
|
||||
// all classes that could not be directly loaded (because they
|
||||
// are new) have been redefined, and no new dependnencies were
|
||||
// identified
|
||||
ins.stream().forEach(u -> u.finish());
|
||||
ins.stream().forEach(Unit::finish);
|
||||
return ins;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
@ -280,7 +281,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
String requiredPrefix = identifier;
|
||||
return computeSuggestions(codeWrap, cursor, anchor).stream()
|
||||
.filter(s -> s.continuation().startsWith(requiredPrefix) && !s.continuation().equals(REPL_DOESNOTMATTER_CLASS_NAME))
|
||||
.sorted(Comparator.comparing(s -> s.continuation()))
|
||||
.sorted(Comparator.comparing(Suggestion::continuation))
|
||||
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
|
||||
}
|
||||
|
||||
@ -509,7 +510,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
@Override
|
||||
public List<SnippetWrapper> wrappers(String input) {
|
||||
return proc.eval.sourceToSnippetsWithWrappers(input).stream()
|
||||
.map(sn -> wrapper(sn))
|
||||
.map(this::wrapper)
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
@ -637,7 +638,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
return IS_STATIC.or(IS_CLASS).or(IS_INTERFACE).negate().test(el) ||
|
||||
IS_PACKAGE.test(encl);
|
||||
};
|
||||
private final Function<Element, Iterable<? extends Element>> IDENTITY = el -> Collections.singletonList(el);
|
||||
private final Function<Element, Iterable<? extends Element>> IDENTITY = Collections::singletonList;
|
||||
private final Function<Boolean, String> DEFAULT_PAREN = hasParams -> hasParams ? "(" : "()";
|
||||
private final Function<Boolean, String> NO_PAREN = hasParams -> "";
|
||||
|
||||
@ -831,7 +832,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
};
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> result = Util.stream(scopeIterable)
|
||||
.flatMap(s -> localElements(s))
|
||||
.flatMap(this::localElements)
|
||||
.flatMap(el -> Util.stream((Iterable<Element>)elementConvertor.apply(el)))
|
||||
.collect(toCollection(ArrayList :: new));
|
||||
result.addAll(listPackages(at, ""));
|
||||
@ -1186,7 +1187,7 @@ class SourceCodeAnalysisImpl extends SourceCodeAnalysis {
|
||||
|
||||
try (JavadocHelper helper = JavadocHelper.create(at.task, findSources())) {
|
||||
result = elements.map(el -> constructDocumentation(at, helper, el, computeJavadoc))
|
||||
.filter(r -> r != null)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
} catch (IOException ex) {
|
||||
proc.debug(ex, "JavadocHelper.close()");
|
||||
|
@ -168,11 +168,11 @@ final class Unit {
|
||||
// Snippets to add to imports
|
||||
Collection<Snippet> plus = plusUnfiltered.stream()
|
||||
.filter(u -> !units.contains(u))
|
||||
.map(u -> u.snippet())
|
||||
.map(Unit::snippet)
|
||||
.collect(toList());
|
||||
// Snippets to wrap in an outer
|
||||
List<Snippet> snippets = units.stream()
|
||||
.map(u -> u.snippet())
|
||||
.map(Unit::snippet)
|
||||
.collect(toList());
|
||||
// Snippet wraps to wrap in an outer
|
||||
List<Wrap> wraps = units.stream()
|
||||
@ -305,8 +305,8 @@ final class Unit {
|
||||
return true;
|
||||
}
|
||||
ClassBytecodes[] cbcs = toRedefine.stream()
|
||||
.map(ci -> ci.toClassBytecodes())
|
||||
.toArray(size -> new ClassBytecodes[size]);
|
||||
.map(ClassInfo::toClassBytecodes)
|
||||
.toArray(ClassBytecodes[]::new);
|
||||
try {
|
||||
state.executionControl().redefine(cbcs);
|
||||
state.classTracker.markLoaded(cbcs);
|
||||
|
@ -359,7 +359,7 @@ abstract class Wrap implements GeneralWrap {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CompoundWrap(" + Arrays.stream(os).map(u -> u.toString()).collect(joining(",")) + ")";
|
||||
return "CompoundWrap(" + Arrays.stream(os).map(Object::toString).collect(joining(",")) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class RemoteExecutionControl extends DirectExecutionControl implements Ex
|
||||
outputs.put("out", st -> System.setOut(new PrintStream(st, true)));
|
||||
outputs.put("err", st -> System.setErr(new PrintStream(st, true)));
|
||||
Map<String, Consumer<InputStream>> input = new HashMap<>();
|
||||
input.put("in", st -> System.setIn(st));
|
||||
input.put("in", System::setIn);
|
||||
forwardExecutionControlAndIO(new RemoteExecutionControl(), inStream, outStream, outputs, input);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user