Java Code Examples for com.google.javascript.rhino.JSDocInfo#getType()
The following examples show how to use
com.google.javascript.rhino.JSDocInfo#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeAnnotationPass.java From clutz with MIT License | 6 votes |
private void maybeSetInlineTypeExpression( Node nameNode, Node commentNode, JSDocInfo docInfo, boolean isReturnType) { if (docInfo == null) { return; } JSTypeExpression type = docInfo.getType(); if (type == null) { return; } setTypeExpression(nameNode, type, isReturnType); // Remove the part of comment that sets the inline type. String toRemove = docInfo.getOriginalCommentString(); List<GeneralComment> comments = nodeComments.getComments(commentNode); if (comments == null) { return; } List<GeneralComment> newComments = Lists.newArrayList(); for (GeneralComment c : comments) { String newText = c.getText().replaceFirst("\\n?" + Pattern.quote(toRemove), ""); newComments.add(GeneralComment.from(newText, c.getOffset())); } nodeComments.setComments(commentNode, newComments); compiler.reportChangeToEnclosingScope(commentNode); }
Example 2
Source File: DeclarationGenerator.java From clutz with MIT License | 5 votes |
/** * Returns whether the author tried to express the concept of a namespace in Closure. TS has a * first-class keyword for it, but in Closure we need to infer it from the JSDoc. Roughly, a * namespace is a static object used for hierarchically organizing values. * * <p>TODO(rado): this might still have some false positives. A more robust check would also * verify that there are child properties (an empty namespace is not useful). */ private boolean isLikelyNamespace(JSDocInfo doc) { if (doc == null) return false; // Authors should prefer @const to express a namespace in externs, and just goog.provide it // in non-extern code. However, there are still usages of @type {Object}. JSTypeExpression type = doc.getType(); if (type != null && type.getRoot().isString() && type.getRoot().getString().equals("Object")) { return true; } return doc.hasConstAnnotation() && !doc.hasType(); }
Example 3
Source File: Closure_70_TypedScopeCreator_t.java From coming with MIT License | 5 votes |
/** * Handle typedefs. * @param t The current traversal. * @param candidate An ASSIGN or VAR node. */ // TODO(nicksantos): Kill this. private void checkForOldStyleTypedef(NodeTraversal t, Node candidate) { // old-style typedefs String typedef = codingConvention.identifyTypeDefAssign(candidate); if (typedef != null) { // TODO(nicksantos|user): This is a terrible, terrible hack // to bail out on recusive typedefs. We'll eventually need // to handle these properly. typeRegistry.declareType(typedef, getNativeType(UNKNOWN_TYPE)); JSDocInfo info = candidate.getJSDocInfo(); JSType realType = null; if (info != null && info.getType() != null) { realType = info.getType().evaluate(scope, typeRegistry); } if (realType == null) { compiler.report( JSError.make( t.getSourceName(), candidate, MALFORMED_TYPEDEF, typedef)); } typeRegistry.overwriteDeclaredType(typedef, realType); // Duplicate typedefs get handled when we try to register // this typedef in the scope. } }
Example 4
Source File: Closure_70_TypedScopeCreator_s.java From coming with MIT License | 5 votes |
/** * Handle typedefs. * @param t The current traversal. * @param candidate An ASSIGN or VAR node. */ // TODO(nicksantos): Kill this. private void checkForOldStyleTypedef(NodeTraversal t, Node candidate) { // old-style typedefs String typedef = codingConvention.identifyTypeDefAssign(candidate); if (typedef != null) { // TODO(nicksantos|user): This is a terrible, terrible hack // to bail out on recusive typedefs. We'll eventually need // to handle these properly. typeRegistry.declareType(typedef, getNativeType(UNKNOWN_TYPE)); JSDocInfo info = candidate.getJSDocInfo(); JSType realType = null; if (info != null && info.getType() != null) { realType = info.getType().evaluate(scope, typeRegistry); } if (realType == null) { compiler.report( JSError.make( t.getSourceName(), candidate, MALFORMED_TYPEDEF, typedef)); } typeRegistry.overwriteDeclaredType(typedef, realType); // Duplicate typedefs get handled when we try to register // this typedef in the scope. } }
Example 5
Source File: Closure_95_TypedScopeCreator_s.java From coming with MIT License | 5 votes |
/** * Handle typedefs. * @param t The current traversal. * @param candidate An ASSIGN or VAR node. */ // TODO(nicksantos): Kill this. private void checkForOldStyleTypedef(NodeTraversal t, Node candidate) { // old-style typedefs String typedef = codingConvention.identifyTypeDefAssign(candidate); if (typedef != null) { // TODO(nicksantos|user): This is a terrible, terrible hack // to bail out on recusive typedefs. We'll eventually need // to handle these properly. typeRegistry.forwardDeclareType(typedef); JSDocInfo info = candidate.getJSDocInfo(); JSType realType = null; if (info != null && info.getType() != null) { realType = info.getType().evaluate(scope, typeRegistry); } if (realType == null) { compiler.report( JSError.make( t.getSourceName(), candidate, MALFORMED_TYPEDEF, typedef)); } typeRegistry.declareType(typedef, realType); // Duplicate typedefs get handled when we try to register // this typedef in the scope. } }
Example 6
Source File: Closure_95_TypedScopeCreator_t.java From coming with MIT License | 5 votes |
/** * Handle typedefs. * @param t The current traversal. * @param candidate An ASSIGN or VAR node. */ // TODO(nicksantos): Kill this. private void checkForOldStyleTypedef(NodeTraversal t, Node candidate) { // old-style typedefs String typedef = codingConvention.identifyTypeDefAssign(candidate); if (typedef != null) { // TODO(nicksantos|user): This is a terrible, terrible hack // to bail out on recusive typedefs. We'll eventually need // to handle these properly. typeRegistry.forwardDeclareType(typedef); JSDocInfo info = candidate.getJSDocInfo(); JSType realType = null; if (info != null && info.getType() != null) { realType = info.getType().evaluate(scope, typeRegistry); } if (realType == null) { compiler.report( JSError.make( t.getSourceName(), candidate, MALFORMED_TYPEDEF, typedef)); } typeRegistry.declareType(typedef, realType); // Duplicate typedefs get handled when we try to register // this typedef in the scope. } }