| 1 |
#include "PHPEntityClass.h" |
| 2 |
#include <wx/tokenzr.h> |
| 3 |
#include <algorithm> |
| 4 |
#include "PHPLookupTable.h" |
| 5 |
|
| 6 |
PHPEntityClass::PHPEntityClass() {} |
| 7 |
|
| 8 |
PHPEntityClass::~PHPEntityClass() {} |
| 9 |
|
| 10 |
void PHPEntityClass::PrintStdout(int indent) const |
| 11 |
{ |
| 12 |
wxString indentString(' ', indent); |
| 13 |
wxPrintf("%sClass name: %s", indentString, GetFullName()); |
| 14 |
if(!GetExtends().IsEmpty()) { |
| 15 |
wxPrintf(", extends %s", GetExtends()); |
| 16 |
} |
| 17 |
if(!GetImplements().IsEmpty()) { |
| 18 |
wxPrintf(", implements: "); |
| 19 |
for(size_t i = 0; i < GetImplements().GetCount(); ++i) { |
| 20 |
wxPrintf("%s ", GetImplements().Item(i)); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
wxPrintf("\n"); |
| 25 |
PHPEntityBase::List_t::const_iterator iter = m_children.begin(); |
| 26 |
for(; iter != m_children.end(); ++iter) { |
| 27 |
(*iter)->PrintStdout(indent + 4); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
void PHPEntityClass::Store(PHPLookupTable* lookup) |
| 32 |
{ |
| 33 |
try { |
| 34 |
wxSQLite3Database& db = lookup->Database(); |
| 35 |
wxSQLite3Statement statement = db.PrepareStatement( |
| 36 |
"REPLACE INTO SCOPE_TABLE (ID, SCOPE_TYPE, SCOPE_ID, NAME, FULLNAME, EXTENDS, " |
| 37 |
"IMPLEMENTS, USING_TRAITS, FLAGS, DOC_COMMENT, " |
| 38 |
"LINE_NUMBER, FILE_NAME) VALUES (NULL, 1, :SCOPE_ID, :NAME, :FULLNAME, :EXTENDS, " |
| 39 |
":IMPLEMENTS, :USING_TRAITS, :FLAGS, :DOC_COMMENT, :LINE_NUMBER, :FILE_NAME)"); |
| 40 |
|
| 41 |
statement.Bind(statement.GetParamIndex(":SCOPE_ID"), Parent()->GetDbId()); |
| 42 |
statement.Bind(statement.GetParamIndex(":NAME"), GetShortName()); |
| 43 |
statement.Bind(statement.GetParamIndex(":FULLNAME"), GetFullName()); |
| 44 |
statement.Bind(statement.GetParamIndex(":EXTENDS"), GetExtends()); |
| 45 |
statement.Bind(statement.GetParamIndex(":IMPLEMENTS"), GetImplementsAsString()); |
| 46 |
statement.Bind(statement.GetParamIndex(":USING_TRAITS"), GetTraitsAsString()); |
| 47 |
statement.Bind(statement.GetParamIndex(":FLAGS"), (int)GetFlags()); |
| 48 |
statement.Bind(statement.GetParamIndex(":DOC_COMMENT"), GetDocComment()); |
| 49 |
statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLine()); |
| 50 |
statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath()); |
| 51 |
statement.ExecuteUpdate(); |
| 52 |
SetDbId(db.GetLastRowId()); |
| 53 |
|
| 54 |
// Now that we got the class saved, store any PHPDocVar |
| 55 |
std::for_each( |
| 56 |
m_varPhpDocs.begin(), m_varPhpDocs.end(), [&](PHPDocVar::Ptr_t doc) { doc->Store(db, GetDbId()); }); |
| 57 |
lookup->UpdateClassCache(GetFullName()); |
| 58 |
} catch(wxSQLite3Exception& exc) { |
| 59 |
wxUnusedVar(exc); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
void PHPEntityClass::FromResultSet(wxSQLite3ResultSet& res) |
| 64 |
{ |
| 65 |
SetDbId(res.GetInt("ID")); |
| 66 |
SetFullName(res.GetString("FULLNAME")); |
| 67 |
SetShortName(res.GetString("NAME")); |
| 68 |
SetExtends(res.GetString("EXTENDS")); |
| 69 |
SetImplements(::wxStringTokenize(res.GetString("IMPLEMENTS"), ";", wxTOKEN_STRTOK)); |
| 70 |
SetTraits(::wxStringTokenize(res.GetString("USING_TRAITS"), ";", wxTOKEN_STRTOK)); |
| 71 |
SetDocComment(res.GetString("DOC_COMMENT")); |
| 72 |
SetLine(res.GetInt("LINE_NUMBER")); |
| 73 |
SetFilename(res.GetString("FILE_NAME")); |
| 74 |
SetFlags(res.GetInt("FLAGS")); |
| 75 |
} |
| 76 |
|
| 77 |
wxArrayString PHPEntityClass::GetInheritanceArray() const |
| 78 |
{ |
| 79 |
wxArrayString arr, uniqueArr; |
| 80 |
arr.Add(GetExtends()); |
| 81 |
arr.insert(arr.end(), GetImplements().begin(), GetImplements().end()); |
| 82 |
arr.insert(arr.end(), GetTraits().begin(), GetTraits().end()); |
| 83 |
|
| 84 |
for(size_t i = 0; i < arr.GetCount(); ++i) { |
| 85 |
if(uniqueArr.Index(arr.Item(i)) == wxNOT_FOUND) { |
| 86 |
uniqueArr.Add(arr.Item(i)); |
| 87 |
} |
| 88 |
} |
| 89 |
arr.swap(uniqueArr); |
| 90 |
return arr; |
| 91 |
} |
| 92 |
|
| 93 |
wxString PHPEntityClass::Type() const { return GetFullName(); } |
| 94 |
bool PHPEntityClass::Is(eEntityType type) const { return type == kEntityTypeClass; } |
| 95 |
wxString PHPEntityClass::GetDisplayName() const { return GetShortName(); } |
| 96 |
wxString PHPEntityClass::FormatPhpDoc(const CommentConfigData& data) const |
| 97 |
{ |
| 98 |
wxString doc; |
| 99 |
doc << data.GetCommentBlockPrefix() << "\n" |
| 100 |
<< " * @class " << GetFullName() << "\n" |
| 101 |
<< " * @brief \n" |
| 102 |
<< " */"; |
| 103 |
return doc; |
| 104 |
} |
| 105 |
|
| 106 |
void PHPEntityClass::FromJSON(const JSONItem& json) |
| 107 |
{ |
| 108 |
BaseFromJSON(json); |
| 109 |
m_extends = json.namedObject("extends").toString(); |
| 110 |
m_implements = json.namedObject("implements").toArrayString(); |
| 111 |
m_traits = json.namedObject("traits").toArrayString(); |
| 112 |
} |
| 113 |
|
| 114 |
JSONItem PHPEntityClass::ToJSON() const |
| 115 |
{ |
| 116 |
JSONItem json = BaseToJSON("c"); |
| 117 |
json.addProperty("extends", m_extends); |
| 118 |
json.addProperty("implements", m_implements); |
| 119 |
json.addProperty("traits", m_traits); |
| 120 |
return json; |
| 121 |
} |