<commit_before>import sublime, sublime_plugin
import subprocess
import tempfile
import os
import xml.parsers.expat
import re
import codecs
import glob
import hashlib
import shutil
from xml.etree import ElementTree
from subprocess import Popen, PIPE

try:
    STARTUP_INFO = subprocess.STARTUPINFO()
    STARTUP_INFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    STARTUP_INFO.wShowWindow = subprocess.SW_HIDE
except (AttributeError):
	STARTUP_INFO = None


compilerOutput = re.compile("^([^:]+):([0-9]+): characters? ([0-9]+)-?([0-9]+)? : (.*)", re.M)
packageLine = re.compile("package ([a-z_.]*);")
compactFunc = re.compile("\(.*\)")
compactProp = re.compile(":.*\.([a-z_0-9]+)", re.I)
spaceChars = re.compile("\s")
wordChars = re.compile("[a-z0-9._]", re.I)
importLine = re.compile("^([ \t]*)import\s+([a-z0-9._]+)", re.I | re.M)
packageLine = re.compile("package\s*[a-z0-9.]*;", re.I)

inst = None
class HaxeBuild :

	#auto = None

	def __init__(self) :

		self.args = []
		self.main = "Main"
		self.target = "js"
		self.output = "dummy.js"
		self.hxml = None
		self.classpaths = []

	def to_string(self) :
		out = os.path.basename(self.output)
		return "{out}".format(self=self, out=out);
		#return "{self.main} {self.target}:{out}".format(self=self, out=out);
	
	def make_hxml( self ) :
		outp = "# Autogenerated "+self.hxml+"\n\n"
		outp += "# "+self.to_string() + "\n"
		outp += "-main "+ self.main + "\n"
		for a in self.args :
			outp += " ".join( list(a) ) + "\n"
		
		d = os.path.dirname( self.hxml ) + "/"
		
		# relative paths
		outp = outp.replace( d , "")
		outp = outp.replace( "-cp "+os.path.dirname( self.hxml )+"\n", "")

		outp = outp.replace("--no-output " , "")
		outp = outp.replace("-v" , "")

		outp = outp.replace("dummy" , self.main.lower() )

		#print( outp )
		return outp.strip()


class HaxeGenerateImport( sublime_plugin.TextCommand ):

	start = None
	size = None
	cname = None

	def get_end( self, src, offset ) :
		end = len(src)
		while offset < end:
			c = src[offset]
			offset += 1
			if not wordChars.match(c): break
		return offset - 1

	def get_start( self, src, offset ) :
		foundWord = 0;
		while offset > 0:
			c = src[offset]
			offset -= 1
			if foundWord == 0:
				if not wordChars.match(c): continue
				foundWord = 1
			if not wordChars.match(c): break
		return offset + 2
	
	def get_classname( self, view, src ) :
		loc = view.sel()[0]
		end = max(loc.a, loc.b)
		self.size = loc.size()
		if self.size == 0:
			end = self.get_end(src, end)
			self.start = self.get_start(src, end)
			self.size = end - self.start
		else:
			self.start = end - self.size
		self.cname = view.substr(sublime.Region(self.start, end)).rpartition(".")

	def compact_classname( self, edit, view ) :
		view.replace(edit, sublime.Region(self.start, self.start+self.size), self.cname[2])
		view.sel().clear()
		loc = self.start + len(self.cname[2])
		view.sel().add(sublime.Region(loc, loc))

	def get_indent( self, src, index ) :
		if src[index] == "\n": return index + 1
		return index

	def insert_import( self, edit, view, src) :
		cname = "".join(self.cname)
		clow = cname.lower()
		last = None

		for imp in importLine.finditer(src):
			if clow < imp.group(2).lower():
				print(imp.group(0))
				ins = "{0}import {1};\n".format(imp.group(1), cname)
				view.insert(edit, self.get_indent(src, imp.start(0)), ins)
				return
			last = imp

		if not last is None:
			ins = ";\n{0}import {1}".format(last.group(1), cname)
			view.insert(edit, last.end(2), ins)
		else:
			pkg = packageLine.search(src)
			if not pkg is None:
				ins = "\n\nimport {0};".format(cname)
				view.insert(edit, pkg.end(0), ins)

	def run( self , edit ) :
		complete = HaxeComplete.inst
		view = self.view
		src = view.substr(sublime.Region(0, view.size()))
		self.get_classname(view, src)
		
		if self.cname[1] == "": 
			sublime.status_message("Nothing to import")
			return

		self.compact_classname(edit, view)

		if re.search("import\s+{0}".format("".join(self.cname)), src):<commit_msg>recognize static access when generating import<commit_after>import sublime, sublime_plugin
import subprocess
import tempfile
import os
import xml.parsers.expat
import re
import codecs
import glob
import hashlib
import shutil
from xml.etree import ElementTree
from subprocess import Popen, PIPE

try:
    STARTUP_INFO = subprocess.STARTUPINFO()
    STARTUP_INFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    STARTUP_INFO.wShowWindow = subprocess.SW_HIDE
except (AttributeError):
	STARTUP_INFO = None


compilerOutput = re.compile("^([^:]+):([0-9]+): characters? ([0-9]+)-?([0-9]+)? : (.*)", re.M)
packageLine = re.compile("package ([a-z_.]*);")
compactFunc = re.compile("\(.*\)")
compactProp = re.compile(":.*\.([a-z_0-9]+)", re.I)
spaceChars = re.compile("\s")
wordChars = re.compile("[a-z0-9._]", re.I)
importLine = re.compile("^([ \t]*)import\s+([a-z0-9._]+)", re.I | re.M)
packageLine = re.compile("package\s*[a-z0-9.]*;", re.I)

inst = None
class HaxeBuild :

	#auto = None

	def __init__(self) :

		self.args = []
		self.main = "Main"
		self.target = "js"
		self.output = "dummy.js"
		self.hxml = None
		self.classpaths = []

	def to_string(self) :
		out = os.path.basename(self.output)
		return "{out}".format(self=self, out=out);
		#return "{self.main} {self.target}:{out}".format(self=self, out=out);
	
	def make_hxml( self ) :
		outp = "# Autogenerated "+self.hxml+"\n\n"
		outp += "# "+self.to_string() + "\n"
		outp += "-main "+ self.main + "\n"
		for a in self.args :
			outp += " ".join( list(a) ) + "\n"
		
		d = os.path.dirname( self.hxml ) + "/"
		
		# relative paths
		outp = outp.replace( d , "")
		outp = outp.replace( "-cp "+os.path.dirname( self.hxml )+"\n", "")

		outp = outp.replace("--no-output " , "")
		outp = outp.replace("-v" , "")

		outp = outp.replace("dummy" , self.main.lower() )

		#print( outp )
		return outp.strip()


class HaxeGenerateImport( sublime_plugin.TextCommand ):

	start = None
	size = None
	cname = None

	def get_end( self, src, offset ) :
		end = len(src)
		while offset < end:
			c = src[offset]
			offset += 1
			if not wordChars.match(c): break
		return offset - 1

	def get_start( self, src, offset ) :
		foundWord = 0;
		while offset > 0:
			c = src[offset]
			offset -= 1
			if foundWord == 0:
				if not wordChars.match(c): continue
				foundWord = 1
			if not wordChars.match(c): break
		return offset + 2
	
	def is_membername( self, token ) :
		return token[0] >= "Z" or token == token.upper()

	def get_classname( self, view, src ) :
		loc = view.sel()[0]
		end = max(loc.a, loc.b)
		self.size = loc.size()
		if self.size == 0:
			end = self.get_end(src, end)
			self.start = self.get_start(src, end)
			self.size = end - self.start
		else:
			self.start = end - self.size

		self.cname = view.substr(sublime.Region(self.start, end)).rpartition(".")
		while not self.cname[0] == "" and self.is_membername(self.cname[2]):
			self.size -= 1 + len(self.cname[2])
			self.cname = self.cname[0].rpartition(".")

	def compact_classname( self, edit, view ) :
		view.replace(edit, sublime.Region(self.start, self.start+self.size), self.cname[2])
		view.sel().clear()
		loc = self.start + len(self.cname[2])
		view.sel().add(sublime.Region(loc, loc))

	def get_indent( self, src, index ) :
		if src[index] == "\n": return index + 1
		return index

	def insert_import( self, edit, view, src) :
		cname = "".join(self.cname)
		clow = cname.lower()
		last = None

		for imp in importLine.finditer(src):
			if clow < imp.group(2).lower():
				ins = "{0}import {1};\n".format(imp.group(1), cname)
				view.insert(edit, self.get_indent(src, imp.start(0)), ins)
				return
			last = imp

		if not last is None:
			ins = ";\n{0}import {1}".format(last.group(1), cname)
			view.insert(edit, last.end(2), ins)
		else:
			pkg = packageLine.search(src)
			if not pkg is None:
				ins = "\n\nimport {0};".format(cname)
				view.insert(edit, pkg.end(0), ins)

	def run( self , edit ) :
		complete = HaxeComplete.inst
		view = self.view
		src = view.substr(sublime.Region(0, view.size()))
		self.get_classname(view, src)
		
		if self.cname[1] == "": 
			sublime.status_message("Nothing to import")
			return

		self.compact_classname(edit, view)

		if re.search("import\s+{0}".format("".join(self.cname)), src):
{'fraction_non_alphanumeric': 0.18166383701188454, 'fraction_numerical': 0.010793111811787534, 'mean_word_length': 3.436256051640667, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '3461738', 'n_tokens_mistral': 3512, 'n_tokens_neox': 3142, 'n_words': 707}