1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
#include "PHPEntityVariable.h"
#include "PHPScannerTokens.h"
#include "PHPEntityFunction.h"
#include "PHPEntityClass.h"
#include "PHPLookupTable.h"
PHPEntityVariable::PHPEntityVariable() {}
PHPEntityVariable::~PHPEntityVariable() {}
void PHPEntityVariable::PrintStdout(int indent) const
{
wxString indentString(' ', indent);
wxPrintf("%s%s: %s", indentString, IsMember() ? "Member" : "Variable", GetShortName());
if(!GetTypeHint().IsEmpty()) {
wxPrintf(", TypeHint: %s", GetTypeHint());
}
if(!GetExpressionHint().IsEmpty()) {
wxPrintf(", ExpressionHint: %s", GetExpressionHint());
}
if(IsReference()) {
wxPrintf(", Reference");
}
if(!GetDefaultValue().IsEmpty()) {
wxPrintf(", Default: %s", GetDefaultValue());
}
wxPrintf(", Ln. %d", GetLine());
wxPrintf("\n");
PHPEntityBase::List_t::const_iterator iter = m_children.begin();
for(; iter != m_children.end(); ++iter) {
(*iter)->PrintStdout(indent + 4);
}
}
void PHPEntityVariable::SetVisibility(int visibility)
{
switch(visibility) {
case kPHP_T_PUBLIC:
m_flags &= ~kVar_Private;
m_flags &= ~kVar_Protected;
m_flags |= kVar_Public;
break;
case kPHP_T_PROTECTED:
m_flags &= ~kVar_Private;
m_flags &= ~kVar_Public;
m_flags |= kVar_Protected;
break;
case kPHP_T_PRIVATE:
m_flags &= ~kVar_Public;
m_flags &= ~kVar_Protected;
m_flags |= kVar_Private;
break;
default:
break;
}
}
wxString PHPEntityVariable::ToFuncArgString() const
{
if(!IsFunctionArg()) {
return "";
}
wxString str;
if(!GetTypeHint().IsEmpty()) {
if(IsNullable()) {
str << "?";
}
str << GetTypeHint() << " ";
}
if(IsReference()) {
str << "&";
}
str << GetShortName();
if(!GetDefaultValue().IsEmpty()) {
str << " = " << GetDefaultValue();
}
return str;
}
void PHPEntityVariable::Store(PHPLookupTable* lookup)
{
if(IsFunctionArg() || IsMember() || IsDefine()) {
try {
wxSQLite3Database& db = lookup->Database();
wxSQLite3Statement statement = db.PrepareStatement(
"INSERT OR REPLACE INTO VARIABLES_TABLE VALUES (NULL, "
":SCOPE_ID, :FUNCTION_ID, :NAME, :FULLNAME, :SCOPE, :TYPEHINT, :DEFAULT_VALUE, "
":FLAGS, :DOC_COMMENT, :LINE_NUMBER, :FILE_NAME)");
wxLongLong functionId, scopeId;
if(IsFunctionArg()) {
functionId = Parent()->GetDbId();
} else {
functionId = -1;
}
if(IsMember() || IsDefine()) {
scopeId = Parent()->GetDbId();
} else {
scopeId = -1;
}
statement.Bind(statement.GetParamIndex(":SCOPE_ID"), scopeId);
statement.Bind(statement.GetParamIndex(":FUNCTION_ID"), functionId);
statement.Bind(statement.GetParamIndex(":NAME"), GetShortName());
statement.Bind(statement.GetParamIndex(":FULLNAME"), GetFullName());
statement.Bind(statement.GetParamIndex(":SCOPE"), GetScope());
statement.Bind(statement.GetParamIndex(":TYPEHINT"), GetTypeHint());
statement.Bind(statement.GetParamIndex(":DEFAULT_VALUE"), GetDefaultValue());
statement.Bind(statement.GetParamIndex(":FLAGS"), (int)GetFlags());
statement.Bind(statement.GetParamIndex(":DOC_COMMENT"), GetDocComment());
statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLine());
statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
statement.ExecuteUpdate();
SetDbId(db.GetLastRowId());
} catch(wxSQLite3Exception& exc) {
wxUnusedVar(exc);
}
}
}
void PHPEntityVariable::FromResultSet(wxSQLite3ResultSet& res)
{
SetDbId(res.GetInt("ID"));
SetFullName(res.GetString("FULLNAME"));
SetShortName(res.GetString("NAME"));
SetTypeHint(res.GetString("TYPEHINT"));
SetFlags(res.GetInt("FLAGS"));
SetDocComment(res.GetString("DOC_COMMENT"));
SetLine(res.GetInt("LINE_NUMBER"));
SetFilename(res.GetString("FILE_NAME"));
SetDefaultValue(res.GetString("DEFAULT_VALUE"));
}
wxString PHPEntityVariable::GetScope() const
{
PHPEntityBase* parent = Parent();
if(parent && parent->Is(kEntityTypeFunction) && IsFunctionArg()) {
return parent->Cast<PHPEntityFunction>()->GetScope();
} else if(parent && parent->Is(kEntityTypeClass) && IsMember()) {
return parent->GetFullName();
} else if(parent && parent->Is(kEntityTypeNamespace) && IsDefine()) {
return parent->GetFullName();
} else {
return "";
}
}
wxString PHPEntityVariable::Type() const { return GetTypeHint(); }
bool PHPEntityVariable::Is(eEntityType type) const { return type == kEntityTypeVariable; }
wxString PHPEntityVariable::GetDisplayName() const { return GetFullName(); }
wxString PHPEntityVariable::GetNameNoDollar() const
{
wxString name = GetShortName();
if(name.StartsWith("$")) {
name.Remove(0, 1);
}
name.Trim().Trim(false);
return name;
}
wxString PHPEntityVariable::FormatPhpDoc(const CommentConfigData& data) const
{
wxString doc;
doc << data.GetCommentBlockPrefix() << "\n"
<< " * @var " << GetTypeHint() << "\n"
<< " */";
return doc;
}
wxString PHPEntityVariable::ToTooltip() const
{
if(IsConst() && !GetDefaultValue().IsEmpty()) {
return GetDefaultValue();
} else {
return wxEmptyString;
}
}
void PHPEntityVariable::FromJSON(const JSONItem& json)
{
BaseFromJSON(json);
m_typeHint = json.namedObject("type-hint").toString();
m_expressionHint = json.namedObject("expr-hint").toString();
m_defaultValue = json.namedObject("defaultValue").toString();
}
JSONItem PHPEntityVariable::ToJSON() const
{
JSONItem json = BaseToJSON("v"); // type variable
json.addProperty("type-hint", m_typeHint);
json.addProperty("expr-hint", m_expressionHint);
json.addProperty("defaultValue", m_defaultValue);
return json;
}
|