Java Code Examples for com.google.javascript.rhino.Node#setStaticMember()

The following examples show how to use com.google.javascript.rhino.Node#setStaticMember() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConversionPass.java    From clutz with MIT License 5 votes vote down vote up
/**
 * Attempts to move a method declaration into a class definition. This generates a new
 * MEMBER_FUNCTION_DEF Node while removing the old function node from the AST.
 */
private void moveMethodsIntoClasses(ClassMemberDeclaration declaration) {
  Node classMembers = declaration.classNode.getLastChild();
  String fieldName = declaration.memberName;

  // Detach nodes in order to move them around in the AST.
  declaration.exprRoot.detach();
  declaration.rhs.detach();

  Node memberFunc = IR.memberFunctionDef(fieldName, declaration.rhs);
  memberFunc.setStaticMember(declaration.isStatic);
  memberFunc.setJSDocInfo(declaration.jsDoc);
  if (declaration.classNode.getToken() == Token.INTERFACE) {
    Node body = declaration.rhs.getLastChild();
    Preconditions.checkState(body.isNormalBlock());
    if (body.hasChildren()) {
      compiler.report(
          JSError.make(
              declaration.rhs,
              GentsErrorManager.GENTS_CLASS_PASS_ERROR,
              String.format("Interface method %s should be empty.", declaration.memberName)));
    }
    declaration.rhs.replaceChild(body, new Node(Token.EMPTY));
  }

  // Append the new method to the class
  classMembers.addChildToBack(memberFunc);
  nodeComments.moveComment(declaration.exprRoot, memberFunc);
  compiler.reportChangeToEnclosingScope(memberFunc);
}
 
Example 2
Source File: TypeConversionPass.java    From clutz with MIT License 5 votes vote down vote up
private Node createMemberVariableDef(ClassMemberDeclaration declaration) {
  Node fieldNode = Node.newString(Token.MEMBER_VARIABLE_DEF, declaration.memberName);
  fieldNode.setJSDocInfo(declaration.jsDoc);
  fieldNode.setStaticMember(declaration.isStatic);
  nodeComments.moveComment(declaration.exprRoot, fieldNode);
  return fieldNode;
}