diff --git a/CodeFormatter/PHPFormatterBuffer.cpp b/CodeFormatter/PHPFormatterBuffer.cpp index 49140737cf..583a5923af 100644 --- a/CodeFormatter/PHPFormatterBuffer.cpp +++ b/CodeFormatter/PHPFormatterBuffer.cpp @@ -95,7 +95,7 @@ PHPFormatterBuffer& PHPFormatterBuffer::ProcessToken(const phpLexerToken& token) if(m_options.flags & kPFF_BreakBeforeWhile) { InsertSeparatorLine(); } - } else if(token.type == kPHP_T_CLASS) { + } else if(token.type == kPHP_T_CLASS || token.type == kPHP_T_ENUM) { if(m_options.flags & kPFF_BreakBeforeClass) { InsertSeparatorLine(); } diff --git a/CodeLite/PHPEntityBase.h b/CodeLite/PHPEntityBase.h index b2affcde3a..ae08777eda 100644 --- a/CodeLite/PHPEntityBase.h +++ b/CodeLite/PHPEntityBase.h @@ -84,6 +84,7 @@ enum { kClass_Interface = (1 << 1), kClass_Trait = (1 << 2), kClass_Abstract = (1 << 3), + kClass_Enum = (1 << 4), }; class WXDLLIMPEXP_CL PHPEntityBase diff --git a/CodeLite/PHPEntityClass.h b/CodeLite/PHPEntityClass.h index ccf4d43800..c7b3cf4ffa 100644 --- a/CodeLite/PHPEntityClass.h +++ b/CodeLite/PHPEntityClass.h @@ -74,7 +74,9 @@ class WXDLLIMPEXP_CL PHPEntityClass : public PHPEntityBase void SetIsInterface(bool b) { SetFlag(kClass_Interface, b); } bool IsInterface() const { return HasFlag(kClass_Interface); } void SetIsTrait(bool b) { SetFlag(kClass_Trait, b); } + void SetIsEnum(bool b) { SetFlag(kClass_Enum, b); } bool IsTrait() const { return HasFlag(kClass_Trait); } + bool IsEnum() const { return HasFlag(kClass_Enum); } void SetIsAbstractClass(bool b) { SetFlag(kClass_Abstract, b); } bool IsAbstractClass() const { return HasFlag(kClass_Abstract); } }; diff --git a/CodeLite/PHPExpression.cpp b/CodeLite/PHPExpression.cpp index 4546e34cd3..847488ba35 100644 --- a/CodeLite/PHPExpression.cpp +++ b/CodeLite/PHPExpression.cpp @@ -56,6 +56,7 @@ phpLexerToken::Vet_t PHPExpression::CreateExpression(const wxString& text) case kPHP_T_CASE: case kPHP_T_RETURN: case kPHP_T_THROW: + case kPHP_T_ENUM: case kPHP_T_CLASS: case kPHP_T_TRAIT: case kPHP_T_INTERFACE: diff --git a/CodeLite/PHPScannerTokens.h b/CodeLite/PHPScannerTokens.h index 976b20e148..e22d244047 100644 --- a/CodeLite/PHPScannerTokens.h +++ b/CodeLite/PHPScannerTokens.h @@ -128,8 +128,9 @@ enum { kPHP_T_ISSET, kPHP_T_EMPTY, kPHP_T_HALT_COMPILER, - kPHP_T_CLASS, - kPHP_T_TRAIT, + kPHP_T_CLASS, + kPHP_T_TRAIT, + kPHP_T_ENUM, kPHP_T_INTERFACE, kPHP_T_EXTENDS, kPHP_T_IMPLEMENTS, diff --git a/CodeLite/PHPSourceFile.cpp b/CodeLite/PHPSourceFile.cpp index f16091c440..f5fc72861a 100644 --- a/CodeLite/PHPSourceFile.cpp +++ b/CodeLite/PHPSourceFile.cpp @@ -186,6 +186,12 @@ void PHPSourceFile::Parse(int exitDepth) case kPHP_T_CONST: OnConstant(token); break; + case kPHP_T_CASE: + if(Class() == CurrentScope().get()) { + // in class cope, this means that this is an enum case + OnConstant(token); + } + break; case kPHP_T_REQUIRE: case kPHP_T_REQUIRE_ONCE: case kPHP_T_INCLUDE: @@ -212,6 +218,7 @@ void PHPSourceFile::Parse(int exitDepth) case kPHP_T_CLASS: case kPHP_T_INTERFACE: case kPHP_T_TRAIT: + case kPHP_T_ENUM: // Found class OnClass(token); m_lookBackTokens.clear(); @@ -364,7 +371,7 @@ void PHPSourceFile::OnFunction() // update function attributes ParseFunctionSignature(funcDepth); func->SetFlags(LookBackForFunctionFlags()); - if(LookBackTokensContains(kPHP_T_ABSTRACT) || // The 'abstract modifier was found for this this function + if(LookBackTokensContains(kPHP_T_ABSTRACT) || // The 'abstract modifier was found for this function (funcPtr->Parent() && funcPtr->Parent()->Is(kEntityTypeClass) && funcPtr->Parent()->Cast()->IsInterface())) // We are inside an interface { @@ -792,6 +799,30 @@ void PHPSourceFile::OnClass(const phpLexerToken& tok) pClass->SetFullName(PrependCurrentScope(token.Text())); pClass->SetLine(token.lineNumber); + if (tok.type == kPHP_T_ENUM) { + pClass->SetIsEnum(true); + wxArrayString implements; + NextToken(token); + if (token.type == ':') { + NextToken(token); + if (token.type == kPHP_T_IDENTIFIER) { + if (token.Text() == "int") { + implements.Add("\\IntBackedEnum"); + } else if (token.Text() == "string") { + implements.Add("\\StringBackedEnum"); + } else { + implements.Add("\\BackedEnum"); + } + } else { + implements.Add("\\BackedEnum"); + } + } else { + UngetToken(token); + implements.Add("\\UnitEnum"); + } + pClass->SetImplements(implements); + } + while(NextToken(token)) { if(token.IsAnyComment()) continue; diff --git a/CodeLite/PhpLexer.l b/CodeLite/PhpLexer.l index 3da6230d9c..9e7de712ac 100644 --- a/CodeLite/PhpLexer.l +++ b/CodeLite/PhpLexer.l @@ -281,6 +281,7 @@ horizontal_white [ ]|{h_tab} "goto" {LEX_RETURN(kPHP_T_GOTO);} "echo" {LEX_RETURN(kPHP_T_ECHO);} "print" {LEX_RETURN(kPHP_T_PRINT);} +"enum" {LEX_RETURN(kPHP_T_ENUM);} "class" {LEX_RETURN(kPHP_T_CLASS);} "interface" {LEX_RETURN(kPHP_T_INTERFACE);} "trait" {LEX_RETURN(kPHP_T_TRAIT);} diff --git a/codelitephp/PHPParser/php_code_completion.cpp b/codelitephp/PHPParser/php_code_completion.cpp index 26d4d7d54c..99e11264b4 100644 --- a/codelitephp/PHPParser/php_code_completion.cpp +++ b/codelitephp/PHPParser/php_code_completion.cpp @@ -762,7 +762,7 @@ int PHPCodeCompletion::GetLocationForSettersGetters(const wxString& filecontent, phpLexerToken token; bool isOK = false; while(::phpLexerNext(scanner, token)) { - if(token.type != kPHP_T_CLASS) { + if(token.type != kPHP_T_CLASS && token.type != kPHP_T_ENUM) { continue; }