<commit_before>/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scala.tools.scaladoc;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;

import ch.epfl.lamp.util.Pair;

import scala.tools.util.SourceFile;

import scalac.Global;
import scalac.symtab.Scope;
import scalac.symtab.Scope.SymbolIterator;
import scalac.symtab.Symbol;
import scalac.symtab.Type;
import scalac.symtab.Modifiers;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.NameTransformer;

import java.io.*;
import scalac.ast.printer.*;
import scala.tools.scalac.ast.parser.Parser$class;
import scalac.Unit;

/**
 * This class contains functions to retrieve information from a Scala
 * library.
 */
public class ScalaSearch {

    /////////////////// SYMBOLS TESTERS ////////////////////////////

    /** Test if the given symbol is a class, a package, or an object.
     */
    static boolean isContainer(Symbol sym) {
	return sym.isClass() || sym.isModule() || sym.isPackage() || sym.isPackageClass();
    }

    /** Test if the given symbol has a lazy type.
     */
    static boolean isLazy(Symbol sym) {
	return
	    (sym.rawInfo() instanceof Type.LazyType)  ||
	    ((sym.rawInfo() instanceof Type.TypeRef)  &&
	     (sym.rawInfo().symbol().rawInfo() instanceof Type.LazyType));
    }

    /** Test if the given symbol is private (without evaluating its type).
     */
    static boolean isPrivate(Symbol sym) {
	return (sym.flags & Modifiers.PRIVATE) != 0;
    }

    /** Test if the given symbol has been generated by the compiler.
     */
    public static boolean isGenerated(Symbol sym) {
	return
	    (sym.isSynthetic() && !sym.isRoot()) ||
	    (sym.name.indexOf('$') >= 0 &&
	     NameTransformer.decode(sym.name).equals(sym.name.toString())) ||
	    NameTransformer.decode(sym.name).endsWith("_=");
    }

    /** Test if the given symbol is an empty java module generated to
     * contain static fields and methods of a java class.
     */
    public static boolean isEmptyJavaModule(Symbol sym) {
        return sym.isModule() && sym.isJava() && !(sym.isPackage() || sym.isPackageClass()) && (members(sym).length == 0);
    }

    /** Test if the given symbol is access method for a val.
     */
    public static boolean isValMethod(Symbol sym) {
        return  (sym.isInitializedMethod() && (sym.flags & Modifiers.STABLE) != 0);
    }

    /** Test if the given symbol is relevant for the documentation.
     */
    public static boolean isRelevant(Symbol sym) {
	return !isGenerated(sym) && !isLazy(sym) && !isPrivate(sym) &&
	    !sym.isConstructor() &&
            !sym.isCaseFactory() && !isEmptyJavaModule(sym);
    }

    //////////////////////// SCOPE ITERATOR //////////////////////////////

    /** A symbol iterator that returns all alternatives of an overloaded symbol
     *  instead of the overloaded symbol itself (does not unload lazy symbols).
     */
    public static class UnloadLazyIterator extends SymbolIterator {
        private SymbolIterator iterator;
        private Symbol[] alternatives;
        private int index;

        public UnloadLazyIterator(SymbolIterator iterator) {
            this.iterator = iterator;
            this.alternatives = null;
            this.index = -1;
        }

        public boolean hasNext() {
            return index >=  0 || iterator.hasNext();
        }
        public Symbol next() {
            if (index >= 0) {
                Symbol symbol = alternatives[index++];
                if (index == alternatives.length) {
                    alternatives = null;
                    index = -1;
                }
                return symbol;
            } else {<commit_msg>- I added a filter to symbols to be documented ...<commit_after>/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scala.tools.scaladoc;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;

import ch.epfl.lamp.util.Pair;

import scala.tools.util.SourceFile;

import scalac.Global;
import scalac.symtab.Scope;
import scalac.symtab.Scope.SymbolIterator;
import scalac.symtab.Symbol;
import scalac.symtab.Type;
import scalac.symtab.Modifiers;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.NameTransformer;

import java.io.*;
import scalac.ast.printer.*;
import scala.tools.scalac.ast.parser.Parser$class;
import scalac.Unit;

/**
 * This class contains functions to retrieve information from a Scala
 * library.
 */
public class ScalaSearch {

    /////////////////// SYMBOLS TESTERS ////////////////////////////

    /** Test if the given symbol is a class, a package, or an object.
     */
    static boolean isContainer(Symbol sym) {
	return sym.isClass() || sym.isModule() || sym.isPackage() || sym.isPackageClass();
    }

    /** Test if the given symbol has a lazy type.
     */
    static boolean isLazy(Symbol sym) {
	return
	    (sym.rawInfo() instanceof Type.LazyType)  ||
	    ((sym.rawInfo() instanceof Type.TypeRef)  &&
	     (sym.rawInfo().symbol().rawInfo() instanceof Type.LazyType));
    }

    /** Test if the given symbol is private (without evaluating its type).
     */
    static boolean isPrivate(Symbol sym) {
	return (sym.flags & Modifiers.PRIVATE) != 0;
    }

    /** Test if the given symbol has been generated by the compiler.
     */
    public static boolean isGenerated(Symbol sym) {
	return
	    (sym.isSynthetic() && !sym.isRoot()) ||
	    (sym.name.indexOf('$') >= 0 &&
	     NameTransformer.decode(sym.name).equals(sym.name.toString())) ||
	    NameTransformer.decode(sym.name).endsWith("_=");
    }

    /** Test if the given symbol is an empty java module generated to
     * contain static fields and methods of a java class.
     */
    public static boolean isEmptyJavaModule(Symbol sym) {
        return sym.isModule() && sym.isJava() && !(sym.isPackage() || sym.isPackageClass()) && (members(sym).length == 0);
    }

    /** Test if the given symbol is access method for a val.
     */
    public static boolean isValMethod(Symbol sym) {
        return  (sym.isInitializedMethod() && (sym.flags & Modifiers.STABLE) != 0);
    }

    /** Test if the given symbol is a phantom top-level class or object.
     */
    public static boolean isPhantom(Symbol sym) {
        return
            (sym.isClass() && sym.info().isError()) ||
            (sym.isModule() && sym.info() == Type.NoType);
    }

    /** Test if the given symbol is relevant for the documentation.
     */
    public static boolean isRelevant(Symbol sym) {
	return !isGenerated(sym) && !isLazy(sym) && !isPrivate(sym) &&
	    !sym.isConstructor() &&
            !sym.isCaseFactory() && !isEmptyJavaModule(sym) &&
            !isPhantom(sym);
    }

    //////////////////////// SCOPE ITERATOR //////////////////////////////

    /** A symbol iterator that returns all alternatives of an overloaded symbol
     *  instead of the overloaded symbol itself (does not unload lazy symbols).
     */
    public static class UnloadLazyIterator extends SymbolIterator {
        private SymbolIterator iterator;
        private Symbol[] alternatives;
        private int index;

        public UnloadLazyIterator(SymbolIterator iterator) {
            this.iterator = iterator;
            this.alternatives = null;
            this.index = -1;
        }

        public boolean hasNext() {
            return index >=  0 || iterator.hasNext();
        }
        public Symbol next() {
            if (index >= 0) {
                Symbol symbol = alternatives[index++];
                if (index == alternatives.length) {
                    alternatives = null;
                    index = -1;
                }
                return symbol;
            } else {
{'fraction_non_alphanumeric': 0.1409148519414679, 'fraction_numerical': 0.00276529554096094, 'mean_word_length': 2.022284122562674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6531695', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2383, 'n_words': 656}