@@ -113,7 +113,9 @@ public int cloneCmd(@Parameters(index = "0") String url) {
113113
114114 // Launching Editor on the Cloned Directory
115115 System .out .println ("Launching Editor Now..." );
116- launch_editor (directory , ide , directory .toAbsolutePath ().toString (),filePath );
116+ GenericIDE genericIde = new GenericIDE (ide ) ;
117+ genericIde .getIDE ().launch_editor (directory , ide , directory .toAbsolutePath ().toString (),filePath );
118+
117119 } catch (Exception e ) {
118120 throw new IllegalStateException (e );
119121 }
@@ -288,37 +290,108 @@ public void setClone_path(String clone_path) {
288290
289291 }
290292
291- public static void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
293+ public static abstract class IDE {
294+ public abstract void launch_editor (Path directory , String ide , String path , String filePath )throws IOException , InterruptedException ;
295+
296+ }
297+
298+ public static class GenericIDE extends IDE {
299+
300+ IDE ide ;
301+
302+ GenericIDE (){
303+ // Default Constructor
304+ }
305+
306+ GenericIDE (String ide ){
307+ setIDE (ide );
308+ }
309+
310+ public IDE getIDE (){
311+ //Return Current IDE
312+ return ide ;
313+ }
314+
315+ public IDE getIDE (String ide ){
316+ // Will return IDE based on String
317+ switch (ide ){
318+ case "code" :
319+ case "code.cmd" :
320+ return new VsCode ();
321+
322+ case "idea" :
323+ case "idea64.exe" :
324+ return new IntelliJIdea ();
325+
326+ case "eclipse" :
327+ case "eclipse.exe" :
328+ return new Eclipse ();
329+ default :
330+ throw new IllegalArgumentException ("IDE not supported" );
331+ }
332+
333+ }
334+
335+ public void setIDE (String ide ){
336+ this .ide = getIDE (ide );
337+ }
292338
293- if (filePath .indexOf ("#" )>0 ){
294- filePath = filePath .replace ("#L" ,"#" );
295- // ==== VS CODE ====
296- // code -g file:line
297- if (ide .equals ("code" )||ide .equals ("code.cmd" )){
339+ public void launch_editor (Path directory , String ide , String path , String filePath )throws IOException , InterruptedException {
340+ runCommand (directory .getParent (),ide ,path ,filePath );
341+ }
342+
343+ }
344+
345+ public static class VsCode extends IDE {
346+
347+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
348+ if (filePath .indexOf ("#" )>0 ){
349+ // code -g file:line
350+ filePath = filePath .replace ("#L" ,"#" );
298351 filePath = filePath .replace ("#" ,":" );
299352 runCommand (directory .getParent (), ide ,"-g" ,path ,filePath );
300353 }
301- // ===== IntelliJ =====
302- // idea64.exe [--line <number>] [--column <number>] <path ...>
303- // idea /home/fahad/MyProjects/testings/jbang --line 3 /home/fahad/MyProjects/testings/jbang/otp.java
304- if (ide .equals ("idea" )||ide .equals ("idea.exe" )||ide .equals ("idea64.exe" )){
354+ else {
355+ new GenericIDE ().launch_editor (directory .getParent (),ide ,path ,filePath );
356+ }
357+ }
358+ }
359+
360+ public static class IntelliJIdea extends IDE {
361+
362+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
363+ if (filePath .indexOf ("#" )>0 ){
364+ filePath = filePath .replace ("#L" ,"#" );
365+ // idea64.exe [--line <number>] [--column <number>] <path ...>
366+ // idea /home/fahad/MyProjects/testings/jbang --line 3 /home/fahad/MyProjects/testings/jbang/otp.java
305367 String lineNumber = filePath .substring (filePath .lastIndexOf ("#" )+1 );
306368 filePath = filePath .substring (0 ,filePath .lastIndexOf ("#" ));
307369 runCommand (directory .getParent (), ide ,path ,"--line" ,lineNumber ,filePath );
308370 }
309- // === Eclipse =====
310- // eclipse.exe file.txt:22
311- if (ide .equals ("eclipse" )){
312- filePath = filePath .replace ("#" ,":" );
313- runCommand (directory .getParent (), ide ,path ,filePath );
371+ else {
372+ runCommand (directory .getParent (),ide ,path ,filePath );
373+ new GenericIDE ().launch_editor (directory .getParent (),ide ,path ,filePath );
314374 }
315-
316- }
317- else {
318- runCommand (directory .getParent (),ide ,path ,filePath );// Launching the editor now
319375 }
320376 }
321377
378+ public static class Eclipse extends IDE {
379+
380+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
381+ if (filePath .indexOf ("#" )>0 ){
382+ filePath = filePath .replace ("#L" ,"#" );
383+ // eclipse.exe file.txt:22
384+ if (ide .equals ("eclipse" )){
385+ filePath = filePath .replace ("#" ,":" );
386+ runCommand (directory .getParent (), ide ,path ,filePath );
387+ }
322388
389+ }
390+ else {
391+ runCommand (directory .getParent (),ide ,path ,filePath );
392+ new GenericIDE ().launch_editor (directory .getParent (),ide ,path ,filePath );
393+ }
394+ }
395+ }
323396
324397}
0 commit comments