< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/TraverseProc.java

Print this page
rev 50763 : 8205455: jdeprscan issues annotation processor warning regarding RELEASE_10
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  24  */
  25 
  26 package com.sun.tools.jdeprscan;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Collection;
  30 import java.util.Comparator;
  31 import java.util.HashMap;
  32 import java.util.HashSet;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 import javax.annotation.processing.AbstractProcessor;
  38 import javax.annotation.processing.Messager;
  39 import javax.annotation.processing.ProcessingEnvironment;
  40 import javax.annotation.processing.RoundEnvironment;
  41 import javax.annotation.processing.SupportedAnnotationTypes;
  42 import javax.annotation.processing.SupportedSourceVersion;
  43 
  44 import javax.lang.model.element.ModuleElement;
  45 import javax.lang.model.element.TypeElement;
  46 import javax.lang.model.util.Elements;
  47 
  48 import static javax.lang.model.SourceVersion.RELEASE_10;
  49 import javax.lang.model.element.Element;
  50 import javax.lang.model.element.ElementKind;
  51 import javax.lang.model.element.Modifier;

  52 import javax.lang.model.element.PackageElement;


  53 import javax.tools.Diagnostic;
  54 
  55 @SupportedSourceVersion(RELEASE_10)
  56 @SupportedAnnotationTypes("*")
  57 public class TraverseProc extends AbstractProcessor {
  58     Elements elements;
  59     Messager messager;
  60     final List<String> moduleRoots;
  61     Map<PackageElement, List<TypeElement>> publicTypes;
  62 
  63     TraverseProc(List<String> roots) {
  64         moduleRoots = roots;
  65     }
  66 
  67     @Override
  68     public void init(ProcessingEnvironment pe) {
  69         super.init(pe);
  70         elements = pe.getElementUtils();
  71         messager = pe.getMessager();
  72     }
  73 
  74     @Override





  75     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  76         if (roundEnv.processingOver()) {
  77             return false;
  78         }
  79 
  80         Set<ModuleElement> modules = new HashSet<>();
  81         for (String mname : moduleRoots) {
  82             ModuleElement me = elements.getModuleElement(mname);
  83             if (me == null) {
  84                 messager.printMessage(Diagnostic.Kind.ERROR,
  85                                       String.format("module %s not found%n", mname));
  86             } else {
  87                 modules.addAll(findModules(me));
  88             }
  89         }
  90 
  91         Set<PackageElement> packages = findPackages(modules);
  92 
  93         publicTypes = findPublicTypes(packages);
  94 


   1 /*
   2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  24  */
  25 
  26 package com.sun.tools.jdeprscan;
  27 
  28 import java.util.ArrayList;
  29 import java.util.Collection;
  30 import java.util.Comparator;
  31 import java.util.HashMap;
  32 import java.util.HashSet;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 import javax.annotation.processing.AbstractProcessor;
  38 import javax.annotation.processing.Messager;
  39 import javax.annotation.processing.ProcessingEnvironment;
  40 import javax.annotation.processing.RoundEnvironment;
  41 import javax.annotation.processing.SupportedAnnotationTypes;
  42 import javax.annotation.processing.SupportedSourceVersion;
  43 
  44 import javax.lang.model.SourceVersion;




  45 import javax.lang.model.element.Element;
  46 import javax.lang.model.element.ElementKind;
  47 import javax.lang.model.element.Modifier;
  48 import javax.lang.model.element.ModuleElement;
  49 import javax.lang.model.element.PackageElement;
  50 import javax.lang.model.element.TypeElement;
  51 import javax.lang.model.util.Elements;
  52 import javax.tools.Diagnostic;
  53 

  54 @SupportedAnnotationTypes("*")
  55 public class TraverseProc extends AbstractProcessor {
  56     Elements elements;
  57     Messager messager;
  58     final List<String> moduleRoots;
  59     Map<PackageElement, List<TypeElement>> publicTypes;
  60 
  61     TraverseProc(List<String> roots) {
  62         moduleRoots = roots;
  63     }
  64 
  65     @Override
  66     public void init(ProcessingEnvironment pe) {
  67         super.init(pe);
  68         elements = pe.getElementUtils();
  69         messager = pe.getMessager();
  70     }
  71 
  72     @Override
  73     public SourceVersion getSupportedSourceVersion() {
  74         return SourceVersion.latest();
  75     }
  76 
  77     @Override
  78     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  79         if (roundEnv.processingOver()) {
  80             return false;
  81         }
  82 
  83         Set<ModuleElement> modules = new HashSet<>();
  84         for (String mname : moduleRoots) {
  85             ModuleElement me = elements.getModuleElement(mname);
  86             if (me == null) {
  87                 messager.printMessage(Diagnostic.Kind.ERROR,
  88                                       String.format("module %s not found%n", mname));
  89             } else {
  90                 modules.addAll(findModules(me));
  91             }
  92         }
  93 
  94         Set<PackageElement> packages = findPackages(modules);
  95 
  96         publicTypes = findPublicTypes(packages);
  97 


< prev index next >