Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PackageImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PackageImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PackageImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PackageImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,80 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.mutable.MPackage;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * <p>Generic implementation of JPackage/InternalJPackage that is good
+ * enough for all samples, right now. This might change if we ever wrap
+ * a model which natively supports package-level annotation.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class PackageImpl extends AnnotatedElementImpl implements MPackage {
+
+ // ========================================================================
+ // Variables
+
+ private List mRootClasses = new ArrayList();
+ private String mName;
+
+ // ========================================================================
+ // Constructors
+
+ public PackageImpl(ElementContext ctx, String name) {
+ super(ctx);
+ mName = name;
+ int lastDot = mName.lastIndexOf('.');
+ setSimpleName((lastDot == -1) ? mName : mName.substring(lastDot + 1));
+ }
+
+ // ========================================================================
+ // JElement implementation
+
+ public String getQualifiedName() { return mName; }
+
+ public void accept(MVisitor visitor) { visitor.visit(this); }
+
+ public void accept(JVisitor visitor) { visitor.visit(this); }
+
+ // ========================================================================
+ // JPackage implementation
+
+ public JClass[] getClasses() {
+ JClass[] out = new JClass[mRootClasses.size()];
+ mRootClasses.toArray(out);
+ return out;
+ }
+
+ // ========================================================================
+ // MPackage implementation
+
+ public MClass[] getMutableClasses() {
+ MClass[] out = new MClass[mRootClasses.size()];
+ mRootClasses.toArray(out);
+ return out;
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ParameterImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ParameterImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ParameterImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/ParameterImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,92 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.DirectJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.UnqualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MParameter;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+/**
+ * <p>Implementation of JParameter and MParameter.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class ParameterImpl extends MemberImpl implements MParameter {
+
+ // ========================================================================
+ // Variables
+
+ private JClassRef mTypeClassRef;
+
+ // ========================================================================
+ // Constructors
+
+ /*package*/ ParameterImpl(String simpleName,
+ InvokableImpl containingMember,
+ String typeName)
+ {
+ super(containingMember);
+ setSimpleName(simpleName);
+ setType(typeName);
+ }
+
+ // ========================================================================
+ // JElement implementation
+
+ public String getQualifiedName() {
+ return getSimpleName();//FIXME
+ }
+
+ // ========================================================================
+ // MParameter implementation
+
+ public void setType(String qcname) {
+ if (qcname == null) throw new IllegalArgumentException("null typename");
+ mTypeClassRef = QualifiedJClassRef.create
+ (qcname,(ClassImpl)getContainingClass());
+ }
+
+ public void setType(JClass qcname) {
+ if (qcname == null) throw new IllegalArgumentException("null qcname");
+ mTypeClassRef = DirectJClassRef.create(qcname);
+ }
+
+ public void setUnqualifiedType(String ucname) {
+ if (ucname == null) throw new IllegalArgumentException("null ucname");
+ mTypeClassRef = UnqualifiedJClassRef.create
+ (ucname,(ClassImpl)getContainingClass());
+ }
+
+ // ========================================================================
+ // JParameter implementation
+
+ public JClass getType() {
+ return mTypeClassRef.getRefClass();
+ }
+
+ // ========================================================================
+ // JElement implementation
+
+ public void accept(MVisitor visitor) { visitor.visit(this); }
+
+ public void accept(JVisitor visitor) { visitor.visit(this); }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PrimitiveClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PrimitiveClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PrimitiveClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PrimitiveClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,161 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>JClass implementation for primitive types.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public final class PrimitiveClassImpl extends BuiltinClassImpl {
+
+ // ========================================================================
+ // Constants
+
+ private static final Object[][] PRIMITIVES = {
+ // Name FD Class
+ {"int", "I", int.class},
+ {"long", "J", long.class},
+ {"boolean", "Z", boolean.class},
+ {"short", "S", short.class},
+ {"byte", "B", byte.class},
+ {"char", "C", char.class},
+ {"float", "F", float.class},
+ {"double", "D", double.class},
+ };
+
+ private static final Map NAME_TO_FD, NAME_TO_CLASS;
+
+ static {
+ NAME_TO_FD = new HashMap();
+ NAME_TO_CLASS = new HashMap();
+ for (int i = 0; i < PRIMITIVES.length; i++) {
+ NAME_TO_FD.put(PRIMITIVES[i][0],PRIMITIVES[i][1]);
+ NAME_TO_CLASS.put(PRIMITIVES[i][0],PRIMITIVES[i][2]);
+ }
+ };
+
+ // ========================================================================
+ // Factory methods
+
+ public static void mapNameToPrimitive(ElementContext ctx, Map out) {
+ for(int i=0; i<PrimitiveClassImpl.PRIMITIVES.length; i++) {
+ JClass c = new PrimitiveClassImpl(ctx,(String)PRIMITIVES[i][0]);
+ out.put(PrimitiveClassImpl.PRIMITIVES[i][0],c);
+ out.put(PrimitiveClassImpl.PRIMITIVES[i][1],c);
+ // REVIEW we map both the name and the fd to the class. does that
+ // seem ok?
+ }
+ }
+
+ /**
+ * Returns the field descriptor for an named primitive, e.g. 'I' for
+ * 'int', or null if the parameter does not name a primitive.
+ */
+ public static String getPrimitiveClassForName(String named) {
+ return (String)NAME_TO_FD.get(named);
+ }
+
+ /**
+ * Returns a JClass representing the named primitive type. The name
+ * parameter can be a simple type name (e.g. 'int') or a field
+ * descriptor (e.g. 'I'). Returns null if the parameter does not
+ * name a primitive type.
+ */
+/* public static JClass getPrimitiveClassForName(String named) {
+ JClass out = (JClass) NAME_TO_JCLASS.get(named);
+ if (out != null) return out;
+ return (JClass) FD_TO_JCLASS.get(named);
+ }*/
+
+ /**
+ * Returns a JClass representing the given primitive Class. Returns
+ * null if the parameter is not a primitive class.
+ */
+ /*public static JClass getPrimitiveClass(Class clazz) {
+ return getPrimitiveClassForName(clazz.getName());
+ }*/
+
+ // ========================================================================
+ // Public static utilities
+
+ /**
+ * Returns true if the named type is a primitive. The parameter can
+ * be a simple type name (e.g. 'int') or a field descriptor
+ * (e.g. 'I').
+ */
+ public static boolean isPrimitive(String name) {
+ return (NAME_TO_FD.get(name) != null);
+ }
+
+ /**
+ * Returns the field descriptor for the given name, e.g. 'int' returns
+ * 'I'.
+ */
+ public static final String getFieldDescriptor(String classname) {
+ return (String)NAME_TO_FD.get(classname);
+ }
+
+
+ /**
+ * Returns the primitve class for the given name, e.g. 'int' returns
+ * int.class. It's really stupid that there isn't a way to deal
+ * with this built in to java.
+ */
+ public static final Class getPrimitiveClass(String classname) {
+ return (Class)NAME_TO_CLASS.get(classname);
+ }
+
+ // ========================================================================
+ // Constructors
+
+ private PrimitiveClassImpl(ElementContext ctx, String name) {
+ super(ctx);
+ if (name == null) throw new IllegalArgumentException("null name");
+ if (!NAME_TO_FD.containsKey(name)) {
+ throw new IllegalArgumentException("Unknown primitive class '"+
+ name+"'");
+ }
+ reallySetSimpleName(name);
+ }
+
+ // ========================================================================
+ // JElement implementation
+
+ public String getQualifiedName() { return getSimpleName(); }
+
+ // ========================================================================
+ // JClass implementation
+
+ public String getFieldDescriptor() {
+ return (String)NAME_TO_FD.get(getSimpleName());
+ }
+
+ public boolean isAssignableFrom(JClass c) {
+ return c.isPrimitiveType() && c.getSimpleName().equals(getSimpleName());
+ }
+
+ public boolean isPrimitiveType() { return true; }
+
+ public Class getPrimitiveClass() {
+ return (Class)NAME_TO_CLASS.get(getSimpleName());
+ }
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/PropertyImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,225 @@
+/* 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.elements;
+
+
+import org.apache.xmlbeans.impl.jam.JAnnotation;
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JComment;
+import org.apache.xmlbeans.impl.jam.JMethod;
+import org.apache.xmlbeans.impl.jam.JProperty;
+import org.apache.xmlbeans.impl.jam.JSourcePosition;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
+import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.visitor.JVisitor;
+import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
+
+/**
+ * <p>Implementation of JProperty.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class PropertyImpl extends AnnotatedElementImpl implements JProperty {
+
+ // ========================================================================
+ // Variables
+
+ private String mName;
+ private JMethod mGetter, mSetter;
+ private JClassRef mTypeRef;
+
+ // ========================================================================
+ // Constructor
+
+ /**
+ * <p>You'll usually want to use the getProperties() factory method
+ * instead of constructing JProperties yourself. This constructor
+ * is exposed just in case the default rules in the factory method
+ * for identifying properties are insufficient for some use
+ * case.</p>
+ *
+ */
+ public PropertyImpl(String name,
+ JMethod getter,
+ JMethod setter,
+ String qualifiedTypeName)
+ {
+ super((ElementImpl)
+ ((getter != null) ? getter.getParent() : setter.getParent()));
+ //FIXME should do more validation on the arguments
+ mName = name;
+ mGetter = getter;
+ mSetter = setter;
+ ClassImpl cont = (ClassImpl)((getter != null) ?
+ getter.getContainingClass() : setter.getContainingClass());
+ mTypeRef = QualifiedJClassRef.create(qualifiedTypeName,cont);
+ initAnnotations();
+ }
+
+ // ========================================================================
+ // Public methods
+
+ /**
+ * Returns a JClass which represents the type of this property.
+ */
+ public JClass getType() { return mTypeRef.getRefClass(); }
+
+ /**
+ * Returns the simple name of this property. For example, for a
+ * property manifest by getFoo() and setFoo(), this will return
+ * 'foo'.
+ */
+ public String getSimpleName() { return mName; }
+
+
+ /**
+ * Returns the simple name of this property. For example, for a
+ * property manifest by getFoo() and setFoo(), this will return
+ * 'foo'.
+ */
+ public String getQualifiedName() {
+ return getParent().getQualifiedName()+"."+getSimpleName(); //REVIEW
+ }
+
+ /**
+ * Returns a JMethod which represents the setter for this property.
+ * Returns null if this property is view-only.
+ */
+ public JMethod getSetter() { return mSetter; }
+
+ /**
+ * Returns a JMethod which represents the getter for this property.
+ * Returns null if this property is write-only.
+ */
+ public JMethod getGetter() { return mGetter; }
+
+ // ========================================================================
+ // JElement implementation
+
+ /**
+ * Returns all of the annotations on the getter and/or the setter
+ * methods.
+ */
+ public JAnnotation[] getAnnotations() {
+ return combine((mGetter == null) ?
+ ElementImpl.NO_ANNOTATION : mGetter.getAnnotations(),
+ (mSetter == null) ?
+ ElementImpl.NO_ANNOTATION : mSetter.getAnnotations());
+ }
+
+ /**
+ * Returns annotations with the given name that are found on this
+ * property's getter and/or setter.
+
+ public JAnnotation[] getAnnotations(String named) {
+ return combine((mGetter == null) ?
+ BaseJElement.NO_ANNOTATION : mGetter.getAnnotations(named),
+ (mSetter == null) ?
+ BaseJElement.NO_ANNOTATION : mSetter.getAnnotations(named));
+ }
+ */
+
+ //internal use only
+ public void setSetter(JMethod method) { mSetter = method; }
+
+ //internal use only
+ public void setGetter(JMethod method) { mGetter = method; }
+
+ /**
+ * Returns the first annotation with the given name that is found on
+ * this property's getter and/or setters.
+ */
+ public JAnnotation getAnnotation(String named) {
+ JAnnotation out = (mGetter != null) ? mGetter.getAnnotation(named) : null;
+ if (out != null) return out;
+ return (mSetter != null) ? mSetter.getAnnotation(named) : null;
+ }
+
+ public JComment getComment() {
+ //REVIEW do we want to somehow merge the comments?
+ if (mGetter != null) return mGetter.getComment();
+ if (mSetter != null) return mSetter.getComment();
+ return null;
+ }
+
+ public JSourcePosition getSourcePosition() {
+ return mGetter != null ?
+ mGetter.getSourcePosition() : mSetter.getSourcePosition();
+ }
+
+ public void accept(JVisitor visitor) {
+ if (mGetter != null) visitor.visit(mGetter);
+ if (mSetter != null) visitor.visit(mSetter);
+ }
+
+ // ========================================================================
+ // Object implementation
+
+ public String toString() { return getQualifiedName(); }
+
+ // ========================================================================
+ // Private methods
+
+ private void initAnnotations() {
+ if (mSetter != null) {
+ JAnnotation[] anns = mSetter.getAnnotations();
+ for(int i=0; i<anns.length; i++) super.addAnnotation(anns[i]);
+ anns = mSetter.getAllJavadocTags();
+ for(int i=0; i<anns.length; i++) super.addAnnotation(anns[i]);
+ }
+ if (mGetter != null) {
+ JAnnotation[] anns = mGetter.getAnnotations();
+ for(int i=0; i<anns.length; i++) super.addAnnotation(anns[i]);
+ anns = mGetter.getAllJavadocTags();
+ for(int i=0; i<anns.length; i++) super.addAnnotation(anns[i]);
+ }
+ }
+
+
+ /**
+ * Returns an array that is the union of the two arrays of
+ * anotations.
+ */
+ private JAnnotation[] combine(JAnnotation[] a, JAnnotation[] b) {
+ if (a.length == 0) return b;
+ if (b.length == 0) return a;
+ JAnnotation[] out = new JAnnotation[a.length+b.length];
+ System.arraycopy(a,0,out,0,a.length);
+ System.arraycopy(b,0,out,a.length,b.length);
+ return out;
+ }
+
+ /**
+ * Returns an array that is the union of the two arrays of
+ * anotations.
+ */
+ private JComment[] combine(JComment[] a, JComment[] b) {
+ if (a.length == 0) return b;
+ if (b.length == 0) return a;
+ JComment[] out = new JComment[a.length+b.length];
+ System.arraycopy(a,0,out,0,a.length);
+ System.arraycopy(b,0,out,a.length,b.length);
+ return out;
+ }
+
+ public void accept(MVisitor visitor) {
+ //review this is kinda broken
+ if (mGetter != null) visitor.visit((MMethod)mGetter);
+ if (mSetter != null) visitor.visit((MMethod)mSetter);
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/SourcePositionImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/SourcePositionImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/SourcePositionImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/SourcePositionImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,58 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.mutable.MSourcePosition;
+
+import java.net.URI;
+
+/**
+ * <p>Implementation of JSourcePosition and MSourcePosition.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public final class SourcePositionImpl implements MSourcePosition {
+
+ // ========================================================================
+ // Variables
+
+ private int mColumn = -1;
+ private int mLine = -1;
+ private URI mURI = null;
+
+ // ========================================================================
+ // Constructors
+
+ /*package*/ SourcePositionImpl() {}
+
+ // ========================================================================
+ // MSourcePosition implementation
+
+ public void setColumn(int col) { mColumn = col; }
+
+ public void setLine(int line) { mLine = line; }
+
+ public void setSourceURI(URI uri) { mURI = uri; }
+
+ // ========================================================================
+ // JSourcePosition implementation
+
+ public int getColumn() { return mColumn; }
+
+ public int getLine() { return mLine; }
+
+ public URI getSourceURI() { return mURI; }
+}
\ No newline at end of file
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/UnresolvedClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/UnresolvedClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/UnresolvedClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/UnresolvedClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,61 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+import org.apache.xmlbeans.impl.jam.JPackage;
+
+/**
+ * <p>This is the JClass that is returned when a java type cannot be
+ * resolved. It has only a name.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public final class UnresolvedClassImpl extends BuiltinClassImpl {
+
+ // ========================================================================
+ // Variables
+
+ private String mPackageName;
+
+ // ========================================================================
+ // Constructor
+
+ public UnresolvedClassImpl(String packageName,
+ String simpleName,
+ ElementContext ctx) {
+ super(ctx);
+ if (packageName == null) throw new IllegalArgumentException("null pkg");
+ mPackageName = packageName;
+ reallySetSimpleName(simpleName);
+ }
+
+ // ========================================================================
+ // JClass elements
+
+ public String getQualifiedName() {
+ return ((mPackageName.length() > 0) ? (mPackageName + '.') : "") +
+ mSimpleName;
+ }
+
+ public String getFieldDescriptor() { return getQualifiedName(); }
+
+ public JPackage getContainingPackage() { return null; }
+
+ public boolean isAssignableFrom(JClass c) { return false; }
+
+ public boolean isUnresolvedType() { return true; }
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/VoidClassImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/VoidClassImpl.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/VoidClassImpl.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/elements/VoidClassImpl.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,53 @@
+/* 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.elements;
+
+import org.apache.xmlbeans.impl.jam.JClass;
+
+/**
+ * <p>Class implementation to represent the 'void' type.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public final class VoidClassImpl extends BuiltinClassImpl {
+
+ // ========================================================================
+ // Constants
+
+ private static final String SIMPLE_NAME = "void";
+
+// ========================================================================
+ // Public static utilities
+
+ public static boolean isVoid(String fd) {
+ return fd.equals(SIMPLE_NAME);
+ }
+
+ // ========================================================================
+ // Singleton
+
+ public VoidClassImpl(ElementContext ctx) {
+ super(ctx);
+ super.reallySetSimpleName(SIMPLE_NAME);
+ }
+
+ // ========================================================================
+ // JClass implementation
+
+ public boolean isVoidType() { return true; }
+
+ public boolean isAssignableFrom(JClass c) { return false; }
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassBuilder.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,394 @@
+/* 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.javadoc;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.ConstructorDoc;
+import com.sun.javadoc.Doc;
+import com.sun.javadoc.ExecutableMemberDoc;
+import com.sun.javadoc.FieldDoc;
+import com.sun.javadoc.MethodDoc;
+import com.sun.javadoc.PackageDoc;
+import com.sun.javadoc.Parameter;
+import com.sun.javadoc.ProgramElementDoc;
+import com.sun.javadoc.RootDoc;
+import com.sun.javadoc.SourcePosition;
+import com.sun.javadoc.Tag;
+import com.sun.javadoc.Type;
+import org.apache.xmlbeans.impl.jam.annotation.JavadocTagParser;
+import org.apache.xmlbeans.impl.jam.internal.JamServiceContextImpl;
+import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
+import org.apache.xmlbeans.impl.jam.internal.elements.PrimitiveClassImpl;
+import org.apache.xmlbeans.impl.jam.mutable.MAnnotatedElement;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.mutable.MElement;
+import org.apache.xmlbeans.impl.jam.mutable.MField;
+import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.mutable.MParameter;
+import org.apache.xmlbeans.impl.jam.mutable.MSourcePosition;
+import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
+import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
+import org.apache.xmlbeans.impl.jam.provider.JamServiceContext;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class JavadocClassBuilder extends JamClassBuilder implements JamClassPopulator {
+
+ // ========================================================================
+ // Constants
+
+ public static final String ARGS_PROPERTY = "javadoc.args";
+ public static final String PARSETAGS_PROPERTY = "javadoc.parsetags";
+
+ // ========================================================================
+ // Variables
+
+ private RootDoc mRootDoc = null;
+ private JavadocTigerDelegate mTigerDelegate = null;
+ private JavadocTagParser mTagParser = null;
+ private boolean mParseTags = true;//FIXME
+
+ // ========================================================================
+ // Constructors
+
+ public JavadocClassBuilder() {}
+
+ // ========================================================================
+ // JamClassBuilder implementation
+
+ public void init(ElementContext ctx) {
+ if (ctx == null) throw new IllegalArgumentException("null context");
+ super.init(ctx);
+ getLogger().verbose("init()",this);
+ initDelegate(ctx);
+ initJavadoc((JamServiceContext)ctx); //dirty cast because we're 'built in'
+ }
+
+
+ public MClass build(String packageName, String className) {
+ assertInitialized();
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("trying to build '"+packageName+"' '"+className+"'");
+ }
+ String loadme = (packageName.trim().length() > 0) ?
+ (packageName + '.' + className) :
+ className;
+ ClassDoc cd = mRootDoc.classNamed(loadme);
+ if (cd == null) {
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("no ClassDoc for "+loadme);
+ }
+ return null;
+ }
+ List importSpecs = null;
+ {
+ ClassDoc[] imported = cd.importedClasses();
+ if (imported != null) {
+ importSpecs = new ArrayList();
+ for(int i=0; i<imported.length; i++) {
+ importSpecs.add(getFdFor(imported[i]));
+ }
+ }
+ }
+ {
+ PackageDoc[] imported = cd.importedPackages();
+ if (imported != null) {
+ if (importSpecs == null) importSpecs = new ArrayList();
+ for(int i=0; i<imported.length; i++) {
+ importSpecs.add(imported[i].name()+".*");
+ }
+ }
+ }
+ String[] importSpecsArray = null;
+ if (importSpecs != null) {
+ importSpecsArray = new String[importSpecs.size()];
+ importSpecs.toArray(importSpecsArray);
+ }
+ MClass out = createClassToBuild(packageName, className, importSpecsArray, this);
+ out.setArtifact(cd);
+ return out;
+ }
+
+ // ========================================================================
+ // JamClassPopulator implementation
+
+ public void populate(MClass dest) {
+ if (dest == null) throw new IllegalArgumentException("null dest");
+ assertInitialized();
+ ClassDoc src = (ClassDoc)dest.getArtifact();
+ if (src == null) throw new IllegalStateException("null artifact");
+ dest.setModifiers(src.modifierSpecifier());
+ dest.setIsInterface(src.isInterface());
+ if (mTigerDelegate != null) dest.setIsEnumType(mTigerDelegate.isEnum(src));
+ // set the superclass
+ ClassDoc s = src.superclass();
+ if (s != null) dest.setSuperclass(getFdFor(s));
+ // set the interfaces
+ ClassDoc[] ints = src.interfaces();
+ for(int i=0; i<ints.length; i++) {
+ dest.addInterface(getFdFor(ints[i]));
+ }
+ // add the fields
+ FieldDoc[] fields = src.fields();
+ for(int i=0; i<fields.length; i++) populate(dest.addNewField(),fields[i]);
+ // add the constructors
+ ConstructorDoc[] ctors = src.constructors();
+ for(int i=0; i<ctors.length; i++) populate(dest.addNewConstructor(),ctors[i]);
+ // add the methods
+ MethodDoc[] methods = src.methods();
+ for(int i=0; i<methods.length; i++) populate(dest.addNewMethod(),methods[i]);
+
+ // add the 'annotation elements' separately. javadoc used to return them
+ // as methods but this has changed recently.
+ if (mTigerDelegate != null) {
+ mTigerDelegate.populateAnnotationTypeIfNecessary(src,dest,this);
+ }
+
+ // add the annotations
+ addAnnotations(dest, src);
+ // add the source position
+ addSourcePosition(dest,src);
+ // add any inner classes
+ ClassDoc[] inners = src.innerClasses();
+ if (inners != null) {
+ for(int i=0; i<inners.length; i++) {
+ MClass inner = dest.addNewInnerClass(inners[i].typeName());
+ inner.setArtifact(inners[i]);
+ populate(inner);
+ }
+ }
+ }
+
+ // this is a gross little callback hook for Javadoc15DelegateImpl.
+ // kinda hacky but we have little choice
+ public MMethod addMethod(MClass dest, MethodDoc doc) {
+ MMethod out = dest.addNewMethod();
+ populate(out,doc);
+ return out;
+ }
+
+ // ========================================================================
+ // Private methods
+
+ private void initDelegate(ElementContext ctx) {
+ mTigerDelegate = JavadocTigerDelegate.create(ctx);
+ }
+
+ private void initJavadoc(JamServiceContext serviceContext) {
+ // grab some useful stuff
+ mTagParser = serviceContext.getTagParser();
+ String pct = serviceContext.getProperty(PARSETAGS_PROPERTY);
+ if (pct != null) {
+ mParseTags = Boolean.valueOf(pct).booleanValue();
+ getLogger().verbose("mParseTags="+mParseTags,this);
+ }
+ // now go run javadoc on the appropriate files
+ File[] files;
+ try {
+ files = serviceContext.getSourceFiles();
+ } catch(IOException ioe) {
+ getLogger().error(ioe);
+ return;
+ }
+ if (files == null || files.length == 0) {
+ throw new IllegalArgumentException("No source files in context.");
+ }
+ String sourcePath = (serviceContext.getInputSourcepath() == null) ? null :
+ serviceContext.getInputSourcepath().toString();
+ String classPath = (serviceContext.getInputClasspath() == null) ? null :
+ serviceContext.getInputClasspath().toString();
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("sourcePath ="+sourcePath);
+ getLogger().verbose("classPath ="+classPath);
+ for(int i=0; i<files.length; i++) {
+ getLogger().verbose("including '"+files[i]+"'");
+ }
+ }
+ JavadocRunner jdr = JavadocRunner.newInstance();
+ try {
+ PrintWriter out = null;
+ if (getLogger().isVerbose(this)) {
+ out = new PrintWriter(System.out);
+ }
+ mRootDoc = jdr.run(files,
+ out,
+ sourcePath,
+ classPath,
+ getJavadocArgs(serviceContext),
+ getLogger());
+ if (mRootDoc == null) {
+ getLogger().error("Javadoc returned a null root");//FIXME error
+ } else {
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose(" received "+mRootDoc.classes().length+
+ " ClassDocs from javadoc: ");
+ }
+ ClassDoc[] classes = mRootDoc.classes();
+ // go through and explicitly add all of the class names. we need to
+ // do this in case they passed any 'unstructured' classes. to the
+ // params. this could use a little TLC.
+ for(int i=0; i<classes.length; i++) {
+ if (classes[i].containingClass() != null) continue; // skip inners
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("..."+classes[i].qualifiedName());
+ }
+ ((JamServiceContextImpl)serviceContext).
+ includeClass(getFdFor(classes[i]));
+ }
+ }
+ } catch (FileNotFoundException e) {
+ getLogger().error(e);
+ } catch (IOException e) {
+ getLogger().error(e);
+ }
+ }
+
+ private void populate(MField dest, FieldDoc src) {
+ dest.setArtifact(src);
+ dest.setSimpleName(src.name());
+ dest.setType(getFdFor(src.type()));
+ dest.setModifiers(src.modifierSpecifier());
+ addAnnotations(dest, src);
+ addSourcePosition(dest,src);
+ }
+
+ private void populate(MMethod dest, MethodDoc src) {
+ if (dest == null) throw new IllegalArgumentException("null dest");
+ if (src == null) throw new IllegalArgumentException("null src");
+ populate((MInvokable)dest,(ExecutableMemberDoc)src);
+ dest.setReturnType(getFdFor(src.returnType()));
+ }
+
+ private void populate(MInvokable dest, ExecutableMemberDoc src) {
+ if (dest == null) throw new IllegalArgumentException("null dest");
+ if (src == null) throw new IllegalArgumentException("null src");
+ dest.setArtifact(src);
+ dest.setSimpleName(src.name());
+ dest.setModifiers(src.modifierSpecifier());
+ ClassDoc[] exceptions = src.thrownExceptions();
+ for(int i=0; i<exceptions.length; i++) {
+ dest.addException(getFdFor(exceptions[i]));
+ }
+ Parameter[] params = src.parameters();
+ for(int i=0; i<params.length; i++) {
+ populate(dest.addNewParameter(),src,params[i]);
+ }
+ addAnnotations(dest, src);
+ addSourcePosition(dest,src);
+ }
+
+ private void populate(MParameter dest, ExecutableMemberDoc method, Parameter src) {
+ dest.setArtifact(src);
+ dest.setSimpleName(src.name());
+ dest.setType(getFdFor(src.type()));
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,method,src);
+ }
+
+
+ private String[] getJavadocArgs(JamServiceContext ctx) {
+ String prop = ctx.getProperty(ARGS_PROPERTY);
+ if (prop == null) return null;
+ StringTokenizer t = new StringTokenizer(prop);
+ String[] out = new String[t.countTokens()];
+ int i = 0;
+ while(t.hasMoreTokens()) out[i++] = t.nextToken();
+ return out;
+ }
+
+ private void addAnnotations(MAnnotatedElement dest, ProgramElementDoc src) {
+ String comments = src.commentText();
+ if (comments != null) dest.createComment().setText(comments);
+ Tag[] tags = src.tags();
+ //if (mLogger.isVerbose(this)) {
+ // mLogger.verbose("processing "+tags.length+" javadoc tags on "+dest);
+ //}
+ for(int i=0; i<tags.length; i++) {
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("...'"+tags[i].name()+"' ' "+tags[i].text());
+ }
+ //note name() returns the '@', so we strip it here
+ mTagParser.parse(dest,tags[i]);
+ }
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,src);
+ }
+
+ // ========================================================================
+ // Shared(?) utilities
+
+ /**
+ * Returns a classfile-style field descriptor for the given type.
+ * This has to be called to get a name for a javadoc type that can
+ * be used with Class.forName(), JRootContext.getClass(), or
+ * JClass.forName().
+ */
+ public static String getFdFor(Type t) {
+ if (t == null) throw new IllegalArgumentException("null type");
+ String dim = t.dimension();
+ if (dim == null || dim.length() == 0) {
+ ClassDoc cd = t.asClassDoc();
+ if (cd != null) {
+ ClassDoc outer = cd.containingClass();
+ if (outer == null) return cd.qualifiedName();
+ String simpleName = cd.name();
+ simpleName = simpleName.substring(simpleName.lastIndexOf('.')+1);
+ return outer.qualifiedName()+'$'+simpleName;
+ } else {
+ return t.qualifiedTypeName();
+ }
+ } else {
+ StringWriter out = new StringWriter();
+ for(int i=0, iL=dim.length()/2; i<iL; i++) out.write("[");
+ String primFd =
+ PrimitiveClassImpl.getPrimitiveClassForName(t.qualifiedTypeName());
+ if (primFd != null) { //i.e. if primitive
+ out.write(primFd);
+ } else {
+ out.write("L");
+ if (t.asClassDoc() != null) {
+ out.write(t.asClassDoc().qualifiedName());
+ } else {
+ out.write(t.qualifiedTypeName());
+ }
+ out.write(";");
+ }
+ return out.toString();
+ }
+ }
+
+ public static void addSourcePosition(MElement dest, Doc src) {
+ SourcePosition pos = src.position();
+ if (pos != null) addSourcePosition(dest,pos);
+ }
+
+ public static void addSourcePosition(MElement dest, SourcePosition pos) {
+ MSourcePosition sp = dest.createSourcePosition();
+ sp.setColumn(pos.column());
+ sp.setLine(pos.line());
+ File f = pos.file();
+ if (f != null) sp.setSourceURI(f.toURI());
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassloadingException.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassloadingException.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassloadingException.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocClassloadingException.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,97 @@
+/* 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.javadoc;
+
+/**
+ * Exception thrown to indicate the likely manifestation of a thorny
+ * classloading problem with javadoc. See the EXPLANATION constant for
+ * details.
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class JavadocClassloadingException extends RuntimeException {
+
+ // ========================================================================
+ // Constants
+
+ private static final String SOME_CLASS_IN_TOOLS_JAR =
+ "com.sun.javadoc.Doclet";
+
+ private static final String STANDARD_EXPLANATION =
+ "An error has occurred while invoking javadoc to inspect your source\n"+
+ "files. This may be due to the fact that $JAVA_HOME/lib/tools.jar does\n"+
+ "not seem to be in your system classloader. One common case in which \n"+
+ "this happens is when using the 'ant' tool, which uses a special\n"+
+ "context classloader to load classes from tools.jar.\n"+
+ "\n"+
+ "This situation elicits what is believed to a javadoc bug in the initial\n"+
+ "release of JDK 1.5. Javadoc attempts to use its own context classloader\n"+
+ "tools.jar but ignores one that may have already been set, which leads\n"+
+ "to some classes being loaded into two different classloaders. The\n"+
+ "telltale sign of this problem is a javadoc error message saying that\n"+
+ "'languageVersion() must return LanguageVersion - you might see this\n"+
+ "message in your process' output.\n"+
+ "\n"+
+ "This will hopefully be fixed in a later release of JDK 1.5; if a new\n"+
+ "version of 1.5 has become available, you might be able to solve this\n"+
+ "by simply upgrading to the latest JDK.\n"+
+ "\n"+
+ "Alternatively, you can work around it by simply including \n"+
+ "$JAVA_HOME/lib/tools.jar in the java -classpath\n"+
+ "parameter. If you are running ant, you will need to modify the standard\n"+
+ "ant script to include tools.jar in the -classpath.\n";
+
+
+
+ // ========================================================================
+ // Static utilities
+
+ /**
+ * Returns true if tools.jar is not in the system classloader. If true, it
+ * is very likely that any javadoc failures are due to the problem described
+ * above.
+ */
+ public static boolean isClassloadingProblemPresent() {
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ try {
+ cl.loadClass(SOME_CLASS_IN_TOOLS_JAR);
+ return false;
+ } catch(ClassNotFoundException cnfe) {
+ return true;
+ }
+ }
+
+ // ========================================================================
+ // Constructors
+
+ public JavadocClassloadingException() {
+ super((ALTERNATE_EXPLANATION != null) ? ALTERNATE_EXPLANATION :
+ STANDARD_EXPLANATION);
+ }
+
+ // ========================================================================
+ // hack
+
+ private static String ALTERNATE_EXPLANATION = null;
+
+ /**
+ * Quick and dirty way for user to alter the explanation for this problem
+ * with more specific information or solutions.
+ */
+ public static void setExplanation(String msg) {
+ ALTERNATE_EXPLANATION = msg;
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocResults.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocResults.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocResults.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocResults.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,91 @@
+/* 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.javadoc;
+
+import com.sun.javadoc.RootDoc;
+
+import java.lang.reflect.Method;
+
+/**
+ * <p>Used by JavadocRunner to ensure that we always stash the results
+ * of a javadoc run in a place where we can get them. This is particularly
+ * painful because one implements a javdoc doclet by providing a static
+ * callback method. In the case of multiple classloaders, extra care must be
+ * taken to ensure that we can stash away the RootDoc result received in
+ * the callback and retrieve it later.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class JavadocResults {
+
+ // ========================================================================
+ // Singleton
+
+ private static final JavadocResults INSTANCE = new JavadocResults();
+
+ // ========================================================================
+ // Variables
+
+ private ThreadLocal mRootsPerThread = new ThreadLocal();
+
+ // ========================================================================
+ // Public methods
+
+ public static void prepare() {
+ Thread.currentThread().
+ setContextClassLoader(JavadocResults.class.getClassLoader());
+ }
+
+ public static void setRoot(RootDoc root) {
+ try {
+ Object holder = getHolder();
+ Method setter = holder.getClass().getMethod("_setRoot",
+ new Class[] { RootDoc.class });
+ setter.invoke(holder,new Object[] {root});
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw new IllegalStateException();//FIXME??
+ }
+ }
+
+ public static RootDoc getRoot() {
+ try {
+ Object holder = getHolder();
+ Method getter = holder.getClass().getMethod("_getRoot",new Class[0]);
+ return (RootDoc)getter.invoke(holder,(Object[])null);
+ } catch(Exception e) {
+ e.printStackTrace();
+ throw new IllegalStateException();//FIXME??
+ }
+ }
+
+ // ========================================================================
+ // DO NOT CALL THESE METHODS
+
+ public void _setRoot(RootDoc root) { mRootsPerThread.set(root); }
+
+ public RootDoc _getRoot() { return (RootDoc)mRootsPerThread.get(); }
+
+ public static JavadocResults getInstance() { return INSTANCE; }
+
+ private static Object getHolder() throws Exception {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Class clazz = classLoader.loadClass(JavadocResults.class.getName());
+ Method method = clazz.getMethod("getInstance",new Class[0]);
+ return method.invoke(null,new Object[0]);
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocRunner.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocRunner.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocRunner.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocRunner.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,175 @@
+/* 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.javadoc;
+
+import com.sun.javadoc.Doclet;
+import com.sun.javadoc.RootDoc;
+import org.apache.xmlbeans.impl.jam.provider.JamLogger;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * <p>This class does its best to encapsulate and make threadsafe the
+ * nastiness that is the javadoc 'invocation' API.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class JavadocRunner extends Doclet {
+
+ // ========================================================================
+ // Constants
+
+ private static final String JAVADOC_RUNNER_150 =
+ "org.apache.xmlbeans.impl.jam.internal.javadoc.JavadocRunner_150";
+
+ // ========================================================================
+ // Factory methods
+
+ public static JavadocRunner newInstance() {
+ try {
+ // See if we can load a 1.5-specific class. If we can't, don't use
+ // the default. FIXME please rationalize handling of this throughout
+ // the code.
+ Class.forName("com.sun.javadoc.AnnotationDesc");
+ } catch (ClassNotFoundException e) {
+ return new JavadocRunner();
+ }
+ //REVIEW we should probably normalize the handling of 1.5-specific class
+ //instantation and error handling
+ try {
+ Class onefive = Class.forName(JAVADOC_RUNNER_150);
+ return (JavadocRunner)onefive.newInstance();
+ } catch(ClassNotFoundException cnfe) {
+ } catch (IllegalAccessException e) {
+ } catch (InstantiationException e) {
+ }
+ return new JavadocRunner();
+ }
+
+ // ========================================================================
+ // Constructor
+
+ public JavadocRunner() {}
+
+ // ========================================================================
+ // Public methods
+
+ /**
+ * Runs javadoc on the given source directory and returns a JDRoot
+ * which wraps the javadoc view of the source files there.
+ */
+ /*package*/ synchronized RootDoc run(File[] files,
+ PrintWriter out,
+ String sourcePath,
+ String classPath,
+ String[] javadocArgs,
+ JamLogger logger)
+ throws IOException, FileNotFoundException
+ {
+ if (files == null || files.length == 0) {
+ throw new FileNotFoundException("No input files found.");
+ }
+ List argList = new ArrayList();
+ if (javadocArgs != null) {
+ argList.addAll(Arrays.asList(javadocArgs));
+ }
+ argList.add("-private");
+ if (sourcePath != null) {
+ argList.add("-sourcepath");
+ argList.add(sourcePath);
+ }
+ if (classPath != null) {
+ argList.add("-classpath");
+ argList.add(classPath);
+ argList.add("-docletpath");
+ argList.add(classPath);
+ }
+ for(int i=0; i<files.length; i++) {
+ argList.add(files[i].toString());
+ if (out != null) out.println(files[i].toString());
+ }
+ String[] args = new String[argList.size()];
+ argList.toArray(args);
+ // create a buffer to capture the crap javadoc spits out. we'll
+ // just ignore it unless something goes wrong
+ PrintWriter spewWriter;
+ StringWriter spew = null;
+ if (out == null) {
+ spewWriter = new PrintWriter(spew = new StringWriter());
+ } else {
+ spewWriter = out;
+ }
+ ClassLoader originalCCL = Thread.currentThread().getContextClassLoader();
+ try {
+ JavadocResults.prepare();
+ if (logger.isVerbose(this)) {
+ logger.verbose("Invoking javadoc. Command line equivalent is: ");
+ StringWriter sw = new StringWriter();
+ sw.write("javadoc ");
+ for(int i=0; i<args.length; i++) {
+ sw.write("'");
+ sw.write(args[i]);
+ sw.write("' ");
+ }
+ logger.verbose(" "+sw.toString());
+ }
+ int result = com.sun.tools.javadoc.Main.execute("JAM",
+ spewWriter,
+ spewWriter,
+ spewWriter,
+ this.getClass().getName(),
+ args);
+ RootDoc root = JavadocResults.getRoot();
+ if (result != 0 || root == null) {
+ spewWriter.flush();
+ if (JavadocClassloadingException.isClassloadingProblemPresent()) {
+ throw new JavadocClassloadingException();
+ }
+ throw new RuntimeException("Unknown javadoc problem: result="+result+
+ ", root="+root+":\n"+
+ ((spew == null) ? "" : spew.toString()));
+ }
+ return root;
+ } catch(RuntimeException e) {
+ throw e;
+ } finally {
+ //clean up the mess
+ Thread.currentThread().setContextClassLoader(originalCCL);
+ }
+ }
+
+ // ========================================================================
+ // Doclet 'implementation'
+
+ public static boolean start(RootDoc root) {
+ JavadocResults.setRoot(root);
+ return true;
+ }
+
+ /* need to tuck this away in 1.5-safeville
+ public static LanguageVersion languageVersion() {
+ return LanguageVersion.JAVA_1_5;
+ }
+ */
+}
\ No newline at end of file
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocTigerDelegate.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocTigerDelegate.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocTigerDelegate.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JavadocTigerDelegate.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,122 @@
+/* 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.javadoc;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.ExecutableMemberDoc;
+import com.sun.javadoc.Parameter;
+import com.sun.javadoc.ProgramElementDoc;
+import org.apache.xmlbeans.impl.jam.internal.TigerDelegate;
+import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
+import org.apache.xmlbeans.impl.jam.mutable.MAnnotatedElement;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.provider.JamLogger;
+
+/**
+ * Provides an interface to 1.5-specific functionality. The impl of
+ * this class is loaded by-name at runtime.
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public abstract class JavadocTigerDelegate extends TigerDelegate {
+
+ // ========================================================================
+ // Constants
+
+ private static final String JAVADOC_DELEGATE_IMPL =
+ "org.apache.xmlbeans.impl.jam.internal.javadoc.JavadocTigerDelegateImpl_150";
+
+ // This is part of a hack for EJBgen, which for some reason it behaves really
+ // badly when we supply it default values. This should be removed
+ // when EJBgen can be fixed.
+
+ public static final String ANNOTATION_DEFAULTS_DISABLED_PROPERTY =
+ "ANNOTATION_DEFAULTS_DISABLED_PROPERTY";
+
+ // ========================================================================
+ // Factory
+
+ public static JavadocTigerDelegate create(JamLogger logger) {
+ if (!isTigerJavadocAvailable(logger)) return null;
+ // ok, if we could load that, let's new up the extractor delegate
+ try {
+ JavadocTigerDelegate out = (JavadocTigerDelegate)
+ Class.forName(JAVADOC_DELEGATE_IMPL).newInstance();
+ out.init(logger);
+ return out;
+ } catch (ClassNotFoundException e) {
+ issue14BuildWarning(e,logger);
+ } catch (IllegalAccessException e) {
+ logger.error(e);
+ } catch (InstantiationException e) {
+ logger.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * @deprecated
+ */
+ public static JavadocTigerDelegate create(ElementContext ctx)
+ {
+ if (!isTigerJavadocAvailable(ctx.getLogger())) return null;
+ // ok, if we could load that, let's new up the extractor delegate
+ try {
+ JavadocTigerDelegate out = (JavadocTigerDelegate)
+ Class.forName(JAVADOC_DELEGATE_IMPL).newInstance();
+ out.init(ctx);
+ return out;
+ } catch (ClassNotFoundException e) {
+ ctx.getLogger().error(e);
+ } catch (IllegalAccessException e) {
+ ctx.getLogger().error(e);
+ } catch (InstantiationException e) {
+ ctx.getLogger().error(e);
+ }
+ return null;
+ }
+
+ // ========================================================================
+ // Public methods
+
+ /**
+ * Returns true if the given ClassDoc represents an enum.
+ */
+ public abstract boolean isEnum(ClassDoc cd);
+
+ public abstract void init(JamLogger logger);
+
+ public abstract void populateAnnotationTypeIfNecessary(ClassDoc cd,
+ MClass clazz,
+ JavadocClassBuilder builder);
+
+
+ // ========================================================================
+ // Deprecated stuff, trying to move away from this
+
+ /**
+ * @deprecated
+ */
+ public abstract void extractAnnotations(MAnnotatedElement dest,
+ ProgramElementDoc src);
+
+ /**
+ * @deprecated
+ */
+ public abstract void extractAnnotations(MAnnotatedElement dest,
+ ExecutableMemberDoc method,
+ Parameter src);
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStruct.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStruct.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStruct.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStruct.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,55 @@
+/* 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.parser;
+
+import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
+import org.apache.xmlbeans.impl.jam.mutable.MParameter;
+
+/**
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+/*package*/ class ParamStruct {
+
+ // ========================================================================
+ // Variables
+
+ private String mName;
+ private String mType;
+
+ // ========================================================================
+ // Constructors
+
+ public ParamStruct(String type, String name) {
+ init(type,name);
+ }
+
+ // ========================================================================
+ // Public methods
+
+ public void init(String type, String name) {
+ mType = type;
+ mName = name;
+ }
+
+ public MParameter createParameter(MInvokable e) {
+ if (e == null) throw new IllegalArgumentException("null invokable");
+ MParameter param = e.addNewParameter();
+ param.setSimpleName(mName);
+ param.setUnqualifiedType(mType);
+ return param;
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStructPool.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStructPool.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStructPool.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParamStructPool.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,65 @@
+/* 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.parser;
+
+import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Utility class which the parser uses to store a list of method
+ * or constructor parameters during lookahead. The structures
+ * get reused for efficiency.</p>
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class ParamStructPool {
+
+ // ========================================================================
+ // Constants
+
+ private static final boolean VERBOSE = true;
+
+ // ========================================================================
+ // Variables
+
+ private List mList = new ArrayList();
+ private int mLength = 0;
+
+ // ========================================================================
+ // Public methods
+
+ public void setParametersOn(MInvokable e) {
+ for(int i=0; i<mLength; i++) {
+ ParamStruct struct = (ParamStruct)mList.get(i);
+ struct.createParameter(e);
+ }
+ }
+
+ public void add(String type, String name) {
+ mLength++;
+ if (mLength >= mList.size()) {
+ mList.add(new ParamStruct(type,name));
+ } else {
+ ((ParamStruct)mList.get(mLength)).init(type,name);
+ }
+ }
+
+ public void clear() {
+ mLength = 0;
+ }
+
+}
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParserClassBuilder.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParserClassBuilder.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParserClassBuilder.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/parser/ParserClassBuilder.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,221 @@
+/* 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.parser;
+
+import org.apache.xmlbeans.impl.jam.JamClassLoader;
+import org.apache.xmlbeans.impl.jam.internal.JamPrinter;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
+import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
+import org.apache.xmlbeans.impl.jam.provider.JamServiceContext;
+import org.apache.xmlbeans.impl.jam.provider.ResourcePath;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+//FIXME uncomment when we get around to working on the parser again
+//import org.apache.xmlbeans.impl.jam.internal.parser.generated.JavaLexer;
+//import org.apache.xmlbeans.impl.jam.internal.parser.generated.JavaParser;
+
+/**
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class ParserClassBuilder extends JamClassBuilder implements JamClassPopulator {
+
+ // ========================================================================
+ // Constants
+
+ private static final boolean VERBOSE = false;
+
+ // ========================================================================
+ // Variables
+
+ private ResourcePath mSourcePath;
+ private boolean mVerbose = VERBOSE;
+ private PrintWriter mOut = new PrintWriter(System.out);
+
+ // ========================================================================
+ // Constructors
+
+ private ParserClassBuilder() {}
+
+ public ParserClassBuilder(JamServiceContext jsp) {
+ mSourcePath = jsp.getInputSourcepath();
+ //mOut = jsp.getOut();
+ }
+
+ // ========================================================================
+ // BaseJClassLoader implementation
+
+ public MClass build(String pkg, String name) {
+ if (pkg == null) throw new IllegalArgumentException("null pkg");
+ if (name == null) throw new IllegalArgumentException("null name");
+ String filespec = pkg.replace('.',File.separatorChar)+
+ File.separatorChar+name+".java";
+ if (name.indexOf(".") != -1) {
+ throw new IllegalArgumentException("inner classes are NYI at the moment");
+ }
+ InputStream in = mSourcePath.findInPath(filespec);
+ if (in == null) {
+ if (mVerbose) {
+ mOut.println("[ParserClassBuilder] could not find "+filespec);
+ }
+ return null;
+ } else {
+ if (mVerbose) {
+ mOut.println("[ParserClassBuilder] loading class "+pkg+" "+name);
+ mOut.println("[ParserClassBuilder] from file "+filespec);
+ }
+ }
+ Reader rin = new InputStreamReader(in);
+ try {
+ /*
+ MClass[] clazz = null;//FIXME parse(rin,loader);
+ if (clazz.length > 1) {
+ System.out.println("WARNING: multiple classes per package are not "+
+ "handled correctly at the moment. FIXME");
+ }
+ return clazz[0]; //FIXME deal properly with multiple classes
+ */
+ } catch(Throwable t) {
+ t.printStackTrace();
+ } finally {
+ try {
+ rin.close();
+ } catch(IOException ohwell) {
+ ohwell.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ // ========================================================================
+ // JamClassPopulator implementation
+
+ public void populate(MClass m) {
+ throw new IllegalStateException("NYI");
+ }
+
+ // ========================================================================
+ // Private methods
+
+ private static MClass[] parse(Reader in, JamClassLoader loader) throws Exception {
+ if (in == null) throw new IllegalArgumentException("null in");
+ if (loader == null) throw new IllegalArgumentException("null loader");
+
+ //FIXME uncomment when we get around to working on the parser again
+ throw new IllegalStateException("temporarily NI");
+/*
+ JavaLexer lexer = new JavaLexer(in);
+ JavaParser parser = new JavaParser(lexer);
+ parser.setClassLoader(loader);
+ parser.start();
+ return parser.getResults();
+ */
+ }
+
+ // ========================================================================
+ // main method
+
+ public static void main(String[] files) {
+ new ParserClassBuilder.MainTool().process(files);
+ }
+
+ static class MainTool {
+ private List mFailures = new ArrayList();
+ private int mCount = 0;
+ private PrintWriter mOut = new PrintWriter(System.out);
+ private long mStartTime = System.currentTimeMillis();
+
+ public void process(String[] files) {
+ try {
+ for(int i=0; i<files.length; i++) {
+ File input = new File(files[i]);
+ parse(new ParserClassBuilder(),input);
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ mOut.println("\n\n\n");
+ int fails = mFailures.size();
+ if (fails != 0) {
+ mOut.println("The following files failed to parse:");
+ for(int i=0; i<fails; i++) {
+ mOut.println(((File)mFailures.get(i)).getAbsolutePath());
+ }
+ }
+ mOut.println((((mCount-fails)*100)/mCount)+
+ "% ("+(mCount-fails)+"/"+mCount+") "+
+ "of input java files successfully parsed.");
+ mOut.println("Total time: "+
+ ((System.currentTimeMillis()-mStartTime)/1000)+
+ " seconds.");
+ mOut.flush();
+ System.out.flush();
+ System.err.flush();
+ }
+
+ private void parse(ParserClassBuilder parser, File input)
+ throws Exception
+ {
+ System.gc();
+ if (input.isDirectory()) {
+ if (VERBOSE) mOut.println("scanning in directory "+input);
+ File[] files = input.listFiles();
+ for(int i=0; i<files.length; i++) {
+ parse(parser,files[i]);
+ }
+ } else {
+ if (!input.getName().endsWith(".java")) return;
+ if (VERBOSE) {
+ mOut.println("-----------------------------------------");
+ mOut.println("processing "+input);
+ mOut.println("-----------------------------------------");
+ }
+ mCount++;
+ MClass[] results = null;
+ try {
+ results = parser.parse(new FileReader(input),null);
+ if (results == null) {
+ mOut.println("[error, parser result is null]");
+ addFailure(input);
+ } else {
+ if (VERBOSE) {
+ JamPrinter jp = JamPrinter.newInstance();
+ for(int i=0; i<results.length; i++) {
+ jp.print(results[i],mOut);
+ }
+ }
+ }
+ } catch(Throwable e) {
+ e.printStackTrace(mOut);
+ addFailure(input);
+ }
+ }
+ }
+
+ private void addFailure(File file) {
+ mFailures.add(file);
+ }
+ }
+}
\ No newline at end of file
Added: xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java
URL: http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java?rev=1857518&view=auto
==============================================================================
--- xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java (added)
+++ xmlbeans/branches/xmlbeans-536/src/jam/org/apache/xmlbeans/impl/jam/internal/reflect/ReflectClassBuilder.java Sun Apr 14 13:55:06 2019
@@ -0,0 +1,203 @@
+/* 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.reflect;
+
+import org.apache.xmlbeans.impl.jam.internal.elements.ElementContext;
+import org.apache.xmlbeans.impl.jam.mutable.MClass;
+import org.apache.xmlbeans.impl.jam.mutable.MConstructor;
+import org.apache.xmlbeans.impl.jam.mutable.MField;
+import org.apache.xmlbeans.impl.jam.mutable.MInvokable;
+import org.apache.xmlbeans.impl.jam.mutable.MMethod;
+import org.apache.xmlbeans.impl.jam.mutable.MParameter;
+import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
+import org.apache.xmlbeans.impl.jam.provider.JamClassPopulator;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ *
+ * @author Patrick Calahan <email: pcal-at-bea-dot-com>
+ */
+public class ReflectClassBuilder extends JamClassBuilder implements JamClassPopulator {
+
+ // ========================================================================
+ // Variables
+
+ private ClassLoader mLoader;
+ private ReflectTigerDelegate mTigerDelegate = null;
+
+ // ========================================================================
+ // Constructors
+
+ public ReflectClassBuilder(ClassLoader rcl) {
+ if (rcl == null) throw new IllegalArgumentException("null rcl");
+ mLoader = rcl;
+ }
+
+ // ========================================================================
+ // JamClassBuilder implementation
+
+ public void init(ElementContext ctx) {
+ super.init(ctx);
+ initDelegate(ctx);
+ }
+
+ public MClass build(String packageName, String className) {
+ assertInitialized();
+ if (getLogger().isVerbose(this)) {
+ getLogger().verbose("trying to build '"+packageName+"' '"+className+"'");
+ }
+ Class rclass;
+ try {
+ String loadme = (packageName.trim().length() > 0) ?
+ (packageName + '.' + className) :
+ className;
+ rclass = mLoader.loadClass(loadme);
+ } catch(ClassNotFoundException cnfe) {
+ getLogger().verbose(cnfe,this);
+ return null;
+ }
+ MClass out = createClassToBuild(packageName, className, null, this);
+ out.setArtifact(rclass);
+ return out;
+ }
+
+ // ========================================================================
+ // JamClassPopulator implementation
+
+ public void populate(MClass dest) {
+ assertInitialized();
+ Class src = (Class)dest.getArtifact();
+ dest.setModifiers(src.getModifiers());
+ dest.setIsInterface(src.isInterface());
+ if (mTigerDelegate != null) dest.setIsEnumType(mTigerDelegate.isEnum(src));
+ // set the superclass
+ Class s = src.getSuperclass();
+ if (s != null) dest.setSuperclass(s.getName());
+ // set the interfaces
+ Class[] ints = src.getInterfaces();
+ for(int i=0; i<ints.length; i++) dest.addInterface(ints[i].getName());
+ // add the fields
+ Field[] fields = null;
+ try {
+ fields = src.getFields();
+ } catch(Exception ignore) {
+ //FIXME there seems to be some JDK bugs here, workaround for now 180996
+ }
+ if (fields != null) {
+ for(int i=0; i<fields.length; i++) populate(dest.addNewField(),fields[i]);
+ }
+ // add the methods
+ Method[] methods = src.getDeclaredMethods();
+ for(int i=0; i<methods.length; i++) populate(dest.addNewMethod(),methods[i]);
+
+ if (mTigerDelegate != null) mTigerDelegate.populateAnnotationTypeIfNecessary(src,dest,this);
+
+ // add the constructors
+ Constructor[] ctors = src.getDeclaredConstructors();
+ for(int i=0; i<ctors.length; i++) populate(dest.addNewConstructor(),ctors[i]);
+ // add the annotations
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,src);
+
+
+ // add any inner classes
+ Class[] inners = src.getDeclaredClasses();
+ if (inners != null) {
+ for(int i=0; i<inners.length; i++) {
+ if (mTigerDelegate != null) {
+ // skip anonymous classes
+ if ((mTigerDelegate.getEnclosingConstructor(inners[i]) != null) ||
+ (mTigerDelegate.getEnclosingMethod(inners[i]) != null)) continue;
+ }
+ String simpleName = inners[i].getName();
+ int lastDollar = simpleName.lastIndexOf('$');
+ simpleName = simpleName.substring(lastDollar+1);
+ { //skip member anons
+ char first = simpleName.charAt(0);
+ if ( ('0' <= first) && (first <= '9')) {
+ continue;
+ }
+ }
+ MClass inner = dest.addNewInnerClass(simpleName);
+ inner.setArtifact(inners[i]);
+ populate(inner);
+ }
+ }
+ }
+
+
+ // ========================================================================
+ // Private methods
+
+ private void initDelegate(ElementContext ctx) {
+ // ok, if we could load that, let's new up the extractor delegate
+ mTigerDelegate = ReflectTigerDelegate.create(ctx);
+ }
+
+ private void populate(MField dest, Field src) {
+ dest.setArtifact(src);
+ dest.setSimpleName(src.getName());
+ dest.setType(src.getType().getName());
+ dest.setModifiers(src.getModifiers());
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,src);
+ }
+
+ private void populate(MConstructor dest, Constructor src) {
+ dest.setArtifact(src);
+ dest.setSimpleName(src.getName());
+ dest.setModifiers(src.getModifiers());
+ Class[] exceptions = src.getExceptionTypes();
+ addThrows(dest,exceptions);
+ Class[] paramTypes = src.getParameterTypes();
+ for(int i=0; i<paramTypes.length; i++) {
+ MParameter p = addParameter(dest, i, paramTypes[i]);
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(p,src,i);
+ }
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,src);
+ }
+
+ private void populate(MMethod dest, Method src) {
+ dest.setArtifact(src);
+ dest.setSimpleName(src.getName());
+ dest.setModifiers(src.getModifiers());
+ dest.setReturnType(src.getReturnType().getName());
+ Class[] exceptions = src.getExceptionTypes();
+ addThrows(dest,exceptions);
+ Class[] paramTypes = src.getParameterTypes();
+ for(int i=0; i<paramTypes.length; i++) {
+ MParameter p = addParameter(dest, i, paramTypes[i]);
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(p,src,i);
+ }
+ if (mTigerDelegate != null) mTigerDelegate.extractAnnotations(dest,src);
+ }
+
+ private void addThrows(MInvokable dest, Class[] exceptionTypes) {
+ for(int i=0; i<exceptionTypes.length; i++) {
+ dest.addException(exceptionTypes[i].getName());
+ }
+ }
+
+ private MParameter addParameter(MInvokable dest,
+ int paramNum,
+ Class paramType)
+ {
+ MParameter p = dest.addNewParameter();
+ p.setSimpleName("param"+paramNum);
+ p.setType(paramType.getName());
+ return p;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org
|