MCPcopy Index your code
hub / github.com/processing/processing / getSourceLine

Method getSourceLine

java/src/processing/mode/java/Debugger.java:1187–1223  ·  view source on GitHub ↗

Read a line from the given file in the builds src folder. 1-based i.e. first line has line no. 1 @param filePath @param lineNo @return the requested source line

(String filePath, int lineNo, int radius)

Source from the content-addressed store, hash-verified

1185 * @return the requested source line
1186 */
1187 protected String getSourceLine(String filePath, int lineNo, int radius) {
1188 if (lineNo == -1) {
1189 loge("invalid line number: " + lineNo, null);
1190 return "";
1191 }
1192 //System.out.println("getting line: " + lineNo);
1193 File f = new File(srcPath + File.separator + filePath);
1194 String output = "";
1195 try {
1196 BufferedReader r = new BufferedReader(new FileReader(f));
1197 int i = 1;
1198 //String line = "";
1199 while (i <= lineNo + radius) {
1200 String line = r.readLine(); // line no. i
1201 if (line == null) {
1202 break; // end of file
1203 }
1204 if (i >= lineNo - radius) {
1205 if (i > lineNo - radius) {
1206 output += "\n"; // add newlines before all lines but the first
1207 }
1208 output += f.getName() + ":" + i + (i == lineNo ? " => " : " ") + line;
1209 }
1210 i++;
1211 }
1212 r.close();
1213 return output;
1214
1215 } catch (FileNotFoundException ex) {
1216 //System.err.println(ex);
1217 return f.getName() + ":" + lineNo;
1218
1219 } catch (IOException ex) {
1220 loge("other io exception", ex);
1221 return "";
1222 }
1223 }
1224
1225
1226 /**

Callers 1

printSourceLocationMethod · 0.95

Calls 3

logeMethod · 0.95
getNameMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected