Fixes, annotation processor works for player cls
This commit is contained in:
parent
59d8cd970e
commit
89fb273714
7 changed files with 59 additions and 11 deletions
|
@ -7,6 +7,7 @@ import java.util.logging.Logger;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
@ -29,6 +30,8 @@ public class TestPrepare {
|
|||
return Mockito.mock(PluginManager.class);
|
||||
if (returns(invocation, Collection.class))
|
||||
return Collections.EMPTY_LIST;
|
||||
if (returns(invocation, BukkitScheduler.class))
|
||||
return Mockito.mock(BukkitScheduler.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,8 +99,8 @@ public class Channel {
|
|||
}
|
||||
|
||||
public static class RecipientTestResult {
|
||||
public String errormessage;
|
||||
public int score;
|
||||
public String errormessage = null;
|
||||
public int score = -1; // Anything below 0 is "never send"
|
||||
|
||||
/**
|
||||
* Creates a result that indicates an <b>error</b>
|
||||
|
|
|
@ -14,6 +14,7 @@ import javassist.Modifier;
|
|||
* @author Norbi
|
||||
*
|
||||
*/
|
||||
@TBMCCommandEnforcer
|
||||
public abstract class TBMCCommandBase {
|
||||
|
||||
public TBMCCommandBase() {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package buttondevteam.lib.chat;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
public @interface TBMCCommandEnforcer {
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
|
||||
@AbstractUserClass(foldername = "minecraft", prototype = TBMCPlayer.class)
|
||||
@TBMCPlayerEnforcer
|
||||
public abstract class TBMCPlayerBase extends ChromaGamerBase {
|
||||
protected UUID uuid;
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package buttondevteam.lib.player;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
public @interface TBMCPlayerEnforcer {
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package buttondevteam.buttonproc;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
|
@ -9,21 +11,32 @@ import javax.annotation.processing.SupportedSourceVersion;
|
|||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
/** * A simple session bean type annotation processor. The implementation * is based on the standard annotation processing API in Java 6. */
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||
@SupportedAnnotationTypes("buttondevteam.*")
|
||||
public class ButtonProcessor extends AbstractProcessor {
|
||||
/** * Check if both @Stateful and @Stateless are present in an * session bean. If so, emits a warning message. */
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> typeElements, RoundEnvironment roundEnv) { // TODO: SEparate JAR
|
||||
for (TypeElement te : typeElements) {
|
||||
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(te);
|
||||
for (Element element : elements) {
|
||||
System.out.println("Processing " + element);
|
||||
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
for (TypeElement te : annotations) {
|
||||
Set<? extends Element> classes = roundEnv.getElementsAnnotatedWith(te);
|
||||
for (Element targetcl : classes) {
|
||||
System.out.println("Processing " + targetcl);
|
||||
List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils()
|
||||
.getAllAnnotationMirrors(targetcl);
|
||||
System.out.println("Annotations: " + annotationMirrors);
|
||||
Function<String, Boolean> hasAnnotation = ann -> annotationMirrors.stream()
|
||||
.anyMatch(am -> am.getAnnotationType().toString().contains(ann));
|
||||
if (hasAnnotation.apply("ChromaGamerEnforcer") && !hasAnnotation.apply("UserClass")
|
||||
&& !targetcl.getModifiers().contains(Modifier.ABSTRACT))
|
||||
processingEnv.getMessager().printMessage(Kind.ERROR,
|
||||
"No UserClass annotation found for " + targetcl.getSimpleName(), targetcl);
|
||||
if (hasAnnotation.apply("TBMCPlayerEnforcer") && !hasAnnotation.apply("PlayerClass")
|
||||
&& !targetcl.getModifiers().contains(Modifier.ABSTRACT))
|
||||
processingEnv.getMessager().printMessage(Kind.ERROR,
|
||||
"No PlayerClass annotation found for " + targetcl.getSimpleName(), targetcl);
|
||||
for (AnnotationMirror annotation : annotationMirrors) {
|
||||
String type = annotation.getAnnotationType().toString();
|
||||
System.out.println("Type: " + type);
|
||||
|
@ -32,4 +45,9 @@ public class ButtonProcessor extends AbstractProcessor {
|
|||
}
|
||||
return true; // claim the annotations
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue