dialect = JAVA_DIALECT;
}
}
public Location getLocation() {
Location location = new Location(this.location);
switch (this.location) {
case Location.LOCATION_LHS_INSIDE_CONDITION_START:
int index = findToken("(", Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
if (index != -1) {
Object o = parserList.get(index - 1);
if (o instanceof DroolsToken) {
String className = ((DroolsToken) o).getText();
location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, className);
}
}
String propertyName = null;
if (index + 1 < parserList.size()) {
propertyName = "";
}
int i = index + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
propertyName += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME, propertyName);
break;
case Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR:
index = findToken("(", Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
if (index != -1) {
Object o = parserList.get(index - 1);
if (o instanceof DroolsToken) {
String className = ((DroolsToken) o).getText();
location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, className);
}
}
propertyName = null;
index = findTokenBack(Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
if (index != -1) {
if (index + 1 < locationIndex) {
propertyName = "";
}
i = index + 1;
while (i < locationIndex) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
String token = ((DroolsToken) o).getText();
if (":".equals(token)) {
propertyName = "";
} else {
propertyName += token;
}
} else {
break;
}
}
location.setProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME, propertyName);
}
break;
case Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT:
int index1 = findToken("(", Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
int index2 = findTokenBack(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, locationIndex);
int index3 = findTokenBack(Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
int index4 = findTokenBack(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, locationIndex);
if (index1 != -1 && index2 != -1) {
Object o = parserList.get(index1 - 1);
if (o instanceof DroolsToken) {
String className = ((DroolsToken) o).getText();
location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, className);
}
}
String operator = "";
for (i = index2 + 1; i < locationIndex; i++) {
Object o = parserList.get(i);
if (o instanceof DroolsToken) {
operator += ((DroolsToken) o).getText();
}
if (index4 != -1 && i >= index4 ){
break;
}
if (i < locationIndex - 1) {
operator += " ";
}
}
location.setProperty(Location.LOCATION_PROPERTY_OPERATOR, operator.trim());
propertyName = null;
if (index1 != -1) {
if (index3 + 1 < locationIndex - 1) {
propertyName = "";
}
i = index3 + 1;
while (i < locationIndex - 1) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
String token = ((DroolsToken) o).getText();
if (":".equals(token)) {
propertyName = "";
} else {
propertyName += token;
}
} else {
break;
}
}
location.setProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME, propertyName);
}
break;
case Location.LOCATION_LHS_INSIDE_CONDITION_END:
index = findToken("(", Location.LOCATION_LHS_INSIDE_CONDITION_START, locationIndex);
if (index != -1) {
Object o = parserList.get(index - 1);
if (o instanceof DroolsToken) {
String className = ((DroolsToken) o).getText();
location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, className);
}
}
break;
case Location.LOCATION_LHS_INSIDE_EVAL:
String eval = "";
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
eval += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_EVAL_CONTENT, eval.trim());
break;
case Location.LOCATION_LHS_FROM:
String from = null;
if (locationIndex + 1 < parserList.size()) {
from = "";
}
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_FROM_CONTENT, from);
break;
case Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE:
from = "";
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, from);
break;
case Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE:
from = "";
index = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, locationIndex);
index2 = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION, locationIndex);
if (index != -1 && index2 != -1) {
for (i = index + 1; i < index2 - 3; i++) {
Object o = parserList.get(i);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, from.trim());
}
from = "";
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, from);
break;
case Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE:
from = "";
index = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, locationIndex);
index2 = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION, locationIndex);
index3 = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, locationIndex);
index4 = findTokenBack(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT, locationIndex);
if (index != -1 && index2 != -1) {
for (i = index + 1; i < index2 - 3; i++) {
Object o = parserList.get(i);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, from.trim());
}
from = "";
if (index3 != -1 && index4 != -1) {
for (i = index3 + 1; i < index4 - 3; i++) {
Object o = parserList.get(i);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, from);
}
from = "";
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
from += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT, from);
break;
case Location.LOCATION_RHS:
String rhs = "";
i = locationIndex + 1;
int endLocationOfLast = Integer.MAX_VALUE - 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
DroolsToken token = (DroolsToken) o;
if (endLocationOfLast + 1 < token.getStartIndex()) {
rhs += " ";
}
rhs += token.getText();
endLocationOfLast = token.getStopIndex();
}
}
location.setProperty(Location.LOCATION_RHS_CONTENT, rhs);
break;
case Location.LOCATION_RULE_HEADER:
String header = "";
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
header += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_HEADER_CONTENT, header);
break;
case Location.LOCATION_RULE_HEADER_KEYWORD:
header = "";
index = findTokenBack(Location.LOCATION_RULE_HEADER, locationIndex);
if (index != -1) {
for (i = index + 1; i < locationIndex; i++) {
Object o = parserList.get(i);
if (o instanceof DroolsToken) {
header += ((DroolsToken) o).getText();
}
}
}
i = locationIndex + 1;
while (i < parserList.size()) {
Object o = parserList.get(i++);
if (o instanceof DroolsToken) {
header += ((DroolsToken) o).getText();
}
}
location.setProperty(Location.LOCATION_HEADER_CONTENT, header.trim());
break;
}
return location;
}