- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
public static void replaceChild (AstNode parent, AstNode child, AstNode newChild) {
try {
parent.replaceChild(child, newChild)
} catch (NullPointerException e1) {
// this is one of those shitty nodes with default children handling broken
try {
// maybe it was assignment
Assignment ass = (Assignment)parent
if (ass.left == child) {
ass.left = newChild
} else {
ass.right = newChild
}
} catch (Throwable e2) {
// not assignment :S
try {
// maybe it's (...)
ParenthesizedExpression pae = (ParenthesizedExpression)parent
pae.expression = newChild
} catch (Throwable e3) {
// not (...) either :S
try {
// Function call?
FunctionCall fuc = (FunctionCall)parent
for (int i = 0; i < fuc.arguments.size(); i++) {
if (fuc.arguments.get(i) == child) {
fuc.arguments.set(i, newChild)
break;
}
}
} catch (Throwable e4) {
try {
// Expression statement?
ExpressionStatement est = (ExpressionStatement)parent
est.expression = newChild
} catch (Throwable e5) {
try {
// var foo = bar?
VariableInitializer vin = (VariableInitializer)parent
if (vin.initializer == child) {
vin.initializer = newChild
} else {
// should not happen in our useage
vin.target = newChild
}
} catch (Throwable e6) {
try {
// what if?
IfStatement ifs = (IfStatement)parent
if (ifs.condition == child) {
ifs.condition = newChild
} else if (ifs.thenPart == child) {
ifs.thenPart = newChild
} else {
ifs.elsePart = newChild
}
} catch (Throwable e7) {
try {
// while loop?
WhileLoop whl = (WhileLoop)parent
if (whl.condition == child) {
whl.condition = newChild
} else {
whl.body = newChild
}
} catch (Throwable e8) {
try {
// Infix expression?
InfixExpression iex = (InfixExpression)parent
if (iex.left == child) {
iex.left = newChild
} else {
iex.right = newChild
}
} catch (Throwable e9) {
try {
// do loop?
DoLoop dol = (DoLoop)parent
if (dol.condition == child) {
dol.condition = newChild
} else {
dol.body = newChild
}
} catch (Throwable e10) {
try {
// for loop?
ForLoop fol = (ForLoop)parent
if (fol.condition == child) {
fol.condition = newChild
} else if (fol.initializer == child) {
fol.initializer = newChild
} else if (fol.increment == child) {
fol.increment = newChild
} else {
fol.body = newChild
}
} catch (Throwable e11) {
try {
ConditionalExpression cex = (ConditionalExpression)parent
if (cex.testExpression == child) {
Комментарии (0) RSS
Добавить комментарий