Skip to content

Commit 2db1b72

Browse files
committed
Code clean up.
net.servicestack:android/client look like they need to be updated. Build errors around IReturn and response status.
1 parent 229304b commit 2db1b72

10 files changed

+176
-322
lines changed

src/ServiceStackIDEA/.idea/workspace.xml

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

src/ServiceStackIDEA/README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The Java file will then be added to the related package or `/src/main/java` fold
4242

4343
#### Update ServiceStack Reference
4444

45-
Once you have added a ServiceStack reference, it can be easily updated by using AndroidStudio `Intension` shortcut, usually Alt+Enter when in the file.
45+
Once you have added a ServiceStack reference, it can be easily updated by using AndroidStudio `Intention` shortcut, usually Alt+Enter when in the file.
4646

4747
![](https://github.com/ServiceStack/Assets/raw/master/img/servicestackidea/android-update-example.gif)
4848

-1.78 KB
Binary file not shown.

src/ServiceStackIDEA/src/AddRef.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
import com.google.gson.FieldNamingPolicy;
2-
import com.google.gson.Gson;
3-
import com.google.gson.GsonBuilder;
41
import com.intellij.ide.util.PackageChooserDialog;
52
import com.intellij.openapi.editor.Document;
3+
import com.intellij.openapi.editor.Editor;
64
import com.intellij.openapi.fileEditor.FileDocumentManager;
75
import com.intellij.openapi.fileEditor.FileEditorManager;
6+
import com.intellij.openapi.fileEditor.TextEditor;
87
import com.intellij.openapi.module.Module;
98
import com.intellij.openapi.project.Project;
109
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
1110
import com.intellij.openapi.vfs.LocalFileSystem;
1211
import com.intellij.openapi.vfs.VirtualFile;
1312
import com.intellij.openapi.vfs.VirtualFileManager;
14-
import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl;
15-
import com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl;
1613
import com.intellij.psi.JavaPsiFacade;
1714
import com.intellij.psi.PsiDirectory;
1815
import com.intellij.psi.PsiManager;
1916
import com.intellij.psi.PsiPackage;
20-
import com.intellij.psi.impl.file.PsiDirectoryImpl;
21-
import com.intellij.psi.util.ClassUtil;
2217
import com.intellij.ui.JBColor;
23-
import com.sun.javafx.fxml.builder.URLBuilder;
2418
import org.apache.http.client.utils.URIBuilder;
2519
import org.jetbrains.annotations.NotNull;
26-
import org.jetbrains.annotations.Nullable;
2720

2821
import javax.swing.*;
2922
import javax.swing.event.DocumentEvent;
@@ -248,7 +241,7 @@ private void onOK() {
248241
try {
249242
URIBuilder urlBuilder = createUrl(addressUrlTextField.getText());
250243
urlBuilder.addParameter("Package", packageBrowse.getText());
251-
String name = getDtoNameWithoutExtention().replaceAll("\\.", "_");
244+
String name = getDtpNameWithoutExtension().replaceAll("\\.", "_");
252245
urlBuilder.addParameter("GlobalNamespace", name);
253246
url = urlBuilder.build().toString();
254247

@@ -344,6 +337,10 @@ private String getDtoPath() throws FileNotFoundException {
344337
throw new FileNotFoundException();
345338
}
346339
PsiDirectory rootPackageDir = PsiManager.getInstance(module.getProject()).findDirectory(selectedFolder);
340+
if(rootPackageDir == null) {
341+
errorMessage = "Unable to determine path for DTO file.";
342+
throw new FileNotFoundException();
343+
}
347344
fullDtoPath = rootPackageDir.getVirtualFile().getPath() + "/" + getDtoFileName();
348345
} else {
349346
String moduleSourcePath;
@@ -359,10 +356,16 @@ private String getDtoPath() throws FileNotFoundException {
359356

360357
private void refreshBuildFile() {
361358
VirtualFileManager.getInstance().syncRefresh();
359+
if(module.getModuleFile() == null) { return; }
360+
362361
VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(module.getModuleFile().getParent().getUrl() + "/build.gradle");
363362

363+
if(fileByUrl == null) { return; }
364+
364365
FileEditorManager.getInstance(module.getProject()).openFile(fileByUrl, false);
365-
Document document = FileEditorManager.getInstance(module.getProject()).getSelectedTextEditor().getDocument();
366+
Editor currentEditor = FileEditorManager.getInstance(module.getProject()).getSelectedTextEditor();
367+
if(currentEditor == null) { return; }
368+
Document document = currentEditor.getDocument();
366369

367370
FileDocumentManager.getInstance().reloadFromDisk(document);
368371
VirtualFileManager.getInstance().syncRefresh();
@@ -378,7 +381,9 @@ private void refreshFile(String filePath, boolean openFile) {
378381
}
379382

380383
FileEditorManager.getInstance(module.getProject()).openFile(fileByUrl, false);
381-
Document document = FileEditorManager.getInstance(module.getProject()).getSelectedTextEditor().getDocument();
384+
Editor currentEditor = FileEditorManager.getInstance(module.getProject()).getSelectedTextEditor();
385+
if(currentEditor == null) { return; }
386+
Document document = currentEditor.getDocument();
382387

383388
if (!openFile) FileEditorManager.getInstance(module.getProject()).closeFile(fileByUrl);
384389

@@ -444,7 +449,7 @@ private String getDtoFileName() {
444449
}
445450
}
446451

447-
private String getDtoNameWithoutExtention() {
452+
private String getDtpNameWithoutExtension() {
448453
String name = nameTextField.getText();
449454
int p = name.lastIndexOf(".");
450455
String e = name.substring(p + 1);
@@ -461,11 +466,4 @@ private void onCancel() {
461466
// add your code here if necessary
462467
dispose();
463468
}
464-
465-
public static void main(String[] args) {
466-
AddRef dialog = new AddRef(null);
467-
dialog.pack();
468-
dialog.setVisible(true);
469-
System.exit(0);
470-
}
471469
}

src/ServiceStackIDEA/src/AddServiceStackReference.java

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import com.google.common.collect.Lists;
22
import com.intellij.facet.Facet;
33
import com.intellij.facet.FacetManager;
4-
import com.intellij.ide.util.DirectoryUtil;
5-
import com.intellij.ide.util.PackageUtil;
64
import com.intellij.notification.Notification;
75
import com.intellij.notification.NotificationType;
86
import com.intellij.notification.Notifications;
@@ -14,13 +12,8 @@
1412
import com.intellij.openapi.module.Module;
1513
import com.intellij.openapi.module.ModuleManager;
1614
import com.intellij.openapi.project.Project;
17-
import com.intellij.openapi.ui.PackageChooser;
1815
import com.intellij.openapi.vfs.VirtualFile;
19-
import com.intellij.openapi.vfs.VirtualFileManager;
2016
import com.intellij.psi.*;
21-
import com.intellij.psi.codeStyle.PackageEntry;
22-
import com.intellij.psi.impl.file.PsiJavaDirectoryImpl;
23-
import com.intellij.psi.search.PackageScope;
2417
import org.jetbrains.annotations.NotNull;
2518

2619
import java.util.ArrayList;
@@ -30,8 +23,6 @@
3023
public class AddServiceStackReference extends AnAction {
3124

3225
public void actionPerformed(AnActionEvent e) {
33-
34-
// TODO: insert action logic here
3526
Module module = getModule(e);
3627
AddRef dialog = new AddRef(module);
3728
dialog.pack();
@@ -42,41 +33,39 @@ public void actionPerformed(AnActionEvent e) {
4233

4334
//Check if a package was selected in the left hand menu, populate package name
4435
PsiElement element = DataKeys.PSI_ELEMENT.getData(e.getDataContext());
45-
if (element != null && element instanceof PsiPackage){
46-
PsiPackage psiPackage = (PsiPackage)element;
36+
if (element != null && element instanceof PsiPackage) {
37+
PsiPackage psiPackage = (PsiPackage) element;
4738
dialog.setSelectedPackage(psiPackage);
4839
dialog.setVisible(true);
4940
return;
5041
}
5142

5243
//Check if a directory containing a Java file was selected, populate package name
53-
if (element != null && element instanceof PsiDirectory){
44+
if (element != null && element instanceof PsiDirectory) {
5445
PsiElement firstChild = element.getFirstChild();
5546
dialog.setSelectedDirectory(((PsiDirectory) element).getVirtualFile().getPath());
56-
if(firstChild != null && firstChild instanceof PsiJavaFile) {
57-
PsiJavaFile firstJavaFile = (PsiJavaFile)firstChild;
47+
if (firstChild != null && firstChild instanceof PsiJavaFile) {
48+
PsiJavaFile firstJavaFile = (PsiJavaFile) firstChild;
5849
PsiPackage mainPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(firstJavaFile.getPackageName());
59-
if(mainPackage != null) {
50+
if (mainPackage != null) {
6051
dialog.setSelectedPackage(mainPackage);
6152
}
62-
} else {
53+
} else if(module.getModuleFile() != null) {
6354
try {
64-
PsiDirectory selectedDir = (PsiDirectory)element;
55+
PsiDirectory selectedDir = (PsiDirectory) element;
6556
String packageName = "";
6657
String moduleDirectoryName = module.getModuleFile().getParent().getName();
6758
List<String> packageArray = new ArrayList<>();
68-
while(selectedDir != null && !(Objects.equals(selectedDir.getName(), moduleDirectoryName))) {
59+
while (selectedDir != null && !(Objects.equals(selectedDir.getName(), moduleDirectoryName))) {
6960
packageArray.add(selectedDir.getName());
7061
selectedDir = selectedDir.getParent();
7162
PsiPackage mainPackage = testPackage(module, packageName, packageArray);
72-
if(mainPackage != null) {
63+
if (mainPackage != null) {
7364
dialog.setSelectedPackage(mainPackage);
7465
break;
7566
}
7667
}
77-
78-
79-
}catch (Exception ex) {
68+
} catch (Exception ex) {
8069
//do nothing, can't get package name.
8170
}
8271
}
@@ -86,41 +75,40 @@ public void actionPerformed(AnActionEvent e) {
8675

8776
//Check if a Java file was selected, display without a package name if no file.
8877
VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
89-
if(selectedFile == null) {
78+
if (selectedFile == null) {
9079
Notification notification = new Notification("ServiceStackIDEA", "Error Add ServiceStack Reference", "Context menu failed find folder or file.", NotificationType.ERROR);
9180
Notifications.Bus.notify(notification);
9281
return;
9382
}
94-
if(selectedFile.isDirectory()) {
83+
if (selectedFile.isDirectory()) {
9584
dialog.setSelectedDirectory(selectedFile.getPath());
96-
} else if(selectedFile.getParent().isDirectory()) {
85+
} else if (selectedFile.getParent().isDirectory()) {
9786
dialog.setSelectedDirectory(selectedFile.getParent().getPath());
9887
} else {
9988
Notification notification = new Notification("ServiceStackIDEA", "Error Add ServiceStack Reference", "Context menu failed find folder or file.", NotificationType.ERROR);
10089
Notifications.Bus.notify(notification);
10190
return;
10291
}
10392

104-
10593
//Check for document, display without a package name if no document.
10694
Document document = FileDocumentManager.getInstance().getDocument(selectedFile);
107-
if(document == null) {
95+
if (document == null) {
10896
dialog.setVisible(true);
10997
return;
11098
}
11199

112100
//Check if a 'PsiFile', display without a package name if no PsiFile.
113101
PsiFile psiFile = PsiDocumentManager.getInstance(module.getProject()).getPsiFile(document);
114-
if(psiFile == null) {
102+
if (psiFile == null) {
115103
dialog.setVisible(true);
116104
return;
117105
}
118106

119107
//Finally check if a Java file and populate package name with class package name.
120-
if(Objects.equals(psiFile.getFileType().getName(), "JAVA")) {
121-
PsiJavaFile javaFile = (PsiJavaFile)psiFile;
108+
if (Objects.equals(psiFile.getFileType().getName(), "JAVA")) {
109+
PsiJavaFile javaFile = (PsiJavaFile) psiFile;
122110
PsiPackage mainPackage = JavaPsiFacade.getInstance(module.getProject()).findPackage(javaFile.getPackageName());
123-
if(mainPackage != null) {
111+
if (mainPackage != null) {
124112
dialog.setSelectedPackage(mainPackage);
125113
}
126114
}
@@ -130,8 +118,8 @@ public void actionPerformed(AnActionEvent e) {
130118

131119
private PsiPackage testPackage(Module module, String packageName, List<String> packageArray) {
132120
List<String> packageNameOrderedList = Lists.reverse(packageArray);
133-
for(int i = 0; i < packageNameOrderedList.size(); i++) {
134-
if(i < packageNameOrderedList.size() - 1) {
121+
for (int i = 0; i < packageNameOrderedList.size(); i++) {
122+
if (i < packageNameOrderedList.size() - 1) {
135123
packageName += packageNameOrderedList.get(i) + ".";
136124
} else {
137125
packageName += packageNameOrderedList.get(i);
@@ -163,8 +151,8 @@ static Module getModule(Project project) {
163151

164152
private static boolean isAndroidProject(@NotNull Module module) {
165153
Facet[] facetsByType = FacetManager.getInstance(module).getAllFacets();
166-
for (Facet facet :facetsByType) {
167-
if(Objects.equals(facet.getTypeId().toString(), "android")) {
154+
for (Facet facet : facetsByType) {
155+
if (Objects.equals(facet.getTypeId().toString(), "android")) {
168156
return true;
169157
}
170158
}

src/ServiceStackIDEA/src/GradleBuildFileHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import com.google.common.base.Joiner;
21
import com.intellij.openapi.module.Module;
3-
import com.intellij.openapi.project.Project;
42
import com.intellij.openapi.vfs.VirtualFile;
53

64
import java.io.*;
@@ -9,6 +7,7 @@
97

108
/**
119
* Created by Layoric on 2/04/2015.
10+
* Methods to help insert gradle dependency
1211
*/
1312
public class GradleBuildFileHelper {
1413

src/ServiceStackIDEA/src/ServiceStackMetadata.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/ServiceStackIDEA/src/UpdateServiceStackReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.intellij.openapi.actionSystem.AnActionEvent;
55
import com.intellij.openapi.actionSystem.DataKeys;
66
import com.intellij.openapi.application.ApplicationManager;
7-
import com.intellij.openapi.command.CommandProcessor;
87
import com.intellij.openapi.editor.Document;
98
import com.intellij.openapi.fileEditor.FileDocumentManager;
109
import com.intellij.openapi.module.Module;
@@ -21,6 +20,7 @@
2120

2221
/**
2322
* Created by Layoric on 9/04/2015.
23+
* Update ServiceStack Reference Project menu context action
2424
*/
2525
public class UpdateServiceStackReference extends AnAction {
2626

0 commit comments

Comments
 (0)