This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from whitechi73/kritor
kritorをmasterブランチに設定する
- Loading branch information
Showing
119 changed files
with
11,778 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
processor/src/main/java/moe/fuqiuluo/ksp/impl/GrpcProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
@file:Suppress("UNCHECKED_CAST") | ||
@file:OptIn(KspExperimental::class) | ||
|
||
package moe.fuqiuluo.ksp.impl | ||
|
||
import com.google.devtools.ksp.KspExperimental | ||
import com.google.devtools.ksp.getAnnotationsByType | ||
import com.google.devtools.ksp.getClassDeclarationByName | ||
import com.google.devtools.ksp.getJavaClassByName | ||
import com.google.devtools.ksp.getKotlinClassByName | ||
import com.google.devtools.ksp.processing.CodeGenerator | ||
import com.google.devtools.ksp.processing.Dependencies | ||
import com.google.devtools.ksp.processing.KSPLogger | ||
import com.google.devtools.ksp.processing.Resolver | ||
import com.google.devtools.ksp.processing.SymbolProcessor | ||
import com.google.devtools.ksp.symbol.KSAnnotated | ||
import com.google.devtools.ksp.symbol.KSClassDeclaration | ||
import com.google.devtools.ksp.symbol.KSDeclaration | ||
import com.google.devtools.ksp.symbol.KSFunctionDeclaration | ||
import com.google.devtools.ksp.symbol.KSType | ||
import com.google.devtools.ksp.symbol.KSTypeParameter | ||
import com.google.devtools.ksp.symbol.Modifier | ||
import com.google.devtools.ksp.validate | ||
import com.squareup.kotlinpoet.FileSpec | ||
import com.squareup.kotlinpoet.FunSpec | ||
import com.squareup.kotlinpoet.KModifier | ||
import kritor.service.Grpc | ||
|
||
class GrpcProcessor( | ||
private val codeGenerator: CodeGenerator, | ||
private val logger: KSPLogger | ||
): SymbolProcessor { | ||
override fun process(resolver: Resolver): List<KSAnnotated> { | ||
val symbols = resolver.getSymbolsWithAnnotation(Grpc::class.qualifiedName!!) | ||
val actions = (symbols as Sequence<KSFunctionDeclaration>).toList() | ||
|
||
if (actions.isEmpty()) return emptyList() | ||
|
||
// 怎么返回nullable的结果 | ||
val packageName = "kritor.handlers" | ||
val funcBuilder = FunSpec.builder("handleGrpc") | ||
.addModifiers(KModifier.SUSPEND) | ||
.addParameter("cmd", String::class) | ||
.addParameter("data", ByteArray::class) | ||
.returns(ByteArray::class) | ||
val fileSpec = FileSpec.scriptBuilder("AutoGrpcHandlers", packageName) | ||
|
||
logger.warn("Found ${actions.size} grpc-actions") | ||
|
||
//logger.error(resolver.getClassDeclarationByName("io.kritor.AuthReq").toString()) | ||
//logger.error(resolver.getJavaClassByName("io.kritor.AuthReq").toString()) | ||
//logger.error(resolver.getKotlinClassByName("io.kritor.AuthReq").toString()) | ||
|
||
actions.forEach { action -> | ||
val methodName = action.qualifiedName?.asString()!! | ||
val grpcMethod = action.getAnnotationsByType(Grpc::class).first() | ||
val service = grpcMethod.serviceName | ||
val funcName = grpcMethod.funcName | ||
funcBuilder.addStatement("if (cmd == \"${service}.${funcName}\") {\t") | ||
|
||
val reqType = action.parameters[0].type.toString() | ||
val rspType = action.returnType.toString() | ||
funcBuilder.addStatement("val resp: $rspType = $methodName($reqType.parseFrom(data))") | ||
funcBuilder.addStatement("return resp.toByteArray()") | ||
|
||
funcBuilder.addStatement("}") | ||
} | ||
funcBuilder.addStatement("return EMPTY_BYTE_ARRAY") | ||
fileSpec | ||
.addStatement("import io.kritor.*") | ||
.addStatement("import io.kritor.core.*") | ||
.addStatement("import io.kritor.contact.*") | ||
.addStatement("import io.kritor.group.*") | ||
.addStatement("import io.kritor.friend.*") | ||
.addStatement("import io.kritor.file.*") | ||
.addStatement("import io.kritor.message.*") | ||
.addStatement("import io.kritor.web.*") | ||
.addStatement("import io.kritor.developer.*") | ||
.addFunction(funcBuilder.build()) | ||
.addImport("moe.fuqiuluo.symbols", "EMPTY_BYTE_ARRAY") | ||
runCatching { | ||
codeGenerator.createNewFile( | ||
dependencies = Dependencies(aggregating = false), | ||
packageName = packageName, | ||
fileName = fileSpec.name | ||
).use { outputStream -> | ||
outputStream.writer().use { | ||
fileSpec.build().writeTo(it) | ||
} | ||
} | ||
} | ||
|
||
return emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
processor/src/main/java/moe/fuqiuluo/ksp/providers/GrpcProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package moe.fuqiuluo.ksp.providers | ||
|
||
import com.google.auto.service.AutoService | ||
import com.google.devtools.ksp.processing.SymbolProcessor | ||
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment | ||
import com.google.devtools.ksp.processing.SymbolProcessorProvider | ||
import moe.fuqiuluo.ksp.impl.GrpcProcessor | ||
|
||
@AutoService(SymbolProcessorProvider::class) | ||
class GrpcProvider: SymbolProcessorProvider { | ||
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor { | ||
return GrpcProcessor( | ||
environment.codeGenerator, | ||
environment.logger | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
protobuf/src/main/java/protobuf/oidb/cmd0x11c5/NtV2RichMediaRsp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
qqinterface/src/main/java/com/tencent/mobileqq/msf/sdk/MsfMessagePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.tencent.mobileqq.msf.sdk; | ||
|
||
import com.tencent.qphone.base.remote.FromServiceMsg; | ||
import com.tencent.qphone.base.remote.ToServiceMsg; | ||
|
||
public class MsfMessagePair { | ||
public FromServiceMsg fromServiceMsg; | ||
public String sendProcess; | ||
public ToServiceMsg toServiceMsg; | ||
|
||
public MsfMessagePair(String str, ToServiceMsg toServiceMsg, FromServiceMsg fromServiceMsg) { | ||
|
||
} | ||
|
||
public MsfMessagePair(ToServiceMsg toServiceMsg, FromServiceMsg fromServiceMsg) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mqq.app; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
|
||
import com.tencent.mobileqq.app.BusinessObserver; | ||
|
||
public class NewIntent extends Intent { | ||
public boolean runNow; | ||
|
||
public NewIntent(Context context, Class<? extends Servlet> cls) { | ||
super(context, cls); | ||
} | ||
|
||
public BusinessObserver getObserver() { | ||
return null; | ||
} | ||
|
||
public boolean isWithouLogin() { | ||
return false; | ||
} | ||
|
||
public void setObserver(BusinessObserver businessObserver) { | ||
|
||
} | ||
|
||
public void setWithouLogin(boolean z) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.