[Jiemamy-notify] commit [1952] [CORE-76] Modelの実装ソースに含まれるfieldを拾うのではなく、Modelのインターフェースに含まれるgetterからfieldを拾う(名称を推測)するよう修正

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 9月 24日 (水) 03:24:48 JST


Revision: 1952
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=1952
Author:   shin1
Date:     2008-09-24 03:24:48 +0900 (Wed, 24 Sep 2008)

Log Message:
-----------
[CORE-76]Modelの実装ソースに含まれるfieldを拾うのではなく、Modelのインターフェースに含まれるgetterからfieldを拾う(名称を推測)するよう修正

Modified Paths:
--------------
    sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java


-------------- next part --------------
Modified: sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java
===================================================================
--- sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java	2008-09-23 17:14:10 UTC (rev 1951)
+++ sandbox/org.jiemamy.core.eventcodegen/trunk/org.jiemamy.core.eventcodegen/src/main/java/org/jiemamy/core/eventcodegen/JiemamyModelDoclet.java	2008-09-23 18:24:48 UTC (rev 1952)
@@ -20,9 +20,10 @@
 
 import com.sun.javadoc.ClassDoc;
 import com.sun.javadoc.Doclet;
-import com.sun.javadoc.FieldDoc;
 import com.sun.javadoc.LanguageVersion;
+import com.sun.javadoc.MethodDoc;
 import com.sun.javadoc.RootDoc;
+import com.sun.javadoc.Type;
 
 /**
  * Event用のソースを自動生成する。 j-coreプロジェクト配下のソースを読み込み、{@link JiemamyModel}を発見した場合にその{@link JiemamyModel}用のChangeListenerとChangeSupportを自動生成する。
@@ -32,10 +33,10 @@
 public class JiemamyModelDoclet extends Doclet {
 	public List<JiemamyModel> model;
 	public Map<Class<?>, CollectionProperty> collectionProperties = new HashMap<Class<?>, CollectionProperty>();
-//	 public static final String OUTPUTDIR_SPECS = "src/main/java/";
-	 public static final String OUTPUTDIR_IMPLEMENTS = "src/main/java/";
-//	public static final String OUTPUTDIR_IMPLEMENTS = "../org.jiemamy.core/src/main/java/";
-	public static final String OUTPUTDIR_SPECS = "../org.jiemamy.spec.event/src/main/java/";
+	 public static final String OUTPUTDIR_SPECS = "src/main/java/";
+	public static final String OUTPUTDIR_IMPLEMENTS = "src/main/java/";
+	// public static final String OUTPUTDIR_IMPLEMENTS = "../org.jiemamy.core/src/main/java/";
+//	public static final String OUTPUTDIR_SPECS = "../org.jiemamy.spec.event/src/main/java/";
 
 	public static LanguageVersion languageVersion() {
 		return LanguageVersion.JAVA_1_5;
@@ -118,30 +119,34 @@
 		addImportClasses(importClasses,
 				"org.jiemamy.spec.event.ObservableCollectionChangeEvent");
 		List<CollectionProperty> properties = new ArrayList<CollectionProperty>();
-		FieldDoc[] fields = classDoc.fields();
-		for (FieldDoc fieldDoc : fields) {
-			String fieldTypeName = fieldDoc.type().qualifiedTypeName();
+		MethodDoc[] methods = classDoc.methods();
+		for (MethodDoc methodDoc : methods) {
+			if (methodDoc.name().startsWith("get") == false) {
+				continue;
+			}
+			Type type = methodDoc.returnType();
+			String fieldTypeName = type.qualifiedTypeName();
 			Class<?> fieldType = Class.forName(fieldTypeName);
 			if (isSubClass(fieldType, List.class)
 					|| isSubClass(fieldType, List.class)) {
 				// ListまたはSetのサブクラス
-				String parameterClassName = getParameterClassName(fieldDoc);
+				String parameterClassName = getParameterClassName(methodDoc);
 				addImportClasses(importClasses, fieldTypeName);
 				addImportClasses(importClasses, parameterClassName);
-				properties.add(new CollectionProperty(fieldDoc.name(), fieldDoc
-						.type().qualifiedTypeName().toString(),
-						parameterClassName));
+				properties
+						.add(new CollectionProperty(getFieldName(methodDoc),
+								type.qualifiedTypeName().toString(),
+								parameterClassName));
 			} else if (isSubClass(fieldType, Map.class)) {
 				// Mapのサブクラス
-				String[] parameterClassNames = getParameterClassNames(fieldDoc);
+				String[] parameterClassNames = getParameterClassNames(methodDoc);
 				addImportClasses(importClasses, fieldTypeName);
 				addImportClasses(importClasses, parameterClassNames[0]);
 				addImportClasses(importClasses, parameterClassNames[1]);
 				try {
 					CollectionProperty collectionProperty = new CollectionProperty(
-							fieldDoc.name(), fieldDoc.type()
-									.qualifiedTypeName().toString(),
-							parameterClassNames[1]);
+							getFieldName(methodDoc), type.qualifiedTypeName()
+									.toString(), parameterClassNames[1]);
 					collectionProperty
 							.setMapKeyClassName(parameterClassNames[0]);
 					properties.add(collectionProperty);
@@ -236,6 +241,11 @@
 		}
 	}
 
+	private static String getFieldName(MethodDoc methodDoc) {
+		String name = methodDoc.name().replaceFirst("get", "");
+		return name.substring(0, 1).toLowerCase() + name.substring(1);
+	}
+
 	/**
 	 * あるクラスがあるクラスのサブクラスかどうか。
 	 * 
@@ -266,11 +276,11 @@
 	/**
 	 * {@link List}や{@link Set}フィールドのGeneric情報を返す。
 	 * 
-	 * @param fieldDoc
+	 * @param methodDoc
 	 * @return
 	 */
-	private static String getParameterClassName(FieldDoc fieldDoc) {
-		String parameterizedType = fieldDoc.type().asParameterizedType()
+	private static String getParameterClassName(MethodDoc methodDoc) {
+		String parameterizedType = methodDoc.returnType().asParameterizedType()
 				.toString();
 		int index1 = parameterizedType.indexOf('<');
 		int index2 = parameterizedType.lastIndexOf('>');
@@ -280,11 +290,11 @@
 	/**
 	 * {@link Map}フィールドのGeneric情報を返す。
 	 * 
-	 * @param fieldDoc
+	 * @param methodDoc
 	 * @return
 	 */
-	private static String[] getParameterClassNames(FieldDoc fieldDoc) {
-		String parameterizedType = fieldDoc.type().asParameterizedType()
+	private static String[] getParameterClassNames(MethodDoc methodDoc) {
+		String parameterizedType = methodDoc.returnType().asParameterizedType()
 				.toString();
 		int index1 = parameterizedType.indexOf('<');
 		int index2 = parameterizedType.lastIndexOf('>');


Jiemamy-notify メーリングリストの案内
Back to archive index