<commit_before>package com4j.tlbimp.driver;

import com4j.GUID;
import com4j.COM4J;
import com4j.tlbimp.BindingException;
import com4j.tlbimp.CodeWriter;
import com4j.tlbimp.ErrorListener;
import com4j.tlbimp.Generator;
import com4j.tlbimp.ReferenceResolver;
import com4j.tlbimp.TypeLibInfo;
import com4j.tlbimp.def.IWTypeLib;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Locale;

/**
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (scm, (C) 2008, <EMAIL>)
 */
final class Driver {

    private final Map<GUID,Lib> libs = new HashMap<GUID,Lib>();

    private String packageName="";

    private Locale locale = Locale.getDefault();

    public void addLib( Lib r ) {
        libs.put(r.getLibid(),r);
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public void setLocale(String locale) {
        String[] tokens = locale.split("_");
        this.locale = new Locale(
            tokens.length>0 ? tokens[0] : "",
            tokens.length>1 ? tokens[1] : "",
            tokens.length>2 ? tokens[2] : ""
        );
    }


    public void run( CodeWriter cw, final ErrorListener el ) throws BindingException, IOException {

        final Set<IWTypeLib> libsToGen = new HashSet<IWTypeLib>();
        for (Lib lib : libs.values()) {
            libsToGen.add(COM4J.loadTypeLibrary(lib.getFile()).queryInterface(IWTypeLib.class));
        }

        ReferenceResolver resolver = new ReferenceResolver() {
            public String resolve(IWTypeLib lib) {

                GUID libid = lib.getLibid();
//                // TODO: move this to a filter
                if( libid.equals(GUID.GUID_STDOLE)){
                    return "com4j.stdole";
                }
//                if(suppress(lib)){
//                    return ""; // don't generate STDOLE. That's replaced by com4j runtime.
//                }

                if(!libsToGen.contains(lib)){
                  System.out.println("Found an referenced library: "+lib.getName());
                  try {
                    Lib l = new Lib();
                    TypeLibInfo tli = TypeLibInfo.locate(lib.getLibid(), null);
                    l.setFile(tli.typeLibrary);
                    addLib(l);
                    libsToGen.add(lib);
                  } catch (BindingException e) {
                    el.warning(Messages.COULDNT_LOCATE_REFERENCED_TYPELIB.format(lib.getName()));
                    e.printStackTrace();
                    el.warning(Messages.REFERENCED_TYPELIB_GENERATED.format(lib.getName(),packageName));
                    libsToGen.add(lib);
                  }
                }

                if( libs.containsKey(libid) ) {
                    String pkg = libs.get(libid).getPackage();
                    if(pkg!=null)
                        return packageName + "." + pkg;
                }

//                if( libsToGen.add(lib) )
//                    el.warning(Messages.REFERENCED_TYPELIB_GENERATED.format(lib.getName(),packageName));

                return packageName;
            }

            public boolean suppress(IWTypeLib lib) {
                GUID libid = lib.getLibid();

                if( libid.equals(GUID.GUID_STDOLE))
                    return true;

                Lib r = libs.get(libid);
                if(r!=null)
                    return r.suppress();
                else
                    return false;
            }
        };
<commit_msg>BugFix: If the prefix packageName was empty, the resulting package names started with an dot.<commit_after>package com4j.tlbimp.driver;

import com4j.GUID;
import com4j.COM4J;
import com4j.tlbimp.BindingException;
import com4j.tlbimp.CodeWriter;
import com4j.tlbimp.ErrorListener;
import com4j.tlbimp.Generator;
import com4j.tlbimp.ReferenceResolver;
import com4j.tlbimp.TypeLibInfo;
import com4j.tlbimp.def.IWTypeLib;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Locale;

/**
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (scm, (C) 2008, <EMAIL>)
 */
final class Driver {

    private final Map<GUID,Lib> libs = new HashMap<GUID,Lib>();

    private String packageName="";

    private Locale locale = Locale.getDefault();

    public void addLib( Lib r ) {
        libs.put(r.getLibid(),r);
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public void setLocale(String locale) {
        String[] tokens = locale.split("_");
        this.locale = new Locale(
            tokens.length>0 ? tokens[0] : "",
            tokens.length>1 ? tokens[1] : "",
            tokens.length>2 ? tokens[2] : ""
        );
    }


    public void run( CodeWriter cw, final ErrorListener el ) throws BindingException, IOException {

        final Set<IWTypeLib> libsToGen = new HashSet<IWTypeLib>();
        for (Lib lib : libs.values()) {
            libsToGen.add(COM4J.loadTypeLibrary(lib.getFile()).queryInterface(IWTypeLib.class));
        }

        ReferenceResolver resolver = new ReferenceResolver() {
            public String resolve(IWTypeLib lib) {

                GUID libid = lib.getLibid();
//                // TODO: move this to a filter
                if( libid.equals(GUID.GUID_STDOLE)){
                    return "com4j.stdole";
                }
//                if(suppress(lib)){
//                    return ""; // don't generate STDOLE. That's replaced by com4j runtime.
//                }

                if(!libsToGen.contains(lib)){
                  System.out.println("Found an referenced library: "+lib.getName());
                  try {
                    Lib l = new Lib();
                    TypeLibInfo tli = TypeLibInfo.locate(lib.getLibid(), null);
                    l.setFile(tli.typeLibrary);
                    addLib(l);
                    libsToGen.add(lib);
                  } catch (BindingException e) {
                    el.warning(Messages.COULDNT_LOCATE_REFERENCED_TYPELIB.format(lib.getName()));
                    e.printStackTrace();
                    el.warning(Messages.REFERENCED_TYPELIB_GENERATED.format(lib.getName(),packageName));
                    libsToGen.add(lib);
                  }
                }

                if (libs.containsKey(libid)) {
                  String pkg = libs.get(libid).getPackage();
                  if (pkg != null) {
                    if (packageName != null && !packageName.isEmpty()) {
                      return packageName + "." + pkg;
                    } else {
                      return pkg;
                    }
                  }
                }

//                if( libsToGen.add(lib) )
//                    el.warning(Messages.REFERENCED_TYPELIB_GENERATED.format(lib.getName(),packageName));

                return packageName;
            }

            public boolean suppress(IWTypeLib lib) {
                GUID libid = lib.getLibid();

                if( libid.equals(GUID.GUID_STDOLE))
                    return true;

                Lib r = libs.get(libid);
                if(r!=null)
                    return r.suppress();
                else
                    return false;
            }
        };

{'fraction_non_alphanumeric': 0.11292517006802721, 'fraction_numerical': 0.006530612244897959, 'mean_word_length': 1.6750363901018923, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '3302209', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2047, 'n_words': 415}