package com.oracle.objectfile.debugentry;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Range {
private static final String CLASS_DELIMITER = ".";
private final String cachePath;
private String fileName;
private Path filePath;
private String className;
private String methodName;
private String symbolName;
private String paramNames;
private String returnTypeName;
private String fullMethodName;
private int lo;
private int hi;
private int line;
private boolean isDeoptTarget;
private Range primary;
public Range(String fileName, Path filePath, Path cachePath, String className, String methodName, String symbolName, String paramNames, String returnTypeName, StringTable stringTable, int lo,
int hi, int line, boolean isDeoptTarget) {
this(fileName, filePath, cachePath, className, methodName, symbolName, paramNames, returnTypeName, stringTable, lo, hi, line, isDeoptTarget, null);
}
public Range(String fileName, Path filePath, Path cachePath, String className, String methodName, String symbolName, String paramNames, String returnTypeName, StringTable stringTable, int lo,
int hi, int line, Range primary) {
this(fileName, filePath, cachePath, className, methodName, symbolName, paramNames, returnTypeName, stringTable, lo, hi, line, false, primary);
}
private Range(String fileName, Path filePath, Path cachePath, String className, String methodName, String symbolName, String paramNames, String returnTypeName, StringTable stringTable, int lo,
int hi, int line, boolean isDeoptTarget, Range primary) {
this.fileName = (fileName == null ? null : stringTable.uniqueDebugString(fileName));
this.filePath = filePath;
this.cachePath = (cachePath == null ? "" : stringTable.uniqueDebugString(cachePath.toString()));
this.className = stringTable.uniqueString(className);
this.methodName = stringTable.uniqueString(methodName);
this.symbolName = stringTable.uniqueString(symbolName);
this.paramNames = stringTable.uniqueString(paramNames);
this.returnTypeName = stringTable.uniqueString(returnTypeName);
this.fullMethodName = stringTable.uniqueDebugString(constructClassAndMethodNameWithParams());
this.lo = lo;
this.hi = hi;
this.line = line;
this.isDeoptTarget = isDeoptTarget;
this.primary = primary;
}
public boolean contains(Range other) {
return (lo <= other.lo && hi >= other.hi);
}
public boolean isPrimary() {
return getPrimary() == null;
}
public Range getPrimary() {
return primary;
}
public String getFileName() {
return fileName;
}
public Path getFilePath() {
return filePath;
}
public Path getFileAsPath() {
if (filePath != null) {
return filePath.resolve(fileName);
} else if (fileName != null) {
return Paths.get(fileName);
} else {
return null;
}
}
public String getClassName() {
return className;
}
public String getMethodName() {
return methodName;
}
public String getSymbolName() {
return symbolName;
}
public int getHi() {
return hi;
}
public int getLo() {
return lo;
}
public int getLine() {
return line;
}
public String getFullMethodName() {
return fullMethodName;
}
public boolean isDeoptTarget() {
return isDeoptTarget;
}
public String getParamNames() {
return paramNames;
}
public String getClassAndMethodName() {
return getExtendedMethodName(false, false);
}
private String getExtendedMethodName(boolean includeParams, boolean includeReturnType) {
StringBuilder builder = new StringBuilder();
if (includeReturnType && returnTypeName.length() > 0) {
builder.append(returnTypeName);
builder.append(' ');
}
if (className != null) {
builder.append(className);
builder.append(CLASS_DELIMITER);
}
builder.append(methodName);
if (includeParams && !paramNames.isEmpty()) {
builder.append('(');
builder.append(paramNames);
builder.append(')');
}
return builder.toString();
}
private String constructClassAndMethodNameWithParams() {
return getExtendedMethodName(true, false);
}
public String getCachePath() {
return cachePath;
}
@Override
public String toString() {
return String.format("Range(lo=0x%05x hi=0x%05x %s %s:%d)", lo, hi, constructClassAndMethodNameWithParams(), getFileAsPath(), line);
}
}