Example #1
0
 /* (non-Javadoc)
  * @see org.exist.xquery.Module#resolveVariable(org.exist.dom.QName)
  */
 public Variable resolveVariable(QName qname) throws XPathException {
   VariableDeclaration decl = (VariableDeclaration) mGlobalVariables.get(qname);
   if (decl != null && !mStaticVariables.containsKey(qname)) {
     decl.eval(null);
   }
   return (Variable) mStaticVariables.get(qname);
 }
  @Override
  protected void fillVoiceXmlDocument(
      Document document, Element formElement, VoiceXmlDialogueContext dialogueContext)
      throws VoiceXmlDocumentRenderingException {
    addVariableDeclarations(formElement, mVariables);

    Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT);

    if (mScript != null) {
      Element scriptElement = DomUtils.appendNewElement(blockElement, SCRIPT_ELEMENT);
      DomUtils.appendNewText(scriptElement, mScript);
    }

    StringBuffer scriptBuffer = new StringBuffer();

    scriptBuffer.append(RIVR_SCOPE_OBJECT + ".addValueResult({");
    boolean first = true;
    for (VariableDeclaration variableDeclaration : mVariables) {
      if (!first) {
        scriptBuffer.append(", ");
      } else {
        first = false;
      }
      scriptBuffer.append("\"");
      scriptBuffer.append(variableDeclaration.getName());
      scriptBuffer.append("\": ");
      scriptBuffer.append("dialog.");
      scriptBuffer.append(variableDeclaration.getName());
    }
    scriptBuffer.append("});");

    createScript(blockElement, scriptBuffer.toString());
    createGotoSubmit(blockElement);
  }
Example #3
0
 public void testJSDocAttachment14() {
   AstRoot root = parse("var a = (/** @type {!Foo} */ {});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   assertEquals("/** @type {!Foo} */", root.getComments().first().getValue());
   VariableDeclaration vd = (VariableDeclaration) root.getFirstChild();
   VariableInitializer vi = vd.getVariables().get(0);
   assertNotNull(((ParenthesizedExpression) vi.getInitializer()).getExpression().getJsDoc());
 }
Example #4
0
 public void testParsingWithoutJSDoc() {
   AstRoot root = parse("var a = /** @type number */(x);", false);
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   assertEquals("/** @type number */", root.getComments().first().getValue());
   VariableDeclaration vd = (VariableDeclaration) root.getFirstChild();
   VariableInitializer vi = vd.getVariables().get(0);
   assertTrue(vi.getInitializer() instanceof ParenthesizedExpression);
 }
Example #5
0
 // Declared in VariableDeclaration.jrag at line 139
 private VariableDeclaration rewriteRule0() {
   {
     VariableDeclaration decl =
         getVariableDecl(0).createVariableDeclarationFrom(getModifiers(), getTypeAccess());
     decl.setStart(start); // copy location information
     decl.setEnd(end); // copy location information
     return decl;
   }
 }
Example #6
0
 public void testJSDocAttachment3() {
   AstRoot root = parse("var a = /** @type number */(x);");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   assertEquals("/** @type number */", root.getComments().first().getValue());
   VariableDeclaration vd = (VariableDeclaration) root.getFirstChild();
   VariableInitializer vi = vd.getVariables().get(0);
   assertNotNull(vi.getInitializer().getJsDoc());
 }
Example #7
0
 public Variable getVariable() {
   if (!bound) {
     bound = true;
     int position = find(statementList, after);
     VariableDeclaration varDecl =
         new VariableDeclaration(
             OJUtil.toTypeName(type, typeFactory), variable.toString(), null);
     statementList.insertElementAt(varDecl, position);
     varDecl.setInitializer(thunk.getInitializer());
   }
   return variable;
 }
Example #8
0
 private List createVariableDeclarationList() {
   List varList = new List();
   for (int j = 0; j < getNumVariableDecl(); j++) {
     VariableDeclaration v =
         getVariableDecl(j)
             .createVariableDeclarationFrom(
                 (Modifiers) getModifiers().fullCopy(), (Access) getTypeAccess().fullCopy());
     if (j == 0) v.setStart(start);
     varList.add(v);
   }
   return varList;
 }
Example #9
0
  public void testLinenoVarDecl() {
    AstRoot root = parse("\nvar\n" + "    a =\n" + "    3\n");

    VariableDeclaration decl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars = decl.getVariables();
    VariableInitializer init = vars.get(0);
    AstNode declName = init.getTarget();
    AstNode expr = init.getInitializer();

    assertEquals(1, decl.getLineno());
    assertEquals(2, init.getLineno());
    assertEquals(2, declName.getLineno());
    assertEquals(3, expr.getLineno());
  }
Example #10
0
  public void testLinenoInfix() {
    AstRoot root =
        parse(
            "\nvar d = a\n"
                + "    + \n"
                + "    b;\n"
                + "var\n"
                + "    e =\n"
                + "    a +\n"
                + "    c;\n"
                + "var f = b\n"
                + "    / c;\n");

    VariableDeclaration stmt1 = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = stmt1.getVariables();
    VariableInitializer var1 = vars1.get(0);
    Name firstVarName = (Name) var1.getTarget();
    InfixExpression var1Add = (InfixExpression) var1.getInitializer();

    VariableDeclaration stmt2 = (VariableDeclaration) stmt1.getNext();
    List<VariableInitializer> vars2 = stmt2.getVariables();
    VariableInitializer var2 = vars2.get(0);
    Name secondVarName = (Name) var2.getTarget();
    InfixExpression var2Add = (InfixExpression) var2.getInitializer();

    VariableDeclaration stmt3 = (VariableDeclaration) stmt2.getNext();
    List<VariableInitializer> vars3 = stmt3.getVariables();
    VariableInitializer var3 = vars3.get(0);
    Name thirdVarName = (Name) var3.getTarget();
    InfixExpression thirdVarDiv = (InfixExpression) var3.getInitializer();

    ReturnStatement returnStmt = (ReturnStatement) stmt3.getNext();

    assertEquals(1, var1.getLineno());
    assertEquals(1, firstVarName.getLineno());
    assertEquals(1, var1Add.getLineno());
    assertEquals(1, var1Add.getLeft().getLineno());
    assertEquals(3, var1Add.getRight().getLineno());

    // var directive with name on next line wrong --
    // should be 6.
    assertEquals(5, var2.getLineno());
    assertEquals(5, secondVarName.getLineno());
    assertEquals(6, var2Add.getLineno());
    assertEquals(6, var2Add.getLeft().getLineno());
    assertEquals(7, var2Add.getRight().getLineno());

    assertEquals(8, var3.getLineno());
    assertEquals(8, thirdVarName.getLineno());
    assertEquals(8, thirdVarDiv.getLineno());
    assertEquals(8, thirdVarDiv.getLeft().getLineno());
    assertEquals(9, thirdVarDiv.getRight().getLineno());
  }
 /**
  * Return the object into String.
  *
  * @param tab how many tabs (not used here
  * @return a String
  */
 public String toString(int tab) {
   // todo : rewrite tostring method
   StringBuffer buff = new StringBuffer(tabString(tab));
   buff.append("var ");
   buff.append(variable.toStringExpression());
   return buff.toString();
 }
Example #12
0
 public void declareVariable(QName qname, VariableDeclaration decl) throws XPathException {
   if (!qname.getNamespaceURI().equals(getNamespaceURI()))
     throw new XPathException(
         decl.getASTNode(),
         "err:XQST0048: It is a static error if a function "
             + "or variable declared in a library module is not in the target namespace of the library module.");
   mGlobalVariables.put(qname, decl);
 }
 /*
  * @see ASTVisitor#visit(LambdaExpression)
  */
 @Override
 public boolean visit(LambdaExpression node) {
   boolean hasParentheses = node.hasParentheses();
   if (hasParentheses) this.fBuffer.append('(');
   for (Iterator<? extends VariableDeclaration> it = node.parameters().iterator();
       it.hasNext(); ) {
     VariableDeclaration v = it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(","); // $NON-NLS-1$
     }
   }
   if (hasParentheses) this.fBuffer.append(')');
   this.fBuffer.append(" -> "); // $NON-NLS-1$
   node.getBody().accept(this);
   return false;
 }
Example #14
0
 /** Visits this node, the variable list, and if present, the body expression or statement. */
 @Override
 public void visit(NodeVisitor v) {
   if (v.visit(this)) {
     variables.visit(v);
     if (body != null) {
       body.visit(v);
     }
   }
 }
Example #15
0
  public void testRegexpLocation() {
    AstNode root = parse("\nvar path =\n" + "      replace(\n" + "/a/g," + "'/');\n");

    VariableDeclaration firstVarDecl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = firstVarDecl.getVariables();
    VariableInitializer firstInitializer = vars1.get(0);
    Name firstVarName = (Name) firstInitializer.getTarget();
    FunctionCall callNode = (FunctionCall) firstInitializer.getInitializer();
    AstNode fnName = callNode.getTarget();
    List<AstNode> args = callNode.getArguments();
    RegExpLiteral regexObject = (RegExpLiteral) args.get(0);
    AstNode aString = args.get(1);

    assertEquals(1, firstVarDecl.getLineno());
    assertEquals(1, firstVarName.getLineno());
    assertEquals(2, callNode.getLineno());
    assertEquals(2, fnName.getLineno());
    assertEquals(3, regexObject.getLineno());
    assertEquals(3, aString.getLineno());
  }
Example #16
0
  public void testObjectLitLocation() {
    AstNode root =
        parse(
            "\nvar foo =\n"
                + "{ \n"
                + "'A' : 'A', \n"
                + "'B' : 'B', \n"
                + "'C' : \n"
                + "      'C' \n"
                + "};\n");

    VariableDeclaration firstVarDecl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = firstVarDecl.getVariables();
    VariableInitializer firstInitializer = vars1.get(0);
    Name firstVarName = (Name) firstInitializer.getTarget();

    ObjectLiteral objectLiteral = (ObjectLiteral) firstInitializer.getInitializer();
    List<ObjectProperty> props = objectLiteral.getElements();
    ObjectProperty firstObjectLit = props.get(0);
    ObjectProperty secondObjectLit = props.get(1);
    ObjectProperty thirdObjectLit = props.get(2);

    AstNode firstKey = firstObjectLit.getLeft();
    AstNode firstValue = firstObjectLit.getRight();
    AstNode secondKey = secondObjectLit.getLeft();
    AstNode secondValue = secondObjectLit.getRight();
    AstNode thirdKey = thirdObjectLit.getLeft();
    AstNode thirdValue = thirdObjectLit.getRight();

    assertEquals(1, firstVarName.getLineno());
    assertEquals(2, objectLiteral.getLineno());
    assertEquals(3, firstObjectLit.getLineno());
    assertEquals(3, firstKey.getLineno());
    assertEquals(3, firstValue.getLineno());

    assertEquals(4, secondKey.getLineno());
    assertEquals(4, secondValue.getLineno());

    assertEquals(5, thirdKey.getLineno());
    assertEquals(6, thirdValue.getLineno());
  }
Example #17
0
 @Override
 public String toSource(int depth) {
   String pad = makeIndent(depth);
   StringBuilder sb = new StringBuilder();
   sb.append(pad);
   sb.append("let (");
   printList(variables.getVariables(), sb);
   sb.append(") ");
   if (body != null) {
     sb.append(body.toSource(depth));
   }
   return sb.toString();
 }
Example #18
0
  @Override
  /** For FETCH join, the path must be two level exactly. */
  public void setSchemaName(String schemaName) {
    if (fetch) {
      //			int dotFirst = schemaName.indexOf('.');
      //			int dotLast = schemaName.lastIndexOf('.');
      //			if(dotFirst < 0 || dotFirst != dotLast) {
      //				throw new EJBQLException("Invalid fetch join path: " + schemaName + " - the path must be
      // *.*, i.e., contains exactly one dot.");
      //			}

      if (schemaName.indexOf('.') < 0) {
        throw new EJBQLException(
            "Invalid fetch join path: "
                + schemaName
                + " - the path must contain at least one dot.");
      }
    }
    super.setSchemaName(schemaName);
  }
Example #19
0
  public void testLinenoLiteral() {
    AstRoot root =
        parse(
            "\nvar d =\n"
                + "    \"foo\";\n"
                + "var e =\n"
                + "    1;\n"
                + "var f = \n"
                + "    1.2;\n"
                + "var g = \n"
                + "    2e5;\n"
                + "var h = \n"
                + "    'bar';\n");

    VariableDeclaration stmt1 = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = stmt1.getVariables();
    VariableInitializer firstVar = vars1.get(0);
    Name firstVarName = (Name) firstVar.getTarget();
    AstNode firstVarLiteral = firstVar.getInitializer();

    VariableDeclaration stmt2 = (VariableDeclaration) stmt1.getNext();
    List<VariableInitializer> vars2 = stmt2.getVariables();
    VariableInitializer secondVar = vars2.get(0);
    Name secondVarName = (Name) secondVar.getTarget();
    AstNode secondVarLiteral = secondVar.getInitializer();

    VariableDeclaration stmt3 = (VariableDeclaration) stmt2.getNext();
    List<VariableInitializer> vars3 = stmt3.getVariables();
    VariableInitializer thirdVar = vars3.get(0);
    Name thirdVarName = (Name) thirdVar.getTarget();
    AstNode thirdVarLiteral = thirdVar.getInitializer();

    VariableDeclaration stmt4 = (VariableDeclaration) stmt3.getNext();
    List<VariableInitializer> vars4 = stmt4.getVariables();
    VariableInitializer fourthVar = vars4.get(0);
    Name fourthVarName = (Name) fourthVar.getTarget();
    AstNode fourthVarLiteral = fourthVar.getInitializer();

    VariableDeclaration stmt5 = (VariableDeclaration) stmt4.getNext();
    List<VariableInitializer> vars5 = stmt5.getVariables();
    VariableInitializer fifthVar = vars5.get(0);
    Name fifthVarName = (Name) fifthVar.getTarget();
    AstNode fifthVarLiteral = fifthVar.getInitializer();

    assertEquals(2, firstVarLiteral.getLineno());
    assertEquals(4, secondVarLiteral.getLineno());
    assertEquals(6, thirdVarLiteral.getLineno());
    assertEquals(8, fourthVarLiteral.getLineno());
    assertEquals(10, fifthVarLiteral.getLineno());
  }
Example #20
0
 /**
  * Sets variable list. Sets list parent to this node.
  *
  * @throws IllegalArgumentException if variables is {@code null}
  */
 public void setVariables(VariableDeclaration variables) {
   assertNotNull(variables);
   this.variables = variables;
   variables.setParent(this);
 }
 public Expression expressionAt(int line, int column) {
   if (variable.isAt(line, column)) return variable.expressionAt(line, column);
   return null;
 }
 public String getNameLowerCase() {
   if (nameLowerCase == null) {
     nameLowerCase = variable.getName().toLowerCase();
   }
   return nameLowerCase;
 }
 public String getName() {
   if (cachedToString == null) {
     cachedToString = variable.getName();
   }
   return cachedToString;
 }
Example #24
0
 @Override
 public Void visitVariableDeclaration(VariableDeclaration node) {
   visit(node.getName());
   visit(" = ", node.getInitializer());
   return null;
 }
 public void visit(VariableDeclaration entity) {
   wGetVisitor1().visit(entity.getName());
   wGetVisitor1().visit(entity.getReference());
   wGetVisitor1().visit(entity.getReferenceType());
 }
Example #26
0
 /**
  *
  *
  * <pre>
  * VariableDeclaration : BindingIdentifier Initializer<span><sub>opt</sub></span>
  * VariableDeclaration: BindingPattern Initializer
  * </pre>
  */
 @Override
 public List<Name> visit(VariableDeclaration node, List<Name> names) {
   return node.getBinding().accept(this, names);
 }