<commit_before>package com.redhat.ceylon.eclipse.code.outline;

import static com.redhat.ceylon.eclipse.code.complete.CodeCompletions.getQualifiedDescriptionFor;
import static com.redhat.ceylon.eclipse.code.outline.CeylonLabelProvider.getImageForDeclaration;
import static com.redhat.ceylon.eclipse.code.outline.CeylonLabelProvider.getPackageLabel;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.PARAMS_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.PARAM_TYPES_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.RETURN_TYPES_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.TYPE_PARAMS_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.ui.CeylonResources.MULTIPLE_TYPES_IMAGE;
import static com.redhat.ceylon.eclipse.util.EditorUtil.getPreferences;
import static com.redhat.ceylon.eclipse.util.Highlights.PACKAGE_STYLER;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Font;

import com.redhat.ceylon.model.typechecker.model.ClassOrInterface;
import com.redhat.ceylon.model.typechecker.model.Declaration;

abstract class CeylonHierarchyLabelProvider 
        extends StyledCellLabelProvider {
        
    @Override
    public void removeListener(ILabelProviderListener listener) {}

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void dispose() {}

    @Override
    public void addListener(ILabelProviderListener listener) {}

    Font getFont() {
        return null;
    }

    String getPrefix() {
        return null;
    }

    private StyledString getStyledText(CeylonHierarchyNode n) {
        Declaration dec = getDisplayedDeclaration(n);
        if (dec==null) {
        	return new StyledString();
        }
        IPreferenceStore prefs = getPreferences();
        StyledString result = 
                getQualifiedDescriptionFor(dec, 
                        prefs.getBoolean(TYPE_PARAMS_IN_OUTLINES),
                        prefs.getBoolean(PARAMS_IN_OUTLINES),
                        prefs.getBoolean(PARAM_TYPES_IN_OUTLINES),
                        prefs.getBoolean(RETURN_TYPES_IN_OUTLINES),
                        getPrefix(), getFont());
        /*if (d.isClassOrInterfaceMember()) {
            Declaration container = (Declaration) d.getContainer();
            result.append(" in ")
                  .append(container.getName(), Highlights.TYPE_ID_STYLER);
        }*/
        result.append(" \u2014 ", PACKAGE_STYLER)
              .append(getPackageLabel(dec), PACKAGE_STYLER);
        if (n.isNonUnique()) {
            result.append(" \u2014 and other supertypes")
                  .append(getViewInterfacesShortcut());
        }
        return result;
    }

    String getViewInterfacesShortcut() {
        return "";
    }
    
    abstract boolean isShowingRefinements();

    Declaration getDisplayedDeclaration(CeylonHierarchyNode node) {
        Declaration declaration = node.getDeclaration();
        if (declaration!=null && 
                isShowingRefinements() && 
                declaration.isClassOrInterfaceMember()) {
            declaration = 
                    (ClassOrInterface) 
                        declaration.getContainer();
        }
        return declaration;
    }
    
    @Override
    public void update(ViewerCell cell) {
        CeylonHierarchyNode n = 
                (CeylonHierarchyNode) cell.getElement();
        if (n.isMultiple()) {
            cell.setText("multiple supertypes" + 
                    getViewInterfacesShortcut());
            cell.setStyleRanges(new StyleRange[0]);
            cell.setImage(MULTIPLE_TYPES_IMAGE);
        }
        else {
            StyledString styledText = getStyledText(n);
            cell.setText(styledText.toString());
            cell.setStyleRanges(styledText.getStyleRanges());
            cell.setImage(getImageForDeclaration(
                    getDisplayedDeclaration(n),
                    n.isFocus()));
        }
        super.update(cell);
    }
}<commit_msg>better label for object expressions in hierarchy<commit_after>package com.redhat.ceylon.eclipse.code.outline;

import static com.redhat.ceylon.eclipse.code.complete.CodeCompletions.getQualifiedDescriptionFor;
import static com.redhat.ceylon.eclipse.code.outline.CeylonLabelProvider.getImageForDeclaration;
import static com.redhat.ceylon.eclipse.code.outline.CeylonLabelProvider.getPackageLabel;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.PARAMS_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.PARAM_TYPES_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.RETURN_TYPES_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.code.preferences.CeylonPreferenceInitializer.TYPE_PARAMS_IN_OUTLINES;
import static com.redhat.ceylon.eclipse.ui.CeylonResources.MULTIPLE_TYPES_IMAGE;
import static com.redhat.ceylon.eclipse.util.EditorUtil.getPreferences;
import static com.redhat.ceylon.eclipse.util.Highlights.PACKAGE_STYLER;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Font;

import com.redhat.ceylon.eclipse.util.Highlights;
import com.redhat.ceylon.model.typechecker.model.ClassOrInterface;
import com.redhat.ceylon.model.typechecker.model.Declaration;

abstract class CeylonHierarchyLabelProvider 
        extends StyledCellLabelProvider {
        
    @Override
    public void removeListener(ILabelProviderListener listener) {}

    @Override
    public boolean isLabelProperty(Object element, String property) {
        return false;
    }

    @Override
    public void dispose() {}

    @Override
    public void addListener(ILabelProviderListener listener) {}

    Font getFont() {
        return null;
    }

    String getPrefix() {
        return null;
    }

    private StyledString getStyledText(CeylonHierarchyNode n) {
        Declaration dec = getDisplayedDeclaration(n);
        if (dec==null) {
        	return new StyledString();
        }
        IPreferenceStore prefs = getPreferences();
        StyledString result;
        if (dec.isNamed()) {
            result = 
                    getQualifiedDescriptionFor(dec, 
                        prefs.getBoolean(TYPE_PARAMS_IN_OUTLINES),
                        prefs.getBoolean(PARAMS_IN_OUTLINES),
                        prefs.getBoolean(PARAM_TYPES_IN_OUTLINES),
                        prefs.getBoolean(RETURN_TYPES_IN_OUTLINES),
                        getPrefix(), getFont());
        }
        else {
            result =
                    new StyledString()
                        .append("anonymous ")
                        .append("object", Highlights.KW_STYLER)
                        .append(" expession");
        }
        /*if (d.isClassOrInterfaceMember()) {
            Declaration container = (Declaration) d.getContainer();
            result.append(" in ")
                  .append(container.getName(), Highlights.TYPE_ID_STYLER);
        }*/
        result.append(" \u2014 ", PACKAGE_STYLER)
              .append(getPackageLabel(dec), PACKAGE_STYLER);
        if (n.isNonUnique()) {
            result.append(" \u2014 and other supertypes")
                  .append(getViewInterfacesShortcut());
        }
        return result;
    }

    String getViewInterfacesShortcut() {
        return "";
    }
    
    abstract boolean isShowingRefinements();

    Declaration getDisplayedDeclaration(CeylonHierarchyNode node) {
        Declaration declaration = node.getDeclaration();
        if (declaration!=null && 
                isShowingRefinements() && 
                declaration.isClassOrInterfaceMember()) {
            declaration = 
                    (ClassOrInterface) 
                        declaration.getContainer();
        }
        return declaration;
    }
    
    @Override
    public void update(ViewerCell cell) {
        CeylonHierarchyNode n = 
                (CeylonHierarchyNode) cell.getElement();
        if (n.isMultiple()) {
            cell.setText("multiple supertypes" + 
                    getViewInterfacesShortcut());
            cell.setStyleRanges(new StyleRange[0]);
            cell.setImage(MULTIPLE_TYPES_IMAGE);
        }
        else {
            StyledString styledText = getStyledText(n);
            cell.setText(styledText.toString());
            cell.setStyleRanges(styledText.getStyleRanges());
            cell.setImage(getImageForDeclaration(
                    getDisplayedDeclaration(n),
                    n.isFocus()));
        }
        super.update(cell);
    }
}
{'fraction_non_alphanumeric': 0.08933933933933934, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 2.624174115818111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7397675', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2564, 'n_words': 386}