本文整理汇总了Java中com.google.javascript.rhino.JSDocInfoBuilder.maybeCopyFrom方法的典型用法代码示例。如果您正苦于以下问题:Java JSDocInfoBuilder.maybeCopyFrom方法的具体用法?Java JSDocInfoBuilder.maybeCopyFrom怎么用?Java JSDocInfoBuilder.maybeCopyFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.JSDocInfoBuilder
的用法示例。
在下文中一共展示了JSDocInfoBuilder.maybeCopyFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: visit
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (isBehavior(n)) {
if (!NodeUtil.isNameDeclaration(n) && !n.isAssign()) {
compiler.report(JSError.make(n, PolymerPassErrors.POLYMER_UNQUALIFIED_BEHAVIOR));
return;
}
// Add @nocollapse.
JSDocInfoBuilder newDocs = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
newDocs.recordNoCollapse();
n.setJSDocInfo(newDocs.build());
Node behaviorValue = n.getSecondChild();
if (NodeUtil.isNameDeclaration(n)) {
behaviorValue = n.getFirstFirstChild();
}
suppressBehavior(behaviorValue);
}
}
示例3: getConstructorDoc
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
/** @return The proper constructor doc for the Polymer call. */
private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) {
JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info);
constructorDoc.recordConstructor();
JSTypeExpression baseType = new JSTypeExpression(
new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))),
PolymerPass.VIRTUAL_FILE);
constructorDoc.recordBaseType(baseType);
String interfaceName = getInterfaceName(cls);
JSTypeExpression interfaceType = new JSTypeExpression(
new Node(Token.BANG, IR.string(interfaceName)), PolymerPass.VIRTUAL_FILE);
constructorDoc.recordImplementedInterface(interfaceType);
return constructorDoc;
}
示例4: appendPropertiesToBlock
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
/**
* Appends all properties in the ClassDefinition to the prototype of the custom element.
*/
private void appendPropertiesToBlock(
final PolymerClassDefinition cls, Node block, String basePath) {
for (MemberDefinition prop : cls.props) {
Node propertyNode = IR.exprResult(
NodeUtil.newQName(compiler, basePath + prop.name.getString()));
// If a property string is quoted, make sure the added prototype properties are also quoted
if (prop.name.isQuotedString()) {
continue;
}
propertyNode.useSourceInfoIfMissingFromForTree(prop.name);
JSDocInfoBuilder info = JSDocInfoBuilder.maybeCopyFrom(prop.info);
JSTypeExpression propType = PolymerPassStaticUtils.getTypeFromProperty(prop, compiler);
if (propType == null) {
return;
}
info.recordType(propType);
propertyNode.getFirstChild().setJSDocInfo(info.build());
block.addChildToBack(propertyNode);
}
}
示例5: visitMethod
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
/**
* Handles transpilation of a standard class member function. Getters, setters, and the
* constructor are not handled here.
*/
private void visitMethod(Node member, ClassDeclarationMetadata metadata) {
Node qualifiedMemberAccess = getQualifiedMemberAccess(
member,
NodeUtil.newQName(compiler, metadata.fullClassName),
NodeUtil.newQName(compiler, metadata.fullClassName + ".prototype"));
Node method = member.getLastChild().detach();
Node assign = IR.assign(qualifiedMemberAccess, method);
assign.useSourceInfoIfMissingFromForTree(member);
JSDocInfo info = member.getJSDocInfo();
if (member.isStaticMember() && NodeUtil.referencesThis(assign.getLastChild())) {
JSDocInfoBuilder memberDoc = JSDocInfoBuilder.maybeCopyFrom(info);
memberDoc.recordThisType(
new JSTypeExpression(new Node(Token.BANG, new Node(Token.QMARK)),
member.getSourceFileName()));
info = memberDoc.build();
}
if (info != null) {
assign.setJSDocInfo(info);
}
Node newNode = NodeUtil.newExpr(assign);
metadata.insertNodeAndAdvance(newNode);
}
示例6: visitNamespaceDeclaration
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void visitNamespaceDeclaration(NodeTraversal t, Node n, Node parent) {
popNamespace(n, parent);
for (Node name = NodeUtil.getRootOfQualifiedName(n.getFirstChild()); name != n;
name = name.getParent()) {
String fullName = maybePrependCurrNamespace(name.getQualifiedName());
if (!convertedNamespaces.contains(fullName)) {
JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
doc.recordConstancy();
Node namespaceDec = NodeUtil.newQNameDeclaration(
compiler, fullName, IR.objectlit(), doc.build()).useSourceInfoFromForTree(n);
parent.addChildBefore(namespaceDec, n);
convertedNamespaces.add(fullName);
}
}
replaceWithNodes(t, n, n.getLastChild().children());
}
示例7: maybeAddGenerics
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void maybeAddGenerics(Node n, Node jsDocNode) {
Node name = n.getFirstChild();
Node generics = (Node) name.getProp(Node.GENERIC_TYPE_LIST);
if (generics != null) {
JSDocInfoBuilder doc = JSDocInfoBuilder.maybeCopyFrom(jsDocNode.getJSDocInfo());
// Discard the type bound (the "extends" part) for now
for (Node typeName : generics.children()) {
doc.recordTemplateTypeName(typeName.getString());
if (typeName.hasChildren()) {
compiler.report(JSError.make(name, CANNOT_CONVERT_BOUNDED_GENERICS));
typeName.removeChildren();
}
}
name.removeProp(Node.GENERIC_TYPE_LIST);
jsDocNode.setJSDocInfo(doc.build());
}
}
示例8: visitTypeAlias
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void visitTypeAlias(NodeTraversal t, Node n, Node parent) {
String alias = n.getString();
if (t.getScope().isDeclared(alias, true)) {
compiler.report(
JSError.make(n, TYPE_ALIAS_ALREADY_DECLARED, alias));
}
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
builder.recordTypedef(new JSTypeExpression(
convertWithLocation(n.getFirstChild()), n.getSourceFileName()));
Node newName =
maybeGetQualifiedNameNode(IR.name(n.getString())).useSourceInfoIfMissingFromForTree(n);
Node newDec1 = NodeUtil.newQNameDeclaration(
compiler,
newName.getQualifiedName(),
null,
builder.build()).useSourceInfoFromForTree(n);
parent.replaceChild(n, newDec1);
t.reportCodeChange();
}
示例9: visitVarInsideNamespace
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void visitVarInsideNamespace(NodeTraversal t, Node n, Node parent) {
if (currNamespace != null) {
Node insertPoint = n;
for (Node child : n.children()) {
Node name = child;
String oldName = name.getString();
String qName = maybePrependCurrNamespace(oldName);
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(child.getJSDocInfo());
if (n.isConst()) {
builder.recordConstancy();
}
Node newDec = NodeUtil.newQNameDeclaration(
compiler,
qName,
child.removeFirstChild(),
builder.build()).useSourceInfoFromForTree(n);
parent.addChildAfter(newDec, insertPoint);
insertPoint = newDec;
}
n.detach();
t.reportCodeChange();
}
}
示例10: extractInlineJSDoc
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private static void extractInlineJSDoc(Node srcDeclaration, Node srcName, Node destDeclaration) {
JSDocInfo existingInfo = srcDeclaration.getJSDocInfo();
if (existingInfo == null) {
// Extract inline JSDoc from "src" and add it to the "dest" node.
existingInfo = srcName.getJSDocInfo();
srcName.setJSDocInfo(null);
}
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(existingInfo);
destDeclaration.setJSDocInfo(builder.build());
}
示例11: maybeAddConstJSDoc
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private static void maybeAddConstJSDoc(Node srcDeclaration, Node srcParent, Node srcName,
Node destDeclaration) {
if (srcDeclaration.isConst()
// Don't add @const for the left side of a for/in. If we do we get warnings from the NTI.
&& !(srcParent.isForIn() && srcDeclaration == srcParent.getFirstChild())) {
extractInlineJSDoc(srcDeclaration, srcName, destDeclaration);
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(destDeclaration.getJSDocInfo());
builder.recordConstancy();
destDeclaration.setJSDocInfo(builder.build());
}
}
示例12: visitEnum
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void visitEnum(NodeTraversal t, Node n, Node parent) {
Node name = n.getFirstChild();
Node members = n.getLastChild();
double nextValue = 0;
Node[] stringKeys = new Node[members.getChildCount()];
int i = 0;
for (Node child = members.getFirstChild(); child != null; child = child.getNext(), i++) {
if (child.hasChildren()) {
nextValue = child.getFirstChild().getDouble() + 1;
} else {
child.addChildToFront(IR.number(nextValue++));
}
stringKeys[i] = child;
}
members.detachChildren();
String oldName = name.getString();
String qName = maybePrependCurrNamespace(oldName);
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
builder.recordEnumParameterType(
new JSTypeExpression(IR.string("number"), n.getSourceFileName()));
Node newDec = NodeUtil.newQNameDeclaration(
compiler,
qName,
IR.objectlit(stringKeys),
builder.build()).useSourceInfoFromForTree(n);
n.setJSDocInfo(null);
parent.replaceChild(n, newDec);
t.reportCodeChange();
}
示例13: maybeAddVisibility
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void maybeAddVisibility(Node n) {
Visibility access = (Visibility) n.getProp(Node.ACCESS_MODIFIER);
if (access != null) {
if (n.isComputedProp()) {
compiler.report(JSError.make(n, COMPUTED_PROP_ACCESS_MODIFIER));
}
JSDocInfoBuilder memberDoc = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo());
memberDoc.recordVisibility(access);
n.setJSDocInfo(memberDoc.build());
n.removeProp(Node.ACCESS_MODIFIER);
}
}
示例14: maybeVisitColonType
import com.google.javascript.rhino.JSDocInfoBuilder; //导入方法依赖的package包/类
private void maybeVisitColonType(NodeTraversal t, Node n, Node jsDocNode) {
Node type = n.getDeclaredTypeExpression();
boolean hasColonType = type != null;
if (n.isRest() && hasColonType) {
type = new Node(Token.ELLIPSIS, convertWithLocation(type.removeFirstChild()));
} else if (n.isMemberVariableDef()) {
if (type != null) {
type = maybeProcessOptionalProperty(n, type);
}
} else {
type = maybeProcessOptionalParameter(n, type);
}
if (type == null) {
return;
}
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(jsDocNode.getJSDocInfo());
JSTypeExpression typeExpression = new JSTypeExpression(type, n.getSourceFileName());
switch (n.getToken()) {
case FUNCTION:
builder.recordReturnType(typeExpression);
break;
case MEMBER_VARIABLE_DEF:
builder.recordType(typeExpression);
break;
default:
builder.recordType(typeExpression);
builder.recordInlineType();
}
jsDocNode.setJSDocInfo(builder.build());
if (hasColonType) {
n.setDeclaredTypeExpression(null);
t.reportCodeChange();
}
}
示例15: 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);
}
}
}