Skip to content

Commit

Permalink
Improve for multi line and multi lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
gayanper committed Jul 27, 2022
1 parent 9b001d7 commit a62d1fc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ public String getCondition() {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof IBreakpoint)) {
if (!(obj instanceof Breakpoint)) {
return super.equals(obj);
}

IBreakpoint breakpoint = (IBreakpoint) obj;
return Objects.equals(this.className(), breakpoint.className()) && this.getLineNumber() == breakpoint.getLineNumber();
Breakpoint breakpoint = (Breakpoint) obj;
return Objects.equals(this.className(), breakpoint.className())
&& this.getLineNumber() == breakpoint.getLineNumber() &&
Objects.equals(this.methodSignature, breakpoint.methodSignature);
}

@Override
public int hashCode() {
return Objects.hash(this.className, this.lineNumber, this.methodSignature);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

package com.microsoft.java.debug.core;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import com.sun.jdi.event.ThreadDeathEvent;
import org.apache.commons.lang3.StringUtils;

import com.sun.jdi.ThreadReference;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.event.ThreadDeathEvent;

import io.reactivex.disposables.Disposable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, bo

// Compute the breakpoints that are newly added.
List<IBreakpoint> toAdd = new ArrayList<>();
List<Integer> visitedLineNumbers = new ArrayList<>();
List<Integer> visitedBreakpoints = new ArrayList<>();
for (IBreakpoint breakpoint : breakpoints) {
IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.getLineNumber()));
IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.hashCode()));
if (existed != null) {
result.add(existed);
visitedLineNumbers.add(existed.getLineNumber());
visitedBreakpoints.add(existed.hashCode());
continue;
} else {
result.add(breakpoint);
Expand All @@ -95,7 +95,7 @@ public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, bo
// Compute the breakpoints that are no longer listed.
List<IBreakpoint> toRemove = new ArrayList<>();
for (IBreakpoint breakpoint : breakpointMap.values()) {
if (!visitedLineNumbers.contains(breakpoint.getLineNumber())) {
if (!visitedBreakpoints.contains(breakpoint.hashCode())) {
toRemove.add(breakpoint);
}
}
Expand All @@ -113,7 +113,7 @@ private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints)
for (IBreakpoint breakpoint : breakpoints) {
breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement());
this.breakpoints.add(breakpoint);
breakpointMap.put(String.valueOf(breakpoint.getLineNumber()), breakpoint);
breakpointMap.put(String.valueOf(breakpoint.hashCode()), breakpoint);
}
}
}
Expand All @@ -133,7 +133,7 @@ private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoint
// Destroy the breakpoint on the debugee VM.
breakpoint.close();
this.breakpoints.remove(breakpoint);
breakpointMap.remove(String.valueOf(breakpoint.getLineNumber()));
breakpointMap.remove(String.valueOf(breakpoint.hashCode()));
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Remove breakpoint exception: %s", e.toString()), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ public boolean visit(LambdaExpression node) {
int startPosition = node.getStartPosition();

int startColumn = this.compilationUnit.getColumnNumber(startPosition);
int endColumn = this.compilationUnit.getColumnNumber(startPosition + node.getLength());
int lineNumber = this.compilationUnit.getLineNumber(startPosition);
int endPosition = startPosition + node.getLength();
int endColumn = this.compilationUnit.getColumnNumber(endPosition);
int startLine = this.compilationUnit.getLineNumber(startPosition);
int endLine = this.compilationUnit.getLineNumber(endPosition);

if (column >= startColumn && column <= endColumn && lineNumber == line) {
// lambda on same line:
// list.stream().map(i -> i + 1);
//
// lambda on multiple lines:
// list.stream().map(user
// -> user.isSystem() ? new SystemUser(user) : new EndUser(user));

if ((startLine == endLine && column >= startColumn && column <= endColumn && line == startLine) ||
(startLine != endLine && line >= startLine && line <= endLine
&& (column >= startColumn || column <= endColumn))) {
this.lambdaMethodBinding = node.resolveMethodBinding();
this.found = true;
this.lambdaExpression = node;
Expand Down

0 comments on commit a62d1fc

Please sign in to comment.