<commit_before>package ch.liquidmind.inflection.association;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public class Pass3Scanner extends AbstractScanner
{
	public Pass3Scanner( Map< String, Class > classes )
	{
		super( classes );
	}

	public void scan()
	{
		getClasses().values().forEach( aClass -> setupClass( aClass ) );
	}
	
	private void setupClass( Class aClass )
	{
		setupProperties( aClass );
		setupAssociations( aClass );
	}

	private void setupProperties( Class aClass )
	{
		aClass.getOwnedProperties().forEach( property -> setupProperty( property ) );
	}
	
	private void setupProperty( Property property )
	{
		ch.liquidmind.inflection.association.annotations.Property propertyAnnotation = getPropertyAnnotation( property );
		property.setRedefinedProperty( determineRedefinedProperty( property, propertyAnnotation ) );
		property.setSubsettedProperty( determineSubsettedProperty( property, propertyAnnotation ) );
	}
	
	private Property determineRedefinedProperty( Property property, ch.liquidmind.inflection.association.annotations.Property propertyAnnotation )
	{
		Property specifiedProperty = ( propertyAnnotation == null ? null : findProperty( property.getOwningClass(), propertyAnnotation.redefines() ) );
		Property overriddenProperty = findProperty( property.getOwningClass().getSuperClass(), property.getName() );
		
		if ( ( specifiedProperty != null && overriddenProperty != null ) && !specifiedProperty.equals( overriddenProperty ) )
			throw new RuntimeException( String.format( "Ambiguous redefinition for property %s.%s: property both overrides %s.%s and redefines %s.%s.", 
				property.getOwningClass().getName(), property.getName(), overriddenProperty.getOwningClass().getName(), overriddenProperty.getName(),
				 specifiedProperty.getOwningClass().getName(), specifiedProperty.getName() ) );
		
		if ( propertyAnnotation != null && !propertyAnnotation.redefines().isEmpty() && specifiedProperty == null )
			throw new RuntimeException( String.format( "Illegal redefinition for property %s.%s: specified property %s cannot be found.", 
				property.getOwningClass().getName(), property.getName(), propertyAnnotation.redefines() ) );

		Property redefinedProperty = ( specifiedProperty != null ? specifiedProperty : overriddenProperty );
		Property redefiningProperty = ( redefinedProperty == null ? null : redefinedProperty.getRedefiningProperty() );
		
		java.lang.Class< ? > classOfRedefiningProperty = ( redefiningProperty == null ? null : redefiningProperty.getOwningClass().getTargetClass() );
		java.lang.Class< ? > classOfProperty = property.getOwningClass().getTargetClass();
		
		if ( classOfRedefiningProperty != null && classOfRedefiningProperty.isAssignableFrom( classOfProperty ) )
			throw new RuntimeException( String.format( "Illegal redefinition for property %s.%s: specified property %s.%s is already redefined by %s.%s.",
				property.getOwningClass().getName(), property.getName(), redefinedProperty.getOwningClass().getName(), redefinedProperty.getName(),
				redefiningProperty.getOwningClass().getName(), redefiningProperty.getName() ) );
				
		if ( redefinedProperty != null && isFinal( redefinedProperty ) )
			throw new RuntimeException( String.format( "Illegal redefinition for final property %s.%s.",
				redefinedProperty.getOwningClass().getName(), redefinedProperty.getName() ) );
		
		return redefinedProperty;
	}
	<commit_msg>Removed automatic redefinitions for overriding properties.<commit_after>package ch.liquidmind.inflection.association;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public class Pass3Scanner extends AbstractScanner
{
	public Pass3Scanner( Map< String, Class > classes )
	{
		super( classes );
	}

	public void scan()
	{
		getClasses().values().forEach( aClass -> setupClass( aClass ) );
	}
	
	private void setupClass( Class aClass )
	{
		setupProperties( aClass );
		setupAssociations( aClass );
	}

	private void setupProperties( Class aClass )
	{
		aClass.getOwnedProperties().forEach( property -> setupProperty( property ) );
	}
	
	private void setupProperty( Property property )
	{
		ch.liquidmind.inflection.association.annotations.Property propertyAnnotation = getPropertyAnnotation( property );
		property.setRedefinedProperty( determineRedefinedProperty( property, propertyAnnotation ) );
		property.setSubsettedProperty( determineSubsettedProperty( property, propertyAnnotation ) );
	}
	
	private Property determineRedefinedProperty( Property property, ch.liquidmind.inflection.association.annotations.Property propertyAnnotation )
	{
		Property redefinedProperty = ( propertyAnnotation == null ? null : findProperty( property.getOwningClass(), propertyAnnotation.redefines() ) );
		
		if ( propertyAnnotation != null && !propertyAnnotation.redefines().isEmpty() && redefinedProperty == null )
			throw new RuntimeException( String.format( "Illegal redefinition for property %s.%s: specified property %s cannot be found.", 
				property.getOwningClass().getName(), property.getName(), propertyAnnotation.redefines() ) );

		Property redefiningProperty = ( redefinedProperty == null ? null : redefinedProperty.getRedefiningProperty() );
		
		java.lang.Class< ? > classOfRedefiningProperty = ( redefiningProperty == null ? null : redefiningProperty.getOwningClass().getTargetClass() );
		java.lang.Class< ? > classOfProperty = property.getOwningClass().getTargetClass();
		
		if ( classOfRedefiningProperty != null && classOfRedefiningProperty.isAssignableFrom( classOfProperty ) )
			throw new RuntimeException( String.format( "Illegal redefinition for property %s.%s: specified property %s.%s is already redefined by %s.%s.",
				property.getOwningClass().getName(), property.getName(), redefinedProperty.getOwningClass().getName(), redefinedProperty.getName(),
				redefiningProperty.getOwningClass().getName(), redefiningProperty.getName() ) );
				
		if ( redefinedProperty != null && isFinal( redefinedProperty ) )
			throw new RuntimeException( String.format( "Illegal redefinition for final property %s.%s.",
				redefinedProperty.getOwningClass().getName(), redefinedProperty.getName() ) );
		
		return redefinedProperty;
	}
	
{'fraction_non_alphanumeric': 0.1129379225568531, 'fraction_numerical': 0.0006146281499692685, 'mean_word_length': 5.614837398373984, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1919141', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1703, 'n_words': 395}