Skip to content

新增 Java 语言支持 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $ leetcode-tool help

```js
{
"lang": "go", // 项目全局语言, 配置后 new 命令 --lang 参数可省略, 目前支持 go ts js py3
"lang": "go", // 项目全局语言, 配置后 new 命令 --lang 参数可省略, 目前支持 go ts js py3 java
"cookie": "xxx"
}
```
Expand All @@ -41,6 +41,7 @@ $ leetcode-tool help
- Typescript ts
- Javascript js
- Python3 py3
- Java java

## 主要功能

Expand Down
30 changes: 30 additions & 0 deletions cmd/new/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ var (
LeetcodeLang: "Python3",
TplFiles: []TplFile{{"code", "solve_%s.py", codeStrPy3}, {"test", "test_%s.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}},
},
"java": {
LeetcodeLang: "Java",
TplFiles: []TplFile{{"code", "solve_%s.java", codeStrJava}, {"test", "test_%s.java", testCodeStrJava}},
},
}
)

Expand Down Expand Up @@ -212,3 +216,29 @@ var (
pass
`
)

var (
codeStrJava = `package {{ .Folder }};

/**
* @index {{ .Index }}
* @title {{ .Title }}
* @difficulty {{ .Difficulty }}
* @tags {{ .TagStr }}
* @draft false
* @link {{ .Link }}
* @frontendId {{ .FrontendId }}
*/
{{ .Code }}
`

testCodeStrJava = `package {{ .Folder }};

public class test_{{ printf "%04s" .Index }} {
public static void main(String[] args) {
Solution solution = new Solution();
// do some test
}
}
`
)