You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/06/10 21:15:11 UTC
cvs commit: xml-xmlbeans/v2/jam/src15/org/apache/xmlbeans/impl/jam/internal/java15 Javadoc15DelegateImpl.java Reflect15DelegateImpl.java
pcal 2004/06/10 12:15:11
Modified: v2 build.xml
v2/jam build.xml
Added: v2/jam/src15/org/apache/xmlbeans/impl/jam/internal/java15
Javadoc15DelegateImpl.java
Reflect15DelegateImpl.java
Removed: v2/jam/src/org/apache/xmlbeans/impl/jam/internal/java15
Javadoc15DelegateImpl.java
Reflect15DelegateImpl.java
Log:
update javac targeting in build scripts, restructure 1.5-specific JAM sources
Revision Changes Path
1.66 +30 -26 xml-xmlbeans/v2/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- build.xml 10 Jun 2004 18:11:27 -0000 1.65
+++ build.xml 10 Jun 2004 19:15:11 -0000 1.66
@@ -1,6 +1,8 @@
<project name="Xbean" default="default" basedir=".">
<property name="build.compiler" value="javac1.4"/>
+ <property name="javac.source" value="1.4"/>
+ <property name="javac.target" value="1.4"/>
<property name="product.version" value="1.0.0"/>
<property name="jam_root" value="jam"/>
@@ -174,6 +176,7 @@
<target name="zipcompare.classes">
<mkdir dir="build/private/classes/zipcompare"/>
<javac srcdir="src/zipcompare"
+ source="${javac.source}" target="${javac.target}"
destdir="build/private/classes/zipcompare"
debug="on"/>
</target>
@@ -186,7 +189,7 @@
<property name="docs.dir" value="build/docs"/>
<delete dir="${docs.dir}"/>
<mkdir dir="${docs.dir}"/>
- <javadoc packagenames="*" sourcepath="src/xmlpublic" classpath="${javadoc.path}" destdir="${docs.dir}/reference" windowtitle="XMLBeans Documentation" source="1.4" stylesheetfile="docs/stylesheet.css">
+ <javadoc packagenames="*" sourcepath="src/xmlpublic" classpath="${javadoc.path}" destdir="${docs.dir}/reference" windowtitle="XMLBeans Documentation" source="${javac.source}" target="${javac.target}" stylesheetfile="docs/stylesheet.css">
<link href="http://e-docs.bea.com/wls/docs81/javadocs/"/>
<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
<link href="http://java.sun.com/j2ee/1.4/docs/api/"/>
@@ -320,6 +323,7 @@
<target name="xmlinputstream.classes" depends="dirs">
<mkdir dir="build/classes/xmlinputstream"/>
<javac srcdir="src/xmlinputstream"
+ source="${javac.source}" target="${javac.target}"
destdir="build/classes/xmlinputstream"
debug="on"/>
</target>
@@ -328,7 +332,7 @@
<target name="xmlpublic.classes" depends="dirs, xmlinputstream.classes, jsr173_api.jar">
<mkdir dir="build/classes/xmlpublic"/>
- <javac srcdir="src/xmlpublic" destdir="build/classes/xmlpublic" source="1.4" debug="on">
+ <javac srcdir="src/xmlpublic" destdir="build/classes/xmlpublic" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/classes/xmlinputstream"/>
<pathelement location="build/lib/jsr173_api.jar"/>
@@ -349,7 +353,7 @@
<target name="typestore.classes" depends="dirs, xmlpublic.classes, common.classes, xmlinputstream.classes">
<mkdir dir="build/classes/typestore"/>
- <javac srcdir="src/typestore" destdir="build/classes/typestore" source="1.4" debug="on">
+ <javac srcdir="src/typestore" destdir="build/classes/typestore" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/xmlinputstream"/>
@@ -364,7 +368,7 @@
<target name="common.classes" depends="dirs, xmlpublic.jar, xmlinputstream.classes, jsr173_api.jar">
<mkdir dir="build/classes/common"/>
- <javac srcdir="src/common" destdir="build/classes/common" source="1.4" debug="on">
+ <javac srcdir="src/common" destdir="build/classes/common" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/xmlinputstream"/>
@@ -380,7 +384,7 @@
repackage.classes, xmlpublic.classes, typestore.classes, xsdschema.classes,
configschema.classes, toolschema.classes, jsr173_api.jar, jam">
<mkdir dir="build/classes/typeimpl"/>
- <javac destdir="build/classes/typeimpl" source="1.4" debug="on">
+ <javac destdir="build/classes/typeimpl" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/classes/newstore2"/>
<pathelement location="build/classes/xmlstore"/>
@@ -417,7 +421,7 @@
<target name="xmlcomp.classes" depends="dirs, repackage.classes, typeimpl.classes, xmlpublic.classes, typestore.classes">
<mkdir dir="build/classes/xmlcomp"/>
- <javac srcdir="src/xmlcomp" destdir="build/classes/xmlcomp" source="1.4" debug="on">
+ <javac srcdir="src/xmlcomp" destdir="build/classes/xmlcomp" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/xmlinputstream"/>
@@ -437,7 +441,7 @@
<target name="binding.classes" depends="dirs, repackage.classes, typeimpl.classes, xmlpublic.classes, typestore.classes, configschema.classes, xmlcomp.classes, jam, jsr173.jar">
<mkdir dir="build/classes/binding"/>
- <javac srcdir="src/binding" destdir="build/classes/binding" source="1.4" debug="on">
+ <javac srcdir="src/binding" destdir="build/classes/binding" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/configschema"/>
@@ -482,7 +486,7 @@
<target name="marshal.classes" depends="dirs, binding.classes, typeimpl.classes, xmlpublic.classes, jsr173_api.jar">
<mkdir dir="build/classes/marshal"/>
- <javac srcdir="src/marshal" destdir="build/classes/marshal" source="1.4" debug="on">
+ <javac srcdir="src/marshal" destdir="build/classes/marshal" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/configschema"/>
@@ -502,7 +506,7 @@
<target name="xmlstore.classes"
depends="dirs, common.classes, typestore.classes, xmlpublic.classes">
<mkdir dir="build/classes/xmlstore"/>
- <javac srcdir="src/xmlstore" destdir="build/classes/xmlstore" source="1.4" debug="on">
+ <javac srcdir="src/xmlstore" destdir="build/classes/xmlstore" source="${javac.source}" target="${javac.target}" debug="on">
<classpath id="xmlstore.compile.path">
<pathelement location="build/lib/jsr173_api.jar"/>
<pathelement location="build/classes/xmlinputstream"/>
@@ -518,7 +522,7 @@
<target name="saaj_api.classes" depends="dirs">
<mkdir dir="build/classes/saaj_api"/>
- <javac srcdir="src/saaj_api" destdir="build/classes/saaj_api" source="1.4" debug="on">
+ <javac srcdir="src/saaj_api" destdir="build/classes/saaj_api" source="${javac.source}" target="${javac.target}" debug="on">
<classpath id="saaj_api.compile.path">
</classpath>
</javac>
@@ -530,7 +534,7 @@
<target name="newstore2.classes"
depends="dirs, common.classes, xmlpublic.classes, typestore.classes, saaj_api.classes">
<mkdir dir="build/classes/newstore2"/>
- <javac srcdir="src/newstore2" destdir="build/classes/newstore2" source="1.4" debug="on">
+ <javac srcdir="src/newstore2" destdir="build/classes/newstore2" source="${javac.source}" target="${javac.target}" debug="on">
<classpath id="newstore2.compile.path">
<pathelement location="build/classes/typestore"/>
<pathelement location="build/lib/jsr173_api.jar"/>
@@ -613,7 +617,7 @@
<target name="xmlconfig.classes" depends="dirs, xmlpublic.jar, configschema.classes">
<mkdir dir="build/classes/xmlconfig"/>
- <javac srcdir="src/xmlconfig" destdir="build/classes/xmlconfig" source="1.4" debug="on">
+ <javac srcdir="src/xmlconfig" destdir="build/classes/xmlconfig" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/lib/xmlpublic.jar"/>
<pathelement location="build/classes/configschema"/>
@@ -752,7 +756,7 @@
<target name="repackage.classes">
<mkdir dir="build/classes/repackage"/>
- <javac srcdir="src/repackage" destdir="build/classes/repackage" source="1.4" debug="on"/>
+ <javac srcdir="src/repackage" destdir="build/classes/repackage" source="${javac.source}" target="${javac.target}" debug="on"/>
</target>
<!-- xpath target ============================================= -->
@@ -763,7 +767,7 @@
srcdir="src/xpath"
destdir="build/classes/xpath"
classpathref="xpath.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on">
<classpath id="xpath.compile.path">
<pathelement location="build/classes/xmlpublic"/>
@@ -836,7 +840,7 @@
<javac
srcdir="test/cases/xbean/marshal"
destdir="build/private/classes/marshal"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on">
<classpath>
<pathelement location="build/classes/binding"/>
@@ -919,7 +923,7 @@
srcdir="test/src/drt"
destdir="build/private/classes/drt"
classpathref="test.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on"/>
</target>
@@ -1117,7 +1121,7 @@
<target name="extensions.compile" depends="build.simpleBeans, simpleBeans.check" unless="simpleBeans.notRequired">
<mkdir dir="build/test/extensions"/>
- <javac srcdir="test/src/extensions" destdir="build/test/extensions" debug="on">
+ <javac srcdir="test/src/extensions" destdir="build/test/extensions" debug="on" source="${javac.source}" target="${javac.target}">
<classpath>
<fileset refid="xbean.jars"/>
<fileset refid="extension.jars"/>
@@ -1182,7 +1186,7 @@
<mkdir dir="build/test/extensionsuse"/>
- <javac srcdir="test/src/extensionsuse" destdir="build/test/extensionsuse" debug="on">
+ <javac srcdir="test/src/extensionsuse" destdir="build/test/extensionsuse" debug="on" source="${javac.source}" target="${javac.target}">
<classpath>
<fileset refid="xbean.jars"/>
<pathelement location="external/lib/junit.jar"/>
@@ -1224,7 +1228,7 @@
srcdir="test/src/drt"
destdir="build/private/classes/drt"
classpathref="test.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on"/>
</target>
@@ -1257,7 +1261,7 @@
<!--
<target name="soaptest.classes" depends="dirs, stsschema.jar">
<mkdir dir="build/private/classes/soaptest"/>
- <javac srcdir="test/src/soaptest" destdir="build/private/classes/soaptest" source="1.4" debug="on">
+ <javac srcdir="test/src/soaptest" destdir="build/private/classes/soaptest" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="external/lib/jdom.jar"/>
<pathelement location="external/lib/junit.jar"/>
@@ -1278,7 +1282,7 @@
<!--
<target name="erictest.classes" depends="dirs, xbean, jsr173_api.jar">
<mkdir dir="build/private/classes/erictest"/>
- <javac srcdir="test/src/erictest" destdir="build/private/classes/erictest" source="1.4" debug="on">
+ <javac srcdir="test/src/erictest" destdir="build/private/classes/erictest" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/ar/xbean.jar"/>
<pathelement location="build/private/lib/ericschema.jar"/>
@@ -1299,7 +1303,7 @@
srcdir="test/src/random"
destdir="build/private/classes/random"
classpathref="test.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on"/>
</target>
@@ -1311,7 +1315,7 @@
<!--
<target name="teststore.classes" depends="dirs">
<mkdir dir="build/private/classes/teststore"/>
- <javac srcdir="test/src/teststore" destdir="build/private/classes/teststore" source="1.4" debug="on">
+ <javac srcdir="test/src/teststore" destdir="build/private/classes/teststore" source="${javac.source}" target="${javac.target}" debug="on">
<classpath>
<pathelement location="build/private/classes/simpletypes"/>
<pathelement location="build/private/classes/xmlcomp"/>
@@ -1432,7 +1436,7 @@
srcdir="test/src/streamtest"
destdir="build/private/classes/streamtest"
classpathref="test.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on"/>
</target>
@@ -1465,7 +1469,7 @@
srcdir="test/src/xpath"
destdir="build/private/classes/testxpath"
classpathref="testxpath.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on">
<classpath id="testxpath.compile.path">
<pathelement location="build/lib/xmlpublic.jar"/>
@@ -1498,7 +1502,7 @@
srcdir="test/cases/marshal"
destdir="build/private/classes/marshal"
classpathref="testmarshal.compile.path"
- source="1.4"
+ source="${javac.source}" target="${javac.target}"
debug="on">
<classpath id="testmarshal.compile.path">
<pathelement location="build/classes/binding"/>
1.20 +33 -14 xml-xmlbeans/v2/jam/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/jam/build.xml,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- build.xml 16 Apr 2004 21:37:01 -0000 1.19
+++ build.xml 10 Jun 2004 19:15:11 -0000 1.20
@@ -3,6 +3,7 @@
<property name='build_dir' value='../build/jam'/>
<property name='src_dir' value='src'/>
+ <property name='src15_dir' value='src15'/>
<property name="site_dir" value='website'/>
<property name='jam_jar' value='${build_dir}/jam.jar'/>
@@ -13,6 +14,12 @@
<property name='gen_dir' value='${build_dir}/generatedsrc'/>
<property name='classes_dir' value='${build_dir}/classes'/>
<property name='antlr_jar' value='external/lib/antlr.jar'/>
+ <property name='javac.source' value='1.34xxx'/>
+ <property name='javac.target' value='1.34xxx'/>
+
+
+
+
<!--FIXME need to do get the jar ourselves -->
<property name='staxapi_jar' value='../build/lib/jsr173_api.jar'/>
@@ -45,12 +52,15 @@
-->
</target>
-
- <target name='compile' depends='exclude15,jsr173,parser'>
+ <target name='compile' depends='jsr173,parser,compile14,
+ do15compile.check,compile15'/>
+
+ <target name='compile14'>
<mkdir dir='${classes_dir}'/>
<javac srcdir='${src_dir}' destdir='${classes_dir}'
- debug='on' excludes='${exclude15}'>
+ source='1.4' target='1.4'
+ debug='on'>
<src path='${src_dir}'/>
<src path='${gen_dir}'/>
<classpath>
@@ -60,10 +70,21 @@
<pathelement path='${java.class.path}'/>
</classpath>
</javac>
-
-
</target>
+ <target name='compile15' if='do15compile'>
+ <mkdir dir='${classes_dir}'/>
+ <javac srcdir='${src15_dir}' destdir='${classes_dir}'
+ source='1.5' target='1.5'
+ debug='on'>
+ <classpath>
+ <pathelement location='${antlr_jar}'/>
+ <pathelement location='${staxapi_jar}'/>
+ <pathelement path='${classes_dir}'/>
+ <pathelement path='${java.class.path}'/>
+ </classpath>
+ </javac>
+ </target>
<target name='jsr173'>
<ant dir='..' target='jsr173.jar' inheritAll='false' />
@@ -75,7 +96,7 @@
<ant dir='${tests_dir}' target='all' inheritAll='false' />
</target>
- <target name="javadocs" depends='compile'>
+ <target name='javadocs' depends='compile'>
<mkdir dir='${javadocbuild_dir}' />
<javadoc packagenames='*'
destdir='${javadocbuild_dir}'
@@ -127,6 +148,7 @@
<mkdir dir='${classes_dir}'/>
<javac srcdir='${src_dir}' destdir='${classes_dir}'
+ source='${javac.source}' target='${javac.target}'
includes='**/tools/*.java'/>
<java classname='org.apache.xmlbeans.impl.jam.tools.Repackage'
@@ -145,15 +167,16 @@
</ant>
</target>
- <target name='exclude15' depends='exclude15.check,exclude15.warn'/>
+ <target name='do15compile.check'
+ depends='do15compile.look,no15.warn'/>
- <target name='exclude15.check'>
- <condition property='exclude15'>
+ <target name='do15compile.look'>
+ <condition property='do15compile'>
<contains string='${java.version}' substring='1.5'/>
</condition>
</target>
- <target name='exclude15.warn' unless='exclude15'>
+ <target name='no15.warn' unless='do15compile'>
<echo message='======================================================'/>
<echo message='W A R N I N G: You are building JAM without JDK 1.5.'/>
<echo message='The resulting build of JAM will not support'/>
@@ -163,11 +186,7 @@
<echo message='JAM under 1.5.'/>
<echo message='======================================================'/>
- <!-- not clear why, but setting this value on the condition element
- above doesn't seem to work. so, just do it here -->
- <property name='exclude15' value='**/internal/java15/**/*.java'/>
</target>
-
1.1 xml-xmlbeans/v2/jam/src15/org/apache/xmlbeans/impl/jam/internal/java15/Javadoc15DelegateImpl.java
Index: Javadoc15DelegateImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.internal.java15;
import org.apache.xmlbeans.impl.jam.mutable.MAnnotatedElement;
import org.apache.xmlbeans.impl.jam.mutable.MAnnotation;
import org.apache.xmlbeans.impl.jam.internal.javadoc.Javadoc15Delegate;
import org.apache.xmlbeans.impl.jam.internal.javadoc.JavadocClassBuilder;
import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
import org.apache.xmlbeans.impl.jam.JClass;
import com.sun.javadoc.ProgramElementDoc;
import com.sun.javadoc.AnnotationDesc;
import com.sun.javadoc.Parameter;
import com.sun.javadoc.Type;
import com.sun.javadoc.AnnotationValue;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.SourcePosition;
import com.sun.javadoc.AnnotationTypeElementDoc;
import com.sun.javadoc.ExecutableMemberDoc;
/**
* @author Patrick Calahan <email: pcal-at-bea-dot-com>
*/
public class Javadoc15DelegateImpl implements Javadoc15Delegate {
// ========================================================================
// Variables
private ElementContext mContext = null;
// ========================================================================
// Javadoc15Delegate implementation
public void init(ElementContext ctx) {
if (mContext != null) {
throw new IllegalStateException("init called more than once");
}
mContext = ctx;
}
public void extractAnnotations(MAnnotatedElement dest,
ProgramElementDoc src) {
if (mContext == null) throw new IllegalStateException("init not called");
if (dest == null) throw new IllegalArgumentException("null dest");
if (src == null) throw new IllegalArgumentException("null src");
extractAnnotations(dest,src.annotations(),src.position());
}
public void extractAnnotations(MAnnotatedElement dest,
ExecutableMemberDoc method,
Parameter src)
{
// extractAnnotations(dest,src.annotations(),method.position());
//FIXME uncomment when SUN implements Parameter.annotations()
//
// [java] Exception in thread "main" java.lang.UnsupportedOperationException:
// Not implemented in this release
// [java] at com.sun.tools.javadoc.ParameterImpl.annotations(ParameterImpl.java:83)
}
public boolean isEnum(ClassDoc cd) {
return cd.isEnum();
}
// ========================================================================
// Private methods
private void extractAnnotations(MAnnotatedElement dest,
AnnotationDesc[] anns,
SourcePosition sp)
{
if (anns == null) return; //?
for(int i=0; i<anns.length; i++) {
MAnnotation destAnn = dest.findOrCreateAnnotation
(anns[i].annotationType().asClassDoc().qualifiedName());
populateAnnotation(destAnn,anns[i],sp);
}
}
private void populateAnnotation(MAnnotation dest,
AnnotationDesc src,
SourcePosition sp) {
if (sp != null) JavadocClassBuilder.addSourcePosition(dest,sp);
AnnotationDesc.ElementValuePair[] mvps = src.elementValues();
for(int i=0; i<mvps.length; i++) {
Type jmt = mvps[i].element().returnType();
String typeName = jmt.qualifiedTypeName();
String name = mvps[i].element().name();
AnnotationValue aval = mvps[i].value();
Object valueObj;
try {
valueObj = aval.value();
} catch(NullPointerException npe) {
//FIXME temporary workaround for sun bug
mContext.getLogger().warning
("Encountered a known javadoc bug which usually \n"+
"indicates a syntax error in an annotation value declaration.\n"+
"The value is being ignored.\n"+
"[file="+sp.file()+", line="+sp.line()+"]");
continue;
}
if (mContext.getLogger().isVerbose(this)) {
mContext.getLogger().verbose(name+" is a "+typeName+" with valueObj "+
valueObj+", class is "+valueObj.getClass());
}
// ok, take a look at how what it really is and translate it into an
// appropriate represenatation
if (valueObj instanceof AnnotationDesc) {
MAnnotation nested = dest.createNestedValue(name,typeName);
populateAnnotation(nested,(AnnotationDesc)valueObj,sp);
} else if (valueObj instanceof Number || valueObj instanceof Boolean) {
JClass type = mContext.getClassLoader().loadClass(jmt.typeName());
dest.setSimpleValue(name,valueObj,type);
} else if (valueObj instanceof FieldDoc) {
// this means it's an enum constant
JClass type = mContext.getClassLoader().loadClass
(((FieldDoc)valueObj).containingClass().qualifiedName());
String val = ((FieldDoc)valueObj).name(); //REVIEW is this right?
dest.setSimpleValue(name,val,type);
} else if (valueObj instanceof ClassDoc) {
JClass clazz = mContext.getClassLoader().loadClass
(((FieldDoc)valueObj).containingClass().qualifiedName());
dest.setSimpleValue(name,clazz,loadClass(JClass.class));
} else if (valueObj instanceof String) {
String v = ((String)valueObj).trim();
if (v.startsWith("\"") && v.endsWith("\"")) {
//javadoc gives us the quotes, which seems kinda dumb. just deal.
valueObj = v.substring(1,v.length()-1);
}
dest.setSimpleValue(name,valueObj,loadClass(String.class));
} else if (valueObj instanceof AnnotationValue[]) {
// this is another big chunk of work, just factored into a new
// method to keep things cleaner
populateArrayMember(dest,mvps[i].element(),(AnnotationValue[])valueObj,sp);
} else {
mContext.getLogger().error("Value of annotation member "+name+" is " +
"of an unexpected type: "+
valueObj.getClass()+" ["+valueObj+"]");
}
}
}
/**
*
* The javadocs for com.sun.javadoc.AnnotationValue.value() read as follows:
*
* <p><pre><i>
*
* Returns the value. The type of the returned object is one of the
* following:
*
* a wrapper class for a primitive type
* String
* ClassDoc
* FieldDoc (representing an enum constant)
* AnnotationDesc
* AnnotationValue[]
*
* </i></pre></p>
*
* <p>It seems quite broken to me that in the array case, it returns an array
* of AnnotationValues. It would be a lot easier to deal with the API
* if that last line instead read "or an array of any of the above."
* As it is, it's imposible to get the doclet API to give you a simple
* array of ints, for example. It's not at all clear what the extra
* wrapping buys you.</p>
*
* <p>So, this method does a bunch of work so that JAM does the unwrapping
* for the user.</p>
*/
private void populateArrayMember(MAnnotation dest,
AnnotationTypeElementDoc memberDoc,
AnnotationValue[] annValueArray,
SourcePosition sp)
{
if (sp != null) JavadocClassBuilder.addSourcePosition(dest,sp);
String memberName = memberDoc.name();
Type returnType = memberDoc.returnType();
if (annValueArray.length == 0) {
Object[] value = new Object[0];
//FIXME this is a little bit busted - we should try to give them
//more type information than this. it's just a little bit harder
//to figure it out from the javadoc objects
dest.setSimpleValue(memberName,value,
loadClass(returnType.qualifiedTypeName()));
return;
}
// unpack the AnnotationValue values into a single array.
Object[] valueArray = new Object[annValueArray.length];
for(int i=0; i<valueArray.length; i++) {
try {
valueArray[i] = annValueArray[i].value();
if (valueArray[i] == null) {
mContext.getLogger().error
("Javadoc provided an array annotation member value which contains "+
"[file="+sp.file()+", line="+sp.line()+"]");
return;
}
} catch(NullPointerException npe) {
//FIXME temporary workaround for sun bug
mContext.getLogger().warning
("Encountered a known javadoc bug which usually \n"+
"indicates a syntax error in an annotation value declaration.\n"+
"The value is being ignored.\n"+
"[file="+sp.file()+", line="+sp.line()+"]");
return;
}
}
// now go do something with them
if (valueArray[0] instanceof AnnotationDesc) {
String annType =
((AnnotationDesc)valueArray[0]).annotationType().qualifiedName();
MAnnotation[] anns = dest.createNestedValueArray
(memberName, annType, valueArray.length);
for(int i=0; i<anns.length; i++) {
populateAnnotation(anns[i],(AnnotationDesc)valueArray[i],sp);
}
} else if (valueArray[0] instanceof Number || valueArray[0] instanceof Boolean) {
JClass type = loadClass(JavadocClassBuilder.getFdFor(returnType));
dest.setSimpleValue(memberName,annValueArray,type);
} else if (valueArray[0] instanceof FieldDoc) {
// this means it's an array of an enum constants
String enumTypeName =
((FieldDoc)valueArray[0]).containingClass().qualifiedName();
JClass memberType = loadClass("[L"+enumTypeName+";");
String[] value = new String[valueArray.length];
for(int i=0; i<valueArray.length; i++) {
value[i] = ((FieldDoc)valueArray[i]).name(); //REVIEW is this right?
}
dest.setSimpleValue(memberName,value,memberType);
} else if (valueArray[0] instanceof ClassDoc) {
JClass[] value = new JClass[valueArray.length];
for(int i=0; i<value.length; i++) {
value[i] = loadClass(((ClassDoc)valueArray[0]).qualifiedName());
}
dest.setSimpleValue(memberName,value,loadClass(JClass[].class));
} else if (valueArray[0] instanceof String) {
String[] value = new String[valueArray.length];
for(int i=0; i<value.length; i++) {
String v = ((String)valueArray[i]).trim();
if (v.startsWith("\"") && v.endsWith("\"")) {
//javadoc gives us the quotes, which seems kinda dumb. just deal.
v = v.substring(1,v.length()-1);
}
value[i] = v;
}
dest.setSimpleValue(memberName,value,loadClass(String[].class));
} else {
mContext.getLogger().error("Value of array annotation member "+
memberName+" is of an unexpected type: "+
valueArray[0].getClass()+" ["+
valueArray[0]+"]");
}
}
private JClass loadClass(String fd) {
return mContext.getClassLoader().loadClass(fd);
}
//maybe we should put this on JamClassLoader?
private JClass loadClass(Class clazz) {
return loadClass(clazz.getName());
}
}
1.1 xml-xmlbeans/v2/jam/src15/org/apache/xmlbeans/impl/jam/internal/java15/Reflect15DelegateImpl.java
Index: Reflect15DelegateImpl.java
===================================================================
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.jam.internal.java15;
import org.apache.xmlbeans.impl.jam.internal.reflect.Reflect15Delegate;
import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
import org.apache.xmlbeans.impl.jam.mutable.MMember;
import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
import org.apache.xmlbeans.impl.jam.mutable.MField;
import org.apache.xmlbeans.impl.jam.mutable.MClass;
import org.apache.xmlbeans.impl.jam.mutable.MParameter;
import org.apache.xmlbeans.impl.jam.mutable.MAnnotatedElement;
import org.apache.xmlbeans.impl.jam.mutable.MAnnotation;
import org.apache.xmlbeans.impl.jam.JClass;
import org.apache.xmlbeans.impl.jam.provider.JamLogger;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.lang.annotation.Annotation;
/**
* @author Patrick Calahan <email: pcal-at-bea-dot-com>
*/
public class Reflect15DelegateImpl implements Reflect15Delegate {
// ========================================================================
// Variables
private ElementContext mContext = null;
private JamLogger mLogger = null;
// ========================================================================
// Reflect15Delegate implementation
public void init(ElementContext ctx) {
if (mContext != null) throw new IllegalStateException("init called twice");
mContext = ctx;
mLogger = mContext.getLogger();
}
public void extractAnnotations(MMember dest, Method src) {
Annotation[] anns = src.getDeclaredAnnotations();
if (anns == null) return;
extractAnnotations(dest,anns);
}
public void extractAnnotations(MConstructor dest, Constructor src) {
Annotation[] anns = src.getDeclaredAnnotations();
if (anns == null) return;
extractAnnotations(dest,anns);
}
public void extractAnnotations(MField dest, Field src) {
Annotation[] anns = src.getDeclaredAnnotations();
if (anns == null) return;
extractAnnotations(dest,anns);
}
public void extractAnnotations(MClass dest, Class src) {
Annotation[] anns = src.getDeclaredAnnotations();
if (anns == null) return;
extractAnnotations(dest,anns);
}
public void extractAnnotations(MParameter dest, Method src,
int paramNum) {
Annotation[][] anns;
try {
anns = src.getParameterAnnotations();
} catch(NullPointerException wtf) {
//FIXME workaround, sun code throws an NPE here
if (mLogger.isVerbose(this)) {
mLogger.verbose("ignoring unexpected error while calling Method.getParameterAnnotations():");
mLogger.verbose(wtf);
}
//wtf.printStackTrace();
return;
}
if (anns == null) return;
if (paramNum >= anns.length) {
if (mLogger.isVerbose(this)) {
mLogger.warning("method "+src.getName()+
" has fewer than expected parameter annotations ");
}
return;
}
extractAnnotations(dest,anns[paramNum]);
}
public void extractAnnotations(MParameter dest, Constructor src,
int paramNum) {
Annotation[][] anns;
try {
anns = src.getParameterAnnotations();
} catch(NullPointerException wtf) {
//FIXME workaround, sun code throws an NPE here
if (mLogger.isVerbose(this)) {
mLogger.verbose("ignoring unexpected error while calling Constructor.getParameterAnnotations():");
mLogger.verbose(wtf);
}
//wtf.printStackTrace();
return;
}
if (anns == null) return;
if (paramNum >= anns.length) {
if (mLogger.isVerbose(this)) {
mLogger.warning("constructor "+src.getName()+
" has fewer than expected parameter annotations ");
}
return;
}
extractAnnotations(dest,anns[paramNum]);
}
public boolean isEnum(Class clazz) { return clazz.isEnum(); }
// ========================================================================
// Private methods
private void extractAnnotations(MAnnotatedElement dest,
Annotation[] anns)
{
if (anns == null || anns.length == 0) return;
for(int i=0; i<anns.length; i++) {
MAnnotation destAnn = dest.findOrCreateAnnotation
(anns[i].annotationType().getName());
destAnn.setAnnotationInstance(anns[i]);
populateAnnotation(destAnn,anns[i]);
}
}
private void populateAnnotation(MAnnotation dest, Annotation src) {
boolean isVerbose = mLogger.isVerbose(this);
if (src == null) throw new IllegalArgumentException();
Class annType = src.annotationType();
if (isVerbose) mLogger.verbose("type is "+annType.getName());
//FIXME this is a bit clumsy right now - I think we need to be a little
// more surgical in identifying the annotation member methods
Method[] methods = annType.getMethods();
for(int i=0; i<methods.length; i++) {
if (isVerbose) mLogger.verbose("examining "+methods[i].toString());
int mods = methods[i].getModifiers();
if (Modifier.isStatic(mods)) continue;
if (!Modifier.isPublic(mods)) continue;
if (methods[i].getParameterTypes().length > 0) continue;
{
// try to limit it to real annotation methods.
// FIXME seems like this could be better
Class c = methods[i].getDeclaringClass();
if (Object.class.equals(c) || Annotation.class.equals(c)) {
continue;
}
}
try {
if (isVerbose) mLogger.verbose("invoking "+methods[i].getName()+"()");
Object value = methods[i].invoke(src,(Object[])null);
if (isVerbose) mLogger.verbose("value is "+value);
if (value instanceof Annotation) {
if (isVerbose) mLogger.verbose("it's nested!! creating for "+
methods[i].getName()+" and "+
annType.getName());
MAnnotation nested = dest.createNestedValue(methods[i].getName(),
annType.getName());
nested.setAnnotationInstance(value);
populateAnnotation(nested,(Annotation)value);
} else if (value instanceof Annotation[]) {
Annotation[] anns = (Annotation[])value;
MAnnotation[] nested = dest.createNestedValueArray
(methods[i].getName(),
methods[i].getReturnType().getComponentType().getName(),
anns.length);
for(int j=0; j<anns.length; j++) populateAnnotation(nested[j],anns[j]);
} else {
JClass type = mContext.getClassLoader().
loadClass(methods[i].getReturnType().getName());
dest.setSimpleValue(methods[i].getName(),value,type);
}
} catch (IllegalAccessException e) {
mLogger.warning(e);
} catch (InvocationTargetException e) {
mLogger.warning(e);
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org