Skip to content
Merged
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 @@ -12,10 +12,12 @@
package com.microsoft.java.debug;

import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.internal.debug.core.breakpoints.LambdaLocationLocatorHelper;

/**
* Utility methods around working with JDT Bindings.
*/
@SuppressWarnings("restriction")
public final class BindingUtils {
private BindingUtils() {

Expand Down Expand Up @@ -48,31 +50,14 @@ public static String getMethodName(IMethodBinding binding, boolean fromKey) {
}

/**
* Returns the method signature of the method represented by the binding. Since
* this implementation use the {@link IMethodBinding#getKey()} to extract the
* signature from, the method name must be passed in.
* Returns the method signature of the method represented by the binding
* including the synthetic outer locals.
*
* @param binding the binding which the signature must be resolved for.
* @param name the name of the method.
* @return the signature or null if the signature could not be resolved from the
* key.
* @return the signature or null if the signature could not be resolved.
*/
public static String toSignature(IMethodBinding binding, String name) {
// 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) {
name = "." + name;
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;
public static String toSignature(IMethodBinding binding) {
return LambdaLocationLocatorHelper.toMethodSignature(binding);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getMethodSignature() {
if (this.methodBinding == null) {
return null;
}
return BindingUtils.toSignature(this.methodBinding, getMethodName());
return BindingUtils.toSignature(this.methodBinding);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String getMethodSignature() {
if (!this.found) {
return null;
}
return BindingUtils.toSignature(this.lambdaMethodBinding, getMethodName());
return BindingUtils.toSignature(this.lambdaMethodBinding);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
Expand All @@ -50,10 +52,10 @@
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.manipulation.CoreASTProvider;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
Expand Down Expand Up @@ -276,7 +278,13 @@ private CompilationUnit asCompilationUnit(String uri) {
* setEnvironment(String [], String [], String [], boolean)
* and a unit name setUnitName(String).
*/
parser.setEnvironment(new String[0], new String[0], null, true);
IFile resource = (IFile) JDTUtils.findResource(JDTUtils.toURI(uri),
ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI);
if (resource != null && JdtUtils.isJavaProject(resource.getProject())) {
parser.setProject(JavaCore.create(resource.getProject()));
} else {
parser.setEnvironment(new String[0], new String[0], null, true);
}
parser.setUnitName(Paths.get(filePath).getFileName().toString());
/**
* See the java doc for { @link ASTParser#setSource(char[]) },
Expand Down Expand Up @@ -492,7 +500,7 @@ public List<MethodInvocation> findMethodInvocations(String uri, int line) {
// Keep consistent with JDI since JDI uses binary class name
invocation.declaringTypeName = binding.getDeclaringClass().getBinaryName();
}
invocation.methodGenericSignature = BindingUtils.toSignature(binding, BindingUtils.getMethodName(binding, true));
invocation.methodGenericSignature = BindingUtils.toSignature(binding);
invocation.methodSignature = Signature.getTypeErasure(invocation.methodGenericSignature);
int startOffset = astNode.getStartPosition();
if (astNode instanceof org.eclipse.jdt.core.dom.MethodInvocation) {
Expand Down