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

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (+61 lines)
Lines 43-48 Link Here
43
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
43
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
44
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
44
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
45
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
45
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
46
import org.eclipse.jdt.core.dom.ArrayCreation;
46
import org.eclipse.jdt.core.dom.ArrayInitializer;
47
import org.eclipse.jdt.core.dom.ArrayInitializer;
47
import org.eclipse.jdt.core.dom.ArrayType;
48
import org.eclipse.jdt.core.dom.ArrayType;
48
import org.eclipse.jdt.core.dom.AssertStatement;
49
import org.eclipse.jdt.core.dom.AssertStatement;
Lines 9354-9357 Link Here
9354
		assertNotNull("No binding", packageBinding);
9355
		assertNotNull("No binding", packageBinding);
9355
		assertEquals("Wrong name", "Sample", packageBinding.getName());
9356
		assertEquals("Wrong name", "Sample", packageBinding.getName());
9356
	}
9357
	}
9358
	
9359
	/**
9360
	 * http://dev.eclipse.org/bugs/show_bug.cgi?id=196514
9361
	 */
9362
	public void test0682() throws JavaModelException {
9363
		ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0682", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
9364
		ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
9365
		assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
9366
		CompilationUnit unit = (CompilationUnit) node;
9367
		assertProblemsSize(
9368
				unit,
9369
				2,
9370
				"Variable must provide either dimension expressions or an array initializer\n" + 
9371
				"Syntax error on token \"String\", [ expected after this token");
9372
		node = getASTNode(unit, 0, 1, 0);
9373
		assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
9374
		ExpressionStatement expressionStatement = (ExpressionStatement) node;
9375
		node = expressionStatement.getExpression();
9376
		assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, node.getNodeType());
9377
		MethodInvocation methodInvocation = (MethodInvocation) node;
9378
		List arguments = methodInvocation.arguments();
9379
		assertEquals("Wrong size", 1, arguments.size());
9380
		node = (ASTNode)arguments.get(0);
9381
		assertEquals("Not an array creation", ASTNode.ARRAY_CREATION, node.getNodeType());
9382
		ArrayCreation arrayCreation = (ArrayCreation) node;
9383
		ArrayType arrayType = arrayCreation.getType();
9384
		checkSourceRange(arrayType, "String]", sourceUnit.getSource());
9385
	}
9386
	
9387
	/**
9388
	 * http://dev.eclipse.org/bugs/show_bug.cgi?id=196514
9389
	 */
9390
	public void test0683() throws JavaModelException {
9391
		ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0683", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
9392
		ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
9393
		assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
9394
		CompilationUnit unit = (CompilationUnit) node;
9395
		assertProblemsSize(unit, 0);
9396
		node = getASTNode(unit, 0, 1, 0);
9397
		assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
9398
		ExpressionStatement expressionStatement = (ExpressionStatement) node;
9399
		node = expressionStatement.getExpression();
9400
		assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, node.getNodeType());
9401
		MethodInvocation methodInvocation = (MethodInvocation) node;
9402
		List arguments = methodInvocation.arguments();
9403
		assertEquals("Wrong size", 1, arguments.size());
9404
		node = (ASTNode)arguments.get(0);
9405
		assertEquals("Not an array creation", ASTNode.ARRAY_CREATION, node.getNodeType());
9406
		ArrayCreation arrayCreation = (ArrayCreation) node;
9407
		ArrayType arrayType = arrayCreation.getType();
9408
		checkSourceRange(arrayType, "String[0][b[10]][]", sourceUnit.getSource());
9409
		node = arrayType.getComponentType();
9410
		assertEquals("Not an array type", ASTNode.ARRAY_TYPE, node.getNodeType());
9411
		arrayType = (ArrayType)node;
9412
		checkSourceRange(arrayType, "String[0][b[10]]", sourceUnit.getSource());
9413
		node = arrayType.getComponentType();
9414
		assertEquals("Not an array type", ASTNode.ARRAY_TYPE, node.getNodeType());
9415
		arrayType = (ArrayType)node;
9416
		checkSourceRange(arrayType, "String[0]", sourceUnit.getSource());
9417
	}
9357
}
9418
}
(-)workspace/Converter/src/test0683/Test.java (+7 lines)
Added Link Here
1
package test0683;
2
public class Test {
3
	public void bar(String[][][] a) {}
4
	public void foo(int[] b) {
5
		bar(new String[0][b[10]][]);
6
	}
7
}
(-)workspace/Converter/src/test0682/Test.java (+7 lines)
Added Link Here
1
package test0682;
2
public class Test {
3
	public void bar(String[] a) {}
4
	public void foo(int[] b) {
5
		bar(new String]);
6
	}
7
}
(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (-3 / +9 lines)
Lines 831-837 Link Here
831
			}			
831
			}			
832
			int start = type.getStartPosition();
832
			int start = type.getStartPosition();
833
			int end = type.getStartPosition() + type.getLength();
833
			int end = type.getStartPosition() + type.getLength();
834
			int previousSearchStart = end;
834
			int previousSearchStart = end - 1;
835
			ArrayType componentType = (ArrayType) type.getParent();
835
			ArrayType componentType = (ArrayType) type.getParent();
836
			for (int i = 0; i < dimensionsLength; i++) {
836
			for (int i = 0; i < dimensionsLength; i++) {
837
				previousSearchStart = retrieveRightBracketPosition(previousSearchStart + 1, this.compilationUnitSourceLength);
837
				previousSearchStart = retrieveRightBracketPosition(previousSearchStart + 1, this.compilationUnitSourceLength);
Lines 4239-4248 Link Here
4239
		this.scanner.resetTo(start, end);
4239
		this.scanner.resetTo(start, end);
4240
		try {
4240
		try {
4241
			int token;
4241
			int token;
4242
			int balance = 0;
4242
			while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4243
			while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4243
				switch(token) {
4244
				switch(token) {
4244
					case TerminalTokens.TokenNameRBRACKET:
4245
					case TerminalTokens.TokenNameLBRACKET :
4245
						return this.scanner.currentPosition - 1;
4246
						balance++;
4247
						break;
4248
					case TerminalTokens.TokenNameRBRACKET :
4249
						balance--;
4250
						if (balance == 0) return this.scanner.currentPosition - 1;
4251
						break;
4246
				}
4252
				}
4247
			}
4253
			}
4248
		} catch(InvalidInputException e) {
4254
		} catch(InvalidInputException e) {

Return to bug 196514