Skip to content

Commit 752833b

Browse files
authored
Merge pull request #18 from cesarParra/enum-values
Support for enum values
2 parents 5b5883d + ba01e77 commit 752833b

File tree

15 files changed

+620
-318
lines changed

15 files changed

+620
-318
lines changed

.idea/jsLibraryMappings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Dart_SDK.xml

Lines changed: 21 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/apex-reflection-node/__tests__/end-to-end.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ClassMirror, InterfaceMirror, reflect} from '../index';
1+
import {ClassMirror, EnumMirror, InterfaceMirror, reflect} from '../index';
22

33
describe('Enum Reflection', () => {
44
test('Simple, single line declaration', () => {
@@ -33,6 +33,34 @@ describe('Enum Reflection', () => {
3333
const result = reflect(enumBody).typeMirror;
3434
expect(result.docComment.description).toBe('My enum description');
3535
});
36+
37+
test('Enums can have values', () => {
38+
const enumBody = `
39+
enum MyEnumName {
40+
VALUE_1,
41+
VALUE2
42+
}
43+
`;
44+
const result = reflect(enumBody).typeMirror as EnumMirror;
45+
expect(result.values.length).toBe(2);
46+
expect(result.values[0].name).toBe('VALUE_1');
47+
expect(result.values[1].name).toBe('VALUE2');
48+
});
49+
50+
test('Enum values can have descriptions', () => {
51+
const enumBody = `
52+
enum MyEnumName {
53+
/**
54+
* Value 1 description
55+
*/
56+
VALUE_1,
57+
VALUE2
58+
}
59+
`;
60+
const result = reflect(enumBody).typeMirror as EnumMirror;
61+
expect(result.values.length).toBe(2);
62+
expect(result.values[0].docComment.description).toBe('Value 1 description');
63+
});
3664
});
3765

3866
describe('Interface Reflection', () => {

js/apex-reflection-node/index.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface Annotation {
3939
type: string;
4040
elementValues?: AnnotationElementValue[];
4141
}
42-
export declare type ReferencedType = ReferenceObjectType | ListObjectType | SetObjectType | MapObjectType;
42+
export type ReferencedType = ReferenceObjectType | ListObjectType | SetObjectType | MapObjectType;
4343
export interface ReferenceObjectType {
4444
type: string;
4545
rawDeclaration: string;
@@ -54,6 +54,10 @@ export interface MapObjectType extends ReferenceObjectType {
5454
keyType: ReferenceObjectType;
5555
valueType: ReferenceObjectType;
5656
}
57+
export interface EnumValue {
58+
name: string;
59+
docComment?: DocComment;
60+
}
5761
export interface ParameterMirror {
5862
memberModifiers: string[];
5963
name: string;
@@ -106,8 +110,8 @@ export interface ReflectionResult {
106110
export interface ParsingError {
107111
message: string;
108112
}
109-
declare type TypeName = 'class' | 'interface' | 'enum';
110-
export declare type Type = InterfaceMirror | ClassMirror | EnumMirror;
113+
type TypeName = 'class' | 'interface' | 'enum';
114+
export type Type = InterfaceMirror | ClassMirror | EnumMirror;
111115
export interface EnumMirror {
112116
annotations: Annotation[];
113117
name: string;
@@ -116,6 +120,7 @@ export interface EnumMirror {
116120
docComment?: DocComment;
117121
group?: string;
118122
groupDescription?: string;
123+
values: EnumValue[];
119124
}
120125
export interface InterfaceMirror {
121126
annotations: Annotation[];

js/apex-reflection-node/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export interface MapObjectType extends ReferenceObjectType {
7272
valueType: ReferenceObjectType;
7373
}
7474

75+
export interface EnumValue {
76+
name: string;
77+
docComment?: DocComment;
78+
}
79+
7580
export interface ParameterMirror {
7681
memberModifiers: string[];
7782
name: string;
@@ -144,6 +149,7 @@ export interface EnumMirror {
144149
docComment?: DocComment;
145150
group?: string;
146151
groupDescription?: string;
152+
values: EnumValue[];
147153
}
148154

149155
export interface InterfaceMirror {

0 commit comments

Comments
 (0)