当前位置: 首页>>代码示例>>Java>>正文


Java Node.getLineno方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.Node.getLineno方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getLineno方法的具体用法?Java Node.getLineno怎么用?Java Node.getLineno使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.Node的用法示例。


在下文中一共展示了Node.getLineno方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitNew

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Visits a NEW node.
 */
private void visitNew(NodeTraversal t, Node n) {
  Node constructor = n.getFirstChild();
  FunctionType type = getFunctionType(constructor);
  if (type != null && type.isConstructor()) {
    visitParameterList(t, n, type);
    ensureTyped(t, n, type.getInstanceType());
  } else {
    // TODO(user): add support for namespaced objects.
    if (constructor.getType() != Token.GETPROP) {
      // TODO(user): make the constructor node have lineno/charno
      // and use constructor for a more precise error indication.
      // It seems that GETPROP nodes are missing this information.
      Node line;
      if (constructor.getLineno() < 0 || constructor.getCharno() < 0) {
        line = n;
      } else {
        line = constructor;
      }
      t.report(line, NOT_A_CONSTRUCTOR);
    }
    ensureTyped(t, n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeCheck.java

示例2: shouldTraverse

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
  GraphNode<Node, Branch> gNode = t.getControlFlowGraph().getNode(n);
  if (gNode != null && gNode.getAnnotation() != GraphReachability.REACHABLE) {

    // Only report error when there are some line number informations.
    // There are synthetic nodes with no line number informations, nodes
    // introduce by other passes (although not likely since this pass should
    // be executed early) or some rhino bug.
    if (n.getLineno() != -1 &&
        // Allow spurious semi-colons and spurious breaks.
        n.getType() != Token.EMPTY && n.getType() != Token.BREAK) {
      compiler.report(JSError.make(t, n, level, UNREACHABLE_CODE));
      // From now on, we are going to assume the user fixed the error and not
      // give more warning related to code section reachable from this node.
      new GraphReachability<Node, ControlFlowGraph.Branch>(
          t.getControlFlowGraph()).recompute(n);

      // Saves time by not traversing children.
      return false;
    }
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:CheckUnreachableCode.java

示例3: startSourceMapping

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Starts the source mapping for the given
 * node at the current position.
 */
@Override
void startSourceMapping(Node node) {
  if (createSrcMap
      && node.getProp(Node.SOURCEFILE_PROP) != null
      && node.getLineno() > 0) {
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();

    // If the index is -1, we are not performing any mapping.
    if (index >= 0) {
      Mapping mapping = new Mapping();
      mapping.node = node;
      mapping.start = new Position(line, index);
      mappings.push(mapping);
      allMappings.add(mapping);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CodePrinter.java

示例4: endSourceMapping

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Finishes the source mapping for the given
 * node at the current position.
 */
@Override
void endSourceMapping(Node node) {
  if (createSrcMap
      && node.getProp(Node.SOURCEFILE_PROP) != null
      && node.getLineno() > 0) {
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();

    // If the index is -1, we are not performing any mapping.
    if (index >= 0) {
      Preconditions.checkState(
          !mappings.empty(), "Mismatch in start and end of mapping");

      Mapping mapping = mappings.pop();
      mapping.end = new Position(line, index);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CodePrinter.java

示例5: splitVarDeclarations

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Split a var node such as:
 *   var a, b;
 * into individual statements:
 *   var a;
 *   var b;
 * @param n The whose children we should inspect.
 */
private void splitVarDeclarations(Node n) {
  for (Node next, c = n.getFirstChild(); c != null; c = next) {
    next = c.getNext();
    if (c.getType() == Token.VAR) {
      if (assertOnChange && !c.hasChildren()) {
        throw new IllegalStateException("Empty VAR node.");
      }

      while (c.getFirstChild() != c.getLastChild()) {
        Node name = c.getFirstChild();
        c.removeChild(name);
        Node newVar = new Node(
            Token.VAR, name, n.getLineno(), n.getCharno());
        n.addChildBefore(newVar, c);
        reportCodeChange("VAR with multiple children");
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:Normalize.java

示例6: formatNodePosition

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private String formatNodePosition(Node n) {
  if (n == null) {
    return MISSING_SOURCE + "\n";
  }

  int lineNumber = n.getLineno();
  int columnNumber = n.getCharno();
  String src = compiler.getSourceLine(sourceName, lineNumber);
  if (src == null) {
    src = MISSING_SOURCE;
  }
  return sourceName + ":" + lineNumber + ":" + columnNumber + "\n"
      + src + "\n";
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:NodeTraversal.java

示例7: getLineNumber

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Gets the current line number, or zero if it cannot be determined. The line
 * number is retrieved lazily as a running time optimization.
 */
public int getLineNumber() {
  Node cur = curNode;
  while (cur != null) {
    int line = cur.getLineno();
    if (line >=0) {
      return line;
    }
    cur = cur.getParent();
  }
  return 0;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NodeTraversal.java

示例8: visit

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
  if (n.getType() == Token.SCRIPT) {
    requiresLineNumbers = false;
  } else if (requiresLineNumbers) {
    if (n.getLineno() == -1) {
      // The tree version of the node is really the best diagnostic
      // info we have to offer here.
      compiler.report(
          JSError.make(t, n, MISSING_LINE_INFO,
              n.toStringTree()));
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:LineNumberCheck.java

示例9: JSError

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Creates a JSError for a source file location.  Package private to avoid
 * any entanglement with code outside of the compiler.
 *
 * This is a preferred internal constructor.
 */
private JSError(String sourceName, Node node,
                DiagnosticType type, String... arguments) {
  this(sourceName,
       (node != null) ? node.getLineno() : -1,
       (node != null) ? node.getCharno() : -1,
       type, null, arguments);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:JSError.java

示例10: transform

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private Node transform(AstNode node) {
  String jsDoc = node.getJsDoc();
  NodeWithJsDoc nodeWithJsDoc = null;
  if (jsDoc != null) {
    nodeWithJsDoc = new NodeWithJsDoc();
    nodesWithJsDoc.put(jsDoc, nodeWithJsDoc);
  }

  Node irNode = justTransform(node);
  if (nodeWithJsDoc != null) {
    nodeWithJsDoc.node = irNode;
  }

  // If we have a named function, set the position to that of the name.
  if (irNode.getType() == Token.FUNCTION &&
      irNode.getFirstChild().getLineno() != -1) {
    irNode.setLineno(irNode.getFirstChild().getLineno());
    irNode.setCharno(irNode.getFirstChild().getCharno());
  } else {
    if (irNode.getLineno() == -1) {
      // If we didn't already set the line, then set it now.  This avoids
      // cases like ParenthesizedExpression where we just return a previous
      // node, but don't want the new node to get its parent's line number.
      int lineno = node.getLineno();
      irNode.setLineno(lineno);
      int charno = position2charno(node.getAbsolutePosition());
      irNode.setCharno(charno);
    }
  }
  return irNode;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:IRFactory.java

示例11: getLineNumberOfASTNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private int getLineNumberOfASTNode(Node node) {

		// Get the line number
		int lineNumber = node.getLineno();
		if(lineNumber < 0) lineNumber = 1;

		// Find the parent, to see if it's in a script
		Node parent = node;
		while(parent.getParent() != null) parent = parent.getParent();

		// If it's in an HTML file, add to the line number the offset of the script in the HTML file.
		if(parent instanceof ScriptOrFnNode) {
			
			if(htmlScriptLineNumbers.containsKey(parent))
				lineNumber += htmlScriptLineNumbers.get(parent);

		}
		
		return lineNumber;
		
	}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:Feedlack.java

示例12: rewriteCallExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Rewrite the call so "this" is preserved.
 *   a.b(c);
 * becomes:
 *   var temp1 = a;
 *   var temp0 = temp1.b;
 *   temp0.call(temp1,c);
 *
 * @return The replacement node.
 */
private Node rewriteCallExpression(Node call, DecompositionState state) {
  Preconditions.checkArgument(call.getType() == Token.CALL);
  Node first = call.getFirstChild();
  Preconditions.checkArgument(NodeUtil.isGet(first));

  // Extracts the expression representing the function to call. For example:
  //   "a['b'].c" from "a['b'].c()"
  Node getVarNode = extractExpression(
      first, state.extractBeforeStatement);
  state.extractBeforeStatement = getVarNode;

  // Extracts the object reference to be used as "this". For example:
  //   "a['b']" from "a['b'].c"
  Node getExprNode = getVarNode.getFirstChild().getFirstChild();
  Preconditions.checkArgument(NodeUtil.isGet(getExprNode));
  Node thisVarNode = extractExpression(
      getExprNode.getFirstChild(), state.extractBeforeStatement);
  state.extractBeforeStatement = thisVarNode;

  // Rewrite the CALL expression.
  Node thisNameNode = thisVarNode.getFirstChild();
  Node functionNameNode = getVarNode.getFirstChild();

  // CALL
  //   GETPROP
  //     functionName
  //     "call"
  //   thisName
  //   original-parameter1
  //   original-parameter2
  //   ...
  Node newCall = new Node(Token.CALL,
      new Node(Token.GETPROP,
          functionNameNode.cloneNode(),
          Node.newString("call")),
      thisNameNode.cloneNode(), call.getLineno(), call.getCharno());

  // Throw away the call name
  call.removeFirstChild();
  if (call.hasChildren()) {
    // Add the call parameters to the new call.
    newCall.addChildrenToBack(call.removeChildren());
  }

  // Replace the call.
  Node callParent = call.getParent();
  callParent.replaceChild(call, newCall);

  return newCall;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:61,代码来源:ExpressionDecomposer.java

示例13: addMapping

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Adds a mapping for the given node.
 *
 * @param node The node that the new mapping represents.
 * @param startPosition The position on the starting line
 * @param endPosition The position on the ending line.
 */
void addMapping(Node node, Position startPosition, Position endPosition) {
  Object sourceFile = node.getProp(Node.SOURCEFILE_PROP);

  // If the node does not have an associated source file or
  // its line number is -1, then the node does not have sufficient
  // information for a mapping to be useful.
  if (sourceFile == null || node.getLineno() < 0) {
    return;
  }

  // Create the new mapping.
  Mapping mapping = new Mapping();
  mapping.id = mappings.size();
  mapping.sourceFile = sourceFile.toString();
  mapping.originalPosition = new Position(node.getLineno(), node.getCharno());

  Object originalName = node.getProp(Node.ORIGINALNAME_PROP);

  if (originalName != null) {
    mapping.originalName = originalName.toString();
  }

  // If the mapping is found on the first line, we need to offset
  // its character position by the number of characters found on
  // the *last* line of the source file to which the code is
  // being generated.
  int offsetLine = offsetPosition.getLineNumber();
  int startOffsetPosition = offsetPosition.getCharacterIndex();
  int endOffsetPosition = offsetPosition.getCharacterIndex();

  if (startPosition.getLineNumber() > 0) {
    startOffsetPosition = 0;
  }

  if (endPosition.getLineNumber() > 0) {
    endOffsetPosition = 0;
  }

  mapping.startPosition =
      new Position(startPosition.getLineNumber() + offsetLine,
                   startPosition.getCharacterIndex() + startOffsetPosition);

  mapping.endPosition =
      new Position(endPosition.getLineNumber() + offsetLine,
                   endPosition.getCharacterIndex() + endOffsetPosition);

  mappings.add(mapping);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:56,代码来源:SourceMap.java

示例14: make

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Creates a JSError from a file and Node position.
 *
 * @param sourceName The source file name
 * @param n Determines the line and char position within the source file name
 * @param type The DiagnosticType
 * @param arguments Arguments to be incorporated into the message
 */
public static JSError make(String sourceName, Node n, CheckLevel level,
    DiagnosticType type, String... arguments) {

  return new JSError(sourceName, n.getLineno(), n.getCharno(), type, level,
      arguments);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:JSError.java


注:本文中的com.google.javascript.rhino.Node.getLineno方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。