<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

process.on('unhandledRejection', function(e) {
  console.error("ERROR: Unhandled promise rejection ", e);
  process.exit(1);
});

// Same as genjava.js but doesn't copy source files.

// enable FOAM java support.
global.FOAM_FLAGS = { 'java': true, 'debug': true, 'js': false };

require('../src/foam.js');
require('../src/foam/nanos/nanos.js');

var srcPath = __dirname + "/../src/";

if ( ! (process.argv.length == 4 || process.argv.length == 5) ) {
  console.log("USAGE: genjava.js input-path output-path src-path(optional)");
  process.exit(1);
}

if ( process.argv.length == 5 ) {
  srcPath = process.argv[4];
  if ( ! srcPath.endsWith('/') ) {
    srcPath = srcPath + '/';
  }
}

var path_ = require('path');
var fs_ = require('fs');

srcPath = path_.resolve(srcPath);

var indir = process.argv[2];
indir = path_.resolve(path_.normalize(indir));

var externalFile = require(indir);
var classes = externalFile.classes;
var abstractClasses = externalFile.abstractClasses;
var skeletons = externalFile.skeletons;
var proxies = externalFile.proxies;

var blacklist = {
  'FObject': true,
  'foam.core.AbstractEnum': true,
  'foam.core.AbstractInterface': true,
  'foam.core.Property': true,
  'foam.core.String': true,

  // These have hand written java impls so we don't want to clobber them.
  // TODO: Change gen.sh to prefer hand written java files over generated.
  'foam.dao.AbstractDAO': true,
  'foam.dao.FilteredDAO': true,
  'foam.dao.LimitedDAO': true,
  'foam.dao.NullDAO': true,
  'foam.dao.OrderedDAO': true,
  'foam.dao.SkipDAO': true,
  'foam.box.Context': true,
  'foam.box.HTTPBox': true,
  'foam.box.SessionClientBox': true,
  'foam.box.SocketBox': true,
  'foam.box.WebSocketBox': true,
  'foam.box.TimeoutBox': true,
  'foam.box.RetryBox': true,
  'foam.dao.CachingDAO': true,
  'foam.dao.CompoundDAODecorator': true,
  'foam.dao.ContextualizingDAO': true,
  'foam.dao.DecoratedDAO': true,
  'foam.dao.DeDupDAO': true,
  'foam.dao.GUIDDAO': true,
  'foam.dao.IDBDAO': true,
  'foam.dao.JDAO': true,
  'foam.dao.LoggingDAO': true,
  'foam.dao.MDAO': true,
  'foam.dao.PromisedDAO': true,
  'foam.dao.RequestResponseClientDAO': true,
  'foam.dao.SequenceNumberDAO': true,
  'foam.dao.SyncDAO': true,
  'foam.dao.TimingDAO': true,

  // TODO: These models currently don't compile in java but could be updated to
  // compile properly.
  'foam.blob.BlobBlob': true,
  'foam.dao.CompoundDAODecorator': true,
  'foam.dao.DAODecorator': true,
  'foam.dao.FlowControl': true,
  'foam.dao.PromisedDAO': true,
  'foam.dao.sync.SyncRecord': true,
  'foam.dao.sync.VersionedSyncRecord': true,
  'foam.mlang.order.ThenBy': true,
  'foam.mlang.Expressions': true,
  'foam.nanos.menu.MenuBar': true
};

externalFile.blacklist.forEach(function(cls) {
  blacklist[cls] = true;
});

var outdir = process.argv[3];
outdir = path_.resolve(path_.normalize(outdir));

function ensurePath(p) {
  var i = 1 ;
  var parts = p.split(path_.sep);
  var path = '/' + parts[0];

  while ( i < parts.length ) {
    try {
      var stat = fs_.statSync(path);
      if ( ! stat.isDirectory() ) throw path + 'is not a directory';
    } catch(e) {
      fs_.mkdirSync(path);
    }

    path += path_.sep + parts[i++];
  }
}

function loadClass(c) {
  var path = srcPath;

  if ( foam.Array.isInstance(c) ) {
    path = path + c[0];
    c = c[1];
  }
  if ( ! foam.lookup(c, true) ) require(path + c.replace(/\./g, '/') + '.js');
  return foam.lookup(c);
}

function generateClass(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  if ( typeof cls === 'string' )
    cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.id.replace(/\./g, path_.sep) + '.java';

  ensurePath(outfile);

  writeFileIfUpdated(outfile, cls.buildJavaClass().toJavaSource());
}

function generateAbstractClass(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.id.replace(/\./g, path_.sep) + '.java';

  ensurePath(outfile);

  var javaclass = cls.buildJavaClass(foam.java.Class.create({ abstract: true });

  writeFileIfUpdated(outfile, javaclass.toJavaSource());
}

function generateSkeleton(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.package.replace(/\./g, path_.sep) +
    path_.sep + cls.name + 'Skeleton.java';

  ensurePath(outfile);

  writeFileIfUpdated(outfile, foam.java.Skeleton.create({ of: cls }).buildJavaClass().toJavaSource());
}

function generateProxy(intf) {
  if ( foam.Array.isInstance(intf) ) {
    intf = intf[1];
  }
  intf = foam.lookup(intf);

  var existing = foam.lookup(intf.package + '.Proxy' + intf.name, true);

  if ( existing ) {
    generateClass(existing.id);<commit_msg>Fix genjava2.<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

process.on('unhandledRejection', function(e) {
  console.error("ERROR: Unhandled promise rejection ", e);
  process.exit(1);
});

// Same as genjava.js but doesn't copy source files.

// enable FOAM java support.
global.FOAM_FLAGS = { 'java': true, 'debug': true, 'js': false };

require('../src/foam.js');
require('../src/foam/nanos/nanos.js');

var srcPath = __dirname + "/../src/";

if ( ! (process.argv.length == 4 || process.argv.length == 5) ) {
  console.log("USAGE: genjava.js input-path output-path src-path(optional)");
  process.exit(1);
}

if ( process.argv.length == 5 ) {
  srcPath = process.argv[4];
  if ( ! srcPath.endsWith('/') ) {
    srcPath = srcPath + '/';
  }
}

var path_ = require('path');
var fs_ = require('fs');

srcPath = path_.resolve(srcPath);

var indir = process.argv[2];
indir = path_.resolve(path_.normalize(indir));

var externalFile = require(indir);
var classes = externalFile.classes;
var abstractClasses = externalFile.abstractClasses;
var skeletons = externalFile.skeletons;
var proxies = externalFile.proxies;

var blacklist = {
  'FObject': true,
  'foam.core.AbstractEnum': true,
  'foam.core.AbstractInterface': true,
  'foam.core.Property': true,
  'foam.core.String': true,

  // These have hand written java impls so we don't want to clobber them.
  // TODO: Change gen.sh to prefer hand written java files over generated.
  'foam.dao.AbstractDAO': true,
  'foam.dao.FilteredDAO': true,
  'foam.dao.LimitedDAO': true,
  'foam.dao.NullDAO': true,
  'foam.dao.OrderedDAO': true,
  'foam.dao.SkipDAO': true,
  'foam.box.Context': true,
  'foam.box.HTTPBox': true,
  'foam.box.SessionClientBox': true,
  'foam.box.SocketBox': true,
  'foam.box.WebSocketBox': true,
  'foam.box.TimeoutBox': true,
  'foam.box.RetryBox': true,
  'foam.dao.CachingDAO': true,
  'foam.dao.CompoundDAODecorator': true,
  'foam.dao.ContextualizingDAO': true,
  'foam.dao.DecoratedDAO': true,
  'foam.dao.DeDupDAO': true,
  'foam.dao.GUIDDAO': true,
  'foam.dao.IDBDAO': true,
  'foam.dao.JDAO': true,
  'foam.dao.LoggingDAO': true,
  'foam.dao.MDAO': true,
  'foam.dao.PromisedDAO': true,
  'foam.dao.RequestResponseClientDAO': true,
  'foam.dao.SequenceNumberDAO': true,
  'foam.dao.SyncDAO': true,
  'foam.dao.TimingDAO': true,

  // TODO: These models currently don't compile in java but could be updated to
  // compile properly.
  'foam.blob.BlobBlob': true,
  'foam.dao.CompoundDAODecorator': true,
  'foam.dao.DAODecorator': true,
  'foam.dao.FlowControl': true,
  'foam.dao.PromisedDAO': true,
  'foam.dao.sync.SyncRecord': true,
  'foam.dao.sync.VersionedSyncRecord': true,
  'foam.mlang.order.ThenBy': true,
  'foam.mlang.Expressions': true,
  'foam.nanos.menu.MenuBar': true
};

externalFile.blacklist.forEach(function(cls) {
  blacklist[cls] = true;
});

var outdir = process.argv[3];
outdir = path_.resolve(path_.normalize(outdir));

function ensurePath(p) {
  var i = 1 ;
  var parts = p.split(path_.sep);
  var path = '/' + parts[0];

  while ( i < parts.length ) {
    try {
      var stat = fs_.statSync(path);
      if ( ! stat.isDirectory() ) throw path + 'is not a directory';
    } catch(e) {
      fs_.mkdirSync(path);
    }

    path += path_.sep + parts[i++];
  }
}

function loadClass(c) {
  var path = srcPath;

  if ( foam.Array.isInstance(c) ) {
    path = path + c[0];
    c = c[1];
  }
  if ( ! foam.lookup(c, true) ) require(path + c.replace(/\./g, '/') + '.js');
  return foam.lookup(c);
}

function generateClass(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  if ( typeof cls === 'string' )
    cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.id.replace(/\./g, path_.sep) + '.java';

  ensurePath(outfile);

  writeFileIfUpdated(outfile, cls.buildJavaClass().toJavaSource());
}

function generateAbstractClass(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.id.replace(/\./g, path_.sep) + '.java';

  ensurePath(outfile);

  var javaclass = cls.buildJavaClass(foam.java.Class.create({ abstract: true }));

  writeFileIfUpdated(outfile, javaclass.toJavaSource());
}

function generateSkeleton(cls) {
  if ( foam.Array.isInstance(cls) ) {
    cls = cls[1];
  }
  cls = foam.lookup(cls);

  var outfile = outdir + path_.sep +
    cls.package.replace(/\./g, path_.sep) +
    path_.sep + cls.name + 'Skeleton.java';

  ensurePath(outfile);

  writeFileIfUpdated(outfile, foam.java.Skeleton.create({ of: cls }).buildJavaClass().toJavaSource());
}

function generateProxy(intf) {
  if ( foam.Array.isInstance(intf) ) {
    intf = intf[1];
  }
  intf = foam.lookup(intf);

  var existing = foam.lookup(intf.package + '.Proxy' + intf.name, true);

  if ( existing ) {
    generateClass(existing.id);
{'fraction_non_alphanumeric': 0.17405416370828686, 'fraction_numerical': 0.004564357439902627, 'mean_word_length': 3.613944782405241, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6673125', 'n_tokens_mistral': 3776, 'n_tokens_neox': 3764, 'n_words': 726}