Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.68 KB | None | 0 0
  1.         var meta = null;
  2.         if (Context.getLocalClass().get().meta.has(":composite") == true) {
  3.             meta = Context.getLocalClass().get().meta.extract(":composite");
  4.         } else if (Context.getLocalClass().get().meta.has("composite") == true) {
  5.             meta = Context.getLocalClass().get().meta.extract("composite");
  6.         }
  7.        
  8.         if (meta != null) {
  9.             var m = null;
  10.             for (t in meta) {
  11.                 if (t.name == "composite" || t.name == ":composite") {
  12.                     m = t;
  13.                     break;
  14.                 }
  15.             }
  16.            
  17.             var currentRegisterCompositeFn = MacroHelpers.getFunction(fields, "registerComposite");
  18.             if (currentRegisterCompositeFn != null) {
  19.                 for (p in m.params) {
  20.                     var s = ExprTools.toString(p);
  21.                    
  22.                     // probably a better way to do this
  23.                     if (s.indexOf("Event") != -1) {
  24.                         MacroHelpers.appendLine(currentRegisterCompositeFn, Context.parseInlineString('_internalEventsClass = ${ExprTools.toString(p)}', pos));
  25.                     } else if (s.indexOf("Builder") != -1) {
  26.                         MacroHelpers.appendLine(currentRegisterCompositeFn, Context.parseInlineString('_compositeBuilderClass = ${ExprTools.toString(p)}', pos));
  27.                     } else if (s.indexOf("Layout") != -1) {
  28.                         MacroHelpers.appendLine(currentRegisterCompositeFn, Context.parseInlineString('_defaultLayoutClass = ${ExprTools.toString(p)}', pos));
  29.                     }
  30.                 }
  31.             } else {
  32.                 var code:String = "";
  33.                 code += "function() {\n";
  34.                 code += "super.registerComposite();\n";
  35.  
  36.                 for (p in m.params) {
  37.                     var s = ExprTools.toString(p);
  38.                    
  39.                     // probably a better way to do this
  40.                     if (s.indexOf("Event") != -1) {
  41.                         code += '_internalEventsClass = ${ExprTools.toString(p)};\n';
  42.                     } else if (s.indexOf("Builder") != -1) {
  43.                         code += '_compositeBuilderClass = ${ExprTools.toString(p)};\n';
  44.                     } else if (s.indexOf("Layout") != -1) {
  45.                         code += '_defaultLayoutClass = ${ExprTools.toString(p)};\n';
  46.                     }
  47.                 }
  48.                
  49.                 code += "}";
  50.                
  51.                 var access:Array<Access> = [APrivate, AOverride];
  52.                 MacroHelpers.addFunction("registerComposite", Context.parseInlineString(code, pos), access, fields, pos);
  53.             }
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement