-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for method breakpoints (#426)
Now method breakpoints can added by adding a line breakpoint at method header.
- Loading branch information
Showing
5 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...t.java.debug.plugin/src/main/java/com/microsoft/java/debug/BreakpointLocationLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Microsoft Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Gayan Perera ([email protected]) - initial API and implementation | ||
*******************************************************************************/ | ||
package com.microsoft.java.debug; | ||
|
||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.core.dom.IMethodBinding; | ||
import org.eclipse.jdt.core.dom.MethodDeclaration; | ||
|
||
@SuppressWarnings("restriction") | ||
public class BreakpointLocationLocator | ||
extends org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator { | ||
|
||
private IMethodBinding methodBinding; | ||
|
||
public BreakpointLocationLocator(CompilationUnit compilationUnit, int lineNumber, boolean bindingsResolved, | ||
boolean bestMatch) { | ||
super(compilationUnit, lineNumber, bindingsResolved, bestMatch); | ||
} | ||
|
||
@Override | ||
public boolean visit(MethodDeclaration node) { | ||
boolean result = super.visit(node); | ||
if (methodBinding == null && getLocationType() == LOCATION_METHOD) { | ||
this.methodBinding = node.resolveBinding(); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Returns the signature of method found if the | ||
* {@link org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator#getLocationType()} | ||
* is | ||
* {@link org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator#LOCATION_METHOD}. | ||
* Otherwise return null. | ||
*/ | ||
public String getMethodSignature() { | ||
if (this.methodBinding == null) { | ||
return null; | ||
} | ||
return toSignature(this.methodBinding); | ||
} | ||
|
||
/** | ||
* Returns the name of method found if the | ||
* {@link org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator#getLocationType()} | ||
* is | ||
* {@link org.eclipse.jdt.internal.debug.core.breakpoints.ValidBreakpointLocationLocator#LOCATION_METHOD}. | ||
* Otherwise return null. | ||
*/ | ||
public String getMethodName() { | ||
if (this.methodBinding == null) { | ||
return null; | ||
} | ||
return this.methodBinding.getName(); | ||
} | ||
|
||
@Override | ||
public String getFullyQualifiedTypeName() { | ||
if (this.methodBinding != null) { | ||
return this.methodBinding.getDeclaringClass().getQualifiedName(); | ||
} | ||
return super.getFullyQualifiedTypeName(); | ||
} | ||
|
||
private String toSignature(IMethodBinding binding) { | ||
// use key for now until JDT core provides a public API for this. | ||
// "Ljava/util/Arrays;.asList<T:Ljava/lang/Object;>([TT;)Ljava/util/List<TT;>;" | ||
// "([Ljava/lang/String;)V|Ljava/lang/InterruptedException;" | ||
String signatureString = binding.getKey(); | ||
if (signatureString != null) { | ||
String name = binding.getName(); | ||
int index = signatureString.indexOf(name); | ||
if (index > -1) { | ||
int exceptionIndex = signatureString.indexOf("|", signatureString.lastIndexOf(")")); | ||
if (exceptionIndex > -1) { | ||
return signatureString.substring(index + name.length(), exceptionIndex); | ||
} | ||
return signatureString.substring(index + name.length()); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters