Skip to content

Commit

Permalink
tweak "strong" wrapper type
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareCobbler committed Dec 26, 2024
1 parent 53cde44 commit 099a38a
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 101 deletions.
2 changes: 1 addition & 1 deletion luceedebug/src/main/java/luceedebug/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static void premain(String argString, Instrumentation inst) throws Throwa
//
// See(lucee): loader/src/main/java/lucee/loader/engine/CFMLEngineFactory.java
//
System.setProperty("org.osgi.framework.bootdelegation", "com.sun.jdi,com.sun.jdi.connect,com.sun.jdi.event,com.sun.jdi.request,luceedebug,luceedebug_shadow.*");
System.setProperty("org.osgi.framework.bootdelegation", "com.sun.jdi,com.sun.jdi.connect,com.sun.jdi.event,com.sun.jdi.request,luceedebug,luceedebug.strong,luceedebug_shadow.*");

// touch System.out before agent is loaded, otherwise trying to print from within the agent during jvm initialization phase
// can trigger stackoverflows. And note that System.out.println("") doesn't seem to work, as if printing the empty string
Expand Down
15 changes: 9 additions & 6 deletions luceedebug/src/main/java/luceedebug/DapServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import com.sun.jdi.ObjectCollectedException;

import luceedebug.strong.CanonicalServerAbsPath;
import luceedebug.strong.RawIdePath;

public class DapServer implements IDebugProtocolServer {
private final ILuceeVm luceeVm_;
private final Config config_;
Expand Down Expand Up @@ -70,19 +73,19 @@ private DapServer(ILuceeVm luceeVm, Config config) {
this.config_ = config;

this.luceeVm_.registerStepEventCallback(jdwpThreadID -> {
final var i32_threadID = (int)(long)jdwpThreadID.v;
final var i32_threadID = (int)(long)jdwpThreadID.get();
var event = new StoppedEventArguments();
event.setReason("step");
event.setThreadId(i32_threadID);
clientProxy_.stopped(event);
});

this.luceeVm_.registerBreakpointEventCallback((jdwpThreadID, bpID) -> {
final int i32_threadID = (int)(long)jdwpThreadID.v;
final int i32_threadID = (int)(long)jdwpThreadID.get();
var event = new StoppedEventArguments();
event.setReason("breakpoint");
event.setThreadId(i32_threadID);
event.setHitBreakpointIds(new Integer[] { bpID.v });
event.setHitBreakpointIds(new Integer[] { bpID.get() });
clientProxy_.stopped(event);
});

Expand Down Expand Up @@ -376,10 +379,10 @@ public CompletableFuture<VariablesResponse> variables(VariablesArguments args) {

@Override
public CompletableFuture<SetBreakpointsResponse> setBreakpoints(SetBreakpointsArguments args) {
final var idePath = new StrongString.RawIdePath(args.getSource().getPath());
final var serverAbsPath = new StrongString.CanonicalServerAbsPath(applyPathTransformsIdeToCf(args.getSource().getPath()));
final var idePath = new RawIdePath(args.getSource().getPath());
final var serverAbsPath = new CanonicalServerAbsPath(applyPathTransformsIdeToCf(args.getSource().getPath()));

logger.finest("bp for " + idePath.v + " -> " + serverAbsPath.v);
logger.finest("bp for " + idePath.get() + " -> " + serverAbsPath.get());

final int size = args.getBreakpoints().length;
final int[] lines = new int[size];
Expand Down
8 changes: 4 additions & 4 deletions luceedebug/src/main/java/luceedebug/ILuceeVm.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import com.sun.jdi.*;

import luceedebug.StrongInt.DapBreakpointID;
import luceedebug.StrongLong.JdwpThreadID;
import luceedebug.StrongString.CanonicalServerAbsPath;
import luceedebug.StrongString.RawIdePath;
import luceedebug.strong.DapBreakpointID;
import luceedebug.strong.JdwpThreadID;
import luceedebug.strong.CanonicalServerAbsPath;
import luceedebug.strong.RawIdePath;

public interface ILuceeVm {
public void registerStepEventCallback(Consumer<JdwpThreadID> cb);
Expand Down
24 changes: 0 additions & 24 deletions luceedebug/src/main/java/luceedebug/StrongInt.java

This file was deleted.

28 changes: 0 additions & 28 deletions luceedebug/src/main/java/luceedebug/StrongLong.java

This file was deleted.

30 changes: 0 additions & 30 deletions luceedebug/src/main/java/luceedebug/StrongString.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package luceedebug.coreinject;

import luceedebug.*;
import luceedebug.StrongInt.DapBreakpointID;
import luceedebug.strong.DapBreakpointID;

class Breakpoint implements IBreakpoint {
final int line;
Expand All @@ -23,6 +23,6 @@ public static Breakpoint Unbound(int line, DapBreakpointID ID) {
}

public int getLine() { return line; }
public int getID() { return ID.v; }
public int getID() { return ID.get(); }
public boolean getIsBound() { return isBound; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;

import luceedebug.Config;
import luceedebug.StrongString.CanonicalServerAbsPath;
import luceedebug.strong.CanonicalServerAbsPath;

import com.sun.jdi.*;

Expand Down
10 changes: 5 additions & 5 deletions luceedebug/src/main/java/luceedebug/coreinject/LuceeVm.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import static luceedebug.coreinject.Iife.iife;

import luceedebug.*;
import luceedebug.StrongInt.DapBreakpointID;
import luceedebug.StrongLong.JdwpThreadID;
import luceedebug.StrongString.CanonicalServerAbsPath;
import luceedebug.StrongString.RawIdePath;
import luceedebug.strong.DapBreakpointID;
import luceedebug.strong.JdwpThreadID;
import luceedebug.strong.CanonicalServerAbsPath;
import luceedebug.strong.RawIdePath;

public class LuceeVm implements ILuceeVm {
// This is a key into a map stored on breakpointRequest objects; the value should always be of Integer type
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public String[] getTrackedCanonicalFileNames() {
final var result = new ArrayList<String>();
for (var klassMap : klassMap_.values()) {
for (var mapping : klassMap) {
result.add(mapping.sourceName.v);
result.add(mapping.sourceName.get());
}
}
return result.toArray(size -> new String[size]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package luceedebug.strong;

public final class CanonicalServerAbsPath extends StrongT<String> {
public CanonicalServerAbsPath(String v) {
super(v);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package luceedebug.strong;

public final class DapBreakpointID extends StrongT<Integer> {
public DapBreakpointID(Integer v) {
super(v);
}
}
11 changes: 11 additions & 0 deletions luceedebug/src/main/java/luceedebug/strong/JdwpThreadID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package luceedebug.strong;

public final class JdwpThreadID extends StrongT<Long> {
public JdwpThreadID(Long v) {
super(v);
}

public static JdwpThreadID of(com.sun.jdi.ThreadReference v) {
return new JdwpThreadID(v.uniqueID());
}
}
7 changes: 7 additions & 0 deletions luceedebug/src/main/java/luceedebug/strong/RawIdePath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package luceedebug.strong;

public final class RawIdePath extends StrongT<String> {
public RawIdePath(String v) {
super(v);
}
}
27 changes: 27 additions & 0 deletions luceedebug/src/main/java/luceedebug/strong/StrongT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package luceedebug.strong;

/**
* Typical use case here is derived classes are final and
* are simple "strong" wrappers around the underlying type `T`.
*/
public abstract class StrongT<T> {
private final T v;

StrongT(T v) {
this.v = v;
}

public T get() {
return v;
}

@Override
public int hashCode() {
return v.hashCode();
}

@Override
public boolean equals(Object other) {
return (other instanceof StrongT<?>) && v.equals(((StrongT<?>)other).v);
}
}

0 comments on commit 099a38a

Please sign in to comment.