src/share/classes/com/sun/tools/javah/JavahTask.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2010, 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


  43 import java.util.Map;
  44 import java.util.MissingResourceException;
  45 import java.util.ResourceBundle;
  46 import java.util.Set;
  47 
  48 import javax.annotation.processing.AbstractProcessor;
  49 import javax.annotation.processing.Messager;
  50 import javax.annotation.processing.ProcessingEnvironment;
  51 import javax.annotation.processing.RoundEnvironment;
  52 import javax.annotation.processing.SupportedAnnotationTypes;
  53 
  54 import javax.lang.model.SourceVersion;
  55 import javax.lang.model.element.ExecutableElement;
  56 import javax.lang.model.element.TypeElement;
  57 import javax.lang.model.element.VariableElement;
  58 import javax.lang.model.type.ArrayType;
  59 import javax.lang.model.type.DeclaredType;
  60 import javax.lang.model.type.TypeMirror;
  61 import javax.lang.model.type.TypeVisitor;
  62 import javax.lang.model.util.ElementFilter;
  63 import javax.lang.model.util.SimpleTypeVisitor7;
  64 import javax.lang.model.util.Types;
  65 
  66 import javax.tools.Diagnostic;
  67 import javax.tools.DiagnosticListener;
  68 import javax.tools.JavaCompiler;
  69 import javax.tools.JavaCompiler.CompilationTask;
  70 import javax.tools.JavaFileManager;
  71 import javax.tools.JavaFileObject;
  72 import javax.tools.StandardJavaFileManager;
  73 import javax.tools.StandardLocation;
  74 import javax.tools.ToolProvider;
  75 import static javax.tools.Diagnostic.Kind.*;
  76 
  77 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  78 import com.sun.tools.javac.main.CommandLine;
  79 
  80 /**
  81  * Javah generates support files for native methods.
  82  * Parse commandline options & Invokes javadoc to execute those commands.
  83  *


 736                 allClasses.add(c);
 737                 getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
 738             }
 739         }
 740 
 741         // 4942232:
 742         // check that classes exist for all the parameters of native methods
 743         private void checkMethodParameters(Set<TypeElement> classes) {
 744             Types types = processingEnv.getTypeUtils();
 745             for (TypeElement te: classes) {
 746                 for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
 747                     for (VariableElement ve: ee.getParameters()) {
 748                         TypeMirror tm = ve.asType();
 749                         checkMethodParametersVisitor.visit(tm, types);
 750                     }
 751                 }
 752             }
 753         }
 754 
 755         private TypeVisitor<Void,Types> checkMethodParametersVisitor =
 756                 new SimpleTypeVisitor7<Void,Types>() {
 757             @Override
 758             public Void visitArray(ArrayType t, Types types) {
 759                 visit(t.getComponentType(), types);
 760                 return null;
 761             }
 762             @Override
 763             public Void visitDeclared(DeclaredType t, Types types) {
 764                 t.asElement().getKind(); // ensure class exists
 765                 for (TypeMirror st: types.directSupertypes(t))
 766                     visit(st, types);
 767                 return null;
 768             }
 769         };
 770 
 771         private Gen g;
 772         private Util.Exit exit;
 773     }
 774 }
   1 /*
   2  * Copyright (c) 2002, 2011, 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


  43 import java.util.Map;
  44 import java.util.MissingResourceException;
  45 import java.util.ResourceBundle;
  46 import java.util.Set;
  47 
  48 import javax.annotation.processing.AbstractProcessor;
  49 import javax.annotation.processing.Messager;
  50 import javax.annotation.processing.ProcessingEnvironment;
  51 import javax.annotation.processing.RoundEnvironment;
  52 import javax.annotation.processing.SupportedAnnotationTypes;
  53 
  54 import javax.lang.model.SourceVersion;
  55 import javax.lang.model.element.ExecutableElement;
  56 import javax.lang.model.element.TypeElement;
  57 import javax.lang.model.element.VariableElement;
  58 import javax.lang.model.type.ArrayType;
  59 import javax.lang.model.type.DeclaredType;
  60 import javax.lang.model.type.TypeMirror;
  61 import javax.lang.model.type.TypeVisitor;
  62 import javax.lang.model.util.ElementFilter;
  63 import javax.lang.model.util.SimpleTypeVisitor8;
  64 import javax.lang.model.util.Types;
  65 
  66 import javax.tools.Diagnostic;
  67 import javax.tools.DiagnosticListener;
  68 import javax.tools.JavaCompiler;
  69 import javax.tools.JavaCompiler.CompilationTask;
  70 import javax.tools.JavaFileManager;
  71 import javax.tools.JavaFileObject;
  72 import javax.tools.StandardJavaFileManager;
  73 import javax.tools.StandardLocation;
  74 import javax.tools.ToolProvider;
  75 import static javax.tools.Diagnostic.Kind.*;
  76 
  77 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  78 import com.sun.tools.javac.main.CommandLine;
  79 
  80 /**
  81  * Javah generates support files for native methods.
  82  * Parse commandline options & Invokes javadoc to execute those commands.
  83  *


 736                 allClasses.add(c);
 737                 getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
 738             }
 739         }
 740 
 741         // 4942232:
 742         // check that classes exist for all the parameters of native methods
 743         private void checkMethodParameters(Set<TypeElement> classes) {
 744             Types types = processingEnv.getTypeUtils();
 745             for (TypeElement te: classes) {
 746                 for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
 747                     for (VariableElement ve: ee.getParameters()) {
 748                         TypeMirror tm = ve.asType();
 749                         checkMethodParametersVisitor.visit(tm, types);
 750                     }
 751                 }
 752             }
 753         }
 754 
 755         private TypeVisitor<Void,Types> checkMethodParametersVisitor =
 756                 new SimpleTypeVisitor8<Void,Types>() {
 757             @Override
 758             public Void visitArray(ArrayType t, Types types) {
 759                 visit(t.getComponentType(), types);
 760                 return null;
 761             }
 762             @Override
 763             public Void visitDeclared(DeclaredType t, Types types) {
 764                 t.asElement().getKind(); // ensure class exists
 765                 for (TypeMirror st: types.directSupertypes(t))
 766                     visit(st, types);
 767                 return null;
 768             }
 769         };
 770 
 771         private Gen g;
 772         private Util.Exit exit;
 773     }
 774 }