Java: Report enums and fix parsing them

This commit is contained in:
Colomban Wendling 2013-07-15 17:42:00 +02:00
parent 80ad5c1459
commit b016e132fd
5 changed files with 48 additions and 8 deletions

View File

@ -905,6 +905,7 @@ static void add_top_level_items(GeanyDocument *doc)
&(tv_iters.tag_class), _("Classes"), "classviewer-class",
&(tv_iters.tag_function), _("Methods"), "classviewer-method",
&(tv_iters.tag_member), _("Members"), "classviewer-member",
&(tv_iters.tag_type), _("Enums"), "classviewer-struct",
&(tv_iters.tag_other), _("Other"), "classviewer-other",
NULL);
break;

View File

@ -204,6 +204,7 @@ typedef struct sStatementInfo
boolean haveQualifyingName; /* do we have a name we are considering? */
boolean gotParenName; /* was a name inside parentheses parsed yet? */
boolean gotArgs; /* was a list of parameters parsed yet? */
unsigned int nSemicolons; /* how many semicolons did we see in that statement */
impType implementation; /* abstract or concrete implementation? */
unsigned int tokenIndex; /* currently active token */
tokenInfo* token [((int) NumTokens)];
@ -327,7 +328,7 @@ typedef enum
{
JK_UNDEFINED = -1,
JK_CLASS, JK_FIELD, JK_INTERFACE, JK_METHOD,
JK_PACKAGE
JK_PACKAGE, JK_ENUMERATOR, JK_ENUMERATION
} javaKind;
static kindOption JavaKinds [] = {
@ -336,6 +337,8 @@ static kindOption JavaKinds [] = {
{ TRUE, 'i', "interface", "interfaces"},
{ TRUE, 'm', "method", "methods"},
{ TRUE, 'p', "package", "packages"},
{ TRUE, 'e', "enumerator", "enumerators (values inside an enumeration)"},
{ TRUE, 'g', "enum", "enumeration names"},
};
typedef enum
@ -940,6 +943,7 @@ static void reinitStatement (statementInfo *const st, const boolean partial)
st->implementation = IMP_DEFAULT;
st->gotArgs = FALSE;
st->gotName = FALSE;
st->nSemicolons = 0;
st->haveQualifyingName = FALSE;
st->argEndPosition = 0;
@ -1089,11 +1093,13 @@ static javaKind javaTagKind (const tagType type)
javaKind result = JK_UNDEFINED;
switch (type)
{
case TAG_CLASS: result = JK_CLASS; break;
case TAG_FIELD: result = JK_FIELD; break;
case TAG_INTERFACE: result = JK_INTERFACE; break;
case TAG_METHOD: result = JK_METHOD; break;
case TAG_PACKAGE: result = JK_PACKAGE; break;
case TAG_CLASS: result = JK_CLASS; break;
case TAG_FIELD: result = JK_FIELD; break;
case TAG_INTERFACE: result = JK_INTERFACE; break;
case TAG_METHOD: result = JK_METHOD; break;
case TAG_PACKAGE: result = JK_PACKAGE; break;
case TAG_ENUM: result = JK_ENUMERATION; break;
case TAG_ENUMERATOR: result = JK_ENUMERATOR; break;
default: Assert ("Bad Java tag type" == NULL); break;
}
@ -2786,6 +2792,9 @@ static void nextToken (statementInfo *const st)
}
} while (isType (token, TOKEN_NONE));
if (isType (token, TOKEN_SEMICOLON) && st->parent)
st->parent->nSemicolons ++;
/* We want to know about non-keyword variable types */
if (TOKEN_NONE == st->firstToken->type)
{
@ -2913,7 +2922,9 @@ static void tagCheck (statementInfo *const st)
{
case TOKEN_NAME:
{
if (insideEnumBody (st))
if (insideEnumBody (st) &&
/* Java enumerations can contain members after a semicolon */
(! isLanguage(Lang_java) || st->parent->nSemicolons < 1))
qualifyEnumeratorTag (st, token);
break;
}
@ -3022,7 +3033,9 @@ static void tagCheck (statementInfo *const st)
case TOKEN_SEMICOLON:
case TOKEN_COMMA:
{
if (insideEnumBody (st))
if (insideEnumBody (st) &&
/* Java enumerations can contain members after a semicolon */
(! isLanguage (Lang_java) || st->parent->nSemicolons < 2))
;
else if (isType (prev, TOKEN_NAME))
{

View File

@ -1,3 +1,13 @@
# format=tagmanager
AÌ4ÎeÖ0
BÌ4ÎeÖ0
CÌ4ÎeÖ0
DÌ4ÎeÖ0
EÌ4ÎeÖ0
FÌ4ÎeÖ0
eÌ2Ö0
getShapeÌ128Í()ÎeÖ0Ïpublic final Shape
getStringÌ128Í()ÎeÖ0Ïpublic String
shapeÌ8ÎeÖ0ÏShape
stringÌ8ÎeÖ0ÏString
twoKeywordsInARowÌ8ÎeÖ0Ïboolean

View File

@ -12,4 +12,9 @@ public class C {
void m() {
}
}
public enum FancyEnum2 {
X, Y;
void m2() {
}
}
}

View File

@ -1,4 +1,15 @@
# format=tagmanager
Aフ4ホC.FancyEnumヨ0
Bフ4ホC.FancyEnumヨ0
CÌ1Ö0
FIRST_VALUEフ4ホC.TrivialEnumヨ0
FancyEnumフ2ホCヨ0
FancyEnumÌ128Í(int i)ÎC.FancyEnumÖ0
FancyEnum2フ2ホCヨ0
SECOND_VALUEフ4ホC.TrivialEnumヨ0
TrivialEnumフ2ホCヨ0
Xフ4ホC.FancyEnum2ヨ0
Yフ4ホC.FancyEnum2ヨ0
iフ8ホC.FancyEnumヨ0マint
mÌ128Í()ÎC.FancyEnumÖ0Ïvoid
m2フ128ヘ()ホC.FancyEnum2ヨ0マvoid