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;
}