Skip to content

Commit

Permalink
🌟 创建Codec注解及其处理器
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Sep 10, 2024
1 parent e42c36a commit 15673f7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ plugins {
id 'net.neoforged.moddev' version '2.0.27-beta'
}

version = mod_version
String buildType = 'build'
String buildNumber
if (System.getenv("CI_BUILD") == 'false') buildNumber = null
else {
if (System.getenv("PR_BUILD") != 'false') buildType = 'pr'
buildNumber = System.getenv("GITHUB_RUN_NUMBER")
}
version = "${mod_version}" + (buildNumber != null ? "+${buildType}.${buildNumber}" : "")
group = mod_group_id

repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod_name=AnvilLib
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GNU LGPL 3.0
# The mod version. See https://semver.org/
mod_version=1.0.0
mod_version=1.1.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/anvilcraft/lib/codec/Codec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.anvilcraft.lib.codec;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Codec {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.anvilcraft.lib.codec;

import org.jetbrains.annotations.NotNull;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import java.util.Set;

@SupportedAnnotationTypes("dev.anvilcraft.lib.codec.Codec")
@SupportedSourceVersion(SourceVersion.RELEASE_21)
public class CodecAnnotationProcessor extends AbstractProcessor {
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
}

@Override
public boolean process(Set<? extends TypeElement> annotations, @NotNull RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(Codec.class)) {
TypeElement typeElem = (TypeElement) element;
String typeName = typeElem.getQualifiedName().toString();
Filer filer = processingEnv.getFiler();
}
return true;
}


private void log(String msg) {
if (processingEnv.getOptions().containsKey("debug")) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, msg);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.anvilcraft.lib.codec.CodecAnnotationProcessor

0 comments on commit 15673f7

Please sign in to comment.