You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2004/03/03 09:25:26 UTC
cvs commit: xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam ClassesJamTest.java JamTestBase.java ParserJamTest.java SourcesJamTest.java
pcal 2004/03/03 00:25:26
Modified: v2/src/jam java.g
v2/src/jam/org/apache/xmlbeans/impl/jam/editable
EElement.java EMember.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl
EElementImpl.java
v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc
JDComment.java
v2/src/jam/org/apache/xmlbeans/impl/jam/provider
DefaultCommentProcessor.java
JServiceParamsImpl.java ReflectionClassBuilder.java
v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
FooImpl.java
v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam
ClassesJamTest.java JamTestBase.java
ParserJamTest.java SourcesJamTest.java
Added: v2/src/jam/org/apache/xmlbeans/impl/jam/editable
EComment.java
v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl
ECommentImpl.java
v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses
HeavilyCommented.java
Log:
jam: add some comment-processing infrastructure and tests
Revision Changes Path
1.8 +1 -1 xml-xmlbeans/v2/src/jam/java.g
Index: java.g
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/java.g,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- java.g 3 Mar 2004 00:01:42 -0000 1.7
+++ java.g 3 Mar 2004 08:25:26 -0000 1.8
@@ -214,7 +214,7 @@
private void applyJavadocs(EMember member) {
if (mLastJavadoc != null) {
- member.addComment(mLastJavadoc);
+ member.addNewComment().setText(mLastJavadoc);
if (VERBOSE) {
System.out.println("adding javadocs to "+member.getSimpleName()+":");
System.out.println(mLastJavadoc);
1.6 +5 -0 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EElement.java
Index: EElement.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EElement.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EElement.java 3 Mar 2004 03:57:49 -0000 1.5
+++ EElement.java 3 Mar 2004 08:25:26 -0000 1.6
@@ -23,6 +23,11 @@
*/
public interface EElement extends JElement {
+ public EComment[] getEditableComments();
+
+ public EComment addNewComment();
+
+ public void removeComment(EComment comment);
public void setSimpleName(String name);
1.6 +0 -6 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EMember.java
Index: EMember.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EMember.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EMember.java 1 Mar 2004 00:10:18 -0000 1.5
+++ EMember.java 3 Mar 2004 08:25:26 -0000 1.6
@@ -24,10 +24,4 @@
public interface EMember extends EElement, JMember {
public void setModifiers(int modifiers);
-
- public void addComment(String comment);
-
-
-
-
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/EComment.java
Index: EComment.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.editable;
import org.apache.xmlbeans.impl.jam.JComment;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public interface EComment extends JComment {
/**
* Sets the text of this comment.
*/
public void setText(String text);
}
1.8 +33 -15 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EElementImpl.java
Index: EElementImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/EElementImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- EElementImpl.java 3 Mar 2004 03:57:49 -0000 1.7
+++ EElementImpl.java 3 Mar 2004 08:25:26 -0000 1.8
@@ -15,13 +15,11 @@
package org.apache.xmlbeans.impl.jam.editable.impl;
-import org.apache.xmlbeans.impl.jam.editable.EElement;
-import org.apache.xmlbeans.impl.jam.editable.ESourcePosition;
-import org.apache.xmlbeans.impl.jam.editable.EAnnotation;
-import org.apache.xmlbeans.impl.jam.editable.EElementVisitor;
+import org.apache.xmlbeans.impl.jam.editable.*;
import org.apache.xmlbeans.impl.jam.*;
import java.util.List;
+import java.util.ArrayList;
/**
*
@@ -36,6 +34,7 @@
private ESourcePosition mPosition = null;
private JClassLoader mClassLoader;
private List mAnnotations = null;
+ private List mComments = null;
// ========================================================================
// Constructors
@@ -64,19 +63,14 @@
return mPosition;
}
- //FIXME
public JComment[] getComments() {
- return new JComment[0];
+ return getEditableComments();
}
public JAnnotation[] getAnnotations() {
return getEditableAnnotations();
}
- public JAnnotation[] getAnnotations(String named) {
- return getAnnotations(); //FIXME remove this method please
- }
-
public JAnnotation getAnnotation(String named) {
return getEditableAnnotation(named);
}
@@ -84,12 +78,26 @@
// ========================================================================
// EElement implementation
- public void setSimpleName(String name) {
- mSimpleName = name;
+ public EComment[] getEditableComments() {
+ if (mComments == null) mComments = new ArrayList();
+ EComment[] out = new EComment[mComments.size()];
+ mComments.toArray(out);
+ return out;
}
- public EAnnotation createAnnotation() {
- return null;
+ public EComment addNewComment() {
+ if (mComments == null) mComments = new ArrayList();
+ EComment out = new ECommentImpl();
+ mComments.add(out);
+ return out;
+ }
+
+ public void removeComment(EComment comment) {
+ if (mComments != null) mComments.remove(comment);
+ }
+
+ public void setSimpleName(String name) {
+ mSimpleName = name;
}
public ESourcePosition createSourcePosition() {
@@ -105,10 +113,14 @@
}
public EAnnotation addNewAnnotation() {
- return null;
+ if (mAnnotations == null) mAnnotations = new ArrayList();
+ EAnnotation out = new EAnnotationImpl();
+ mAnnotations.add(out);
+ return out;
}
public void removeAnnotation(EAnnotation ann) {
+ if (mAnnotations != null) mAnnotations.remove(ann);
}
public EAnnotation[] getEditableAnnotations() {
@@ -162,5 +174,11 @@
for(int i=0; i<elems.length; i++) elems[i].acceptAndWalk(v);
}
+ // ========================================================================
+ // Deprecated method impls
+
+ public JAnnotation[] getAnnotations(String named) {
+ return getAnnotations(); //FIXME remove this method please
+ }
}
1.1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/editable/impl/ECommentImpl.java
Index: ECommentImpl.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.editable.impl;
import org.apache.xmlbeans.impl.jam.editable.EComment;
import org.apache.xmlbeans.impl.jam.editable.ESourcePosition;
import org.apache.xmlbeans.impl.jam.JSourcePosition;
import java.io.StringWriter;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.IOException;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class ECommentImpl implements EComment {
// ========================================================================
// Variables
private String mText = null;
private ESourcePosition mSourcePosition = null;
// ========================================================================
// Constructors
public ECommentImpl() {}
// ========================================================================
// EComment implementation
public void setText(String text) {
mText = text;
}
public String getText() {
return (mText == null) ? "" : mText;
}
public JSourcePosition getSourcePosition() {
return mSourcePosition;
}
}
1.4 +30 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDComment.java
Index: JDComment.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDComment.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDComment.java 12 Feb 2004 20:06:15 -0000 1.3
+++ JDComment.java 3 Mar 2004 08:25:26 -0000 1.4
@@ -19,6 +19,11 @@
import org.apache.xmlbeans.impl.jam.JComment;
import org.apache.xmlbeans.impl.jam.JSourcePosition;
+import java.io.StringWriter;
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.io.IOException;
+
/**
* Javadoc-backed implementation of Comment.
*
@@ -36,7 +41,7 @@
// Constructors
public JDComment(String text) {
- mText = text;
+ mText = normalize(text);
}
// ========================================================================
@@ -49,4 +54,28 @@
public JSourcePosition getSourcePosition() {
return mPosition;
}
+
+ // ========================================================================
+ // Private methods
+
+ //this is really just so we can all pass the same comment tests
+ private static final String normalize(String text) {
+ StringWriter out = new StringWriter();
+ BufferedReader in = new BufferedReader(new StringReader(text));
+ String line;
+ try {
+ boolean addBreak = false;
+ while((line = in.readLine()) != null) {
+ if (addBreak) out.write('\n');
+ addBreak = true;
+ out.write(line.trim());
+ }
+ } catch(IOException howOdd) {
+ howOdd.printStackTrace();
+ return text;
+ }
+ return out.toString();
+
+ }
+
}
1.2 +12 -10 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/DefaultCommentProcessor.java
Index: DefaultCommentProcessor.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/DefaultCommentProcessor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultCommentProcessor.java 3 Mar 2004 03:57:49 -0000 1.1
+++ DefaultCommentProcessor.java 3 Mar 2004 08:25:26 -0000 1.2
@@ -15,7 +15,6 @@
package org.apache.xmlbeans.impl.jam.provider;
import org.apache.xmlbeans.impl.jam.editable.*;
-import org.apache.xmlbeans.impl.jam.JComment;
import java.io.*;
@@ -57,7 +56,6 @@
// Protected methods
protected void visit(EElement element) {
- /*
EComment[] comments = element.getEditableComments();
if (comments == null || comments.length == 0) return;
for(int i=0; i<comments.length; i++) {
@@ -65,24 +63,28 @@
if (!text.startsWith("/*")) {
element.removeComment(comments[i]);
} else {
- StringWriter sw = new StringWriter();
- BufferedWriter out = new BufferedWriter(sw);
+ StringWriter out = new StringWriter();
BufferedReader in = new BufferedReader(new StringReader(text));
String line;
+ boolean addBreak = false;
try {
while((line = in.readLine()) != null) {
line = line.trim();
- if (line.equalsxxxfixme("* /")) continue;
+ if (line.equals("*/")) continue;
int offset = line.indexOf('*');
- if (offset == line.length()) continue;
- out.write(line.substring(offset+1));
+ do {
+ offset++;
+ } while(offset < line.length() && line.charAt(offset) == '*');
+ if (addBreak) out.write('\n');
+ if (offset >= line.length()) continue;
+ out.write(line.substring(offset+1).trim());
+ addBreak = true;
}
- comments[i].setText(sw.toString());
+ comments[i].setText(out.toString());
} catch(IOException veryUnexpected) {
veryUnexpected.printStackTrace();
}
}
- }
-*/
+ }
}
}
1.3 +1 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JServiceParamsImpl.java
Index: JServiceParamsImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/JServiceParamsImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JServiceParamsImpl.java 3 Mar 2004 03:57:49 -0000 1.2
+++ JServiceParamsImpl.java 3 Mar 2004 08:25:26 -0000 1.3
@@ -261,7 +261,7 @@
if (mCommentInitializer != null) {
initers.add(mCommentInitializer);
} else {
- //FIXME initers.add(new DefaultCommentInitializer());
+ initers.add(DefaultCommentProcessor.getInstance());
}
if (mOtherInitializers != null) initers.addAll(mOtherInitializers);
// now go
1.3 +1 -1 xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/ReflectionClassBuilder.java
Index: ReflectionClassBuilder.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider/ReflectionClassBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectionClassBuilder.java 3 Mar 2004 00:01:42 -0000 1.2
+++ ReflectionClassBuilder.java 3 Mar 2004 08:25:26 -0000 1.3
@@ -45,7 +45,7 @@
* @deprecated just to wean us off the R* impls.
*/
public static JClassLoader createRClassLoader(ClassLoader cl) {
- return new JClassLoaderImpl(new ReflectionClassBuilder(cl),null);
+ return new JClassLoaderImpl(new ReflectionClassBuilder(cl));
}
public static EClassBuilder getSystemClassBuilder() {
1.5 +1 -0 xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java
Index: FooImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/FooImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FooImpl.java 2 Mar 2004 20:21:53 -0000 1.4
+++ FooImpl.java 3 Mar 2004 08:25:26 -0000 1.5
@@ -36,4 +36,5 @@
+
}
1.1 xml-xmlbeans/v2/test/src/jamtest/dummyclasses/org/apache/xmlbeans/test/jam/dummyclasses/HeavilyCommented.java
Index: HeavilyCommented.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.test.jam.dummyclasses;
import org.apache.xmlbeans.test.jam.dummyclasses.ejb.MyEjbException;
import java.net.MalformedURLException;
/**
*
* @author Patrick Calahan <pc...@bea.com>
*/
public abstract class HeavilyCommented {
/**
* A simple comment.
*/
protected abstract void simpleComment();
/**
* A comment which
* spans
*
* several
*
*
* lines.
*/
protected abstract void multilineComment();
/**
* Here is some
**funky
comment text
but it should still
**** parse correctly
*/
// protected abstract void strangeComment();
}
1.5 +4 -0 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ClassesJamTest.java
Index: ClassesJamTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ClassesJamTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClassesJamTest.java 2 Mar 2004 08:28:19 -0000 1.4
+++ ClassesJamTest.java 3 Mar 2004 08:25:26 -0000 1.5
@@ -90,4 +90,8 @@
}
protected boolean isParameterNamesKnown() { return false; }
+
+ protected boolean isCommentsAvailable() {
+ return false;
+ }
}
1.9 +35 -0 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java
Index: JamTestBase.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/JamTestBase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JamTestBase.java 3 Mar 2004 00:01:43 -0000 1.8
+++ JamTestBase.java 3 Mar 2004 08:25:26 -0000 1.9
@@ -90,6 +90,7 @@
DUMMY+".Baz",
DUMMY+".Foo",
DUMMY+".FooImpl",
+ DUMMY+".HeavilyCommented",
DUMMY+".MyException"
};
@@ -119,6 +120,20 @@
}
};
+ // this needs to correspond to the methods on the FooImpl dummyclass
+ private static final String[] HEAVILY_COMMENTS = {
+ "A simple comment.",
+ "A comment which\nspans\n\nseveral\n\n\nlines."
+ };
+ /**
+ * A comment which
+ * spans
+ *
+ * several
+ *
+ *
+ * lines.
+ */
private static final boolean VERBOSE = false;
@@ -158,6 +173,8 @@
//JStore
protected abstract boolean isParameterNamesKnown();
+ protected abstract boolean isCommentsAvailable();
+
// ========================================================================
// Utility methods
@@ -204,6 +221,24 @@
resolveCheckRecursively(mResult.getAllClasses(),new HashSet());
}
+
+ /**
+ * Test comment parsing on the HeavilyCommented dummy class.
+ */
+ public void testComments() {
+ if (!isCommentsAvailable()) return;
+ JClass hcImpl = mLoader.loadClass(DUMMY+".HeavilyCommented");
+ JMethod[] methods = hcImpl.getDeclaredMethods();
+ for(int i=0; i<methods.length; i++) {
+ JComment[] comments = methods[i].getComments();
+ assertTrue(methods[i].getSimpleName()+" has "+comments.length+
+ "comments, expecting exactly one.",
+ (comments.length == 1));
+ assertTrue("'"+comments[0].getText()+"'\ndoes not match expected\n'" +
+ HEAVILY_COMMENTS[i]+"'",
+ HEAVILY_COMMENTS[i].equals(comments[0].getText()));
+ }
+ }
/**
1.5 +4 -0 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ParserJamTest.java
Index: ParserJamTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/ParserJamTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ParserJamTest.java 3 Mar 2004 00:01:43 -0000 1.4
+++ ParserJamTest.java 3 Mar 2004 08:25:26 -0000 1.5
@@ -51,4 +51,8 @@
protected boolean isParameterNamesKnown() {
return true;
}
+
+ protected boolean isCommentsAvailable() {
+ return true;
+ }
}
1.5 +4 -0 xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/SourcesJamTest.java
Index: SourcesJamTest.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/test/src/jamtest/tests/org/apache/xmlbeans/test/jam/SourcesJamTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SourcesJamTest.java 2 Mar 2004 08:28:19 -0000 1.4
+++ SourcesJamTest.java 3 Mar 2004 08:25:26 -0000 1.5
@@ -92,4 +92,8 @@
protected boolean isParameterNamesKnown() {
return true;
}
+
+ protected boolean isCommentsAvailable() {
+ return true;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org