Skip to content

Commit 5d6a714

Browse files
author
Arthur Ozga
committed
move helpers under codefix dir
1 parent f37640a commit 5d6a714

File tree

6 files changed

+88
-73
lines changed

6 files changed

+88
-73
lines changed

Jakefile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ var servicesSources = [
176176
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
177177
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
178178
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
179+
"codefixes/helpers.ts",
180+
"codefixes/importFixes.ts",
181+
"codefixes/unusedIdentifierFixes.ts"
179182
].map(function (f) {
180183
return path.join(servicesDirectory, f);
181184
}));

src/harness/tsconfig.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@
7474
"../services/formatting/rulesProvider.ts",
7575
"../services/formatting/smartIndenter.ts",
7676
"../services/formatting/tokenRange.ts",
77-
"../services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
77+
"../services/codeFixProvider.ts",
78+
"../services/codefixes/fixes.ts",
79+
"../services/codefixes/fixExtendsInterfaceBecomesImplements.ts",
7880
"../services/codefixes/fixClassIncorrectlyImplementsInterface.ts",
81+
"../services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
7982
"../services/codefixes/fixClassSuperMustPrecedeThisAccess.ts",
8083
"../services/codefixes/fixConstructorForDerivedNeedSuperCall.ts",
81-
"../services/codefixes/fixes.ts",
82-
"../services/codefixes/fixExtendsInterfaceBecomesImplements.ts",
83-
"harness.ts",
84+
"../services/codefixes/helpers.ts",
85+
"../services/codefixes/importFixes.ts",
86+
"../services/codefixes/unusedIdentifierFixes.ts",
87+
"../services/harness.ts",
88+
8489
"sourceMapRecorder.ts",
8590
"harnessLanguageService.ts",
8691
"fourslash.ts",

src/services/codefixes/fixes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
66
/// <reference path='unusedIdentifierFixes.ts' />
77
/// <reference path='importFixes.ts' />
8+
/// <reference path='helpers.ts' />
89

src/services/codefixes/helpers.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* @internal */
2+
namespace ts.codefix {
3+
4+
/**
5+
* Finds members of the resolved type that are missing in the class pointed to by class decl
6+
* and generates source code for the missing members.
7+
* @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for.
8+
* @returns undefined iff there is no insertion available.
9+
*/
10+
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker, newlineChar: string): string {
11+
const classMembers = classDeclaration.symbol.members;
12+
const missingMembers = possiblyMissingSymbols.filter(symbol => !(symbol.getName() in classMembers));
13+
14+
let insertion = "";
15+
16+
for (const symbol of missingMembers) {
17+
insertion = insertion.concat(getInsertionForMemberSymbol(symbol, classDeclaration, checker, newlineChar));
18+
}
19+
return insertion.length > 0 ? insertion : undefined;
20+
}
21+
22+
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {
23+
const name = symbol.getName();
24+
const type = checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration);
25+
const declarations = symbol.getDeclarations();
26+
if (!(declarations && declarations.length)) {
27+
return "";
28+
}
29+
const node = declarations[0];
30+
const visibility = getVisibilityPrefix(getModifierFlags(node));
31+
switch (node.kind) {
32+
case SyntaxKind.PropertySignature:
33+
case SyntaxKind.PropertyDeclaration:
34+
const typeString = checker.typeToString(type, enclosingDeclaration, TypeFormatFlags.None);
35+
return `${visibility}${name}: ${typeString};${newlineChar}`;
36+
37+
case SyntaxKind.MethodSignature:
38+
case SyntaxKind.MethodDeclaration:
39+
const signatures = checker.getSignaturesOfType(type, SignatureKind.Call);
40+
if (!(signatures && signatures.length > 0)) {
41+
return "";
42+
}
43+
// TODO: (arozga) Deal with multiple signatures.
44+
const sigString = checker.signatureToString(signatures[0], enclosingDeclaration, TypeFormatFlags.SuppressAnyReturnType, SignatureKind.Call);
45+
46+
return `${visibility}${name}${sigString}${getMethodBodyStub(newlineChar)}`;
47+
default:
48+
return "";
49+
}
50+
}
51+
52+
function getMethodBodyStub(newLineChar: string) {
53+
return `{${newLineChar}throw new Error('Method not Implemented');${newLineChar}}${newLineChar}`;
54+
}
55+
56+
function getVisibilityPrefix(flags: ModifierFlags): string {
57+
if (flags & ModifierFlags.Public) {
58+
return "public ";
59+
}
60+
else if (flags & ModifierFlags.Protected) {
61+
return "protected ";
62+
}
63+
return "";
64+
}
65+
}

src/services/tsconfig.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@
8888
"formatting/smartIndenter.ts",
8989
"formatting/tokenRange.ts",
9090
"codeFixProvider.ts",
91-
"codeFixes/fixes.ts",
92-
"codeFixes/fixExtendsInterfaceBecomesImplements.ts",
93-
"codeFixes/fixClassIncorrectlyImplementsInterface.ts",
94-
"codeFixes/fixClassDoesntImplementInheritedAbstractMember.ts",
95-
"codeFixes/fixClassSuperMustPrecedeThisAccess.ts",
96-
"codeFixes/fixConstructorForDerivedNeedSuperCall.ts"
91+
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
92+
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
93+
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
94+
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
95+
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
96+
"codefixes/fixes.ts",
97+
"codefixes/helpers.ts",
98+
"codefixes/importFixes.ts",
99+
"codefixes/unusedIdentifierFixes.ts"
97100
]
98-
}
101+
}

src/services/utilities.ts

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,68 +1359,6 @@ namespace ts {
13591359
};
13601360
}
13611361

1362-
/**
1363-
* Finds members of the resolved type that are missing in the class pointed to by class decl
1364-
* and generates source code for the missing members.
1365-
* @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for.
1366-
* @returns undefined iff there is no insertion available.
1367-
*/
1368-
export function getMissingMembersInsertion(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: Symbol[], checker: TypeChecker, newlineChar: string): string {
1369-
const classMembers = classDeclaration.symbol.members;
1370-
const missingMembers = possiblyMissingSymbols.filter(symbol => !(symbol.getName() in classMembers));
1371-
1372-
let insertion = "";
1373-
1374-
for (const symbol of missingMembers) {
1375-
insertion = insertion.concat(getInsertionForMemberSymbol(symbol, classDeclaration, checker, newlineChar));
1376-
}
1377-
return insertion.length > 0 ? insertion : undefined;
1378-
}
1379-
1380-
function getInsertionForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, newlineChar: string): string {
1381-
const name = symbol.getName();
1382-
const type = checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration);
1383-
const declarations = symbol.getDeclarations();
1384-
if (!(declarations && declarations.length)) {
1385-
return "";
1386-
}
1387-
const node = declarations[0];
1388-
const visibility = getVisibilityPrefix(getModifierFlags(node));
1389-
switch (node.kind) {
1390-
case SyntaxKind.PropertySignature:
1391-
case SyntaxKind.PropertyDeclaration:
1392-
const typeString = checker.typeToString(type, enclosingDeclaration, TypeFormatFlags.None);
1393-
return `${visibility}${name}: ${typeString};${newlineChar}`;
1394-
1395-
case SyntaxKind.MethodSignature:
1396-
case SyntaxKind.MethodDeclaration:
1397-
const signatures = checker.getSignaturesOfType(type, SignatureKind.Call);
1398-
if (!(signatures && signatures.length > 0)) {
1399-
return "";
1400-
}
1401-
// TODO: (arozga) Deal with multiple signatures.
1402-
const sigString = checker.signatureToString(signatures[0], enclosingDeclaration, TypeFormatFlags.SuppressAnyReturnType, SignatureKind.Call);
1403-
1404-
return `${visibility}${name}${sigString}${getMethodBodyStub(newlineChar)}`;
1405-
default:
1406-
return "";
1407-
}
1408-
}
1409-
1410-
function getMethodBodyStub(newLineChar: string) {
1411-
return `{${newLineChar}throw new Error('Method not Implemented');${newLineChar}}${newLineChar}`;
1412-
}
1413-
1414-
function getVisibilityPrefix(flags: ModifierFlags): string {
1415-
if (flags & ModifierFlags.Public) {
1416-
return "public ";
1417-
}
1418-
else if (flags & ModifierFlags.Protected) {
1419-
return "protected ";
1420-
}
1421-
return "";
1422-
}
1423-
14241362
export function getOpenBraceEnd(constructor: ConstructorDeclaration, sourceFile: SourceFile) {
14251363
// First token is the open curly, this is where we want to put the 'super' call.
14261364
return constructor.body.getFirstToken(sourceFile).getEnd();

0 commit comments

Comments
 (0)