debt - remove URI.isURI and replace with instanceof-check, classes ftw

This commit is contained in:
Johannes Rieken 2016-01-29 18:43:08 +01:00
parent d3062aa162
commit a5c9aaf846
12 changed files with 17 additions and 66 deletions

View file

@ -306,7 +306,7 @@ export class URL extends URI implements objects.IEqualable {
return false;
}
return ((other instanceof URL) || URI.isURI(other));
return (other instanceof URL || other instanceof URI);
}
public hashCode():number {

View file

@ -315,55 +315,6 @@ export default class URI {
result._formatted = data._formatted;
return result;
}
public static isURI(thing: any): thing is URI {
if (thing instanceof URI) {
return true;
}
if(!thing) {
return false;
}
if (typeof (<URI>thing).scheme !== 'string') {
return false;
}
if (typeof (<URI>thing).authority !== 'string') {
return false;
}
if (typeof (<URI>thing).fsPath !== 'string') {
return false;
}
if (typeof (<URI>thing).query !== 'string') {
return false;
}
if (typeof (<URI>thing).fragment !== 'string') {
return false;
}
if (typeof (<URI>thing).with !== 'function') {
return false;
}
if (typeof (<URI>thing).withScheme !== 'function') {
return false;
}
if (typeof (<URI>thing).withAuthority !== 'function') {
return false;
}
if (typeof (<URI>thing).withPath !== 'function') {
return false;
}
if (typeof (<URI>thing).withQuery !== 'function') {
return false;
}
if (typeof (<URI>thing).withFragment !== 'function') {
return false;
}
if (typeof (<URI>thing).toString !== 'function') {
return false;
}
if (typeof (<URI>thing).toJSON !== 'function') {
return false;
}
return true;
}
}
interface _ISerializedURI {
@ -382,7 +333,7 @@ interface _ISerializedURI {
marshalling.registerMarshallingContribution({
canSerialize: (obj:any): boolean => {
return URI.isURI(obj);
return obj instanceof URI;
},
serialize: (url: URI, serialize: (obj: any) => any): _ISerializedURI => {

View file

@ -107,7 +107,7 @@ export module CommonEditorRegistry {
registerLanguageCommand(id, function(accessor, args) {
const {resource, position} = args;
if (!URI.isURI(resource) || !Position.isIPosition(position)) {
if (!(resource instanceof URI) || !Position.isIPosition(position)) {
throw illegalArgument();
}

View file

@ -45,7 +45,7 @@ export function getCodeLensData(model: IModel): TPromise<ICodeLensData[]> {
CommonEditorRegistry.registerLanguageCommand('_executeCodeLensProvider', function(accessor, args) {
const {resource} = args;
if (!URI.isURI(resource)) {
if (!(resource instanceof URI)) {
throw illegalArgument();
}

View file

@ -59,7 +59,7 @@ export function formatAfterKeystroke(model: IModel, position: IPosition, ch: str
CommonEditorRegistry.registerLanguageCommand('_executeFormatRangeProvider', function(accessor, args) {
const {resource, range, options} = args;
if (!URI.isURI(resource) || !Range.isIRange(range)) {
if (!(resource instanceof URI) || !Range.isIRange(range)) {
throw illegalArgument();
}
const model = accessor.get(IModelService).getModel(resource);
@ -71,7 +71,7 @@ CommonEditorRegistry.registerLanguageCommand('_executeFormatRangeProvider', func
CommonEditorRegistry.registerLanguageCommand('_executeFormatDocumentProvider', function(accessor, args) {
const {resource, options} = args;
if (!URI.isURI(resource)) {
if (!(resource instanceof URI)) {
throw illegalArgument('resource');
}
const model = accessor.get(IModelService).getModel(resource);

View file

@ -50,7 +50,7 @@ export function getQuickFixes(model: IModel, range: IRange): TPromise<IQuickFix2
CommonEditorRegistry.registerLanguageCommand('_executeCodeActionProvider', function(accessor, args) {
const {resource, range} = args;
if (!URI.isURI(resource) || !Range.isIRange(range)) {
if (!(resource instanceof URI) || !Range.isIRange(range)) {
throw illegalArgument();
}

View file

@ -86,7 +86,7 @@ function flatten(bucket: IOutlineEntry[], entries: IOutlineEntry[], overrideCont
CommonEditorRegistry.registerLanguageCommand('_executeDocumentSymbolProvider', function(accessor, args) {
const {resource} = args;
if (!URI.isURI(resource)) {
if (!(resource instanceof URI)) {
throw illegalArgument('resource');
}
const model = accessor.get(IModelService).getModel(resource);

View file

@ -377,7 +377,7 @@ export class FileTracker implements IWorkbenchContribution {
private getMatchingFileEditorInputFromInput(input: EditorInput, updatedFiles: FileChangesEvent): FileEditorInput;
private getMatchingFileEditorInputFromInput(input: EditorInput, arg: any): FileEditorInput {
if (input instanceof FileEditorInput) {
if (URI.isURI(arg)) {
if (arg instanceof URI) {
let deletedResource = <URI>arg;
if (this.containsResource(input, deletedResource)) {
return input;

View file

@ -224,7 +224,7 @@ export class WorkingFilesModel implements IWorkingFilesModel {
let resource: uri;
if (arg1 instanceof WorkingFileEntry) {
resource = (<WorkingFileEntry>arg1).resource;
} else if (uri.isURI(arg1)) {
} else if (arg1 instanceof uri) {
resource = <uri>arg1;
} else {
resource = (<IFileStat>arg1).resource;

View file

@ -65,7 +65,7 @@ suite('Files - FileEditorInput', () => {
assert.strictEqual('file.js', input.getName());
assert.strictEqual(toResource('/foo/bar/file.js').fsPath, input.getResource().fsPath);
assert(URI.isURI(input.getResource()));
assert(input.getResource() instanceof URI);
input = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar.html'), 'text/html', void 0);

View file

@ -132,7 +132,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
// Support opening foreign resources (such as a http link that points outside of the workbench)
let resourceInput = <IResourceInput>input;
if (URI.isURI(resourceInput.resource)) {
if (resourceInput.resource instanceof URI) {
let schema = resourceInput.resource.scheme;
if (schema === network.schemas.http || schema === network.schemas.https) {
window.open(resourceInput.resource.toString());
@ -242,7 +242,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
// Base Text Editor Support for inmemory resources
let resourceInput = <IResourceInput>input;
if (URI.isURI(resourceInput.resource) && resourceInput.resource.scheme === network.schemas.inMemory) {
if (resourceInput.resource instanceof URI && resourceInput.resource.scheme === network.schemas.inMemory) {
// For in-memory resources we only support to resolve the input from the current active editor
// because the workbench does not track editor models by in memory URL. This concept is only
@ -281,17 +281,17 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
}
// Untitled file support
else if (URI.isURI(resourceInput.resource) && (resourceInput.resource.scheme === UntitledEditorInput.SCHEMA)) {
else if (resourceInput.resource instanceof URI && (resourceInput.resource.scheme === UntitledEditorInput.SCHEMA)) {
return TPromise.as<EditorInput>(this.untitledEditorService.createOrGet(resourceInput.resource));
}
// Base Text Editor Support for file resources
else if (this.fileInputDescriptor && URI.isURI(resourceInput.resource) && resourceInput.resource.scheme === network.schemas.file) {
else if (this.fileInputDescriptor && resourceInput.resource instanceof URI && resourceInput.resource.scheme === network.schemas.file) {
return this.createFileInput(resourceInput.resource, resourceInput.mime);
}
// Treat an URI as ResourceEditorInput
else if (URI.isURI(resourceInput.resource)) {
else if (resourceInput.resource instanceof URI) {
return TPromise.as(this.instantiationService.createInstance(ResourceEditorInput,
basename(resourceInput.resource.fsPath),
dirname(resourceInput.resource.fsPath),

View file

@ -374,7 +374,7 @@ export class FileService implements files.IFileService {
private toAbsolutePath(arg1: uri | files.IFileStat): string {
let resource: uri;
if (uri.isURI(arg1)) {
if (arg1 instanceof uri) {
resource = <uri>arg1;
} else {
resource = (<files.IFileStat>arg1).resource;