[#4229] ScalaGenerator generates unneeded imports

This commit is contained in:
lukaseder 2015-06-15 13:21:59 +02:00
parent 6af0c2edf0
commit 87ac3d61b6
3 changed files with 17 additions and 0 deletions

View File

@ -228,6 +228,8 @@ class GenerationUtil {
* Gets the base type for an array type, depending on the RDBMS dialect
*/
static String getArrayBaseType(SQLDialect dialect, String t, String u) {
// [#4388] TODO: Improve array handling
switch (dialect.family()) {
/* [pro] xx
xxxx xxxxxxxxx

View File

@ -4253,6 +4253,8 @@ public class JavaGenerator extends AbstractGenerator {
}
protected String getJavaTypeReference(Database db, DataTypeDefinition type) {
// [#4388] TODO: Improve array handling
if (database.isArrayType(type.getType())) {
String baseType = GenerationUtil.getArrayBaseType(db.getDialect(), type.getType(), type.getUserType());
return getTypeReference(
@ -4307,6 +4309,8 @@ public class JavaGenerator extends AbstractGenerator {
// Array types
if (db.isArrayType(t)) {
// [#4388] TODO: Improve array handling
String baseType = GenerationUtil.getArrayBaseType(db.getDialect(), t, u);
if (scala)

View File

@ -116,6 +116,13 @@ public class JavaWriter extends GeneratorWriter<JavaWriter> {
@Override
protected String beforeClose(String string) {
StringBuilder importString = new StringBuilder();
String pkg = "";
Matcher m = Pattern.compile("(?s:^.*?\\Rpackage\\s+(.*?);?\\R.*?$)").matcher(string);
if (m.find())
pkg = m.group(1);
Pattern samePackagePattern = Pattern.compile(pkg + "\\.[^\\.]+");
String previous = "";
for (String imp : qualifiedTypes) {
@ -129,6 +136,10 @@ public class JavaWriter extends GeneratorWriter<JavaWriter> {
if (imp.endsWith("." + className))
continue;
// [#4229] Avoid Scala-emitted warning of same-package imports
if (isScala && pkg.length() > 0 && samePackagePattern.matcher(imp).matches())
continue;
String topLevelPackage = imp.split("\\.")[0];
if (!topLevelPackage.equals(previous))