本文整理汇总了Java中com.google.javascript.rhino.Token.FUNCTION属性的典型用法代码示例。如果您正苦于以下问题:Java Token.FUNCTION属性的具体用法?Java Token.FUNCTION怎么用?Java Token.FUNCTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.FUNCTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateAssignAllowedStack
/**
* Determines whether assignment to a define should be allowed
* in the subtree of the given node, and if not, records that fact.
*
* @param n The node whose subtree we're about to enter or exit.
* @param entering True if we're entering the subtree, false otherwise.
*/
private void updateAssignAllowedStack(Node n, boolean entering) {
switch (n.getType()) {
case Token.CASE:
case Token.FOR:
case Token.FUNCTION:
case Token.HOOK:
case Token.IF:
case Token.SWITCH:
case Token.WHILE:
if (entering) {
assignAllowed.push(0);
} else {
assignAllowed.remove();
}
break;
}
}
示例2: definitionTypeContainsFunctionType
/**
* Determines if the type of the value of the rhs expression can
* be a function node.
*/
private static boolean definitionTypeContainsFunctionType(Definition def) {
Node rhs = def.getRValue();
if (rhs == null) {
return true;
}
switch (rhs.getType()) {
case Token.ASSIGN:
case Token.AND:
case Token.CALL:
case Token.GETPROP:
case Token.GETELEM:
case Token.FUNCTION:
case Token.HOOK:
case Token.NAME:
case Token.NEW:
case Token.OR:
return true;
default:
return false;
}
}
示例3: findAnonymousFunctionExpressions
/**
* Find anonymous functions that are called directly in the form of
* (function(a,b,...){...})(a,b,...)
* or
* (function(a,b,...){...}).call(this,a,b, ...)
*/
public void findAnonymousFunctionExpressions(NodeTraversal t, Node n) {
switch (n.getType()) {
// Anonymous functions in the form of:
// (function(){})();
case Token.CALL:
Node fnNode = null;
if (n.getFirstChild().getType() == Token.FUNCTION) {
fnNode = n.getFirstChild();
} else if (NodeUtil.isFunctionObjectCall(n)) {
Node fnIdentifingNode = n.getFirstChild().getFirstChild();
if (fnIdentifingNode.getType() == Token.FUNCTION) {
fnNode = fnIdentifingNode;
}
}
// If a interesting function was discovered, add it.
if (fnNode != null) {
Function fn = new AnonymousFunction(fnNode, callsSeen++);
maybeAddFunction(fn, t.getModule());
anonFns.put(fnNode, fn.getName());
}
break;
}
}
示例4: getFunctionValue
/**
* If the given value is a qualified name which refers
* a function, the function's node is returned. Otherwise,
* {@code null} is returned.
*/
protected Node getFunctionValue(Node value) {
String qualifiedName = value.getQualifiedName();
if (qualifiedName == null) {
return null;
}
if (!definitionMap.containsKey(qualifiedName)) {
return null;
}
Node definitionParent = definitionMap.get(qualifiedName);
Node definition = definitionParent.getLastChild();
if (definition.getType() != Token.FUNCTION) {
return null;
}
return definition;
}
示例5: createType
/** Returns a concrete type from the JSType of the given variable. */
private ConcreteType createType(Node name, ConcreteScope scope) {
Preconditions.checkNotNull(name);
Preconditions.checkArgument(name.getType() == Token.NAME);
if (name.getJSType() == null) {
return ConcreteType.ALL;
}
if ((name.getFirstChild() != null)
&& (name.getFirstChild().getType() == Token.FUNCTION)) {
return createConcreteFunction(name.getFirstChild(), scope);
}
return createType(name.getJSType());
}
示例6: visit
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (parent == null) {
return;
}
if (n.getType() == Token.FUNCTION || n.getType() == Token.SCRIPT) {
return;
}
// Removes TRYs that had its CATCH removed and/or empty FINALLY.
if (n.getType() == Token.TRY) {
Node body = n.getFirstChild();
Node catchOrFinallyBlock = body.getNext();
Node finallyBlock = catchOrFinallyBlock.getNext();
if (!catchOrFinallyBlock.hasChildren() &&
(finallyBlock == null || !finallyBlock.hasChildren())) {
n.removeChild(body);
parent.replaceChild(n, body);
compiler.reportCodeChange();
n = body;
}
}
GraphNode<Node, Branch> gNode = curCfg.getNode(n);
if (gNode == null) { // Not in CFG.
return;
}
if (gNode.getAnnotation() != GraphReachability.REACHABLE ||
(removeNoOpStatements && !NodeUtil.mayHaveSideEffects(n))) {
removeDeadExprStatementSafely(n, parent);
}
}
示例7: visit
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
// Function calls
case Token.CALL:
Node child = n.getFirstChild();
String name = null;
// NOTE: The normalization pass insures that local names do not
// collide with global names.
if (child.getType() == Token.NAME) {
name = child.getString();
} else if (child.getType() == Token.FUNCTION) {
name = anonFunctionMap.get(child);
} else if (NodeUtil.isFunctionObjectCall(n)) {
Preconditions.checkState(NodeUtil.isGet(child));
Node fnIdentifingNode = child.getFirstChild();
if (fnIdentifingNode.getType() == Token.NAME) {
name = fnIdentifingNode.getString();
} else if (fnIdentifingNode.getType() == Token.FUNCTION) {
name = anonFunctionMap.get(fnIdentifingNode);
}
}
if (name != null) {
FunctionState fs = functionMap.get(name);
// Only visit call-sites for functions that can be inlined.
if (fs != null) {
callback.visitCallSite(t, n, parent, fs);
}
}
break;
}
}
示例8: visit
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() != Token.VAR) {
return;
}
// It is only safe to collapse anonymous functions that appear
// at top-level blocks. In other cases the difference between
// variable and function declarations can lead to problems or
// expose subtle bugs in browser implementation as function
// definitions are added to scopes before the start of execution.
Node grandparent = parent.getParent();
if (!(parent.getType() == Token.SCRIPT ||
grandparent != null &&
grandparent.getType() == Token.FUNCTION &&
parent.getType() == Token.BLOCK)) {
return;
}
// Need to store the next name in case the current name is removed from
// the linked list.
Preconditions.checkState(n.hasOneChild());
Node name = n.getFirstChild();
Node value = name.getFirstChild();
if (value != null &&
value.getType() == Token.FUNCTION &&
!isRecursiveFunction(value)) {
Node fnName = value.getFirstChild();
fnName.setString(name.getString());
NodeUtil.copyNameAnnotations(name, fnName);
name.removeChild(value);
parent.replaceChild(n, value);
compiler.reportCodeChange();
}
}
示例9: isDeclaration
/**
* Determines if the given name is a declaration, which can be a declaration
* of a variable, function, or argument.
*/
private static boolean isDeclaration(Node n) {
switch (n.getParent().getType()) {
case Token.VAR:
case Token.FUNCTION:
case Token.CATCH:
return true;
case Token.LP:
return n.getParent().getParent().getType() == Token.FUNCTION;
default:
return false;
}
}
示例10: isInThrowExpression
/**
* Is the {@link Node} currently within a 'throw' expression?
*/
private static boolean isInThrowExpression(Node n) {
// Look up the traversal stack to find a THROW node
for (Node ancestor : n.getAncestors()) {
switch (ancestor.getType()) {
case Token.THROW:
return true;
case Token.IF:
case Token.WHILE:
case Token.DO:
case Token.FOR:
case Token.SWITCH:
case Token.CASE:
case Token.DEFAULT:
case Token.BLOCK:
case Token.SCRIPT:
case Token.FUNCTION:
case Token.TRY:
case Token.CATCH:
case Token.RETURN:
case Token.EXPR_RESULT:
// early exit - these nodes types can't be within a THROW
return false;
}
}
return false;
}
示例11: getFuncChild
private Node getFuncChild(Node n) {
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
if (c.getType() == Token.FUNCTION) {
return c;
}
}
return null;
}
示例12: isGlobalFunctionDeclaration
/**
* Determines whether {@code n} is the FUNCTION node in a global function
* declaration.
*/
private boolean isGlobalFunctionDeclaration(NodeTraversal t,
Node n, Node parent) {
return t.inGlobalScope() &&
(NodeUtil.isFunctionDeclaration(n) ||
n.getType() == Token.FUNCTION && parent.getType() == Token.NAME);
}
示例13: shouldTraverse
@Override
public final boolean shouldTraverse(NodeTraversal nodeTraversal, Node n,
Node parent) {
if (n.getType() == Token.FUNCTION ||
n.getType() == Token.SCRIPT) {
sourceName = (String) n.getProp(Node.SOURCENAME_PROP);
}
// We do want to traverse the name of a named function, but we don't
// want to traverse the arguments or body.
return parent == null || parent.getType() != Token.FUNCTION ||
n == parent.getFirstChild() || parent == scope.getRootNode();
}
示例14: findParentOfFuncDescendant
private Node findParentOfFuncDescendant(Node n) {
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
if (c.getType() == Token.FUNCTION) {
return n;
}
Node result = findParentOfFuncDescendant(c);
if (result != null) {
return result;
}
}
return null;
}
示例15: visit
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.GETPROP:
Node propNode = n.getFirstChild().getNext();
if (propNode.getType() == Token.STRING) {
maybeMarkCandidate(propNode, t);
}
break;
case Token.OBJECTLIT:
// The children of an OBJECTLIT node are alternating key/value pairs.
// We skip the values.
for (Node key = n.getFirstChild(); key != null;
key = key.getNext().getNext()) {
// We only want keys that are strings (not numbers), and only keys
// that were unquoted.
if (key.getType() == Token.STRING) {
if (!key.isQuotedString()) {
maybeMarkCandidate(key, t);
} else {
// Ensure that we never rename some other property in a way
// that could conflict with this quoted key.
quotedNames.add(key.getString());
}
}
}
break;
case Token.GETELEM:
// If this is a quoted property access (e.g. x['myprop']), we need to
// ensure that we never rename some other property in a way that
// could conflict with this quoted name.
Node child = n.getLastChild();
if (child != null && child.getType() == Token.STRING) {
quotedNames.add(child.getString());
}
break;
case Token.CALL:
// We replace a JSCompiler_renameProperty function call with a string
// containing the renamed property.
Node fnName = n.getFirstChild();
if (fnName.getType() == Token.NAME &&
RENAME_PROPERTY_FUNCTION_NAME.equals(fnName.getString())) {
callNodeToParentMap.put(n, parent);
countCallCandidates(t, n);
}
break;
case Token.FUNCTION:
// We eliminate any stub implementations of JSCompiler_renameProperty
// that we encounter.
if (NodeUtil.isFunctionDeclaration(n)) {
String name = n.getFirstChild().getString();
if (RENAME_PROPERTY_FUNCTION_NAME.equals(name)) {
if (NodeUtil.isExpressionNode(parent)) {
parent.detachFromParent();
} else {
parent.removeChild(n);
}
compiler.reportCodeChange();
}
} else if (parent.getType() == Token.NAME &&
RENAME_PROPERTY_FUNCTION_NAME.equals(parent.getString())) {
Node varNode = parent.getParent();
if (varNode.getType() == Token.VAR) {
varNode.removeChild(parent);
if (!varNode.hasChildren()) {
varNode.detachFromParent();
}
compiler.reportCodeChange();
}
}
break;
}
}