Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor code refactor #513

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Supplier;

public class AsyncJdwpUtils {
private AsyncJdwpUtils(){}
/**
* Create a the thread pool to process JDWP tasks.
* JDWP tasks are IO-bounded, so use a relatively large thread pool for JDWP tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package com.microsoft.java.debug.core;

public class Configuration {
private Configuration(){}
public static final String LOGGER_NAME = "java-debug";
public static final String USAGE_DATA_LOGGER_NAME = "java-debug-usage-data";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ public void setExceptionBreakpoints(boolean notifyCaught, boolean notifyUncaught
} catch (VMDisconnectedException ex) {
// ignore since removing breakpoints is meaningless when JVM is terminated.
}
subscriptions.forEach(subscription -> {
subscription.dispose();
});
subscriptions.forEach(Disposable::dispose);
subscriptions.clear();
eventRequests.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.sun.jdi.StackFrame;

public final class StackFrameUtility {

private StackFrameUtility(){}
public static boolean isNative(StackFrame frame) {
return frame.location().method().isNative();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public void close() throws Exception {
} catch (VMDisconnectedException ex) {
// ignore since removing breakpoints is meaningless when JVM is terminated.
}
subscriptions().forEach(subscription -> {
subscription.dispose();
});
subscriptions().forEach(Disposable::dispose);
requests.clear();
subscriptions.clear();
}
Expand Down Expand Up @@ -134,7 +132,7 @@ public void setHitCount(int hitCount) {
this.hitCount = hitCount;

Observable.fromIterable(this.requests())
.filter(request -> request instanceof WatchpointRequest)
.filter(WatchpointRequest.class::isInstance)
.subscribe(request -> {
request.addCountFilter(hitCount);
request.enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.microsoft.java.debug.core.protocol.Types;

public class AdapterUtils {
private AdapterUtils(){}
private static final String OS_NAME = System.getProperty("os.name", "").toLowerCase();
private static final Pattern ENCLOSING_CLASS_REGEX = Pattern.compile("^([^\\$]*)");
public static final boolean isWin = isWindows();
Expand Down Expand Up @@ -288,7 +289,7 @@ public static String getSHA256HexDigest(String content) {
} catch (NoSuchAlgorithmException e) {
// ignore it.
}
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if (hashBytes != null) {
for (byte b : hashBytes) {
buf.append(Integer.toHexString((b & 0xFF) + 0x100).substring(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private String getWatchpointKey(IWatchpoint watchpoint) {

@Override
public IWatchpoint[] getWatchpoints() {
return this.watchpoints.values().stream().filter(wp -> wp != null).toArray(IWatchpoint[]::new);
return this.watchpoints.values().stream().filter(Objects::nonNull).toArray(IWatchpoint[]::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package com.microsoft.java.debug.core.adapter;

public final class Constants {
private Constants(){}
public static final String PROJECT_NAME = "projectName";
public static final String DEBUGGEE_ENCODING = "debuggeeEncoding";
public static final String MAIN_CLASS = "mainClass";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public CompletableFuture<Messages.Response> dispatchRequest(Messages.Request req
if (handlers != null && !handlers.isEmpty()) {
CompletableFuture<Messages.Response> future = CompletableFuture.completedFuture(response);
for (IDebugRequestHandler handler : handlers) {
future = future.thenCompose((res) -> {
return handler.handle(command, cmdArgs, res, debugContext);
});
future = future.thenCompose(res -> handler.handle(command, cmdArgs, res, debugContext));
}
return future;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public int getId() {
* @return the ErrorCode type.
*/
public static ErrorCode parse(int id) {
ErrorCode[] found = Arrays.stream(ErrorCode.values()).filter(code -> {
return code.getId() == id;
}).toArray(ErrorCode[]::new);
ErrorCode[] found = Arrays.stream(ErrorCode.values()).filter(code -> code.getId() == id).toArray(ErrorCode[]::new);

if (found.length > 0) {
return found[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Observable<ConsoleMessage> lineMessages() {
return this.messages().map((message) -> {
String[] lines = message.output.split("(?<=\n)");
return Stream.of(lines).map((line) -> new ConsoleMessage(line, message.category)).toArray(ConsoleMessage[]::new);
}).concatMap((lines) -> Observable.fromArray(lines));
}).concatMap(Observable::fromArray);
}

public static class InputStreamObservable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package com.microsoft.java.debug.core.adapter.formatter;

public final class TypeIdentifiers {
private TypeIdentifiers(){}
public static final char ARRAY = '[';
public static final char BYTE = 'B';
public static final char CHAR = 'C';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
String exceptionToString = typeName;
if (toStringMethod != null) {
try {
Value returnValue = jdiException.exception.invokeMethod(thread, toStringMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
Value returnValue = jdiException.exception.invokeMethod(thread, toStringMethod, Collections.emptyList(), ObjectReference.INVOKE_SINGLE_THREADED);
exceptionToString = returnValue.toString();
} catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException
| InvocationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

public class LaunchRequestHandler implements IDebugRequestHandler {
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
protected static final long RUNINTERMINAL_TIMEOUT = 10 * 1000;

protected ILaunchDelegate activeLaunchHandler;
private CompletableFuture<Boolean> waitForDebuggeeConsole = new CompletableFuture<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.microsoft.java.debug.core.adapter.AdapterUtils;

public class LaunchUtils {
private LaunchUtils(){}
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private static Set<Path> tempFilesInUse = new HashSet<>();
private static final Charset SYSTEM_CHARSET;
Expand Down Expand Up @@ -262,7 +263,7 @@ private static long findJavaProcessByCygwinPsCommand(ProcessHandle shellProcess,
}

if (!javaCandidates.isEmpty()) {
Set<Long> descendantWinpids = shellProcess.descendants().map(proc -> proc.pid()).collect(Collectors.toSet());
Set<Long> descendantWinpids = shellProcess.descendants().map(ProcessHandle::pid).collect(Collectors.toSet());
long shellWinpid = shellProcess.pid();
for (PsProcess javaCandidate: javaCandidates) {
if (descendantWinpids.contains(javaCandidate.winpid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void registerBreakpointHandler(IDebugAdapterContext context) {
if (debugSession != null) {
debugSession.getEventHub().events().filter(debugEvent -> debugEvent.event instanceof BreakpointEvent).subscribe(debugEvent -> {
Event event = debugEvent.event;
if (debugEvent.eventSet.size() > 1 && debugEvent.eventSet.stream().anyMatch(t -> t instanceof StepEvent)) {
if (debugEvent.eventSet.size() > 1 && debugEvent.eventSet.stream().anyMatch(StepEvent.class::isInstance)) {
// The StepEvent and BreakpointEvent are grouped in the same event set only if they occurs at the same location and in the same thread.
// In order to avoid two duplicated StoppedEvents, the debugger will skip the BreakpointEvent.
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sun.jdi.Value;

public class JavaLogicalStructureManager {
private JavaLogicalStructureManager(){}
private static final List<JavaLogicalStructure> supportedLogicalStructures = Collections.synchronizedList(new ArrayList<>());

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract class VariableUtils {
* @return true if this value is reference objects.
*/
public static boolean hasChildren(Value value, boolean includeStatic) {
if (value == null || !(value instanceof ObjectReference)) {
if (!(value instanceof ObjectReference)) {
return false;
}
ReferenceType type = ((ObjectReference) value).referenceType();
Expand Down Expand Up @@ -189,7 +189,7 @@ public static List<Variable> listLocalVariables(StackFrame stackFrame) throws Ab
// avoid listing variable on native methods

try {
if (stackFrame.location().method().argumentTypes().size() == 0) {
if (stackFrame.location().method().argumentTypes().isEmpty()) {
return res;
}
} catch (ClassNotLoadedException ex2) {
Expand Down