<commit_before>package ca.concordia.cssanalyser.migration.topreprocessors;

import java.util.ArrayList;
import java.util.List;

import ca.concordia.cssanalyser.analyser.duplication.DuplicationDetector;
import ca.concordia.cssanalyser.analyser.duplication.items.Item;
import ca.concordia.cssanalyser.analyser.duplication.items.ItemSet;
import ca.concordia.cssanalyser.analyser.duplication.items.ItemSetList;
import ca.concordia.cssanalyser.cssmodel.StyleSheet;
import ca.concordia.cssanalyser.cssmodel.declaration.Declaration;
import ca.concordia.cssanalyser.cssmodel.selectors.Selector;
import ca.concordia.cssanalyser.migration.topreprocessors.mixin.MixinMigrationOpportunity;

public abstract class PreprocessorMigrationOpportunitiesDetector {
	
	private final StyleSheet styleSheet;
	
	public abstract MixinMigrationOpportunity getNewPreprocessorSpecificOpportunity();

	public PreprocessorMigrationOpportunitiesDetector(StyleSheet styleSheet) {
		this.styleSheet = styleSheet;
	}

	public List<MixinMigrationOpportunity> findMixinOpportunities() {
		
		// Apply FP-Growth on normal duplications
		DuplicationDetector duplicationDetector = new DuplicationDetector(this.styleSheet);
		duplicationDetector.findDuplications();
		// Subsets will not be there
		List<ItemSetList> itemSetLists = duplicationDetector.fpGrowth(2, true);
		
		List<MixinMigrationOpportunity> mixinRefactoringOpportunities = new ArrayList<>();
		
		/*
		 * Each of the duplications will be a opportunity.
		 * We will add declarations with differences as well.
		 */
		for (ItemSetList itemSetList : itemSetLists) {
			
			for (ItemSet itemSet : itemSetList) {
				
				MixinMigrationOpportunity opportunity = getNewPreprocessorSpecificOpportunity();
				mixinRefactoringOpportunities.add(opportunity);
				
				// First, add all the equal or equivalent declarations to this opportunity
				List<Declaration> declarations = itemSet.getRepresentativeDeclarations();
				
				for (Item item : itemSet)
					opportunity.addEquivalentDeclarations(item);
				
				// A Mixin refactoring opportunity also needs the selectors involved in the duplication
				List<Selector> itemSetSelectors = new ArrayList<>();
				for (Selector s : itemSet.getSupport())
					itemSetSelectors.add(s);
			
				// Try to add declarations with differences
				Selector firstSelector = itemSetSelectors.get(0);
				for (Declaration declarationInTheFirstSelector : firstSelector.getDeclarations()) {
					// We only care about remaining declarations, which are not equal or equivalent
					if (declarations.contains(declarationInTheFirstSelector))
						continue;
					
					List<Declaration> declarationsToAdd = new ArrayList<>();
					declarationsToAdd.add(declarationInTheFirstSelector);
					
					// Compare all other declarations in other selectors with the current declaration in the first selector
					for (int i = 1; i < itemSetSelectors.size(); i++) {
						
						for (Declaration declarationInTheSecondSelector : itemSetSelectors.get(i).getDeclarations()) {
							
							// Again we only care about remaining declarations, which are not equal or equivalent
							if (declarations.contains(declarationInTheSecondSelector))
								continue;

							if (declarationInTheFirstSelector.getProperty().equals(declarationInTheSecondSelector.getProperty())) {
								// Here we go: a difference in values should be there
								// Every value can be a difference
								
								declarationsToAdd.add(declarationInTheSecondSelector);
								
							}

						} 


						/*
						 * Now go for virtual shorthand declarations.
						 */
//						for (ShorthandDeclaration shorthand : itemSetSelectors.get(i).getVirtualShorthandDeclarations()) {
//							// TODO
//						}

					}
					
					// If declarations are present in all selectors
					if (declarationsToAdd.size() == itemSetSelectors.size()) {
						opportunity.addDeclarationsWithDifferences(declarationsToAdd);
					}
				}
			}
		}
		
		return mixinRefactoringOpportunities;
		
	}

}
<commit_msg>Made getNewPreprocessorSpecificOpportunity() protected (The method is useless from outside the class hierarchy)<commit_after>package ca.concordia.cssanalyser.migration.topreprocessors;

import java.util.ArrayList;
import java.util.List;

import ca.concordia.cssanalyser.analyser.duplication.DuplicationDetector;
import ca.concordia.cssanalyser.analyser.duplication.items.Item;
import ca.concordia.cssanalyser.analyser.duplication.items.ItemSet;
import ca.concordia.cssanalyser.analyser.duplication.items.ItemSetList;
import ca.concordia.cssanalyser.cssmodel.StyleSheet;
import ca.concordia.cssanalyser.cssmodel.declaration.Declaration;
import ca.concordia.cssanalyser.cssmodel.selectors.Selector;
import ca.concordia.cssanalyser.migration.topreprocessors.mixin.MixinMigrationOpportunity;

public abstract class PreprocessorMigrationOpportunitiesDetector {
	
	private final StyleSheet styleSheet;
	
	protected abstract MixinMigrationOpportunity getNewPreprocessorSpecificOpportunity();

	public PreprocessorMigrationOpportunitiesDetector(StyleSheet styleSheet) {
		this.styleSheet = styleSheet;
	}

	public List<MixinMigrationOpportunity> findMixinOpportunities() {
		
		// Apply FP-Growth on normal duplications
		DuplicationDetector duplicationDetector = new DuplicationDetector(this.styleSheet);
		duplicationDetector.findDuplications();
		// Subsets will not be there
		List<ItemSetList> itemSetLists = duplicationDetector.fpGrowth(2, true);
		
		List<MixinMigrationOpportunity> mixinRefactoringOpportunities = new ArrayList<>();
		
		/*
		 * Each of the duplications will be a opportunity.
		 * We will add declarations with differences as well.
		 */
		for (ItemSetList itemSetList : itemSetLists) {
			
			for (ItemSet itemSet : itemSetList) {
				
				MixinMigrationOpportunity opportunity = getNewPreprocessorSpecificOpportunity();
				mixinRefactoringOpportunities.add(opportunity);
				
				// First, add all the equal or equivalent declarations to this opportunity
				List<Declaration> declarations = itemSet.getRepresentativeDeclarations();
				
				for (Item item : itemSet)
					opportunity.addEquivalentDeclarations(item);
				
				// A Mixin refactoring opportunity also needs the selectors involved in the duplication
				List<Selector> itemSetSelectors = new ArrayList<>();
				for (Selector s : itemSet.getSupport())
					itemSetSelectors.add(s);
			
				// Try to add declarations with differences
				Selector firstSelector = itemSetSelectors.get(0);
				for (Declaration declarationInTheFirstSelector : firstSelector.getDeclarations()) {
					// We only care about remaining declarations, which are not equal or equivalent
					if (declarations.contains(declarationInTheFirstSelector))
						continue;
					
					List<Declaration> declarationsToAdd = new ArrayList<>();
					declarationsToAdd.add(declarationInTheFirstSelector);
					
					// Compare all other declarations in other selectors with the current declaration in the first selector
					for (int i = 1; i < itemSetSelectors.size(); i++) {
						
						for (Declaration declarationInTheSecondSelector : itemSetSelectors.get(i).getDeclarations()) {
							
							// Again we only care about remaining declarations, which are not equal or equivalent
							if (declarations.contains(declarationInTheSecondSelector))
								continue;

							if (declarationInTheFirstSelector.getProperty().equals(declarationInTheSecondSelector.getProperty())) {
								// Here we go: a difference in values should be there
								// Every value can be a difference
								
								declarationsToAdd.add(declarationInTheSecondSelector);
								
							}

						} 


						/*
						 * Now go for virtual shorthand declarations.
						 */
//						for (ShorthandDeclaration shorthand : itemSetSelectors.get(i).getVirtualShorthandDeclarations()) {
//							// TODO
//						}

					}
					
					// If declarations are present in all selectors
					if (declarationsToAdd.size() == itemSetSelectors.size()) {
						opportunity.addDeclarationsWithDifferences(declarationsToAdd);
					}
				}
			}
		}
		
		return mixinRefactoringOpportunities;
		
	}

}

{'fraction_non_alphanumeric': 0.07774634026325501, 'fraction_numerical': 0.0007380981670562184, 'mean_word_length': 3.9816176470588234, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '3234212', 'n_tokens_mistral': 2820, 'n_tokens_neox': 2195, 'n_words': 513}