MethodReference method = debugInformation.getMethodAt(lineNumber, column); String className; String methodName; SourceLocation location = debugInformation.getSourceLocation(lineNumber, column); if (location != null && location.getFileName() != null) { fileName = location.getFileName();
private static DebugInformation getDebugInformation(File debugFile) { try (InputStream input = new FileInputStream(debugFile)) { return DebugInformation.read(input); } catch (IOException e) { throw new RuntimeException(e); } }
private void generateDebug(DebugInformationBuilder debugInformationBuilder) { try { DebugInformation debugInformation = debugInformationBuilder.getDebugInformation(); String sourceMapName = fileName + ".map"; try (Writer writer = new OutputStreamWriter(buildTarget.appendToResource(fileName), StandardCharsets.UTF_8)) { writer.append("\n//# sourceMappingURL=" + sourceMapName); } try (Writer writer = new OutputStreamWriter(buildTarget.createResource(sourceMapName), StandardCharsets.UTF_8)) { debugInformation.writeAsSourceMaps(writer, "src", fileName); } debugInformation.write(buildTarget.createResource(fileName + ".teavmdbg")); } catch (IOException e) { throw new RuntimeException("IO error occurred writing debug information", e); } }
public String[] getVariableMeaningAt(GeneratedLocation location, String variable) { Integer varIndex = variableNameMap.get(variable); if (varIndex == null) { return new String[0]; } RecordArray mapping = variableMappings[varIndex]; if (mapping == null) { return new String[0]; } int keyIndex = indexByKey(mapping, location); if (keyIndex < 0) { return new String[0]; } GeneratedLocation keyLocation = key(mapping.get(keyIndex)); if (!Objects.equals(getMethodAt(keyLocation), getMethodAt(location))) { return new String[0]; } int[] valueIndexes = mapping.get(keyIndex).getArray(0); String[] result = new String[valueIndexes.length]; for (int i = 0; i < result.length; ++i) { result[i] = valueIndexes[i] >= 0 ? variableNames[valueIndexes[i]] : null; } return result; }
public SourceLocation getSourceLocation(GeneratedLocation generatedLocation) { String fileName = componentByKey(fileMapping, fileNames, generatedLocation); int lineNumberIndex = indexByKey(lineMapping, generatedLocation); int lineNumber = lineNumberIndex >= 0 ? lineMapping.get(lineNumberIndex).get(2) : -1; return new SourceLocation(fileName, lineNumber); }
public SourceLocation getSourceLocation(int line, int column) { return getSourceLocation(new GeneratedLocation(line, column)); }
public MethodReference getMethodAt(int line, int column) { return getMethodAt(new GeneratedLocation(line, column)); }
public DebugInformation getDebugInformation() { if (debugInformation == null) { debugInformation = new DebugInformation(); debugInformation.rebuild();
public Promise<String> getType() { if (type == null) { type = jsValue.getClassName().then(className -> { if (className.startsWith("a/")) { className = className.substring(2); String origClassName = className; int degree = 0; while (className.endsWith("[]")) { className = className.substring(0, className.length() - 2); ++degree; } String javaClassName = debugInformation.getClassNameByJsName(className); if (javaClassName != null) { if (degree > 0) { StringBuilder sb = new StringBuilder(javaClassName); for (int i = 0; i < degree; ++i) { sb.append("[]"); } javaClassName = sb.toString(); } className = javaClassName; } else { className = origClassName; } } return className; }); } return type; }
public MethodReference getMethodAt(GeneratedLocation generatedLocation) { String className = componentByKey(classMapping, classNames, generatedLocation); if (className == null) { return null; } String method = componentByKey(methodMapping, methods, generatedLocation); if (method == null) { return null; } return referenceCache.getCached(className, referenceCache.parseDescriptorCached(method)); }
private int indexByKey(RecordArray mapping, GeneratedLocation location) { int index = binarySearchLocation(mapping, location.getLine(), location.getColumn()); return index >= 0 ? index : -index - 2; }
public String[] getVariableMeaningAt(GeneratedLocation location, String variable) { Integer varIndex = variableNameMap.get(variable); if (varIndex == null) { return new String[0]; } RecordArray mapping = variableMappings[varIndex]; if (mapping == null) { return new String[0]; } int keyIndex = indexByKey(mapping, location); if (keyIndex < 0) { return new String[0]; } GeneratedLocation keyLocation = key(mapping.get(keyIndex)); if (!Objects.equals(getMethodAt(keyLocation), getMethodAt(location))) { return new String[0]; } int[] valueIndexes = mapping.get(keyIndex).getArray(0); String[] result = new String[valueIndexes.length]; for (int i = 0; i < result.length; ++i) { result[i] = valueIndexes[i] >= 0 ? variableNames[valueIndexes[i]] : null; } return result; }
public SourceLocation getSourceLocation(int line, int column) { return getSourceLocation(new GeneratedLocation(line, column)); }
public MethodReference getMethodAt(int line, int column) { return getMethodAt(new GeneratedLocation(line, column)); }
public DebugInformation read() throws IOException { DebugInformation debugInfo = new DebugInformation(); debugInfo.fileNames = readStrings(); debugInfo.classNames = readStrings(); debugInfo.fields = readStrings(); debugInfo.methods = readStrings(); debugInfo.variableNames = readStrings(); debugInfo.exactMethods = readExactMethods(); debugInfo.fileMapping = readMapping(); debugInfo.lineMapping = readMapping(); debugInfo.classMapping = readMapping(); debugInfo.methodMapping = readMapping(); debugInfo.statementStartMapping = readBooleanMapping(); debugInfo.callSiteMapping = readCallSiteMapping(); debugInfo.variableMappings = readVariableMappings(debugInfo.variableNames.length); debugInfo.classesMetadata = readClassesMetadata(debugInfo.classNames.length); debugInfo.controlFlowGraphs = readCFGs(debugInfo.fileNames.length); debugInfo.rebuild(); return debugInfo; }
public SourceLocation getSourceLocation(GeneratedLocation generatedLocation) { String fileName = componentByKey(fileMapping, fileNames, generatedLocation); int lineNumberIndex = indexByKey(lineMapping, generatedLocation); int lineNumber = lineNumberIndex >= 0 ? lineMapping.get(lineNumberIndex).get(2) : -1; return new SourceLocation(fileName, lineNumber); }
String className = String.valueOf(result.get("className", result)); if (debugInformation != null) { String decodedName = debugInformation.getClassNameByJsName(className); if (decodedName != null) { className = decodedName;
public MethodReference getMethodAt(GeneratedLocation generatedLocation) { String className = componentByKey(classMapping, classNames, generatedLocation); if (className == null) { return null; } String method = componentByKey(methodMapping, methods, generatedLocation); if (method == null) { return null; } return new MethodReference(className, MethodDescriptor.parse(method)); }
private int indexByKey(RecordArray mapping, GeneratedLocation location) { int index = binarySearchLocation(mapping, location.getLine(), location.getColumn()); return index >= 0 ? index : -index - 2; }
debugInfo.writeAsSourceMaps(sourceMapsOut, "", file.getPath()); debugInfo.write(out);