Package org.cfeclipse.cfml.parser.docitems

Examples of org.cfeclipse.cfml.parser.docitems.ScriptItem


      this.itemData = this.aNodeToken.image;
      this.setItemData(this.aNodeToken.image);
      this.startPosition = this.aNodeToken.beginColumn;
      this.endPosition = this.aNodeToken.endColumn;
      this.lineNumber = this.aNodeToken.beginLine;
      scriptItem = new ScriptItem(this.lineNumber,this.startPosition,this.endPosition,this.itemName);
      scriptItem.setItemData(this.aNodeToken.image);
      if(this.itemName.endsWith("ASTIfStatement")) {
          String ifStatement = this.aNodeToken.image;
      Token nextPartOfStatement = this.aNodeToken.next;
      while(nextPartOfStatement.next != null && !nextPartOfStatement.image.equalsIgnoreCase(")")) {
        ifStatement = ifStatement.concat(nextPartOfStatement.image + " ");
        nextPartOfStatement = nextPartOfStatement.next;
      }
        this.setItemData(ifStatement + ")");       
      }
      if(this.itemName.endsWith("ASTFunctionCallNode")) {
          String ifStatement = this.aNodeToken.image;
      Token nextPartOfStatement = this.aNodeToken.next;
      while(nextPartOfStatement.next != null && !nextPartOfStatement.image.equalsIgnoreCase(")")) {
        ifStatement = ifStatement.concat(nextPartOfStatement.image + " ");
        nextPartOfStatement = nextPartOfStatement.next;
      }
        this.setItemData(ifStatement + ")");       
      }
      else if(this.itemName.endsWith("ASTStatementExpression")) {
          String statementExp = "";
      Token nextPartOfStatement = this.aNodeToken.next;
      for(int x =0; x <= 2; x++) {
        statementExp = statementExp.concat(nextPartOfStatement.image + " ");
        nextPartOfStatement = nextPartOfStatement.next;
      }
        this.setItemData(statementExp);       
      }
      else if(this.itemName.endsWith("ASTFunctionDeclaration")) {
          String functionString = this.aNodeToken.image;
          if(this.getFirstChild().getClass().getSimpleName().endsWith("ASTParameterList")) {
        Token nextPartOfStatement = this.aNodeToken.next;
        while(nextPartOfStatement.next != null && !nextPartOfStatement.image.equalsIgnoreCase(")")) {
          functionString = functionString.concat(nextPartOfStatement.image + " ");
          nextPartOfStatement = nextPartOfStatement.next;
        }
          functionString = functionString.concat(")");
          this.setItemData(functionString);
          }
          if(this.getLastChild().getClass().getSimpleName().endsWith("ASTBlock")) {
            Node[] paramArray = ((SimpleNode)this.getLastChild()).children;
            ScriptItem funcParamsItem = new ScriptItem(this.lineNumber,this.startPosition,this.endPosition,"param");
            scriptItem.addChild(funcParamsItem);
            for(Node node:paramArray) {
              functionString = functionString.concat(((SimpleNode)node).aNodeToken.image + ", ");
            }
          }
View Full Code Here


      }
    }
    CFNodeList scriptNodes = doc.getDocumentRoot().selectNodes("//ASTAssignment");
    Iterator i = scriptNodes.iterator();
    while (i.hasNext()) {
      ScriptItem assignment = (ScriptItem) i.next();
      if (assignment.getFirstChild().getItemData().equals(variableName)) {
        return assignment.getLastChild().getItemData().replaceAll("\\(.*", "");
      }
    }
    scriptNodes = doc.getDocumentRoot().selectNodes("//ASTVarDeclaration");
    i = scriptNodes.iterator();
    while (i.hasNext()) {
      ScriptItem assignment = (ScriptItem) i.next();
      Iterator id = assignment.selectNodes("//ASTIdentifier").iterator();
      while (id.hasNext()) {
        ScriptItem identifier = (ScriptItem) id.next();
        if (identifier.getItemData().equals(variableName)) {
          return identifier.getParent().getLastChild().getItemData().replaceAll("\\(.*", "");
        }
      }
    }
    return cfcName;
  }
View Full Code Here

        } else {
          startPos = cti.getStartPosition();
          endPos = cti.getEndPosition();
        }
      } else {
        ScriptItem csi = (ScriptItem) firstItem;
        startPos = csi.getStartPosition();
        endPos = csi.getEndPosition();
      }
    } else {
      // otherwise select selected items
      while (selecteditems.hasNext()) {
        endPos = ((DocItem) selecteditems.next()).getEndPosition();
View Full Code Here

        // );
        ParserRuleReturnScope r = parser.scriptBlock();
        CommonTree tree = (CommonTree) r.getTree();
        // first item is EOF, so get kids to get kids
        if (tree == null) {
          ScriptItem errorNode = new ScriptItem(0, 0, 0, "error");
          errorNode.setItemData("Error creating outline: " + parserState.getMessages().toString());
          addDocItemToTree(errorNode);
        } else {
          scriptItemTree(tree, matchStack.peek(), addLines, addOffset, true);
        }
      } catch (RecognitionException e) {
        e.printStackTrace();
      } catch (org.antlr.runtime.tree.RewriteEmptyStreamException e) {
        ScriptItem errorNode = new ScriptItem(0, 0, 0, "error");
        errorNode.setItemData("Error parsing: " + parserState.getMessages().toString());
        addDocItemToTree(errorNode);
      }
    } catch (cfml.parsing.cfscript.ParseException e) {
      parserState.addMessage(new ParseError(e.getLine() + addLines, e.getCol() + addOffset, e.getCol() + addOffset, e.getMessage()
          + e.getLine(), e
View Full Code Here

    Map<String, Integer> lineAndOffset = getTreeLineAndOffset(tree, true);
    int startLine = lineAndOffset.get("line");
    int offset = lineAndOffset.get("offset");
    int startPos = offset;
    int endPos = lineAndOffset.get("endoffset");
    ScriptItem node = getScriptNode(tree, startLine, startPos, endPos);
    if (node == null) {
      // hidden nodes like function bodies ("{", etc.)
      node = (ScriptItem) rootNode;
    } else {
//      node.setItemData(node.getItemData() + " line:" + startLine + " length:" + lineAndOffset.get("length") + " offset:" + startPos
//          + " endoffset:" + endPos);
//      node.setItemData(node.getItemData() + " line:" + node.getLineNumber() + " length:" + lineAndOffset.get("length") + " offset:"
//          + node.getStartPosition() + " endoffset:" + node.getEndPosition());
      rootNode.addChild(node);
      node.setParent(rootNode);
    }
    if (tree.getChildCount() != 0) {
      for (Object kid : tree.getChildren()) {
        CommonTree leaf = (CommonTree) kid;
        scriptItemTree(leaf, node, startLine, endPos, root);
View Full Code Here

      return 0;
    return lineOffsets[line - 2];
  }

  private ScriptItem getScriptNode(CommonTree tree, int startLine, int startPos, int endPos) {
    ScriptItem childNode = null;
    switch (tree.getType()) {
    case CFScriptParser.FUNCTION_NAME:
    case CFScriptParser.FUNCTION_RETURNTYPE:
    case CFScriptParser.SLASH:
    case CFScriptParser.EMPTYARGS:
    case CFScriptParser.RIGHTCURLYBRACKET:
    case CFScriptParser.DOT:
    case CFScriptParser.EOF:
      break;
    case CFScriptParser.FUNCDECL:
    case CFScriptParser.FUNCTION:
      FunctionInfo funkInfo = new FunctionInfo(tree);
      funkInfo.setLineNumber(startLine);
      funkInfo.setStartPosition(startPos);
      // funkInfo.setStartPosition(startPos + funkInfo.getStartPosition());
      // funkInfo.setEndPosition(funkInfo.getEndPosition() + endPos);
      funkInfo.setEndPosition(endPos);
      childNode = funkInfo;
      break;
    case CFScriptParser.FUNCTION_PARAMETER:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTFunctionParameter");
      childNode.setItemData(getChildrenText(tree, ' '));
      break;
    case CFScriptParser.NEW:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTNewOperator");
      childNode.setItemData(getChildrenText(tree, '.'));
      break;
    case CFScriptParser.IDENTIFIER:
      if (tree.getParent().getType() == CFScriptParser.NEW) {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponent");
        childNode.setItemData("new " + tree.getText() + "()");
      } else if (tree.getParent().getType() == CFScriptParser.FUNCTIONCALL) {
        if (tree.getParent().getChild(0).getText().toLowerCase().equals("createobject")) {
          childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponent");
          childNode.setItemData("createobject " + tree.getText() + "()");
        } else if (tree.getParent().getChild(0).getText().toLowerCase().equals("entitynew")) {
          childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponent");
          childNode.setItemData("entitynew " + tree.getText() + "()");
        } else {
          childNode = new ScriptItem(startLine, startPos, endPos, "FunctionCall");
          childNode.setItemData(tree.getText());
        }
      } else if (tree.getParent().getType() == CFScriptParser.JAVAMETHODCALL) {
        childNode = new ScriptItem(startLine, startPos, endPos, "FunctionCall");
        childNode.setItemData(tree.getText());
      } else {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTIdentifier");
        childNode.setItemData(tree.getText());
      }
      break;
    case CFScriptParser.IMPLICITARRAY:
    case CFScriptParser.IMPLICITSTRUCT:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTUnassigned");
      childNode.setItemData(tree.getText());
      break;
    case CFScriptParser.INTEGER_LITERAL:
    case CFScriptParser.STRING_LITERAL:
      if (tree.getParent().getType() == CFScriptParser.FUNCTIONCALL) {
        if (tree.getParent().getChild(0).getText().toLowerCase().equals("createobject")) {
          childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponent");
          childNode.setItemData(tree.getText());
        } else {
          childNode = new ScriptItem(startLine, startPos, endPos, "Literal");
          childNode.setItemData(tree.getText());
        }
      } else {
        childNode = new ScriptItem(startLine, startPos, endPos, "Literal");
        childNode.setItemData(tree.getText());
      }
      break;
    case CFScriptParser.FUNCTIONCALL:
    case CFScriptParser.JAVAMETHODCALL:
      childNode = new ScriptItem(startLine, startPos, endPos, "Call");
      childNode.setItemData("call");
      break;
    case CFScriptParser.RETURN:
      childNode = new ScriptItem(startLine, startPos, endPos, "return");
      childNode.setItemData(tree.getText());
      break;
    case CFScriptParser.VARLOCAL:
      // endPos += ((CommonToken) ((CommonTree) tree.getChild(2)).getToken()).getStopIndex() - 2;
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTVarDeclaration");
      childNode.setItemData("var " + tree.getChild(0).getText() + tree.getChild(1).getText() + tree.getChild(2).getText());
      break;
    case CFScriptParser.COMPDECL:
    case CFScriptParser.COMPONENT:
      // endPos += ((CommonToken) ((CommonTree) tree.getChild(0)).getToken()).getStopIndex() - 2;
      childNode = new ScriptItem(startLine, startPos, endPos, "cfcomponent");
      childNode.setItemData("component");
      break;
    case CFScriptParser.LEFTCURLYBRACKET:
      break;
    case CFScriptParser.FUNCTION_ATTRIBUTE:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTFunctionAttribute");
      childNode.setItemData(tree.getChild(0).getText() + "=" + tree.getChild(1).getText());
      break;
    case CFScriptParser.COMPONENT_ATTRIBUTE:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponentAttribute");
      childNode.setItemData(tree.getChild(0).getText() + "=" + tree.getChild(1).getText());
      break;
    case CFScriptParser.PROPERTYSTATEMENT:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTPropertyStatement");
      childNode.setItemData(getChildrenText(tree, ' '));
      break;
    case CFScriptParser.ANDOPERATOR:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTAndOperator");
      childNode.setItemData(getChildrenText(tree, ' '));
      break;
    case CFScriptParser.CFMLFUNCTIONSTATEMENT:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTCFMLFunctionStatement");
      childNode.setItemData(getChildrenText(tree, ' '));
      break;
    case CFScriptParser.COLON:
      if (tree.getParent().getType() == CFScriptParser.COMPONENT_ATTRIBUTE) {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTComponentAttribute");
        childNode.setItemData(getChildrenText((CommonTree) tree.getParent(), ' '));
      } else if (tree.getParent().getType() == CFScriptParser.CASE) {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTSwitchStatement");
        childNode.setItemData(getChildrenText((CommonTree) tree.getParent(), ' '));
      } else if (tree.getParent().getType() == CFScriptParser.DEFAULT) {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTSwitchStatement");
        childNode.setItemData(getChildrenText((CommonTree) tree.getParent(), ' '));
      } else {
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTAssignment");
        childNode.setItemData(tree.getChild(0).getText() + ":" + tree.getChild(1).getText());
      }
      break;
    case CFScriptParser.SWITCH:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTSwitchStatement");
      childNode.setItemData(tree.getText());
      break;
    case CFScriptParser.EQUALSOP:
      // unscoped assignment registers as EQUALSOP currently
      if (tree.getChildren() != null) {
        // startPos -= (tree.getChild(0).getText().length() + 1);
        // endPos += ((CommonToken) ((CommonTree) tree.getChild(1)).getToken()).getStopIndex();
        childNode = new ScriptItem(startLine, startPos, endPos, "ASTAssignment");
        if (tree.getChild(1).getText().toLowerCase().equals("new")) {
          childNode.setItemData(tree.getChild(0).getText() + '=' + getChildrenText((CommonTree) tree.getChild(1), '.'));
        } else {
          childNode.setItemData(tree.getChild(0).getText() + '=' + tree.getChild(1).getText());
        }
      }
      break;
    default:
      childNode = new ScriptItem(startLine, startPos, endPos, "ASTUnassigned");
      childNode.setItemData(tree.getText() + ":" + tree.getType());
      break;
    }
    return childNode;
  }
View Full Code Here

TOP

Related Classes of org.cfeclipse.cfml.parser.docitems.ScriptItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.