Add removeAbstractModifier Fix

Still need to add localization strings
This commit is contained in:
Arthur Ozga 2016-10-28 18:38:03 -07:00
parent 834245cd8f
commit c89b97b56a
3 changed files with 46 additions and 2 deletions

View File

@ -173,7 +173,8 @@ var servicesSources = [
"codeFixes/fixClassIncorrectlyImplementsInterface.ts",
"codeFixes/fixClassDoesntImplementInheritedAbstractMember.ts",
"codeFixes/fixClassSuperMustPrecedeThisAccess.ts",
"codeFixes/fixConstructorForDerivedNeedSuperCall.ts"
"codeFixes/fixConstructorForDerivedNeedSuperCall.ts",
"codeFixes/fixRemoveAbstractModifierInNonAbstractClass.ts"
].map(function (f) {
return path.join(servicesDirectory, f);
}));

View File

@ -0,0 +1,42 @@
/* @internal */
namespace ts.codefix {
registerCodeFix({
errorCodes: [Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class.code],
getCodeActions: (context: CodeFixContext) => {
const sourceFile = context.sourceFile;
const start = context.span.start;
const token = getTokenAtPosition(sourceFile, start);
Debug.assert(token.kind === SyntaxKind.AbstractKeyword);
const propertyDeclaration = <PropertyDeclaration>token.parent;
const classDeclaration = <ClassDeclaration>propertyDeclaration.parent;
const classKeywordStart = classDeclaration.getChildren()[0].getStart();
let codeFix: CodeAction[] = [
{
description: `Remove abstract modifier from ${propertyDeclaration.name.getText()}.`,
changes: [{
fileName: sourceFile.fileName,
textChanges: [{
span: {start: start, length: context.span.length + /*space*/ 1},
newText: ""
}]
}]
},
{
description: `Make class ${classDeclaration.name.getText()} abstract.`,
changes: [{
fileName: sourceFile.fileName,
textChanges: [{
span: { start: classKeywordStart, length: 0 },
newText: "abstract "
}]
}]
}
];
return codeFix;
}
});
}

View File

@ -2,4 +2,5 @@
/// <reference path="fixClassDoesntImplementInheritedAbstractMember.ts" />
/// <reference path="fixClassSuperMustPrecedeThisAccess.ts" />
/// <reference path="fixConstructorForDerivedNeedSuperCall.ts" />
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
/// <reference path="fixRemoveAbstractModifierInNonAbstractClass.ts" />