Debian Codegraph @

src/com/google/javascript/jscomp/PeepholeReplaceKnownMethods.java

raw symbols SCIP
1 /*
2 * Copyright 2011 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.common.base.Preconditions;
20 import com.google.common.collect.Lists;
21 import com.google.javascript.rhino.IR;
22 import com.google.javascript.rhino.Node;
23 import java.util.List;
24 import java.util.Locale;
25
26 /**
27 * Just to fold known methods when they are called with constants.
28 *
29 */
30 class PeepholeReplaceKnownMethods extends AbstractPeepholeOptimization{
31
32 // The LOCALE independent "locale"
33 private static final Locale ROOT_LOCALE = new Locale("");
34 private final boolean late;
35
36 /**
37 * @param late When late is true, this mean we are currently running after
38 * most of the other optimizations. In this case we avoid changes that make
39 * the code larger (but otherwise easier to analyze - such as using string
40 * splitting).
41 */
42 PeepholeReplaceKnownMethods(boolean late) {
43 this.late = late;
44 }
45
46 @Override
47 Node optimizeSubtree(Node subtree) {
48 if (subtree.isCall() ){
49 return tryFoldKnownMethods(subtree);
50 }
51 return subtree;
52 }
53
54 private Node tryFoldKnownMethods(Node subtree) {
55 // For now we only support string methods .join(),
56 // .indexOf(), .substring() and .substr()
57 // and numeric methods parseInt() and parseFloat().
58
59 subtree = tryFoldArrayJoin(subtree);
60
61 if (subtree.isCall()) {
62 Node callTarget = subtree.getFirstChild();
63 if (callTarget == null) {
64 return subtree;
65 }
66
67 if (NodeUtil.isGet(callTarget)) {
68 subtree = tryFoldKnownStringMethods(subtree);
69 } else {
70 subtree = tryFoldKnownNumericMethods(subtree);
71 }
72 }
73
74 return subtree;
75 }
76
77 /**
78 * Try to evaluate known String methods
79 * .indexOf(), .substr(), .substring()
80 */
81 private Node tryFoldKnownStringMethods(Node subtree) {
82 Preconditions.checkArgument(subtree.isCall());
83
84 // check if this is a call on a string method
85 // then dispatch to specific folding method.
86 Node callTarget = subtree.getFirstChild();
87 if (callTarget == null) {
88 return subtree;
89 }
90
91 if (!NodeUtil.isGet(callTarget)) {
92 return subtree;
93 }
94
95 Node stringNode = callTarget.getFirstChild();
96 Node functionName = stringNode.getNext();
97
98 if ((!stringNode.isString()) ||
99 (!functionName.isString())) {
100 return subtree;
101 }
102
103 String functionNameString = functionName.getString();
104 Node firstArg = callTarget.getNext();
105 if (functionNameString.equals("split")) {
106 subtree = tryFoldStringSplit(subtree, stringNode, firstArg);
107 } else if (firstArg == null) {
108 if (functionNameString.equals("toLowerCase")) {
109 subtree = tryFoldStringToLowerCase(subtree, stringNode);
110 } else if (functionNameString.equals("toUpperCase")) {
111 subtree = tryFoldStringToUpperCase(subtree, stringNode);
112 }
113 return subtree;
114 } else if (NodeUtil.isImmutableValue(firstArg)) {
115 if (functionNameString.equals("indexOf") ||
116 functionNameString.equals("lastIndexOf")) {
117 subtree = tryFoldStringIndexOf(subtree, functionNameString,
118 stringNode, firstArg);
119 } else if (functionNameString.equals("substr")) {
120 subtree = tryFoldStringSubstr(subtree, stringNode, firstArg);
121 } else if (functionNameString.equals("substring")) {
122 subtree = tryFoldStringSubstring(subtree, stringNode, firstArg);
123 } else if (functionNameString.equals("charAt")) {
124 subtree = tryFoldStringCharAt(subtree, stringNode, firstArg);
125 } else if (functionNameString.equals("charCodeAt")) {
126 subtree = tryFoldStringCharCodeAt(subtree, stringNode, firstArg);
127 }
128 }
129
130 return subtree;
131 }
132
133 /**
134 * Try to evaluate known Numeric methods
135 * .parseInt(), parseFloat()
136 */
137 private Node tryFoldKnownNumericMethods(Node subtree) {
138 Preconditions.checkArgument(subtree.isCall());
139
140 if (isASTNormalized()) {
141 // check if this is a call on a string method
142 // then dispatch to specific folding method.
143 Node callTarget = subtree.getFirstChild();
144
145 if (!callTarget.isName()) {
146 return subtree;
147 }
148
149 String functionNameString = callTarget.getString();
150 Node firstArgument = callTarget.getNext();
151 if ((firstArgument != null) &&
152 (firstArgument.isString() ||
153 firstArgument.isNumber())) {
154 if (functionNameString.equals("parseInt") ||
155 functionNameString.equals("parseFloat")) {
156 subtree = tryFoldParseNumber(subtree, functionNameString,
157 firstArgument);
158 }
159 }
160 }
161 return subtree;
162 }
163
164 /**
165 * @return The lowered string Node.
166 */
167 private Node tryFoldStringToLowerCase(Node subtree, Node stringNode) {
168 // From Rhino, NativeString.java. See ECMA 15.5.4.11
169 String lowered = stringNode.getString().toLowerCase(ROOT_LOCALE);
170 Node replacement = IR.string(lowered);
171 subtree.getParent().replaceChild(subtree, replacement);
172 reportCodeChange();
173 return replacement;
174 }
175
176 /**
177 * @return The upped string Node.
178 */
179 private Node tryFoldStringToUpperCase(Node subtree, Node stringNode) {
180 // From Rhino, NativeString.java. See ECMA 15.5.4.12
181 String upped = stringNode.getString().toUpperCase(ROOT_LOCALE);
182 Node replacement = IR.string(upped);
183 subtree.getParent().replaceChild(subtree, replacement);
184 reportCodeChange();
185 return replacement;
186 }
187
188 /**
189 * @param input string representation of a number
190 * @return string with leading and trailing zeros removed
191 */
192 private String normalizeNumericString(String input) {
193 if (input == null || input.length() == 0) {
194 return input;
195 }
196
197 int startIndex = 0, endIndex = input.length() - 1;
198
199 // Remove leading zeros
200 while (startIndex < input.length() && input.charAt(startIndex) == '0' &&
201 input.charAt(startIndex) != '.') {
202 startIndex++;
203 }
204
205 // Remove trailing zeros only after the decimal
206 if (input.indexOf('.') >= 0) {
207 while (endIndex >= 0 && input.charAt(endIndex) == '0') {
208 endIndex--;
209 }
210 if (input.charAt(endIndex) == '.') {
211 endIndex--;
212 }
213 }
214 if (startIndex >= endIndex) {
215 return input;
216 }
217
218 return input.substring(startIndex, endIndex + 1);
219 }
220
221 /**
222 * Try to evaluate parseInt, parseFloat:
223 * parseInt("1") -> 1
224 * parseInt("1", 10) -> 1
225 * parseFloat("1.11") -> 1.11
226 */
227 private Node tryFoldParseNumber(
228 Node n, String functionName, Node firstArg) {
229 Preconditions.checkArgument(n.isCall());
230
231 boolean isParseInt = functionName.equals("parseInt");
232 Node secondArg = firstArg.getNext();
233
234 // Second argument is only used as the radix for parseInt
235 int radix = 0;
236 if (secondArg != null) {
237 if (!isParseInt) {
238 return n;
239 }
240
241 // Third-argument and non-numeric second arg are problematic. Discard.
242 if (secondArg.getNext() != null || !secondArg.isNumber()) {
243 return n;
244 } else {
245 double tmpRadix = secondArg.getDouble();
246 if (tmpRadix != (int)tmpRadix)
247 return n;
248 radix = (int)tmpRadix;
249 if (radix < 0 || radix == 1 || radix > 36) {
250 return n;
251 }
252 }
253 }
254
255 // stringVal must be a valid string.
256 String stringVal = null;
257 Double checkVal;
258 if (firstArg.isNumber()) {
259 checkVal = NodeUtil.getNumberValue(firstArg);
260 if (!(radix == 0 || radix == 10) && isParseInt) {
261 //Convert a numeric first argument to a different base
262 stringVal = String.valueOf(checkVal.intValue());
263 } else {
264 // If parseFloat is called with a numeric argument,
265 // replace it with just the number.
266 // If parseInt is called with a numeric first argument and the radix
267 // is 10 or omitted, just replace it with the number
268 Node numericNode;
269 if (isParseInt) {
270 numericNode = IR.number(checkVal.intValue());
271 } else {
272 numericNode = IR.number(checkVal);
273 }
274 n.getParent().replaceChild(n, numericNode);
275 reportCodeChange();
276 return numericNode;
277 }
278 } else {
279 stringVal = NodeUtil.getStringValue(firstArg);
280 if (stringVal == null) {
281 return n;
282 }
283
284 //Check that the string is in a format we can recognize
285 checkVal = NodeUtil.getStringNumberValue(stringVal);
286 if (checkVal == null) {
287 return n;
288 }
289
290 stringVal = NodeUtil.trimJsWhiteSpace(stringVal);
291 if (stringVal.length() == 0) {
292 return n;
293 }
294 }
295
296 Node newNode;
297 if (stringVal.equals("0")) {
298 // Special case for parseInt("0") or parseFloat("0")
299 newNode = IR.number(0);
300 } else if (isParseInt) {
301 if (radix == 0 || radix == 16) {
302 if (stringVal.length() > 1 &&
303 stringVal.substring(0, 2).equalsIgnoreCase("0x")) {
304 radix = 16;
305 stringVal = stringVal.substring(2);
306 } else if (radix == 0) {
307 // if a radix is not specified or is 0 and the most
308 // significant digit is "0", the string will parse
309 // with a radix of 8 on some browsers, so leave
310 // this case alone. This check does not apply in
311 // script mode ECMA5 or greater
312 if (!isEcmaScript5OrGreater() &&
313 stringVal.substring(0, 1).equals("0")) {
314 return n;
315 }
316
317 radix = 10;
318 }
319 }
320 int newVal = 0;
321 try {
322 newVal = Integer.parseInt(stringVal, radix);
323 } catch (NumberFormatException e) {
324 return n;
325 }
326
327 newNode = IR.number(newVal);
328 } else {
329 String normalizedNewVal = "0";
330 try {
331 double newVal = Double.parseDouble(stringVal);
332 newNode = IR.number(newVal);
333 normalizedNewVal = normalizeNumericString(String.valueOf(newVal));
334 }
335 catch(NumberFormatException e) {
336 return n;
337 }
338 // Make sure that the parsed number matches the original string
339 // This prevents rounding differences between the Java implementation
340 // and native script.
341 if (!normalizeNumericString(stringVal).equals(normalizedNewVal)) {
342 return n;
343 }
344 }
345
346 n.getParent().replaceChild(n, newNode);
347
348 reportCodeChange();
349
350 return newNode;
351 }
352
353 /**
354 * Try to evaluate String.indexOf/lastIndexOf:
355 * "abcdef".indexOf("bc") -> 1
356 * "abcdefbc".indexOf("bc", 3) -> 6
357 */
358 private Node tryFoldStringIndexOf(
359 Node n, String functionName, Node lstringNode, Node firstArg) {
360 Preconditions.checkArgument(n.isCall());
361 Preconditions.checkArgument(lstringNode.isString());
362
363 String lstring = NodeUtil.getStringValue(lstringNode);
364 boolean isIndexOf = functionName.equals("indexOf");
365 Node secondArg = firstArg.getNext();
366 String searchValue = NodeUtil.getStringValue(firstArg);
367 // searchValue must be a valid string.
368 if (searchValue == null) {
369 return n;
370 }
371 int fromIndex = isIndexOf ? 0 : lstring.length();
372 if (secondArg != null) {
373 // Third-argument and non-numeric second arg are problematic. Discard.
374 if (secondArg.getNext() != null || !secondArg.isNumber()) {
375 return n;
376 } else {
377 fromIndex = (int) secondArg.getDouble();
378 }
379 }
380 int indexVal = isIndexOf ? lstring.indexOf(searchValue, fromIndex)
381 : lstring.lastIndexOf(searchValue, fromIndex);
382 Node newNode = IR.number(indexVal);
383 n.getParent().replaceChild(n, newNode);
384
385 reportCodeChange();
386
387 return newNode;
388 }
389
390 /**
391 * Try to fold an array join: ['a', 'b', 'c'].join('') -> 'abc';
392 */
393 private Node tryFoldArrayJoin(Node n) {
394 Node callTarget = n.getFirstChild();
395
396 if (callTarget == null || !callTarget.isGetProp()) {
397 return n;
398 }
399
400 Node right = callTarget.getNext();
401 if (right != null) {
402 if (right.getNext() != null || !NodeUtil.isImmutableValue(right)) {
403 return n;
404 }
405 }
406
407 Node arrayNode = callTarget.getFirstChild();
408 Node functionName = arrayNode.getNext();
409
410 if (!arrayNode.isArrayLit() ||
411 !functionName.getString().equals("join")) {
412 return n;
413 }
414
415 if (right != null && right.isString()
416 && ",".equals(right.getString())) {
417 // "," is the default, it doesn't need to be explicit
418 n.removeChild(right);
419 reportCodeChange();
420 }
421
422 String joinString = (right == null) ? "," : NodeUtil.getStringValue(right);
423 List<Node> arrayFoldedChildren = Lists.newLinkedList();
424 StringBuilder sb = null;
425 int foldedSize = 0;
426 Node prev = null;
427 Node elem = arrayNode.getFirstChild();
428 // Merges adjacent String nodes.
429 while (elem != null) {
430 if (NodeUtil.isImmutableValue(elem) || elem.isEmpty()) {
431 if (sb == null) {
432 sb = new StringBuilder();
433 } else {
434 sb.append(joinString);
435 }
436 sb.append(NodeUtil.getArrayElementStringValue(elem));
437 } else {
438 if (sb != null) {
439 Preconditions.checkNotNull(prev);
440 // + 2 for the quotes.
441 foldedSize += sb.length() + 2;
442 arrayFoldedChildren.add(
443 IR.string(sb.toString()).copyInformationFrom(prev));
444 sb = null;
445 }
446 foldedSize += InlineCostEstimator.getCost(elem);
447 arrayFoldedChildren.add(elem);
448 }
449 prev = elem;
450 elem = elem.getNext();
451 }
452
453 if (sb != null) {
454 Preconditions.checkNotNull(prev);
455 // + 2 for the quotes.
456 foldedSize += sb.length() + 2;
457 arrayFoldedChildren.add(
458 IR.string(sb.toString()).copyInformationFrom(prev));
459 }
460 // one for each comma.
461 foldedSize += arrayFoldedChildren.size() - 1;
462
463 int originalSize = InlineCostEstimator.getCost(n);
464 switch (arrayFoldedChildren.size()) {
465 case 0:
466 Node emptyStringNode = IR.string("");
467 n.getParent().replaceChild(n, emptyStringNode);
468 reportCodeChange();
469 return emptyStringNode;
470 case 1:
471 Node foldedStringNode = arrayFoldedChildren.remove(0);
472 if (foldedSize > originalSize) {
473 return n;
474 }
475 arrayNode.detachChildren();
476 if (!foldedStringNode.isString()) {
477 // If the Node is not a string literal, ensure that
478 // it is coerced to a string.
479 Node replacement = IR.add(
480 IR.string("").srcref(n),
481 foldedStringNode);
482 foldedStringNode = replacement;
483 }
484 n.getParent().replaceChild(n, foldedStringNode);
485 reportCodeChange();
486 return foldedStringNode;
487 default:
488 // No folding could actually be performed.
489 if (arrayFoldedChildren.size() == arrayNode.getChildCount()) {
490 return n;
491 }
492 int kJoinOverhead = "[].join()".length();
493 foldedSize += kJoinOverhead;
494 foldedSize += (right != null) ? InlineCostEstimator.getCost(right) : 0;
495 if (foldedSize > originalSize) {
496 return n;
497 }
498 arrayNode.detachChildren();
499 for (Node node : arrayFoldedChildren) {
500 arrayNode.addChildToBack(node);
501 }
502 reportCodeChange();
503 break;
504 }
505
506 return n;
507 }
508
509 /**
510 * Try to fold .substr() calls on strings
511 */
512 private Node tryFoldStringSubstr(Node n, Node stringNode, Node arg1) {
513 Preconditions.checkArgument(n.isCall());
514 Preconditions.checkArgument(stringNode.isString());
515
516 int start, length;
517 String stringAsString = stringNode.getString();
518
519 // TODO(nicksantos): We really need a NodeUtil.getNumberValue
520 // function.
521 if (arg1 != null && arg1.isNumber()) {
522 start = (int) arg1.getDouble();
523 } else {
524 return n;
525 }
526
527 Node arg2 = arg1.getNext();
528 if (arg2 != null) {
529 if (arg2.isNumber()) {
530 length = (int) arg2.getDouble();
531 } else {
532 return n;
533 }
534
535 if (arg2.getNext() != null) {
536 // If we got more args than we expected, bail out.
537 return n;
538 }
539 } else {
540 // parameter 2 not passed
541 length = stringAsString.length() - start;
542 }
543
544 // Don't handle these cases. The specification actually does
545 // specify the behavior in some of these cases, but we haven't
546 // done a thorough investigation that it is correctly implemented
547 // in all browsers.
548 if ((start + length) > stringAsString.length() ||
549 (length < 0) ||
550 (start < 0)) {
551 return n;
552 }
553
554 String result = stringAsString.substring(start, start + length);
555 Node resultNode = IR.string(result);
556
557 Node parent = n.getParent();
558 parent.replaceChild(n, resultNode);
559 reportCodeChange();
560 return resultNode;
561 }
562
563 /**
564 * Try to fold .substring() calls on strings
565 */
566 private Node tryFoldStringSubstring(Node n, Node stringNode, Node arg1) {
567 Preconditions.checkArgument(n.isCall());
568 Preconditions.checkArgument(stringNode.isString());
569
570 int start, end;
571 String stringAsString = stringNode.getString();
572
573 if (arg1 != null && arg1.isNumber()) {
574 start = (int) arg1.getDouble();
575 } else {
576 return n;
577 }
578
579 Node arg2 = arg1.getNext();
580 if (arg2 != null) {
581 if (arg2.isNumber()) {
582 end = (int) arg2.getDouble();
583 } else {
584 return n;
585 }
586
587 if (arg2.getNext() != null) {
588 // If we got more args than we expected, bail out.
589 return n;
590 }
591 } else {
592 // parameter 2 not passed
593 end = stringAsString.length();
594 }
595
596 // Don't handle these cases. The specification actually does
597 // specify the behavior in some of these cases, but we haven't
598 // done a thorough investigation that it is correctly implemented
599 // in all browsers.
600 if ((end > stringAsString.length()) ||
601 (start > stringAsString.length()) ||
602 (end < 0) ||
603 (start < 0)) {
604 return n;
605 }
606
607 String result = stringAsString.substring(start, end);
608 Node resultNode = IR.string(result);
609
610 Node parent = n.getParent();
611 parent.replaceChild(n, resultNode);
612 reportCodeChange();
613 return resultNode;
614 }
615
616 /**
617 * Try to fold .charAt() calls on strings
618 */
619 private Node tryFoldStringCharAt(Node n, Node stringNode, Node arg1) {
620 Preconditions.checkArgument(n.isCall());
621 Preconditions.checkArgument(stringNode.isString());
622
623 int index;
624 String stringAsString = stringNode.getString();
625
626 if (arg1 != null && arg1.isNumber()
627 && arg1.getNext() == null) {
628 index = (int) arg1.getDouble();
629 } else {
630 return n;
631 }
632
633 if (index < 0 || stringAsString.length() <= index) {
634 // http://es5.github.com/#x15.5.4.4 says "" is returned when index is
635 // out of bounds but we bail.
636 return n;
637 }
638
639 Node resultNode = IR.string(
640 stringAsString.substring(index, index + 1));
641 Node parent = n.getParent();
642 parent.replaceChild(n, resultNode);
643 reportCodeChange();
644 return resultNode;
645 }
646
647 /**
648 * Try to fold .charCodeAt() calls on strings
649 */
650 private Node tryFoldStringCharCodeAt(Node n, Node stringNode, Node arg1) {
651 Preconditions.checkArgument(n.isCall());
652 Preconditions.checkArgument(stringNode.isString());
653
654 int index;
655 String stringAsString = stringNode.getString();
656
657 if (arg1 != null && arg1.isNumber()
658 && arg1.getNext() == null) {
659 index = (int) arg1.getDouble();
660 } else {
661 return n;
662 }
663
664 if (index < 0 || stringAsString.length() <= index) {
665 // http://es5.github.com/#x15.5.4.5 says NaN is returned when index is
666 // out of bounds but we bail.
667 return n;
668 }
669
670 Node resultNode = IR.number(stringAsString.charAt(index));
671 Node parent = n.getParent();
672 parent.replaceChild(n, resultNode);
673 reportCodeChange();
674 return resultNode;
675 }
676
677 /**
678 * Support function for jsSplit, find the first occurrence of
679 * separator within stringValue starting at startIndex.
680 */
681 private int jsSplitMatch(String stringValue, int startIndex,
682 String separator) {
683
684 if (startIndex + separator.length() > stringValue.length()) {
685 return -1;
686 }
687
688 int matchIndex = stringValue.indexOf(separator, startIndex);
689
690 if (matchIndex < 0) {
691 return -1;
692 }
693
694 return matchIndex;
695 }
696
697 /**
698 * Implement the JS String.split method using a string separator.
699 */
700 private String[] jsSplit(String stringValue, String separator, int limit) {
701 Preconditions.checkArgument(limit >= 0);
702 Preconditions.checkArgument(stringValue != null);
703
704 // For limits of 0, return an empty array
705 if (limit == 0) {
706 return new String[0];
707 }
708
709 // If a separator is not specified, return the entire string as
710 // the only element of an array.
711 if (separator == null) {
712 return new String[] {stringValue};
713 }
714
715 List<String> splitStrings = Lists.newArrayList();
716
717 // If an empty string is specified for the separator, split apart each
718 // character of the string.
719 if (separator.length() == 0) {
720 for (int i = 0; i < stringValue.length() && i < limit; i++) {
721 splitStrings.add(stringValue.substring(i, i + 1));
722 }
723 } else {
724 int startIndex = 0, matchIndex;
725 while ((matchIndex =
726 jsSplitMatch(stringValue, startIndex, separator)) >= 0 &&
727 splitStrings.size() < limit) {
728 splitStrings.add(stringValue.substring(startIndex, matchIndex));
729
730 startIndex = matchIndex + separator.length();
731 }
732
733 if (splitStrings.size() < limit) {
734 if (startIndex < stringValue.length()) {
735 splitStrings.add(stringValue.substring(startIndex));
736 } else {
737 splitStrings.add("");
738 }
739 }
740 }
741
742 return splitStrings.toArray(new String[splitStrings.size()]);
743 }
744
745 /**
746 * Try to fold .split() calls on strings
747 */
748 private Node tryFoldStringSplit(Node n, Node stringNode, Node arg1) {
749 if (late) {
750 return n;
751 }
752
753 Preconditions.checkArgument(n.isCall());
754 Preconditions.checkArgument(stringNode.isString());
755
756 String separator = null;
757 String stringValue = stringNode.getString();
758
759 // Maximum number of possible splits
760 int limit = stringValue.length() + 1;
761
762 if (arg1 != null) {
763 if (arg1.isString()) {
764 separator = arg1.getString();
765 } else if (!arg1.isNull()) {
766 return n;
767 }
768
769 Node arg2 = arg1.getNext();
770 if (arg2 != null) {
771 if (arg2.isNumber()) {
772 limit = Math.min((int) arg2.getDouble(), limit);
773 if (limit < 0) {
774 return n;
775 }
776 } else {
777 return n;
778 }
779 }
780 }
781
782 // Split the string and convert the returned array into JS nodes
783 String[] stringArray = jsSplit(stringValue, separator, limit);
784 Node arrayOfStrings = IR.arraylit();
785 for (int i = 0; i < stringArray.length; i++) {
786 arrayOfStrings.addChildToBack(
787 IR.string(stringArray[i]).srcref(stringNode));
788 }
789
790 Node parent = n.getParent();
791 parent.replaceChild(n, arrayOfStrings);
792 reportCodeChange();
793 return arrayOfStrings;
794 }
795 }