Merge pull request #1296 from twpayne/improve-type-checking

Improve type checking
This commit is contained in:
Tom Payne
2013-11-20 02:27:42 -08:00
15 changed files with 71 additions and 39 deletions
+8
View File
@@ -6,7 +6,10 @@
"accessControls": "ERROR", "accessControls": "ERROR",
"ambiguousFunctionDecl": "ERROR", "ambiguousFunctionDecl": "ERROR",
"checkDebuggerStatement": "WARNING", "checkDebuggerStatement": "WARNING",
"checkEventfulObjectDisposal": "ERROR",
"checkProvides": "ERROR",
"checkRegExp": "ERROR", "checkRegExp": "ERROR",
"checkStructDictInheritance": "ERROR",
"checkTypes": "ERROR", "checkTypes": "ERROR",
"checkVars": "ERROR", "checkVars": "ERROR",
"const": "ERROR", "const": "ERROR",
@@ -14,20 +17,25 @@
"deprecated": "ERROR", "deprecated": "ERROR",
"duplicate": "ERROR", "duplicate": "ERROR",
"duplicateMessage": "ERROR", "duplicateMessage": "ERROR",
"es3": "ERROR",
"es5Strict": "ERROR", "es5Strict": "ERROR",
"externsValidation": "ERROR", "externsValidation": "ERROR",
"fileoverviewTags": "ERROR", "fileoverviewTags": "ERROR",
"globalThis": "ERROR", "globalThis": "ERROR",
"internetExplorerChecks": "ERROR", "internetExplorerChecks": "ERROR",
"invalidCasts": "ERROR", "invalidCasts": "ERROR",
"misplacedTypeAnnotation": "ERROR",
"missingProperties": "ERROR", "missingProperties": "ERROR",
"nonStandardJsDocs": "ERROR", "nonStandardJsDocs": "ERROR",
"strictModuleDepCheck": "ERROR", "strictModuleDepCheck": "ERROR",
"suspiciousCode": "ERROR",
"typeInvalidation": "ERROR", "typeInvalidation": "ERROR",
"tweakValidation": "ERROR",
"undefinedNames": "ERROR", "undefinedNames": "ERROR",
"undefinedVars": "ERROR", "undefinedVars": "ERROR",
"unknownDefines": "ERROR", "unknownDefines": "ERROR",
"uselessCode": "ERROR", "uselessCode": "ERROR",
"violatedModuleDep": "ERROR",
"visibility": "ERROR" "visibility": "ERROR"
}, },
+2 -2
View File
@@ -75,7 +75,7 @@ ol.Collection = function(opt_array) {
/** /**
* @private * @private
* @type {Array} * @type {Array.<*>}
*/ */
this.array_ = opt_array || []; this.array_ = opt_array || [];
@@ -112,7 +112,7 @@ ol.Collection.prototype.extend = function(arr) {
/** /**
* Iterate over each element, calling the provided callback. * Iterate over each element, calling the provided callback.
* @param {function(this: S, T, number, Array.<T>): ?} f The function to call * @param {function(this: S, T, number, Array.<T>): *} f The function to call
* for every element. This function takes 3 arguments (the element, the * for every element. This function takes 3 arguments (the element, the
* index and the array). The return value is ignored. * index and the array). The return value is ignored.
* @param {S=} opt_obj The object to be used as the value of 'this' within f. * @param {S=} opt_obj The object to be used as the value of 'this' within f.
+4 -1
View File
@@ -111,7 +111,8 @@ ol.renderer.canvas.Map.prototype.renderFrame = function(frameState) {
for (i = 0, ii = layersArray.length; i < ii; ++i) { for (i = 0, ii = layersArray.length; i < ii; ++i) {
layer = layersArray[i]; layer = layersArray[i];
layerRenderer = this.getLayerRenderer(layer); layerRenderer =
/** @type {ol.renderer.canvas.Layer} */ (this.getLayerRenderer(layer));
layerState = layerStates[goog.getUid(layer)]; layerState = layerStates[goog.getUid(layer)];
if (!layerState.visible || if (!layerState.visible ||
layerState.sourceState != ol.source.State.READY || layerState.sourceState != ol.source.State.READY ||
@@ -133,6 +134,8 @@ ol.renderer.canvas.Map.prototype.renderFrame = function(frameState) {
var dy = goog.vec.Mat4.getElement(transform, 1, 3); var dy = goog.vec.Mat4.getElement(transform, 1, 3);
var dw = image.width * goog.vec.Mat4.getElement(transform, 0, 0); var dw = image.width * goog.vec.Mat4.getElement(transform, 0, 0);
var dh = image.height * goog.vec.Mat4.getElement(transform, 1, 1); var dh = image.height * goog.vec.Mat4.getElement(transform, 1, 1);
goog.asserts.assert(goog.isNumber(image.width));
goog.asserts.assert(goog.isNumber(image.height));
context.drawImage(image, 0, 0, image.width, image.height, context.drawImage(image, 0, 0, image.width, image.height,
Math.round(dx), Math.round(dy), Math.round(dw), Math.round(dh)); Math.round(dx), Math.round(dy), Math.round(dw), Math.round(dh));
} else { } else {
-1
View File
@@ -28,7 +28,6 @@ goog.inherits(ol.renderer.dom.Layer, ol.renderer.Layer);
/** /**
* @protected
* @return {!Element} Target. * @return {!Element} Target.
*/ */
ol.renderer.dom.Layer.prototype.getTarget = function() { ol.renderer.dom.Layer.prototype.getTarget = function() {
+2 -1
View File
@@ -93,7 +93,8 @@ ol.renderer.dom.Map.prototype.renderFrame = function(frameState) {
var layerKey; var layerKey;
for (layerKey in this.getLayerRenderers()) { for (layerKey in this.getLayerRenderers()) {
if (!(layerKey in layerStates)) { if (!(layerKey in layerStates)) {
layerRenderer = this.getLayerRendererByKey(layerKey); layerRenderer = /** @type {ol.renderer.dom.Layer} */
(this.getLayerRendererByKey(layerKey));
goog.dom.removeNode(layerRenderer.getTarget()); goog.dom.removeNode(layerRenderer.getTarget());
} }
} }
@@ -383,6 +383,7 @@ ol.renderer.dom.TileLayerZ_.prototype.removeTilesOutsideExtent =
function(extent, opt_tileRange) { function(extent, opt_tileRange) {
var tileRange = this.tileGrid_.getTileRangeForExtentAndZ( var tileRange = this.tileGrid_.getTileRangeForExtentAndZ(
extent, this.tileCoordOrigin_.z, opt_tileRange); extent, this.tileCoordOrigin_.z, opt_tileRange);
/** @type {Array.<ol.Tile>} */
var tilesToRemove = []; var tilesToRemove = [];
var tile, tileCoordKey; var tile, tileCoordKey;
for (tileCoordKey in this.tiles_) { for (tileCoordKey in this.tiles_) {
+10 -4
View File
@@ -129,10 +129,16 @@ ol.renderer.Layer.prototype.scheduleExpireCache =
function(frameState, tileSource) { function(frameState, tileSource) {
if (tileSource.canExpireCache()) { if (tileSource.canExpireCache()) {
frameState.postRenderFunctions.push( frameState.postRenderFunctions.push(
goog.partial(function(tileSource, map, frameState) { goog.partial(
var tileSourceKey = goog.getUid(tileSource).toString(); /**
tileSource.expireCache(frameState.usedTiles[tileSourceKey]); * @param {ol.source.Tile} tileSource Tile source.
}, tileSource)); * @param {ol.Map} map Map.
* @param {ol.FrameState} frameState Frame state.
*/
function(tileSource, map, frameState) {
var tileSourceKey = goog.getUid(tileSource).toString();
tileSource.expireCache(frameState.usedTiles[tileSourceKey]);
}, tileSource));
} }
}; };
@@ -114,11 +114,16 @@ ol.renderer.webgl.ImageLayer.prototype.renderFrame =
texture = this.createTexture_(image_); texture = this.createTexture_(image_);
if (!goog.isNull(this.texture)) { if (!goog.isNull(this.texture)) {
frameState.postRenderFunctions.push( frameState.postRenderFunctions.push(
goog.partial(function(gl, texture) { goog.partial(
if (!gl.isContextLost()) { /**
gl.deleteTexture(texture); * @param {WebGLRenderingContext} gl GL.
} * @param {WebGLTexture} texture Texture.
}, gl, this.texture)); */
function(gl, texture) {
if (!gl.isContextLost()) {
gl.deleteTexture(texture);
}
}, gl, this.texture));
} }
} }
} }
+12 -6
View File
@@ -124,12 +124,18 @@ ol.renderer.webgl.Layer.prototype.bindFramebuffer =
this.framebufferDimension != framebufferDimension) { this.framebufferDimension != framebufferDimension) {
frameState.postRenderFunctions.push( frameState.postRenderFunctions.push(
goog.partial(function(gl, framebuffer, texture) { goog.partial(
if (!gl.isContextLost()) { /**
gl.deleteFramebuffer(framebuffer); * @param {WebGLRenderingContext} gl GL.
gl.deleteTexture(texture); * @param {WebGLFramebuffer} framebuffer Framebuffer.
} * @param {WebGLTexture} texture Texture.
}, gl, this.framebuffer, this.texture)); */
function(gl, framebuffer, texture) {
if (!gl.isContextLost()) {
gl.deleteFramebuffer(framebuffer);
gl.deleteTexture(texture);
}
}, gl, this.framebuffer, this.texture));
var texture = gl.createTexture(); var texture = gl.createTexture();
gl.bindTexture(goog.webgl.TEXTURE_2D, texture); gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
@@ -279,6 +279,9 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
this.manageTilePyramid( this.manageTilePyramid(
frameState, tileSource, tileGrid, projection, extent, z, frameState, tileSource, tileGrid, projection, extent, z,
tileLayer.getPreload(), tileLayer.getPreload(),
/**
* @param {ol.Tile} tile Tile.
*/
function(tile) { function(tile) {
if (tile.getState() == ol.TileState.LOADED && if (tile.getState() == ol.TileState.LOADED &&
!mapRenderer.isTileTextureLoaded(tile) && !mapRenderer.isTileTextureLoaded(tile) &&
+2 -1
View File
@@ -61,7 +61,8 @@ ol.DebugTile_.prototype.getImage = function(opt_context) {
canvas.width = tileSize[0]; canvas.width = tileSize[0];
canvas.height = tileSize[1]; canvas.height = tileSize[1];
var context = canvas.getContext('2d'); var context = /** @type {CanvasRenderingContext2D} */
(canvas.getContext('2d'));
context.strokeStyle = 'black'; context.strokeStyle = 'black';
context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5); context.strokeRect(0.5, 0.5, tileSize[0] + 0.5, tileSize[1] + 0.5);
+6 -5
View File
@@ -10,6 +10,7 @@ goog.require('goog.object');
* Object's properties (e.g. 'hasOwnProperty' is not allowed as a key). Expiring * Object's properties (e.g. 'hasOwnProperty' is not allowed as a key). Expiring
* items from the cache is the responsibility of the user. * items from the cache is the responsibility of the user.
* @constructor * @constructor
* @template T
*/ */
ol.structs.LRUCache = function() { ol.structs.LRUCache = function() {
@@ -96,7 +97,7 @@ ol.structs.LRUCache.prototype.containsKey = function(key) {
/** /**
* @param {function(this: S, *, string, ol.structs.LRUCache): ?} f The function * @param {function(this: S, T, string, ol.structs.LRUCache): ?} f The function
* to call for every entry from the oldest to the newer. This function takes * to call for every entry from the oldest to the newer. This function takes
* 3 arguments (the entry value, the entry key and the LRUCache object). * 3 arguments (the entry value, the entry key and the LRUCache object).
* The return value is ignored. * The return value is ignored.
@@ -114,7 +115,7 @@ ol.structs.LRUCache.prototype.forEach = function(f, opt_obj) {
/** /**
* @param {string} key Key. * @param {string} key Key.
* @return {*} Value. * @return {T} Value.
*/ */
ol.structs.LRUCache.prototype.get = function(key) { ol.structs.LRUCache.prototype.get = function(key) {
var entry = this.entries_[key]; var entry = this.entries_[key];
@@ -175,7 +176,7 @@ ol.structs.LRUCache.prototype.getValues = function() {
/** /**
* @return {*} Last value. * @return {T} Last value.
*/ */
ol.structs.LRUCache.prototype.peekLast = function() { ol.structs.LRUCache.prototype.peekLast = function() {
goog.asserts.assert(!goog.isNull(this.oldest_)); goog.asserts.assert(!goog.isNull(this.oldest_));
@@ -193,7 +194,7 @@ ol.structs.LRUCache.prototype.peekLastKey = function() {
/** /**
* @return {*} value Value. * @return {T} value Value.
*/ */
ol.structs.LRUCache.prototype.pop = function() { ol.structs.LRUCache.prototype.pop = function() {
goog.asserts.assert(!goog.isNull(this.oldest_)); goog.asserts.assert(!goog.isNull(this.oldest_));
@@ -215,7 +216,7 @@ ol.structs.LRUCache.prototype.pop = function() {
/** /**
* @param {string} key Key. * @param {string} key Key.
* @param {*} value Value. * @param {T} value Value.
*/ */
ol.structs.LRUCache.prototype.set = function(key, value) { ol.structs.LRUCache.prototype.set = function(key, value) {
goog.asserts.assert(!(key in {})); goog.asserts.assert(!(key in {}));
+9 -8
View File
@@ -15,25 +15,26 @@ goog.require('goog.object');
* @see http://hg.python.org/cpython/file/2.7/Lib/heapq.py * @see http://hg.python.org/cpython/file/2.7/Lib/heapq.py
* *
* @constructor * @constructor
* @param {function(?): number} priorityFunction Priority function. * @param {function(T): number} priorityFunction Priority function.
* @param {function(?): string} keyFunction Key function. * @param {function(T): string} keyFunction Key function.
* @template T
*/ */
ol.structs.PriorityQueue = function(priorityFunction, keyFunction) { ol.structs.PriorityQueue = function(priorityFunction, keyFunction) {
/** /**
* @type {function(?): number} * @type {function(T): number}
* @private * @private
*/ */
this.priorityFunction_ = priorityFunction; this.priorityFunction_ = priorityFunction;
/** /**
* @type {function(?): string} * @type {function(T): string}
* @private * @private
*/ */
this.keyFunction_ = keyFunction; this.keyFunction_ = keyFunction;
/** /**
* @type {Array} * @type {Array.<T>}
* @private * @private
*/ */
this.elements_ = []; this.elements_ = [];
@@ -88,7 +89,7 @@ ol.structs.PriorityQueue.prototype.clear = function() {
/** /**
* Remove and return the highest-priority element. O(log N). * Remove and return the highest-priority element. O(log N).
* @return {*} Element. * @return {T} Element.
*/ */
ol.structs.PriorityQueue.prototype.dequeue = function() { ol.structs.PriorityQueue.prototype.dequeue = function() {
var elements = this.elements_; var elements = this.elements_;
@@ -112,7 +113,7 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
/** /**
* Enqueue an element. O(log N). * Enqueue an element. O(log N).
* @param {*} element Element. * @param {T} element Element.
*/ */
ol.structs.PriorityQueue.prototype.enqueue = function(element) { ol.structs.PriorityQueue.prototype.enqueue = function(element) {
goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_)); goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_));
@@ -197,7 +198,7 @@ ol.structs.PriorityQueue.prototype.isKeyQueued = function(key) {
/** /**
* @param {*} element Element. * @param {T} element Element.
* @return {boolean} Is queued. * @return {boolean} Is queued.
*/ */
ol.structs.PriorityQueue.prototype.isQueued = function(element) { ol.structs.PriorityQueue.prototype.isQueued = function(element) {
+1 -4
View File
@@ -16,7 +16,7 @@ ol.DEFAULT_TILE_CACHE_HIGH_WATER_MARK = 2048;
/** /**
* @constructor * @constructor
* @extends {ol.structs.LRUCache} * @extends {ol.structs.LRUCache.<ol.Tile>}
* @param {number=} opt_highWaterMark High water mark. * @param {number=} opt_highWaterMark High water mark.
*/ */
ol.TileCache = function(opt_highWaterMark) { ol.TileCache = function(opt_highWaterMark) {
@@ -49,9 +49,6 @@ ol.TileCache.prototype.expireCache = function(usedTiles) {
var tile, zKey; var tile, zKey;
while (this.canExpireCache()) { while (this.canExpireCache()) {
tile = /** @type {ol.Tile} */ (this.peekLast()); tile = /** @type {ol.Tile} */ (this.peekLast());
// TODO: Enforce ol.Tile in ol.TileCache#set
goog.asserts.assert(tile instanceof ol.Tile,
'ol.TileCache#expireCache only works with ol.Tile values.');
zKey = tile.tileCoord.z.toString(); zKey = tile.tileCoord.z.toString();
if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) { if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
break; break;
+1 -1
View File
@@ -17,7 +17,7 @@ ol.TilePriorityFunction;
/** /**
* @constructor * @constructor
* @extends {ol.structs.PriorityQueue} * @extends {ol.structs.PriorityQueue.<Array>}
* @param {ol.TilePriorityFunction} tilePriorityFunction * @param {ol.TilePriorityFunction} tilePriorityFunction
* Tile priority function. * Tile priority function.
* @param {function(): ?} tileChangeCallback * @param {function(): ?} tileChangeCallback