<commit_before>/*
 * Created on 2. feb.. 2007
 *
 * Copyright (c) 2005, <NAME> <<EMAIL> near strategoxt.org>
 * 
 * Licensed under the GNU General Public License, v2
 */
package org.spoofax.interpreter.terms;

public abstract class BasicStrategoTerm implements IStrategoTerm, Cloneable {

    private IStrategoList annotations;
    
    protected BasicStrategoTerm(IStrategoList annotations) {
        this.annotations = annotations;
    }
    
    public int getStorageType() {
        return MUTABLE; // provides no guarantees (and does not cache hashCode())
    }

    public boolean match(IStrategoTerm second) {
        return this == second || doSlowMatch(second);
    }

    protected abstract boolean doSlowMatch(IStrategoTerm second);
    
    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof IStrategoTerm))
            return false;
        return match((IStrategoTerm)obj);
    }
    
    @Override
    public abstract int hashCode();
    
    @Override
    public abstract String toString();
    
    protected void appendAnnotations(StringBuilder sb) {
        IStrategoList annos = getAnnotations();
        if (annos.size() == 0) return;
        
        sb.append('{');
        sb.append(annos.get(0));
        for (int i = 1; i < annos.size(); i++) {
            sb.append(",");
            sb.append(annos.toString());
        }
        sb.append('}');
    }
    
    protected void printAnnotations(ITermPrinter pp) {
        IStrategoList annos = getAnnotations();
        if (annos.size() == 0) return;
        
        pp.print("{");
        annos.get(0).prettyPrint(pp);
        for (int i = 1; i < annos.size(); i++) {
            pp.print(", ");
            pp.print(annos.toString());
        }
        pp.print("}");
    }
    
    @Override
    protected BasicStrategoTerm clone() {
        try {
            return (BasicStrategoTerm) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e); // silly checked exceptions...
        }
    }
    
    public IStrategoList getAnnotations() {
        return annotations == null ? BasicTermFactory.EMPTY_LIST : annotations;
    }
    
    void internalSetAnnotations(IStrategoList annotations) {
        this.annotations = annotations;<commit_msg>Fixed annotation pretty printing.<commit_after>/*
 * Created on 2. feb.. 2007
 *
 * Copyright (c) 2005, <NAME> <karltk near strategoxt.org>
 * 
 * Licensed under the GNU General Public License, v2
 */
package org.spoofax.interpreter.terms;

public abstract class BasicStrategoTerm implements IStrategoTerm, Cloneable {

    private IStrategoList annotations;
    
    protected BasicStrategoTerm(IStrategoList annotations) {
        this.annotations = annotations;
    }
    
    public int getStorageType() {
        return MUTABLE; // provides no guarantees (and does not cache hashCode())
    }

    public boolean match(IStrategoTerm second) {
        return this == second || doSlowMatch(second);
    }

    protected abstract boolean doSlowMatch(IStrategoTerm second);
    
    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof IStrategoTerm))
            return false;
        return match((IStrategoTerm)obj);
    }
    
    @Override
    public abstract int hashCode();
    
    @Override
    public abstract String toString();
    
    protected void appendAnnotations(StringBuilder sb) {
        IStrategoList annos = getAnnotations();
        if (annos.size() == 0) return;
        
        sb.append('{');
        sb.append(annos.get(0));
        for (annos = annos.tail(); !annos.isEmpty(); annos = annos.tail()) {
            sb.append(',');
            sb.append(annos.head().toString());         
        }
        sb.append('}');
    }
    
    protected void printAnnotations(ITermPrinter pp) {
        IStrategoList annos = getAnnotations();
        if (annos.size() == 0) return;
        
        pp.print("{");
        annos.head().prettyPrint(pp);
        for (annos = annos.tail(); !annos.isEmpty(); annos = annos.tail()) {
            pp.print(",");
            annos.head().prettyPrint(pp);           
        }
        pp.print("}");
    }
    
    @Override
    protected BasicStrategoTerm clone() {
        try {
            return (BasicStrategoTerm) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e); // silly checked exceptions...
        }
    }
    
    public IStrategoList getAnnotations() {
        return annotations == null ? BasicTermFactory.EMPTY_LIST : annotations;
    }
    
    void internalSetAnnotations(IStrategoList annotations) {
        this.annotations = annotations;
{'fraction_non_alphanumeric': 0.11226876461832873, 'fraction_numerical': 0.006166276844567297, 'mean_word_length': 2.2780487804878047, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, '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': '1923571', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1341, 'n_words': 324}