Эх сурвалжийг харах

Work on JSBind to allow it to extract inline comments from the ATOMIC_EVENT and ATOMIC_PARAM blocks.

Shaddock Heath 9 жил өмнө
parent
commit
0fc71cb6c3

+ 30 - 3
Source/ToolCore/JSBind/JSBEvent.cpp

@@ -34,12 +34,13 @@ using namespace Atomic;
 namespace ToolCore
 {
 
-JSBEvent::JSBEvent(Context* context, JSBModule* module, const String& eventID, const String& eventName) :
+JSBEvent::JSBEvent(Context* context, JSBModule* module, const String& eventID, const String& eventName, const String& eventComment) :
     Object(context),
     module_(module), 
     header_(0),
     eventID_(eventID),
-    eventName_(eventName)
+    eventName_(eventName),
+    eventComment_(eventComment)
 {
 
 }
@@ -100,6 +101,7 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
         SharedPtr<JSBEvent> curEvent;
         String eventID;
         String eventName;
+        String eventComment;
 
         for (unsigned j = 0; j < lines.Size(); j++)
         {
@@ -109,6 +111,16 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
             // Note: processes ATOMIC_EVENT decl in commented blocks
             if (line.StartsWith("ATOMIC_EVENT"))
             {
+                // First check to see if there is a line comment above this and try to capture it
+                if (j > 0) {
+                    String prevLine = lines[j-1].Trimmed();
+                    if (prevLine.StartsWith(("//")))
+                    {
+                        prevLine.Replace("//", "");
+                        eventComment = prevLine.Trimmed();
+                    }
+                }
+
                 StringVector parts = line.Split('(');
 
                 if (parts.Size() != 2)
@@ -129,7 +141,7 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
                 eventName = parts[1].Trimmed();
                 eventName.Replace(")", "");
 
-                curEvent = new JSBEvent(module->GetContext(), module, eventID, eventName);
+                curEvent = new JSBEvent(module->GetContext(), module, eventID, eventName, eventComment);
             }            
 
             if (line.Contains("}") && curEvent.NotNull())
@@ -162,6 +174,7 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
 
                 String typeInfo;
                 String enumTypeName;
+                String formalComment;
 
                 // comment contains type
                 if (parts[1].Contains("//"))
@@ -170,6 +183,7 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
                     comment.Replace("//", "");
                     comment = comment.Trimmed();
                     StringVector typeVector = comment.Split(' ');
+                    int commentStart = 1;
                     if (typeVector.Size() > 0)
                     {
                         typeInfo = typeVector[0];
@@ -180,6 +194,18 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
                             {
                                 enumTypeName = typeVector[1];
                             }
+
+                            commentStart = 1;
+                        }
+
+                        // Check to see if there are any comments following and try to capture them
+                        if (typeVector.Size() > commentStart + 1)
+                        {
+                            formalComment = "";
+                            for (int i = commentStart; i < typeVector.Size(); i++) {
+                                formalComment.Append(" ");
+                                formalComment.Append(typeVector[i]);
+                            }
                         }
                     }
                 }
@@ -207,6 +233,7 @@ bool JSBEvent::ScanModuleEvents(JSBModule* module)
                 param.paramName_ = parts[1].Trimmed();
                 param.typeInfo_ = typeInfo;
                 param.enumTypeName_ = enumTypeName;
+                param.comment_ = formalComment;
 
                 curEvent->parameters_.Push(param);
 

+ 4 - 2
Source/ToolCore/JSBind/JSBEvent.h

@@ -49,19 +49,20 @@ namespace ToolCore
             String paramName_;
             String typeInfo_;
             String enumTypeName_;
+            String comment_;
         };
 
-        JSBEvent(Context* context, JSBModule* module, const String& eventID, const String& eventName);
+        JSBEvent(Context* context, JSBModule* module, const String& eventID, const String& eventName, const String& eventComment);
         virtual ~JSBEvent();
 
         const String& GetEventID() const { return eventID_; }
         const String& GetEventName() const { return eventName_; }
+        const String& GetEventComment() const { return eventComment_; }
         unsigned GetEventHash() const;
         /// Generally this is the EventName + "Event"
         String GetScriptEventName(BindingLanguage language = BINDINGLANGUAGE_ANY) const;
         const Vector<EventParam>& GetParameters() const { return parameters_;  }
 
-
         void SetHeader(JSBHeader* header) { header_ = header; }
         JSBHeader* GetHeader() { return header_; }
 
@@ -77,6 +78,7 @@ namespace ToolCore
 
         String eventName_;
         String eventID_;
+        String eventComment_;
 
         Vector<EventParam> parameters_;
 

+ 14 - 1
Source/ToolCore/JSBind/JSBTypeScript.cpp

@@ -446,6 +446,11 @@ void JSBTypeScript::ExportModuleEvents(JSBModule* module)
                 mapped = true;
             }
 
+            if (p.comment_.Length())
+            {
+                source += ToString("        /** %s */\n", p.comment_.CString());
+            }
+
             if (mapped == true) {
                 source += ToString("        %s : %s;\n", paramName.CString(), typeName.CString());
             } else {
@@ -457,7 +462,15 @@ void JSBTypeScript::ExportModuleEvents(JSBModule* module)
         source += "    }\n\n";
 
         // Write the event function signature
-        source += ToString("    /** Wrapper function to generate a properly formatted event handler to pass to 'subscribeToEvent' for the %s event. **/\n", event->GetEventName().CString());
+        if (event->GetEventComment().Length())
+        {
+            source += "    /**\n";
+            source += ToString("     Wrapper function to generate a properly formatted event handler to pass to 'subscribeToEvent' for the %s event. \n\n", event->GetEventName().CString());
+            source += ToString("     %s\n", event->GetEventComment().CString());
+            source += "    **/\n";
+        } else {
+            source += ToString("    /** Wrapper function to generate a properly formatted event handler to pass to 'subscribeToEvent' for the %s event. **/\n", event->GetEventName().CString());
+        }
         source += ToString("    export function %s (callback : Atomic.EventCallback<%s>) : Atomic.EventMetaData;\n", scriptEventName.CString(), scriptEventName.CString());
 
         source += "\n\n";