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

// $Id$

package scalac.symtab.classfile;

import java.util.Iterator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;

import scala.tools.util.AbstractFile;

import scalac.Global;
import scalac.symtab.Scope;
import scalac.symtab.SourceCompleter;
import scalac.symtab.Symbol;
import scalac.symtab.SymbolLoader;
import scalac.symtab.Type;
import scalac.util.Name;
import scalac.util.Debug;

/**
 * This class implements a package member loader. It can be used to
 * complete package class symbols.
 */
public class PackageParser extends SymbolLoader {

    //########################################################################
    // Protected Fields

    /** The directory to read */
    protected final AbstractFile directory;

    /** A table to collect .scala files */
    protected final HashMap/*<String,AbstractFile>*/ sources = new HashMap();
    /** A table to collect .symbl files */
    protected final HashMap/*<String,AbstractFile>*/ symbols = new HashMap();
    /** A table to collect .class files */
    protected final HashMap/*<String,AbstractFile>*/ classes = new HashMap();
    /** A table to collect subdirectories */
    protected final HashMap/*<String,AbstractFile>*/ packages = new HashMap();

    //########################################################################
    // Public Constructors

    /** Initializes this instance. */
    public PackageParser(Global global, AbstractFile directory) {
        super(global);
        this.directory = directory;
        assert directory != null;
    }

    //########################################################################
    // Protected Methods

    /** Returns a new package parser for the given directory. */
    protected PackageParser newPackageParser(AbstractFile directory) {
        return new PackageParser(global, directory);
    }

    /**
     * Collects all members of the package. This method is invoked by
     * method "doComplete". It should not be invoked otherwise.
     */
    protected void collectAllMembers(Symbol clasz) {
        for (Iterator i = directory.list(); i.hasNext(); ) {
            AbstractFile file = (AbstractFile)i.next();
            String filename = file.getName();
            if (file.isDirectory()) {
                if (filename.equals("META-INF")) continue;
                packages.put(filename, file);
                continue;
            }
            if (filename.endsWith(".class")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!classes.containsKey(name)) classes.put(name, file);
                continue;
            }
            if (filename.endsWith(".symbl")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!symbols.containsKey(name)) symbols.put(name, file);
                continue;
            }
            if (filename.endsWith(".scala")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!sources.containsKey(name)) sources.put(name, file);
                continue;
            }
	}
    }

    /**
     * Removes from the members collected by "collectAllMembers" all
     * those that are hidden. This method is invoked by method
     * "doComplete". It should not be invoked otherwise.
     */<commit_msg>- Added method isValidName<commit_after>/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

package scalac.symtab.classfile;

import java.util.Iterator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;

import scala.tools.util.AbstractFile;

import scalac.Global;
import scalac.symtab.Scope;
import scalac.symtab.SourceCompleter;
import scalac.symtab.Symbol;
import scalac.symtab.SymbolLoader;
import scalac.symtab.Type;
import scalac.util.Name;
import scalac.util.Debug;

/**
 * This class implements a package member loader. It can be used to
 * complete package class symbols.
 */
public class PackageParser extends SymbolLoader {

    //########################################################################
    // Protected Fields

    /** The directory to read */
    protected final AbstractFile directory;

    /** A table to collect .scala files */
    protected final HashMap/*<String,AbstractFile>*/ sources = new HashMap();
    /** A table to collect .symbl files */
    protected final HashMap/*<String,AbstractFile>*/ symbols = new HashMap();
    /** A table to collect .class files */
    protected final HashMap/*<String,AbstractFile>*/ classes = new HashMap();
    /** A table to collect subdirectories */
    protected final HashMap/*<String,AbstractFile>*/ packages = new HashMap();

    //########################################################################
    // Public Constructors

    /** Initializes this instance. */
    public PackageParser(Global global, AbstractFile directory) {
        super(global);
        this.directory = directory;
        assert directory != null;
    }

    //########################################################################
    // Protected Methods

    /** Is the given name a valid input file base name? */
    protected boolean isValidName(String name) {
        return name.length() > 0
            &&!name.endsWith("$class")
            && name.indexOf("$$anon") == -1;
    }

    /** Returns a new package parser for the given directory. */
    protected PackageParser newPackageParser(AbstractFile directory) {
        return new PackageParser(global, directory);
    }

    /**
     * Collects all members of the package. This method is invoked by
     * method "doComplete". It should not be invoked otherwise.
     */
    protected void collectAllMembers(Symbol clasz) {
        for (Iterator i = directory.list(); i.hasNext(); ) {
            AbstractFile file = (AbstractFile)i.next();
            String filename = file.getName();
            if (file.isDirectory()) {
                if (filename.equals("META-INF")) continue;
                packages.put(filename, file);
                continue;
            }
            if (filename.endsWith(".class")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!isValidName(name)) continue;
                if (!classes.containsKey(name)) classes.put(name, file);
                continue;
            }
            if (filename.endsWith(".symbl")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!isValidName(name)) continue;
                if (!symbols.containsKey(name)) symbols.put(name, file);
                continue;
            }
            if (filename.endsWith(".scala")) {
                String name = filename.substring(0, filename.length() - 6);
                if (!isValidName(name)) continue;
                if (!sources.containsKey(name)) sources.put(name, file);
                continue;
            }
	}
    }

    /**
     * Removes from the members collected by "collectAllMembers" all
     * those that are hidden. This method is invoked by method
     * "doComplete". It should not be invoked otherwise.
     */
{'fraction_non_alphanumeric': 0.16575638257335196, 'fraction_numerical': 0.0027943604725009525, 'mean_word_length': 2.104889589905363, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '3743267', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1911, 'n_words': 536}