From 3979568b1d959b625c481a79cd0ecbe602577a5a Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Fri, 1 Dec 2023 11:01:41 +0100 Subject: [PATCH] Using Simplify lambda expression and method reference syntax cleanup on core Using the JDT UI "Simplify lambda expression and method reference syntax" clean-up on jdt.core. --- .../eclipse/jdt/internal/codeassist/CompletionEngine.java | 8 ++++---- .../complete/CompletionOnQualifiedNameReference.java | 8 +++----- .../model/org/eclipse/jdt/internal/core/JavaProject.java | 2 +- .../eclipse/jdt/internal/core/SearchableEnvironment.java | 2 +- .../eclipse/jdt/internal/core/builder/ClasspathJrt.java | 2 +- .../jdt/internal/core/builder/NameEnvironment.java | 3 +-- .../org/eclipse/jdt/internal/core/builder/State.java | 4 ++-- .../core/search/matching/JavaSearchNameEnvironment.java | 6 +++--- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java index 70d55a83a4f..bceaae2afa7 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java @@ -9858,8 +9858,8 @@ private char[] findParameterNameAtLocationFromAssistParent(ObjectVector methodsF arguments = ms.arguments; candidates = StreamSupport.stream(methodsFound.spliterator(), false) .filter(Objects::nonNull) - .filter(o -> o instanceof Object[]).map(o -> (Object[]) o) - .map(o -> o[0]).filter(o -> o instanceof MethodBinding).map(b -> (MethodBinding) b) + .filter(Object[].class::isInstance).map(o -> (Object[]) o) + .map(o -> o[0]).filter(MethodBinding.class::isInstance).map(b -> (MethodBinding) b) .filter(b -> CharOperation.equals(ms.selector, b.selector)).findFirst() .map(m -> new MethodBinding[] { m }).orElse(new MethodBinding[0]); } else if (this.parser.assistNodeParent instanceof AllocationExpression ae) { @@ -9869,8 +9869,8 @@ private char[] findParameterNameAtLocationFromAssistParent(ObjectVector methodsF true); } candidates = StreamSupport.stream(methodsFound.spliterator(), false).filter(Objects::nonNull) - .filter(o -> o instanceof Object[]).map(o -> (Object[]) o).map(o -> o[0]) - .filter(o -> o instanceof MethodBinding).map(b -> (MethodBinding) b).filter(b -> b.isConstructor()) + .filter(Object[].class::isInstance).map(o -> (Object[]) o).map(o -> o[0]) + .filter(MethodBinding.class::isInstance).map(b -> (MethodBinding) b).filter(MethodBinding::isConstructor) .toArray(MethodBinding[]::new); } else { return parameterName; diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedNameReference.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedNameReference.java index 43345d54ec1..8d530377965 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedNameReference.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedNameReference.java @@ -77,10 +77,8 @@ public TypeBinding resolveType(BlockScope scope) { throw new CompletionNodeFound(); } - - return new CompletionNodeFound(this, this.binding, scope).throwOrDeferAndReturn(() -> { - // probably not in the position to do useful resolution, just provide some binding - return this.resolvedType = new ProblemReferenceBinding(this.tokens, null, ProblemReasons.NotFound); - }); + + // probably not in the position to do useful resolution, just provide some binding + return new CompletionNodeFound(this, this.binding, scope).throwOrDeferAndReturn(() -> (this.resolvedType = new ProblemReferenceBinding(this.tokens, null, ProblemReasons.NotFound))); } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java index 46c8700fe38..c16327d6e05 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java @@ -3724,7 +3724,7 @@ public CycleInfo(List pathToCycle, List cycle) { } public static Optional findCycleContaining(Collection> infos, IPath path) { - return infos.stream().flatMap(l -> l.stream()).filter(c -> c.cycle.contains(path)).findAny(); + return infos.stream().flatMap(List::stream).filter(c -> c.cycle.contains(path)).findAny(); } public static void add(IPath project, List prefix, List cycle, Map> cyclesPerProject) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java index 0825706358d..667e46913e0 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java @@ -111,7 +111,7 @@ public SearchableEnvironment(JavaProject project, org.eclipse.jdt.core.ICompilat this.moduleUpdater = new ModuleUpdater(project); if (!excludeTestCode) { IClasspathEntry[] expandedClasspath = project.getExpandedClasspath(); - if(Arrays.stream(expandedClasspath).anyMatch(e -> e.isTest())) { + if(Arrays.stream(expandedClasspath).anyMatch(IClasspathEntry::isTest)) { this.moduleUpdater.addReadUnnamedForNonEmptyClasspath(project, expandedClasspath); } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java index f7cfd5453d1..1088a62bf92 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java @@ -273,7 +273,7 @@ protected Collection selectModules(Set keySet, Collection s, m -> getModule(m)); + rootModules = JavaProject.internalDefaultRootModules(keySet, s -> s, this::getModule); } Set allModules = new HashSet<>(rootModules); for (String mod : rootModules) diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index f63661e10bd..607b82aca62 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -27,7 +27,6 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.*; import org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdateKind; -import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; @@ -786,7 +785,7 @@ else if (modulePathEntry != null) public char[][] getAllAutomaticModules() { if (this.modulePathEntries == null) return CharOperation.NO_CHAR_CHAR; - Set set = this.modulePathEntries.values().stream().filter(m -> m.isAutomaticModule()).map(e -> e.getModule().name()) + Set set = this.modulePathEntries.values().stream().filter(IModulePathEntry::isAutomaticModule).map(e -> e.getModule().name()) .collect(Collectors.toSet()); return set.toArray(new char[set.size()][]); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java index 90f51571f8c..444cc4852b0 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java @@ -847,8 +847,8 @@ private void writeBinaryLocations(CompressedWriter out, ClasspathLocation[] loca try { out.writeChars(pkgName.toCharArray()); char[][] targetModules = entry.getValue().stream() - .map(addExport -> addExport.getTargetModules()).filter(targets -> targets != null) - .reduce((f, s) -> CharOperation.arrayConcat(f, s)).orElse(null); + .map(AddExports::getTargetModules).filter(targets -> targets != null) + .reduce(CharOperation::arrayConcat).orElse(null); writeNames(targetModules, out); } catch (IOException e) { // ignore diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java index 2a103fe53d8..c1ea15f336a 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/JavaSearchNameEnvironment.java @@ -99,7 +99,7 @@ public JavaSearchNameEnvironment(IJavaProject javaProject, org.eclipse.jdt.core. // if there are working copies, we need to index their packages too if(this.workingCopies.size() > 0) { - Optional firstSrcLocation = this.locationSet.stream().filter(cp -> cp instanceof ClasspathSourceDirectory).findFirst(); + Optional firstSrcLocation = this.locationSet.stream().filter(ClasspathSourceDirectory.class::isInstance).findFirst(); if(!firstSrcLocation.isPresent()) { /* * Specifying working copies but not providing a project with a source folder is not supported by the current implementation. @@ -572,8 +572,8 @@ public IModule getModule(char[] moduleName) { public char[][] getAllAutomaticModules() { if (this.moduleLocations == null || this.moduleLocations.size() == 0) return CharOperation.NO_CHAR_CHAR; - Set set = this.moduleLocations.values().stream().map(e -> e.getModule()).filter(m -> m != null && m.isAutomatic()) - .map(m -> m.name()).collect(Collectors.toSet()); + Set set = this.moduleLocations.values().stream().map(ClasspathLocation::getModule).filter(m -> m != null && m.isAutomatic()) + .map(IModule::name).collect(Collectors.toSet()); return set.toArray(new char[set.size()][]); }