本文整理汇总了Java中com.google.javascript.rhino.JSDocInfoBuilder.addSuppression方法的典型用法代码示例。如果您正苦于以下问题:Java JSDocInfoBuilder.addSuppression方法的具体用法?Java JSDocInfoBuilder.addSuppression怎么用?Java JSDocInfoBuilder.addSuppression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.JSDocInfoBuilder
的用法示例。
在下文中一共展示了JSDocInfoBuilder.addSuppression方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: suppressDefaultValues
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void suppressDefaultValues(Node behaviorValue) {
for (MemberDefinition property :
PolymerPassStaticUtils.extractProperties(
behaviorValue, PolymerClassDefinition.DefinitionType.ObjectLiteral, compiler)) {
if (!property.value.isObjectLit()) {
continue;
}
Node defaultValue = NodeUtil.getFirstPropMatchingKey(property.value, "value");
if (defaultValue == null || !defaultValue.isFunction()) {
continue;
}
Node defaultValueKey = defaultValue.getParent();
JSDocInfoBuilder suppressDoc =
JSDocInfoBuilder.maybeCopyFrom(defaultValueKey.getJSDocInfo());
suppressDoc.addSuppression("checkTypes");
suppressDoc.addSuppression("globalThis");
suppressDoc.addSuppression("visibility");
defaultValueKey.setJSDocInfo(suppressDoc.build());
}
}
示例2: copyDeclarations
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
/**
* When static get/set properties are transpiled, in addition to the Object.defineProperties, they
* are declared with stub GETPROP declarations so that the type checker understands that these
* properties exist on the class.
* When subclassing, we also need to declare these properties on the subclass so that the type
* checker knows they exist.
*/
private void copyDeclarations(
JavascriptClass superClass, JavascriptClass subClass, Node inheritsCall) {
for (Node staticGetProp : superClass.staticFieldAccess) {
checkState(staticGetProp.isGetProp());
String memberName = staticGetProp.getLastChild().getString();
// We only copy declarations that have corresponding Object.defineProperties
if (!superClass.definedProperties.contains(memberName)) {
continue;
}
// If the subclass already declares the property no need to redeclare it.
if (isOverriden(subClass, memberName)) {
continue;
}
Node subclassNameNode = inheritsCall.getSecondChild();
Node getprop = IR.getprop(subclassNameNode.cloneTree(), IR.string(memberName));
JSDocInfoBuilder info = JSDocInfoBuilder.maybeCopyFrom(staticGetProp.getJSDocInfo());
JSTypeExpression unknown = new JSTypeExpression(new Node(Token.QMARK), "<synthetic>");
info.recordType(unknown); // In case there wasn't a type specified on the base class.
info.addSuppression("visibility");
getprop.setJSDocInfo(info.build());
Node declaration = IR.exprResult(getprop);
declaration.useSourceInfoIfMissingFromForTree(inheritsCall);
Node parent = inheritsCall.getParent();
parent.getParent().addChildBefore(declaration, parent);
compiler.reportChangeToEnclosingScope(parent);
// Copy over field access so that subclasses of this subclass can also make the declarations
if (!subClass.definedProperties.contains(memberName)) {
subClass.staticFieldAccess.add(getprop);
subClass.definedProperties.add(memberName);
}
}
}
示例3: addBehaviorSuppressions
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void addBehaviorSuppressions(Node behaviorValue) {
for (Node keyNode : behaviorValue.children()) {
if (keyNode.getFirstChild().isFunction()) {
keyNode.removeProp(Node.JSDOC_INFO_PROP);
JSDocInfoBuilder suppressDoc = new JSDocInfoBuilder(true);
suppressDoc.addSuppression("checkTypes");
suppressDoc.addSuppression("globalThis");
suppressDoc.addSuppression("visibility");
keyNode.setJSDocInfo(suppressDoc.build());
}
}
suppressDefaultValues(behaviorValue);
}
示例4: ensureLibraryInjected
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
@Override
Node ensureLibraryInjected(String resourceName, boolean force) {
boolean doNotInject =
!force && (options.skipNonTranspilationPasses || options.preventLibraryInjection);
if (injectedLibraries.containsKey(resourceName) || doNotInject) {
return lastInjectedLibrary;
}
// Load/parse the code.
String originalCode = ResourceLoader.loadTextResource(
Compiler.class, "js/" + resourceName + ".js");
Node ast = parseSyntheticCode(" [synthetic:" + resourceName + "] ", originalCode);
// Look for string literals of the form 'require foo bar' or 'externs baz' or 'normalize'.
// As we process each one, remove it from its parent.
for (Node node = ast.getFirstChild();
node != null && node.isExprResult() && node.getFirstChild().isString();
node = ast.getFirstChild()) {
String directive = node.getFirstChild().getString();
List<String> words = Splitter.on(' ').limit(2).splitToList(directive);
switch (words.get(0)) {
case "use":
// 'use strict' is ignored (and deleted).
break;
case "require":
// 'require lib'; pulls in the named library before this one.
ensureLibraryInjected(words.get(1), force);
break;
case "declare":
// 'declare name'; adds the name to the externs (with no type information).
// Note that we could simply add the entire externs library, but that leads to
// potentially-surprising behavior when the externs that are present depend on
// whether or not a polyfill is used.
Node var = IR.var(IR.name(words.get(1)));
JSDocInfoBuilder jsdoc = new JSDocInfoBuilder(false);
// Suppress duplicate-var warning in case this name is already defined in the externs.
jsdoc.addSuppression("duplicate");
var.setJSDocInfo(jsdoc.build());
getSynthesizedExternsInputAtEnd()
.getAstRoot(this)
.addChildToBack(var);
break;
default:
throw new RuntimeException("Bad directive: " + directive);
}
ast.removeChild(node);
}
// If we've already started optimizations, then we need to normalize this.
if (getLifeCycleStage().isNormalized()) {
Normalize.normalizeSyntheticCode(this, ast, "jscomp_" + resourceName + "_");
}
// Insert the code immediately after the last-inserted runtime library.
Node lastChild = ast.getLastChild();
for (Node child = ast.getFirstChild(); child != null; child = child.getNext()) {
NodeUtil.markNewScopesChanged(child, this);
}
Node firstChild = ast.removeChildren();
if (firstChild == null) {
// Handle require-only libraries.
return lastInjectedLibrary;
}
Node parent = getNodeForCodeInsertion(null);
if (lastInjectedLibrary == null) {
parent.addChildrenToFront(firstChild);
} else {
parent.addChildrenAfter(firstChild, lastInjectedLibrary);
}
lastInjectedLibrary = lastChild;
injectedLibraries.put(resourceName, lastChild);
reportChangeToEnclosingScope(parent);
return lastChild;
}
示例5: copyStaticMembers
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void copyStaticMembers(
JavascriptClass superClass, JavascriptClass subClass, Node inheritsCall,
FindStaticMembers findStaticMembers) {
for (Node staticMember : superClass.staticMembers) {
checkState(staticMember.isAssign(), staticMember);
String memberName = staticMember.getFirstChild().getLastChild().getString();
if (superClass.definedProperties.contains(memberName)) {
continue;
}
if (isOverriden(subClass, memberName)) {
continue;
}
if (findStaticMembers.isBefore(inheritsCall, staticMember)) {
// Don't copy members that are defined after the $jscomp.inherits call,
// since they will not work correctly in IE<11, where static inheritance
// is done by copying, rather than prototype manipulation.
continue;
}
JSDocInfoBuilder info = JSDocInfoBuilder.maybeCopyFrom(staticMember.getJSDocInfo());
Node function = staticMember.getLastChild();
Node sourceInfoNode = function;
if (function.isFunction()) {
sourceInfoNode = function.getFirstChild();
Node params = NodeUtil.getFunctionParameters(function);
checkState(params.isParamList(), params);
for (Node param : params.children()) {
if (param.getJSDocInfo() != null) {
String name = param.getString();
info.recordParameter(name, param.getJSDocInfo().getType());
}
}
}
Node subclassNameNode = inheritsCall.getSecondChild();
Node superclassNameNode = subclassNameNode.getNext();
Node assign =
IR.assign(
IR.getprop(subclassNameNode.cloneTree(), IR.string(memberName)),
IR.getprop(superclassNameNode.cloneTree(), IR.string(memberName)));
info.addSuppression("visibility");
assign.setJSDocInfo(info.build());
Node exprResult = IR.exprResult(assign);
exprResult.useSourceInfoIfMissingFromForTree(sourceInfoNode);
Node inheritsExpressionResult = inheritsCall.getParent();
inheritsExpressionResult.getParent().addChildAfter(exprResult, inheritsExpressionResult);
compiler.reportChangeToEnclosingScope(inheritsExpressionResult);
// Add the static member to the subclass so that subclasses also copy this member.
subClass.staticMembers.add(assign);
}
}