1 /*
2 * Copyright (c) 2002, 2013, 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 and invokes javadoc to execute those commands.
83 *
721 allClasses.add(c);
722 getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
723 }
724 }
725
726 // 4942232:
727 // check that classes exist for all the parameters of native methods
728 private void checkMethodParameters(Set<TypeElement> classes) {
729 Types types = processingEnv.getTypeUtils();
730 for (TypeElement te: classes) {
731 for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
732 for (VariableElement ve: ee.getParameters()) {
733 TypeMirror tm = ve.asType();
734 checkMethodParametersVisitor.visit(tm, types);
735 }
736 }
737 }
738 }
739
740 private TypeVisitor<Void,Types> checkMethodParametersVisitor =
741 new SimpleTypeVisitor8<Void,Types>() {
742 @Override
743 public Void visitArray(ArrayType t, Types types) {
744 visit(t.getComponentType(), types);
745 return null;
746 }
747 @Override
748 public Void visitDeclared(DeclaredType t, Types types) {
749 t.asElement().getKind(); // ensure class exists
750 for (TypeMirror st: types.directSupertypes(t))
751 visit(st, types);
752 return null;
753 }
754 };
755
756 private Gen g;
757 private Util.Exit exit;
758 }
759 }
|
1 /*
2 * Copyright (c) 2002, 2014, 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.SimpleTypeVisitor9;
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 and invokes javadoc to execute those commands.
83 *
721 allClasses.add(c);
722 getAllClasses0(ElementFilter.typesIn(c.getEnclosedElements()), allClasses);
723 }
724 }
725
726 // 4942232:
727 // check that classes exist for all the parameters of native methods
728 private void checkMethodParameters(Set<TypeElement> classes) {
729 Types types = processingEnv.getTypeUtils();
730 for (TypeElement te: classes) {
731 for (ExecutableElement ee: ElementFilter.methodsIn(te.getEnclosedElements())) {
732 for (VariableElement ve: ee.getParameters()) {
733 TypeMirror tm = ve.asType();
734 checkMethodParametersVisitor.visit(tm, types);
735 }
736 }
737 }
738 }
739
740 private TypeVisitor<Void,Types> checkMethodParametersVisitor =
741 new SimpleTypeVisitor9<Void,Types>() {
742 @Override
743 public Void visitArray(ArrayType t, Types types) {
744 visit(t.getComponentType(), types);
745 return null;
746 }
747 @Override
748 public Void visitDeclared(DeclaredType t, Types types) {
749 t.asElement().getKind(); // ensure class exists
750 for (TypeMirror st: types.directSupertypes(t))
751 visit(st, types);
752 return null;
753 }
754 };
755
756 private Gen g;
757 private Util.Exit exit;
758 }
759 }
|