Skip to content

Commit 3bf019a

Browse files
committed
initial commit
0 parents  commit 3bf019a

30 files changed

+80277
-0
lines changed

.gitignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
out/
2+
.idea
3+
backup/
4+
.DS_Store
5+
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
.hypothesis/
53+
.pytest_cache/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# pyenv
81+
.python-version
82+
83+
# celery beat schedule file
84+
celerybeat-schedule
85+
86+
# SageMath parsed files
87+
*.sage.py
88+
89+
# Environments
90+
.env
91+
.venv
92+
env/
93+
venv/
94+
ENV/
95+
env.bak/
96+
venv.bak/
97+
98+
# Spyder project settings
99+
.spyderproject
100+
.spyproject
101+
102+
# Rope project settings
103+
.ropeproject
104+
105+
# mkdocs documentation
106+
/site
107+
108+
# mypy
109+
.mypy_cache/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 SpringHerald
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# DeepCommenter
2+
3+
The source code for DeepCommenter.
4+
5+
6+
7+
### How to Use
8+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="PLUGIN_MODULE" version="4">
3+
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
4+
<component name="NewModuleRootManager" inherit-compiler-output="true">
5+
<exclude-output />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
</component>
13+
</module>
7.08 KB
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<idea-plugin>
2+
<id>tech.czxs.deepcommenter</id>
3+
<name>DeepCommenter</name>
4+
<version>1.0</version>
5+
<vendor email="[email protected]" url="http://www.czxs.tech">czxs</vendor>
6+
7+
<description><![CDATA[
8+
<h2>DeepCommenter</h2>
9+
A plugin used to generate comment for java code.<br>
10+
<br>
11+
Usage: Main Menu -> Code -> Generate Comment
12+
<br>
13+
]]></description>
14+
15+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
16+
<idea-version since-build="173.0"/>
17+
18+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
19+
on how to target different products -->
20+
<!-- uncomment to enable plugin in all products
21+
<depends>com.intellij.modules.lang</depends>
22+
-->
23+
24+
<extensions defaultExtensionNs="com.intellij">
25+
<!-- Add your extensions here -->
26+
</extensions>
27+
28+
<actions>
29+
<!-- Add your actions here -->
30+
<action id="TestGeneration.GenerateCommentAction" class="tech.czxs.deepcommenter.GenerateCommentAction"
31+
text="Generate Comment" description="generate comment for select sentences">
32+
<add-to-group group-id="CodeMenu" anchor="after" relative-to-action="Generate"/>
33+
<keyboard-shortcut keymap="$default" first-keystroke="meta alt SLASH"/>
34+
</action>
35+
</actions>
36+
37+
</idea-plugin>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package tech.czxs.deepcommenter;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
6+
import com.intellij.openapi.command.WriteCommandAction;
7+
import com.intellij.openapi.editor.Document;
8+
import com.intellij.openapi.editor.Editor;
9+
import com.intellij.openapi.editor.SelectionModel;
10+
import com.intellij.openapi.progress.ProgressIndicator;
11+
import com.intellij.openapi.progress.ProgressManager;
12+
import com.intellij.openapi.progress.Task;
13+
import com.intellij.openapi.project.Project;
14+
import com.intellij.openapi.ui.Messages;
15+
import com.intellij.openapi.util.TextRange;
16+
import org.jetbrains.annotations.NotNull;
17+
18+
public class GenerateCommentAction extends AnAction {
19+
20+
@Override
21+
public void actionPerformed(AnActionEvent e) {
22+
// TODO: insert action logic here
23+
Editor editor = e.getData(PlatformDataKeys.EDITOR);
24+
if (editor == null) return;
25+
Project project = e.getProject();
26+
27+
SelectionModel selectionModel = editor.getSelectionModel();
28+
String selectedText = selectionModel.getSelectedText();
29+
if (selectedText == null) return;
30+
31+
ProgressManager.getInstance().run(
32+
new Task.Modal(project, "Generating Comment", true) {
33+
@Override
34+
public void run(@NotNull ProgressIndicator indicator) {
35+
36+
indicator.setFraction(0.1);
37+
try {
38+
Thread.sleep(700);
39+
} catch (InterruptedException e) {
40+
e.printStackTrace();
41+
}
42+
43+
}
44+
});
45+
// try {
46+
// Thread.sleep(5000);
47+
// } catch (InterruptedException ex) {
48+
// ex.printStackTrace();
49+
// }
50+
String result;
51+
try {
52+
String s = selectedText;
53+
result = HttpClientPool.getHttpClient().post("http://47.98.158.183:5000/s", s);
54+
// result = HttpClientPool.getHttpClient().post("http://127.0.0.1:5000/s", s);
55+
56+
} catch (Exception ex) {
57+
ex.printStackTrace();
58+
Messages.showMessageDialog("Failed to connect to server.", "Information", Messages.getInformationIcon());
59+
return;
60+
}
61+
62+
Document document = editor.getDocument();
63+
64+
65+
int selectionStart = selectionModel.getSelectionStart();
66+
int line = 0;
67+
int lineOffset = 0;
68+
for (int i = 0; i < document.getLineCount(); i++) {
69+
int tmpOffset = document.getLineStartOffset(i);
70+
if(tmpOffset <= selectionStart) {
71+
line = i;
72+
lineOffset = tmpOffset;
73+
} else break;
74+
}
75+
int lineEndOffset = document.getLineEndOffset(line);
76+
77+
String s = document.getText(new TextRange(lineOffset, lineEndOffset));
78+
79+
int spaceNum = 0;
80+
for (int i = 0; i < s.length(); i++) {
81+
if(s.charAt(i) == ' ') spaceNum++;
82+
else break;
83+
}
84+
StringBuilder sb = new StringBuilder();
85+
for (int i = 0; i < spaceNum; i++) sb.append(" ");
86+
87+
final int insertOffset = lineOffset;
88+
final String result1 = result;
89+
WriteCommandAction.runWriteCommandAction(project, () ->
90+
document.insertString(insertOffset, sb + "/**\n" + sb + " * " + result1 + sb + " */\n"));
91+
92+
selectionModel.removeSelection();
93+
94+
}
95+
96+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package tech.czxs.deepcommenter;
2+
3+
import org.apache.http.HttpResponse;
4+
import org.apache.http.NameValuePair;
5+
import org.apache.http.client.config.RequestConfig;
6+
import org.apache.http.client.entity.UrlEncodedFormEntity;
7+
import org.apache.http.client.methods.HttpGet;
8+
import org.apache.http.client.methods.HttpPost;
9+
import org.apache.http.client.methods.HttpRequestBase;
10+
import org.apache.http.impl.client.CloseableHttpClient;
11+
import org.apache.http.impl.client.HttpClients;
12+
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
13+
import org.apache.http.message.BasicNameValuePair;
14+
import org.apache.http.util.EntityUtils;
15+
16+
import java.net.URLDecoder;
17+
import java.nio.charset.StandardCharsets;
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
22+
public class HttpClientPool {
23+
24+
private static volatile HttpClientPool clientInstance;
25+
private static PoolingHttpClientConnectionManager connectionManager;
26+
27+
28+
/**
29+
* create a client pool for http client .
30+
*/
31+
/**
32+
* create a client pool for http client .
33+
*/
34+
/**
35+
* create a client pool for http client .
36+
*/
37+
public static HttpClientPool getHttpClient() {
38+
HttpClientPool tmp = clientInstance;
39+
if (tmp == null) {
40+
synchronized (HttpClientPool.class) {
41+
tmp = clientInstance;
42+
if (tmp == null) {
43+
tmp = new HttpClientPool();
44+
clientInstance = tmp;
45+
}
46+
}
47+
}
48+
return tmp;
49+
}
50+
51+
/**
52+
* creates a new httpclient object .
53+
*/
54+
/**
55+
* creates a new httpclient object .
56+
*/
57+
private HttpClientPool() {
58+
connectionManager = new PoolingHttpClientConnectionManager();
59+
connectionManager.setMaxTotal(200);// 连接池
60+
connectionManager.setDefaultMaxPerRoute(100);// 每条通道的并发连接数
61+
}
62+
63+
private CloseableHttpClient getHttpClient(int connectionTimeout, int socketTimeOut) {
64+
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionTimeout).setSocketTimeout(socketTimeOut).build();
65+
return HttpClients.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
66+
}
67+
68+
public String get(String url) throws Exception {
69+
HttpGet httpGet = new HttpGet(url);
70+
return getResponseContent(url,httpGet);
71+
}
72+
73+
public String post(String url, String code) throws Exception {
74+
HttpPost httpPost = new HttpPost(url);
75+
List<NameValuePair> nvps = new ArrayList<>();
76+
nvps.add(new BasicNameValuePair("s", code));
77+
httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8));
78+
79+
return getResponseContent(url, httpPost);
80+
}
81+
82+
private String getResponseContent(String url, HttpRequestBase request) throws Exception {
83+
HttpResponse response = null;
84+
try {
85+
response = this.getHttpClient(15000,15000).execute(request);
86+
return EntityUtils.toString(response.getEntity());
87+
} catch (Exception e) {
88+
throw new Exception("got an error from HTTP for url : " + URLDecoder.decode(url, "UTF-8"),e);
89+
} finally {
90+
if(response != null){
91+
EntityUtils.consumeQuietly(response.getEntity());
92+
}
93+
request.releaseConnection();
94+
}
95+
}
96+
}

deepcommenter-server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# code-commentator-server
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public payment data exception ( string message , reason reason ) { super ( message ) ; set message key ( get message key ( ) + reason . to string ( ) ) ; }
2+
public static void sort ( int [ ] data , int start , int end , integercomparator comp ) { quicksort ( data , start , end , comp ) ; }
3+
public java . lang . string tostring ( ) { return tostring ( bool_ , bool_ ) ; }
4+
public map pick up request ( string parking space id , int layer , string area id , string order id ) { log . info ( str_ + parking space id , str_ + layer + str_ + area id + str_ + order id ) ; string [ ] task type = { str_ , str_ , str_ } ; business order service . create pick up order ( parking space id , layer , area id , num_ , direction . di r1 , order id , task type ) ; map < string , string > resp = new hash map < > ( ) ; resp . put ( str_ , area id ) ; return resp ; }
5+
public map pick up request ( string parking space id , int layer , string area id , string order id ) { business order service . create pick up order ( parking space id , layer , area id , num_ , direction . di r1 , order id , task type ) ; map < string , string > resp = new hash map < > ( ) ; resp . put ( str_ , area id ) ; return resp ; }
6+
public static string tostring ( throwable throwable ) { stringwriter stringwriter = new stringwriter ( ) ; throwable . printstacktrace ( new printwriter ( stringwriter ) ) ; return stringwriter . tostring ( ) ; }

0 commit comments

Comments
 (0)