<commit_before>package ca.edchipman.silverstripepdt.style;


import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
import org.eclipse.wst.html.ui.internal.style.LineStyleProviderForHTML;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML;

import ca.edchipman.silverstripepdt.SilverStripePDTPlugin;
import ca.edchipman.silverstripepdt.regions.SilverStripeRegionContext;

@SuppressWarnings("restriction")
public class LineStyleProviderForSS extends LineStyleProviderForHTML {
    private IPreferenceStore preferenceStore;
    
    protected String ssVersion="SS3.0";
    
    public LineStyleProviderForSS() {
        super();
    }
    
    /**
     * a method to centralize all the "format rules" for regions 
     * specifically associated for how to "open" the region.
     */
    // NOTE: this method was just copied down form LineStyleProviderForXML
    public TextAttribute getAttributeFor(ITextRegion region) {
        // not sure why this is coming through null, but just to catch it
        if (region == null) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsXML.XML_CONTENT);
        }
        
        String type = region.getType();
        if (type == SilverStripeRegionContext.SS_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_DELIM);
        } else if (type == SilverStripeRegionContext.SS_CLOSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_DELIM);
        } else if (type == SilverStripeRegionContext.SS_CONDITIONAL_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONDITIONAL_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CONDITIONAL_TEXT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONDITIONAL_TEXT);
        } else if (type == SilverStripeRegionContext.SS_ELSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_ELSE);
        } else if (type == SilverStripeRegionContext.SS_END_IF) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_IF);
        } else if (type == SilverStripeRegionContext.SS_BASE_TAG) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_BASE_TAG);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_DELIM);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_TEXT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_TEXT);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_CLOSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_DELIM);
        } else if (type == SilverStripeRegionContext.SS_REQUIREMENT_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_REQUIREMENT_OPEN);
        } else if (type == SilverStripeRegionContext.SS_REQUIREMENT_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_REQUIREMENT_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_INCLUDE_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_INCLUDE_OPEN);
        } else if (type == SilverStripeRegionContext.SS_INCLUDE_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_INCLUDE_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_CONTROL_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONTROL_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CONTROL_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONTROL_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_CONTROL) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_CONTROL);
        } else if (type == SilverStripeRegionContext.SS_VARIABLE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_VARIABLE);
        } else if (type == SilverStripeRegionContext.SS_CACHEBLOCK_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CACHEBLOCK_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CACHEBLOCK_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CACHEBLOCK_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_CACHEBLOCK) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_CACHEBLOCK);
        } else if (type == SilverStripeRegionContext.SS_UNCACHED_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_UNCACHED_OPEN);
        } else if (type == SilverStripeRegionContext.SS_UNCACHED_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_UNCACHED_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_UNCACHED) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_UNCACHED);
        } else if (type == SilverStripeRegionContext.SS_TEMPLATE_FUNCTION_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_OPEN);
        } else if (type == SilverStripeRegionContext.SS_TEMPLATE_FUNCTION_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_LOOP_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_LOOP_OPEN);
        } else if (type == SilverStripeRegionContext.SS_LOOP_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_LOOP_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_LOOP) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_LOOP);
        } else if (type == SilverStripeRegionContext.SS_WITH_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_WITH_OPEN);
        } else if (type == SilverStripeRegionContext.SS_WITH_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_WITH_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_WITH) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_WITH);
        } else if (type == SilverStripeRegionContext.SS_I18N_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_I18N_OPEN);
        } else if (type == SilverStripeRegionContext.SS_I18N_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_I18N_CONTENT);
        }
        
        
        // first try "standard" tag attributes from super class
        return super.getAttributeFor(region);
    }
    
    public void setSSVersion(String version) {
        this.ssVersion=version;
        
        //Reset
        this.loadColors();
        
        //Refresh
        if(getHighlighter()!=null) {
            getHighlighter().refreshDisplay();
        }
    }
    
    protected void loadColors() {
        if(getTextAttributes()!=null) {
            getTextAttributes().clear();
        }
        
        super.loadColors();

        addTextAttribute(IStyleConstantsSS.SS_DELIM);
        addTextAttribute(IStyleConstantsSS.SS_CONDITIONAL_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_CONDITIONAL_TEXT);
        addTextAttribute(IStyleConstantsSS.SS_END_IF);
        addTextAttribute(IStyleConstantsSS.SS_ELSE);
        addTextAttribute(IStyleConstantsSS.SS_BASE_TAG);
        addTextAttribute(IStyleConstantsSS.SS_COMMENT_DELIM);
        addTextAttribute(IStyleConstantsSS.SS_COMMENT_TEXT);
        addTextAttribute(IStyleConstantsSS.SS_REQUIREMENT_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_REQUIREMENT_CONTENT);
        addTextAttribute(IStyleConstantsSS.SS_INCLUDE_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_INCLUDE_CONTENT);
        addTextAttribute(IStyleConstantsSS.SS_VARIABLE);
        addTextAttribute(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_CONTENT);
        
        if(this.ssVersion.equals("SS3.0")==false) {
            addTextAttribute(IStyleConstantsSS.SS_CONTROL_OPEN);
            addTextAttribute(IStyleConstantsSS.SS_CONTROL_CONTENT);
            addTextAttribute(IStyleConstantsSS.SS_END_CONTROL);
        }else if(this.ssVersion.equals("SS3.0")) {
            addTextAttribute(IStyleConstantsSS.SS_LOOP_OPEN);
            addTextAttribute(IStyleConstantsSS.SS_LOOP_CONTENT);
            addTextAttribute(IStyleConstantsSS.SS_END_LOOP);
            addTextAttribute(IStyleConstantsSS.SS_WITH_OPEN);<commit_msg>Fixed bug 339 exception thrown when opening external ss files<commit_after>package ca.edchipman.silverstripepdt.style;


import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
import org.eclipse.wst.html.ui.internal.style.LineStyleProviderForHTML;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML;

import ca.edchipman.silverstripepdt.SilverStripePDTPlugin;
import ca.edchipman.silverstripepdt.regions.SilverStripeRegionContext;

@SuppressWarnings("restriction")
public class LineStyleProviderForSS extends LineStyleProviderForHTML {
    private IPreferenceStore preferenceStore;
    
    protected String ssVersion="SS3.0";
    
    public LineStyleProviderForSS() {
        super();
    }
    
    /**
     * a method to centralize all the "format rules" for regions 
     * specifically associated for how to "open" the region.
     */
    // NOTE: this method was just copied down form LineStyleProviderForXML
    public TextAttribute getAttributeFor(ITextRegion region) {
        // not sure why this is coming through null, but just to catch it
        if (region == null) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsXML.XML_CONTENT);
        }
        
        String type = region.getType();
        if (type == SilverStripeRegionContext.SS_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_DELIM);
        } else if (type == SilverStripeRegionContext.SS_CLOSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_DELIM);
        } else if (type == SilverStripeRegionContext.SS_CONDITIONAL_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONDITIONAL_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CONDITIONAL_TEXT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONDITIONAL_TEXT);
        } else if (type == SilverStripeRegionContext.SS_ELSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_ELSE);
        } else if (type == SilverStripeRegionContext.SS_END_IF) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_IF);
        } else if (type == SilverStripeRegionContext.SS_BASE_TAG) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_BASE_TAG);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_DELIM);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_TEXT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_TEXT);
        } else if (type == SilverStripeRegionContext.SS_COMMENT_CLOSE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_COMMENT_DELIM);
        } else if (type == SilverStripeRegionContext.SS_REQUIREMENT_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_REQUIREMENT_OPEN);
        } else if (type == SilverStripeRegionContext.SS_REQUIREMENT_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_REQUIREMENT_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_INCLUDE_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_INCLUDE_OPEN);
        } else if (type == SilverStripeRegionContext.SS_INCLUDE_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_INCLUDE_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_CONTROL_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONTROL_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CONTROL_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CONTROL_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_CONTROL) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_CONTROL);
        } else if (type == SilverStripeRegionContext.SS_VARIABLE) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_VARIABLE);
        } else if (type == SilverStripeRegionContext.SS_CACHEBLOCK_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CACHEBLOCK_OPEN);
        } else if (type == SilverStripeRegionContext.SS_CACHEBLOCK_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_CACHEBLOCK_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_CACHEBLOCK) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_CACHEBLOCK);
        } else if (type == SilverStripeRegionContext.SS_UNCACHED_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_UNCACHED_OPEN);
        } else if (type == SilverStripeRegionContext.SS_UNCACHED_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_UNCACHED_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_UNCACHED) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_UNCACHED);
        } else if (type == SilverStripeRegionContext.SS_TEMPLATE_FUNCTION_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_OPEN);
        } else if (type == SilverStripeRegionContext.SS_TEMPLATE_FUNCTION_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_LOOP_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_LOOP_OPEN);
        } else if (type == SilverStripeRegionContext.SS_LOOP_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_LOOP_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_LOOP) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_LOOP);
        } else if (type == SilverStripeRegionContext.SS_WITH_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_WITH_OPEN);
        } else if (type == SilverStripeRegionContext.SS_WITH_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_WITH_CONTENT);
        } else if (type == SilverStripeRegionContext.SS_END_WITH) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_END_WITH);
        } else if (type == SilverStripeRegionContext.SS_I18N_OPEN) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_I18N_OPEN);
        } else if (type == SilverStripeRegionContext.SS_I18N_CONTENT) {
            return (TextAttribute)getTextAttributes().get(IStyleConstantsSS.SS_I18N_CONTENT);
        }
        
        
        // first try "standard" tag attributes from super class
        return super.getAttributeFor(region);
    }
    
    public void setSSVersion(String version) {
        this.ssVersion=version;
        
        //Reset
        this.loadColors();
        
        //Refresh
        if(getHighlighter()!=null) {
            getHighlighter().refreshDisplay();
        }
    }
    
    protected void loadColors() {
        if(getTextAttributes()!=null) {
            getTextAttributes().clear();
        }
        
        super.loadColors();

        addTextAttribute(IStyleConstantsSS.SS_DELIM);
        addTextAttribute(IStyleConstantsSS.SS_CONDITIONAL_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_CONDITIONAL_TEXT);
        addTextAttribute(IStyleConstantsSS.SS_END_IF);
        addTextAttribute(IStyleConstantsSS.SS_ELSE);
        addTextAttribute(IStyleConstantsSS.SS_BASE_TAG);
        addTextAttribute(IStyleConstantsSS.SS_COMMENT_DELIM);
        addTextAttribute(IStyleConstantsSS.SS_COMMENT_TEXT);
        addTextAttribute(IStyleConstantsSS.SS_REQUIREMENT_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_REQUIREMENT_CONTENT);
        addTextAttribute(IStyleConstantsSS.SS_INCLUDE_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_INCLUDE_CONTENT);
        addTextAttribute(IStyleConstantsSS.SS_VARIABLE);
        addTextAttribute(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_OPEN);
        addTextAttribute(IStyleConstantsSS.SS_TEMPLATE_FUNCTION_CONTENT);
        
        if(this.ssVersion==null) {
            this.ssVersion="SS3.0";
        }
        
        if(this.ssVersion.equals("SS3.0")==false) {
            addTextAttribute(IStyleConstantsSS.SS_CONTROL_OPEN);
            addTextAttribute(IStyleConstantsSS.SS_CONTROL_CONTENT);
            addTextAttribute(IStyleConstantsSS.SS_END_CONTROL);
        }else if(this.ssVersion.equals("SS3.0")) {
            addTextAttribute(IStyleConstantsSS.SS_LOOP_OPEN);
            addTextAttribute(IStyleConstantsSS.SS_LOOP_CONTENT);
            addTextAttribute(IStyleConstantsSS.SS_END_LOOP);
            addTextAttribute(IStyleConstantsSS.SS_WITH_OPEN);
{'fraction_non_alphanumeric': 0.0915920716112532, 'fraction_numerical': 0.001758312020460358, 'mean_word_length': 3.834878928387429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6614846', 'n_tokens_mistral': 5408, 'n_tokens_neox': 5374, 'n_words': 704}