diff options
author | Senmori <thesenmori@gmail.com> | 2018-08-26 21:49:20 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-08-26 21:49:31 +1000 |
commit | 9e8b9ec79d42411ad18604b2f2615419d18a2b5e (patch) | |
tree | d738f251a36e3235c206105c2b7c6690aee365c8 /src/main/java | |
parent | 39f216740c54d001396376ad3351b189ee08cceb (diff) | |
download | plugin-annotations-9e8b9ec79d42411ad18604b2f2615419d18a2b5e.tar plugin-annotations-9e8b9ec79d42411ad18604b2f2615419d18a2b5e.tar.gz plugin-annotations-9e8b9ec79d42411ad18604b2f2615419d18a2b5e.tar.lz plugin-annotations-9e8b9ec79d42411ad18604b2f2615419d18a2b5e.tar.xz plugin-annotations-9e8b9ec79d42411ad18604b2f2615419d18a2b5e.zip |
Update plugin-annotations to 1.13
* Add more checks to ensure plugin's are using @Plugin correctly.
* Add no-args constructor check.
* Break up some checks to get better error messages.
* Update error messages to be more informative.
* Update Bukkit version to 1.13
* Bump version
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java index 2f0f8d7..089e709 100644 --- a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java +++ b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java @@ -30,10 +30,12 @@ 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.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.StandardLocation; @@ -67,7 +69,7 @@ public class PluginAnnotationProcessor extends AbstractProcessor { return false; } - if ( elements.isEmpty() ) { + if ( elements.isEmpty() ) { // don't raise error because we don't know which run this is return false; } if ( hasMainBeenFound ) { @@ -81,19 +83,32 @@ public class PluginAnnotationProcessor extends AbstractProcessor { if ( mainPluginElement instanceof TypeElement ) { mainPluginType = ( TypeElement ) mainPluginElement; } else { - raiseError( "Element annotated with @Plugin is not a type!", mainPluginElement ); + raiseError( "Main plugin class is not a class", mainPluginElement ); return false; } - if ( !( mainPluginType.getEnclosingElement() instanceof PackageElement ) && !mainPluginType.getModifiers().contains( Modifier.STATIC ) ) { - raiseError( "Element annotated with @Plugin is not top-level or static nested!", mainPluginType ); + if ( !( mainPluginType.getEnclosingElement() instanceof PackageElement ) ) { + raiseError( "Main plugin class is not a top-level class", mainPluginType ); + return false; + } + + if ( mainPluginType.getModifiers().contains( Modifier.STATIC ) ) { + raiseError( "Main plugin class cannot be static nested", mainPluginType ); return false; } if ( !processingEnv.getTypeUtils().isSubtype( mainPluginType.asType(), fromClass( JavaPlugin.class ) ) ) { - raiseError( "Class annotated with @Plugin is not an subclass of JavaPlugin!", mainPluginType ); + raiseError( "Main plugin class is not an subclass of JavaPlugin!", mainPluginType ); + } + + if ( mainPluginType.getModifiers().contains( Modifier.ABSTRACT ) ) { + raiseError( "Main plugin class cannot be abstract", mainPluginType ); + return false; } + // check for no-args constructor + checkForNoArgsConstructor( mainPluginType ); + Map<String, Object> yml = Maps.newLinkedHashMap(); // linked so we can maintain the same output into file for sanity // populate mainName @@ -227,11 +242,20 @@ public class PluginAnnotationProcessor extends AbstractProcessor { } catch ( IOException e ) { throw new RuntimeException( e ); } - - processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, "NOTE: You are using org.bukkit.plugin.java.annotation, an experimental API!" ); return true; } + private void checkForNoArgsConstructor(TypeElement mainPluginType) { + ExecutableElement construct = null; + for ( ExecutableElement constructor : ElementFilter.constructorsIn( mainPluginType.getEnclosedElements() ) ) { + if ( constructor.getParameters().isEmpty() ) { + return; + } + construct = constructor; + } + raiseError( "Main plugin class must have a no argument constructor.", construct ); + } + private void raiseError(String message) { this.processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, message ); } |