boolean disableOptimizations,
TypeMetadata.Builder typeMetadataBuilder,
ConfigContext configContext,
PathsContext pathsContext,
ParseContext parseContext) {
IndexedEmbedded indexedEmbeddedAnnotation = member.getAnnotation( IndexedEmbedded.class );
if ( indexedEmbeddedAnnotation == null ) {
return;
}
parseContext.collectUnqualifiedCollectionRole( member.getName() );
int oldMaxLevel = parseContext.getMaxLevel();
int potentialLevel = depth( indexedEmbeddedAnnotation ) + parseContext.getLevel();
// This is really catching a possible int overflow. depth() can return Integer.MAX_VALUE, which then can
// overflow in case level > 0. Really this code should be rewritten (HF)
if ( potentialLevel < 0 ) {
potentialLevel = Integer.MAX_VALUE;
}
// HSEARCH-1442 recreating the behavior prior to PropertiesMetadata refactoring
// not sure whether this is algorithmically correct though. @IndexedEmbedded processing should be refactored (HF)
if ( potentialLevel < oldMaxLevel ) {
parseContext.setMaxLevel( potentialLevel );
}
parseContext.incrementLevel();
XClass elementClass;
if ( void.class == indexedEmbeddedAnnotation.targetElement() ) {
elementClass = member.getElementClass();
}
else {
elementClass = reflectionManager.toXClass( indexedEmbeddedAnnotation.targetElement() );
}
if ( parseContext.getMaxLevel() == Integer.MAX_VALUE //infinite
&& parseContext.hasBeenProcessed( elementClass ) ) {
throw log.detectInfiniteTypeLoopInIndexedEmbedded(
elementClass.getName(),
typeMetadataBuilder.getIndexedType().getName(),
buildEmbeddedPrefix( prefix, indexedEmbeddedAnnotation, member )
);
}
String localPrefix = buildEmbeddedPrefix( prefix, indexedEmbeddedAnnotation, member );
PathsContext updatedPathsContext = updatePaths( localPrefix, pathsContext, indexedEmbeddedAnnotation );
boolean pathsCreatedAtThisLevel = false;
if ( pathsContext == null && updatedPathsContext != null ) {
//after this level if not all paths are traversed, then the paths
//either don't exist in the object graph, or aren't indexed paths
pathsCreatedAtThisLevel = true;
}
if ( !parseContext.isMaxLevelReached() || isInPath(
localPrefix,
updatedPathsContext,
indexedEmbeddedAnnotation
) ) {
parseContext.processingClass( elementClass ); //push
EmbeddedTypeMetadata.Builder embeddedTypeMetadataBuilder =
new EmbeddedTypeMetadata.Builder(
reflectionManager.toClass( elementClass ),
member,
typeMetadataBuilder.getScopedAnalyzer()
);
embeddedTypeMetadataBuilder.boost( AnnotationProcessingHelper.getBoost( member, null ) );
//property > entity analyzer
Analyzer analyzer = AnnotationProcessingHelper.
getAnalyzer(
member.getAnnotation( org.hibernate.search.annotations.Analyzer.class ),
configContext
);
if ( analyzer == null ) {
analyzer = typeMetadataBuilder.getAnalyzer();
}
embeddedTypeMetadataBuilder.analyzer( analyzer );
if ( disableOptimizations ) {
typeMetadataBuilder.blacklistForOptimization( elementClass );
}
// about to do a recursion, keep parse state which needs resetting
XClass previousClass = parseContext.getCurrentClass();
parseContext.setCurrentClass( elementClass );
boolean previousIncludeEmbeddedObjectId = parseContext.includeEmbeddedObjectId();
parseContext.setIncludeEmbeddedObjectId( indexedEmbeddedAnnotation.includeEmbeddedObjectId() );
initializeClass(
embeddedTypeMetadataBuilder,
false,
localPrefix,
parseContext,