1 11 package org.eclipse.jdt.internal.compiler.ast; 12 13 import org.eclipse.jdt.internal.compiler.ASTVisitor; 14 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 15 16 19 public class StringLiteralConcatenation extends StringLiteral { 20 private static final int INITIAL_SIZE = 5; 21 public Expression[] literals; 22 public int counter; 23 26 public StringLiteralConcatenation(StringLiteral str1, StringLiteral str2) { 27 super(str1.sourceStart, str1.sourceEnd); 28 this.source = str1.source; 29 this.literals = new StringLiteral[INITIAL_SIZE]; 30 this.counter = 0; 31 this.literals[this.counter++] = str1; 32 extendsWith(str2); 33 } 34 35 38 public StringLiteralConcatenation extendsWith(StringLiteral lit) { 39 this.sourceEnd = lit.sourceEnd; 40 final int literalsLength = this.literals.length; 41 if (this.counter == literalsLength) { 42 System.arraycopy(this.literals, 0, this.literals = new StringLiteral[literalsLength + INITIAL_SIZE], 0, literalsLength); 44 } 45 int length = source.length; 47 System.arraycopy( 48 source, 49 0, 50 source = new char[length + lit.source.length], 51 0, 52 length); 53 System.arraycopy(lit.source, 0, source, length, lit.source.length); 54 this.literals[this.counter++] = lit; 55 return this; 56 } 57 58 public StringBuffer printExpression(int indent, StringBuffer output) { 59 output.append("StringLiteralConcatenation{"); for (int i = 0, max = this.counter; i < max; i++) { 61 this.literals[i].printExpression(indent, output); 62 output.append("+\n"); } 64 return output.append('}'); 65 } 66 67 public char[] source() { 68 return source; 69 } 70 71 public void traverse(ASTVisitor visitor, BlockScope scope) { 72 if (visitor.visit(this, scope)) { 73 for (int i = 0, max = this.counter; i < max; i++) { 74 this.literals[i].traverse(visitor, scope); 75 } 76 } 77 visitor.endVisit(this, scope); 78 } 79 } 80 | Popular Tags |