Skip to content

Commit 9e7b227

Browse files
authored
Merge pull request #23 from maiqingqiang/update-20240929
1.2.10
2 parents c27fd00 + 5c46c80 commit 9e7b227

File tree

5 files changed

+89
-55
lines changed

5 files changed

+89
-55
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
## [Unreleased]
66

7+
## [1.2.10] - 2024-09-29
8+
9+
### Fixed
10+
11+
- Fix SQL2Struct copy and paste bug.
12+
- Fix SQL2Struct comment line break bug.
13+
14+
### Changed
15+
16+
- Bump guava
17+
718
## [1.2.9] - 2024-08-22
819

920
### Fixed
@@ -140,7 +151,8 @@
140151
- ORM Code Completion
141152
- SQL to Struct
142153

143-
[Unreleased]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.9...HEAD
154+
[Unreleased]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.10...HEAD
155+
[1.2.9]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.9...v1.2.10
144156
[1.2.9]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.8...v1.2.9
145157
[1.2.8]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.7...v1.2.8
146158
[1.2.7]: https://github.com/maiqingqiang/go-orm-helper/compare/v1.2.6...v1.2.7

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.github.maiqingqiang.goormhelper
44
pluginName = Go ORM Helper
55
pluginRepositoryUrl = https://github.com/maiqingqiang/go-orm-helper
66
# SemVer format -> https://semver.org
7-
pluginVersion = 1.2.9
7+
pluginVersion = 1.2.10
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 232

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# libraries
33
junit = "5.11.0"
44
lombok = "1.18.34"
5-
guava = "33.3.0-jre"
5+
guava = "33.3.1-jre"
66
druid = "1.2.23"
77
jsqlparser = "5.0"
88
evoInflector = "1.3"

src/main/java/com/github/maiqingqiang/goormhelper/actions/EditorPasteListener.java

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import com.intellij.openapi.actionSystem.DataContext;
1414
import com.intellij.openapi.command.WriteCommandAction;
1515
import com.intellij.openapi.editor.Caret;
16+
import com.intellij.openapi.editor.Document;
1617
import com.intellij.openapi.editor.Editor;
1718
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
1819
import com.intellij.openapi.ide.CopyPasteManager;
1920
import com.intellij.openapi.project.Project;
2021
import com.intellij.psi.PsiFile;
22+
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
2123
import net.sf.jsqlparser.util.validation.Validation;
2224
import net.sf.jsqlparser.util.validation.ValidationError;
2325
import net.sf.jsqlparser.util.validation.feature.FeaturesAllowed;
@@ -27,7 +29,6 @@
2729
import java.awt.datatransfer.DataFlavor;
2830
import java.util.Collections;
2931
import java.util.List;
30-
import java.util.Objects;
3132

3233
public class EditorPasteListener extends EditorActionHandler {
3334

@@ -39,76 +40,91 @@ public EditorPasteListener(EditorActionHandler handler) {
3940

4041
@Override
4142
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
42-
4343
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
44+
if (!(file instanceof GoFile)) {
45+
handler.execute(editor, caret, dataContext);
46+
return;
47+
}
4448

45-
if ((file instanceof GoFile)) {
46-
String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
49+
String text = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
50+
if (!verifySQL(text)) {
51+
handler.execute(editor, caret, dataContext);
52+
return;
53+
}
4754

48-
if (verifySQL(text)) {
49-
Project project = editor.getProject();
55+
Project project = editor.getProject();
56+
if (project == null) {
57+
handler.execute(editor, caret, dataContext);
58+
return;
59+
}
5060

51-
GoORMHelperProjectSettings.State state = Objects.requireNonNull(
52-
GoORMHelperProjectSettings.getInstance(Objects.requireNonNull(project)).getState()
53-
);
61+
GoORMHelperProjectSettings.State state = GoORMHelperProjectSettings.getInstance(project).getState();
62+
if (state == null) {
63+
handler.execute(editor, caret, dataContext);
64+
return;
65+
}
5466

55-
Types.ORM selectedORM = state.defaultORM;
56-
Types.Database selectedDatabase = state.defaultDatabase;
67+
Types.ORM selectedORM = state.defaultORM;
68+
Types.Database selectedDatabase = state.defaultDatabase;
5769

58-
if (selectedORM == Types.ORM.AskEveryTime || selectedDatabase == Types.Database.AskEveryTime) {
59-
ConvertSettingDialogWrapper wrapper = new ConvertSettingDialogWrapper(project);
60-
if (!wrapper.showAndGet()) {
61-
this.handler.execute(editor, caret, dataContext);
62-
return;
63-
}
70+
if (selectedORM == Types.ORM.AskEveryTime || selectedDatabase == Types.Database.AskEveryTime) {
71+
ConvertSettingDialogWrapper wrapper = new ConvertSettingDialogWrapper(project);
72+
if (!wrapper.showAndGet()) {
73+
handler.execute(editor, caret, dataContext);
74+
return;
75+
}
76+
selectedORM = (Types.ORM) wrapper.getOrmComponent().getComponent().getSelectedItem();
77+
selectedDatabase = (Types.Database) wrapper.getDatabaseComponent().getComponent().getSelectedItem();
78+
}
6479

65-
selectedORM = (Types.ORM) wrapper.getOrmComponent().getComponent().getSelectedItem();
66-
selectedDatabase = (Types.Database) wrapper.getDatabaseComponent().getComponent().getSelectedItem();
67-
}
80+
final Types.ORM finalSelectedORM = selectedORM;
81+
final Types.Database finalSelectedDatabase = selectedDatabase;
6882

69-
final Types.ORM finalSelectedORM = selectedORM;
70-
final Types.Database finalSelectedDatabase = selectedDatabase;
71-
72-
WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> {
73-
if (text == null || text.isEmpty() || finalSelectedORM == null || finalSelectedDatabase == null)
74-
return;
75-
76-
ISQL2Struct sql2Struct = finalSelectedORM.sql2Struct(text, finalSelectedDatabase.toDbType());
77-
78-
Caret currentCaret = editor.getCaretModel().getCurrentCaret();
79-
int start = currentCaret.getSelectionStart();
80-
81-
try {
82-
editor.getDocument().insertString(start, sql2Struct.convert());
83-
} catch (Exception ignored) {
84-
Notifications.Bus.notify(
85-
new Notification(
86-
GoORMHelperBundle.message("name"),
87-
GoORMHelperBundle.message("sql.convert.struct.not.support"),
88-
GoORMHelperBundle.message("sql.convert.struct.check"),
89-
NotificationType.WARNING),
90-
project
91-
);
92-
this.handler.execute(editor, caret, dataContext);
93-
}
94-
});
83+
WriteCommandAction.runWriteCommandAction(project, () -> {
84+
if (text == null || text.isEmpty() || finalSelectedORM == null || finalSelectedDatabase == null) {
85+
return;
86+
}
9587

88+
ISQL2Struct sql2Struct = finalSelectedORM.sql2Struct(text, finalSelectedDatabase.toDbType());
89+
if (sql2Struct == null) {
9690
return;
9791
}
98-
}
9992

100-
this.handler.execute(editor, caret, dataContext);
93+
String struct = sql2Struct.convert();
94+
Caret currentCaret = editor.getCaretModel().getCurrentCaret();
95+
int start = currentCaret.getSelectionStart();
96+
int end = currentCaret.getSelectionEnd();
97+
Document document = editor.getDocument();
98+
99+
try {
100+
if (start == end) {
101+
document.insertString(start, struct);
102+
} else {
103+
document.replaceString(start, end, struct);
104+
}
105+
currentCaret.moveToOffset(start + struct.length());
106+
} catch (Exception ignored) {
107+
Notifications.Bus.notify(
108+
new Notification(
109+
GoORMHelperBundle.message("name"),
110+
GoORMHelperBundle.message("sql.convert.struct.not.support"),
111+
GoORMHelperBundle.message("sql.convert.struct.check"),
112+
NotificationType.WARNING),
113+
project
114+
);
115+
handler.execute(editor, caret, dataContext);
116+
}
117+
});
101118
}
102119

103120
private boolean verifySQL(String sql) {
104121
try {
122+
CCJSqlParserUtil.parse(sql);
105123
Validation validation = new Validation(Collections.singletonList(FeaturesAllowed.CREATE), sql);
106124
List<ValidationError> errors = validation.validate();
107-
108125
return errors.isEmpty();
109126
} catch (Exception e) {
110127
return false;
111128
}
112129
}
113-
114-
}
130+
}

src/main/java/com/github/maiqingqiang/goormhelper/sql2struct/impl/SQL2Struct.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ protected String getColumn(@NotNull SQLColumnDefinition definition) {
164164
protected String getComment(@NotNull SQLColumnDefinition definition) {
165165
if (definition.getComment() == null) return "";
166166

167-
return Strings.clearSingleQuotn(definition.getComment().toString());
167+
String comment = definition.getComment().toString();
168+
169+
comment = Strings.clearSingleQuotn(comment);
170+
171+
comment = comment.replaceAll("\\R", " ");
172+
173+
return comment;
168174
}
169175

170176
}

0 commit comments

Comments
 (0)