Source Code Cross Referenced for JavacRoundEnvironment.java in  » 6.0-JDK-Modules-com.sun » tools » com » sun » tools » javac » processing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » tools » com.sun.tools.javac.processing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.tools.javac.processing;
027:
028:        import java.lang.annotation.Annotation;
029:        import com.sun.tools.javac.util.*;
030:        import com.sun.tools.javac.comp.*;
031:        import com.sun.tools.javac.tree.JCTree.*;
032:        import javax.annotation.processing.*;
033:        import javax.lang.model.element.*;
034:        import javax.lang.model.type.DeclaredType;
035:        import javax.lang.model.type.TypeMirror;
036:        import javax.lang.model.util.*;
037:        import java.util.*;
038:
039:        /** 
040:         * Object providing state about a prior round of annotation processing.
041:         *
042:         * <p><b>This is NOT part of any API supported by Sun Microsystems.
043:         * If you write code that depends on this, you do so at your own risk.
044:         * This code and its internal interfaces are subject to change or
045:         * deletion without notice.</b>
046:         */
047:        @Version("@(#)JavacRoundEnvironment.java	1.13 07/05/05")
048:        public class JavacRoundEnvironment implements  RoundEnvironment {
049:            // Default equals and hashCode methods are okay.
050:
051:            private final boolean processingOver;
052:            private final boolean errorRaised;
053:            private final ProcessingEnvironment processingEnv;
054:
055:            // Caller must pass in an immutable set
056:            private final Set<? extends Element> rootElements;
057:
058:            JavacRoundEnvironment(boolean processingOver, boolean errorRaised,
059:                    Set<? extends Element> rootElements,
060:                    ProcessingEnvironment processingEnv) {
061:                this .processingOver = processingOver;
062:                this .errorRaised = errorRaised;
063:                this .rootElements = rootElements;
064:                this .processingEnv = processingEnv;
065:            }
066:
067:            public String toString() {
068:                return String.format(
069:                        "[errorRaised=%b, rootElements=%s, processingOver=%b]",
070:                        errorRaised, rootElements, processingOver);
071:            }
072:
073:            public boolean processingOver() {
074:                return processingOver;
075:            }
076:
077:            /**
078:             * Returns {@code true} if an error was raised in the prior round
079:             * of processing; returns {@code false} otherwise.
080:             * 
081:             * @return {@code true} if an error was raised in the prior round
082:             * of processing; returns {@code false} otherwise.
083:             */
084:            public boolean errorRaised() {
085:                return errorRaised;
086:            }
087:
088:            /**
089:             * Returns the type elements specified by the prior round.
090:             *
091:             * @return the types elements specified by the prior round, or an
092:             * empty set if there were none
093:             */
094:            public Set<? extends Element> getRootElements() {
095:                return rootElements;
096:            }
097:
098:            private static final String NOT_AN_ANNOTATION_TYPE = "The argument does not represent an annotation type: ";
099:
100:            /**
101:             * Returns the elements annotated with the given annotation type.
102:             * Only type elements <i>included</i> in this round of annotation
103:             * processing, or declarations of members, parameters, or type
104:             * parameters declared within those, are returned.  Included type
105:             * elements are {@linkplain #getSpecifiedTypeElements specified
106:             * types} and any types nested within them.
107:             *
108:             * @param a  annotation type being requested
109:             * @return the elements annotated with the given annotation type,
110:             * or an empty set if there are none
111:             */
112:            public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) {
113:                Set<Element> result = Collections.emptySet();
114:                if (a.getKind() != ElementKind.ANNOTATION_TYPE)
115:                    throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE
116:                            + a);
117:
118:                DeclaredType annotationTypeElement;
119:                TypeMirror tm = a.asType();
120:                if (tm instanceof  DeclaredType)
121:                    annotationTypeElement = (DeclaredType) a.asType();
122:                else
123:                    throw new AssertionError("Bad implementation type for "
124:                            + tm);
125:
126:                ElementScanner6<Set<Element>, DeclaredType> scanner = new AnnotationSetScanner(
127:                        result);
128:
129:                for (Element element : rootElements)
130:                    result = scanner.scan(element, annotationTypeElement);
131:
132:                return result;
133:            }
134:
135:            // Could be written as a local class inside getElementsAnnotatedWith
136:            private class AnnotationSetScanner extends
137:                    ElementScanner6<Set<Element>, DeclaredType> {
138:                // Insertion-order preserving set
139:                Set<Element> annotatedElements = new LinkedHashSet<Element>();
140:
141:                AnnotationSetScanner(Set<Element> defaultSet) {
142:                    super (defaultSet);
143:                }
144:
145:                @Override
146:                public Set<Element> scan(Element e, DeclaredType p) {
147:                    java.util.List<? extends AnnotationMirror> annotationMirrors = processingEnv
148:                            .getElementUtils().getAllAnnotationMirrors(e);
149:                    for (AnnotationMirror annotationMirror : annotationMirrors) {
150:                        if (annotationMirror.getAnnotationType().equals(p))
151:                            annotatedElements.add(e);
152:                    }
153:                    e.accept(this , p);
154:                    return annotatedElements;
155:                }
156:
157:            }
158:
159:            /**
160:             * {@inheritdoc}
161:             */
162:            public Set<? extends Element> getElementsAnnotatedWith(
163:                    Class<? extends Annotation> a) {
164:                if (!a.isAnnotation())
165:                    throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE
166:                            + a);
167:                String name = a.getCanonicalName();
168:                if (name == null)
169:                    return Collections.emptySet();
170:                else {
171:                    TypeElement annotationType = processingEnv
172:                            .getElementUtils().getTypeElement(name);
173:                    if (annotationType == null)
174:                        return Collections.emptySet();
175:                    else
176:                        return getElementsAnnotatedWith(annotationType);
177:                }
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.