Skip to content

Commit

Permalink
Merge branch 'XiaoMi:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava authored Apr 9, 2024
2 parents 45628ab + 84e0ed4 commit 9b144d0
Show file tree
Hide file tree
Showing 922 changed files with 139,858 additions and 4,572 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jcommon_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
#settings-properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'

- run: echo '<settings> <interactiveMode>false</interactiveMode> <profiles> <profile> <repositories> <repository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> <servers> <server> <id>github</id> <username>${env.GITHUB_ACTOR}</username> <password>${env.GITHUB_TOKEN}</password> </server> </servers> <mirrors/> <proxies/></settings>' > ~/.m2/settings.xml
- run: cd jcommon; mvn -U clean package --fail-at-end -Dmaven.test.skip=true -pl 'docean'
- run: cd jcommon; mvn -U clean package --fail-at-end -Dmaven.test.skip=true

check-build-21:
name: Jcommon test 21
Expand Down
2 changes: 1 addition & 1 deletion jcommon/aliyun/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>run.mone</groupId>
<artifactId>jcommon</artifactId>
<version>1.4-jdk20-SNAPSHOT</version>
<version>1.6.0-jdk21-SNAPSHOT</version>
</parent>
<artifactId>aliyun</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jcommon/annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>run.mone</groupId>
<artifactId>jcommon</artifactId>
<version>1.4-jdk20-SNAPSHOT</version>
<version>1.6.0-jdk21-SNAPSHOT</version>
</parent>
<artifactId>annotation</artifactId>
<version>1.6.1-jdk20-SNAPSHOT</version>
Expand Down
2 changes: 1 addition & 1 deletion jcommon/antlr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>run.mone</groupId>
<artifactId>jcommon</artifactId>
<version>1.4-jdk20-SNAPSHOT</version>
<version>1.6.0-jdk21-SNAPSHOT</version>
</parent>
<artifactId>antlr</artifactId>
<dependencies>
Expand Down
66 changes: 66 additions & 0 deletions jcommon/antlr/src/main/java/run/mone/antlr/golang/GoCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package run.mone.antlr.golang;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.ArrayList;
import java.util.List;

/**
* @author [email protected]
* @date 2024/1/29 16:56
*/
public class GoCode {


public static List<GoMethod> methods(String code) {
GoLexer lexer = new GoLexer(new ANTLRInputStream(code));
CommonTokenStream tokens = new CommonTokenStream(lexer);
GoParser parser = new GoParser(tokens);
ParseTree tree = parser.sourceFile();
ParseTreeWalker walker = new ParseTreeWalker();
List<GoMethod> list = new ArrayList<>();
GoParserListener listener = new GoParserBaseListener() {
@Override
public void enterFunctionDecl(GoParser.FunctionDeclContext ctx) {
GoParser.SignatureContext signature = ctx.signature();
List<GoParam> params = new ArrayList<>();

//获取参数信息
if (signature != null) {
GoParser.ParametersContext parameters = signature.parameters();
if (parameters != null) {
for (GoParser.ParameterDeclContext paramCtx : parameters.parameterDecl()) {
// 获取参数类型
String paramType = paramCtx.type_().getText();
// 获取参数名称
List<TerminalNode> paramNames = paramCtx.identifierList().IDENTIFIER();
for (TerminalNode paramName : paramNames) {
params.add(GoParam.builder().name(paramName.getText()).type(paramType).build());
}
}
}
}

Token startToken = ctx.getStart();
Token stopToken = ctx.getStop();
// 获取原始的、格式化的函数文本
int startIndex = startToken.getTokenIndex();
int stopIndex = stopToken.getTokenIndex();
List<Token> t = tokens.getTokens(startIndex, stopIndex);
StringBuilder functionText = new StringBuilder();
for (Token token : t) {
functionText.append(token.getText());
}
list.add(GoMethod.builder().name(ctx.IDENTIFIER().getText()).code(functionText.toString()).paramList(params).build());
}
};
walker.walk(listener, tree);
return list;
}

}
Loading

0 comments on commit 9b144d0

Please sign in to comment.