< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.service.processor/src/jdk/vm/ci/service/processor/ServiceProviderProcessor.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.service.processor;
  24 
  25 import java.io.*;
  26 import java.util.*;
  27 
  28 import javax.annotation.processing.*;
  29 import javax.lang.model.*;
  30 import javax.lang.model.element.*;
  31 import javax.lang.model.type.*;







  32 import javax.tools.Diagnostic.Kind;


  33 
  34 import jdk.vm.ci.service.*;
  35 
  36 import javax.tools.*;
  37 
  38 @SupportedAnnotationTypes("jdk.vm.ci.service.ServiceProvider")
  39 public class ServiceProviderProcessor extends AbstractProcessor {
  40 
  41     private final Set<TypeElement> processed = new HashSet<>();
  42 
  43     @Override
  44     public SourceVersion getSupportedSourceVersion() {
  45         return SourceVersion.latest();
  46     }
  47 
  48     private boolean verifyAnnotation(TypeMirror serviceInterface, TypeElement serviceProvider) {
  49         if (!processingEnv.getTypeUtils().isSubtype(serviceProvider.asType(), serviceInterface)) {
  50             String msg = String.format("Service provider class %s must implement service interface %s", serviceProvider.getSimpleName(), serviceInterface);
  51             processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider);
  52             return false;
  53         }
  54 
  55         return true;
  56     }




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.service.processor;
  24 
  25 import java.io.IOException;
  26 import java.io.OutputStreamWriter;
  27 import java.io.PrintWriter;
  28 import java.util.HashSet;
  29 import java.util.Set;
  30 
  31 import javax.annotation.processing.AbstractProcessor;
  32 import javax.annotation.processing.RoundEnvironment;
  33 import javax.annotation.processing.SupportedAnnotationTypes;
  34 import javax.lang.model.SourceVersion;
  35 import javax.lang.model.element.Element;
  36 import javax.lang.model.element.TypeElement;
  37 import javax.lang.model.type.MirroredTypeException;
  38 import javax.lang.model.type.TypeMirror;
  39 import javax.tools.Diagnostic.Kind;
  40 import javax.tools.FileObject;
  41 import javax.tools.StandardLocation;
  42 
  43 import jdk.vm.ci.service.ServiceProvider;


  44 
  45 @SupportedAnnotationTypes("jdk.vm.ci.service.ServiceProvider")
  46 public class ServiceProviderProcessor extends AbstractProcessor {
  47 
  48     private final Set<TypeElement> processed = new HashSet<>();
  49 
  50     @Override
  51     public SourceVersion getSupportedSourceVersion() {
  52         return SourceVersion.latest();
  53     }
  54 
  55     private boolean verifyAnnotation(TypeMirror serviceInterface, TypeElement serviceProvider) {
  56         if (!processingEnv.getTypeUtils().isSubtype(serviceProvider.asType(), serviceInterface)) {
  57             String msg = String.format("Service provider class %s must implement service interface %s", serviceProvider.getSimpleName(), serviceInterface);
  58             processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider);
  59             return false;
  60         }
  61 
  62         return true;
  63     }


< prev index next >