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/04 05:24:24 UTC
cvs commit: xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/provider DefaultCommentProcessor.java
pcal 2004/03/03 20:24:24
Modified: v2/src/jam/org/apache/xmlbeans/impl/jam/provider
DefaultCommentProcessor.java
Log:
jam: little more work on comment stuff
Revision Changes Path
1.4 +110 -8 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultCommentProcessor.java 4 Mar 2004 03:07:43 -0000 1.3
+++ DefaultCommentProcessor.java 4 Mar 2004 04:24:24 -0000 1.4
@@ -15,8 +15,13 @@
package org.apache.xmlbeans.impl.jam.provider;
import org.apache.xmlbeans.impl.jam.editable.*;
+import org.apache.xmlbeans.impl.jam.JComment;
+import org.apache.xmlbeans.impl.jam.JAnnotation;
+import org.apache.xmlbeans.impl.jam.internal.BaseJAnnotation;
import java.io.*;
+import java.util.*;
+import java.lang.reflect.Method;
/**
*
@@ -35,6 +40,17 @@
private DefaultCommentProcessor() {}
// ========================================================================
+ // Constants
+
+ private static final int TAGNAME_COL = 0;
+ private static final int CLASSNAME_COL = 1;
+
+ // ========================================================================
+ // Variables
+
+ private Map mTag2Annclass = null; //maps jd tag names to annotation classes
+
+ // ========================================================================
// EClassInitializer implementation
public void initialize(EClass clazz) {
@@ -42,6 +58,17 @@
}
// ========================================================================
+ // Public methods
+
+ public void setJavadocTagMappings(String[][] mappings) {
+ if (mappings == null) throw new IllegalArgumentException("null mappings");
+ mTag2Annclass = new HashMap();
+ for(int i=0; i<mappings.length; i++) {
+ mTag2Annclass.put(mappings[i][TAGNAME_COL],mappings[i][CLASSNAME_COL]);
+ }
+ }
+
+ // ========================================================================
// EElementVisitor implementation - nothing to see here
public void visit(EClass clazz) { visit((EElement)clazz); }
@@ -57,33 +84,108 @@
protected void visit(EElement element) {
EComment comment = element.getEditableComment();
- if (comment == null) return;
+ if (comment != null) {
+ String[] commentsAndTags = getCommentsAndTags(comment);
+ if (commentsAndTags == null || commentsAndTags.length == 0) return;
+ processComment(element,commentsAndTags[0]);
+ for(int i=1; i<commentsAndTags.length; i++) {
+ processJavadocTag(element,commentsAndTags[i]);
+ }
+ }
+ }
+
+ /**
+ * Returns an array of strings containing the javadoc comments and raw
+ * javadoc tag contents from the given element. Note that comment tokens
+ * (leading '/*', '*', and '*[slash]' are stripped from the comments,
+ * and they are trimmed up a bit. The tag sections contain the javadoc
+ * tag, including the leading '@'. Array index 0 contains the comments,
+ * and each subsequent index holds the javadoc tag contents, if any.
+ *
+ */
+ protected String[] getCommentsAndTags(JComment comment) {
String text = comment.getText().trim();
if (!text.startsWith("/*")) {
- element.removeComment();
- return;
+ return new String[] {comment.getText()}; //not sure what to do with this
}
+ // looks like we have real work to do. first set up a reader
BufferedReader in = new BufferedReader(new StringReader(text));
+ // now create a list to store the string we will return
+ List commentsAndTags = new ArrayList();
+ // get the comment string
StringWriter commentText = new StringWriter();
String nextLine = eatDocChunk(in,commentText);
- processComment(element,commentText.toString());
+ commentsAndTags.add(commentText.toString());
+ // now process the tags, if any
while(nextLine != null) {
StringWriter tagText = new StringWriter();
tagText.write(nextLine);
tagText.write('\n');
nextLine = eatDocChunk(in,tagText);
- processJavadocTag(element,tagText.toString());
+ commentsAndTags.add(tagText.toString());
}
+ String[] out = new String[commentsAndTags.size()];
+ commentsAndTags.toArray(out);
+ return out;
}
- protected void processJavadocTag(EElement element, String tagline) {
-
- }
protected void processComment(EElement commentedElement,
String trimmedComment) {
commentedElement.getEditableComment().setText(trimmedComment);
}
+
+ private String mNameValueSeparators;
+ private ClassLoader mAnnotationClassLoader = null;//FIXME
+ private static final String DEFAULT_NAME_VALUE_SEPS = "\n\r";
+
+ protected void processJavadocTag(EElement element, String tagtext) {
+ if (mTag2Annclass != null) {
+ StringTokenizer st = new StringTokenizer(tagtext,mNameValueSeparators);
+ //get the tagname. it'd better start with '@'
+ String tagName = st.nextToken().trim();
+ if (!tagName.startsWith("@")) {
+ throw new IllegalArgumentException("invalid tagtext '"+tagtext+"'");
+ }
+ tagName = tagName.substring(1).trim();
+ // get the class it maps to and instantiate one
+ String classname = (String)mTag2Annclass.get(tagName);
+ if (classname == null) return; //nothing to be done. maybe log something?
+ Object ann;
+ try {
+ Class annClass = mAnnotationClassLoader.loadClass(classname);
+ ann = annClass.newInstance();
+ } catch(ClassNotFoundException cnfe) {
+ cnfe.printStackTrace();//FIXME better logging
+ return;
+ } catch(InstantiationException ie) {
+ ie.printStackTrace();//FIXME better logging
+ return; // maybe should be logged?
+ } catch(IllegalAccessException iae) {
+ iae.printStackTrace(); //FIXME better logging
+ return; // maybe should be logged?
+ }
+ // cool. now create an EAnnotation to wrap it
+ EAnnotation ea = element.addNewAnnotation();
+ ea.setAnnotationObject(ann);
+ // now populate ann from name-value pairs FIXME
+ while (st.hasMoreTokens()) {
+ String pair = st.nextToken();
+ int eq = pair.indexOf('=');
+ if (eq <= 0) continue; // if not there or is first character
+ String name = pair.substring(0, eq).trim();
+ String value = (eq < pair.length() - 1) ? pair.substring(eq + 1) : null;
+ setValue(ann,name,value);
+ }
+ }
+ }
+
+ private void setValue(Object dest, String name, String value) {
+ //FIXME Method
+ }
+
+
+
// ========================================================================
// Private methods
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org