<commit_before>package ca.concordia.cssanalyser.cssmodel.declaration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import ca.concordia.cssanalyser.cssmodel.declaration.value.DeclarationValue;
import ca.concordia.cssanalyser.cssmodel.declaration.value.ValueType;
import ca.concordia.cssanalyser.cssmodel.selectors.Selector;


/**
 * Representation of shorthand declarations
 * @author <NAME>
 *
 */
public class ShorthandDeclaration extends Declaration {

	private Map<String, Declaration> individualDeclarations;
	
	private static final Map<String, Set<String>> shorthandProperties = new HashMap<>();
	
	private boolean isVirtual = false;
	
	static {
		initializeShorthandsMap();
	}

	public ShorthandDeclaration(String propertyName, List<DeclarationValue> values, Selector belongsTo, int fileLineNumber, int fileColNumber, boolean important) {
		super(propertyName, values, belongsTo, fileLineNumber, fileColNumber, important);
		if (individualDeclarations == null)
			individualDeclarations =  new HashMap<>();
	}
	
	/**
	 * Sets the value indicating whether this shorthand declaration 
	 * is virtual
	 * (i.e. it has been added as an equivalent for a set of 
	 * individual declarations when finding type III duplication
	 * instances)
	 * @return
	 */
	public void isVirtual(boolean virtual) {
		this.isVirtual = virtual;
	}
	
	/**
	 * Shows whether this shorthand declaration is virtual
	 * (i.e. it has been added as an equivalent for a set of 
	 * individual declarations when finding type III duplication
	 * instances)
	 * @return
	 */
	public boolean isVirtual() {
		return this.isVirtual;
	}
	
	private static void initializeShorthandsMap() {
		
		//addShorthandProperty("animation", )
		
		addShorthandProperty("background", "background-image",
										   "background-repeat",
										   "background-attachement",
										   "background-origin",
										   "background-clip",
										   "background-position",
										   "background-size",
										   "background-color");
		
		addShorthandProperty("border", "border-color",
									   "border-width",
									   "border-style");
		
		addShorthandProperty("border-bottom", "border-bottom-color",
											  "border-bottom-width",
											  "border-bottom-style");
		
		addShorthandProperty("border-left", "border-left-color",
				  							"border-left-width",
				  							"border-left-style");
		
		addShorthandProperty("border-right", "border-right-color",
			  							     "border-right-width",
				  							 "border-right-style");
		
		addShorthandProperty("border-top", "border-top-color",
				  						   "border-top-width",
				  						   "border-top-style");
		
		addShorthandProperty("border-color", "border-left-color",
											 "border-right-color",
											 "border-top-color",
											 "border-bottom-color");
		
		addShorthandProperty("border-width", "border-left-width",
											 "border-right-width",
											 "border-top-width",
											 "border-bottom-width");
		
		addShorthandProperty("border-style", "border-left-style",
											 "border-right-style",
											 "border-top-style",
											 "border-bottom-style");
		
		addShorthandProperty("outline", "outline-color",
						     "outline-width",
						     "outline-style");
		
		//addShorthandProperty("border-image", );
		//addShorthandProperty("target", );
		
		addShorthandProperty("border-radius", "border-top-left-radius",
											  "border-top-right-radius",
											  "border-bottom-right-radius",
											  "border-bottom-left-radius");
		
		addShorthandProperty("list-style", "list-style-type",
										   "list-style-position",
										   "list-style-image");
		
		addShorthandProperty("margin", "margin-left",
									   "margin-right",
									   "margin-top",
									   "margin-bottom");
		
		addShorthandProperty("column-rule", "column-rule-style",
											"column-rule-color",
											"column-rule-width");
		
		addShorthandProperty("columns", "column-width",
										"column-count");
		
		addShorthandProperty("padding", "padding-left",
									    "padding-right",
									    "padding-top",
									    "padding-bottom");
		
		addShorthandProperty("transition", "transition-duration", 
										   "transition-timing-function",
										   "transition-delay", 
										   "transition-property");
		
		addShorthandProperty("font", "font-style",
									 "font-variant",
									 "font-weight",
									 "font-stretch",
									 "font-size",
									 "line-height",
									 "font-family");
	}
	
	private static void addShorthandProperty(String shorthandPropertyName, String... individualPropertyNames) {
		shorthandProperties.put(shorthandPropertyName, new HashSet<>(Arrays.asList(individualPropertyNames)));
	}

	/**
	 * Specifies whether a property is a shorthand or not.
	 * @param property
	 * @return
	 */
	public static boolean isShorthandProperty(String property) {
		property = getNonVendorProperty(property);
		return shorthandProperties.containsKey(property);
	}
	
	public static Set<String> getIndividualPropertiesForAShorthand(String shorthandProperty) {
		Set<String> result = new HashSet<>();
		Set<String> currentLevel = shorthandProperties.get(shorthandProperty);<commit_msg>added getAllShorthandProperties() to ShorthandDeclaration class<commit_after>package ca.concordia.cssanalyser.cssmodel.declaration;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import ca.concordia.cssanalyser.cssmodel.declaration.value.DeclarationValue;
import ca.concordia.cssanalyser.cssmodel.declaration.value.ValueType;
import ca.concordia.cssanalyser.cssmodel.selectors.Selector;


/**
 * Representation of shorthand declarations
 * @author <NAME>
 *
 */
public class ShorthandDeclaration extends Declaration {

	private Map<String, Declaration> individualDeclarations;
	
	private static final Map<String, Set<String>> shorthandProperties = new HashMap<>();
	
	private boolean isVirtual = false;
	
	static {
		initializeShorthandsMap();
	}

	public ShorthandDeclaration(String propertyName, List<DeclarationValue> values, Selector belongsTo, int fileLineNumber, int fileColNumber, boolean important) {
		super(propertyName, values, belongsTo, fileLineNumber, fileColNumber, important);
		if (individualDeclarations == null)
			individualDeclarations =  new HashMap<>();
	}
	
	/**
	 * Sets the value indicating whether this shorthand declaration 
	 * is virtual
	 * (i.e. it has been added as an equivalent for a set of 
	 * individual declarations when finding type III duplication
	 * instances)
	 * @return
	 */
	public void isVirtual(boolean virtual) {
		this.isVirtual = virtual;
	}
	
	/**
	 * Shows whether this shorthand declaration is virtual
	 * (i.e. it has been added as an equivalent for a set of 
	 * individual declarations when finding type III duplication
	 * instances)
	 * @return
	 */
	public boolean isVirtual() {
		return this.isVirtual;
	}
	
	private static void initializeShorthandsMap() {
		
		//addShorthandProperty("animation", )
		
		addShorthandProperty("background", "background-image",
										   "background-repeat",
										   "background-attachement",
										   "background-origin",
										   "background-clip",
										   "background-position",
										   "background-size",
										   "background-color");
		
		addShorthandProperty("border", "border-color",
									   "border-width",
									   "border-style");
		
		addShorthandProperty("border-bottom", "border-bottom-color",
											  "border-bottom-width",
											  "border-bottom-style");
		
		addShorthandProperty("border-left", "border-left-color",
				  							"border-left-width",
				  							"border-left-style");
		
		addShorthandProperty("border-right", "border-right-color",
			  							     "border-right-width",
				  							 "border-right-style");
		
		addShorthandProperty("border-top", "border-top-color",
				  						   "border-top-width",
				  						   "border-top-style");
		
		addShorthandProperty("border-color", "border-left-color",
											 "border-right-color",
											 "border-top-color",
											 "border-bottom-color");
		
		addShorthandProperty("border-width", "border-left-width",
											 "border-right-width",
											 "border-top-width",
											 "border-bottom-width");
		
		addShorthandProperty("border-style", "border-left-style",
											 "border-right-style",
											 "border-top-style",
											 "border-bottom-style");
		
		addShorthandProperty("outline", "outline-color",
						     "outline-width",
						     "outline-style");
		
		//addShorthandProperty("border-image", );
		//addShorthandProperty("target", );
		
		addShorthandProperty("border-radius", "border-top-left-radius",
											  "border-top-right-radius",
											  "border-bottom-right-radius",
											  "border-bottom-left-radius");
		
		addShorthandProperty("list-style", "list-style-type",
										   "list-style-position",
										   "list-style-image");
		
		addShorthandProperty("margin", "margin-left",
									   "margin-right",
									   "margin-top",
									   "margin-bottom");
		
		addShorthandProperty("column-rule", "column-rule-style",
											"column-rule-color",
											"column-rule-width");
		
		addShorthandProperty("columns", "column-width",
										"column-count");
		
		addShorthandProperty("padding", "padding-left",
									    "padding-right",
									    "padding-top",
									    "padding-bottom");
		
		addShorthandProperty("transition", "transition-duration", 
										   "transition-timing-function",
										   "transition-delay", 
										   "transition-property");
		
		addShorthandProperty("font", "font-style",
									 "font-variant",
									 "font-weight",
									 "font-stretch",
									 "font-size",
									 "line-height",
									 "font-family");
	}
	
	/**
	 * Returns an Iterable containing all shorthand property names
	 * @return
	 */
	public static Iterable<String> getAllShorthandProperties() {
		return shorthandProperties.keySet();
	}
	
	private static void addShorthandProperty(String shorthandPropertyName, String... individualPropertyNames) {
		shorthandProperties.put(shorthandPropertyName, new HashSet<>(Arrays.asList(individualPropertyNames)));
	}

	/**
	 * Specifies whether a property is a shorthand or not.
	 * @param property
	 * @return
	 */
	public static boolean isShorthandProperty(String property) {
		property = getNonVendorProperty(property);
		return shorthandProperties.containsKey(property);
	}
	
	public static Set<String> getIndividualPropertiesForAShorthand(String shorthandProperty) {
		Set<String> result = new HashSet<>();
		Set<String> currentLevel = shorthandProperties.get(shorthandProperty);
{'fraction_non_alphanumeric': 0.12269606071557644, 'fraction_numerical': 0.0, 'mean_word_length': 2.987391930835735, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '3837677', 'n_tokens_mistral': 4341, 'n_tokens_neox': 3102, 'n_words': 592}