Skip to content

Commit c3a40a9

Browse files
committed
Please create a sql formatter plugin for eclipse #304
1 parent eaa458b commit c3a40a9

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

gudusoft.gsqlparser.sqlformatter.plugin/src/gudusoft/gsqlparser/sqlformatter/core/SqlFormat.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
package gudusoft.gsqlparser.sqlformatter.core;
33

4+
import gudusoft.gsqlparser.sqlformatter.SQLFormatPlugin;
5+
46
import java.io.BufferedReader;
57
import java.io.IOException;
68
import java.io.InputStreamReader;
@@ -9,6 +11,9 @@
911
import java.net.URL;
1012
import java.net.URLEncoder;
1113

14+
import org.eclipse.core.runtime.IStatus;
15+
import org.eclipse.core.runtime.Status;
16+
import org.eclipse.swt.widgets.Display;
1217
import org.json.JSONObject;
1318

1419
public class SqlFormat
@@ -31,8 +36,20 @@ public String format( String sql, String formatOptions )
3136
formatSql ) );
3237
return jsonObject.getString( "rspn_formatted_sql" );
3338
}
34-
catch ( Exception e )
39+
catch ( final Exception e )
3540
{
41+
Display.getDefault( ).syncExec( new Runnable( ) {
42+
43+
public void run( )
44+
{
45+
Status status = new Status( IStatus.ERROR,
46+
SQLFormatPlugin.PLUGIN_ID,
47+
e.getMessage( ),
48+
e );
49+
SQLFormatPlugin.getDefault( ).getLog( ).log( status );
50+
}
51+
} );
52+
3653
}
3754
return null;
3855
}
@@ -65,10 +82,19 @@ public String sendPost( String url, String param )
6582
result += line;
6683
}
6784
}
68-
catch ( Exception e )
85+
catch ( final Exception e )
6986
{
70-
System.out.println( "Send post request failed!\n" + e );
71-
e.printStackTrace( );
87+
Display.getDefault( ).syncExec( new Runnable( ) {
88+
89+
public void run( )
90+
{
91+
Status status = new Status( IStatus.ERROR,
92+
SQLFormatPlugin.PLUGIN_ID,
93+
"Send post request failed!",
94+
e );
95+
SQLFormatPlugin.getDefault( ).getLog( ).log( status );
96+
}
97+
} );
7298
}
7399
finally
74100
{
@@ -83,9 +109,19 @@ public String sendPost( String url, String param )
83109
in.close( );
84110
}
85111
}
86-
catch ( IOException ex )
112+
catch ( final IOException ex )
87113
{
88-
ex.printStackTrace( );
114+
Display.getDefault( ).syncExec( new Runnable( ) {
115+
116+
public void run( )
117+
{
118+
Status status = new Status( IStatus.ERROR,
119+
SQLFormatPlugin.PLUGIN_ID,
120+
"Send post request failed!",
121+
ex );
122+
SQLFormatPlugin.getDefault( ).getLog( ).log( status );
123+
}
124+
} );
89125
}
90126
}
91127
return result;

gudusoft.gsqlparser.sqlformatter.plugin/src/gudusoft/gsqlparser/sqlformatter/ui/FormatSQLAction.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import gudusoft.gsqlparser.sqlformatter.core.SqlFormat;
66
import gudusoft.gsqlparser.sqlformatter.ui.util.UIUtil;
77

8+
import org.eclipse.core.runtime.IStatus;
9+
import org.eclipse.core.runtime.Status;
810
import org.eclipse.jface.action.IAction;
911
import org.eclipse.jface.text.BadLocationException;
1012
import org.eclipse.jface.text.IDocument;
@@ -52,7 +54,7 @@ public void run( )
5254
SQLFormatPlugin.getDefault( )
5355
.getPreferenceStore( )
5456
.getString( SQLFormatPlugin.FORMAT_OPTIONS ) );
55-
Display.getDefault( ).syncExec( new Runnable( ) {
57+
Display.getDefault( ).asyncExec( new Runnable( ) {
5658

5759
public void run( )
5860
{
@@ -80,7 +82,13 @@ public void run( )
8082
}
8183
catch ( BadLocationException e )
8284
{
83-
85+
Status status = new Status( IStatus.ERROR,
86+
SQLFormatPlugin.PLUGIN_ID,
87+
e.getMessage( ),
88+
e );
89+
SQLFormatPlugin.getDefault( )
90+
.getLog( )
91+
.log( status );
8492
}
8593
}
8694
}

0 commit comments

Comments
 (0)