View | Details | Raw Unified | Return to bug 193979
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-11 / +18 lines)
Lines 1579-1590 Link Here
1579
			// look for "string1" + "string2"
1579
			// look for "string1" + "string2"
1580
			if (this.optimizeStringLiterals) {
1580
			if (this.optimizeStringLiterals) {
1581
				if (expr1 instanceof StringLiteral) {
1581
				if (expr1 instanceof StringLiteral) {
1582
					if (expr2 instanceof CharLiteral) { // string+char
1582
					if (((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) {
1583
						this.expressionStack[this.expressionPtr] = 
1583
						if (expr2 instanceof CharLiteral) { // string+char
1584
							((StringLiteral) expr1).extendWith((CharLiteral) expr2); 
1584
							this.expressionStack[this.expressionPtr] = 
1585
					} else if (expr2 instanceof StringLiteral) { //string+string
1585
								((StringLiteral) expr1).extendWith((CharLiteral) expr2); 
1586
						this.expressionStack[this.expressionPtr] = 
1586
						} else if (expr2 instanceof StringLiteral) { //string+string
1587
							((StringLiteral) expr1).extendWith((StringLiteral) expr2); 
1587
							this.expressionStack[this.expressionPtr] = 
1588
								((StringLiteral) expr1).extendWith((StringLiteral) expr2); 
1589
						} else {
1590
							this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1591
						}
1588
					} else {
1592
					} else {
1589
						this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1593
						this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1590
					}
1594
					}
Lines 1609-1615 Link Here
1609
					cursor.right = expr2;
1613
					cursor.right = expr2;
1610
					cursor.sourceEnd = expr2.sourceEnd;
1614
					cursor.sourceEnd = expr2.sourceEnd;
1611
					this.expressionStack[this.expressionPtr] = cursor;
1615
					this.expressionStack[this.expressionPtr] = cursor;
1612
					// BE_INSTRUMENTATION: neutralized in the released code					
1616
					// BE_INSTRUMENTATION: neutralized in the released code
1613
//					cursor.depthTracker = ((BinaryExpression)cursor.left).
1617
//					cursor.depthTracker = ((BinaryExpression)cursor.left).
1614
//						depthTracker + 1;					
1618
//						depthTracker + 1;					
1615
				} else if (expr1 instanceof BinaryExpression &&
1619
				} else if (expr1 instanceof BinaryExpression &&
Lines 1626-1632 Link Here
1626
						new BinaryExpression(expr1, expr2, PLUS);
1630
						new BinaryExpression(expr1, expr2, PLUS);
1627
				}
1631
				}
1628
			} else if (expr1 instanceof StringLiteral) {
1632
			} else if (expr1 instanceof StringLiteral) {
1629
				if (expr2 instanceof StringLiteral) {
1633
				if (expr2 instanceof StringLiteral
1634
						&& ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) {
1630
					// string + string
1635
					// string + string
1631
					this.expressionStack[this.expressionPtr] = 
1636
					this.expressionStack[this.expressionPtr] = 
1632
						((StringLiteral) expr1).extendsWith((StringLiteral) expr2); 
1637
						((StringLiteral) expr1).extendsWith((StringLiteral) expr2); 
Lines 1651-1657 Link Here
1651
					}
1656
					}
1652
					cursor.right = expr2;
1657
					cursor.right = expr2;
1653
					cursor.sourceEnd = expr2.sourceEnd;
1658
					cursor.sourceEnd = expr2.sourceEnd;
1654
					// BE_INSTRUMENTATION: neutralized in the released code					
1659
					// BE_INSTRUMENTATION: neutralized in the released code
1655
//					cursor.depthTracker = ((BinaryExpression)cursor.left).
1660
//					cursor.depthTracker = ((BinaryExpression)cursor.left).
1656
//						depthTracker + 1;
1661
//						depthTracker + 1;
1657
					this.expressionStack[this.expressionPtr] = cursor;
1662
					this.expressionStack[this.expressionPtr] = cursor;
Lines 1754-1760 Link Here
1754
		case PLUS :
1759
		case PLUS :
1755
			// look for "string1" + "string2"
1760
			// look for "string1" + "string2"
1756
			if (this.optimizeStringLiterals) {
1761
			if (this.optimizeStringLiterals) {
1757
				if (expr1 instanceof StringLiteral) {
1762
				if (expr1 instanceof StringLiteral
1763
						&& ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) {
1758
					if (expr2 instanceof CharLiteral) { // string+char
1764
					if (expr2 instanceof CharLiteral) { // string+char
1759
						this.expressionStack[this.expressionPtr] = 
1765
						this.expressionStack[this.expressionPtr] = 
1760
							((StringLiteral) expr1).extendWith((CharLiteral) expr2); 
1766
							((StringLiteral) expr1).extendWith((CharLiteral) expr2); 
Lines 1768-1774 Link Here
1768
					this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1774
					this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS);
1769
				}
1775
				}
1770
			} else if (expr1 instanceof StringLiteral) {
1776
			} else if (expr1 instanceof StringLiteral) {
1771
				if (expr2 instanceof StringLiteral) {
1777
				if (expr2 instanceof StringLiteral
1778
						&& ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) {
1772
					// string + string
1779
					// string + string
1773
					this.expressionStack[this.expressionPtr] = 
1780
					this.expressionStack[this.expressionPtr] = 
1774
						((StringLiteral) expr1).extendsWith((StringLiteral) expr2); 
1781
						((StringLiteral) expr1).extendsWith((StringLiteral) expr2); 
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (-1 / +61 lines)
Lines 54-59 Link Here
54
import org.eclipse.jdt.core.dom.CharacterLiteral;
54
import org.eclipse.jdt.core.dom.CharacterLiteral;
55
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
55
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
56
import org.eclipse.jdt.core.dom.CompilationUnit;
56
import org.eclipse.jdt.core.dom.CompilationUnit;
57
import org.eclipse.jdt.core.dom.ConditionalExpression;
57
import org.eclipse.jdt.core.dom.ConstructorInvocation;
58
import org.eclipse.jdt.core.dom.ConstructorInvocation;
58
import org.eclipse.jdt.core.dom.EnumDeclaration;
59
import org.eclipse.jdt.core.dom.EnumDeclaration;
59
import org.eclipse.jdt.core.dom.Expression;
60
import org.eclipse.jdt.core.dom.Expression;
Lines 117-123 Link Here
117
	static {
118
	static {
118
//		TESTS_NAMES = new String[] {"test0602"};
119
//		TESTS_NAMES = new String[] {"test0602"};
119
//		TESTS_RANGE = new int[] { 670, -1 };
120
//		TESTS_RANGE = new int[] { 670, -1 };
120
//		TESTS_NUMBERS =  new int[] { 677 };
121
//		TESTS_NUMBERS =  new int[] { 678 };
121
	}
122
	}
122
	public static Test suite() {
123
	public static Test suite() {
123
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
124
		return buildModelTestSuite(ASTConverterTestAST3_2.class);
Lines 9229-9232 Link Here
9229
		assertNotNull("No fields", fields);
9230
		assertNotNull("No fields", fields);
9230
		assertTrue("Empty", fields.length != 0);
9231
		assertTrue("Empty", fields.length != 0);
9231
	}
9232
	}
9233
9234
	/*
9235
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=193979
9236
	 */
9237
	public void test0678() throws JavaModelException {
9238
		ICompilationUnit workingCopy = null;
9239
		try {
9240
			String contents =
9241
				"public class X {\n" + 
9242
				"	public String foo() {\n" + 
9243
				"		return((true ? \"\" : (\"Hello\" + \" World\") + \"!\"));\n" + 
9244
				"	}\n" + 
9245
				"}";
9246
			workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
9247
			ASTNode node = buildAST(
9248
				contents,
9249
				workingCopy);
9250
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
9251
			CompilationUnit unit = (CompilationUnit) node;
9252
			assertProblemsSize(unit, 0);
9253
			node = getASTNode(unit, 0, 0, 0);
9254
			assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
9255
			ReturnStatement returnStatement = (ReturnStatement) node;
9256
			Expression expression = returnStatement.getExpression();
9257
			assertNotNull("No expression", expression);
9258
			assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, expression.getNodeType());
9259
			expression = ((ParenthesizedExpression) expression).getExpression();
9260
			assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, expression.getNodeType());
9261
			expression = ((ParenthesizedExpression) expression).getExpression();
9262
			assertEquals("Not a conditional expression", ASTNode.CONDITIONAL_EXPRESSION, expression.getNodeType());
9263
			ConditionalExpression conditionalExpression = (ConditionalExpression) expression;
9264
			final Expression elseExpression = conditionalExpression.getElseExpression();
9265
			assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, elseExpression.getNodeType());
9266
			InfixExpression infixExpression = (InfixExpression) elseExpression;
9267
			List extendedOperands = infixExpression.extendedOperands();
9268
			assertEquals("wrong size", 0, extendedOperands.size());
9269
			Expression leftOperand = infixExpression.getLeftOperand();
9270
			assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, leftOperand.getNodeType());
9271
			ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) leftOperand;
9272
			assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, parenthesizedExpression.getExpression().getNodeType());
9273
			Expression rightOperand = infixExpression.getRightOperand();
9274
			assertEquals("Not a string literal", ASTNode.STRING_LITERAL, rightOperand.getNodeType());
9275
			StringLiteral stringLiteral = (StringLiteral) rightOperand;
9276
			assertEquals("wrong value", "!", stringLiteral.getLiteralValue());
9277
			infixExpression = (InfixExpression) parenthesizedExpression.getExpression();
9278
			leftOperand = infixExpression.getLeftOperand();
9279
			assertEquals("Not a string literal", ASTNode.STRING_LITERAL, leftOperand.getNodeType());
9280
			stringLiteral = (StringLiteral) leftOperand;
9281
			assertEquals("wrong value", "Hello", stringLiteral.getLiteralValue());
9282
			rightOperand = infixExpression.getRightOperand();
9283
			assertEquals("Not a string literal", ASTNode.STRING_LITERAL, rightOperand.getNodeType());
9284
			stringLiteral = (StringLiteral) rightOperand;
9285
			assertEquals("wrong value", " World", stringLiteral.getLiteralValue());
9286
			assertEquals("Wrong size", 0, infixExpression.extendedOperands().size());
9287
		} finally {
9288
			if (workingCopy != null)
9289
				workingCopy.discardWorkingCopy();
9290
		}
9291
	}
9232
}
9292
}

Return to bug 193979