From 5512bf181aaf344f6df8a3060c346d84829ac7cc Mon Sep 17 00:00:00 2001 From: Travis Burtrum Date: Fri, 7 Sep 2012 14:10:35 -0400 Subject: [PATCH] Initial Commit, version 0.1 --- .gitignore | 3 + apt-mirror-api/pom.xml | 54 +++ .../sun/mirror/apt/AnnotationProcessor.java | 71 ++++ .../apt/AnnotationProcessorEnvironment.java | 183 ++++++++++ .../apt/AnnotationProcessorFactory.java | 110 ++++++ .../apt/AnnotationProcessorListener.java | 43 +++ .../sun/mirror/apt/AnnotationProcessors.java | 132 +++++++ .../main/java/com/sun/mirror/apt/Filer.java | 161 +++++++++ .../java/com/sun/mirror/apt/Messager.java | 101 ++++++ .../sun/mirror/apt/RoundCompleteEvent.java | 75 ++++ .../sun/mirror/apt/RoundCompleteListener.java | 49 +++ .../java/com/sun/mirror/apt/RoundState.java | 66 ++++ .../main/java/com/sun/mirror/apt/package.html | 46 +++ .../mirror/declaration/AnnotationMirror.java | 89 +++++ .../AnnotationTypeDeclaration.java | 58 ++++ .../AnnotationTypeElementDeclaration.java | 58 ++++ .../mirror/declaration/AnnotationValue.java | 83 +++++ .../mirror/declaration/ClassDeclaration.java | 88 +++++ .../declaration/ConstructorDeclaration.java | 45 +++ .../sun/mirror/declaration/Declaration.java | 168 +++++++++ .../declaration/EnumConstantDeclaration.java | 49 +++ .../mirror/declaration/EnumDeclaration.java | 56 +++ .../declaration/ExecutableDeclaration.java | 86 +++++ .../mirror/declaration/FieldDeclaration.java | 80 +++++ .../declaration/InterfaceDeclaration.java | 57 +++ .../mirror/declaration/MemberDeclaration.java | 58 ++++ .../mirror/declaration/MethodDeclaration.java | 60 ++++ .../com/sun/mirror/declaration/Modifier.java | 101 ++++++ .../declaration/PackageDeclaration.java | 98 ++++++ .../declaration/ParameterDeclaration.java | 55 +++ .../mirror/declaration/TypeDeclaration.java | 142 ++++++++ .../declaration/TypeParameterDeclaration.java | 70 ++++ .../com/sun/mirror/declaration/package.html | 48 +++ .../main/java/com/sun/mirror/overview.html | 117 +++++++ .../com/sun/mirror/type/AnnotationType.java | 53 +++ .../java/com/sun/mirror/type/ArrayType.java | 54 +++ .../java/com/sun/mirror/type/ClassType.java | 75 ++++ .../com/sun/mirror/type/DeclaredType.java | 112 ++++++ .../java/com/sun/mirror/type/EnumType.java | 53 +++ .../com/sun/mirror/type/InterfaceType.java | 60 ++++ .../mirror/type/MirroredTypeException.java | 87 +++++ .../mirror/type/MirroredTypesException.java | 97 ++++++ .../com/sun/mirror/type/PrimitiveType.java | 84 +++++ .../com/sun/mirror/type/ReferenceType.java | 46 +++ .../java/com/sun/mirror/type/TypeMirror.java | 85 +++++ .../com/sun/mirror/type/TypeVariable.java | 58 ++++ .../java/com/sun/mirror/type/VoidType.java | 49 +++ .../com/sun/mirror/type/WildcardType.java | 75 ++++ .../java/com/sun/mirror/type/package.html | 46 +++ .../sun/mirror/util/DeclarationFilter.java | 317 +++++++++++++++++ .../sun/mirror/util/DeclarationScanner.java | 268 ++++++++++++++ .../sun/mirror/util/DeclarationVisitor.java | 166 +++++++++ .../sun/mirror/util/DeclarationVisitors.java | 103 ++++++ .../com/sun/mirror/util/Declarations.java | 70 ++++ .../mirror/util/SimpleDeclarationVisitor.java | 234 +++++++++++++ .../sun/mirror/util/SimpleTypeVisitor.java | 189 ++++++++++ .../mirror/util/SourceOrderDeclScanner.java | 277 +++++++++++++++ .../com/sun/mirror/util/SourcePosition.java | 73 ++++ .../java/com/sun/mirror/util/TypeVisitor.java | 138 ++++++++ .../main/java/com/sun/mirror/util/Types.java | 190 ++++++++++ .../java/com/sun/mirror/util/package.html | 46 +++ apt-processor/pom.xml | 70 ++++ .../moparisthebest/mirror/AptProcessor.java | 149 ++++++++ .../javax.annotation.processing.Processor | 6 + core/pom.xml | 38 ++ ...ConvertAnnotationProcessorEnvironment.java | 328 ++++++++++++++++++ .../ConvertAnnotationProcessorFactory.java | 214 ++++++++++++ .../mirror/apt/ConvertFiler.java | 120 +++++++ .../mirror/apt/ConvertMessager.java | 91 +++++ .../mirror/convert/Convertable.java | 148 ++++++++ .../mirror/convert/ConvertableIface.java | 25 ++ .../mirror/convert/ElementFilter.java | 49 +++ .../mirror/convert/InstanceFilter.java | 45 +++ .../declaration/ConvertAnnotationMirror.java | 115 ++++++ .../ConvertAnnotationTypeDeclaration.java | 60 ++++ ...nvertAnnotationTypeElementDeclaration.java | 47 +++ .../declaration/ConvertAnnotationValue.java | 134 +++++++ .../declaration/ConvertClassDeclaration.java | 60 ++++ .../ConvertConstructorDeclaration.java | 29 ++ .../declaration/ConvertDeclaration.java | 186 ++++++++++ .../ConvertEnumConstantDeclaration.java | 37 ++ .../declaration/ConvertEnumDeclaration.java | 38 ++ .../ConvertExecutableDeclaration.java | 61 ++++ .../declaration/ConvertFieldDeclaration.java | 77 ++++ .../ConvertInterfaceDeclaration.java | 29 ++ .../declaration/ConvertMemberDeclaration.java | 46 +++ .../declaration/ConvertMethodDeclaration.java | 39 +++ .../ConvertPackageDeclaration.java | 78 +++++ .../ConvertParameterDeclaration.java | 40 +++ .../declaration/ConvertTypeDeclaration.java | 83 +++++ .../ConvertTypeParameterDeclaration.java | 47 +++ .../com/moparisthebest/mirror/log/Debug.java | 93 +++++ .../mirror/type/ConvertAnnotationType.java | 37 ++ .../mirror/type/ConvertArrayType.java | 36 ++ .../mirror/type/ConvertClassType.java | 52 +++ .../mirror/type/ConvertDeclaredType.java | 62 ++++ .../mirror/type/ConvertEnumType.java | 38 ++ .../mirror/type/ConvertInterfaceType.java | 37 ++ .../type/ConvertMirroredTypeException.java | 29 ++ .../type/ConvertMirroredTypesException.java | 29 ++ .../mirror/type/ConvertPrimitiveType.java | 36 ++ .../mirror/type/ConvertReferenceType.java | 25 ++ .../mirror/type/ConvertTypeMirror.java | 151 ++++++++ .../mirror/type/ConvertTypeVariable.java | 39 +++ .../mirror/type/ConvertVoidType.java | 27 ++ .../mirror/type/ConvertWildcardType.java | 46 +++ .../mirror/util/ConvertDeclarations.java | 48 +++ .../mirror/util/ConvertSourcePosition.java | 170 +++++++++ .../mirror/util/ConvertTypes.java | 108 ++++++ extra/Test.java | 75 ++++ extra/compile.sh | 119 +++++++ extra/declaration.txt | 25 ++ extra/type.txt | 20 ++ netui-compiler-test/pom.xml | 118 +++++++ .../BackingControlsController.java | 30 ++ .../java/backingControls/TestControl.java | 27 ++ .../src/main/java/backingControls/page1.java | 27 ++ .../backingControls/TestControlImpl.jcs | 21 ++ .../src/test/java/AptGenerationTest.java | 99 ++++++ netui-compiler/pom.xml | 84 +++++ .../java6/ControlAnnotationProcessor.java | 29 ++ .../ControlClientAnnotationProcessor.java | 29 ++ .../ControlMemberTypeAnnotationProcessor.java | 29 ++ .../ControlSecondaryAnnotationProcessor.java | 29 ++ .../java6/PageFlowAnnotationProcessor.java | 29 ++ .../javax.annotation.processing.Processor | 8 + pom.xml | 119 +++++++ readme.txt | 32 ++ 128 files changed, 10366 insertions(+) create mode 100644 .gitignore create mode 100755 apt-mirror-api/pom.xml create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessor.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorEnvironment.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorFactory.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorListener.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessors.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/Filer.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/Messager.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteEvent.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteListener.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundState.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/apt/package.html create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationMirror.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeElementDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationValue.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/ClassDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/ConstructorDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/Declaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumConstantDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/ExecutableDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/FieldDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/InterfaceDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/MemberDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/MethodDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/Modifier.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/PackageDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/ParameterDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeParameterDeclaration.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/declaration/package.html create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/overview.html create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/AnnotationType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/ArrayType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/ClassType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/DeclaredType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/EnumType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/InterfaceType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypeException.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypesException.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/PrimitiveType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/ReferenceType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/TypeMirror.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/TypeVariable.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/VoidType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/WildcardType.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/type/package.html create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationFilter.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationScanner.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitor.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitors.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/Declarations.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleDeclarationVisitor.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleTypeVisitor.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/SourceOrderDeclScanner.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/SourcePosition.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/TypeVisitor.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/Types.java create mode 100755 apt-mirror-api/src/main/java/com/sun/mirror/util/package.html create mode 100755 apt-processor/pom.xml create mode 100755 apt-processor/src/main/java/com/moparisthebest/mirror/AptProcessor.java create mode 100755 apt-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor create mode 100755 core/pom.xml create mode 100755 core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorEnvironment.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorFactory.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/apt/ConvertFiler.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/apt/ConvertMessager.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/convert/Convertable.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/convert/ConvertableIface.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/convert/ElementFilter.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/convert/InstanceFilter.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationMirror.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeElementDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationValue.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertClassDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertConstructorDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertEnumConstantDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertEnumDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertExecutableDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertFieldDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertInterfaceDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertMemberDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertMethodDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertPackageDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertParameterDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertTypeDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/declaration/ConvertTypeParameterDeclaration.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/log/Debug.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertAnnotationType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertArrayType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertClassType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertDeclaredType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertEnumType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertInterfaceType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertMirroredTypeException.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertMirroredTypesException.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertPrimitiveType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertReferenceType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertTypeMirror.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertTypeVariable.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertVoidType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/type/ConvertWildcardType.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/util/ConvertDeclarations.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/util/ConvertSourcePosition.java create mode 100755 core/src/main/java/com/moparisthebest/mirror/util/ConvertTypes.java create mode 100755 extra/Test.java create mode 100755 extra/compile.sh create mode 100755 extra/declaration.txt create mode 100755 extra/type.txt create mode 100755 netui-compiler-test/pom.xml create mode 100755 netui-compiler-test/src/main/java/backingControls/BackingControlsController.java create mode 100755 netui-compiler-test/src/main/java/backingControls/TestControl.java create mode 100755 netui-compiler-test/src/main/java/backingControls/page1.java create mode 100755 netui-compiler-test/src/main/resources/backingControls/TestControlImpl.jcs create mode 100755 netui-compiler-test/src/test/java/AptGenerationTest.java create mode 100755 netui-compiler/pom.xml create mode 100755 netui-compiler/src/main/java/org/apache/beehive/controls/runtime/generator/java6/ControlAnnotationProcessor.java create mode 100755 netui-compiler/src/main/java/org/apache/beehive/controls/runtime/generator/java6/ControlClientAnnotationProcessor.java create mode 100755 netui-compiler/src/main/java/org/apache/beehive/controls/runtime/generator/java6/ControlMemberTypeAnnotationProcessor.java create mode 100755 netui-compiler/src/main/java/org/apache/beehive/controls/runtime/generator/java6/ControlSecondaryAnnotationProcessor.java create mode 100755 netui-compiler/src/main/java/org/apache/beehive/netui/compiler/java6/PageFlowAnnotationProcessor.java create mode 100755 netui-compiler/src/main/resources/META-INF/services/javax.annotation.processing.Processor create mode 100755 pom.xml create mode 100644 readme.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91259d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +*.iml +*/target/ diff --git a/apt-mirror-api/pom.xml b/apt-mirror-api/pom.xml new file mode 100755 index 0000000..0c65596 --- /dev/null +++ b/apt-mirror-api/pom.xml @@ -0,0 +1,54 @@ + + + + + + com.moparisthebest.aptIn16 + aptIn16 + 0.1 + + 4.0.0 + apt-mirror-api + 1.0 + apt-mirror-api + + + + default-tools.jar + + + java.vendor + Sun Microsystems Inc. + + + + + com.sun + tools + 1.6 + system + ${java.home}/../lib/tools.jar + + + + + + \ No newline at end of file diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessor.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessor.java new file mode 100755 index 0000000..a540fe7 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessor.java @@ -0,0 +1,71 @@ +/* + * @(#)AnnotationProcessor.java 1.2 04/02/10 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + + +import java.io.IOException; +import java.util.Collection; + + +/** + * An annotation processor, used to examine and process the + * annotations of program elements. An annotation processor may, + * for example, create new source files and XML documents to be used + * in conjunction with the original code. + *

+ *

An annotation processor is constructed by a + * {@linkplain AnnotationProcessorFactory factory}, which provides it with an + * {@linkplain AnnotationProcessorEnvironment environment} that + * encapsulates the state it needs. + * Messages regarding warnings and errors encountered during processing + * should be directed to the environment's {@link Messager}, + * and new files may be created using the environment's {@link Filer}. + *

+ *

Each annotation processor is created to process annotations + * of a particular annotation type or set of annotation types. + * It may use its environment to find the program elements with + * annotations of those types. It may freely examine any other program + * elements in the course of its processing. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/02/10 + * @since 1.5 + */ + +public interface AnnotationProcessor { + + /** + * Process all program elements supported by this annotation processor. + */ + void process(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorEnvironment.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorEnvironment.java new file mode 100755 index 0000000..0c14a00 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorEnvironment.java @@ -0,0 +1,183 @@ +/* + * @(#)AnnotationProcessorEnvironment.java 1.7 04/07/19 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + + +import java.util.Collection; +import java.util.Map; + +import com.sun.mirror.declaration.*; +import com.sun.mirror.util.*; + + +/** + * The environment encapsulating the state needed by an annotation processor. + * An annotation processing tool makes this environment available + * to all annotation processors. + *

+ *

When an annotation processing tool is invoked, it is given a + * set of type declarations on which to operate. These + * are refered to as the specified types. + * The type declarations said to be included in this invocation + * consist of the specified types and any types nested within them. + *

+ *

{@link DeclarationFilter} + * provides a simple way to select just the items of interest + * when a method returns a collection of declarations. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.7 04/07/19 + * @since 1.5 + */ + +public interface AnnotationProcessorEnvironment { + + /** + * Returns the options passed to the annotation processing tool. + * Options are returned in the form of a map from option name + * (such as "-encoding") to option value. + * For an option with no value (such as "-help"), the + * corresponding value in the map is null. + *

+ *

Options beginning with "-A" are processor-specific. + * Such options are unrecognized by the tool, but intended to be used by + * some annotation processor. + * + * @return the options passed to the tool + */ + Map getOptions(); + + /** + * Returns the messager used to report errors, warnings, and other + * notices. + * + * @return the messager + */ + Messager getMessager(); + + /** + * Returns the filer used to create new source, class, or auxiliary + * files. + * + * @return the filer + */ + Filer getFiler(); + + + /** + * Returns the declarations of the types specified when the + * annotation processing tool was invoked. + * + * @return the types specified when the tool was invoked, or an + * empty collection if there were none + */ + Collection getSpecifiedTypeDeclarations(); + + /** + * Returns the declaration of a package given its fully qualified name. + * + * @param name fully qualified package name, or "" for the unnamed package + * @return the declaration of the named package, or null if it cannot + * be found + */ + PackageDeclaration getPackage(String name); + + /** + * Returns the declaration of a type given its fully qualified name. + * + * @param name fully qualified type name + * @return the declaration of the named type, or null if it cannot be + * found + */ + TypeDeclaration getTypeDeclaration(String name); + + /** + * A convenience method that returns the declarations of the types + * {@linkplain AnnotationProcessorEnvironment included} + * in this invocation of the annotation processing tool. + * + * @return the declarations of the types included in this invocation + * of the tool, or an empty collection if there are none + */ + Collection getTypeDeclarations(); + + /** + * Returns the declarations annotated with the given annotation type. + * Only declarations of the types + * {@linkplain AnnotationProcessorEnvironment included} + * in this invocation of the annotation processing tool, or + * declarations of members, parameters, or type parameters + * declared within those, are returned. + * + * @param a annotation type being requested + * @return the declarations annotated with the given annotation type, + * or an empty collection if there are none + */ + Collection getDeclarationsAnnotatedWith( + AnnotationTypeDeclaration a); + + /** + * Returns an implementation of some utility methods for + * operating on declarations. + * + * @return declaration utilities + */ + Declarations getDeclarationUtils(); + + /** + * Returns an implementation of some utility methods for + * operating on types. + * + * @return type utilities + */ + Types getTypeUtils(); + + /** + * Add a listener. If the listener is currently registered to listen, + * adding it again will have no effect. + * + * @param listener The listener to add. + * @throws NullPointerException if the listener is null + */ + void addListener(AnnotationProcessorListener listener); + + + /** + * Remove a listener. If the listener is not currently listening, + * the method call does nothing. + * + * @param listener The listener to remove. + * @throws NullPointerException if the listener is null + */ + void removeListener(AnnotationProcessorListener listener); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorFactory.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorFactory.java new file mode 100755 index 0000000..4b067b9 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorFactory.java @@ -0,0 +1,110 @@ +/* + * @(#)AnnotationProcessorFactory.java 1.9 04/07/13 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + + +import java.util.Collection; +import java.util.Set; + +import com.sun.mirror.declaration.AnnotationTypeDeclaration; + + +/** + * A factory for creating annotation processors. + * Each factory is responsible for creating processors for one or more + * annotation types. + * The factory is said to support these types. + *

+ *

Each implementation of an AnnotationProcessorFactory + * must provide a public no-argument constructor to be used by tools to + * instantiate the factory. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.9 04/07/13 + * @since 1.5 + */ + +public interface AnnotationProcessorFactory { + + /** + * Returns the options recognized by this factory or by any of the + * processors it may create. + * Only {@linkplain AnnotationProcessorEnvironment#getOptions() + * processor-specific} options are included, each of which begins + * with "-A". For example, if this factory recognizes + * options such as -Adebug -Aloglevel=3, it will + * return the strings "-Adebug" and "-Aloglevel". + *

+ *

A tool might use this information to determine if any + * options provided by a user are unrecognized by any processor, + * in which case it may wish to report an error. + * + * @return the options recognized by this factory or by any of the + * processors it may create, or an empty collection if none + */ + Collection supportedOptions(); + + /** + * Returns the names of the annotation types supported by this factory. + * An element of the result may be the canonical (fully qualified) name + * of a supported annotation type. Alternately it may be of the form + * "name.*" + * representing the set of all annotation types + * with canonical names beginning with "name." + * Finally, "*" by itself represents the set of all + * annotation types. + * + * @return the names of the annotation types supported by this factory + */ + Collection supportedAnnotationTypes(); + + /** + * Returns an annotation processor for a set of annotation + * types. The set will be empty if the factory supports + * "*" and the specified type declarations have + * no annotations. Note that the set of annotation types may be + * empty for other reasons, such as giving the factory an + * opportunity to register a listener. An + * AnnotationProcessorFactory must gracefully handle an + * empty set of annotations; an appropriate response to an empty + * set will often be returning {@link AnnotationProcessors#NO_OP}. + * + * @param atds type declarations of the annotation types to be processed + * @param env environment to use during processing + * @return an annotation processor for the given annotation types, + * or null if the types are not supported or the + * processor cannot be created + */ + AnnotationProcessor getProcessorFor(Set atds, + AnnotationProcessorEnvironment env); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorListener.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorListener.java new file mode 100755 index 0000000..4553518 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessorListener.java @@ -0,0 +1,43 @@ +/* + * @(#)AnnotationProcessorListener.java 1.1 04/06/25 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + +/** + * Superinterface for all annotation processor event listeners. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/06/25 + * @since 1.5 + */ +public interface AnnotationProcessorListener extends java.util.EventListener { +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessors.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessors.java new file mode 100755 index 0000000..5b37de2 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/AnnotationProcessors.java @@ -0,0 +1,132 @@ +/* + * @(#)AnnotationProcessors.java 1.2 04/06/21 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + +import com.sun.mirror.apt.*; + +import java.util.*; + +/** + * Utilities to create specialized annotation processors. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @since 1.5 + */ +public class AnnotationProcessors { + static class NoOpAP implements AnnotationProcessor { + NoOpAP() { + } + + public void process() { + } + } + + /** + * Combines multiple annotation processors into a simple composite + * processor. + * The composite processor functions by invoking each of its component + * processors in sequence. + */ + static class CompositeAnnotationProcessor implements AnnotationProcessor { + + private List aps = + new LinkedList(); + + /** + * Constructs a new composite annotation processor. + * + * @param aps the component annotation processors + */ + public CompositeAnnotationProcessor(Collection aps) { + this.aps.addAll(aps); + } + + /** + * Constructs a new composite annotation processor. + * + * @param aps the component annotation processors + */ + public CompositeAnnotationProcessor(AnnotationProcessor... aps) { + for (AnnotationProcessor ap : aps) + this.aps.add(ap); + } + + /** + * Invokes the process method of each component processor, + * in the order in which the processors were passed to the constructor. + */ + public void process() { + for (AnnotationProcessor ap : aps) + ap.process(); + } + } + + + /** + * An annotation processor that does nothing and has no state. + * May be used multiple times. + * + * @since 1.5 + */ + public final static AnnotationProcessor NO_OP = new NoOpAP(); + + /** + * Constructs a new composite annotation processor. A composite + * annotation processor combines multiple annotation processors + * into one and functions by invoking each of its component + * processors' process methods in sequence. + * + * @param aps The processors to create a composite of + * @since 1.5 + */ + public static AnnotationProcessor getCompositeAnnotationProcessor(AnnotationProcessor... aps) { + return new CompositeAnnotationProcessor(aps); + } + + /** + * Constructs a new composite annotation processor. A composite + * annotation processor combines multiple annotation processors + * into one and functions by invoking each of its component + * processors' process methods in the sequence the processors are + * returned by the collection's iterator. + * + * @param aps A collection of processors to create a composite of + * @since 1.5 + */ + public static AnnotationProcessor getCompositeAnnotationProcessor(Collection aps) { + return new CompositeAnnotationProcessor(aps); + } +} + + + diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/Filer.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/Filer.java new file mode 100755 index 0000000..4131e5f --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/Filer.java @@ -0,0 +1,161 @@ +/* + * @(#)Filer.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + + +import java.io.*; + + +/** + * This interface supports the creation of new files by an + * annotation processor. + * Files created in this way will be known to the annotation processing + * tool implementing this interface, better enabling the tool to manage them. + * Four kinds of files are distinguished: + * source files, class files, other text files, and other binary files. + * The latter two are collectively referred to as auxiliary files. + *

+ *

There are two distinguished locations (subtrees within the + * file system) where newly created files are placed: + * one for new source files, and one for new class files. + * (These might be specified on a tool's command line, for example, + * using flags such as -s and -d.) + * Auxiliary files may be created in either location. + *

+ *

During each run of an annotation processing tool, a file + * with a given pathname may be created only once. If that file already + * exists before the first attempt to create it, the old contents will + * be deleted. Any subsequent attempt to create the same file during + * a run will fail. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface Filer { + + /** + * Creates a new source file and returns a writer for it. + * The file's name and path (relative to the root of all newly created + * source files) is based on the type to be declared in that file. + * If more than one type is being declared, the name of the principal + * top-level type (the public one, for example) should be used. + *

+ *

The {@linkplain java.nio.charset.Charset charset} used to + * encode the file is determined by the implementation. + * An annotation processing tool may have an -encoding + * flag or the like for specifying this. It will typically use + * the platform's default encoding if none is specified. + * + * @param name canonical (fully qualified) name of the principal type + * being declared in this file + * @return a writer for the new file + * @throws IOException if the file cannot be created + */ + PrintWriter createSourceFile(String name) throws IOException; + + /** + * Creates a new class file, and returns a stream for writing to it. + * The file's name and path (relative to the root of all newly created + * class files) is based on the name of the type being written. + * + * @param name canonical (fully qualified) name of the type being written + * @return a stream for writing to the new file + * @throws IOException if the file cannot be created + */ + OutputStream createClassFile(String name) throws IOException; + + /** + * Creates a new text file, and returns a writer for it. + * The file is located along with either the + * newly created source or newly created binary files. It may be + * named relative to some package (as are source and binary files), + * and from there by an arbitrary pathname. In a loose sense, the + * pathname of the new file will be the concatenation of + * loc, pkg, and relPath. + *

+ *

A {@linkplain java.nio.charset.Charset charset} for + * encoding the file may be provided. If none is given, the + * charset used to encode source files + * (see {@link #createSourceFile(String)}) will be used. + * + * @param loc location of the new file + * @param pkg package relative to which the file should be named, + * or the empty string if none + * @param relPath final pathname components of the file + * @param charsetName the name of the charset to use, or null if none + * is being explicitly specified + * @return a writer for the new file + * @throws IOException if the file cannot be created + */ + PrintWriter createTextFile(Location loc, + String pkg, + File relPath, + String charsetName) throws IOException; + + /** + * Creates a new binary file, and returns a stream for writing to it. + * The file is located along with either the + * newly created source or newly created binary files. It may be + * named relative to some package (as are source and binary files), + * and from there by an arbitrary pathname. In a loose sense, the + * pathname of the new file will be the concatenation of + * loc, pkg, and relPath. + * + * @param loc location of the new file + * @param pkg package relative to which the file should be named, + * or the empty string if none + * @param relPath final pathname components of the file + * @return a stream for writing to the new file + * @throws IOException if the file cannot be created + */ + OutputStream createBinaryFile(Location loc, + String pkg, + File relPath) throws IOException; + + + /** + * Locations (subtrees within the file system) where new files are created. + */ + enum Location { + /** + * The location of new source files. + */ + SOURCE_TREE, + /** + * The location of new class files. + */ + CLASS_TREE + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/Messager.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/Messager.java new file mode 100755 index 0000000..a54567a --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/Messager.java @@ -0,0 +1,101 @@ +/* + * @(#)Messager.java 1.2 04/07/27 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + + +import com.sun.mirror.util.SourcePosition; + + +/** + * A Messager provides the way for + * an annotation processor to report error messages, warnings, and + * other notices. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/07/27 + * @since 1.5 + */ + +public interface Messager { + + /** + * Prints an error message. + * Equivalent to printError(null, msg). + * + * @param msg the message, or an empty string if none + */ + void printError(String msg); + + /** + * Prints an error message. + * + * @param pos the position where the error occured, or null if it is + * unknown or not applicable + * @param msg the message, or an empty string if none + */ + void printError(SourcePosition pos, String msg); + + /** + * Prints a warning message. + * Equivalent to printWarning(null, msg). + * + * @param msg the message, or an empty string if none + */ + void printWarning(String msg); + + /** + * Prints a warning message. + * + * @param pos the position where the warning occured, or null if it is + * unknown or not applicable + * @param msg the message, or an empty string if none + */ + void printWarning(SourcePosition pos, String msg); + + /** + * Prints a notice. + * Equivalent to printNotice(null, msg). + * + * @param msg the message, or an empty string if none + */ + void printNotice(String msg); + + /** + * Prints a notice. + * + * @param pos the position where the noticed occured, or null if it is + * unknown or not applicable + * @param msg the message, or an empty string if none + */ + void printNotice(SourcePosition pos, String msg); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteEvent.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteEvent.java new file mode 100755 index 0000000..d1390df --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteEvent.java @@ -0,0 +1,75 @@ +/* + * @(#)RoundCompleteEvent.java 1.2 04/07/19 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + +/** + * Event for the completion of a round of annotation processing. + *

+ *

While this class extends the serializable EventObject, it + * cannot meaningfully be serialized because all of the annotation + * processing tool's internal state would potentially be needed. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/07/19 + * @since 1.5 + */ +public abstract class RoundCompleteEvent extends java.util.EventObject { + private RoundState rs; + + /** + * The current AnnotationProcessorEnvironment is regarded + * as the source of events. + * + * @param source The source of events + * @param rs The state of the round + */ + protected RoundCompleteEvent(AnnotationProcessorEnvironment source, + RoundState rs) { + super(source); + this.rs = rs; + } + + /** + * Return round state. + */ + public RoundState getRoundState() { + return rs; + } + + /** + * Return source. + */ + public AnnotationProcessorEnvironment getSource() { + return (AnnotationProcessorEnvironment) super.getSource(); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteListener.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteListener.java new file mode 100755 index 0000000..e650c02 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundCompleteListener.java @@ -0,0 +1,49 @@ +/* + * @(#)RoundCompleteListener.java 1.1 04/06/25 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + +/** + * Listener for the completion of a round of annotation processing. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/06/25 + * @since 1.5 + */ +public interface RoundCompleteListener extends AnnotationProcessorListener { + /** + * Invoked after all processors for a round have run to completion. + * + * @param event An event for round completion + */ + void roundComplete(RoundCompleteEvent event); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundState.java b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundState.java new file mode 100755 index 0000000..9060d9d --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/RoundState.java @@ -0,0 +1,66 @@ +/* + * @(#)RoundState.java 1.1 04/06/25 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.apt; + +/** + * Represents the status of a completed round of annotation processing. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/06/25 + * @since 1.5 + */ +public interface RoundState { + /** + * Returns true if this was the last round of annotation + * processing; returns false if there will be a subsequent round. + */ + boolean finalRound(); + + /** + * Returns true if an error was raised in this round of processing; + * returns false otherwise. + */ + boolean errorRaised(); + + /** + * Returns true if new source files were created in this round of + * processing; returns false otherwise. + */ + boolean sourceFilesCreated(); + + /** + * Returns true if new class files were created in this round of + * processing; returns false otherwise. + */ + boolean classFilesCreated(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/apt/package.html b/apt-mirror-api/src/main/java/com/sun/mirror/apt/package.html new file mode 100755 index 0000000..9f5c003 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/apt/package.html @@ -0,0 +1,46 @@ + + + + + + + + +Classes used to communicate information between +{@linkplain com.sun.mirror.apt.AnnotationProcessor annotation processors} +and an annotation processing tool. + +

Note that the apt tool and its associated APIs may be + changed or superseded in future j2se releases. + + @since 1.5 + + diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationMirror.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationMirror.java new file mode 100755 index 0000000..61ef386 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationMirror.java @@ -0,0 +1,89 @@ +/* + * @(#)AnnotationMirror.java 1.5 04/07/16 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + +import java.util.Map; + +import com.sun.mirror.type.AnnotationType; +import com.sun.mirror.util.SourcePosition; + + +/** + * Represents an annotation. An annotation associates a value with + * each element of an annotation type. + *

+ *

Annotations should not be compared using reference-equality + * ("=="). There is no guarantee that any particular + * annotation will always be represented by the same object. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.5 04/07/16 + * @since 1.5 + */ + +public interface AnnotationMirror { + + /** + * Returns the annotation type of this annotation. + * + * @return the annotation type of this annotation + */ + AnnotationType getAnnotationType(); + + /** + * Returns the source position of the beginning of this annotation. + * Returns null if the position is unknown or not applicable. + *

+ *

This source position is intended for use in providing diagnostics, + * and indicates only approximately where an annotation begins. + * + * @return the source position of the beginning of this annotation or + * null if the position is unknown or not applicable + */ + SourcePosition getPosition(); + + /** + * Returns this annotation's elements and their values. + * This is returned in the form of a map that associates elements + * with their corresponding values. + * Only those elements and values explicitly present in the + * annotation are included, not those that are implicitly assuming + * their default values. + * The order of the map matches the order in which the + * elements appear in the annotation's source. + * + * @return this annotation's elements and their values, + * or an empty map if there are none + */ + Map getElementValues(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeDeclaration.java new file mode 100755 index 0000000..9e0769e --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeDeclaration.java @@ -0,0 +1,58 @@ +/* + * @(#)AnnotationTypeDeclaration.java 1.2 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + + +/** + * Represents the declaration of an annotation type. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/04/20 + * @since 1.5 + */ + +public interface AnnotationTypeDeclaration extends InterfaceDeclaration { + + /** + * Returns the annotation type elements of this annotation type. + * These are the methods that are directly declared in the type's + * declaration. + * + * @return the annotation type elements of this annotation type, + * or an empty collection if there are none + */ + Collection getMethods(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeElementDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeElementDeclaration.java new file mode 100755 index 0000000..78c52b9 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationTypeElementDeclaration.java @@ -0,0 +1,58 @@ +/* + * @(#)AnnotationTypeElementDeclaration.java 1.3 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +/** + * Represents an element of an annotation type. + * + * @author Joe Darcy + * @author Scott Seligman + * @version 1.3 04/04/20 + * @since 1.5 + */ + +public interface AnnotationTypeElementDeclaration extends MethodDeclaration { + + /** + * Returns the default value of this element. + * + * @return the default value of this element, or null if this element + * has no default. + */ + AnnotationValue getDefaultValue(); + + /** + * {@inheritDoc} + */ + AnnotationTypeDeclaration getDeclaringType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationValue.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationValue.java new file mode 100755 index 0000000..53dc31c --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/AnnotationValue.java @@ -0,0 +1,83 @@ +/* + * @(#)AnnotationValue.java 1.6 04/07/19 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + +import com.sun.mirror.util.SourcePosition; + +/** + * Represents a value of an annotation type element. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.6 04/07/19 + * @since 1.5 + */ + +public interface AnnotationValue { + + /** + * Returns the value. + * The result has one of the following types: + *

+ * + * @return the value + */ + Object getValue(); + + /** + * Returns the source position of the beginning of this annotation value. + * Returns null if the position is unknown or not applicable. + *

+ *

This source position is intended for use in providing diagnostics, + * and indicates only approximately where an annotation value begins. + * + * @return the source position of the beginning of this annotation value or + * null if the position is unknown or not applicable + */ + SourcePosition getPosition(); + + /** + * Returns a string representation of this value. + * This is returned in a form suitable for representing this value + * in the source code of an annotation. + * + * @return a string representation of this value + */ + String toString(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ClassDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ClassDeclaration.java new file mode 100755 index 0000000..f1e04fc --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ClassDeclaration.java @@ -0,0 +1,88 @@ +/* + * @(#)ClassDeclaration.java 1.3 04/02/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + +import com.sun.mirror.type.ClassType; + + +/** + * Represents the declaration of a class. + * For the declaration of an interface, see {@link InterfaceDeclaration}. + * Provides access to information about the class, its members, and + * its constructors. + * Note that an {@linkplain EnumDeclaration enum} is a kind of class. + *

+ *

While a ClassDeclaration represents the declaration + * of a class, a {@link ClassType} represents a class type. + * See {@link TypeDeclaration} for more on this distinction. + *

+ *

{@link com.sun.mirror.util.DeclarationFilter} + * provides a simple way to select just the items of interest + * when a method returns a collection of declarations. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.3 04/02/20 + * @see ClassType + * @since 1.5 + */ + +public interface ClassDeclaration extends TypeDeclaration { + + /** + * Returns the class type directly extended by this class. + * The only class with no superclass is java.lang.Object, + * for which this method returns null. + * + * @return the class type directly extended by this class, or null + * if there is none + */ + ClassType getSuperclass(); + + /** + * Returns the constructors of this class. + * This includes the default constructor if this class has + * no constructors explicitly declared. + * + * @return the constructors of this class + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getConstructors(); + + /** + * {@inheritDoc} + */ + Collection getMethods(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ConstructorDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ConstructorDeclaration.java new file mode 100755 index 0000000..818b3aa --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ConstructorDeclaration.java @@ -0,0 +1,45 @@ +/* + * @(#)ConstructorDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +/** + * Represents a constructor of a class or interface. + * + * @author Joe Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface ConstructorDeclaration extends ExecutableDeclaration { +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Declaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Declaration.java new file mode 100755 index 0000000..fc16edb --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Declaration.java @@ -0,0 +1,168 @@ +/* + * @(#)Declaration.java 1.6 04/07/16 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.lang.annotation.Annotation; +import java.util.Collection; + +import com.sun.mirror.type.*; +import com.sun.mirror.util.*; + + +/** + * Represents the declaration of a program element such as a package, + * class, or method. Each declaration represents a static, language-level + * construct (and not, for example, a runtime construct of the virtual + * machine), and typically corresponds one-to-one with a particular + * fragment of source code. + *

+ *

Declarations should be compared using the {@link #equals(Object)} + * method. There is no guarantee that any particular declaration will + * always be represented by the same object. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.6 04/07/16 + * @see Declarations + * @see TypeMirror + * @since 1.5 + */ + +public interface Declaration { + + /** + * Tests whether an object represents the same declaration as this. + * + * @param obj the object to be compared with this declaration + * @return true if the specified object represents the same + * declaration as this + */ + boolean equals(Object obj); + + /** + * Returns the text of the documentation ("javadoc") comment of + * this declaration. + * + * @return the documentation comment of this declaration, or null + * if there is none + */ + String getDocComment(); + + /** + * Returns the annotations that are directly present on this declaration. + * + * @return the annotations directly present on this declaration; + * an empty collection if there are none + */ + Collection getAnnotationMirrors(); + + /** + * Returns the annotation of this declaration having the specified + * type. The annotation may be either inherited or directly + * present on this declaration. + *

+ *

The annotation returned by this method could contain an element + * whose value is of type Class. + * This value cannot be returned directly: information necessary to + * locate and load a class (such as the class loader to use) is + * not available, and the class might not be loadable at all. + * Attempting to read a Class object by invoking the relevant + * method on the returned annotation + * will result in a {@link MirroredTypeException}, + * from which the corresponding {@link TypeMirror} may be extracted. + * Similarly, attempting to read a Class[]-valued element + * will result in a {@link MirroredTypesException}. + *

+ *

+ * Note: This method is unlike + * others in this and related interfaces. It operates on run-time + * reflective information -- representations of annotation types + * currently loaded into the VM -- rather than on the mirrored + * representations defined by and used throughout these + * interfaces. It is intended for callers that are written to + * operate on a known, fixed set of annotation types. + *
+ * + * @param the annotation type + * @param annotationType the Class object corresponding to + * the annotation type + * @return the annotation of this declaration having the specified type + * @see #getAnnotationMirrors() + */ + A getAnnotation(Class annotationType); + + /** + * Returns the modifiers of this declaration, excluding annotations. + * Implicit modifiers, such as the public and static + * modifiers of interface members, are included. + * + * @return the modifiers of this declaration in undefined order; + * an empty collection if there are none + */ + Collection getModifiers(); + + /** + * Returns the simple (unqualified) name of this declaration. + * The name of a generic type does not include any reference + * to its formal type parameters. + * For example, the simple name of the interface declaration + * {@code java.util.Set} is "Set". + * If this declaration represents the empty package, an empty + * string is returned. + * If it represents a constructor, the simple name of its + * declaring class is returned. + * + * @return the simple name of this declaration + */ + String getSimpleName(); + + /** + * Returns the source position of the beginning of this declaration. + * Returns null if the position is unknown or not applicable. + *

+ *

This source position is intended for use in providing + * diagnostics, and indicates only approximately where a declaration + * begins. + * + * @return the source position of the beginning of this declaration, + * or null if the position is unknown or not applicable + */ + SourcePosition getPosition(); + + /** + * Applies a visitor to this declaration. + * + * @param v the visitor operating on this declaration + */ + void accept(DeclarationVisitor v); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumConstantDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumConstantDeclaration.java new file mode 100755 index 0000000..edd65f8 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumConstantDeclaration.java @@ -0,0 +1,49 @@ +/* + * @(#)EnumConstantDeclaration.java 1.2 04/03/09 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +/** + * Represents an enum constant declaration. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/03/09 + * @since 1.5 + */ + +public interface EnumConstantDeclaration extends FieldDeclaration { + /** + * {@inheritDoc} + */ + EnumDeclaration getDeclaringType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumDeclaration.java new file mode 100755 index 0000000..c377dc4 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/EnumDeclaration.java @@ -0,0 +1,56 @@ +/* + * @(#)EnumDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + + +/** + * Represents the declaration of an enum type. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface EnumDeclaration extends ClassDeclaration { + + /** + * Returns the enum constants defined for this enum. + * + * @return the enum constants defined for this enum, + * or an empty collection if there are none + */ + Collection getEnumConstants(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ExecutableDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ExecutableDeclaration.java new file mode 100755 index 0000000..6aad0a5 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ExecutableDeclaration.java @@ -0,0 +1,86 @@ +/* + * @(#)ExecutableDeclaration.java 1.2 04/03/08 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + +import com.sun.mirror.type.ReferenceType; + + +/** + * Represents a method or constructor of a class or interface. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/03/08 + * @since 1.5 + */ + +public interface ExecutableDeclaration extends MemberDeclaration { + + /** + * Returns true if this method or constructor accepts a variable + * number of arguments. + * + * @return true if this method or constructor accepts a variable + * number of arguments + */ + boolean isVarArgs(); + + /** + * Returns the formal type parameters of this method or constructor. + * They are returned in declaration order. + * + * @return the formal type parameters of this method or constructor, + * or an empty collection if there are none + */ + Collection getFormalTypeParameters(); + + /** + * Returns the formal parameters of this method or constructor. + * They are returned in declaration order. + * + * @return the formal parameters of this method or constructor, + * or an empty collection if there are none + */ + Collection getParameters(); + + /** + * Returns the exceptions and other throwables listed in this + * method or constructor's throws clause. + * + * @return the exceptions and other throwables listed in the + * throws clause, or an empty collection if there are none + */ + Collection getThrownTypes(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/FieldDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/FieldDeclaration.java new file mode 100755 index 0000000..294fccb --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/FieldDeclaration.java @@ -0,0 +1,80 @@ +/* + * @(#)FieldDeclaration.java 1.2 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import com.sun.mirror.type.TypeMirror; + + +/** + * Represents a field of a type declaration. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/04/20 + * @since 1.5 + */ + +public interface FieldDeclaration extends MemberDeclaration { + + /** + * Returns the type of this field. + * + * @return the type of this field + */ + TypeMirror getType(); + + /** + * Returns the value of this field if this field is a compile-time + * constant. Returns null otherwise. + * The value will be of a primitive type or String. + * If the value is of a primitive type, it is wrapped in the + * appropriate wrapper class (such as {@link Integer}). + * + * @return the value of this field if this field is a compile-time + * constant, or null otherwise + */ + Object getConstantValue(); + + /** + * Returns the text of a constant expression representing the + * value of this field if this field is a compile-time constant. + * Returns null otherwise. + * The value will be of a primitive type or String. + * The text returned is in a form suitable for representing the value + * in source code. + * + * @return the text of a constant expression if this field is a + * compile-time constant, or null otherwise + */ + String getConstantExpression(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/InterfaceDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/InterfaceDeclaration.java new file mode 100755 index 0000000..a9b2d92 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/InterfaceDeclaration.java @@ -0,0 +1,57 @@ +/* + * @(#)InterfaceDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import com.sun.mirror.type.InterfaceType; + + +/** + * Represents the declaration of an interface. + * Provides access to information about the interface and its members. + * Note that an {@linkplain AnnotationTypeDeclaration annotation type} is + * a kind of interface. + *

+ *

While an InterfaceDeclaration represents the + * declaration of an interface, an {@link InterfaceType} + * represents an interface type. + * See {@link TypeDeclaration} for more on this distinction. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @see InterfaceType + * @since 1.5 + */ + +public interface InterfaceDeclaration extends TypeDeclaration { +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MemberDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MemberDeclaration.java new file mode 100755 index 0000000..376f0b2 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MemberDeclaration.java @@ -0,0 +1,58 @@ +/* + * @(#)MemberDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +/** + * Represents a declaration that may be a member or constructor of a declared + * type. This includes fields, constructors, methods, and (since they + * may be nested) declared types themselves. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface MemberDeclaration extends Declaration { + + /** + * Returns the type declaration within which this member or constructor + * is declared. + * If this is the declaration of a top-level type (a non-nested class + * or interface), returns null. + * + * @return the type declaration within which this member or constructor + * is declared, or null if there is none + */ + TypeDeclaration getDeclaringType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MethodDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MethodDeclaration.java new file mode 100755 index 0000000..77935e5 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/MethodDeclaration.java @@ -0,0 +1,60 @@ +/* + * @(#)MethodDeclaration.java 1.2 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import com.sun.mirror.type.TypeMirror; +import com.sun.mirror.type.VoidType; + + +/** + * Represents a method of a class or interface. + * Note that an + * {@linkplain AnnotationTypeElementDeclaration annotation type element} + * is a kind of method. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/04/20 + * @since 1.5 + */ + +public interface MethodDeclaration extends ExecutableDeclaration { + + /** + * Returns the formal return type of this method. + * Returns {@link VoidType} if this method does not return a value. + * + * @return the formal return type of this method + */ + TypeMirror getReturnType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Modifier.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Modifier.java new file mode 100755 index 0000000..06bda0b --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/Modifier.java @@ -0,0 +1,101 @@ +/* + * @(#)Modifier.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +/** + * Represents a modifier on the declaration of a program element such + * as a class, method, or field. + *

+ *

Not all modifiers are applicable to all kinds of declarations. + * When two or more modifiers appear in the source code of a declaration, + * then it is customary, though not required, that they appear in the same + * order as the constants listed in the detail section below. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/25 + * @since 1.5 + */ + +public enum Modifier { + + // See JLS2 sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1. + // java.lang.reflect.Modifier includes INTERFACE, but that's a VMism. + + /** + * The modifier public + */PUBLIC, + /** + * The modifier protected + */PROTECTED, + /** + * The modifier private + */PRIVATE, + /** + * The modifier abstract + */ABSTRACT, + /** + * The modifier static + */STATIC, + /** + * The modifier final + */FINAL, + /** + * The modifier transient + */TRANSIENT, + /** + * The modifier volatile + */VOLATILE, + /** + * The modifier synchronized + */SYNCHRONIZED, + /** + * The modifier native + */NATIVE, + /** + * The modifier strictfp + */STRICTFP; + + + private String lowercase = null; // modifier name in lowercase + + /** + * Returns this modifier's name in lowercase. + */ + public String toString() { + if (lowercase == null) { + lowercase = name().toLowerCase(java.util.Locale.US); + } + return lowercase; + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/PackageDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/PackageDeclaration.java new file mode 100755 index 0000000..130f2a2 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/PackageDeclaration.java @@ -0,0 +1,98 @@ +/* + * @(#)PackageDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + + +/** + * Represents the declaration of a package. Provides access to information + * about the package and its members. + *

+ *

{@link com.sun.mirror.util.DeclarationFilter} + * provides a simple way to select just the items of interest + * when a method returns a collection of declarations. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface PackageDeclaration extends Declaration { + + /** + * Returns the fully qualified name of this package. + * This is also known as the package's canonical name. + * + * @return the fully qualified name of this package, or the + * empty string if this is the unnamed package + */ + String getQualifiedName(); + + /** + * Returns the declarations of the top-level classes in this package. + * Interfaces are not included, but enum types are. + * + * @return the declarations of the top-level classes in this package + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getClasses(); + + /** + * Returns the declarations of the top-level enum types in this package. + * + * @return the declarations of the top-level enum types in this package + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getEnums(); + + /** + * Returns the declarations of the top-level interfaces in this package. + * Annotation types are included. + * + * @return the declarations of the top-level interfaces in this package + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getInterfaces(); + + /** + * Returns the declarations of the top-level annotation types in this + * package. + * + * @return the declarations of the top-level annotation types in this + * package + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getAnnotationTypes(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ParameterDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ParameterDeclaration.java new file mode 100755 index 0000000..73ad2d3 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/ParameterDeclaration.java @@ -0,0 +1,55 @@ +/* + * @(#)ParameterDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import com.sun.mirror.type.TypeMirror; + + +/** + * Represents a formal parameter of a method or constructor. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface ParameterDeclaration extends Declaration { + + /** + * Returns the type of this parameter. + * + * @return the type of this parameter + */ + TypeMirror getType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeDeclaration.java new file mode 100755 index 0000000..2a9a270 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeDeclaration.java @@ -0,0 +1,142 @@ +/* + * @(#)TypeDeclaration.java 1.4 04/04/30 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + +import com.sun.mirror.type.*; + + +/** + * Represents the declaration of a class or interface. + * Provides access to information about the type and its members. + * Note that an {@linkplain EnumDeclaration enum} is a kind of class, + * and an {@linkplain AnnotationTypeDeclaration annotation type} is + * a kind of interface. + *

+ *

+ * While a TypeDeclaration represents the declaration + * of a class or interface, a {@link DeclaredType} represents a class + * or interface type, the latter being a use + * (or invocation) of the former. + * The distinction is most apparent with generic types, + * for which a single declaration can define a whole + * family of types. For example, the declaration of + * {@code java.util.Set} corresponds to the parameterized types + * {@code java.util.Set} and {@code java.util.Set} + * (and many others), and to the raw type {@code java.util.Set}. + *

+ *

{@link com.sun.mirror.util.DeclarationFilter} + * provides a simple way to select just the items of interest + * when a method returns a collection of declarations. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.4 04/04/30 + * @see DeclaredType + * @since 1.5 + */ + +public interface TypeDeclaration extends MemberDeclaration { + + /** + * Returns the package within which this type is declared. + * + * @return the package within which this type is declared + */ + PackageDeclaration getPackage(); + + /** + * Returns the fully qualified name of this class or interface + * declaration. More precisely, it returns the canonical + * name. + * The name of a generic type does not include any reference + * to its formal type parameters. + * For example, the the fully qualified name of the interface declaration + * {@code java.util.Set} is "java.util.Set". + * + * @return the fully qualified name of this class or interface declaration + */ + String getQualifiedName(); + + /** + * Returns the formal type parameters of this class or interface. + * + * @return the formal type parameters, or an empty collection + * if there are none + */ + Collection getFormalTypeParameters(); + + /** + * Returns the interface types directly implemented by this class + * or extended by this interface. + * + * @return the interface types directly implemented by this class + * or extended by this interface, or an empty collection if there are none + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getSuperinterfaces(); + + /** + * Returns the fields that are directly declared by this class or + * interface. Includes enum constants. + * + * @return the fields that are directly declared, + * or an empty collection if there are none + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getFields(); + + /** + * Returns the methods that are directly declared by this class or + * interface. Includes annotation type elements. Excludes + * implicitly declared methods of an interface, such as + * toString, that correspond to the methods of + * java.lang.Object. + * + * @return the methods that are directly declared, + * or an empty collection if there are none + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getMethods(); + + /** + * Returns the declarations of the nested classes and interfaces + * that are directly declared by this class or interface. + * + * @return the declarations of the nested classes and interfaces, + * or an empty collection if there are none + * @see com.sun.mirror.util.DeclarationFilter + */ + Collection getNestedTypes(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeParameterDeclaration.java b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeParameterDeclaration.java new file mode 100755 index 0000000..427a5f3 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/TypeParameterDeclaration.java @@ -0,0 +1,70 @@ +/* + * @(#)TypeParameterDeclaration.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.declaration; + + +import java.util.Collection; + +import com.sun.mirror.type.*; + + +/** + * Represents a formal type parameter of a generic type, method, + * or constructor declaration. + * A type parameter declares a {@link TypeVariable}. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface TypeParameterDeclaration extends Declaration { + + /** + * Returns the bounds of this type parameter. + * These are the types given by the extends clause. + * If there is no explicit extends clause, then + * java.lang.Object is considered to be the sole bound. + * + * @return the bounds of this type parameter + */ + Collection getBounds(); + + /** + * Returns the type, method, or constructor declaration within which + * this type parameter is declared. + * + * @return the declaration within which this type parameter is declared + */ + Declaration getOwner(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/declaration/package.html b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/package.html new file mode 100755 index 0000000..16f3257 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/declaration/package.html @@ -0,0 +1,48 @@ + + + + + + + + +Interfaces used to model program element declarations. +A declaration is represented by the appropriate subinterface of +{@link com.sun.mirror.declaration.Declaration}, +and an annotation is represented as an +{@link com.sun.mirror.declaration.AnnotationMirror}. + +

Note that the apt tool and its associated APIs may be + changed or superseded in future j2se releases. + + @since 1.5 + + diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/overview.html b/apt-mirror-api/src/main/java/com/sun/mirror/overview.html new file mode 100755 index 0000000..eb0f6b1 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/overview.html @@ -0,0 +1,117 @@ + + + + + + + + +The Mirror API is used to model the semantic structure of a program. +It provides representations of the entities +declared in a program, such as classes, methods, and fields. +Constructs below the method level, such as +individual statements and expressions, are not represented. + +

Also included is support for writing + {@linkplain com.sun.mirror.apt.AnnotationProcessor annotation processors} + to examine and process the annotations + of program elements. An annotation processor may, as an example, create + new source files and XML documents to be used in conjunction with the + original code. + + +

Characteristics of the API

+ +A program is represented at the language level, rather than at the +level of the virtual machine. Nested classes, for example, are +handled as first-class constructs, +rather than in the translated form understood by the VM. +Both source code and compiled code (class files) may be modeled +in this way. + +

Programs are modeled in their static, or build-time, form. + This differs from the {@linkplain java.lang.reflect reflection} API, + which provides run-time information about classes and objects. + +

The API does not provide direct support for generating new code. + + +

Declarations and Types

+ +The mirror API represents program constructs principally through the +{@link com.sun.mirror.declaration.Declaration} interface +and its hierarchy of subinterfaces in the package {@link +com.sun.mirror.declaration}. A Declaration represents a +program element such as a package, class, or method. +The interface hierarchy is depicted + here. + +

Types are represented by the {@link com.sun.mirror.type.TypeMirror} + interface and its hierarchy of subinterfaces in the + package {@link com.sun.mirror.type}. Types include primitive types, + class and interface types, array types, type variables, and wildcards. + The interface hierarchy is depicted + here. + +

The API makes a clear distinction between declarations and types. + This is most significant for generic types, where a single declaration + can define an infinite family of types. For example, the declaration of + java.util.Set defines the raw type java.util.Set, + the parameterized type {@code java.util.Set + }, + and much more. Only the declaration can be annotated, for example, + and only a type can appear in a method signature. + +

A program being modeled may be incomplete, in that + it may depend on an unknown class or interface type. + This may be the result of a processing error such as a missing class file, + or perhaps the missing type is to be created by an annotation processor. + See {@link com.sun.mirror.type.DeclaredType} for information on + how such unknown types are handled. + + +

Utilities and Tool Support

+ + The {@link com.sun.mirror.util} package provides + utilities to assist in the processing of declarations and types. + Included is support for using the visitor design pattern when + operating on declaration and type objects. + +

The {@link com.sun.mirror.apt} package supports the writing + of annotation processors. It provides the mechanism for them to + interact with an annotation processing tool. + + + @since 1.5 + + + diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/AnnotationType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/AnnotationType.java new file mode 100755 index 0000000..0fd9d2f --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/AnnotationType.java @@ -0,0 +1,53 @@ +/* + * @(#)AnnotationType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.AnnotationTypeDeclaration; + + +/** + * Represents an annotation type. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface AnnotationType extends InterfaceType { + + /** + * {@inheritDoc} + */ + AnnotationTypeDeclaration getDeclaration(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/ArrayType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/ArrayType.java new file mode 100755 index 0000000..4839e83 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/ArrayType.java @@ -0,0 +1,54 @@ +/* + * @(#)ArrayType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +/** + * Represents an array type. + * A multidimensional array type is represented as an array type + * whose component type is also an array type. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface ArrayType extends ReferenceType { + + /** + * Returns the component type of this array type. + * + * @return the component type of this array type + */ + TypeMirror getComponentType(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/ClassType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/ClassType.java new file mode 100755 index 0000000..c7952bc --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/ClassType.java @@ -0,0 +1,75 @@ +/* + * @(#)ClassType.java 1.2 04/04/30 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.*; + + +/** + * Represents a class type. + * Interface types are represented separately by {@link InterfaceType}. + * Note that an {@linkplain EnumType enum} is a kind of class. + *

+ *

While a {@link ClassDeclaration} represents the declaration + * of a class, a ClassType represents a class type. + * See {@link TypeDeclaration} for more on this distinction. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/04/30 + * @since 1.5 + */ + +public interface ClassType extends DeclaredType { + + /** + * {@inheritDoc} + */ + ClassDeclaration getDeclaration(); + + /** + * Returns the class type that is a direct supertype of this one. + * This is the superclass of this type's declaring class, with any + * type arguments substituted in. + * The only class with no superclass is java.lang.Object, + * for which this method returns null. + *

+ *

For example, the class type extended by + * {@code java.util.TreeSet} is + * {@code java.util.AbstractSet}. + * + * @return the class type that is a direct supertype of this one, + * or null if there is none + */ + ClassType getSuperclass(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/DeclaredType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/DeclaredType.java new file mode 100755 index 0000000..04dc25c --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/DeclaredType.java @@ -0,0 +1,112 @@ +/* + * @(#)DeclaredType.java 1.6 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import java.util.Collection; + +import com.sun.mirror.declaration.TypeDeclaration; + + +/** + * Represents a declared type, either a class type or an interface type. + * This includes parameterized types such as {@code java.util.Set} + * as well as raw types. + *

+ *

While a TypeDeclaration represents the declaration + * of a class or interface, a DeclaredType represents a class + * or interface type, the latter being a use of the former. + * See {@link TypeDeclaration} for more on this distinction. + *

+ *

A DeclaredType may represent a type + * for which details (declaration, supertypes, etc.) are unknown. + * This may be the result of a processing error, such as a missing class file, + * and is indicated by {@link #getDeclaration()} returning null. + * Other method invocations on such an unknown type will not, in general, + * return meaningful results. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.6 04/06/07 + * @since 1.5 + */ + +public interface DeclaredType extends ReferenceType { + + /** + * Returns the declaration of this type. + *

+ *

Returns null if this type's declaration is unknown. This may + * be the result of a processing error, such as a missing class file. + * + * @return the declaration of this type, or null if unknown + */ + TypeDeclaration getDeclaration(); + + /** + * Returns the type that contains this type as a member. + * Returns null if this is a top-level type. + *

+ *

For example, the containing type of {@code O.I} + * is the type {@code O}, and the containing type of + * {@code O.I} is the type {@code O}. + * + * @return the type that contains this type, + * or null if this is a top-level type + */ + DeclaredType getContainingType(); + + /** + * Returns (in order) the actual type arguments of this type. + * For a generic type nested within another generic type + * (such as {@code Outer.Inner}), only the type + * arguments of the innermost type are included. + * + * @return the actual type arguments of this type, or an empty collection + * if there are none + */ + Collection getActualTypeArguments(); + + /** + * Returns the interface types that are direct supertypes of this type. + * These are the interface types implemented or extended + * by this type's declaration, with any type arguments + * substituted in. + *

+ *

For example, the interface type extended by + * {@code java.util.Set} is {@code java.util.Collection}. + * + * @return the interface types that are direct supertypes of this type, + * or an empty collection if there are none + */ + Collection getSuperinterfaces(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/EnumType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/EnumType.java new file mode 100755 index 0000000..0ea656c --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/EnumType.java @@ -0,0 +1,53 @@ +/* + * @(#)EnumType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.EnumDeclaration; + + +/** + * Represents an enum type. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface EnumType extends ClassType { + + /** + * {@inheritDoc} + */ + EnumDeclaration getDeclaration(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/InterfaceType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/InterfaceType.java new file mode 100755 index 0000000..655aa46 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/InterfaceType.java @@ -0,0 +1,60 @@ +/* + * @(#)InterfaceType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.*; + + +/** + * Represents an interface type. + * Note that an {@linkplain AnnotationType annotation type} is + * a kind of interface. + *

+ *

While an {@link InterfaceDeclaration} represents the + * declaration of an interface, an InterfaceType + * represents an interface type. + * See {@link TypeDeclaration} for more on this distinction. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface InterfaceType extends DeclaredType { + + /** + * {@inheritDoc} + */ + InterfaceDeclaration getDeclaration(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypeException.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypeException.java new file mode 100755 index 0000000..1b9c2ca --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypeException.java @@ -0,0 +1,87 @@ +/* + * @(#)MirroredTypeException.java 1.1 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import java.lang.annotation.Annotation; + +import com.sun.mirror.declaration.Declaration; + + +/** + * Thrown when an application attempts to access the {@link Class} object + * corresponding to a {@link TypeMirror}. + * + * @see MirroredTypesException + * @see Declaration#getAnnotation(Class) + */ +public class MirroredTypeException extends RuntimeException { + + private static final long serialVersionUID = 1; + + private transient TypeMirror type; // cannot be serialized + private String name; // type's qualified "name" + + /** + * Constructs a new MirroredTypeException for the specified type. + * + * @param type the type being accessed + */ + public MirroredTypeException(TypeMirror type) { + super("Attempt to access Class object for TypeMirror " + type); + this.type = type; + name = type.toString(); + } + + /** + * Returns the type mirror corresponding to the type being accessed. + * The type mirror may be unavailable if this exception has been + * serialized and then read back in. + * + * @return the type mirror, or null if unavailable + */ + public TypeMirror getTypeMirror() { + return type; + } + + /** + * Returns the fully qualified name of the type being accessed. + * More precisely, returns the canonical name of a class, + * interface, array, or primitive, and returns "void" for + * the pseudo-type representing the type of void. + * + * @return the fully qualified name of the type being accessed + */ + public String getQualifiedName() { + return name; + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypesException.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypesException.java new file mode 100755 index 0000000..7b95a77 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/MirroredTypesException.java @@ -0,0 +1,97 @@ +/* + * @(#)MirroredTypesException.java 1.1 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import com.sun.mirror.declaration.Declaration; + + +/** + * Thrown when an application attempts to access a sequence of {@link Class} + * objects each corresponding to a {@link TypeMirror}. + * + * @see MirroredTypeException + * @see Declaration#getAnnotation(Class) + */ +public class MirroredTypesException extends RuntimeException { + + private static final long serialVersionUID = 1; + + private transient Collection types; // cannot be serialized + private Collection names; // types' qualified "names" + + /** + * Constructs a new MirroredTypesException for the specified types. + * + * @param types an ordered collection of the types being accessed + */ + @SuppressWarnings({"unchecked"}) + public MirroredTypesException(Collection types) { + super("Attempt to access Class objects for TypeMirrors " + types); + this.types = types; + names = new ArrayList(); + for (TypeMirror t : types) { + names.add(t.toString()); + } + } + + /** + * Returns the type mirrors corresponding to the types being accessed. + * The type mirrors may be unavailable if this exception has been + * serialized and then read back in. + * + * @return the type mirrors in order, or null if unavailable + */ + public Collection getTypeMirrors() { + return (types != null) + ? Collections.unmodifiableCollection(types) + : null; + } + + /** + * Returns the fully qualified names of the types being accessed. + * More precisely, returns the canonical names of each class, + * interface, array, or primitive, and "void" for + * the pseudo-type representing the type of void. + * + * @return the fully qualified names, in order, of the types being + * accessed + */ + public Collection getQualifiedNames() { + return Collections.unmodifiableCollection(names); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/PrimitiveType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/PrimitiveType.java new file mode 100755 index 0000000..1019146 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/PrimitiveType.java @@ -0,0 +1,84 @@ +/* + * @(#)PrimitiveType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +/** + * Represents a primitive type. These include + * boolean, byte, short, int, + * long, char, float, and double. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface PrimitiveType extends TypeMirror { + + /** + * Returns the kind of primitive type that this object represents. + * + * @return the kind of primitive type that this object represents + */ + Kind getKind(); + + /** + * An enumeration of the different kinds of primitive types. + */ + enum Kind { + /** + * The primitive type boolean + */BOOLEAN, + /** + * The primitive type byte + */BYTE, + /** + * The primitive type short + */SHORT, + /** + * The primitive type int + */INT, + /** + * The primitive type long + */LONG, + /** + * The primitive type char + */CHAR, + /** + * The primitive type float + */FLOAT, + /** + * The primitive type double + */DOUBLE + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/ReferenceType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/ReferenceType.java new file mode 100755 index 0000000..b5ada76 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/ReferenceType.java @@ -0,0 +1,46 @@ +/* + * @(#)ReferenceType.java 1.2 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +/** + * Represents a reference type. + * These include class and interface types, array types, and type variables. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/06/07 + * @since 1.5 + */ + +public interface ReferenceType extends TypeMirror { +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeMirror.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeMirror.java new file mode 100755 index 0000000..d56348e --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeMirror.java @@ -0,0 +1,85 @@ +/* + * @(#)TypeMirror.java 1.3 04/07/16 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.Declaration; +import com.sun.mirror.util.Types; +import com.sun.mirror.util.TypeVisitor; + + +/** + * Represents a type in the Java programming language. + * Types include primitive types, class and interface types, array + * types, and type variables. Wildcard type arguments, and the + * pseudo-type representing the type of void, are represented + * by type mirrors as well. + *

+ *

Types may be compared using the utility methods in + * {@link Types}. + * There is no guarantee that any particular type will + * always be represented by the same object. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.3 04/07/16 + * @see Declaration + * @see Types + * @since 1.5 + */ + +public interface TypeMirror { + + /** + * Returns a string representation of this type. + * Any names embedded in the expression are qualified. + * + * @return a string representation of this type + */ + String toString(); + + /** + * Tests whether two types represent the same type. + * + * @param obj the object to be compared with this type + * @return true if the specified object represents the same + * type as this. + */ + boolean equals(Object obj); + + /** + * Applies a visitor to this type. + * + * @param v the visitor operating on this type + */ + void accept(TypeVisitor v); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeVariable.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeVariable.java new file mode 100755 index 0000000..689ec67 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/TypeVariable.java @@ -0,0 +1,58 @@ +/* + * @(#)TypeVariable.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.*; + + +/** + * Represents a type variable. + * A type variable is declared by a + * {@linkplain TypeParameterDeclaration type parameter} of a + * type, method, or constructor. + * + * @author Joe Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface TypeVariable extends ReferenceType { + + /** + * Returns the type parameter that declared this type variable. + * + * @return the type parameter that declared this type variable + */ + TypeParameterDeclaration getDeclaration(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/VoidType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/VoidType.java new file mode 100755 index 0000000..4171ead --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/VoidType.java @@ -0,0 +1,49 @@ +/* + * @(#)VoidType.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import com.sun.mirror.declaration.MethodDeclaration; + + +/** + * A pseudo-type representing the type of void. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @see MethodDeclaration#getReturnType() + * @since 1.5 + */ + +public interface VoidType extends TypeMirror { +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/WildcardType.java b/apt-mirror-api/src/main/java/com/sun/mirror/type/WildcardType.java new file mode 100755 index 0000000..6eeb87b --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/WildcardType.java @@ -0,0 +1,75 @@ +/* + * @(#)WildcardType.java 1.5 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.type; + + +import java.util.Collection; + + +/** + * Represents a wildcard type argument. + * Examples include:


+ *   ?
+ *   ? extends Number
+ *   ? super T
+ * 
+ *

+ *

A wildcard may have its upper bound explicitly set by an + * extends clause, its lower bound explicitly set by a + * super clause, or neither (but not both). + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.5 04/06/07 + * @since 1.5 + */ + +public interface WildcardType extends TypeMirror { + + /** + * Returns the upper bounds of this wildcard. + * If no upper bound is explicitly declared, then + * an empty collection is returned. + * + * @return the upper bounds of this wildcard + */ + Collection getUpperBounds(); + + /** + * Returns the lower bounds of this wildcard. + * If no lower bound is explicitly declared, then + * an empty collection is returned. + * + * @return the lower bounds of this wildcard + */ + Collection getLowerBounds(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/type/package.html b/apt-mirror-api/src/main/java/com/sun/mirror/type/package.html new file mode 100755 index 0000000..cd71742 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/type/package.html @@ -0,0 +1,46 @@ + + + + + + + + +Interfaces used to model types. +A type is represented by the appropriate subinterface of +{@link com.sun.mirror.type.TypeMirror}. + +

Note that the apt tool and its associated APIs may be + changed or superseded in future j2se releases. + + @since 1.5 + + diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationFilter.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationFilter.java new file mode 100755 index 0000000..6dba1b7 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationFilter.java @@ -0,0 +1,317 @@ +/* + * @(#)DeclarationFilter.java 1.2 04/07/19 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import java.util.ArrayList; +import java.util.Collection; + +import com.sun.mirror.declaration.Declaration; +import com.sun.mirror.declaration.Modifier; + +import static com.sun.mirror.declaration.Modifier.*; + + +/** + * A filter for selecting just the items of interest + * from a collection of declarations. + * The filter is said to select or to match those declarations. + * Filters can be created in several ways: + * by the static methods described below, + * by negating or composing existing filters, + * or by subclasses that implement arbitrary matching rules. + *

+ *

A subclass can create an arbitrary filter simply by implementing + * the {@link #matches(Declaration)} method. + *

+ *

Examples. + *

Selecting the public declarations from a collection: + *

+ *     result = FILTER_PUBLIC.filter(decls);		
+ * Selecting class declarations (including enums): + *
+ *     classFilter = DeclarationFilter.getFilter(ClassDeclaration.class);
+ *     result = classFilter.filter(decls);		
+ * Selecting class declarations but excluding enums: + *
+ *     enumFilter = DeclarationFilter.getFilter(EnumDeclaration.class);
+ *     compoundFilter = classFilter.and(enumFilter.not());
+ *     result = compoundFilter.filter(decls);		
+ * Selecting declarations named "Bob": + *
+ *     nameFilter = new DeclarationFilter() {
+ *                      public boolean matches(Declaration d) {
+ *                          return d.getSimpleName().equals("Bob");
+ *                      }
+ *                  };
+ *     result = nameFilter.filter(decls);		
+ * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/07/19 + * @since 1.5 + */ + +public class DeclarationFilter { + + // Predefined filters for convenience. + + /** + * A filter that selects only public declarations. + */ + public static final DeclarationFilter FILTER_PUBLIC = + new AccessFilter(PUBLIC); + + /** + * A filter that selects only protected declarations. + */ + public static final DeclarationFilter FILTER_PROTECTED = + new AccessFilter(PROTECTED); + + /** + * A filter that selects only public or protected + * declarations. + */ + public static final DeclarationFilter FILTER_PUBLIC_OR_PROTECTED = + new AccessFilter(PUBLIC, PROTECTED); + + /** + * A filter that selects only package-private (default) + * declarations. + */ + public static final DeclarationFilter FILTER_PACKAGE = + new AccessFilter(); + + /** + * A filter that selects only private declarations. + */ + public static final DeclarationFilter FILTER_PRIVATE = + new AccessFilter(PRIVATE); + + + /** + * Constructs an identity filter: one that selects all declarations. + */ + public DeclarationFilter() { + } + + + // Methods to create a filter. + + /** + * Returns a filter that selects declarations containing all of a + * collection of modifiers. + * + * @param mods the modifiers to match (non-null) + * @return a filter that matches declarations containing mods + */ + public static DeclarationFilter getFilter( + final Collection mods) { + return new DeclarationFilter() { + public boolean matches(Declaration d) { + return d.getModifiers().containsAll(mods); + } + }; + } + + /** + * Returns a filter that selects declarations of a particular kind. + * For example, there may be a filter that selects only class + * declarations, or only fields. + * The filter will select declarations of the specified kind, + * and also any subtypes of that kind; for example, a field filter + * will also select enum constants. + * + * @param kind the kind of declarations to select + * @return a filter that selects declarations of a particular kind + */ + public static DeclarationFilter getFilter( + final Class kind) { + return new DeclarationFilter() { + public boolean matches(Declaration d) { + return kind.isInstance(d); + } + }; + } + + /** + * Returns a filter that selects those declarations selected + * by both this filter and another. + * + * @param f filter to be composed with this one + * @return a filter that selects those declarations selected by + * both this filter and another + */ + public DeclarationFilter and(DeclarationFilter f) { + final DeclarationFilter f1 = this; + final DeclarationFilter f2 = f; + return new DeclarationFilter() { + public boolean matches(Declaration d) { + return f1.matches(d) && f2.matches(d); + } + }; + } + + /** + * Returns a filter that selects those declarations selected + * by either this filter or another. + * + * @param f filter to be composed with this one + * @return a filter that selects those declarations selected by + * either this filter or another + */ + public DeclarationFilter or(DeclarationFilter f) { + final DeclarationFilter f1 = this; + final DeclarationFilter f2 = f; + return new DeclarationFilter() { + public boolean matches(Declaration d) { + return f1.matches(d) || f2.matches(d); + } + }; + } + + /** + * Returns a filter that selects those declarations not selected + * by this filter. + * + * @return a filter that selects those declarations not selected + * by this filter + */ + public DeclarationFilter not() { + return new DeclarationFilter() { + public boolean matches(Declaration d) { + return !DeclarationFilter.this.matches(d); + } + }; + } + + + // Methods to apply a filter. + + /** + * Tests whether this filter matches a given declaration. + * The default implementation always returns true; + * subclasses should override this. + * + * @param decl the declaration to match + * @return true if this filter matches the given declaration + */ + public boolean matches(Declaration decl) { + return true; + } + + /** + * Returns the declarations matched by this filter. + * The result is a collection of the same type as the argument; + * the {@linkplain #filter(Collection, Class) two-parameter version} + * of filter offers control over the result type. + * + * @param type of the declarations being filtered + * @param decls declarations being filtered + * @return the declarations matched by this filter + */ + public Collection filter(Collection decls) { + ArrayList res = new ArrayList(decls.size()); + for (D d : decls) { + if (matches(d)) { + res.add(d); + } + } + return res; + } + + /** + * Returns the declarations matched by this filter, with the result + * being restricted to declarations of a given kind. + * Similar to the simpler + * {@linkplain #filter(Collection) single-parameter version} + * of filter, but the result type is specified explicitly. + * + * @param type of the declarations being returned + * @param decls declarations being filtered + * @param resType type of the declarations being returned -- + * the reflective view of D + * @return the declarations matched by this filter, restricted to those + * of the specified type + */ + public Collection + filter(Collection decls, Class resType) { + ArrayList res = new ArrayList(decls.size()); + for (Declaration d : decls) { + if (resType.isInstance(d) && matches(d)) { + res.add(resType.cast(d)); + } + } + return res; + } + + + /* + * A filter based on access modifiers. + */ + private static class AccessFilter extends DeclarationFilter { + + // The first access modifier to filter on, or null if we're looking + // for declarations with no access modifiers. + private Modifier mod1 = null; + + // The second access modifier to filter on, or null if none. + private Modifier mod2 = null; + + // Returns a filter that matches declarations with no access + // modifiers. + AccessFilter() { + } + + // Returns a filter that matches m. + AccessFilter(Modifier m) { + mod1 = m; + } + + // Returns a filter that matches either m1 or m2. + AccessFilter(Modifier m1, Modifier m2) { + mod1 = m1; + mod2 = m2; + } + + public boolean matches(Declaration d) { + Collection mods = d.getModifiers(); + if (mod1 == null) { // looking for package private + return !(mods.contains(PUBLIC) || + mods.contains(PROTECTED) || + mods.contains(PRIVATE)); + } + return mods.contains(mod1) && + (mod2 == null || mods.contains(mod2)); + } + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationScanner.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationScanner.java new file mode 100755 index 0000000..1e18e16 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationScanner.java @@ -0,0 +1,268 @@ +/* + * @(#)DeclarationScanner.java 1.5 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + +import com.sun.mirror.declaration.*; + +/** + * A visitor for declarations that scans declarations contained within + * the given declaration. For example, when visiting a class, the + * methods, fields, constructors, and nested types of the class are + * also visited. + *

+ *

To control the processing done on a declaration, users of this + * class pass in their own visitors for pre and post processing. The + * preprocessing visitor is called before the contained declarations + * are scanned; the postprocessing visitor is called after the + * contained declarations are scanned. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.5 04/04/20 + * @since 1.5 + */ + +class DeclarationScanner implements DeclarationVisitor { + protected DeclarationVisitor pre; + protected DeclarationVisitor post; + + DeclarationScanner(DeclarationVisitor pre, DeclarationVisitor post) { + this.pre = pre; + this.post = post; + } + + /** + * Visits a declaration. + * + * @param d the declaration to visit + */ + public void visitDeclaration(Declaration d) { + d.accept(pre); + d.accept(post); + } + + /** + * Visits a package declaration. + * + * @param d the declaration to visit + */ + public void visitPackageDeclaration(PackageDeclaration d) { + d.accept(pre); + + for (ClassDeclaration classDecl : d.getClasses()) { + classDecl.accept(this); + } + + for (InterfaceDeclaration interfaceDecl : d.getInterfaces()) { + interfaceDecl.accept(this); + } + + d.accept(post); + } + + /** + * Visits a member or constructor declaration. + * + * @param d the declaration to visit + */ + public void visitMemberDeclaration(MemberDeclaration d) { + visitDeclaration(d); + } + + /** + * Visits a type declaration. + * + * @param d the declaration to visit + */ + public void visitTypeDeclaration(TypeDeclaration d) { + d.accept(pre); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { + tpDecl.accept(this); + } + + for (FieldDeclaration fieldDecl : d.getFields()) { + fieldDecl.accept(this); + } + + for (MethodDeclaration methodDecl : d.getMethods()) { + methodDecl.accept(this); + } + + for (TypeDeclaration typeDecl : d.getNestedTypes()) { + typeDecl.accept(this); + } + + d.accept(post); + } + + /** + * Visits a class declaration. + * + * @param d the declaration to visit + */ + public void visitClassDeclaration(ClassDeclaration d) { + d.accept(pre); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { + tpDecl.accept(this); + } + + for (FieldDeclaration fieldDecl : d.getFields()) { + fieldDecl.accept(this); + } + + for (MethodDeclaration methodDecl : d.getMethods()) { + methodDecl.accept(this); + } + + for (TypeDeclaration typeDecl : d.getNestedTypes()) { + typeDecl.accept(this); + } + + for (ConstructorDeclaration ctorDecl : d.getConstructors()) { + ctorDecl.accept(this); + } + + d.accept(post); + } + + /** + * Visits an enum declaration. + * + * @param d the declaration to visit + */ + public void visitEnumDeclaration(EnumDeclaration d) { + visitClassDeclaration(d); + } + + /** + * Visits an interface declaration. + * + * @param d the declaration to visit + */ + public void visitInterfaceDeclaration(InterfaceDeclaration d) { + visitTypeDeclaration(d); + } + + /** + * Visits an annotation type declaration. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d) { + visitInterfaceDeclaration(d); + } + + /** + * Visits a field declaration. + * + * @param d the declaration to visit + */ + public void visitFieldDeclaration(FieldDeclaration d) { + visitMemberDeclaration(d); + } + + /** + * Visits an enum constant declaration. + * + * @param d the declaration to visit + */ + public void visitEnumConstantDeclaration(EnumConstantDeclaration d) { + visitFieldDeclaration(d); + } + + /** + * Visits a method or constructor declaration. + * + * @param d the declaration to visit + */ + public void visitExecutableDeclaration(ExecutableDeclaration d) { + d.accept(pre); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { + tpDecl.accept(this); + } + + for (ParameterDeclaration pDecl : d.getParameters()) { + pDecl.accept(this); + } + + d.accept(post); + } + + /** + * Visits a constructor declaration. + * + * @param d the declaration to visit + */ + public void visitConstructorDeclaration(ConstructorDeclaration d) { + visitExecutableDeclaration(d); + } + + /** + * Visits a method declaration. + * + * @param d the declaration to visit + */ + public void visitMethodDeclaration(MethodDeclaration d) { + visitExecutableDeclaration(d); + } + + /** + * Visits an annotation type element declaration. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeElementDeclaration( + AnnotationTypeElementDeclaration d) { + visitMethodDeclaration(d); + } + + /** + * Visits a parameter declaration. + * + * @param d the declaration to visit + */ + public void visitParameterDeclaration(ParameterDeclaration d) { + visitDeclaration(d); + } + + /** + * Visits a type parameter declaration. + * + * @param d the declaration to visit + */ + public void visitTypeParameterDeclaration(TypeParameterDeclaration d) { + visitDeclaration(d); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitor.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitor.java new file mode 100755 index 0000000..80b5c9d --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitor.java @@ -0,0 +1,166 @@ +/* + * @(#)DeclarationVisitor.java 1.3 04/04/20 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + +import com.sun.mirror.declaration.*; + + +/** + * A visitor for declarations, in the style of the standard visitor + * design pattern. Classes implementing this interface are used to + * operate on a declaration when the kind of declaration is unknown at + * compile time. When a visitor is passed to a declaration's {@link + * Declaration#accept accept} method, the most specific + * visitXxx method applicable to that declaration is + * invoked. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.3 04/04/20 + * @since 1.5 + */ + +public interface DeclarationVisitor { + + /** + * Visits a declaration. + * + * @param d the declaration to visit + */ + public void visitDeclaration(Declaration d); + + /** + * Visits a package declaration. + * + * @param d the declaration to visit + */ + public void visitPackageDeclaration(PackageDeclaration d); + + /** + * Visits a member or constructor declaration. + * + * @param d the declaration to visit + */ + public void visitMemberDeclaration(MemberDeclaration d); + + /** + * Visits a type declaration. + * + * @param d the declaration to visit + */ + public void visitTypeDeclaration(TypeDeclaration d); + + /** + * Visits a class declaration. + * + * @param d the declaration to visit + */ + public void visitClassDeclaration(ClassDeclaration d); + + /** + * Visits an enum declaration. + * + * @param d the declaration to visit + */ + public void visitEnumDeclaration(EnumDeclaration d); + + /** + * Visits an interface declaration. + * + * @param d the declaration to visit + */ + public void visitInterfaceDeclaration(InterfaceDeclaration d); + + /** + * Visits an annotation type declaration. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d); + + /** + * Visits a field declaration. + * + * @param d the declaration to visit + */ + public void visitFieldDeclaration(FieldDeclaration d); + + /** + * Visits an enum constant declaration. + * + * @param d the declaration to visit + */ + public void visitEnumConstantDeclaration(EnumConstantDeclaration d); + + /** + * Visits a method or constructor declaration. + * + * @param d the declaration to visit + */ + public void visitExecutableDeclaration(ExecutableDeclaration d); + + /** + * Visits a constructor declaration. + * + * @param d the declaration to visit + */ + public void visitConstructorDeclaration(ConstructorDeclaration d); + + /** + * Visits a method declaration. + * + * @param d the declaration to visit + */ + public void visitMethodDeclaration(MethodDeclaration d); + + /** + * Visits an annotation type element declaration. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeElementDeclaration( + AnnotationTypeElementDeclaration d); + + /** + * Visits a parameter declaration. + * + * @param d the declaration to visit + */ + public void visitParameterDeclaration(ParameterDeclaration d); + + /** + * Visits a type parameter declaration. + * + * @param d the declaration to visit + */ + public void visitTypeParameterDeclaration(TypeParameterDeclaration d); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitors.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitors.java new file mode 100755 index 0000000..7ca57f2 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/DeclarationVisitors.java @@ -0,0 +1,103 @@ +/* + * @(#)DeclarationVisitors.java 1.4 04/07/13 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + +/** + * Utilities to create specialized DeclarationVisitor instances. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.4 04/07/13 + * @since 1.5 + */ +public class DeclarationVisitors { + private DeclarationVisitors() { + } // do not instantiate. + + /** + * A visitor that has no side effects and keeps no state. + */ + public static final DeclarationVisitor NO_OP = new SimpleDeclarationVisitor(); + + /** + * Return a DeclarationVisitor that will scan the + * declaration structure, visiting declarations contained in + * another declaration. For example, when visiting a class, the + * fields, methods, constructors, etc. of the class are also + * visited. The order in which the contained declarations are scanned is + * not specified. + *

+ *

The pre and post + * DeclarationVisitor parameters specify, + * respectively, the processing the scanner will do before or + * after visiting the contained declarations. If only one of pre + * and post processing is needed, use {@link + * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the + * other parameter. + * + * @param pre visitor representing processing to do before + * visiting contained declarations. + * @param post visitor representing processing to do after + * visiting contained declarations. + */ + public static DeclarationVisitor getDeclarationScanner(DeclarationVisitor pre, + DeclarationVisitor post) { + return new DeclarationScanner(pre, post); + } + + /** + * Return a DeclarationVisitor that will scan the + * declaration structure, visiting declarations contained in + * another declaration in source code order. For example, when + * visiting a class, the fields, methods, constructors, etc. of + * the class are also visited. The order in which the contained + * declarations are visited is as close to source code order as + * possible; declaration mirrors created from class files instead + * of source code will not have source position information. + *

+ *

The pre and post + * DeclarationVisitor parameters specify, + * respectively, the processing the scanner will do before or + * after visiting the contained declarations. If only one of pre + * and post processing is needed, use {@link + * DeclarationVisitors#NO_OP DeclarationVisitors.NO_OP} for the other parameter. + * + * @param pre visitor representing processing to do before + * visiting contained declarations. + * @param post visitor representing processing to do after + * visiting contained declarations. + */ + public static DeclarationVisitor getSourceOrderDeclarationScanner(DeclarationVisitor pre, + DeclarationVisitor post) { + return new SourceOrderDeclScanner(pre, post); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/Declarations.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/Declarations.java new file mode 100755 index 0000000..236bd9a --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/Declarations.java @@ -0,0 +1,70 @@ +/* + * @(#)Declarations.java 1.1 04/01/26 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import com.sun.mirror.declaration.*; + + +/** + * Utility methods for operating on declarations. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.1 04/01/26 + * @since 1.5 + */ + +public interface Declarations { + + /** + * Tests whether one type, method, or field declaration hides another. + * + * @param sub the first member + * @param sup the second member + * @return true if and only if the first member hides + * the second + */ + boolean hides(MemberDeclaration sub, MemberDeclaration sup); + + /** + * Tests whether one method overrides another. When a + * non-abstract method overrides an abstract one, the + * former is also said to implement the latter. + * + * @param sub the first method + * @param sup the second method + * @return true if and only if the first method overrides + * the second + */ + boolean overrides(MethodDeclaration sub, MethodDeclaration sup); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleDeclarationVisitor.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleDeclarationVisitor.java new file mode 100755 index 0000000..c0553c1 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleDeclarationVisitor.java @@ -0,0 +1,234 @@ +/* + * @(#)SimpleDeclarationVisitor.java 1.3 04/04/30 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import com.sun.mirror.declaration.*; + + +/** + * A simple visitor for declarations. + *

+ *

The implementations of the methods of this class do nothing but + * delegate up the declaration hierarchy. A subclass should override the + * methods that correspond to the kinds of declarations on which it + * will operate. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.3 04/04/30 + * @since 1.5 + */ + +public class SimpleDeclarationVisitor implements DeclarationVisitor { + + /** + * Creates a new SimpleDeclarationVisitor. + */ + public SimpleDeclarationVisitor() { + } + + /** + * Visits a declaration. + * The implementation does nothing. + * + * @param d the declaration to visit + */ + public void visitDeclaration(Declaration d) { + } + + /** + * Visits a package declaration. + * The implementation simply invokes + * {@link #visitDeclaration visitDeclaration}. + * + * @param d the declaration to visit + */ + public void visitPackageDeclaration(PackageDeclaration d) { + visitDeclaration(d); + } + + /** + * Visits a member or constructor declaration. + * The implementation simply invokes + * {@link #visitDeclaration visitDeclaration}. + * + * @param d the declaration to visit + */ + public void visitMemberDeclaration(MemberDeclaration d) { + visitDeclaration(d); + } + + /** + * Visits a type declaration. + * The implementation simply invokes + * {@link #visitMemberDeclaration visitMemberDeclaration}. + * + * @param d the declaration to visit + */ + public void visitTypeDeclaration(TypeDeclaration d) { + visitMemberDeclaration(d); + } + + /** + * Visits a class declaration. + * The implementation simply invokes + * {@link #visitTypeDeclaration visitTypeDeclaration}. + * + * @param d the declaration to visit + */ + public void visitClassDeclaration(ClassDeclaration d) { + visitTypeDeclaration(d); + } + + /** + * Visits an enum declaration. + * The implementation simply invokes + * {@link #visitClassDeclaration visitClassDeclaration}. + * + * @param d the declaration to visit + */ + public void visitEnumDeclaration(EnumDeclaration d) { + visitClassDeclaration(d); + } + + /** + * Visits an interface declaration. + * The implementation simply invokes + * {@link #visitTypeDeclaration visitTypeDeclaration}. + * + * @param d the declaration to visit + */ + public void visitInterfaceDeclaration(InterfaceDeclaration d) { + visitTypeDeclaration(d); + } + + /** + * Visits an annotation type declaration. + * The implementation simply invokes + * {@link #visitInterfaceDeclaration visitInterfaceDeclaration}. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d) { + visitInterfaceDeclaration(d); + } + + /** + * Visits a field declaration. + * The implementation simply invokes + * {@link #visitMemberDeclaration visitMemberDeclaration}. + * + * @param d the declaration to visit + */ + public void visitFieldDeclaration(FieldDeclaration d) { + visitMemberDeclaration(d); + } + + /** + * Visits an enum constant declaration. + * The implementation simply invokes + * {@link #visitFieldDeclaration visitFieldDeclaration}. + * + * @param d the declaration to visit + */ + public void visitEnumConstantDeclaration(EnumConstantDeclaration d) { + visitFieldDeclaration(d); + } + + /** + * Visits a method or constructor declaration. + * The implementation simply invokes + * {@link #visitMemberDeclaration visitMemberDeclaration}. + * + * @param d the declaration to visit + */ + public void visitExecutableDeclaration(ExecutableDeclaration d) { + visitMemberDeclaration(d); + } + + /** + * Visits a constructor declaration. + * The implementation simply invokes + * {@link #visitExecutableDeclaration visitExecutableDeclaration}. + * + * @param d the declaration to visit + */ + public void visitConstructorDeclaration(ConstructorDeclaration d) { + visitExecutableDeclaration(d); + } + + /** + * Visits a method declaration. + * The implementation simply invokes + * {@link #visitExecutableDeclaration visitExecutableDeclaration}. + * + * @param d the declaration to visit + */ + public void visitMethodDeclaration(MethodDeclaration d) { + visitExecutableDeclaration(d); + } + + /** + * Visits an annotation type element declaration. + * The implementation simply invokes + * {@link #visitMethodDeclaration visitMethodDeclaration}. + * + * @param d the declaration to visit + */ + public void visitAnnotationTypeElementDeclaration( + AnnotationTypeElementDeclaration d) { + visitMethodDeclaration(d); + } + + /** + * Visits a parameter declaration. + * The implementation simply invokes + * {@link #visitDeclaration visitDeclaration}. + * + * @param d the declaration to visit + */ + public void visitParameterDeclaration(ParameterDeclaration d) { + visitDeclaration(d); + } + + /** + * Visits a type parameter declaration. + * The implementation simply invokes + * {@link #visitDeclaration visitDeclaration}. + * + * @param d the declaration to visit + */ + public void visitTypeParameterDeclaration(TypeParameterDeclaration d) { + visitDeclaration(d); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleTypeVisitor.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleTypeVisitor.java new file mode 100755 index 0000000..4b5ae83 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/SimpleTypeVisitor.java @@ -0,0 +1,189 @@ +/* + * @(#)SimpleTypeVisitor.java 1.4 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import com.sun.mirror.type.*; + + +/** + * A simple visitor for types. + *

+ *

The implementations of the methods of this class do nothing but + * delegate up the type hierarchy. A subclass should override the + * methods that correspond to the kinds of types on which it will + * operate. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.4 04/06/07 + * @since 1.5 + */ + +public class SimpleTypeVisitor implements TypeVisitor { + + /** + * Creates a new SimpleTypeVisitor. + */ + public SimpleTypeVisitor() { + } + + /** + * Visits a type mirror. + * The implementation does nothing. + * + * @param t the type to visit + */ + public void visitTypeMirror(TypeMirror t) { + } + + /** + * Visits a primitive type. + * The implementation simply invokes + * {@link #visitTypeMirror visitTypeMirror}. + * + * @param t the type to visit + */ + public void visitPrimitiveType(PrimitiveType t) { + visitTypeMirror(t); + } + + /** + * Visits a void type. + * The implementation simply invokes + * {@link #visitTypeMirror visitTypeMirror}. + * + * @param t the type to visit + */ + public void visitVoidType(VoidType t) { + visitTypeMirror(t); + } + + /** + * Visits a reference type. + * The implementation simply invokes + * {@link #visitTypeMirror visitTypeMirror}. + * + * @param t the type to visit + */ + public void visitReferenceType(ReferenceType t) { + visitTypeMirror(t); + } + + /** + * Visits a declared type. + * The implementation simply invokes + * {@link #visitReferenceType visitReferenceType}. + * + * @param t the type to visit + */ + public void visitDeclaredType(DeclaredType t) { + visitReferenceType(t); + } + + /** + * Visits a class type. + * The implementation simply invokes + * {@link #visitDeclaredType visitDeclaredType}. + * + * @param t the type to visit + */ + public void visitClassType(ClassType t) { + visitDeclaredType(t); + } + + /** + * Visits an enum type. + * The implementation simply invokes + * {@link #visitClassType visitClassType}. + * + * @param t the type to visit + */ + public void visitEnumType(EnumType t) { + visitClassType(t); + } + + /** + * Visits an interface type. + * The implementation simply invokes + * {@link #visitDeclaredType visitDeclaredType}. + * + * @param t the type to visit + */ + public void visitInterfaceType(InterfaceType t) { + visitDeclaredType(t); + } + + /** + * Visits an annotation type. + * The implementation simply invokes + * {@link #visitInterfaceType visitInterfaceType}. + * + * @param t the type to visit + */ + public void visitAnnotationType(AnnotationType t) { + visitInterfaceType(t); + } + + /** + * Visits an array type. + * The implementation simply invokes + * {@link #visitReferenceType visitReferenceType}. + * + * @param t the type to visit + */ + public void visitArrayType(ArrayType t) { + visitReferenceType(t); + } + + /** + * Visits a type variable. + * The implementation simply invokes + * {@link #visitReferenceType visitReferenceType}. + * + * @param t the type to visit + */ + public void visitTypeVariable(TypeVariable t) { + visitReferenceType(t); + } + + /** + * Visits a wildcard. + * The implementation simply invokes + * {@link #visitTypeMirror visitTypeMirror}. + * + * @param t the type to visit + */ + public void visitWildcardType(WildcardType t) { + visitTypeMirror(t); + } +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/SourceOrderDeclScanner.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/SourceOrderDeclScanner.java new file mode 100755 index 0000000..92c496e --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/SourceOrderDeclScanner.java @@ -0,0 +1,277 @@ +/* + * @(#)SourceOrderDeclScanner.java 1.5 04/09/16 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + +import com.sun.mirror.declaration.*; + +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * A visitor for declarations that scans declarations contained within + * the given declaration in source code order. For example, when + * visiting a class, the methods, fields, constructors, and nested + * types of the class are also visited. + *

+ * To control the processing done on a declaration, users of this + * class pass in their own visitors for pre and post processing. The + * preprocessing visitor is called before the contained declarations + * are scanned; the postprocessing visitor is called after the + * contained declarations are scanned. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.5 04/09/16 + * @since 1.5 + */ +class SourceOrderDeclScanner extends DeclarationScanner { + static class SourceOrderComparator implements java.util.Comparator { + SourceOrderComparator() { + } + + + static boolean equals(Declaration d1, Declaration d2) { + return d1 == d2 || (d1 != null && d1.equals(d2)); + } + + private static class DeclPartialOrder extends com.sun.mirror.util.SimpleDeclarationVisitor { + private int value = 1000; + + private static int staticAdjust(Declaration d) { + return d.getModifiers().contains(Modifier.STATIC) ? 0 : 1; + } + + DeclPartialOrder() { + } + + public int getValue() { + return value; + } + + @Override + public void visitTypeParameterDeclaration(TypeParameterDeclaration d) { + value = 0; + } + + @Override + public void visitEnumConstantDeclaration(EnumConstantDeclaration d) { + value = 1; + } + + @Override + public void visitClassDeclaration(ClassDeclaration d) { + value = 2 + staticAdjust(d); + } + + @Override + public void visitInterfaceDeclaration(InterfaceDeclaration d) { + value = 4; + } + + @Override + public void visitEnumDeclaration(EnumDeclaration d) { + value = 6; + } + + @Override + public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d) { + value = 8; + } + + @Override + public void visitFieldDeclaration(FieldDeclaration d) { + value = 10 + staticAdjust(d); + } + + @Override + public void visitConstructorDeclaration(ConstructorDeclaration d) { + value = 12; + } + + @Override + public void visitMethodDeclaration(MethodDeclaration d) { + value = 14 + staticAdjust(d); + } + } + + private int compareEqualPosition(Declaration d1, Declaration d2) { + assert d1.getPosition() == d2.getPosition(); + + DeclPartialOrder dpo1 = new DeclPartialOrder(); + DeclPartialOrder dpo2 = new DeclPartialOrder(); + + d1.accept(dpo1); + d2.accept(dpo2); + + int difference = dpo1.getValue() - dpo2.getValue(); + if (difference != 0) + return difference; + else { + int result = d1.getSimpleName().compareTo(d2.getSimpleName()); + if (result != 0) + return result; + return (int) (Long.signum((long) System.identityHashCode(d1) - + (long) System.identityHashCode(d2))); + } + } + + public int compare(Declaration d1, Declaration d2) { + if (equals(d1, d2)) + return 0; + + SourcePosition p1 = d1.getPosition(); + SourcePosition p2 = d2.getPosition(); + + if (p1 == null && p2 != null) + return 1; + else if (p1 != null && p2 == null) + return -1; + else if (p1 == null && p2 == null) + return compareEqualPosition(d1, d2); + else { + assert p1 != null && p2 != null; + int fileComp = p1.file().compareTo(p2.file()); + if (fileComp == 0) { + long diff = (long) p1.line() - (long) p2.line(); + if (diff == 0) { + diff = Long.signum((long) p1.column() - (long) p2.column()); + if (diff != 0) + return (int) diff; + else { + // declarations may be two + // compiler-generated members with the + // same source position + return compareEqualPosition(d1, d2); + } + } else + return (diff < 0) ? -1 : 1; + } else + return fileComp; + } + } + } + + final static java.util.Comparator comparator = new SourceOrderComparator(); + + SourceOrderDeclScanner(DeclarationVisitor pre, DeclarationVisitor post) { + super(pre, post); + } + + /** + * Visits a type declaration. + * + * @param d the declaration to visit + */ + public void visitTypeDeclaration(TypeDeclaration d) { + d.accept(pre); + + SortedSet decls = new + TreeSet(SourceOrderDeclScanner.comparator); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { + decls.add(tpDecl); + } + + for (FieldDeclaration fieldDecl : d.getFields()) { + decls.add(fieldDecl); + } + + for (MethodDeclaration methodDecl : d.getMethods()) { + decls.add(methodDecl); + } + + for (TypeDeclaration typeDecl : d.getNestedTypes()) { + decls.add(typeDecl); + } + + for (Declaration decl : decls) + decl.accept(this); + + d.accept(post); + } + + /** + * Visits a class declaration. + * + * @param d the declaration to visit + */ + public void visitClassDeclaration(ClassDeclaration d) { + d.accept(pre); + + SortedSet decls = new + TreeSet(SourceOrderDeclScanner.comparator); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { + decls.add(tpDecl); + } + + for (FieldDeclaration fieldDecl : d.getFields()) { + decls.add(fieldDecl); + } + + for (MethodDeclaration methodDecl : d.getMethods()) { + decls.add(methodDecl); + } + + for (TypeDeclaration typeDecl : d.getNestedTypes()) { + decls.add(typeDecl); + } + + for (ConstructorDeclaration ctorDecl : d.getConstructors()) { + decls.add(ctorDecl); + } + + for (Declaration decl : decls) + decl.accept(this); + + d.accept(post); + } + + public void visitExecutableDeclaration(ExecutableDeclaration d) { + d.accept(pre); + + SortedSet decls = new + TreeSet(SourceOrderDeclScanner.comparator); + + for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) + decls.add(tpDecl); + + for (ParameterDeclaration pDecl : d.getParameters()) + decls.add(pDecl); + + for (Declaration decl : decls) + decl.accept(this); + + d.accept(post); + } + +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/SourcePosition.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/SourcePosition.java new file mode 100755 index 0000000..d2f83af --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/SourcePosition.java @@ -0,0 +1,73 @@ +/* + * @(#)SourcePosition.java 1.2 04/07/16 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import java.io.File; + + +/** + * Represents a position in a source file. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.2 04/07/16 + * @since 1.5 + */ + +public interface SourcePosition { + + /** + * Returns the source file containing this position. + * + * @return the source file containing this position; never null + */ + File file(); + + /** + * Returns the line number of this position. Lines are numbered + * starting with 1. + * + * @return the line number of this position, or 0 if the line + * number is unknown or not applicable + */ + int line(); + + /** + * Returns the column number of this position. Columns are numbered + * starting with 1. + * + * @return the column number of this position, or 0 if the column + * number is unknown or not applicable + */ + int column(); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/TypeVisitor.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/TypeVisitor.java new file mode 100755 index 0000000..42c71bb --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/TypeVisitor.java @@ -0,0 +1,138 @@ +/* + * @(#)TypeVisitor.java 1.4 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import com.sun.mirror.type.*; + + +/** + * A visitor for types, in the style of the standard visitor design pattern. + * This is used to operate on a type when the kind + * of type is unknown at compile time. + * When a visitor is passed to a type's + * {@link TypeMirror#accept accept} method, + * the most specific visitXxx method applicable to + * that type is invoked. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.4 04/06/07 + * @since 1.5 + */ + +public interface TypeVisitor { + + /** + * Visits a type mirror. + * + * @param t the type to visit + */ + public void visitTypeMirror(TypeMirror t); + + /** + * Visits a primitive type. + * + * @param t the type to visit + */ + public void visitPrimitiveType(PrimitiveType t); + + /** + * Visits a void type. + * + * @param t the type to visit + */ + public void visitVoidType(VoidType t); + + /** + * Visits a reference type. + * + * @param t the type to visit + */ + public void visitReferenceType(ReferenceType t); + + /** + * Visits a declared type. + * + * @param t the type to visit + */ + public void visitDeclaredType(DeclaredType t); + + /** + * Visits a class type. + * + * @param t the type to visit + */ + public void visitClassType(ClassType t); + + /** + * Visits an enum type. + * + * @param t the type to visit + */ + public void visitEnumType(EnumType t); + + /** + * Visits an interface type. + * + * @param t the type to visit + */ + public void visitInterfaceType(InterfaceType t); + + /** + * Visits an annotation type. + * + * @param t the type to visit + */ + public void visitAnnotationType(AnnotationType t); + + /** + * Visits an array type. + * + * @param t the type to visit + */ + public void visitArrayType(ArrayType t); + + /** + * Visits a type variable. + * + * @param t the type to visit + */ + public void visitTypeVariable(TypeVariable t); + + /** + * Visits a wildcard. + * + * @param t the type to visit + */ + public void visitWildcardType(WildcardType t); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/Types.java b/apt-mirror-api/src/main/java/com/sun/mirror/util/Types.java new file mode 100755 index 0000000..e162f84 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/Types.java @@ -0,0 +1,190 @@ +/* + * @(#)Types.java 1.3 04/06/07 + * + * Copyright (c) 2004, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of + * its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.sun.mirror.util; + + +import java.util.Collection; + +import com.sun.mirror.declaration.*; +import com.sun.mirror.type.*; + + +/** + * Utility methods for operating on types. + * + * @author Joseph D. Darcy + * @author Scott Seligman + * @version 1.3 04/06/07 + * @since 1.5 + */ + +public interface Types { + + /** + * Tests whether one type is a subtype of the another. + * Any type is considered to be a subtype of itself. + * + * @param t1 the first type + * @param t2 the second type + * @return true if and only if the first type is a subtype + * of the second + */ + boolean isSubtype(TypeMirror t1, TypeMirror t2); + + /** + * Tests whether one type is assignable to another. + * + * @param t1 the first type + * @param t2 the second type + * @return true if and only if the first type is assignable + * to the second + */ + boolean isAssignable(TypeMirror t1, TypeMirror t2); + + /** + * Returns the erasure of a type. + * + * @param t the type to be erased + * @return the erasure of the given type + */ + TypeMirror getErasure(TypeMirror t); + + /** + * Returns a primitive type. + * + * @param kind the kind of primitive type to return + * @return a primitive type + */ + PrimitiveType getPrimitiveType(PrimitiveType.Kind kind); + + /** + * Returns the pseudo-type representing the type of void. + * + * @return the pseudo-type representing the type of void + */ + VoidType getVoidType(); + + /** + * Returns an array type with the specified component type. + * + * @param componentType the component type + * @return an array type with the specified component type. + * @throws IllegalArgumentException if the component type is not valid for + * an array + */ + ArrayType getArrayType(TypeMirror componentType); + + /** + * Returns the type variable declared by a type parameter. + * + * @param tparam the type parameter + * @return the type variable declared by the type parameter + */ + TypeVariable getTypeVariable(TypeParameterDeclaration tparam); + + /** + * Returns a new wildcard. + * Either the wildcards's upper bounds or lower bounds may be + * specified, or neither, but not both. + * + * @param upperBounds the upper bounds of this wildcard, + * or an empty collection if none + * @param lowerBounds the lower bounds of this wildcard, + * or an empty collection if none + * @return a new wildcard + * @throws IllegalArgumentException if bounds are not valid + */ + WildcardType getWildcardType(Collection upperBounds, + Collection lowerBounds); + + /** + * Returns the type corresponding to a type declaration and + * actual type arguments. + * Given the declaration for String, for example, this + * method may be used to get the String type. It may + * then be invoked a second time, with the declaration for Set, + * to make the parameterized type {@code Set}. + *

+ *

The number of type arguments must either equal the + * number of the declaration's formal type parameters, or must be + * zero. If zero, and if the declaration is generic, + * then the declaration's raw type is returned. + *

+ *

If a parameterized type is being returned, its declaration + * must not be contained within a generic outer class. + * The parameterized type {@code Outer.Inner}, + * for example, may be constructed by first using this + * method to get the type {@code Outer}, and then invoking + * {@link #getDeclaredType(DeclaredType, TypeDeclaration, TypeMirror...)}. + * + * @param decl the type declaration + * @param typeArgs the actual type arguments + * @return the type corresponding to the type declaration and + * actual type arguments + * @throws IllegalArgumentException if too many or too few + * type arguments are given, or if an inappropriate type + * argument or declaration is provided + */ + DeclaredType getDeclaredType(TypeDeclaration decl, + TypeMirror... typeArgs); + + /** + * Returns the type corresponding to a type declaration + * and actual arguments, given a + * {@linkplain DeclaredType#getContainingType() containing type} + * of which it is a member. + * The parameterized type {@code Outer.Inner}, + * for example, may be constructed by first using + * {@link #getDeclaredType(TypeDeclaration, TypeMirror...)} + * to get the type {@code Outer}, and then invoking + * this method. + *

+ *

If the containing type is a parameterized type, + * the number of type arguments must equal the + * number of the declaration's formal type parameters. + * If it is not parameterized or if it is null, this method is + * equivalent to getDeclaredType(decl, typeArgs). + * + * @param containing the containing type, or null if none + * @param decl the type declaration + * @param typeArgs the actual type arguments + * @return the type corresponding to the type declaration and + * actual type arguments, + * contained within the given type + * @throws IllegalArgumentException if too many or too few + * type arguments are given, or if an inappropriate type + * argument, declaration, or containing type is provided + */ + DeclaredType getDeclaredType(DeclaredType containing, + TypeDeclaration decl, + TypeMirror... typeArgs); +} diff --git a/apt-mirror-api/src/main/java/com/sun/mirror/util/package.html b/apt-mirror-api/src/main/java/com/sun/mirror/util/package.html new file mode 100755 index 0000000..f551750 --- /dev/null +++ b/apt-mirror-api/src/main/java/com/sun/mirror/util/package.html @@ -0,0 +1,46 @@ + + + + + + + + +Utilities to assist in the processing of {@linkplain +com.sun.mirror.declaration declarations} and {@linkplain +com.sun.mirror.type types}. + +

Note that the apt tool and its associated APIs may be + changed or superseded in future j2se releases. + + @since 1.5 + + diff --git a/apt-processor/pom.xml b/apt-processor/pom.xml new file mode 100755 index 0000000..02a1547 --- /dev/null +++ b/apt-processor/pom.xml @@ -0,0 +1,70 @@ + + + + + + com.moparisthebest.aptIn16 + aptIn16 + 0.1 + + 4.0.0 + apt-processor + apt-processor + + + ${project.groupId} + core + ${project.version} + + + + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + default-compile + + -proc:none + + ** + + + + + compile-everything-else + compile + + compile + + + + + + + + + \ No newline at end of file diff --git a/apt-processor/src/main/java/com/moparisthebest/mirror/AptProcessor.java b/apt-processor/src/main/java/com/moparisthebest/mirror/AptProcessor.java new file mode 100755 index 0000000..e5394bb --- /dev/null +++ b/apt-processor/src/main/java/com/moparisthebest/mirror/AptProcessor.java @@ -0,0 +1,149 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror; + +import com.sun.mirror.apt.AnnotationProcessorFactory; +import com.sun.mirror.declaration.AnnotationTypeDeclaration; +import com.moparisthebest.mirror.apt.ConvertAnnotationProcessorEnvironment; +import com.moparisthebest.mirror.apt.ConvertAnnotationProcessorFactory; +import com.moparisthebest.mirror.declaration.ConvertDeclaration; + +import javax.annotation.processing.Completion; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import java.io.IOException; +import java.net.URL; +import java.util.*; + +public class AptProcessor implements Processor { + + final List factories; + final Set supportedOptions; + final Set supportedAnnotationTypes; + + protected ConvertAnnotationProcessorEnvironment env; + + public AptProcessor() throws IOException { + System.out.println("AptProcessor starting!"); + Enumeration resources = getClass().getClassLoader().getResources("META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory"); + Set apfSet = new HashSet(); + String line; + while (resources.hasMoreElements()) { + try { + Scanner scan = new Scanner(resources.nextElement().openStream()); + while (scan.hasNextLine()) { + line = scan.nextLine().trim(); + // if line is empty or it's a comment (whitespace leading a hashtag), then skip + if (line.isEmpty() || line.matches("^\\s*#.*")) + continue; + apfSet.add(line); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + List factoryList = new ArrayList(apfSet.size()); + Collection options = new ArrayList(); + Set annotationTypes = new HashSet(); + for (String apfName : apfSet) { + try { + AnnotationProcessorFactory apf = (AnnotationProcessorFactory) Class.forName(apfName).newInstance(); + System.out.println("AptProcessor running " + apfName); + factoryList.add(apf); + annotationTypes.addAll(apf.supportedAnnotationTypes()); + options.addAll(apf.supportedOptions()); + } catch (Exception e) { + e.printStackTrace(); + } + } + this.factories = Collections.unmodifiableList(factoryList); + this.supportedOptions = Collections.unmodifiableSet(ConvertAnnotationProcessorFactory.cleanOptions(options)); + this.supportedAnnotationTypes = Collections.unmodifiableSet(annotationTypes); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + //env.getFiler().setModified(false); // don't care about modified here I guess, just always return true + env.setRoundEnv(roundEnv); + final Set annotationTypes = + Collections.unmodifiableSet( + ConvertDeclaration.getConvertable().convertToSet(annotations, AnnotationTypeDeclaration.class)); + for (AnnotationProcessorFactory factory : factories) { + // sending in all instead of just the ones they handle *sometimes* causes exceptions, so I guess we will + // sort them out... + factory.getProcessorFor(annotationTypes, env).process(); + /* + Set atds = new HashSet(); + Collection supportedTypes = factory.supportedAnnotationTypes(); + for(AnnotationTypeDeclaration atd : annotationTypes) + if(supportedTypes.contains(atd.)) + atd. + if(!atds.isEmpty()) + factory.getProcessorFor(annotationTypes, env).process(); + */ + } + //return env.getFiler().isModified(); + return true; + } + + @Override + public Set getSupportedOptions() { + return supportedOptions; + } + + @Override + public Set getSupportedAnnotationTypes() { + return supportedAnnotationTypes; + } + + @Override + public void init(ProcessingEnvironment processingEnv) { + env = new ConvertAnnotationProcessorEnvironment(processingEnv); + /* + if (!(processingEnv instanceof com.sun.tools.javac.processing.JavacProcessingEnvironment)) { + return; + } + try { + System.out.println(processingEnv.getClass().getName()); + com.sun.tools.javac.processing.JavacProcessingEnvironment pe = (com.sun.tools.javac.processing.JavacProcessingEnvironment) processingEnv; + Field discoveredProcs = pe.getClass().getDeclaredField("discoveredProcs"); + com.sun.tools.javac.processing.JavacProcessingEnvironment.DiscoveredProcessors discoveredProcs. + } catch (Exception e) { + + } + System.exit(0); + */ + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public Iterable getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) { + return Collections.emptyList(); + } +} diff --git a/apt-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/apt-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100755 index 0000000..3737673 --- /dev/null +++ b/apt-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,6 @@ +# This file contains the processor's we want to run +# in this jar, there is only one, which runs all of +# the old-style Java 5 apt processors it can find +# automatically just like apt did, but in javac. + +com.moparisthebest.mirror.AptProcessor diff --git a/core/pom.xml b/core/pom.xml new file mode 100755 index 0000000..935a6e2 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,38 @@ + + + + + + com.moparisthebest.aptIn16 + aptIn16 + 0.1 + + 4.0.0 + core + core + + + ${project.groupId} + apt-mirror-api + 1.0 + + + \ No newline at end of file diff --git a/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorEnvironment.java b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorEnvironment.java new file mode 100755 index 0000000..0c38a3b --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorEnvironment.java @@ -0,0 +1,328 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.apt; + +import com.moparisthebest.mirror.convert.Convertable; +import com.moparisthebest.mirror.util.ConvertTypes; +import com.sun.mirror.apt.AnnotationProcessorEnvironment; +import com.sun.mirror.apt.AnnotationProcessorListener; +import com.sun.mirror.apt.Messager; +import com.sun.mirror.declaration.AnnotationTypeDeclaration; +import com.sun.mirror.declaration.Declaration; +import com.sun.mirror.declaration.PackageDeclaration; +import com.sun.mirror.declaration.TypeDeclaration; +import com.sun.mirror.util.Declarations; +import com.sun.mirror.util.Types; +import com.moparisthebest.mirror.declaration.ConvertDeclaration; +import com.moparisthebest.mirror.log.Debug; +import com.moparisthebest.mirror.type.ConvertTypeMirror; +import com.moparisthebest.mirror.util.ConvertDeclarations; +import com.moparisthebest.mirror.util.ConvertSourcePosition; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import java.io.File; +import java.util.*; + +public class ConvertAnnotationProcessorEnvironment implements AnnotationProcessorEnvironment { + + private static final Object lock = new Object(); + private boolean deriveSourcePath; + private final Map options; + + private final ProcessingEnvironment internal; + private final ConvertFiler filer; + private final ConvertMessager messager; + + private RoundEnvironment roundEnv = null; + + public static Elements elements = null; + + private static final boolean debugOptions = ConvertAnnotationProcessorFactory.debug; + + public ConvertAnnotationProcessorEnvironment(ProcessingEnvironment internal) { + //System.out.printf("internal: '%s' hash: '%s'\n", internal.toString(), internal.hashCode()); + this.internal = internal; + filer = new ConvertFiler(internal.getFiler()); + messager = new ConvertMessager(internal.getMessager()); + ConvertSourcePosition.setProcessingEnvironment(internal, this); + // now set some static variables around, this could be nicer... + elements = internal.getElementUtils(); + ConvertDeclaration.elements = elements; + ConvertTypeMirror.types = internal.getTypeUtils(); + + // now calculate options once, since they are sort-of expensive + // real apt passes them back like so: + //{-d=./aptgen, save-parameter-names=null, -s=./aptgen, -Aweb.content.root=./aptgen=null, -classpath=.;../netui16compiler/target/classes;../netui/target/classes;../controls/target/classes;../target/netui16compiler.jar, -nocompile=null, -factory=org.apache.beehive.netui.compiler.apt.PageFlowAnnotationProcessorFactory, -sourcepath=./aptgen} + // whereas internal.getOptions passes them like this: + // {web.content.root=./aptgen} + final Map ret = new HashMap(); + final Map internalOptions = internal.getOptions(); + if (debugOptions) { + final File workingDir = new File("."); + System.out.println("working dir: " + workingDir.getAbsolutePath()); + System.err.println("@@@@options: " + internalOptions); + } + // first put -A in front of all options + for (Map.Entry internalOption : internalOptions.entrySet()) + ret.put("-A" + internalOption.getKey(), internalOption.getValue()); + // now set classpath + // some annotation processors (I'm looking at you beehive...) request '-classpath' and ignore '-cp', + // so put it under both :rolleyes: + ret.put("-cp", System.getProperty("java.class.path")); + ret.put("-classpath", System.getProperty("java.class.path")); + if (System.getProperty("sun.boot.class.path") != null) + ret.put("-bootclasspath", System.getProperty("sun.boot.class.path")); + if (debugOptions) { + System.out.println("System properties: " + System.getProperties()); + System.out.println("java.class.path: " + System.getProperty("java.class.path")); + System.out.println("java.source.path: " + System.getProperty("java.source.path")); + System.out.println("sun.boot.class.path: " + System.getProperty("sun.boot.class.path")); + System.err.println("@@@@partialoptions: " + ret); + } + // now the hard part, get the rest of the options sent to javac... + + // this will probably only work on sun compilers, but I'm out of options + String command = System.getProperty("sun.java.command"); + // can't split by space because it isn't escaped or quoted... + //command: com.sun.tools.javac.Main -processor org.apache.beehive.netui.compiler.java6.PageFlowAnnotationProcessor -proc:only -Aweb.content.root=./apt gen -d ./apt gen -s ./apt gen -sourcepath ./apt gen -cp .;../netui16compiler/target/classes;../netui/target/classes;../controls/target/classes;C:\Users\burtrutj\.m2\repository\org\apache\beehive\beehive-netui-compiler\1.0.2\beehive-netui-compiler-1.0.2.jar;C:\Users\burtrutj\.m2\repository\org\apache\beehive\beehive-controls\1.0.2\beehive-controls-1.0.2.jar;../target/netui16compiler.jar backingControls/BackingControlsController.java backingControls/TestControl.java backingControls/page1.java + if (debugOptions) + System.err.println("command: " + command); + if (command != null) + try { + String[] options = command.split(" -"); // this should only break if a single argument has the literal string ' -' in it, hopefully it won't happen often + if (debugOptions) + System.out.println("options length: " + options.length); + // skip index one because it's the name of the program, ie com.sun.tools.javac.Main + for (int i = 1; i < options.length - 1; ++i) { + if (debugOptions) + System.err.println("option: " + options[i]); + if (options[i].startsWith("A") || options[i].startsWith("cp") || options[i].startsWith("classpath")) + continue; // it's an option we already have from above + if (debugOptions) + System.err.println("processing option: " + options[i]); + String[] item = options[i].split(" ", 2); + if (item.length == 0) + continue; // shouldn't ever be here + if (item[0].equals("bootclasspath") && item[1].trim().startsWith("@") && ret.containsKey("-bootclasspath")) + continue; + ret.put("-" + item[0], item.length < 2 ? null : item[1].trim()); + } + // we saved the last option for last, because it has all the appended to it, what to do... + // all items in have to exist on the filesystem before we get here, so starting from the front + // grab the longest string that is a complete file, discard, and continue doing that until the file doesn't end + // with .java or we are out of files. + if (debugOptions) + System.err.println("last option: " + options[options.length - 1]); + String[] item = options[options.length - 1].split(" ", 2); + if (item.length < 2) + ret.put(item[0], null); + else { + // I thought there had to be an item at 1, or no files would have been passed to javac + // turns out things like maven have their own launchers... + final String valueAndFiles = item[1]; + int stopIncluding = valueAndFiles.length(); + // match the biggest file possible in the string, starting from the beginning + outer: + for (int i = 0; i < stopIncluding; ++i) { + do { + String fileName = valueAndFiles.substring(i, stopIncluding); + //System.err.println("fileName: "+fileName); + if (new File(fileName).isFile()) { + //System.err.println("success! it's a file!"); + if (!fileName.trim().toLowerCase().endsWith(".java")) { + //System.err.println("breaking because filename doesn't end with .java: "+fileName.toLowerCase()); + break outer; + } + stopIncluding = i; + i = 0; + continue outer; + } + } while (++i < stopIncluding); + } + String value = valueAndFiles.substring(0, stopIncluding).trim(); + if (debugOptions) + System.err.printf("last option: '%s':'%s'\n", item[0], value.isEmpty() ? null : value); + ret.put(item[0], value.isEmpty() ? null : value); + } + + // now make sure -sourcepath is in there, some annotation processors (again, I'm looking at you, flipping beehive) + // require it be specified, if it isn't, try to hack it out... + //if(false) + if (ret.get("-sourcepath") == null || ret.get("-sourcepath").isEmpty()) + try { + File path = null; + try { + FileObject sourcePath = internal.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "trash"); + //FileObject sourcePath = internal.getFiler().getResource(StandardLocation.SOURCE_PATH, "", "com/moparisthebest/controls/studysearch/studySearchCtrl.java"); + + //FileObject sourcePath = internal.getFiler().createResource(StandardLocation.SOURCE_PATH, "", "trash"); + path = new File(sourcePath.toUri()); + path = path.getParentFile().getCanonicalFile(); + } catch (Exception e) { + //todo: this fails on jdk7, but works fine on jdk6, figure out a better way, for now, deriveSourcePath is called + if (debugOptions) + e.printStackTrace(); + //Iterable spi = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH); + //Iterator sp = spi.iterator(); + //while(sp.hasNext()) + // System.out.println(sp.next()); + } + if (debugOptions) + System.err.println("guessed sourcepath: " + path); + if (path != null) + ret.put("-sourcepath", path.getAbsolutePath()); + } catch (Exception e) { + e.printStackTrace(); + } + } catch (Throwable e) { + System.out.println("Exception parsing command line options:"); + e.printStackTrace(); + System.out.println("successfully parsed options are: " + ret); + } + // try to derive it if it still doesn't exist and it's possible with ConvertSourcePosition + deriveSourcePath = ConvertSourcePosition.supported() && (ret.get("-sourcepath") == null || ret.get("-sourcepath").isEmpty()); + //System.err.println("@@@@fixedoptions: " + ret); + //System.exit(0); + this.options = deriveSourcePath ? ret : Collections.unmodifiableMap(ret); + if (debugOptions) + System.out.println("options: " + this.options); + } + + public void deriveSourcePath(File file, String packageName) { + if (!deriveSourcePath) + return; + try { + File sourcePath = file; + int subDirs = packageName.split("\\.").length; + while (subDirs-- >= 0) + sourcePath = sourcePath.getParentFile(); + //System.out.println("sourcePath: "+sourcePath); + // todo: we should really concatenate different sourcepath's with the platform's + // todo: path seperator, but for jdk6 we just specify one source path, + // todo: so we might as well do the same here for now + deriveSourcePath = false; + this.options.put("-sourcepath", sourcePath.getAbsolutePath()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void setRoundEnv(RoundEnvironment roundEnv) { + this.roundEnv = roundEnv; + } + + @Override + public Map getOptions() { + Debug.implemented("Map"); + return options; + } + + @Override + public Messager getMessager() { + return messager; + } + + @Override + public ConvertFiler getFiler() { + return filer; + } + + @Override + public Declarations getDeclarationUtils() { + return new ConvertDeclarations(internal.getElementUtils()); + } + + @Override + public Types getTypeUtils() { + return new ConvertTypes(internal.getTypeUtils()); + } + + @Override + public Collection getSpecifiedTypeDeclarations() { + Debug.implemented("Collection"); + return Collections.emptyList(); //todo: probably not right? + } + + @Override + public Collection getTypeDeclarations() { + Debug.implemented("Collection"); + return Collections.emptyList(); //todo: probably not right? + } + + @Override + public PackageDeclaration getPackage(String name) { + Debug.implemented("PackageDeclaration"); + return ConvertDeclaration.convert(internal.getElementUtils().getPackageElement(name), PackageDeclaration.class); + } + + @Override + public TypeDeclaration getTypeDeclaration(String name) { + Debug.implemented("TypeDeclaration"); + return ConvertDeclaration.convert(internal.getElementUtils().getTypeElement(name), TypeDeclaration.class); + } + + @Override + public Collection getDeclarationsAnnotatedWith(AnnotationTypeDeclaration a) { + Debug.implemented("Collection"); + //System.err.println("AnnotationTypeDeclaration: "+a); + //System.err.println("TypeElement: "+Convertable.unwrapClass(a, TypeElement.class)); + List ret = ConvertDeclaration.getConvertable().convert(roundEnv.getElementsAnnotatedWith(Convertable.unwrapClass(a, TypeElement.class))); + //System.err.println("retnoconvert: "+roundEnv.getElementsAnnotatedWith(Convertable.unwrapClass(a, TypeElement.class))); + //System.err.println("ret: "+ret); + //System.err.println("retclass: "+ret.toArray()[0].getClass()); + return ret; + //return Convertable.sort(ret); + } + + @Override + public void addListener(AnnotationProcessorListener listener) { + // not supported + } + + @Override + public void removeListener(AnnotationProcessorListener listener) { + // not supported + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof ProcessingEnvironment) return internal.equals(o); + if (o == null || getClass() != o.getClass()) return false; + + ConvertAnnotationProcessorEnvironment that = (ConvertAnnotationProcessorEnvironment) o; + + return internal.equals(that.internal); + } + + @Override + public int hashCode() { + return internal.hashCode(); + } + + @Override + public String toString() { + return internal.toString(); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorFactory.java b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorFactory.java new file mode 100755 index 0000000..2679f89 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertAnnotationProcessorFactory.java @@ -0,0 +1,214 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.apt; + +import com.moparisthebest.mirror.convert.Convertable; +import com.moparisthebest.mirror.declaration.ConvertDeclaration; +import com.sun.mirror.apt.AnnotationProcessorFactory; +import com.sun.mirror.declaration.AnnotationTypeDeclaration; +import com.moparisthebest.mirror.log.Debug; + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.*; + +public class ConvertAnnotationProcessorFactory implements Processor { + + public static final boolean debug = false; + + static { + String command = System.getProperty("sun.java.command"); + // hack to stop IDEA from permanently freezing when processing annotations + // todo: please tell me why, for the life of me I can't figure it out... + if (command != null && command.startsWith("com.intellij.rt.compiler")) { + // command looks like: com.intellij.rt.compiler.JavacRunner java version 1.6.0_30 com.sun.tools.javac.Main [options] + System.setOut(System.err); + System.err.println("INFO: activated IDEA hack of re-directing System.out to System.err"); + } + + PrintStream oldOut = System.out; + + if ((debug || System.getProperty("aptin16.debug") != null)) + try { + FileOutputStream fos = null; + try { + fos = new FileOutputStream("/aptin16.log"); + } catch (Exception e) { + fos = new FileOutputStream(System.getProperty("user.home") + "/aptin16.log"); + } + PrintStream out = new PrintStream(fos, true); + System.setOut(out); + System.setErr(out); + System.out.println(new Date() + ": log successfully set!"); + System.out.printf("oldOut: '%s' class: '%s'\n", oldOut.toString(), oldOut.getClass().toString()); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private final AnnotationProcessorFactory internal; + + // at least for now, all of the ProcessingEnvironment's multiple instances get sent + // are the EXACT same object, so we might as well make this static and save some time + protected static ConvertAnnotationProcessorEnvironment env = null; + + public ConvertAnnotationProcessorFactory(String annotationProcessorFactoryName) { + AnnotationProcessorFactory internal = null; + try { + internal = (AnnotationProcessorFactory) Class.forName(annotationProcessorFactoryName).newInstance(); + System.out.println("ConvertAnnotationProcessorFactory running " + internal.getClass().getName()); + } catch (Throwable e) { + System.out.printf("Not running AnnotationProcessorFactory '%s' because of error!\n", annotationProcessorFactoryName); + e.printStackTrace(); + } + this.internal = internal; + } + + public ConvertAnnotationProcessorFactory(AnnotationProcessorFactory internal) { + if (internal == null) + throw new NullPointerException("AnnotationProcessorFactory cannot be null!"); + System.out.println("ConvertAnnotationProcessorFactory running " + internal.getClass().getName()); + this.internal = internal; + } + + public static Set cleanOptions(Collection input) { + Set ret = new LinkedHashSet(input.size()); + for (String option : input) + ret.add(option.replaceFirst("^-A", "")); // have to strip -A from beginning of options... + if (Debug.debug) + System.out.println("supportedOptions: " + ret); + return ret; + } + + @Override + public Set getSupportedOptions() { + return cleanOptions(internal.supportedOptions()); + } + + @Override + public Set getSupportedAnnotationTypes() { + if (Debug.debug) + System.out.printf("factory: '%s' supportedAnnotationTypes: '%s'\n", internal.getClass().getName(), internal.supportedAnnotationTypes()); + return Convertable.toSet(internal.supportedAnnotationTypes()); + } + + private static synchronized void staticInit(ProcessingEnvironment processingEnv) { + if (env != null) + return; + env = new ConvertAnnotationProcessorEnvironment(processingEnv); + /* + // the following helps us debug, since I know no way of debugging in javac itself + System.setOut( + new PrintStream(System.out) { + + + public static final byte debugLevel = 90; + + public void printInfo() { + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + int x = 2; // start at 3 + printStackTrace(stackTrace[x], "", ""); + int level = x + debugLevel; + StringBuilder tabs = new StringBuilder(); + while (++x < level && x < stackTrace.length) + printStackTrace(stackTrace[x], "Called", tabs.append('\t').toString()); + } + + private void printStackTrace(StackTraceElement ste, String msg, String returnType) { + super.printf("%s%s.%s(%s:%d) %s\n", + returnType, + //ste.getClassName().replaceFirst(".*\\.", "") + ste.getClassName() + , ste.getMethodName(), + ste.getFileName(), ste.getLineNumber(), + msg); + } + + @Override + public void println(String x) { + printInfo(); + super.println(x); + } + } + ); + System.setErr(System.out); + //System.err.println("woohoo! quitting!"); + //System.exit(0); + */ + } + + @Override + public void init(ProcessingEnvironment processingEnv) { + //env = new ConvertAnnotationProcessorEnvironment(processingEnv); // if we change it back to an instance variable + staticInit(processingEnv); + } + + /** + * @param annotations + * @param roundEnv + * @return + */ + @Override + public synchronized boolean process(Set annotations, RoundEnvironment roundEnv) { + env.getFiler().setModified(false); + env.setRoundEnv(roundEnv); + internal.getProcessorFor(ConvertDeclaration.getConvertable().convertToSet(annotations, AnnotationTypeDeclaration.class), env).process(); + return env.getFiler().isModified(); //todo: don't know what to return here + //return true; + //return false; // apt didn't return anything or have a notion of 'claiming' annotations, but false breaks beehive... + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public Iterable getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) { + return Collections.emptyList(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof AnnotationProcessorFactory) return internal.equals(o); + if (o == null || getClass() != o.getClass()) return false; + + ConvertAnnotationProcessorFactory that = (ConvertAnnotationProcessorFactory) o; + + return internal.equals(that.internal); + } + + @Override + public int hashCode() { + return internal.hashCode(); + } + + @Override + public String toString() { + return internal.toString(); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/apt/ConvertFiler.java b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertFiler.java new file mode 100755 index 0000000..9b76730 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertFiler.java @@ -0,0 +1,120 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.apt; + +import com.moparisthebest.mirror.log.Debug; + +import javax.tools.StandardLocation; +import java.io.*; + +public class ConvertFiler implements com.sun.mirror.apt.Filer { + + private final javax.annotation.processing.Filer internal; + private boolean modified = false; + + public ConvertFiler(javax.annotation.processing.Filer internal) { + this.internal = internal; + } + + public boolean isModified() { + return modified; + } + + public void setModified(boolean modified) { + this.modified = modified; + } + + @Override + public PrintWriter createSourceFile(String name) throws IOException { + Debug.implemented(PrintWriter.class); + modified = true; + return new PrintWriter(internal.createSourceFile(name).openWriter()); + } + + @Override + public OutputStream createClassFile(String name) throws IOException { + Debug.implemented(OutputStream.class); + modified = true; + return internal.createClassFile(name).openOutputStream(); + } + + public static StandardLocation convert(Location location) { + switch (location) { + case CLASS_TREE: + return StandardLocation.CLASS_OUTPUT; + case SOURCE_TREE: + return StandardLocation.SOURCE_OUTPUT; + default: + return null; // should NEVER get here (those are the only two options for Location) + } + } + + @Override + public PrintWriter createTextFile(Location loc, String pkg, File relPath, String charsetName) throws IOException { + Debug.implemented(PrintWriter.class); + try { + OutputStream os = createBinaryFile(loc, pkg, relPath); + // since charsetName can be null, we need to use a different constructor + return new PrintWriter(charsetName == null ? new OutputStreamWriter(os) : new OutputStreamWriter(os, charsetName)); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public OutputStream createBinaryFile(Location loc, String pkg, File relPath) throws IOException { + Debug.implemented(OutputStream.class); + String relativeName = relPath.getPath(); + //relativeName = relPath.getName(); + relativeName = relativeName.replaceAll("\\\\", "/"); // on windows the relPath sometimes contains \ instead of /, which messes everything up + //System.out.printf("loc: '%s' pkg: '%s' relPath: '%s' relativeName: '%s'\n", loc, pkg, relPath.toString(), relativeName); + modified = true; + try { + return internal.createResource(convert(loc), pkg, relativeName).openOutputStream(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public boolean equals(Object o) { + Debug.implemented(); + if (this == o) return true; + if (o instanceof javax.annotation.processing.Filer) return internal.equals(o); + if (o == null || getClass() != o.getClass()) return false; + + ConvertFiler that = (ConvertFiler) o; + + return internal.equals(that.internal); + } + + @Override + public int hashCode() { + Debug.implemented(int.class); + return internal.hashCode(); + } + + @Override + public String toString() { + Debug.implemented(String.class); + return internal.toString(); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/apt/ConvertMessager.java b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertMessager.java new file mode 100755 index 0000000..43eb1db --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/apt/ConvertMessager.java @@ -0,0 +1,91 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.apt; + +import com.sun.mirror.util.SourcePosition; +import com.moparisthebest.mirror.log.Debug; + +import javax.annotation.processing.Messager; +import javax.tools.Diagnostic; + +public class ConvertMessager implements com.sun.mirror.apt.Messager { + + private final javax.annotation.processing.Messager internal; + + public ConvertMessager(Messager internal) { + this.internal = internal; + } + + @Override + public void printError(String msg) { + Debug.implemented(void.class); + internal.printMessage(Diagnostic.Kind.ERROR, msg); + } + + @Override + public void printWarning(String msg) { + Debug.implemented(void.class); + internal.printMessage(Diagnostic.Kind.WARNING, msg); + } + + @Override + public void printNotice(String msg) { + Debug.implemented(void.class); + internal.printMessage(Diagnostic.Kind.NOTE, msg); + } + + @Override + public void printError(SourcePosition pos, String msg) { + Debug.implemented(void.class); + printError(msg); // ignore pos + } + + @Override + public void printWarning(SourcePosition pos, String msg) { + Debug.implemented(void.class); + printWarning(msg); // ignore pos + } + + @Override + public void printNotice(SourcePosition pos, String msg) { + Debug.implemented(void.class); + printNotice(msg); // ignore pos + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof javax.annotation.processing.Messager) return internal.equals(o); + if (o == null || getClass() != o.getClass()) return false; + + ConvertMessager that = (ConvertMessager) o; + + return internal.equals(that.internal); + } + + @Override + public int hashCode() { + return internal.hashCode(); + } + + @Override + public String toString() { + return internal.toString(); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/convert/Convertable.java b/core/src/main/java/com/moparisthebest/mirror/convert/Convertable.java new file mode 100755 index 0000000..59866da --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/convert/Convertable.java @@ -0,0 +1,148 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.convert; + +import java.util.*; + +public abstract class Convertable implements ConvertableIface { + + public abstract T convertToType(F from); + + @Override + @SuppressWarnings({"unchecked"}) + public E convertToType(F from, Class type) { + return (E) convertToType(from); + } + + public List convert(Collection from, Class type) { + List ret = new ArrayList(from.size()); + for (F fromF : from) + ret.add(convertToType(fromF, type)); + return ret; + } + + public Set convertToSet(Collection from, Class type) { + Set ret = new LinkedHashSet(from.size()); + for (F fromF : from) + ret.add(convertToType(fromF, type)); + return ret; + } + + public List convert(Collection from) { + List ret = new ArrayList(from.size()); + for (F fromF : from) + ret.add(convertToType(fromF)); + return ret; + } + + public Set convertToSet(Collection from) { + Set ret = new LinkedHashSet(from.size()); + for (F fromF : from) + ret.add(convertToType(fromF)); + return ret; + } + + @SuppressWarnings({"unchecked"}) + public static R[] unwrapClass(Object[] convertable, R[] dest) { + if (convertable == null || dest == null) + return null; + if (convertable.length != dest.length) + throw new RuntimeException("convertable and dest need to be arrays of same length!"); + try { + Class componentType = (Class) dest.getClass().getComponentType(); + for (int x = 0; x < dest.length; ++x) + dest[x] = unwrapClass(convertable[x], componentType); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("fatal error!"); + System.exit(1); + } + return dest; + } + + @SuppressWarnings({"unchecked"}) + public static R unwrapClass(Object convertable, Class iface) { + if (convertable == null) + return null; + try { + return iface.cast(((ConvertableIface) convertable).unwrap()); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("fatal error!"); + System.exit(1); + } + return null; + } + + public static > List convertEnums(Collection from, Class newe) { + List ret = new ArrayList(from.size()); + for (Enum old : from) + ret.add(convertEnum(old, newe)); + return ret; + } + + public static > E convertEnum(Enum old, Class newe) { + return Enum.valueOf(newe, old.toString().toUpperCase()); + } + + public static Set toSet(Collection c) { + try { + if (c instanceof Set) + return (Set) c; + } catch (Exception e) { + // do nothing + } + Set ret = new LinkedHashSet(); + ret.addAll(c); + return ret; + } + + @SuppressWarnings({"unchecked"}) + public static List sort(List ret) { + //System.out.println("un-sorted: "+ret); + Collections.sort(ret, toStringComparator); + //System.out.println("sorted: "+ret); + return ret; + } + + @SuppressWarnings({"unchecked"}) + public static Set sort(Set set) { + /*return set;*/ + + TreeSet ret = new TreeSet(toStringComparator); + ret.addAll(set); + return ret; + + } + + @SuppressWarnings({"unchecked"}) + public static E[] sort(E[] ret) { + Arrays.sort(ret, toStringComparator); + return ret; + } + + public static final Comparator toStringComparator = new ToStringComparator(); + + private static class ToStringComparator implements Comparator { + public int compare(Object f1, Object f2) { + return f1.toString().compareTo(f2.toString()); + } + } + +} diff --git a/core/src/main/java/com/moparisthebest/mirror/convert/ConvertableIface.java b/core/src/main/java/com/moparisthebest/mirror/convert/ConvertableIface.java new file mode 100755 index 0000000..8b4ed05 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/convert/ConvertableIface.java @@ -0,0 +1,25 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.convert; + +public interface ConvertableIface { + public E convertToType(F from, Class type); + + public F unwrap(); +} diff --git a/core/src/main/java/com/moparisthebest/mirror/convert/ElementFilter.java b/core/src/main/java/com/moparisthebest/mirror/convert/ElementFilter.java new file mode 100755 index 0000000..6e42e2b --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/convert/ElementFilter.java @@ -0,0 +1,49 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.convert; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import java.util.*; + +public class ElementFilter { + // Assumes targetKinds and E are sensible. + private static > C collectionFilter(C collection, Iterable elements, Class clazz, ElementKind... kinds) { + for (E e : elements) { + ElementKind findKind = e.getKind(); + for (ElementKind kind : kinds) + if (kind == findKind) { + collection.add(clazz.cast(e)); + break; + } + } + return collection; + } + + // Assumes targetKinds and E are sensible. + public static List listFilter(Iterable elements, Class clazz, ElementKind... kinds) { + return collectionFilter(new ArrayList(), elements, clazz, kinds); + } + + // Assumes targetKinds and E are sensible. + public static Set setFilter(Iterable elements, Class clazz, ElementKind... kinds) { + // Return set preserving iteration order of input set. + return collectionFilter(new LinkedHashSet(), elements, clazz); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/convert/InstanceFilter.java b/core/src/main/java/com/moparisthebest/mirror/convert/InstanceFilter.java new file mode 100755 index 0000000..dfdd42b --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/convert/InstanceFilter.java @@ -0,0 +1,45 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.convert; + +import java.util.*; + +public class InstanceFilter { + + // Assumes targetKinds and E are sensible. + private static > C collectionFilter(C collection, Iterable elements, Class clazz) { + for (E e : elements) { + //if (clazz.isAssignableFrom(e.getClass())) + if (clazz.isInstance(e)) + collection.add(clazz.cast(e)); + } + return collection; + } + + // Assumes targetKinds and E are sensible. + public static List listFilter(Iterable elements, Class clazz) { + return collectionFilter(new ArrayList(), elements, clazz); + } + + // Assumes targetKinds and E are sensible. + public static Set setFilter(Iterable elements, Class clazz) { + // Return set preserving iteration order of input set. + return collectionFilter(new LinkedHashSet(), elements, clazz); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationMirror.java b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationMirror.java new file mode 100755 index 0000000..d8d30c1 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationMirror.java @@ -0,0 +1,115 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.declaration; + +import com.moparisthebest.mirror.convert.Convertable; +import com.moparisthebest.mirror.util.ConvertSourcePosition; +import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; +import com.sun.mirror.declaration.AnnotationValue; +import com.sun.mirror.type.AnnotationType; +import com.sun.mirror.util.SourcePosition; +import com.moparisthebest.mirror.log.Debug; +import com.moparisthebest.mirror.type.ConvertTypeMirror; + +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.ExecutableElement; +import java.util.HashMap; +import java.util.Map; + +public class ConvertAnnotationMirror extends Convertable implements com.sun.mirror.declaration.AnnotationMirror { + + private final javax.lang.model.element.AnnotationMirror internal; + + protected ConvertAnnotationMirror(AnnotationMirror internal) { + this.internal = internal; + } + + private ConvertAnnotationMirror() { + this.internal = null; + } + + public static Convertable getConvertable() { + return new ConvertAnnotationMirror(); + } + + public static com.sun.mirror.declaration.AnnotationMirror convert(F from) { + return convert(from, ConvertAnnotationMirror.class); + } + + @SuppressWarnings({"unchecked"}) + public static T convert(F from, Class thisClass) { + return (T) new ConvertAnnotationMirror(from); + } + + + @Override + public com.sun.mirror.declaration.AnnotationMirror convertToType(AnnotationMirror from) { + return new ConvertAnnotationMirror(from); + } + + @Override + public AnnotationMirror unwrap() { + return internal; + } + + @Override + public AnnotationType getAnnotationType() { + return ConvertTypeMirror.convert(internal.getAnnotationType(), AnnotationType.class); + } + + @Override + public Map getElementValues() { + Debug.implemented("Map"); + Map internalValues = internal.getElementValues(); + Map ret = new HashMap(internalValues.size()); + for (Map.Entry internalEntry : internalValues.entrySet()) + ret.put(new ConvertAnnotationTypeElementDeclaration(internalEntry.getKey()), new ConvertAnnotationValue(internalEntry.getValue())); + if (Debug.debug) + System.err.println("elementValues: " + ret); + return ret; + } + + @Override + public SourcePosition getPosition() { + Debug.implemented("SourcePosition"); + return ConvertSourcePosition.convert(internal); + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o instanceof javax.lang.model.element.AnnotationMirror) return internal.equals(o); + if (o == null || getClass() != o.getClass()) return false; + + ConvertAnnotationMirror that = (ConvertAnnotationMirror) o; + + return internal.equals(that.internal); + } + + @Override + public int hashCode() { + return internal.hashCode(); + } + + @Override + public String toString() { + return internal.toString(); + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeDeclaration.java b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeDeclaration.java new file mode 100755 index 0000000..7db9346 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeDeclaration.java @@ -0,0 +1,60 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.declaration; + +import com.sun.mirror.declaration.AnnotationTypeElementDeclaration; +import com.moparisthebest.mirror.log.Debug; + +import javax.lang.model.element.TypeElement; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class ConvertAnnotationTypeDeclaration extends ConvertInterfaceDeclaration + implements com.sun.mirror.declaration.AnnotationTypeDeclaration + // , ConvertableIface +{ + + protected ConvertAnnotationTypeDeclaration(TypeElement internalTypeElement) { + super(internalTypeElement); + } + + @Override + @SuppressWarnings({"unchecked"}) + public Collection getMethods() { + Debug.implemented("Collection"); + Collection superMethods = (Collection) super.getMethods(); + List ret = new ArrayList(superMethods.size()); + for (ConvertMethodDeclaration item : superMethods) + if (item instanceof AnnotationTypeElementDeclaration) + ret.add((AnnotationTypeElementDeclaration) item); + else + ret.add(new ConvertAnnotationTypeElementDeclaration(item.internalExecutableElement)); + //org.apache.beehive.netui.pageflow.annotations.Jpf.SimpleAction + if (Debug.debug) { + System.err.println("TypeElement: " + internalTypeElement); + System.err.println("ret: " + ret); + System.err.println("unfiltered: " + superMethods); + //System.err.println("filtered: "+InstanceFilter.listFilter(superMethods, AnnotationTypeElementDeclaration.class)); + } + return sort(ret);// or not to sort? + //return InstanceFilter.listFilter(superMethods, AnnotationTypeElementDeclaration.class); + //return (Collection)superMethods; + } +} diff --git a/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeElementDeclaration.java b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeElementDeclaration.java new file mode 100755 index 0000000..45123a8 --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationTypeElementDeclaration.java @@ -0,0 +1,47 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.declaration; + +import com.moparisthebest.mirror.log.Debug; +import com.sun.mirror.declaration.AnnotationTypeDeclaration; +import com.sun.mirror.declaration.AnnotationValue; + +import javax.lang.model.element.ExecutableElement; + +public class ConvertAnnotationTypeElementDeclaration extends ConvertMethodDeclaration implements com.sun.mirror.declaration.AnnotationTypeElementDeclaration { + + protected ConvertAnnotationTypeElementDeclaration(ExecutableElement internalExecutableElement) { + super(internalExecutableElement); + } + + @Override + public AnnotationValue getDefaultValue() { + Debug.implemented("AnnotationValue"); + return new ConvertAnnotationValue(internalExecutableElement.getDefaultValue()); + } + + @Override + public AnnotationTypeDeclaration getDeclaringType() { + Debug.implemented("AnnotationTypeDeclaration"); + ConvertTypeDeclaration ret = (ConvertTypeDeclaration) super.getDeclaringType(); + if (ret instanceof AnnotationTypeDeclaration) + return (AnnotationTypeDeclaration) ret; + return new ConvertAnnotationTypeDeclaration(ret.internalTypeElement);// todo: no idea why I have to do this, returns ClassTypeDeclaration + } +} \ No newline at end of file diff --git a/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationValue.java b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationValue.java new file mode 100755 index 0000000..f6a8ede --- /dev/null +++ b/core/src/main/java/com/moparisthebest/mirror/declaration/ConvertAnnotationValue.java @@ -0,0 +1,134 @@ +/* + * aptIn16 - Apt implementation with Java 6 annotation processors. + * Copyright (C) 2012 Travis Burtrum (moparisthebest) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published y + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.moparisthebest.mirror.declaration; + +import com.moparisthebest.mirror.convert.Convertable; +import com.moparisthebest.mirror.util.ConvertSourcePosition; +import com.sun.mirror.util.SourcePosition; +import com.moparisthebest.mirror.log.Debug; +import com.moparisthebest.mirror.type.ConvertTypeMirror; + +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.VariableElement; +import java.util.List; + +public class ConvertAnnotationValue extends Convertable implements com.sun.mirror.declaration.AnnotationValue { + private final javax.lang.model.element.AnnotationValue internal; + + protected ConvertAnnotationValue(AnnotationValue internal) { + this.internal = internal; + } + + private ConvertAnnotationValue() { + this.internal = null; + } + + public static Convertable getConvertable() { + return new ConvertAnnotationValue(); + } + + public static com.sun.mirror.declaration.AnnotationValue convert(F from) { + return convert(from, ConvertAnnotationValue.class); + } + + @SuppressWarnings({"unchecked"}) + public static T convert(F from, Class thisClass) { + return (T) new ConvertAnnotationValue(from); + } + + @Override + public com.sun.mirror.declaration.AnnotationValue convertToType(AnnotationValue from) { + return convert(from); + } + + @Override + public AnnotationValue unwrap() { + return internal; + } + + /** + * Returns the value. + * The result has one of the following types: + *