Merge pull request #778 from Microsoft/getOccurrencesSetItAndForGetIt

getOccurrences for 'get' and 'set' keywords.
This commit is contained in:
Daniel Rosenwasser 2014-09-30 14:54:18 -07:00
commit f2880ce5b7
4 changed files with 124 additions and 0 deletions

View file

@ -2680,6 +2680,11 @@ module ts {
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
}
break;
case SyntaxKind.GetKeyword:
case SyntaxKind.SetKeyword:
if (hasKind(node.parent, SyntaxKind.GetAccessor) || hasKind(node.parent, SyntaxKind.SetAccessor)) {
return getGetAndSetOccurrences(<AccessorDeclaration>node.parent);
}
}
return undefined;
@ -3010,6 +3015,23 @@ module ts {
return map(keywords, getReferenceEntryFromNode);
}
function getGetAndSetOccurrences(accessorDeclaration: AccessorDeclaration): ReferenceEntry[] {
var keywords: Node[] = [];
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.GetAccessor);
tryPushAccessorKeyword(accessorDeclaration.symbol, SyntaxKind.SetAccessor);
return map(keywords, getReferenceEntryFromNode);
function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind): void {
var accessor = getDeclarationOfKind(accessorSymbol, accessorKind);
if (accessor) {
forEach(accessor.getChildren(), child => pushKeywordIf(keywords, child, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword));
}
}
}
// returns true if 'node' is defined and has a matching 'kind'.
function hasKind(node: Node, kind: SyntaxKind) {
return node !== undefined && node.kind === kind;

View file

@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// [|set|] bar(b: any) {
//// }
////
//// public [|get|] bar(): any {
//// return undefined;
//// }
////
//// public set set(s: any) {
//// }
////
//// public get set(): any {
//// return undefined;
//// }
////
//// public set get(g: any) {
//// }
////
//// public get get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});

View file

@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// set bar(b: any) {
//// }
////
//// public get bar(): any {
//// return undefined;
//// }
////
//// public [|set|] set(s: any) {
//// }
////
//// public [|get|] set(): any {
//// return undefined;
//// }
////
//// public set get(g: any) {
//// }
////
//// public get get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});

View file

@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
////class Foo {
//// set bar(b: any) {
//// }
////
//// public get bar(): any {
//// return undefined;
//// }
////
//// public set set(s: any) {
//// }
////
//// public get set(): any {
//// return undefined;
//// }
////
//// public [|set|] get(g: any) {
//// }
////
//// public [|get|] get(): any {
//// return undefined;
//// }
////}
test.ranges().forEach(r => {
goTo.position(r.start);
test.ranges().forEach(range => {
verify.occurrencesAtPositionContains(range, false);
});
verify.occurrencesAtPositionCount(test.ranges().length);
});