Merge pull request #778 from Microsoft/getOccurrencesSetItAndForGetIt
getOccurrences for 'get' and 'set' keywords.
This commit is contained in:
commit
f2880ce5b7
|
@ -2680,6 +2680,11 @@ module ts {
|
||||||
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
|
return getConstructorOccurrences(<ConstructorDeclaration>node.parent);
|
||||||
}
|
}
|
||||||
break;
|
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;
|
return undefined;
|
||||||
|
@ -3010,6 +3015,23 @@ module ts {
|
||||||
return map(keywords, getReferenceEntryFromNode);
|
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'.
|
// returns true if 'node' is defined and has a matching 'kind'.
|
||||||
function hasKind(node: Node, kind: SyntaxKind) {
|
function hasKind(node: Node, kind: SyntaxKind) {
|
||||||
return node !== undefined && node.kind === kind;
|
return node !== undefined && node.kind === kind;
|
||||||
|
|
34
tests/cases/fourslash/getOccurrencesSetAndGet.ts
Normal file
34
tests/cases/fourslash/getOccurrencesSetAndGet.ts
Normal 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);
|
||||||
|
});
|
34
tests/cases/fourslash/getOccurrencesSetAndGet2.ts
Normal file
34
tests/cases/fourslash/getOccurrencesSetAndGet2.ts
Normal 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);
|
||||||
|
});
|
34
tests/cases/fourslash/getOccurrencesSetAndGet3.ts
Normal file
34
tests/cases/fourslash/getOccurrencesSetAndGet3.ts
Normal 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);
|
||||||
|
});
|
Loading…
Reference in a new issue