本文整理汇总了Java中com.sun.jdi.Location.sourceName方法的典型用法代码示例。如果您正苦于以下问题:Java Location.sourceName方法的具体用法?Java Location.sourceName怎么用?Java Location.sourceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jdi.Location
的用法示例。
在下文中一共展示了Location.sourceName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sourceFile
import com.sun.jdi.Location; //导入方法依赖的package包/类
/**
* Return a File cooresponding to the source of this location.
* Return null if not available.
*/
File sourceFile(Location loc) {
try {
String filename = loc.sourceName();
String refName = loc.declaringType().name();
int iDot = refName.lastIndexOf('.');
String pkgName = (iDot >= 0)? refName.substring(0, iDot+1) : "";
String full = pkgName.replace('.', File.separatorChar) + filename;
for (int i= 0; i < dirs.length; ++i) {
File path = new File(dirs[i], full);
if (path.exists()) {
return path;
}
}
return null;
} catch (AbsentInformationException e) {
return null;
}
}
示例2: printLocation
import com.sun.jdi.Location; //导入方法依赖的package包/类
protected void printLocation(SuspendContextImpl suspendContext) {
try {
Location location = suspendContext.getFrameProxy().location();
String message = "paused at " + location.sourceName() + ":" + location.lineNumber();
println(message, ProcessOutputTypes.SYSTEM);
}
catch (Throwable e) {
addException(e);
}
}
示例3: convertDebuggerSourceToClient
import com.sun.jdi.Location; //导入方法依赖的package包/类
private Types.Source convertDebuggerSourceToClient(Location location, IDebugAdapterContext context) throws URISyntaxException {
final String fullyQualifiedName = location.declaringType().name();
String sourceName = "";
String relativeSourcePath = "";
try {
// When the .class file doesn't contain source information in meta data,
// invoking Location#sourceName() would throw AbsentInformationException.
sourceName = location.sourceName();
relativeSourcePath = location.sourcePath();
} catch (AbsentInformationException e) {
String enclosingType = AdapterUtils.parseEnclosingType(fullyQualifiedName);
sourceName = enclosingType.substring(enclosingType.lastIndexOf('.') + 1) + ".java";
relativeSourcePath = enclosingType.replace('.', File.separatorChar) + ".java";
}
final String finalRelativeSourcePath = relativeSourcePath;
// use a lru cache for better performance
String uri = context.getSourceLookupCache().computeIfAbsent(fullyQualifiedName, key -> {
String fromProvider = context.getProvider(ISourceLookUpProvider.class).getSourceFileURI(key, finalRelativeSourcePath);
// avoid return null which will cause the compute function executed again
return StringUtils.isBlank(fromProvider) ? "" : fromProvider;
});
if (!StringUtils.isBlank(uri)) {
// The Source.path could be a file system path or uri string.
if (uri.startsWith("file:")) {
String clientPath = AdapterUtils.convertPath(uri, context.isDebuggerPathsAreUri(), context.isClientPathsAreUri());
return new Types.Source(sourceName, clientPath, 0);
} else {
// If the debugger returns uri in the Source.path for the StackTrace response, VSCode client will try to find a TextDocumentContentProvider
// to render the contents.
// Language Support for Java by Red Hat extension has already registered a jdt TextDocumentContentProvider to parse the jdt-based uri.
// The jdt uri looks like 'jdt://contents/rt.jar/java.io/PrintStream.class?=1.helloworld/%5C/usr%5C/lib%5C/jvm%5C/java-8-oracle%5C/jre%5C/
// lib%5C/rt.jar%3Cjava.io(PrintStream.class'.
return new Types.Source(sourceName, uri, 0);
}
} else {
// If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user.
String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath);
if (absoluteSourcepath != null) {
return new Types.Source(sourceName, absoluteSourcepath, 0);
} else {
return null;
}
}
}
示例4: getEventMessage
import com.sun.jdi.Location; //导入方法依赖的package包/类
public String getEventMessage(LocatableEvent event) {
String exceptionName = (getQualifiedName() != null)? getQualifiedName() : CommonClassNames.JAVA_LANG_THROWABLE;
String threadName = null;
if (event instanceof ExceptionEvent) {
ExceptionEvent exceptionEvent = (ExceptionEvent)event;
try {
exceptionName = exceptionEvent.exception().type().name();
threadName = exceptionEvent.thread().name();
}
catch (Exception ignore) {
}
}
final Location location = event.location();
final String locationQName = DebuggerUtilsEx.getLocationMethodQName(location);
String locationFileName;
try {
locationFileName = location.sourceName();
}
catch (AbsentInformationException e) {
locationFileName = "";
}
final int locationLine = Math.max(0, location.lineNumber());
if (threadName != null) {
return DebuggerBundle.message(
"exception.breakpoint.console.message.with.thread.info",
exceptionName,
threadName,
locationQName,
locationFileName,
locationLine
);
}
else {
return DebuggerBundle.message(
"exception.breakpoint.console.message",
exceptionName,
locationQName,
locationFileName,
locationLine
);
}
}