本文整理汇总了Java中com.google.javascript.jscomp.NodeUtil.isNameDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java NodeUtil.isNameDeclaration方法的具体用法?Java NodeUtil.isNameDeclaration怎么用?Java NodeUtil.isNameDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.NodeUtil
的用法示例。
在下文中一共展示了NodeUtil.isNameDeclaration方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public final void visit(NodeTraversal nodeTraversal, Node n, Node parent) {
if (n.isCall()
&& parent.isExprResult()
&& matchName(n.getFirstChild())) {
calls.add(parent);
} else if (NodeUtil.isNameDeclaration(parent)
&& n.hasChildren()
&& n.getLastChild().isCall()
&& matchName(n.getLastChild().getFirstChild())) {
checkState(n.isName() || n.isDestructuringLhs(), n);
calls.add(parent);
} else if (!calls.isEmpty() && parent != null && NodeUtil.isStatement(parent)) {
// Reached a non-goog.(require|provide|forwardDeclare) statement, so stop.
finished = true;
}
}
示例2: visit
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, final Node n, final Node parent) {
if (NodeUtil.isNameDeclaration(n)) {
RequireDetector detector = new RequireDetector();
traverseEs6(t.getCompiler(), n, detector);
if (detector.foundRequire) {
Node addAfter = n;
for (Node last = n.getLastChild();
last != null && last != n.getFirstChild();
last = n.getLastChild()) {
n.removeChild(last);
Node newDecl = declaration(last, n.getToken()).srcrefTree(last);
parent.addChildAfter(newDecl, addAfter);
addAfter = newDecl;
t.reportCodeChange();
}
}
}
}
示例3: visit
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.isScript()) {
visitScript();
return;
}
if (n.isClass() || n.isFunction() || NodeUtil.isNameDeclaration(n)) {
visitInternalNameDefinition(n, parent);
}
if (n.isExport()) {
visitExport(n);
}
if (n.isImport()) {
visitImport(n);
}
}
示例4: isFunctionThatShouldHaveJsDoc
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
/**
* Whether the given function should have JSDoc. True if it's a function declared
* in the global scope, or a method on a class which is declared in the global scope.
*/
private boolean isFunctionThatShouldHaveJsDoc(NodeTraversal t, Node function) {
if (!(t.inGlobalHoistScope() || t.inModuleScope())) {
return false;
}
if (NodeUtil.isFunctionDeclaration(function)) {
return true;
}
if (NodeUtil.isNameDeclaration(function.getGrandparent()) || function.getParent().isAssign()) {
return true;
}
if (function.getParent().isExport()) {
return true;
}
if (function.getGrandparent().isClassMembers()) {
Node memberNode = function.getParent();
if (memberNode.isMemberFunctionDef()) {
// A constructor with no parameters doesn't need JSDoc,
// but all other member functions do.
return !isConstructorWithoutParameters(function);
} else if (memberNode.isGetterDef() || memberNode.isSetterDef()) {
return true;
}
}
if (function.getGrandparent().isObjectLit()
&& NodeUtil.isCallTo(function.getGrandparent().getParent(), "Polymer")) {
return true;
}
return false;
}
示例5: getNamespace
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
private static final String getNamespace(Node requireStatement) {
if (requireStatement.isExprResult()) {
// goog.require('a.b.c');
return requireStatement.getFirstChild().getLastChild().getString();
} else if (NodeUtil.isNameDeclaration(requireStatement)) {
if (requireStatement.getFirstChild().isName()) {
// const x = goog.require('a.b.c');
return requireStatement.getFirstFirstChild().getLastChild().getString();
} else if (requireStatement.getFirstChild().isDestructuringLhs()) {
// const {x} = goog.require('a.b.c');
return requireStatement.getFirstChild().getLastChild().getLastChild().getString();
}
}
throw new IllegalArgumentException("Unexpected node " + requireStatement);
}
示例6: apply
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public String apply(Node n) {
String key = null;
boolean isForwardDeclare = false;
if (NodeUtil.isNameDeclaration(n)) {
if (n.getFirstChild().isName()) {
// Case 1:
// var x = goog.require('w.x');
// or
// var x = goog.forwardDeclare('w.x');
key = n.getFirstChild().getString();
if (n.getFirstFirstChild()
.getFirstChild()
.matchesQualifiedName("goog.forwardDeclare")) {
isForwardDeclare = true;
}
} else if (n.getFirstChild().isDestructuringLhs()) {
// Case 2: var {y} = goog.require('w.x');
// All case 2 nodes should come after all case 1 nodes. ('{' sorts after a-z)
Node pattern = n.getFirstFirstChild();
checkState(pattern.isObjectPattern(), pattern);
Node call = n.getFirstChild().getLastChild();
checkState(call.isCall(), call);
checkState(
call.getFirstChild().matchesQualifiedName("goog.require"), call.getFirstChild());
if (!pattern.hasChildren()) {
key = "{";
} else {
key = "{" + pattern.getFirstChild().getString();
}
}
} else if (n.isExprResult()) {
// Case 3, one of:
// goog.provide('a.b.c');
// goog.require('a.b.c');
// goog.forwardDeclare('a.b.c');
// All case 3 nodes should come after case 1 and 2 nodes, so prepend
// '|' which sorts after '{'
key = "|" + n.getFirstChild().getLastChild().getString();
if (n.getFirstFirstChild().matchesQualifiedName("goog.forwardDeclare")) {
isForwardDeclare = true;
}
} else {
throw new IllegalArgumentException("Unexpected node " + n);
}
// Make sure all forwardDeclares come after all requires.
return (isForwardDeclare ? "z" : "a") + checkNotNull(key);
}
示例7: visit
import com.google.javascript.jscomp.NodeUtil; //导入方法依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getToken()) {
case SCRIPT:
// Duplicate provides are already checked in ProcessClosurePrimitives.
checkForDuplicates(requires);
reportIfOutOfOrder(requires, REQUIRES_NOT_SORTED);
reportIfOutOfOrder(provides, PROVIDES_NOT_SORTED);
reset();
break;
case CALL:
Node callee = n.getFirstChild();
if (!callee.matchesQualifiedName("goog.require")
&& !callee.matchesQualifiedName("goog.forwardDeclare")
&& !callee.matchesQualifiedName("goog.provide")
&& !callee.matchesQualifiedName("goog.module")) {
return;
}
if (parent.isExprResult() && NodeUtil.isTopLevel(parent.getParent())) {
Node namespaceNode = n.getLastChild();
if (!namespaceNode.isString()) {
return;
}
String namespace = namespaceNode.getString();
if (namespace == null) {
return;
}
if (callee.matchesQualifiedName("goog.require")
|| callee.matchesQualifiedName("goog.forwardDeclare")) {
requires.add(parent);
} else {
if (!requires.isEmpty()) {
t.report(n, PROVIDES_AFTER_REQUIRES);
}
if (callee.matchesQualifiedName("goog.provide")) {
provides.add(parent);
}
}
} else if (NodeUtil.isNameDeclaration(parent.getParent())
&& (callee.matchesQualifiedName("goog.require")
|| callee.matchesQualifiedName("goog.forwardDeclare"))) {
requires.add(parent.getParent());
}
break;
default:
break;
}
}