src/share/jaxws_classes/com/sun/tools/internal/jxc/ap/AnnotationParser.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
24 */ 24 */
25 25
26 package com.sun.tools.internal.jxc.ap; 26 package com.sun.tools.internal.jxc.ap;
27 27
28 import com.sun.tools.internal.jxc.ConfigReader; 28 import com.sun.tools.internal.jxc.ConfigReader;
29 import com.sun.tools.internal.jxc.api.JXC;
29 import com.sun.tools.internal.xjc.ErrorReceiver; 30 import com.sun.tools.internal.xjc.ErrorReceiver;
30 import com.sun.tools.internal.xjc.api.J2SJAXBModel; 31 import com.sun.tools.internal.xjc.api.J2SJAXBModel;
31 import com.sun.tools.internal.xjc.api.Reference; 32 import com.sun.tools.internal.xjc.api.Reference;
32 import com.sun.tools.internal.xjc.api.XJC;
33 import org.xml.sax.SAXException; 33 import org.xml.sax.SAXException;
34 34
35 import javax.annotation.processing.AbstractProcessor; 35 import javax.annotation.processing.AbstractProcessor;
36 import javax.annotation.processing.ProcessingEnvironment; 36 import javax.annotation.processing.ProcessingEnvironment;
37 import javax.annotation.processing.RoundEnvironment; 37 import javax.annotation.processing.RoundEnvironment;
38 import javax.annotation.processing.SupportedAnnotationTypes; 38 import javax.annotation.processing.SupportedAnnotationTypes;
39 import javax.annotation.processing.SupportedOptions; 39 import javax.annotation.processing.SupportedOptions;
40 import javax.annotation.processing.SupportedSourceVersion;
41 import javax.lang.model.SourceVersion; 40 import javax.lang.model.SourceVersion;
42 import javax.lang.model.element.Element; 41 import javax.lang.model.element.Element;
43 import javax.lang.model.element.ElementKind; 42 import javax.lang.model.element.ElementKind;
44 import javax.lang.model.element.TypeElement; 43 import javax.lang.model.element.TypeElement;
45 import javax.lang.model.util.ElementFilter; 44 import javax.lang.model.util.ElementFilter;
48 import java.io.File; 47 import java.io.File;
49 import java.io.IOException; 48 import java.io.IOException;
50 import java.util.ArrayList; 49 import java.util.ArrayList;
51 import java.util.Collection; 50 import java.util.Collection;
52 import java.util.Collections; 51 import java.util.Collections;
53 import java.util.List;
54 import java.util.Set; 52 import java.util.Set;
55 import java.util.StringTokenizer; 53 import java.util.StringTokenizer;
56 54
57 /** 55 /**
58 * This class behaves as a JAXB Annotation Processor, 56 * This class behaves as a JAXB Annotation Processor,
59 * It reads the user specified typeDeclarations 57 * It reads the user specified typeDeclarations
60 * and the config files 58 * and the config files
61 * It also reads config files 59 * It also reads config files
62 * 60 *
61 * Used in unit tests
62 *
63 * @author Bhakti Mehta (bhakti.mehta@sun.com) 63 * @author Bhakti Mehta (bhakti.mehta@sun.com)
64 */ 64 */
65 @SupportedAnnotationTypes("javax.xml.bind.annotation.*") 65 @SupportedAnnotationTypes("javax.xml.bind.annotation.*")
66 @SupportedOptions("jaxb.config") // Const.CONFIG_FILE_OPTION.getValue() 66 @SupportedOptions("jaxb.config")
67 @SupportedSourceVersion(SourceVersion.RELEASE_6)
68 public final class AnnotationParser extends AbstractProcessor { 67 public final class AnnotationParser extends AbstractProcessor {
69 68
70 private ErrorReceiver errorListener; 69 private ErrorReceiver errorListener;
71 70
72 @Override 71 @Override
108 configFile, 107 configFile,
109 errorListener 108 errorListener
110 ); 109 );
111 110
112 Collection<Reference> classesToBeIncluded = configReader.getClassesToBeIncluded(); 111 Collection<Reference> classesToBeIncluded = configReader.getClassesToBeIncluded();
113 J2SJAXBModel model = XJC.createJavaCompiler().bind( 112 J2SJAXBModel model = JXC.createJavaCompiler().bind(
114 classesToBeIncluded, Collections.<QName, Reference>emptyMap(), null, processingEnv); 113 classesToBeIncluded, Collections.<QName, Reference>emptyMap(), null, processingEnv);
115 114
116 SchemaOutputResolver schemaOutputResolver = configReader.getSchemaOutputResolver(); 115 SchemaOutputResolver schemaOutputResolver = configReader.getSchemaOutputResolver();
117 116
118 model.generateSchema(schemaOutputResolver, errorListener); 117 model.generateSchema(schemaOutputResolver, errorListener);
126 return true; 125 return true;
127 } 126 }
128 127
129 private void filterClass(Collection<TypeElement> rootElements, Collection<? extends Element> elements) { 128 private void filterClass(Collection<TypeElement> rootElements, Collection<? extends Element> elements) {
130 for (Element element : elements) { 129 for (Element element : elements) {
131 if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.INTERFACE)) { 130 if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.INTERFACE) ||
131 element.getKind().equals(ElementKind.ENUM)) {
132 rootElements.add((TypeElement) element); 132 rootElements.add((TypeElement) element);
133 filterClass(rootElements, ElementFilter.typesIn(element.getEnclosedElements())); 133 filterClass(rootElements, ElementFilter.typesIn(element.getEnclosedElements()));
134 } 134 }
135 } 135 }
136 } 136 }
137
138 @Override
139 public SourceVersion getSupportedSourceVersion() {
140 if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_6) > 0)
141 return SourceVersion.valueOf("RELEASE_7");
142 else
143 return SourceVersion.RELEASE_6;
144 }
137 } 145 }

mercurial