Skip to content

Commit 6026ce6

Browse files
committed
Add Dart ServiceStack Reference support
1 parent 4fba5c2 commit 6026ce6

File tree

8 files changed

+85
-37
lines changed

8 files changed

+85
-37
lines changed

src/ServiceStackIDEA/.idea/workspace.xml

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddServiceStackAction.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void actionPerformed(AnActionEvent e) {
5252
if (mainPackage != null) {
5353
dialog.setSelectedPackage(mainPackage);
5454
}
55-
} else if(module.getModuleFile() != null) {
55+
} else if (module.getModuleFile() != null) {
5656
try {
5757
PsiDirectory selectedDir = (PsiDirectory) element;
5858
String packageName = "";
@@ -122,13 +122,16 @@ public void actionPerformed(AnActionEvent e) {
122122
}
123123

124124
private void ShowDialog(Module module, AddRef dialog) {
125-
if(GradleBuildFileHelper.isGradleModule(module) && GradleBuildFileHelper.isUsingKotlin(module)) {
125+
if (GradleBuildFileHelper.isGradleModule(module) && GradleBuildFileHelper.isUsingKotlin(module)) {
126126
dialog.setFileName("dtos.kt");
127127
}
128-
129-
if(IDEAPomFileHelper.isMavenProjectWithKotlin(module)) {
128+
else if (IDEAPomFileHelper.isMavenProjectWithKotlin(module)) {
130129
dialog.setFileName("dtos.kt");
131130
}
131+
else if (GradleBuildFileHelper.isDartProject(module)) {
132+
dialog.setFileName("dtos.dart");
133+
}
134+
132135
dialog.setVisible(true);
133136
}
134137

@@ -152,7 +155,7 @@ public void update(AnActionEvent e) {
152155
return;
153156
}
154157

155-
if(!(PlatformUtils.isIntelliJ() || isAndroidProject(module))) {
158+
if (!(PlatformUtils.isIntelliJ() || isAndroidProject(module))) {
156159
e.getPresentation().setVisible(false);
157160
return;
158161
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.servicestack.idea;
2+
3+
public class DartNativeTypesHandler extends BaseNativeTypesHandler {
4+
@Override
5+
public String getFileExtension() {
6+
return ".dart";
7+
}
8+
9+
@Override
10+
public String getRelativeTypesUrl() {
11+
return "types/dart";
12+
}
13+
14+
@Override
15+
public NativeTypesLanguage getTypesLanguage() {
16+
return NativeTypesLanguage.Dart;
17+
}
18+
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/GradleBuildFileHelper.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public static Boolean isGradleModule(Module module) {
7575
return getGradleBuildFile(module) != null;
7676
}
7777

78+
public static Boolean isDartProject(Module module) {
79+
return getDartPubspec(module) != null;
80+
}
81+
7882
public static Boolean isUsingKotlin(Module module){
7983
if (!isGradleModule(module)) {
8084
return false;
@@ -102,20 +106,27 @@ public static Boolean isUsingKotlin(Module module){
102106

103107
public static File getGradleBuildFile(Module module) {
104108
VirtualFile moduleFile = module.getModuleFile();
105-
if(moduleFile == null) {
109+
if (moduleFile == null) {
106110
return null;
107111
}
108112
String moduleDirectory = moduleFile.getParent().getPath();
109113
File file = new File(moduleDirectory);
110-
File[] matchingFiles = file.listFiles(new FilenameFilter() {
111-
@Override
112-
public boolean accept(File dir, String name) {
113-
return name.startsWith("build.gradle");
114-
}
115-
});
116-
if(matchingFiles == null || matchingFiles.length == 0) {
114+
File[] matchingFiles = file.listFiles((dir, name) -> name.startsWith("build.gradle"));
115+
return matchingFiles == null || matchingFiles.length == 0
116+
? null
117+
: matchingFiles[0];
118+
}
119+
120+
public static File getDartPubspec(Module module) {
121+
VirtualFile moduleFile = module.getModuleFile();
122+
if (moduleFile == null) {
117123
return null;
118124
}
119-
return matchingFiles[0];
125+
String moduleDirectory = moduleFile.getParent().getPath();
126+
File file = new File(moduleDirectory);
127+
File[] matchingFiles = file.listFiles((dir, name) -> name.startsWith("pubspec.yaml"));
128+
return matchingFiles == null || matchingFiles.length == 0
129+
? null
130+
: matchingFiles[0];
120131
}
121132
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/IDEAUtils.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.intellij.util.PlatformUtils;
1212

1313
import java.io.*;
14+
import java.nio.charset.StandardCharsets;
1415
import java.util.List;
1516

1617
/**
@@ -54,16 +55,11 @@ public static void refreshFile(Module module, String filePath, boolean openFile)
5455
VirtualFileManager.getInstance().syncRefresh();
5556
}
5657

57-
public static void refreshFile(String filePath, boolean openFile) {
58-
59-
}
60-
6158
public static boolean writeDtoFile(List<String> codeLines, String path, StringBuilder errorMessage) {
6259
BufferedWriter writer = null;
6360
boolean result = true;
6461
try {
65-
writer = new BufferedWriter(new OutputStreamWriter(
66-
new FileOutputStream(path), "utf-8"));
62+
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8));
6763
for (String item : codeLines) {
6864
writer.write(item);
6965
writer.newLine();
@@ -100,6 +96,10 @@ public static INativeTypesHandler getDefaultNativeTypesHandler(Module module) {
10096
return new KotlinNativeTypesHandler();
10197
}
10298

99+
if (GradleBuildFileHelper.isDartProject(module)) {
100+
return new DartNativeTypesHandler();
101+
}
102+
103103
if (PlatformUtils.isWebStorm()) {
104104
return new TypeScriptConcreteNativeTypesHandler();
105105
}
@@ -109,10 +109,11 @@ public static INativeTypesHandler getDefaultNativeTypesHandler(Module module) {
109109

110110
public static INativeTypesHandler getNativeTypesHandler(String fileName) {
111111
INativeTypesHandler result = null;
112-
if (fileName.endsWith(".kt")) result = new KotlinNativeTypesHandler();
112+
if (fileName.endsWith(".kt")) result = new KotlinNativeTypesHandler();
113113
if (fileName.endsWith(".java")) result = new JavaNativeTypesHandler();
114-
if (fileName.endsWith(".dtos.ts")) result = new TypeScriptConcreteNativeTypesHandler();
115-
if (fileName.endsWith(".dtos.d.ts")) result = new TypeScriptNativeTypesHandler();
114+
if (fileName.endsWith("dtos.dart")) result = new DartNativeTypesHandler();
115+
if (fileName.endsWith("dtos.ts")) result = new TypeScriptConcreteNativeTypesHandler();
116+
if (fileName.endsWith("dtos.d.ts")) result = new TypeScriptNativeTypesHandler();
116117
return result;
117118
}
118119
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/NativeTypesLanguage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public enum NativeTypesLanguage {
77
Java,
88
Kotlin,
9+
Dart,
910
TypeScriptConcrete,
1011
TypeScript
1112
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/UpdateServiceStackUtils.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ public static void updateServiceStackReference(PsiFile psiFile) {
3131
while (scanner.hasNextLine()) {
3232
String line = scanner.nextLine();
3333
linesOfCode.add(line);
34-
if(line.startsWith("*/")) break;
34+
if (line.startsWith("*/")) break;
3535
}
3636
scanner.close();
3737

3838
int startParamsIndex = 0;
3939
String baseUrl = null;
40-
for(String item : linesOfCode) {
40+
for (String item : linesOfCode) {
4141
startParamsIndex++;
42-
if(item.startsWith("BaseUrl:")) {
42+
if (item.startsWith("BaseUrl:")) {
4343
baseUrl = item.split(":",2)[1].trim();
4444
break;
4545
}
4646
}
47-
if(baseUrl == null) {
47+
if (baseUrl == null) {
4848
Notification notification = new Notification("ServiceStackIDEA", "Error Updating Reference", "BaseUrl property not found.", NotificationType.ERROR);
4949
Notifications.Bus.notify(notification);
5050
return;
5151
}
52-
if(!baseUrl.endsWith("/")) {
52+
if (!baseUrl.endsWith("/")) {
5353
baseUrl += "/";
5454
}
5555

@@ -66,16 +66,16 @@ public static void updateServiceStackReference(PsiFile psiFile) {
6666
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(psiFile.getName());
6767

6868
String existingPath = builder.getPath();
69-
if(existingPath == null || existingPath.equals("/")) {
69+
if (existingPath == null || existingPath.equals("/")) {
7070
builder.setPath(combinePath("", nativeTypesHandler.getRelativeTypesUrl()));
7171
} else {
7272
builder.setPath(combinePath(existingPath, nativeTypesHandler.getRelativeTypesUrl()));
7373
}
7474

7575
Map<String,String> options = new HashMap<String,String>();
76-
for(int i = startParamsIndex; i < linesOfCode.size(); i++) {
76+
for (int i = startParamsIndex; i < linesOfCode.size(); i++) {
7777
String configLine = linesOfCode.get(i);
78-
if(!configLine.startsWith("//") && configLine.contains(":")) {
78+
if (!configLine.startsWith("//") && configLine.contains(":")) {
7979
String[] keyVal = configLine.split(":");
8080
options.put(keyVal[0], keyVal[1].trim());
8181
}
@@ -86,7 +86,7 @@ public static void updateServiceStackReference(PsiFile psiFile) {
8686
int count = 0;
8787
// Using URIBuilder with 'addParameter' URL encodes query values..
8888
// Append manually below to avoid issues https://github.com/ServiceStack/ServiceStack.Java/issues/6
89-
for(Map.Entry<String,String> option : options.entrySet()) {
89+
for (Map.Entry<String,String> option : options.entrySet()) {
9090
if(count == 0) {
9191
serverUrl += "?";
9292
} else {
@@ -113,7 +113,7 @@ public static void updateServiceStackReference(PsiFile psiFile) {
113113
}
114114

115115
String javaCode = javaCodeResponse.toString();
116-
if(!javaCode.startsWith("/* Options:")) {
116+
if (!javaCode.startsWith("/* Options:")) {
117117
Notification notification = new Notification("ServiceStackIDEA", "Error Updating Reference", "Invalid response from provided BaseUrl - " + baseUrl, NotificationType.ERROR);
118118
Notifications.Bus.notify(notification);
119119
return;

src/ServiceStackIDEA/src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<id>net.servicestack.ideaplugin</id>
33
<name>ServiceStack</name>
44
<!--Change build version in build.gradle-->
5-
<version>1.0.14</version>
5+
<version>1.0.15</version>
66
<vendor email="team@servicestack.net" url="https://servicestack.net/">ServiceStack</vendor>
77

88
<description><![CDATA[
@@ -11,6 +11,7 @@
1111

1212
<change-notes><![CDATA[
1313
<ul>
14+
<li>1.0.15 - Add Dart ServiceStack Reference support.</li>
1415
<li>1.0.14 - Fix adding Android dependencies.</li>
1516
<li>1.0.12 - Fix TypeScript dialog defaults to use classes over definitions only.</li>
1617
<li>1.0.11 - Small UI fixes.</li>

0 commit comments

Comments
 (0)