Skip to content

Commit d91d87c

Browse files
cigalygavinking
authored andcommitted
HHH-18693 Changed name generation for metamodel classes and sources
Generated metadata for inner class A.B is A_.B_ Path source for inner class is identical to path source for enclosing class
1 parent dcdeb04 commit d91d87c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/CompilationStatement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ private List<File> getCompilationUnits(List<Class<?>> classesToCompile, List<Str
100100
}
101101

102102
private String getPathToSource(Class<?> testClass) {
103+
if ( testClass.isMemberClass() ) {
104+
return getPathToSource( testClass.getDeclaringClass() );
105+
}
103106
return TestUtil.getSourceBaseDir( testClass ).getAbsolutePath() + File.separator + testClass.getName()
104107
.replace( PACKAGE_SEPARATOR, File.separator ) + ".java";
105108
}

tooling/metamodel-generator/src/test/java/org/hibernate/processor/test/util/TestUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public static Class<?> getMetamodelClassFor(String className) {
335335
}
336336

337337
public static File getMetaModelSourceFileFor(Class<?> clazz, boolean prefix) {
338+
if ( clazz.isMemberClass() ) {
339+
return getMetaModelSourceFileFor( clazz.getEnclosingClass(), prefix );
340+
}
338341
String metaModelClassName = getMetaModelClassName(clazz, prefix);
339342
// generate the file name
340343
String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
@@ -351,13 +354,17 @@ public static File getMetaModelSourceFileFor(String className) {
351354
}
352355

353356
private static String getMetaModelClassName(Class<?> clazz, boolean prefix) {
354-
return prefix
355-
? clazz.getPackageName() + '.' + META_MODEL_CLASS_POSTFIX + clazz.getSimpleName()
356-
: clazz.getName() + META_MODEL_CLASS_POSTFIX;
357+
final String packageName = clazz.getPackageName();
358+
return prefix ? packageName + '.' + META_MODEL_CLASS_POSTFIX + clazz.getName().substring( packageName.length() + 1 )
359+
.replaceAll( "\\$", "\\$_" )
360+
: packageName + clazz.getName().substring( packageName.length() )
361+
.replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX;
357362
}
358363

359364
private static String getMetaModelClassName(String className) {
360-
return className + META_MODEL_CLASS_POSTFIX;
365+
final int index = className.lastIndexOf( '.' );
366+
final String packageName = className.substring( 0, index + 1 );
367+
return packageName + className.substring( packageName.length() ).replaceAll( "\\$", "_\\$" ) + META_MODEL_CLASS_POSTFIX;
361368
}
362369

363370
public static String getMetaModelSourceAsString(Class<?> clazz) {

0 commit comments

Comments
 (0)