Skip to content

Commit

Permalink
Using Simplify lambda expression and method reference syntax cleanup on
Browse files Browse the repository at this point in the history
core

Using the JDT UI "Simplify lambda expression and method reference
syntax" clean-up on jdt.core.
  • Loading branch information
vogella committed Dec 1, 2023
1 parent b2cad64 commit 3979568
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3724,7 +3724,7 @@ public CycleInfo(List<IPath> pathToCycle, List<IPath> cycle) {
}

public static Optional<CycleInfo> findCycleContaining(Collection<List<CycleInfo>> 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<IPath> prefix, List<IPath> cycle, Map<IPath, List<CycleInfo>> cyclesPerProject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected Collection<String> selectModules(Set<String> keySet, Collection<String
result.retainAll(limitModules);
rootModules = result;
} else {
rootModules = JavaProject.internalDefaultRootModules(keySet, s -> s, m -> getModule(m));
rootModules = JavaProject.internalDefaultRootModules(keySet, s -> s, this::getModule);
}
Set<String> allModules = new HashSet<>(rootModules);
for (String mod : rootModules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -786,7 +785,7 @@ else if (modulePathEntry != null)
public char[][] getAllAutomaticModules() {
if (this.modulePathEntries == null)
return CharOperation.NO_CHAR_CHAR;
Set<char[]> set = this.modulePathEntries.values().stream().filter(m -> m.isAutomaticModule()).map(e -> e.getModule().name())
Set<char[]> set = this.modulePathEntries.values().stream().filter(IModulePathEntry::isAutomaticModule).map(e -> e.getModule().name())
.collect(Collectors.toSet());
return set.toArray(new char[set.size()][]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClasspathLocation> firstSrcLocation = this.locationSet.stream().filter(cp -> cp instanceof ClasspathSourceDirectory).findFirst();
Optional<ClasspathLocation> 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.
Expand Down Expand Up @@ -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<char[]> set = this.moduleLocations.values().stream().map(e -> e.getModule()).filter(m -> m != null && m.isAutomatic())
.map(m -> m.name()).collect(Collectors.toSet());
Set<char[]> 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()][]);
}

Expand Down

0 comments on commit 3979568

Please sign in to comment.