Eugene-commits
Threads by month
- ----- 2026 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
January 2011
- 2 participants
- 16 discussions
r1044 - in trunk/eugene/src: main/java/org/nuiton/eugene main/java/org/nuiton/eugene/java/extension test/java/org/nuiton/eugene/java/extension
by tchemit@users.nuiton.org Jan. 31, 2011
by tchemit@users.nuiton.org Jan. 31, 2011
Jan. 31, 2011
Author: tchemit
Date: 2011-01-31 19:08:12 +0100 (Mon, 31 Jan 2011)
New Revision: 1044
Url: http://nuiton.org/repositories/revision/eugene/1044
Log:
Improve importerManager
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2011-01-31 13:32:42 UTC (rev 1043)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2011-01-31 18:08:12 UTC (rev 1044)
@@ -165,6 +165,21 @@
return false;
}
String type = attribute.getType();
+ return isPrimitiveType(type);
+// return "byte".equals(type) || "short".equals(type)
+// || "int".equals(type) || "long".equals(type)
+// || "float".equals(type) || "double".equals(type)
+// || "char".equals(type) || "boolean".equals(type);
+ }
+
+ /**
+ * Tests if the given type is a primitive type.
+ *
+ * @param type the type to test
+ * @return {@code true} if given type is primitive.
+ * @since 2.3.2
+ */
+ public static boolean isPrimitiveType(String type) {
return "byte".equals(type) || "short".equals(type)
|| "int".equals(type) || "long".equals(type)
|| "float".equals(type) || "double".equals(type)
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-31 13:32:42 UTC (rev 1043)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-31 18:08:12 UTC (rev 1044)
@@ -120,22 +120,29 @@
if (fqn.trim().isEmpty() ||
fqn.startsWith("java.lang.") && lastDotIndex == 9) {
+
+ // reacts as if it was imported
return true;
}
// Exclude primitive types
if (primitiveTypes.contains(fqn)) {
- return true;
+
+ // was not imported
+ return false;
}
if (JavaGeneratorUtil.containsGenerics(fqn)) {
// Generics case :
String[] parts = JavaGeneratorUtil.splitGeneric(fqn);
- for (String part : parts) {
- if (addImport(part)) {
- return true;
- }
+ boolean doImport = false;
+ if (addImport(parts[0])) {
+ doImport = true;
}
- return false;
+ for (int i = 1, partsLength = parts.length; i < partsLength; i++) {
+ String part = parts[i];
+ addImport(part);
+ }
+ return doImport;
}
// // Reject generics
// if (fqn.contains("<") || fqn.contains(">")) {
@@ -166,11 +173,6 @@
*/
public String getType(String fqn) {
boolean importResult = addImport(fqn);
- if (!importResult) {
-
- // There is a conflict, do not use simple name
- return fqn;
- }
if (JavaGeneratorUtil.containsGenerics(fqn)) {
String[] parts = JavaGeneratorUtil.splitGeneric(fqn);
@@ -180,6 +182,12 @@
}
return JavaGeneratorUtil.joinGeneric(parts);
}
+
+ if (!importResult) {
+
+ // There is a conflict, do not use simple name
+ return fqn;
+ }
// No conflict, use simple name
int packageEndIndex = getLastDotIndex(fqn);
if (packageEndIndex == -1) {
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-31 13:32:42 UTC (rev 1043)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-31 18:08:12 UTC (rev 1044)
@@ -125,6 +125,32 @@
}
@Test
+ public void testGetImportsWithWildcard() throws Exception {
+ Assert.assertTrue(mgr.addImport("org.nuiton.eugene.*"));
+ Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Toto"));
+ Assert.assertTrue(mgr.addImport("org.nuiton.eugene.subpackage.Tata"));
+ List<String> imports = mgr.getImports("org.nuiton.eugene");
+ Assert.assertEquals(1, imports.size());
+ Assert.assertEquals("org.nuiton.eugene.subpackage.Tata", imports.get(0));
+
+ imports = mgr.getImports("org.nuiton");
+ Assert.assertEquals(3, imports.size());
+ // Check using alphabetic sort
+ Assert.assertEquals("org.nuiton.eugene.*", imports.get(0));
+ Assert.assertEquals("org.nuiton.eugene.Toto", imports.get(1));
+ Assert.assertEquals("org.nuiton.eugene.subpackage.Tata", imports.get(2));
+ }
+
+@Test
+ public void testGetImportsWithGeneric() throws Exception {
+ Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Toto<String, java.util.File>"));
+ List<String> imports = mgr.getImports("org.nuiton.eugene");
+ Assert.assertEquals(1, imports.size());
+ Assert.assertEquals("java.util.File", imports.get(0));
+ }
+
+
+ @Test
public void testGetImports() throws Exception {
Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Toto"));
Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Tutu"));
1
0
Author: tchemit
Date: 2011-01-31 14:32:42 +0100 (Mon, 31 Jan 2011)
New Revision: 1043
Url: http://nuiton.org/repositories/revision/eugene/1043
Log:
use i18n 2.3
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-29 13:50:52 UTC (rev 1042)
+++ trunk/pom.xml 2011-01-31 13:32:42 UTC (rev 1043)
@@ -366,7 +366,7 @@
<processorPluginVersion>1.1</processorPluginVersion>
<nuitonUtilsVersion>2.0</nuitonUtilsVersion>
- <nuitonI18nVersion>2.2</nuitonI18nVersion>
+ <nuitonI18nVersion>2.3</nuitonI18nVersion>
<!--Multilanguage maven-site -->
<locales>en,fr</locales>
1
0
r1042 - in trunk/eugene/src: main/java/org/nuiton/eugene/java main/java/org/nuiton/eugene/java/extension test/java/org/nuiton/eugene/java test/java/org/nuiton/eugene/java/extension
by tchemit@users.nuiton.org Jan. 29, 2011
by tchemit@users.nuiton.org Jan. 29, 2011
Jan. 29, 2011
Author: tchemit
Date: 2011-01-29 14:50:52 +0100 (Sat, 29 Jan 2011)
New Revision: 1042
Url: http://nuiton.org/repositories/revision/eugene/1042
Log:
Evolution #1268: Improve importManager
Evolution #1273: Add usefull method in JavaGeneratorUtil to deal with generics
Added:
trunk/eugene/src/test/java/org/nuiton/eugene/java/JavaGeneratorUtilTest.java
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2011-01-29 07:20:31 UTC (rev 1041)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGeneratorUtil.java 2011-01-29 13:50:52 UTC (rev 1042)
@@ -34,6 +34,9 @@
import org.nuiton.eugene.models.object.ObjectModelOperation;
import org.nuiton.eugene.models.object.ObjectModelParameter;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Utility class for pure java templates.
*
@@ -174,4 +177,208 @@
String value = findTagValue(EugeneTagValues.TAG_CONSTANT_PREFIX, classifier, model);
return value;
}
+
+ /**
+ * Split the given fqn which contains a generic declaration into his parts.
+ * <p/>
+ * Example :
+ * <pre>
+ * java.util.List<Integer> : [java.util.List, Integer]
+ * java.util.List<java.util.List<Integer>> : [java.util.List, java.util.List<Integer>]
+ * java.util.Map<Integer, Integer> : [java.util.Map, Integer, Integer]
+ * java.util.Map<Integer, java.util.List<Integer>> : [java.util.Map, Integer, java.util.List<Integer>]
+ * <p/>
+ * </pre>
+ * <strong>Note:</strong> We only deal with one level of generics here in
+ * order to be able easly to rebuild after all the fqn with simple names...
+ *
+ * @param fqn the fqn to split
+ * @return the array of all parts of the fqn.
+ * @since 2.3.2
+ */
+ public static String[] splitGeneric(String fqn) {
+ if (fqn == null) {
+ return null;
+ }
+
+ int firstPartIndex = fqn.indexOf('<');
+ if (firstPartIndex == -1) {
+
+ // no generics, just return the fqn
+ return new String[]{fqn};
+ }
+
+ List<String> parts = new ArrayList<String>();
+ parts.add(fqn.substring(0, firstPartIndex));
+ String rest = fqn.substring(firstPartIndex + 1,
+ fqn.lastIndexOf('>'));
+
+ if (containsGenerics(rest) && rest.contains(",")) {
+
+ // there is others generics in generics, worse case...
+ int begin = 0;
+ int count = 0;
+ int max = rest.length();
+ for (int i = 0; i < max; i++) {
+ char c = rest.charAt(i);
+ if (c == '<') {
+
+ count++;
+ } else if (c == '>') {
+
+ count--;
+ } else if (c == ',') {
+
+ // arrives on a possible split
+ if (count == 0) {
+
+ // can safely add this part
+ String part = rest.substring(begin, i);
+ parts.add(part.trim());
+ begin = i + 1;
+ }
+ }
+ }
+
+ // there is a last part to add ?
+ if (begin < max) {
+ String part = rest.substring(begin, max);
+ parts.add(part.trim());
+ }
+
+ } else {
+
+ // simple case : each part of the generics has no other generics
+ String[] split = rest.split(",");
+ for (String part : split) {
+ parts.add(part.trim());
+ }
+ }
+
+ return parts.toArray(new String[parts.size()]);
+ }
+
+ /**
+ * Join generics parts of a fqn into aparts.
+ * <p/>
+ * Example :
+ * <pre>
+ * [java.util.List, Integer] : java.util.List<Integer>
+ * [java.util.List, java.util.List<Integer>] : java.util.List<java.util.List<Integer>>
+ * [java.util.Map, Integer, Integer] : java.util.Map<Integer, Integer>
+ * [java.util.Map, Integer, java.util.List<Integer>] : java.util.Map<Integer, java.util.List<Integer>>
+ * </pre>
+ *
+ * @param genericParts the parts of fqn
+ * @return the fqn from his parts
+ * @since 2.3.2
+ */
+ public static String joinGeneric(String... genericParts) {
+
+ if (genericParts == null || genericParts.length == 0) {
+
+ // this case should never happen ?
+ return null;
+ }
+
+ if (genericParts.length == 1) {
+
+ // in fact, no generics
+ return genericParts[0];
+ }
+
+ StringBuilder sb = new StringBuilder(genericParts[0]);
+
+ sb.append("<").append(genericParts[1]);
+
+ for (int i = 2, max = genericParts.length; i < max; i++) {
+ String genericPart = genericParts[i];
+ sb.append(", ").append(genericPart);
+ }
+ sb.append('>');
+ return sb.toString();
+ }
+
+ /**
+ * Tells if the given fqn contains a generic declaration (says contains a
+ * {@code <} caracter).
+ *
+ * @param fqn the fqn to test
+ * @return {@code true} if given fqn contains a generic declaration
+ * @since 2.3.2
+ */
+ public static boolean containsGenerics(String fqn) {
+ return fqn.contains("<");
+ }
+
+ /**
+ * Split the given fqns gieven the list separator.
+ * <p/>
+ * Example :
+ * <pre>
+ * Boolean, File : [Boolean, File]
+ * Boolean , java.util.List<Integer> : [Boolean, java.util.List<Integer>]
+ * <p/>
+ * </pre>
+ * <p/>
+ * <strong>Note:</strong> You can NOT use as separator {@code '<'} nor
+ * {@code '>'} nor {@code ' '}.
+ *
+ * @param fqns the fqn list to split
+ * @param separator the fqn separactor char
+ * @return the array of all parts of the fqn.
+ * @since 2.3.2
+ */
+ public static String[] splitFqnList(String fqns, char separator) {
+ if (separator == '<' || separator == '>' || separator == ' ') {
+ throw new IllegalArgumentException(
+ "Can not use '<' nor '>' for the separator");
+ }
+ if (fqns == null) {
+ return null;
+ }
+
+ int firstPartIndex = fqns.indexOf('<');
+ if (firstPartIndex == -1) {
+
+ // no generics, just return the fqn
+ return new String[]{fqns};
+ }
+
+ List<String> parts = new ArrayList<String>();
+
+
+ // there is others generics in generics, worse case...
+ int begin = 0;
+ int count = 0;
+ int max = fqns.length();
+ for (int i = 0; i < max; i++) {
+ char c = fqns.charAt(i);
+ if (c == '<') {
+
+ count++;
+ } else if (c == '>') {
+
+ count--;
+ } else if (c == separator) {
+
+ // arrives on a possible split
+ if (count == 0) {
+
+ // can safely add this part
+ String part = fqns.substring(begin, i);
+ parts.add(part.trim());
+ begin = i + 1;
+ }
+ }
+ }
+
+ // there is a last part to add ?
+ if (begin < max) {
+ String part = fqns.substring(begin, max);
+ parts.add(part.trim());
+ }
+
+ return parts.toArray(new String[parts.size()]);
+ }
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-29 07:20:31 UTC (rev 1041)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-29 13:50:52 UTC (rev 1042)
@@ -27,6 +27,7 @@
import org.apache.commons.lang.StringUtils;
import org.nuiton.eugene.GeneratorUtil;
+import org.nuiton.eugene.java.JavaGeneratorUtil;
import java.util.ArrayList;
import java.util.Collections;
@@ -125,10 +126,10 @@
if (primitiveTypes.contains(fqn)) {
return true;
}
- if (containsGenerics(fqn)) {
+ if (JavaGeneratorUtil.containsGenerics(fqn)) {
// Generics case :
- String[] parts = splitGeneric(fqn);
+ String[] parts = JavaGeneratorUtil.splitGeneric(fqn);
for (String part : parts) {
if (addImport(part)) {
return true;
@@ -170,14 +171,14 @@
// There is a conflict, do not use simple name
return fqn;
}
- if (containsGenerics(fqn)) {
+ if (JavaGeneratorUtil.containsGenerics(fqn)) {
- String[] parts = splitGeneric(fqn);
+ String[] parts = JavaGeneratorUtil.splitGeneric(fqn);
for (int i = 0; i < parts.length; i++) {
String part = parts[i];
parts[i] = getType(part);
}
- return joinGeneric(parts);
+ return JavaGeneratorUtil.joinGeneric(parts);
}
// No conflict, use simple name
int packageEndIndex = getLastDotIndex(fqn);
@@ -192,7 +193,7 @@
if (StringUtils.isBlank(returnType)) {
return null;
}
- if (containsGenerics(returnType)) {
+ if (JavaGeneratorUtil.containsGenerics(returnType)) {
// the return type is in two parts : <...> ...
String[] parts =
@@ -253,139 +254,6 @@
}
/**
- * Split the given fqn which contains a generic declaration into his parts.
- * <p/>
- * Example :
- * <pre>
- * java.util.List<Integer> : [java.util.List, Integer]
- * java.util.List<java.util.List<Integer>> : [java.util.List, java.util.List<Integer>]
- * java.util.Map<Integer, Integer> : [java.util.Map, Integer, Integer]
- * java.util.Map<Integer, java.util.List<Integer>> : [java.util.Map, Integer, java.util.List<Integer>]
- * <p/>
- * </pre>
- * <strong>Note:</strong> We only deal with one level of generics here in
- * order to be able easly to rebuild after all the fqn with simple names...
- *
- * @param fqn the fqn to split
- * @return the array of all parts of the fqn.
- * @since 2.3.2
- */
- public String[] splitGeneric(String fqn) {
- if (fqn == null) {
- return null;
- }
-
- int firstPartIndex = fqn.indexOf('<');
- if (firstPartIndex == -1) {
-
- // no generics, just return the fqn
- return new String[]{fqn};
- }
-
- List<String> parts = new ArrayList<String>();
- parts.add(fqn.substring(0, firstPartIndex));
- String rest = fqn.substring(firstPartIndex + 1,
- fqn.lastIndexOf('>'));
-
- if (containsGenerics(rest) && rest.contains(",")) {
-
- // there is others generics in generics, worse case...
- int begin = 0;
- int count = 0;
- int max = rest.length();
- for (int i = 0; i < max; i++) {
- char c = rest.charAt(i);
- if (c == '<') {
-
- count++;
- } else if (c == '>') {
-
- count--;
- } else if (c == ',') {
-
- // arrives on a possible split
- if (count == 0) {
-
- // can safely add this part
- String part = rest.substring(begin, i);
- parts.add(part.trim());
- begin = i + 1;
- }
- }
- }
-
- // there is a last part to add ?
- if (begin < max) {
- String part = rest.substring(begin, max);
- parts.add(part.trim());
- }
-
- } else {
-
- // simple case : each part of the generics has no other generics
- String[] split = rest.split(",");
- for (String part : split) {
- parts.add(part.trim());
- }
- }
-
- return parts.toArray(new String[parts.size()]);
- }
-
- /**
- * Join generics parts of a fqn into aparts.
- * <p/>
- * Example :
- * <pre>
- * [java.util.List, Integer] : java.util.List<Integer>
- * [java.util.List, java.util.List<Integer>] : java.util.List<java.util.List<Integer>>
- * [java.util.Map, Integer, Integer] : java.util.Map<Integer, Integer>
- * [java.util.Map, Integer, java.util.List<Integer>] : java.util.Map<Integer, java.util.List<Integer>>
- * </pre>
- *
- * @param genericParts the parts of fqn
- * @return the fqn from his parts
- * @since 2.3.2
- */
- public String joinGeneric(String... genericParts) {
-
- if (genericParts == null || genericParts.length == 0) {
-
- // this case should never happen ?
- return null;
- }
-
- if (genericParts.length == 1) {
-
- // in fact, no generics
- return genericParts[0];
- }
-
- StringBuilder sb = new StringBuilder(genericParts[0]);
-
- sb.append("<").append(genericParts[1]);
-
- for (int i = 2, max = genericParts.length; i < max; i++) {
- String genericPart = genericParts[i];
- sb.append(", ").append(genericPart);
- }
- sb.append('>');
- return sb.toString();
- }
-
- /**
- * Tells if the given fqn contains a generic declaration (says contains a
- * {@code <} caracter).
- *
- * @param fqn the fqn to test
- * @return {@code true} if given fqn contains a generic declaration
- * @since 2.3.2
- */
- public boolean containsGenerics(String fqn) {
- return fqn.contains("<");
- }
-
- /**
* Obtains the last dot index in the given fqn.
*
* @param fqn the fqn to test
Added: trunk/eugene/src/test/java/org/nuiton/eugene/java/JavaGeneratorUtilTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/java/JavaGeneratorUtilTest.java (rev 0)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/java/JavaGeneratorUtilTest.java 2011-01-29 13:50:52 UTC (rev 1042)
@@ -0,0 +1,129 @@
+package org.nuiton.eugene.java;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.util.StringUtil;
+
+/**
+ * Test class {@link JavaGeneratorUtil}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.3.2
+ */
+public class JavaGeneratorUtilTest {
+
+ @Test
+ public void splitGeneric() throws Exception {
+
+ String[] actual;
+ String[] expected;
+
+ expected = null;
+ actual = JavaGeneratorUtil.splitGeneric(null);
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.List");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "Integer"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.List<Integer>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "java.util.List<Integer>"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.List<java.util.List<Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "Integer"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.Map<Integer, Integer>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.List<Integer>"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.Map<Integer, java.util.List<Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer>"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "X<Y<Z>>", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = JavaGeneratorUtil.splitGeneric("java.util.Map< X<Y<Z>>, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+
+ @Test
+ public void joinGeneric() throws Exception {
+ String actual;
+ String expected;
+
+ expected = null;
+ actual = JavaGeneratorUtil.joinGeneric((String) null);
+ Assert.assertEquals(expected, actual);
+
+ expected = null;
+ actual = JavaGeneratorUtil.joinGeneric(StringUtil.EMPTY_STRING_ARRAY);
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.List";
+ actual = JavaGeneratorUtil.joinGeneric("java.util.List");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.List<Integer>";
+ actual = JavaGeneratorUtil.joinGeneric("java.util.List", "Integer");
+ Assert.assertEquals(expected, actual);
+
+
+ expected = "java.util.List<java.util.List<Integer>>";
+ actual = JavaGeneratorUtil.joinGeneric("java.util.List", "java.util.List<Integer>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.Map<Integer, Integer>";
+ actual = JavaGeneratorUtil.joinGeneric("java.util.Map", "Integer", "Integer");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.Map<Integer, java.util.List<Integer>>";
+ actual = JavaGeneratorUtil.joinGeneric("java.util.Map", "Integer", "java.util.List<Integer>");
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void splitFqnList() throws Exception {
+
+ String[] actual;
+ String[] expected;
+
+ expected = null;
+ actual = JavaGeneratorUtil.splitFqnList(null, ',');
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List"};
+ actual = JavaGeneratorUtil.splitFqnList("java.util.List", ',');
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"Integer", "java.util.List<Integer>"};
+ actual = JavaGeneratorUtil.splitFqnList("Integer, java.util.List<Integer>", ',');
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "java.util.List<java.util.List<Integer>>"};
+ actual = JavaGeneratorUtil.splitFqnList("java.util.List, java.util.List<java.util.List<Integer>>", ',');
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "java.util.Map<Integer, Integer>"};
+ actual = JavaGeneratorUtil.splitFqnList("java.util.List, java.util.Map<Integer, Integer>", ',');
+ Assert.assertArrayEquals(expected, actual);
+
+
+ expected = new String[]{"java.util.Map< X<Y<Z>>>", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = JavaGeneratorUtil.splitFqnList("java.util.Map< X<Y<Z>>>, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>", ',');
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map< X<Y<Z>>>", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = JavaGeneratorUtil.splitFqnList("java.util.Map< X<Y<Z>>>| java.util.Map<Integer, Integer, Toto<A, B, C>>| X| Y<X>", '|');
+ Assert.assertArrayEquals(expected, actual);
+ }
+}
Property changes on: trunk/eugene/src/test/java/org/nuiton/eugene/java/JavaGeneratorUtilTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-29 07:20:31 UTC (rev 1041)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-29 13:50:52 UTC (rev 1042)
@@ -29,7 +29,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.nuiton.util.StringUtil;
import java.io.Serializable;
import java.util.List;
@@ -50,85 +49,6 @@
}
@Test
- public void splitGeneric() throws Exception {
-
- String[] actual;
- String[] expected;
-
- expected = null;
- actual = mgr.splitGeneric(null);
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.List"};
- actual = mgr.splitGeneric("java.util.List");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.List", "Integer"};
- actual = mgr.splitGeneric("java.util.List<Integer>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.List", "java.util.List<Integer>"};
- actual = mgr.splitGeneric("java.util.List<java.util.List<Integer>>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.Map", "Integer", "Integer"};
- actual = mgr.splitGeneric("java.util.Map<Integer, Integer>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.Map", "Integer", "java.util.List<Integer>"};
- actual = mgr.splitGeneric("java.util.Map<Integer, java.util.List<Integer>>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer>"};
- actual = mgr.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer>>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
- actual = mgr.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
- Assert.assertArrayEquals(expected, actual);
-
- expected = new String[]{"java.util.Map", "X<Y<Z>>", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
- actual = mgr.splitGeneric("java.util.Map< X<Y<Z>>, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
- Assert.assertArrayEquals(expected, actual);
- }
-
-
- @Test
- public void joinGeneric() throws Exception {
- String actual;
- String expected;
-
- expected = null;
- actual = mgr.joinGeneric((String) null);
- Assert.assertEquals(expected, actual);
-
- expected = null;
- actual = mgr.joinGeneric(StringUtil.EMPTY_STRING_ARRAY);
- Assert.assertEquals(expected, actual);
-
- expected = "java.util.List";
- actual = mgr.joinGeneric("java.util.List");
- Assert.assertEquals(expected, actual);
-
- expected = "java.util.List<Integer>";
- actual = mgr.joinGeneric("java.util.List", "Integer");
- Assert.assertEquals(expected, actual);
-
-
- expected = "java.util.List<java.util.List<Integer>>";
- actual = mgr.joinGeneric("java.util.List", "java.util.List<Integer>");
- Assert.assertEquals(expected, actual);
-
- expected = "java.util.Map<Integer, Integer>";
- actual = mgr.joinGeneric("java.util.Map", "Integer", "Integer");
- Assert.assertEquals(expected, actual);
-
- expected = "java.util.Map<Integer, java.util.List<Integer>>";
- actual = mgr.joinGeneric("java.util.Map", "Integer", "java.util.List<Integer>");
- Assert.assertEquals(expected, actual);
- }
-
- @Test
public void getReturnType() throws Exception {
String actual;
String expected;
1
0
r1041 - in trunk/eugene/src: main/java/org/nuiton/eugene main/java/org/nuiton/eugene/java/extension test/java/org/nuiton/eugene test/java/org/nuiton/eugene/java/extension
by tchemit@users.nuiton.org Jan. 29, 2011
by tchemit@users.nuiton.org Jan. 29, 2011
Jan. 29, 2011
Author: tchemit
Date: 2011-01-29 08:20:31 +0100 (Sat, 29 Jan 2011)
New Revision: 1041
Url: http://nuiton.org/repositories/revision/eugene/1041
Log:
Evolution #1268: Improve importManager
pass to debug level some tests
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManagerExtension.java
trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2011-01-27 08:53:21 UTC (rev 1040)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/GeneratorUtil.java 2011-01-29 07:20:31 UTC (rev 1041)
@@ -667,6 +667,48 @@
}
/**
+ *
+ * @param str the string to parse
+ * @return the string without any
+ * @since 2.3.2
+ */
+ public static String[] splitGenericDefinition(String str) {
+
+ // always trim the string
+ String result = str.trim();
+
+ if (!result.startsWith("<")) {
+
+ // not starting by a generics definition, no treatment to do
+ return new String[]{str};
+ }
+
+ int i = 0;
+ for (int length = result.length(), count = 0; i < length; i++) {
+ char c = result.charAt(i);
+ if ('<' == c) {
+ count++;
+ } else if ('>' == c) {
+ count--;
+ }
+ if (count == 0) {
+ break;
+ }
+ }
+
+ // the i position was on the last closing caracter, can safely
+ // remove until this position + 1
+ String prefix = result.substring(0,i+1);
+ String end = result.substring(i + 1);
+
+ // remove any starting spaces
+ while (end.startsWith(" ")) {
+ end = end.substring(1);
+ }
+ return new String[]{prefix, end};
+ }
+
+ /**
* Parse a fully qualified generic java type, and extract each
* imbricated types.
*
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-27 08:53:21 UTC (rev 1040)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManager.java 2011-01-29 07:20:31 UTC (rev 1041)
@@ -25,6 +25,9 @@
package org.nuiton.eugene.java.extension;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.eugene.GeneratorUtil;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -37,10 +40,10 @@
* Class used in generators that allows to manage easily imports. A first-pass
* allow to register imports, and in a second-pass, returns the type to use in
* generated code.
- *
- * @author thimel, chemit
- * @version $Revision$
*
+ * @author athimel <thimle(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
* @since 2.0.0
*/
public class ImportsManager {
@@ -73,11 +76,14 @@
primitiveTypes.add("void");
}
+
private Map<String, String> imports = new HashMap<String, String>();
+
private State state = State.FILLING;
/**
* From the given class, add it to the imports list.
+ *
* @param clazz the class to import
* @return true if import add was successful
* @see ImportsManager#addImport(String)
@@ -91,29 +97,50 @@
* If there is a conflict adding this import, will return false.
* If reading of the imports has started, this method will return false,
* unless type does not need to be imported.
+ *
* @param fqn the fully qualified name to import
* @return true if import add was successful
*/
public boolean addImport(String fqn) {
+
+ // don't include null fqn
+ if (fqn == null) {
+ return false;
+ }
+
+ int lastDotIndex = getLastDotIndex(fqn);
+
// if no package don't include it
- if (!fqn.contains(".")) {
+ if (lastDotIndex == -1) {
return true;
}
// Exclude java.lang classes
- if (fqn == null || fqn.trim().isEmpty() ||
- fqn.startsWith("java.lang.") && fqn.lastIndexOf(".") == 9) {
+
+ if (fqn.trim().isEmpty() ||
+ fqn.startsWith("java.lang.") && lastDotIndex == 9) {
return true;
}
// Exclude primitive types
if (primitiveTypes.contains(fqn)) {
return true;
}
- // Reject generics
- if (fqn.contains("<") || fqn.contains(">")) {
+ if (containsGenerics(fqn)) {
+
+ // Generics case :
+ String[] parts = splitGeneric(fqn);
+ for (String part : parts) {
+ if (addImport(part)) {
+ return true;
+ }
+ }
return false;
}
- String name = fqn.substring(fqn.lastIndexOf(".") + 1);
+// // Reject generics
+// if (fqn.contains("<") || fqn.contains(">")) {
+// return false;
+// }
+ String name = fqn.substring(lastDotIndex + 1);
String inPlaceFqn = imports.get(name);
if (inPlaceFqn == null) {
// Someone has started to read imports, impossible to add some more
@@ -132,37 +159,78 @@
* Accorging to the already added types, returns the type to write in file.
* If there is a conflict, returns the fully qualified name, otherwise
* returns the simple name
+ *
* @param fqn the fully qualified name to add
* @return the fqn or simple name according to in-place imports
*/
public String getType(String fqn) {
boolean importResult = addImport(fqn);
if (!importResult) {
+
// There is a conflict, do not use simple name
return fqn;
+ }
+ if (containsGenerics(fqn)) {
+
+ String[] parts = splitGeneric(fqn);
+ for (int i = 0; i < parts.length; i++) {
+ String part = parts[i];
+ parts[i] = getType(part);
+ }
+ return joinGeneric(parts);
+ }
+ // No conflict, use simple name
+ int packageEndIndex = getLastDotIndex(fqn);
+ if (packageEndIndex == -1) {
+ return fqn;
} else {
- // No conflict, use simple name
- int packageEndIndex = fqn.lastIndexOf(".");
- if (packageEndIndex == -1) {
- return fqn;
- } else {
- return fqn.substring(packageEndIndex + 1);
+ return fqn.substring(packageEndIndex + 1);
+ }
+ }
+
+ public String getReturnType(String returnType) {
+ if (StringUtils.isBlank(returnType)) {
+ return null;
+ }
+ if (containsGenerics(returnType)) {
+
+ // the return type is in two parts : <...> ...
+ String[] parts =
+ GeneratorUtil.splitGenericDefinition(returnType);
+ if (parts.length == 1) {
+
+ // no generic definition
+ return getType(returnType);
}
+ String genericDef = parts[0];
+ String strictReturnType = parts[1];
+ if (StringUtils.isNotBlank(genericDef)) {
+ genericDef += " ";
+ }
+ return genericDef + getType(strictReturnType);
+ } else {
+ return getType(returnType);
}
}
/**
* List the imports. This method will remove the useless imports according
* to the given packageName (no need to import a class in the same package)
+ *
* @param packageName the current package name (to avoid useless imports)
* @return the imports alphabeticaly sorted
*/
public List<String> getImports(String packageName) {
state = State.READING;
List<String> result = new ArrayList<String>();
+ int packageLength = packageName.length();
+ String packagePrefix = packageName + ".";
for (String fqn : imports.values()) {
- if (!(fqn.lastIndexOf(".") == packageName.length() &&
- fqn.startsWith(packageName + "."))) {
+ int lastDotIndex = getLastDotIndex(fqn);
+
+ // only keep sub package of given package
+ if (!(lastDotIndex == packageLength &&
+ fqn.startsWith(packagePrefix))) {
result.add(fqn);
}
}
@@ -183,4 +251,148 @@
FILLING, READING
}
+
+ /**
+ * Split the given fqn which contains a generic declaration into his parts.
+ * <p/>
+ * Example :
+ * <pre>
+ * java.util.List<Integer> : [java.util.List, Integer]
+ * java.util.List<java.util.List<Integer>> : [java.util.List, java.util.List<Integer>]
+ * java.util.Map<Integer, Integer> : [java.util.Map, Integer, Integer]
+ * java.util.Map<Integer, java.util.List<Integer>> : [java.util.Map, Integer, java.util.List<Integer>]
+ * <p/>
+ * </pre>
+ * <strong>Note:</strong> We only deal with one level of generics here in
+ * order to be able easly to rebuild after all the fqn with simple names...
+ *
+ * @param fqn the fqn to split
+ * @return the array of all parts of the fqn.
+ * @since 2.3.2
+ */
+ public String[] splitGeneric(String fqn) {
+ if (fqn == null) {
+ return null;
+ }
+
+ int firstPartIndex = fqn.indexOf('<');
+ if (firstPartIndex == -1) {
+
+ // no generics, just return the fqn
+ return new String[]{fqn};
+ }
+
+ List<String> parts = new ArrayList<String>();
+ parts.add(fqn.substring(0, firstPartIndex));
+ String rest = fqn.substring(firstPartIndex + 1,
+ fqn.lastIndexOf('>'));
+
+ if (containsGenerics(rest) && rest.contains(",")) {
+
+ // there is others generics in generics, worse case...
+ int begin = 0;
+ int count = 0;
+ int max = rest.length();
+ for (int i = 0; i < max; i++) {
+ char c = rest.charAt(i);
+ if (c == '<') {
+
+ count++;
+ } else if (c == '>') {
+
+ count--;
+ } else if (c == ',') {
+
+ // arrives on a possible split
+ if (count == 0) {
+
+ // can safely add this part
+ String part = rest.substring(begin, i);
+ parts.add(part.trim());
+ begin = i + 1;
+ }
+ }
+ }
+
+ // there is a last part to add ?
+ if (begin < max) {
+ String part = rest.substring(begin, max);
+ parts.add(part.trim());
+ }
+
+ } else {
+
+ // simple case : each part of the generics has no other generics
+ String[] split = rest.split(",");
+ for (String part : split) {
+ parts.add(part.trim());
+ }
+ }
+
+ return parts.toArray(new String[parts.size()]);
+ }
+
+ /**
+ * Join generics parts of a fqn into aparts.
+ * <p/>
+ * Example :
+ * <pre>
+ * [java.util.List, Integer] : java.util.List<Integer>
+ * [java.util.List, java.util.List<Integer>] : java.util.List<java.util.List<Integer>>
+ * [java.util.Map, Integer, Integer] : java.util.Map<Integer, Integer>
+ * [java.util.Map, Integer, java.util.List<Integer>] : java.util.Map<Integer, java.util.List<Integer>>
+ * </pre>
+ *
+ * @param genericParts the parts of fqn
+ * @return the fqn from his parts
+ * @since 2.3.2
+ */
+ public String joinGeneric(String... genericParts) {
+
+ if (genericParts == null || genericParts.length == 0) {
+
+ // this case should never happen ?
+ return null;
+ }
+
+ if (genericParts.length == 1) {
+
+ // in fact, no generics
+ return genericParts[0];
+ }
+
+ StringBuilder sb = new StringBuilder(genericParts[0]);
+
+ sb.append("<").append(genericParts[1]);
+
+ for (int i = 2, max = genericParts.length; i < max; i++) {
+ String genericPart = genericParts[i];
+ sb.append(", ").append(genericPart);
+ }
+ sb.append('>');
+ return sb.toString();
+ }
+
+ /**
+ * Tells if the given fqn contains a generic declaration (says contains a
+ * {@code <} caracter).
+ *
+ * @param fqn the fqn to test
+ * @return {@code true} if given fqn contains a generic declaration
+ * @since 2.3.2
+ */
+ public boolean containsGenerics(String fqn) {
+ return fqn.contains("<");
+ }
+
+ /**
+ * Obtains the last dot index in the given fqn.
+ *
+ * @param fqn the fqn to test
+ * @return the last index of a dot in given fqn
+ * @since 2.3.2
+ */
+ public int getLastDotIndex(String fqn) {
+ return fqn.lastIndexOf(".");
+ }
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManagerExtension.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManagerExtension.java 2011-01-27 08:53:21 UTC (rev 1040)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/extension/ImportsManagerExtension.java 2011-01-29 07:20:31 UTC (rev 1041)
@@ -34,39 +34,56 @@
import java.util.Map;
/**
- * ImportsManagerExtension
- *
+ * Extension for ObjectModel to manage imports for all classifiers in the model.
+ * <p/>
* Created: 2 nov. 2009
*
- * @author fdesbois
- * @version $Revision$
- *
- * Extension for ObjectModel to manage imports for all classifiers in the model.
+ * @author fdesbois <desbois(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @version $Id$
*/
public class ImportsManagerExtension {
- private static final Log log = LogFactory.getLog(ImportsManagerExtension.class);
-
/**
- * Extension static used to identify ImportsManagerExtension in ObjectModel
+ * Logger.
*/
+ private static final Log log =
+ LogFactory.getLog(ImportsManagerExtension.class);
+
+ /** Extension static used to identify ImportsManagerExtension in ObjectModel */
public static final String OBJECTMODEL_EXTENSION = "imports";
/**
- * Map of ImportsManager with key equals to the classifier qualified name associated to
- * the ImportsManager
+ * Map of ImportsManager with key equals to the classifier qualified name
+ * associated to the ImportsManager.
*/
protected Map<String, ImportsManager> managers;
/**
- * Get the ImportsManager associated to the classifier. If not exist, it will be created.
- *
+ * Get the ImportsManager associated to the classifier.
+ * <p/>
+ * <strong>Note:</strong> if not exist, it will be created.
+ *
* @param classifier reference for the ImportsManager
* @return the importsManager associated to the classifier (never null)
*/
public ImportsManager getManager(ObjectModelClassifier classifier) {
+ String fqn = classifier.getQualifiedName();
+ ImportsManager manager = getManager(fqn);
+ return manager;
+ }
+
+ /**
+ * Get the ImportsManager associated to the given {@code fqn}.
+ * <p/>
+ * <strong>Note:</strong> if not exist, it will be created.
+ *
+ * @param fqn reference for the ImportsManager
+ * @return the importsManager associated to the classifier (never null)
+ * @since 2.3.2
+ */
+ public ImportsManager getManager(String fqn) {
Map<String, ImportsManager> managers = getManagers();
- String fqn = classifier.getQualifiedName();
ImportsManager manager = managers.get(fqn);
if (manager == null) {
manager = new ImportsManager();
@@ -85,10 +102,27 @@
* @return a List of String which contains all imports for the classifier
*/
public List<String> getImports(ObjectModelClassifier classifier) {
- ImportsManager manager = getManager(classifier);
- return manager.getImports(classifier.getPackageName());
+ List<String> imports = getImports(classifier.getQualifiedName(),
+ classifier.getPackageName()
+ );
+ return imports;
}
+ /**
+ * Get imports for a classifier.
+ * <p/>
+ * The ImportsManager must be defined in the model.
+ *
+ * @param fqn reference for the imports
+ * @param packageName package name of the fqn
+ * @return a List of String which contains all imports for the classifier
+ * @since 2.3.2
+ */
+ public List<String> getImports(String fqn, String packageName) {
+ ImportsManager manager = getManager(fqn);
+ return manager.getImports(packageName);
+ }
+
protected Map<String, ImportsManager> getManagers() {
if (managers == null) {
managers = new HashMap<String, ImportsManager>();
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2011-01-27 08:53:21 UTC (rev 1040)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/GeneratorUtilTest.java 2011-01-29 07:20:31 UTC (rev 1041)
@@ -42,7 +42,9 @@
@Test
public void testGetOperationParametersListName() {
- log.debug("getOperationParametersListName");
+ if (log.isDebugEnabled()) {
+ log.debug("getOperationParametersListName");
+ }
ObjectModelOperationImpl op = new ObjectModelOperationImpl();
@@ -69,7 +71,9 @@
@Test
public void testGetOperationParametersListDeclaration() {
- log.debug("getOperationParametersListDeclaration");
+ if (log.isDebugEnabled()) {
+ log.debug("getOperationParametersListDeclaration");
+ }
ObjectModelOperationImpl op = new ObjectModelOperationImpl();
@@ -100,97 +104,129 @@
/** Test of getSimpleName method, of class GeneratorUtil. */
@Test
public void testGetSimpleName() {
- log.debug("getSimpleName");
+ if (log.isDebugEnabled()) {
+ log.debug("getSimpleName");
+ }
String str = "List";
String expResult = "List";
String result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Regex";
expResult = "Regex";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T> java.util.List<T>";
expResult = "<T> List<T>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
expResult = "List<? extends Bonzoms>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<org.chorem.jtimer.Jtimer>";
expResult = "List<Jtimer>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Set<java.util.Collection<java.util.Collection<java.util.Collection" +
"<java.lang.String>>>>";
expResult = "Set<Collection<Collection<Collection<String>>>>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
expResult = "Map<Jtimer, Collection<String>>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "new java.util.HashMap<org.chorem.jtimer.Jtimer, T extends java.lang.String>()";
expResult = "new HashMap<Jtimer, T extends String>()";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<O>";
expResult = "Class<O>";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "2.0";
expResult = "2.0";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "\"eric.chatellier\"";
expResult = "\"eric.chatellier\"";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T extends org.nuiton.topia.TopiaEntity, D extends org.nuiton.topia.TopiaDAO<? super T>> D";
expResult = "<T extends TopiaEntity, D extends TopiaDAO<? super T>> D";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Object...";
expResult = "Object...";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<A>...";
expResult = "Class<A>...";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.lang.Class<A>...";
expResult = "Class<A>...";
result = GeneratorUtil.getSimpleName(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
}
@@ -200,97 +236,129 @@
*/
@Test
public void testGetSimpleNameAndRemoveGenericsDefinition() {
- log.debug("getSimpleName");
+ if (log.isDebugEnabled()) {
+ log.debug("getSimpleName");
+ }
String str = "List";
String expResult = "List";
String result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Regex";
expResult = "Regex";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T> java.util.List<T>";
expResult = "List<T>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
expResult = "List<? extends Bonzoms>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<org.chorem.jtimer.Jtimer>";
expResult = "List<Jtimer>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Set<java.util.Collection<java.util.Collection<java.util.Collection" +
"<java.lang.String>>>>";
expResult = "Set<Collection<Collection<Collection<String>>>>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
expResult = "Map<Jtimer, Collection<String>>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "new java.util.HashMap<org.chorem.jtimer.Jtimer, T extends java.lang.String>()";
expResult = "new HashMap<Jtimer, T extends String>()";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<O>";
expResult = "Class<O>";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "2.0";
expResult = "2.0";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "\"eric.chatellier\"";
expResult = "\"eric.chatellier\"";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T extends org.nuiton.topia.TopiaEntity, D extends org.nuiton.topia.TopiaDAO<? super T>> D";
expResult = "D";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Object...";
expResult = "Object...";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<A>...";
expResult = "Class<A>...";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.lang.Class<A>...";
expResult = "Class<A>...";
result = GeneratorUtil.getSimpleName(str, true);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
}
@@ -298,86 +366,113 @@
/** Test of removeGenericDefinition method, of class GeneratorUtil. */
@Test
public void testRemoveGenericDefinition() {
- log.debug("removeGenericDefinition");
+ if (log.isDebugEnabled()) {
+ log.debug("removeGenericDefinition");
+ }
String str = "List";
String expResult = "List";
String result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.Regex";
expResult = "java.util.Regex";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T> java.util.List<T>";
expResult = "java.util.List<T>";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
-
str = " <T> java.util.List<T> ";
expResult = "java.util.List<T>";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
expResult = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.util.List<org.chorem.jtimer.Jtimer>";
expResult = "java.util.List<org.chorem.jtimer.Jtimer>";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<O>";
expResult = "Class<O>";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "2.0";
expResult = "2.0";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "\"eric.chatellier\"";
expResult = "\"eric.chatellier\"";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "<T extends org.nuiton.topia.TopiaEntity, D extends org.nuiton.topia.TopiaDAO<? super T>> D";
expResult = "D";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Object...";
expResult = "Object...";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "Class<A>...";
expResult = "Class<A>...";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
str = "java.lang.Class<A>...";
expResult = "java.lang.Class<A>...";
result = GeneratorUtil.removeGenericDefinition(str);
- log.info(str + " -> " + result);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + result);
+ }
Assert.assertEquals(expResult, result);
}
@@ -385,63 +480,85 @@
public void testGetTypesList() {
String str = "List";
Set<String> results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(1, results.size());
str = "java.util.Regex";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(1, results.size());
str = "java.util.List<? extends org.chorem.bonzoms.Bonzoms>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(2, results.size());
str = "java.util.List<org.chorem.jtimer.Jtimer>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(2, results.size());
str = "java.util.Set<java.util.Collection<java.util.Collection<java.util.Collection" +
"<java.lang.String>>>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(3, results.size());
str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<java.lang.String>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(4, results.size());
str = "new java.util.HashMap<org.chorem.jtimer.Jtimer, T extends java.lang.String>()";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(3, results.size());
str = "java.util.Map<org.chorem.jtimer.Jtimer, java.util.Collection<String>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(4, results.size());
str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(4, results.size());
str = "java.util.List<java.util.Map<java.util.Date, java.lang.Integer>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(4, results.size());
str = "java.util.TreeMap<java.util.ArrayList<java.util.Date>, java.util.SortedSet<java.lang.Number, java.lang.Double>>";
results = GeneratorUtil.getTypesList(str);
- log.info(str + " -> " + results);
+ if (log.isDebugEnabled()) {
+ log.debug(str + " -> " + results);
+ }
Assert.assertEquals(6, results.size());
// str = "<T extends org.nuiton.topia.TopiaEntity> T";
// results = GeneratorUtil.getTypesList(str);
-// log.info(str + " -> " + results);
+// log.debug(str + " -> " + results);
// assertEquals(results.size(), 1);
}
Modified: trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java
===================================================================
--- trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-27 08:53:21 UTC (rev 1040)
+++ trunk/eugene/src/test/java/org/nuiton/eugene/java/extension/ImportsManagerTest.java 2011-01-29 07:20:31 UTC (rev 1041)
@@ -25,9 +25,11 @@
package org.nuiton.eugene.java.extension;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.nuiton.util.StringUtil;
import java.io.Serializable;
import java.util.List;
@@ -41,8 +43,136 @@
mgr = new ImportsManager();
}
+ @After
+ public void tearDown() throws Exception {
+ mgr.clearImports();
+ mgr = null;
+ }
+
@Test
+ public void splitGeneric() throws Exception {
+
+ String[] actual;
+ String[] expected;
+
+ expected = null;
+ actual = mgr.splitGeneric(null);
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List"};
+ actual = mgr.splitGeneric("java.util.List");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "Integer"};
+ actual = mgr.splitGeneric("java.util.List<Integer>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.List", "java.util.List<Integer>"};
+ actual = mgr.splitGeneric("java.util.List<java.util.List<Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "Integer"};
+ actual = mgr.splitGeneric("java.util.Map<Integer, Integer>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.List<Integer>"};
+ actual = mgr.splitGeneric("java.util.Map<Integer, java.util.List<Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer>"};
+ actual = mgr.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "Integer", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = mgr.splitGeneric("java.util.Map<Integer, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
+ Assert.assertArrayEquals(expected, actual);
+
+ expected = new String[]{"java.util.Map", "X<Y<Z>>", "java.util.Map<Integer, Integer, Toto<A, B, C>>", "X", "Y<X>"};
+ actual = mgr.splitGeneric("java.util.Map< X<Y<Z>>, java.util.Map<Integer, Integer, Toto<A, B, C>>, X, Y<X>>");
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+
+ @Test
+ public void joinGeneric() throws Exception {
+ String actual;
+ String expected;
+
+ expected = null;
+ actual = mgr.joinGeneric((String) null);
+ Assert.assertEquals(expected, actual);
+
+ expected = null;
+ actual = mgr.joinGeneric(StringUtil.EMPTY_STRING_ARRAY);
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.List";
+ actual = mgr.joinGeneric("java.util.List");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.List<Integer>";
+ actual = mgr.joinGeneric("java.util.List", "Integer");
+ Assert.assertEquals(expected, actual);
+
+
+ expected = "java.util.List<java.util.List<Integer>>";
+ actual = mgr.joinGeneric("java.util.List", "java.util.List<Integer>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.Map<Integer, Integer>";
+ actual = mgr.joinGeneric("java.util.Map", "Integer", "Integer");
+ Assert.assertEquals(expected, actual);
+
+ expected = "java.util.Map<Integer, java.util.List<Integer>>";
+ actual = mgr.joinGeneric("java.util.Map", "Integer", "java.util.List<Integer>");
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getReturnType() throws Exception {
+ String actual;
+ String expected;
+
+ expected = null;
+ actual = mgr.getReturnType(null);
+ Assert.assertEquals(expected, actual);
+
+ expected = "List";
+ actual = mgr.getReturnType("java.util.List");
+ Assert.assertEquals(expected, actual);
+
+ expected = "List<Integer>";
+ actual = mgr.getReturnType("java.util.List<Integer>");
+ Assert.assertEquals(expected, actual);
+
+
+ expected = "List<List<Integer>>";
+ actual = mgr.getReturnType("java.util.List<java.util.List<Integer>>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "Map<Integer, Integer>";
+ actual = mgr.getReturnType("java.util.Map< Integer,Integer>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "Map<Integer, List<Integer>>";
+ actual = mgr.getReturnType("java.util.Map<Integer,java.util.List<Integer>>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "<O> Map<O, List<Integer>>";
+ actual = mgr.getReturnType("<O> java.util.Map<O, java.util.List<Integer>>");
+ Assert.assertEquals(expected, actual);
+
+ expected = "<O extends java.util.List> Map<O, List<Toto>>";
+ actual = mgr.getReturnType("<O extends java.util.List> java.util.Map<O, java.util.List<a.b.Toto>>");
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
public void testAddImport() throws Exception {
+
+ Assert.assertFalse(mgr.addImport((String) null)); // Not accept null value
+
Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Toto"));
Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Toto")); //Repeat to test acceptance
Assert.assertTrue(mgr.addImport("org.nuiton.eugene.Tutu"));
@@ -63,13 +193,15 @@
Assert.assertEquals("Toto", mgr.getType("org.nuiton.eugene.Toto"));
Assert.assertEquals("Toto", mgr.getType("org.nuiton.eugene.Toto")); //Repeat to test acceptance
Assert.assertEquals("Tutu", mgr.getType("org.nuiton.eugene.Tutu"));
+ Assert.assertEquals("Tutu<Toto>", mgr.getType("org.nuiton.eugene.Tutu<org.nuiton.eugene.Toto>"));
+
Assert.assertEquals("org.chorem.eugene.Tutu", mgr.getType("org.chorem.eugene.Tutu")); //Conflict, package differs
Assert.assertEquals("void", mgr.getType("void"));
Assert.assertEquals("boolean", mgr.getType("boolean"));
Assert.assertEquals("Byte", mgr.getType("Byte"));
Assert.assertEquals("Toto", mgr.getType("java.lang.Toto"));
- Assert.assertEquals("java.lang.sub.Toto", mgr.getType("java.lang.sub.Toto"));
+ Assert.assertEquals("java.lang.sub.Toto", mgr.getType("java.lang.sub.Toto")); // Conflict, package differs
}
@Test
1
0
Author: tchemit
Date: 2011-01-27 09:53:21 +0100 (Thu, 27 Jan 2011)
New Revision: 1040
Url: http://nuiton.org/repositories/revision/eugene/1040
Log:
Update mavenpom4redmineAndCentral to 2.4.3.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-26 13:48:15 UTC (rev 1039)
+++ trunk/pom.xml 2011-01-27 08:53:21 UTC (rev 1040)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.4.2</version>
+ <version>2.4.3</version>
</parent>
<artifactId>eugene</artifactId>
@@ -462,12 +462,12 @@
<tasks>
<copy todir="target/site/xsd/v1" verbose="${maven.verbose}" failonerror="false" overwrite="true">
<fileset dir="${basedir}/eugene/src/main/resources/xsd">
- <include name="**/*.xsd" />
+ <include name="**/*.xsd"/>
</fileset>
</copy>
<copy todir="target/site/dtd/v1" verbose="${maven.verbose}" failonerror="false" overwrite="true">
<fileset dir="${basedir}/eugene/src/main/resources/dtd">
- <include name="**/*.dtd" />
+ <include name="**/*.dtd"/>
</fileset>
</copy>
</tasks>
1
0
r1039 - in trunk: . ant-eugene-task eugene maven-eugene-plugin
by hudson@users.nuiton.org Jan. 26, 2011
by hudson@users.nuiton.org Jan. 26, 2011
Jan. 26, 2011
Author: hudson
Date: 2011-01-26 14:48:15 +0100 (Wed, 26 Jan 2011)
New Revision: 1039
Url: http://nuiton.org/repositories/revision/eugene/1039
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/ant-eugene-task/pom.xml
trunk/eugene/pom.xml
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Modified: trunk/ant-eugene-task/pom.xml
===================================================================
--- trunk/ant-eugene-task/pom.xml 2011-01-26 13:48:14 UTC (rev 1038)
+++ trunk/ant-eugene-task/pom.xml 2011-01-26 13:48:15 UTC (rev 1039)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2011-01-26 13:48:14 UTC (rev 1038)
+++ trunk/eugene/pom.xml 2011-01-26 13:48:15 UTC (rev 1039)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:48:14 UTC (rev 1038)
+++ trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:48:15 UTC (rev 1039)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-26 13:48:14 UTC (rev 1038)
+++ trunk/pom.xml 2011-01-26 13:48:15 UTC (rev 1039)
@@ -37,7 +37,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.3.1</version>
+ <version>2.3.2-SNAPSHOT</version>
<modules>
<module>eugene</module>
@@ -431,11 +431,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.3.1</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.3.1
+ scm:svn:http://svn.nuiton.org/svn/eugene/trunk
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/eugene/tags/eugene-2.3.1</url>
+ <url>http://www.nuiton.org/repositories/browse/eugene/trunk</url>
</scm>
<profiles>
1
0
Author: hudson
Date: 2011-01-26 14:48:14 +0100 (Wed, 26 Jan 2011)
New Revision: 1038
Url: http://nuiton.org/repositories/revision/eugene/1038
Log:
[maven-release-plugin] copy for tag eugene-2.3.1
Added:
tags/eugene-2.3.1/
Property changes on: tags/eugene-2.3.1
___________________________________________________________________
Added: svn:ignore
+ target
.settings
bin
.classpath
.project
*.iml
*.ipr
*.iws
Added: svn:mergeinfo
+ /branches/1.0.1-Javabuilder:641-651
/branches/1.1.0-Javabuilder:652-681
/branches/eugene-2.0:682-754
1
0
r1037 - in trunk: . ant-eugene-task eugene maven-eugene-plugin
by hudson@users.nuiton.org Jan. 26, 2011
by hudson@users.nuiton.org Jan. 26, 2011
Jan. 26, 2011
Author: hudson
Date: 2011-01-26 14:48:13 +0100 (Wed, 26 Jan 2011)
New Revision: 1037
Url: http://nuiton.org/repositories/revision/eugene/1037
Log:
[maven-release-plugin] prepare release eugene-2.3.1
Modified:
trunk/ant-eugene-task/pom.xml
trunk/eugene/pom.xml
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Modified: trunk/ant-eugene-task/pom.xml
===================================================================
--- trunk/ant-eugene-task/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
+++ trunk/ant-eugene-task/pom.xml 2011-01-26 13:48:13 UTC (rev 1037)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
+++ trunk/eugene/pom.xml 2011-01-26 13:48:13 UTC (rev 1037)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
+++ trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:48:13 UTC (rev 1037)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>eugene</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
</parent>
<groupId>org.nuiton.eugene</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
+++ trunk/pom.xml 2011-01-26 13:48:13 UTC (rev 1037)
@@ -37,7 +37,7 @@
</parent>
<artifactId>eugene</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.3.1</version>
<modules>
<module>eugene</module>
@@ -431,11 +431,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/eugene/trunk</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.3.1</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/eugene/trunk
+ scm:svn:http://svn.nuiton.org/svn/eugene/tags/eugene-2.3.1
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/eugene/trunk</url>
+ <url>http://www.nuiton.org/repositories/browse/eugene/tags/eugene-2.3.1</url>
</scm>
<profiles>
1
0
Jan. 26, 2011
Author: tchemit
Date: 2011-01-26 14:41:07 +0100 (Wed, 26 Jan 2011)
New Revision: 1036
Url: http://nuiton.org/repositories/revision/eugene/1036
Log:
clean poms
Modified:
trunk/eugene/pom.xml
trunk/maven-eugene-plugin/pom.xml
trunk/pom.xml
Modified: trunk/eugene/pom.xml
===================================================================
--- trunk/eugene/pom.xml 2011-01-26 13:23:17 UTC (rev 1035)
+++ trunk/eugene/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
@@ -83,22 +83,6 @@
<artifactId>commons-io</artifactId>
</dependency>
- <!--dependency>
- <groupId>org.apache.ant</groupId>
- <artifactId>ant</artifactId>
- </dependency-->
-
- <!--dependency>
- <groupId>dom4j</groupId>
- <artifactId>dom4j</artifactId>
- <exclusions>
- <exclusion>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- </exclusion>
- </exclusions>
- </dependency-->
-
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
@@ -109,28 +93,12 @@
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
- <!--exclusions>
- <exclusion>
- <groupId>com.ibm.icu</groupId>
- <artifactId>icu4j</artifactId>
- </exclusion>
- <exclusion>
- <groupId>xerces</groupId>
- <artifactId>xmlParserAPIs</artifactId>
- </exclusion>
- </exclusions-->
</dependency>
<!-- Meta model uml d'eclipse -->
<dependency>
<groupId>org.eclipse.uml2.uml</groupId>
<artifactId>resources</artifactId>
- <!--exclusions>
- <exclusion>
- <groupId>org.eclipse.uml2</groupId>
- <artifactId>uml</artifactId>
- </exclusion>
- </exclusions-->
</dependency>
<dependency>
@@ -194,8 +162,8 @@
</executions>
<configuration>
<includes>**/*.java</includes>
- <!--<includes>org/nuiton/eugene/java/JavaGenerator.java</includes>-->
- <filters>org.nuiton.processor.filters.GeneratorTemplatesFilter
+ <filters>
+ org.nuiton.processor.filters.GeneratorTemplatesFilter
</filters>
</configuration>
</plugin>
Modified: trunk/maven-eugene-plugin/pom.xml
===================================================================
--- trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:23:17 UTC (rev 1035)
+++ trunk/maven-eugene-plugin/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
@@ -158,8 +158,6 @@
<value>true</value>
</property>
</activation>
-
-
<build>
<plugins>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-26 13:23:17 UTC (rev 1035)
+++ trunk/pom.xml 2011-01-26 13:41:07 UTC (rev 1036)
@@ -264,20 +264,6 @@
<version>1.5.15</version>
</dependency>
- <!--dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.2</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.16</version>
- <scope>test</scope>
- </dependency-->
-
</dependencies>
</dependencyManagement>
1
0
r1035 - trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by tchemit@users.nuiton.org Jan. 26, 2011
by tchemit@users.nuiton.org Jan. 26, 2011
Jan. 26, 2011
Author: tchemit
Date: 2011-01-26 14:23:17 +0100 (Wed, 26 Jan 2011)
New Revision: 1035
Url: http://nuiton.org/repositories/revision/eugene/1035
Log:
Evolution #1218: Add stereotypes and tagvalues in the available-data goal
Modified:
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-26 12:45:00 UTC (rev 1034)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-26 13:23:17 UTC (rev 1035)
@@ -38,6 +38,7 @@
import java.util.Arrays;
import java.util.EnumSet;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -115,6 +116,10 @@
*/
protected Map<String, ModelPropertiesUtil.ModelPropertiesProvider> modelPropertiesProviders;
+ protected Map<String, ModelPropertiesUtil.ModelPropertiesProvider> loadedProviders;
+
+ protected ModelPropertiesUtil.ModelPropertiesProvider currentPropertiesProvider;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
StringBuilder buffer = new StringBuilder();
@@ -149,6 +154,19 @@
}
}
+ if (safeDataTypes.contains(AvailableData.stereotype) ||
+ safeDataTypes.contains(AvailableData.tagvalue)) {
+
+ loadedProviders = new LinkedHashMap<String, ModelPropertiesUtil.ModelPropertiesProvider>();
+ // init stores
+ for (Map.Entry<String, ModelPropertiesUtil.ModelPropertiesProvider> e : modelPropertiesProviders.entrySet()) {
+ ModelPropertiesUtil.ModelPropertiesProvider provider = ModelPropertiesUtil.newStore(
+ Arrays.asList(e.getValue()),
+ false
+ );
+ loadedProviders.put(e.getKey(), provider);
+ }
+ }
for (AvailableData data : safeDataTypes) {
buffer.append("\n");
appendData(data, buffer);
@@ -160,24 +178,68 @@
protected void appendData(AvailableData data, StringBuilder buffer) {
- Map<String, ?> map = data.getData(this);
+ String dataType = data.name();
- int size = map.size();
- String dataType = data.name();
- if (size == 0) {
- buffer.append("\nNo available ").append(dataType).append(".");
- } else if (size == 1) {
- buffer.append("\nFound one ").append(dataType).append(" : ");
+ if (data == AvailableData.tagvalue || data == AvailableData.stereotype) {
+
+ int nbData = 0;
+ for (ModelPropertiesUtil.ModelPropertiesProvider provider : loadedProviders.values()) {
+ currentPropertiesProvider = provider;
+ nbData += data.getData(this).size();
+ }
+ currentPropertiesProvider = null;
+
+ String format = "\nFound %s %ss in %s provider(s) : %s\n";
+
+ buffer.append(String.format(format,
+ nbData,
+ dataType,
+ loadedProviders.size(),
+ loadedProviders.keySet())
+ );
+
+ for (Map.Entry<String, ModelPropertiesUtil.ModelPropertiesProvider> e : loadedProviders.entrySet()) {
+ String providerName = e.getKey();
+ ModelPropertiesUtil.ModelPropertiesProvider provider = e.getValue();
+ currentPropertiesProvider = provider;
+ Map<String, ?> map = data.getData(this);
+
+ int size = map.size();
+ buffer.append("\nProvider [").append(providerName).append("] - ");
+ if (size == 0) {
+ buffer.append("No available ").append(dataType).append(".");
+ } else if (size == 1) {
+ buffer.append("Found one ").append(dataType).append(" : ");
+ } else {
+ buffer.append("Found ");
+ buffer.append(size);
+ buffer.append(" ");
+ buffer.append(dataType);
+ buffer.append("s : ");
+ }
+ for (Map.Entry<String, ?> e2 : map.entrySet()) {
+ data.toString(buffer, e2);
+ }
+ }
} else {
- buffer.append("\nFound ");
- buffer.append(size);
- buffer.append(" ");
- buffer.append(dataType);
- buffer.append("s : ");
+ Map<String, ?> map = data.getData(this);
+
+ int size = map.size();
+ if (size == 0) {
+ buffer.append("\nNo available ").append(dataType).append(".");
+ } else if (size == 1) {
+ buffer.append("\nFound one ").append(dataType).append(" : ");
+ } else {
+ buffer.append("\nFound ");
+ buffer.append(size);
+ buffer.append(" ");
+ buffer.append(dataType);
+ buffer.append("s : ");
+ }
+ for (Map.Entry<String, ?> e : map.entrySet()) {
+ data.toString(buffer, e);
+ }
}
- for (Map.Entry<String, ?> e : map.entrySet()) {
- data.toString(buffer, e);
- }
}
enum AvailableData {
@@ -225,7 +287,7 @@
tagvalue {
@Override
public Map<String, ?> getData(AvailableDataMojo mojo) {
- return mojo.getModelPropertiesProvider().getTagValueStore();
+ return mojo.getCurrentPropertiesProvider().getTagValueStore();
}
@Override
@@ -258,7 +320,7 @@
stereotype {
@Override
public Map<String, ?> getData(AvailableDataMojo mojo) {
- return mojo.getModelPropertiesProvider().getStereotypeStore();
+ return mojo.getCurrentPropertiesProvider().getStereotypeStore();
}
@Override
@@ -306,6 +368,10 @@
}
}
+ protected ModelPropertiesUtil.ModelPropertiesProvider getCurrentPropertiesProvider() {
+ return currentPropertiesProvider;
+ }
+
protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
ModelPropertiesUtil.ModelPropertiesProvider provider;
1
0
Jan. 26, 2011
Author: tchemit
Date: 2011-01-26 13:45:00 +0100 (Wed, 26 Jan 2011)
New Revision: 1034
Url: http://nuiton.org/repositories/revision/eugene/1034
Log:
Evolution #1248: Remove deprecated extensions in 2.3
Removed:
trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManager.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManagerExtension.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManager.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManagerExtension.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManager.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManagerExtension.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManager.java
trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManagerExtension.java
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManager.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManager.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,90 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-import org.nuiton.eugene.models.object.ObjectModelElement;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * To manage annotations for any {@link ObjectModelElement} of a classifier.
- * <p/>
- * Created: 17 déc. 2009
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @version $Revision$
- * @since 2.0.0
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.AnnotationsManager}
- */
-@Deprecated
-public class AnnotationsManager {
-
- private static final String[] EMPTY_STRING_ARRAY = new String[]{};
-
- protected Map<ObjectModelElement, List<String>> annotations;
-
- /**
- * Add the {@code annotation} for the given {@code element} of
- * the classifier.
- *
- * @param element the element where to register the annotation
- * @param annotation the annotation to register
- */
- public void addAnnotation(ObjectModelElement element, String annotation) {
- Map<ObjectModelElement, List<String>> map = getAnnotations();
- List<String> list = map.get(element);
- if (list == null) {
- list = new ArrayList<String>();
- map.put(element, list);
- }
- list.add(annotation);
- }
-
- /**
- * Obtain the array of annotations registred for a given element of
- * the classifier.
- *
- * @param element the element where to search for annotations
- * @return the annotations for the element (empty arry if none found
- */
- public String[] getAnnotations(ObjectModelElement element) {
- Map<ObjectModelElement, List<String>> map = getAnnotations();
- List<String> list = map.get(element);
- return list == null ? EMPTY_STRING_ARRAY :
- list.toArray(new String[list.size()]);
- }
-
- protected Map<ObjectModelElement, List<String>> getAnnotations() {
- if (annotations == null) {
- annotations = new HashMap<ObjectModelElement, List<String>>();
- }
- return annotations;
- }
-
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManagerExtension.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManagerExtension.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/AnnotationsManagerExtension.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,111 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelElement;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Created: 17 déc. 2009
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @version $Revision$
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.AnnotationsManagerExtension}
- */
-@Deprecated
-public class AnnotationsManagerExtension {
-
- private static final Log log = LogFactory.getLog(AnnotationsManagerExtension.class);
-
- /**
- * Extension static used to identify AnnotationsManagerExtension in
- * ObjectModel.
- */
- public static final String OBJECTMODEL_EXTENSION = "annotations";
-
- /**
- * Map of AnotationsManager with key equals to the classifier qualified
- * name associated to the AnotationsManager
- */
- protected Map<String, AnnotationsManager> managers;
-
- private static final String[] EMPTY_STRING_ARRAY = new String[]{};
-
- /**
- * Get the registred annotations for the given {@code element} in the
- * given {@code classifier}.
- *
- * <b>Note:</b> The method always returns a {@code none null} value, but
- * an empty array when no annotation when no annotation found for the
- * element.
- *
- * @param classifier the classifier where is the element
- * @param element the element on which searching annotations
- * @return the array of annotation registred or an empty array if none.
- */
- public String[] getAnnotations(ObjectModelClassifier classifier,
- ObjectModelElement element) {
- AnnotationsManager annotationsManager = getManager(classifier);
- String[] result = null;
- if (annotationsManager != null) {
- result = annotationsManager.getAnnotations(element);
- }
- return result == null ? EMPTY_STRING_ARRAY : result;
- }
-
- /**
- * Get the AnotationsManager associated to the classifier. If not exist,
- * it will be created.
- *
- * @param classifier reference for the AnotationsManager
- * @return the annotationsManager associated to the classifier (never null)
- */
- public AnnotationsManager getManager(ObjectModelClassifier classifier) {
- Map<String, AnnotationsManager> managers = getManagers();
- String fqn = classifier.getQualifiedName();
- AnnotationsManager manager = managers.get(fqn);
- if (manager == null) {
- manager = new AnnotationsManager();
- managers.put(fqn, manager);
- if (log.isDebugEnabled()) {
- log.debug("Add new annotationsManager for : " + fqn);
- }
- }
- return manager;
- }
-
- protected Map<String, AnnotationsManager> getManagers() {
- if (managers == null) {
- managers = new HashMap<String, AnnotationsManager>();
- }
- return managers;
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManager.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManager.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,83 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.eugene.java;
-
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * To manage some verbatim code to inject in operations.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0.2
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.CodesManager}
- */
-@Deprecated
-public class CodesManager {
-
- private static final String EMPTY_STRING = "";
-
- /** store of codes associated to operations */
- protected Map<ObjectModelOperation, StringBuilder> codes;
-
- /**
- * Add the {@code annotation} for the given {@code element} of
- * the classifier.
- *
- * @param operation the operation on which add the code
- * @param code the code to add
- */
- public void addCode(ObjectModelOperation operation, String code) {
- Map<ObjectModelOperation, StringBuilder> map = getCodes();
-
- StringBuilder buffer = map.get(operation);
- if (buffer == null) {
- buffer = new StringBuilder();
- map.put(operation, buffer);
- }
- buffer.append('\n').append(code);
- }
-
- /**
- * Obtain the codes registred for a given operation of the classifier.
- *
- * @param operation the operation where to search for code
- * @return the code for the operation (empty if none found)
- */
- public String getCode(ObjectModelOperation operation) {
- Map<ObjectModelOperation, StringBuilder> map = getCodes();
- StringBuilder buffer = map.get(operation);
- return buffer == null ? EMPTY_STRING : buffer.toString();
- }
-
- protected Map<ObjectModelOperation, StringBuilder> getCodes() {
- if (codes == null) {
- codes = new HashMap<ObjectModelOperation, StringBuilder>();
- }
- return codes;
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManagerExtension.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManagerExtension.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/CodesManagerExtension.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,115 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.eugene.java;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-import org.nuiton.eugene.models.object.ObjectModelOperation;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Object model extensions to manage verbatim code to attzach to operations.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see CodesManager
- * @since 2.0.2
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.CodesManagerExtension}
- */
-@Deprecated
-public class CodesManagerExtension {
-
- private static final Log log = LogFactory.getLog(CodesManagerExtension.class);
-
- /** Extension static used to identify CodesManagerExtension in ObjectModel */
- public static final String OBJECTMODEL_EXTENSION = "codes";
-
- /**
- * Map of CodesManager with key equals to the classifier qualified name
- * associated to the CodesManager
- */
- protected Map<String, CodesManager> managers;
-
- /**
- * Add the {@code code} for the given {@code operation} of the
- * given {@code classifier}.
- *
- * @param classifier the classifier container of the operation
- * @param operation the operation on which to add the code
- * @param code the code to add for the operation
- */
- public void addcode(ObjectModelClassifier classifier,
- ObjectModelOperation operation,
- String code) {
- CodesManager codesManager = getManager(classifier);
- codesManager.addCode(operation, code);
- }
-
- /**
- * Get body code for a operation of the given classifier.
- * <p/>
- * The CodesManager must be defined in the model.
- *
- * @param classifier reference for the codes
- * @param operation the operation to seek
- * @return the body code of the method
- */
- public String getCode(ObjectModelClassifier classifier,
- ObjectModelOperation operation) {
- CodesManager manager = getManager(classifier);
- return manager.getCode(operation);
- }
-
- /**
- * Get the CodesManager associated to the classifier.
- * <p/>
- * <b>Note:</b> If not exist, it will be created.
- *
- * @param classifier reference for the ImportsManager
- * @return the codesManager associated to the classifier (never null)
- */
- protected CodesManager getManager(ObjectModelClassifier classifier) {
- Map<String, CodesManager> managers = getManagers();
- String fqn = classifier.getQualifiedName();
- CodesManager manager = managers.get(fqn);
- if (manager == null) {
- manager = new CodesManager();
- managers.put(fqn, manager);
- if (log.isDebugEnabled()) {
- log.debug("Add new codesManager for : " + fqn);
- }
- }
- return manager;
- }
-
- protected Map<String, CodesManager> getManagers() {
- if (managers == null) {
- managers = new HashMap<String, CodesManager>();
- }
- return managers;
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManager.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManager.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,72 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-import org.nuiton.eugene.GeneratorUtil;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Manager of constant names.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since ?
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.ConstantsManager}
- */
-@Deprecated
-public class ConstantsManager {
- /**
- * cache of constant name (values) for property name (keys)
- */
- protected Map<String, String> nameToConstant;
-
- /**
- * Obtain a constant nmae from a property name and store it in cache
- * the first time it had to build it.
- *
- * @param propertyName the propertyName to convert
- * @return the equivalent constant name
- */
- public String getConstantName(String propertyName) {
- Map<String, String> map = getNameToConstant();
- if (map.containsKey(propertyName)) {
- return map.get(propertyName);
- }
- // convert propertyName to constant name
- String constantName =
- GeneratorUtil.convertVariableNameToConstantName(propertyName);
- map.put(propertyName,constantName);
- return constantName;
- }
-
- protected Map<String, String> getNameToConstant() {
- if (nameToConstant == null) {
- nameToConstant = new TreeMap<String, String>();
- }
- return nameToConstant;
- }
-}
\ No newline at end of file
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManagerExtension.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManagerExtension.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ConstantsManagerExtension.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,57 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since ?
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.ConstantsManagerExtension}
- */
-@Deprecated
-public class ConstantsManagerExtension {
-
- /**
- * Extension static used to identify {@code ConstantsManagerExtension} in
- * ObjectModel
- */
- public static final String OBJECTMODEL_EXTENSION = "constants";
-
- /**
- * the unique manager to use
- */
- protected ConstantsManager manager = new ConstantsManager();
-
- /**
- * Obtain a constant nmae from a property name and store it in cache
- * the first time it had to build it.
- *
- * @param propertyName the propertyName to convert
- * @return the equivalent constant name
- */
- public String getConstantName(String propertyName) {
- return manager.getConstantName(propertyName);
- }
-}
\ No newline at end of file
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManager.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManager.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManager.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,188 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Class used in generators that allows to manage easily imports. A first-pass
- * allow to register imports, and in a second-pass, returns the type to use in
- * generated code.
- *
- * @author thimel, chemit
- * @version $Revision$
-
- * @since 2.0.0
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.ImportsManager}
- */
-@Deprecated
-public class ImportsManager {
-
- private static Set<String> primitiveTypes;
-
- static {
- primitiveTypes = new HashSet<String>();
-
- primitiveTypes.add("byte");
- primitiveTypes.add("Byte");
- primitiveTypes.add("short");
- primitiveTypes.add("Short");
- primitiveTypes.add("int");
- primitiveTypes.add("Integer");
- primitiveTypes.add("long");
- primitiveTypes.add("Long");
- primitiveTypes.add("float");
- primitiveTypes.add("Float");
- primitiveTypes.add("double");
- primitiveTypes.add("Double");
-
- primitiveTypes.add("char");
- primitiveTypes.add("Char");
- primitiveTypes.add("String");
-
- primitiveTypes.add("boolean");
- primitiveTypes.add("Boolean");
-
- primitiveTypes.add("void");
-
- }
- private Map<String, String> imports = new HashMap<String, String>();
- private State state = State.FILLING;
-
- /**
- * From the given class, add it to the imports list.
- * @param clazz the class to import
- * @return true if import add was successful
- * @see ImportsManager#addImport(String)
- */
- public boolean addImport(Class<?> clazz) {
- return addImport(clazz.getName());
- }
-
- /**
- * From the given fqn (fully qualified name), add it to the imports list.
- * If there is a conflict adding this import, will return false.
- * If reading of the imports has started, this method will return false,
- * unless type does not need to be imported.
- * @param fqn the fully qualified name to import
- * @return true if import add was successful
- */
- public boolean addImport(String fqn) {
- // if no package don't include it
- if (fqn.indexOf(".") == -1) {
- return true;
- }
-
- // Exclude java.lang classes
- if (fqn == null || fqn.trim().isEmpty() ||
- (fqn.startsWith("java.lang.") && fqn.lastIndexOf(".") == 9)) {
- return true;
- }
- // Exclude primitive types
- if (primitiveTypes.contains(fqn)) {
- return true;
- }
- // Reject generics
- if (fqn.indexOf("<") != -1 || fqn.indexOf(">") != -1) {
- return false;
- }
- String name = fqn.substring(fqn.lastIndexOf(".") + 1);
- String inPlaceFqn = imports.get(name);
- if (inPlaceFqn == null) {
- // Someone has started to read imports, impossible to add some more
- if (state == State.READING) {
- return false;
- } else {
- imports.put(name, fqn);
- return true;
- }
- }
- // if fqn is not the same, return false. Otherwise, no need to override.
- return inPlaceFqn.equals(fqn);
- }
-
- /**
- * Accorging to the already added types, returns the type to write in file.
- * If there is a conflict, returns the fully qualified name, otherwise
- * returns the simple name
- * @param fqn the fully qualified name to add
- * @return the fqn or simple name according to in-place imports
- */
- public String getType(String fqn) {
- boolean importResult = addImport(fqn);
- if (!importResult) {
- // There is a conflict, do not use simple name
- return fqn;
- } else {
- // No conflict, use simple name
- int packageEndIndex = fqn.lastIndexOf(".");
- if (packageEndIndex == -1) {
- return fqn;
- } else {
- return fqn.substring(packageEndIndex + 1);
- }
- }
- }
-
- /**
- * List the imports. This method will remove the useless imports according
- * to the given packageName (no need to import a class in the same package)
- * @param packageName the current package name (to avoid useless imports)
- * @return the imports alphabeticaly sorted
- */
- public List<String> getImports(String packageName) {
- state = State.READING;
- List<String> result = new ArrayList<String>();
- for (String fqn : imports.values()) {
- if (!(fqn.lastIndexOf(".") == packageName.length() &&
- fqn.startsWith(packageName + "."))) {
- result.add(fqn);
- }
- }
- Collections.sort(result);
- return result;
- }
-
- /**
- * Method to reset imports list. If imports has been listed, it becomes back
- * possible to add imports.
- */
- public void clearImports() {
- imports.clear();
- state = State.FILLING;
- }
-
- private enum State {
-
- FILLING, READING
- }
-}
Deleted: trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManagerExtension.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManagerExtension.java 2011-01-26 12:44:37 UTC (rev 1033)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/java/ImportsManagerExtension.java 2011-01-26 12:45:00 UTC (rev 1034)
@@ -1,101 +0,0 @@
-/*
- * #%L
- * EUGene :: EUGene
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2004 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.eugene.java;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.eugene.models.object.ObjectModelClassifier;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ImportsManagerExtension
- *
- * Created: 2 nov. 2009
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Extension for ObjectModel to manage imports for all classifiers in the model.
- *
- * @deprecated since 2.3, use now the class {@link org.nuiton.eugene.java.extension.ImportsManagerExtension}
- * */
-@Deprecated
-public class ImportsManagerExtension {
-
- private static final Log log = LogFactory.getLog(ImportsManagerExtension.class);
-
- /**
- * Extension static used to identify ImportsManagerExtension in ObjectModel
- */
- public static final String OBJECTMODEL_EXTENSION = "imports";
-
- /**
- * Map of ImportsManager with key equals to the classifier qualified name associated to
- * the ImportsManager
- */
- protected Map<String, ImportsManager> managers;
-
- /**
- * Get the ImportsManager associated to the classifier. If not exist, it will be created.
- *
- * @param classifier reference for the ImportsManager
- * @return the importsManager associated to the classifier (never null)
- */
- public ImportsManager getManager(ObjectModelClassifier classifier) {
- Map<String, ImportsManager> managers = getManagers();
- String fqn = classifier.getQualifiedName();
- ImportsManager manager = managers.get(fqn);
- if (manager == null) {
- manager = new ImportsManager();
- managers.put(fqn, manager);
- if (log.isDebugEnabled()) {
- log.debug("Add new importsManager for : " + fqn);
- }
- }
- return manager;
- }
-
- /**
- * Get imports for a classifier. The ImportsManager must be defined in the model.
- *
- * @param classifier reference for the imports
- * @return a List of String which contains all imports for the classifier
- */
- public List<String> getImports(ObjectModelClassifier classifier) {
- ImportsManager manager = getManager(classifier);
- return manager.getImports(classifier.getPackageName());
- }
-
- protected Map<String, ImportsManager> getManagers() {
- if (managers == null) {
- managers = new HashMap<String, ImportsManager>();
- }
- return managers;
- }
-}
1
0
Author: tchemit
Date: 2011-01-26 13:44:37 +0100 (Wed, 26 Jan 2011)
New Revision: 1033
Url: http://nuiton.org/repositories/revision/eugene/1033
Log:
Evolution #1245: Updates nuiton-utils to 2.0
Evolution #1246: Updates nuiton-i18n to 2.2
Evolution #1247: Updates mavenpom to 2.4.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-23 17:29:32 UTC (rev 1032)
+++ trunk/pom.xml 2011-01-26 12:44:37 UTC (rev 1033)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.4.2-SNAPSHOT</version>
+ <version>2.4.2</version>
</parent>
<artifactId>eugene</artifactId>
@@ -379,8 +379,8 @@
<projectId>eugene</projectId>
<processorPluginVersion>1.1</processorPluginVersion>
- <nuitonUtilsVersion>1.5.2</nuitonUtilsVersion>
- <nuitonI18nVersion>2.0.1</nuitonI18nVersion>
+ <nuitonUtilsVersion>2.0</nuitonUtilsVersion>
+ <nuitonI18nVersion>2.2</nuitonI18nVersion>
<!--Multilanguage maven-site -->
<locales>en,fr</locales>
1
0
Author: tchemit
Date: 2011-01-23 18:29:32 +0100 (Sun, 23 Jan 2011)
New Revision: 1032
Url: http://nuiton.org/repositories/revision/eugene/1032
Log:
Updates to mavenpom 2.4.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-21 17:22:03 UTC (rev 1031)
+++ trunk/pom.xml 2011-01-23 17:29:32 UTC (rev 1032)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>2.4.1</version>
+ <version>2.4.2-SNAPSHOT</version>
</parent>
<artifactId>eugene</artifactId>
1
0
r1031 - in trunk: eugene/src/main/java/org/nuiton/eugene maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by tchemit@users.nuiton.org Jan. 21, 2011
by tchemit@users.nuiton.org Jan. 21, 2011
Jan. 21, 2011
Author: tchemit
Date: 2011-01-21 18:22:03 +0100 (Fri, 21 Jan 2011)
New Revision: 1031
Url: http://nuiton.org/repositories/revision/eugene/1031
Log:
Evolution #1219: Add documentation for stereotype and tagvalue in the annotation
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java
trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java
trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java 2011-01-21 14:45:11 UTC (rev 1030)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneStereoTypes.java 2011-01-21 17:22:03 UTC (rev 1031)
@@ -48,7 +48,8 @@
* @see JavaBeanTransformer
* @see JavaGeneratorUtil#hasBeanStereotype(ObjectModelClassifier)
*/
- @StereotypeDefinition(target = ObjectModelClassifier.class)
+ @StereotypeDefinition(target = ObjectModelClassifier.class,
+ documentation = "To specify that a class is a JavaBean")
String STEREOTYPE_BEAN = "bean";
/**
@@ -56,7 +57,8 @@
*
* @see GeneratorUtil#hasIndexedStereotype(ObjectModelAttribute)
*/
- @StereotypeDefinition(target = ObjectModelAttribute.class)
+ @StereotypeDefinition(target = ObjectModelAttribute.class,
+ documentation = "To specify that a attribute is indexed")
String STEREOTYPE_INDEXED = "indexed";
/**
@@ -65,7 +67,8 @@
* @see GeneratorUtil#hasOrderedStereotype(ObjectModelAttribute)
* @since 2.3
*/
- @StereotypeDefinition(target = ObjectModelAttribute.class)
+ @StereotypeDefinition(target = ObjectModelAttribute.class,
+ documentation = "To specify that a attribute is ordered")
String STEREOTYPE_ORDERED = "ordered";
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2011-01-21 14:45:11 UTC (rev 1030)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/EugeneTagValues.java 2011-01-21 17:22:03 UTC (rev 1031)
@@ -32,6 +32,7 @@
import org.nuiton.eugene.models.object.ObjectModelReader;
import static org.nuiton.eugene.ModelPropertiesUtil.TagValueDefinition;
+
/**
* Defines all tag values managed by Eugene.
* <p/>
@@ -54,7 +55,8 @@
* @see ObjectModelReader#loadModelTagValue(ObjectModel, String, String)
* @since 2.3
*/
- @TagValueDefinition(target = {ObjectModel.class})
+ @TagValueDefinition(target = {ObjectModel.class},
+ documentation = "To set the version of the model.")
String TAG_VERSION = "version";
/**
@@ -67,7 +69,8 @@
* @see GeneratorUtil#getDocumentationTagValue(ObjectModelElement)
* @since 2.5
*/
- @TagValueDefinition(target = {ObjectModel.class, ObjectModelElement.class})
+ @TagValueDefinition(target = {ObjectModel.class, ObjectModelElement.class},
+ documentation = "Sets the documentation of a model or any of his elements")
String TAG_DOCUMENTATION = "documentation";
/**
@@ -79,7 +82,8 @@
* @see JavaGeneratorUtil#getConstantPrefixTagValue(ObjectModel, ObjectModelClassifier)
* @since 2.3
*/
- @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class})
+ @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "Sets the prefix of any constant to be generated for the given class")
String TAG_CONSTANT_PREFIX = "constantPrefix";
/**
@@ -91,7 +95,8 @@
* @see JavaGeneratorUtil#getNoPCSTagValue(ObjectModel, ObjectModelClassifier)
* @since 2.3
*/
- @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class})
+ @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "To specify to not generate any propertyChange code for a class or any class of a model")
String TAG_NO_PCS = "noPCS";
/**
@@ -102,6 +107,7 @@
* @see JavaGeneratorUtil#getI18nPrefixTagValue(ObjectModelElement, ObjectModel)
* @since 2.3
*/
- @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class})
+ @TagValueDefinition(target = {ObjectModel.class, ObjectModelClassifier.class},
+ documentation = "Sets the i18n prefix to use on I18n keys generated")
String TAG_I18N_PREFIX = "i18n";
}
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java 2011-01-21 14:45:11 UTC (rev 1030)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java 2011-01-21 17:22:03 UTC (rev 1031)
@@ -178,6 +178,14 @@
* @return the array of target object model element which can accept the tag value.
*/
Class<?>[] target();
+
+ /**
+ * Obtain the english documentation of the stereotype.
+ *
+ * @return the documentation of the stereotype.
+ * @since 2.3.1
+ */
+ String documentation();
}
/**
@@ -205,6 +213,14 @@
* @return the array of target object model element which can accept the tag value.
*/
Class<?>[] target();
+
+ /**
+ * Obtain the english documentation of the tag value.
+ *
+ * @return the documentation of the tag value.
+ * @since 2.3.1
+ */
+ String documentation();
}
/**
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-21 14:45:11 UTC (rev 1030)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-21 17:22:03 UTC (rev 1031)
@@ -251,7 +251,8 @@
buffer.append(name);
buffer.append("] targets : '");
buffer.append(toString(value));
- buffer.append('\'');
+ buffer.append("\' : ");
+ buffer.append(((ModelPropertiesUtil.TagValueDefinition) value).documentation());
}
},
stereotype {
@@ -283,7 +284,8 @@
buffer.append(name);
buffer.append("] targets : '");
buffer.append(toString(value));
- buffer.append('\'');
+ buffer.append("\' : ");
+ buffer.append(((ModelPropertiesUtil.StereotypeDefinition) value).documentation());
}
};
1
0
r1030 - in trunk: eugene/src/main/java/org/nuiton/eugene maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin
by tchemit@users.nuiton.org Jan. 21, 2011
by tchemit@users.nuiton.org Jan. 21, 2011
Jan. 21, 2011
Author: tchemit
Date: 2011-01-21 15:45:11 +0100 (Fri, 21 Jan 2011)
New Revision: 1030
Url: http://nuiton.org/repositories/revision/eugene/1030
Log:
Evolution #1218: Add stereotypes and tagvalues in the available-data goal
Modified:
trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java
trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java
===================================================================
--- trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java 2011-01-21 10:43:29 UTC (rev 1029)
+++ trunk/eugene/src/main/java/org/nuiton/eugene/ModelPropertiesUtil.java 2011-01-21 14:45:11 UTC (rev 1030)
@@ -221,6 +221,8 @@
protected Map<String, TagValueDefinition> tagValueStore;
+ protected Map<String, StereotypeDefinition> stereotypeStore;
+
protected boolean verbose;
protected ModelPropertiesProvider() {
@@ -235,7 +237,7 @@
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
-
+
public abstract void init() throws Exception;
protected void scanStereotypeClass(Class<?> holder) throws IllegalAccessException {
@@ -279,13 +281,11 @@
}
}
- protected Map<String, StereotypeDefinition> stereotypeStore;
-
- protected Map<String, StereotypeDefinition> getStereotypeStore() {
+ public Map<String, StereotypeDefinition> getStereotypeStore() {
return stereotypeStore;
}
- protected Map<String, TagValueDefinition> getTagValueStore() {
+ public Map<String, TagValueDefinition> getTagValueStore() {
return tagValueStore;
}
Modified: trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java
===================================================================
--- trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-21 10:43:29 UTC (rev 1029)
+++ trunk/maven-eugene-plugin/src/main/java/org/nuiton/eugene/plugin/AvailableDataMojo.java 2011-01-21 14:45:11 UTC (rev 1030)
@@ -29,6 +29,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.nuiton.eugene.ModelPropertiesUtil;
import org.nuiton.eugene.ModelReader;
import org.nuiton.eugene.Template;
import org.nuiton.eugene.models.Model;
@@ -47,12 +48,12 @@
* (otherwise will display all known data types).
* <p/>
*
+ * @author tchemit <chemit(a)codelutin.com>
* @goal available-data
* @requiresProject true
* @requiresDirectInvocation true
* @requiresDependencyResolution test
* @since 2.0.0
- * @author tchemit <chemit(a)codelutin.com>
*/
public class AvailableDataMojo extends AbstractMojo {
@@ -65,7 +66,9 @@
* modeltype,
* modelreader,
* modeltemplate,
- * writer
+ * writer,
+ * stereotype,
+ * tagvalue
* </pre>
* <p/>
* <b>Note:</b> Let empty to display all data types.
@@ -82,18 +85,21 @@
* @component role="org.nuiton.eugene.models.Model"
*/
protected Map<String, Model> modelTypes;
+
/**
* All available writers introspects via plexus
*
* @component role="org.nuiton.eugene.ModelReader"
*/
protected Map<String, ModelReader<?>> modelReaders;
+
/**
* All available templates introspects via plexus
*
* @component role="org.nuiton.eugene.Template"
*/
protected Map<String, Template<?>> modelTemplates;
+
/**
* All available writers introspects via plexus
*
@@ -101,6 +107,14 @@
*/
protected Map<String, ChainedFileWriter> writers;
+ /**
+ * All available model properties providers introspects via plexus
+ *
+ * @component role="org.nuiton.eugene.ModelPropertiesUtil$ModelPropertiesProvider"
+ * @since 2.3.1
+ */
+ protected Map<String, ModelPropertiesUtil.ModelPropertiesProvider> modelPropertiesProviders;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
StringBuilder buffer = new StringBuilder();
@@ -162,13 +176,7 @@
buffer.append("s : ");
}
for (Map.Entry<String, ?> e : map.entrySet()) {
- String name = e.getKey();
- Object value = e.getValue();
- buffer.append("\n [");
- buffer.append(name);
- buffer.append("] with implementation '");
- buffer.append(data.toString(value));
- buffer.append('\'');
+ data.toString(buffer, e);
}
}
@@ -184,6 +192,7 @@
public Map<String, ?> getData(AvailableDataMojo mojo) {
return mojo.writers;
}
+
@Override
String toString(Object data) {
ChainedFileWriter w = (ChainedFileWriter) data;
@@ -212,6 +221,70 @@
public Map<String, ?> getData(AvailableDataMojo mojo) {
return mojo.modelTemplates;
}
+ },
+ tagvalue {
+ @Override
+ public Map<String, ?> getData(AvailableDataMojo mojo) {
+ return mojo.getModelPropertiesProvider().getTagValueStore();
+ }
+
+ @Override
+ String toString(Object data) {
+ ModelPropertiesUtil.TagValueDefinition d = (ModelPropertiesUtil.TagValueDefinition) data;
+ StringBuilder sb = new StringBuilder();
+ Class<?>[] targets = d.target();
+ for (Class<?> aClass : targets) {
+ sb.append(", ").append(aClass.getSimpleName());
+ }
+ String result = sb.toString();
+ if (targets.length > 0) {
+ result = result.substring(2);
+ }
+ return result;
+ }
+
+ @Override
+ void toString(StringBuilder buffer, Map.Entry<String, ?> e) {
+ String name = e.getKey();
+ Object value = e.getValue();
+ buffer.append("\n [");
+ buffer.append(name);
+ buffer.append("] targets : '");
+ buffer.append(toString(value));
+ buffer.append('\'');
+ }
+ },
+ stereotype {
+ @Override
+ public Map<String, ?> getData(AvailableDataMojo mojo) {
+ return mojo.getModelPropertiesProvider().getStereotypeStore();
+ }
+
+ @Override
+ String toString(Object data) {
+ ModelPropertiesUtil.StereotypeDefinition d = (ModelPropertiesUtil.StereotypeDefinition) data;
+ StringBuilder sb = new StringBuilder();
+ Class<?>[] targets = d.target();
+ for (Class<?> aClass : targets) {
+ sb.append(", ").append(aClass.getSimpleName());
+ }
+ String result = sb.toString();
+ if (targets.length > 0) {
+ result = result.substring(2);
+ }
+ return result;
+ }
+
+ @Override
+ void toString(StringBuilder buffer, Map.Entry<String, ?> e) {
+ String name = e.getKey();
+ Object value = e.getValue();
+ buffer.append("\n [");
+ buffer.append(name);
+ buffer.append("] targets : '");
+ buffer.append(toString(value));
+ buffer.append('\'');
+ }
};
abstract Map<String, ?> getData(AvailableDataMojo mojo);
@@ -219,6 +292,39 @@
String toString(Object data) {
return data.getClass().getName();
}
+
+ void toString(StringBuilder buffer, Map.Entry<String, ?> e) {
+ String name = e.getKey();
+ Object value = e.getValue();
+ buffer.append("\n [");
+ buffer.append(name);
+ buffer.append("] with implementation '");
+ buffer.append(toString(value));
+ buffer.append('\'');
+ }
}
+ protected ModelPropertiesUtil.ModelPropertiesProvider getModelPropertiesProvider() {
+
+ ModelPropertiesUtil.ModelPropertiesProvider provider;
+
+ if (modelPropertiesProviders == null ||
+ modelPropertiesProviders.isEmpty()) {
+
+ // could not find any model properties via plexus
+ // try to obtain them by ServiceLoader
+
+ provider = ModelPropertiesUtil.newStore(
+ getClass().getClassLoader(),
+ false
+ );
+ } else {
+ provider = ModelPropertiesUtil.newStore(
+ modelPropertiesProviders.values(),
+ false
+ );
+ }
+ return provider;
+ }
+
}
1
0
Author: tchemit
Date: 2011-01-21 11:43:29 +0100 (Fri, 21 Jan 2011)
New Revision: 1029
Url: http://nuiton.org/repositories/revision/eugene/1029
Log:
Evolution #1217: Updates Processor to 1.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-23 10:27:24 UTC (rev 1028)
+++ trunk/pom.xml 2011-01-21 10:43:29 UTC (rev 1029)
@@ -41,8 +41,8 @@
<modules>
<module>eugene</module>
+ <module>maven-eugene-plugin</module>
<module>ant-eugene-task</module>
- <module>maven-eugene-plugin</module>
</modules>
<dependencyManagement>
@@ -378,7 +378,7 @@
<!-- pour un muli module on doit fixer le projectId -->
<projectId>eugene</projectId>
- <processorPluginVersion>1.0.4</processorPluginVersion>
+ <processorPluginVersion>1.1</processorPluginVersion>
<nuitonUtilsVersion>1.5.2</nuitonUtilsVersion>
<nuitonI18nVersion>2.0.1</nuitonI18nVersion>
1
0