Kouksi44

signature

Mar 11th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 KB | None | 0 0
  1. local ACC_FLAGS = {
  2.   ["ACC_PUBLIC"] = 0;
  3.   ["ACC_PRIVATE"] = 1;
  4.   ["ACC_FINAL"] = 2;
  5.   ["ACC_STATIC"] = 3;
  6.   ["ACC_SYNTHETIC"] = 4;
  7.   ["ACC_PROPERTY"] = 14;
  8.   ["ACC_ASYNC"] = 15;
  9. }
  10.  
  11. local NATIVE_TYPES = {
  12.   ["number"] = 5;
  13.   ["table"] = 6;
  14.   ["thread"] = 7;
  15.   ["function"] = 8;
  16.   ["string"] = 9;
  17.   ["boolean"] = 10;
  18.   ["void"] = 11;
  19.   ["object"] = 12;
  20.   ["generic"] = 13;
  21. }
  22.  
  23. local resolve = function(annotations,sig)
  24.   local resolved = {}
  25.   for i=1,#(annotations or {}) do
  26.     if annotations[i] == "public"    then resolved[ACC_FLAGS.ACC_PUBLIC]    = true end
  27.     if annotations[i] == "private"   then resolved[ACC_FLAGS.ACC_PRIVATE]   = true end
  28.     if annotations[i] == "final"     then resolved[ACC_FLAGS.ACC_FINAL]     = true end
  29.     if annotations[i] == "static"    then resolved[ACC_FLAGS.ACC_STATIC]    = true end
  30.     if annotations[i] == "synthetic" then resolved[ACC_FLAGS.ACC_SYNTHETIC] = true end
  31.     if annotations[i] == "property"  then resolved[ACC_FLAGS.ACC_PROPERTY]  = true end
  32.     if annotations[i] == "async"     then resolved[ACC_FLAGS.ACC_ASYNC]     = true end
  33.  
  34.     if annotations[i] == "number"    then resolved[NATIVE_TYPES.number]   = true sig.fieldType = "number"   end
  35.     if annotations[i] == "Table"     then resolved[NATIVE_TYPES.table]    = true sig.fieldType = "table"    end
  36.     if annotations[i] == "thread"    then resolved[NATIVE_TYPES.thread]   = true sig.fieldType = "thread"   end
  37.     if annotations[i] == "String"    then resolved[NATIVE_TYPES.string]   = true sig.fieldType = "string"   end
  38.     if annotations[i] == "function"  then resolved[NATIVE_TYPES.Function] = true sig.fieldType = "function" end
  39.     if annotations[i] == "boolean"   then resolved[NATIVE_TYPES.boolean]  = true sig.fieldType = "boolean"  end
  40.     if annotations[i] == "void"      then resolved[NATIVE_TYPES.void]     = true sig.fieldType = "void"     end
  41.     if annotations[i] == "object"    then resolved[NATIVE_TYPES.object]   = true sig.fieldType = "object"   end
  42.     if annotations[i] == "generic"   then resolved[NATIVE_TYPES.generic]  = true sig.fieldType = "generic"  end
  43.   end
  44.  
  45.   if (not resolved[0]) and (not resolved[1]) then
  46.     resolved[0] = true
  47.   end
  48.   return resolved
  49. end
  50.  
  51.  
  52.  
  53. local signature = function(class,id,annotations,value,_type,objType)
  54.   local sig = {}
  55.       sig.class       = class
  56.       sig.name        = id
  57.       sig.value       = value
  58.       sig.type = _type
  59.       sig.fieldType = nil
  60.       sig.objType = objType
  61.       sig.settable = false
  62.       sig.gettable = false
  63.       sig.annotations = resolve(annotations,sig)
  64.       sig.toPath = function() -- order: public | private | static | final
  65.         local p = "/"
  66.         if sig.annotations[ACC_FLAGS.ACC_PUBLIC]  then p = p.."public/"  end
  67.         if sig.annotations[ACC_FLAGS.ACC_PRIVATE] then p = p.."private/" end
  68.         if sig.annotations[ACC_FLAGS.ACC_STATIC]  then p = p.."static/"  end
  69.         if sig.annotations[ACC_FLAGS.ACC_FINAL]   then p = p.."final/"   end
  70.         return p
  71.       end
  72.       sig.public = function()
  73.         return (sig.annotations[ACC_FLAGS.ACC_PUBLIC] or (sig.annotations[ACC_FLAGS.ACC_PUBLIC] == nil and sig.annotations[ACC_FLAGS.ACC_PRIVATE] == nil and
  74.                 sig.annotations[ACC_FLAGS.ACC_STATIC] == nil and sig.annotations[ACC_FLAGS.ACC_FINAL] == nil))
  75.       end
  76.       sig.private = function()
  77.         return (sig.annotations[ACC_FLAGS.ACC_PRIVATE] == true)
  78.       end
  79.       sig.static = function()
  80.         return (sig.annotations[ACC_FLAGS.ACC_STATIC] == true)
  81.       end
  82.       sig.final = function()
  83.         return sig.annotations[ACC_FLAGS.ACC_FINAL] == true
  84.       end
  85.       sig.generic = function()
  86.         return sig.annotations[NATIVE_TYPES.generic] == true
  87.       end
  88.       sig.property = function()
  89.         return sig.annotations[ACC_FLAGS.ACC_PROPERTY] == true
  90.       end
  91.       sig.hasType = function()
  92.         return sig.fieldType ~= nil
  93.       end
  94.       sig.getType = function()
  95.         return sig.fieldType
  96.       end
  97.       sig.setType = function(t)
  98.         sig.fieldType = t
  99.       end
  100.       sig.async = function()
  101.         return sig.annotations[ACC_FLAGS.ACC_ASYNC] == true
  102.       end
  103.  
  104.   return sig
  105. end
  106.  
  107. return signature
Advertisement
Add Comment
Please, Sign In to add comment