View | Details | Raw Unified | Return to bug 148224 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (+106 lines)
Lines 8014-8017 Link Here
8014
		IVariableBinding variableBinding = fieldAccess.resolveFieldBinding();
8014
		IVariableBinding variableBinding = fieldAccess.resolveFieldBinding();
8015
		assertNotNull("No variable binding", variableBinding);
8015
		assertNotNull("No variable binding", variableBinding);
8016
	}
8016
	}
8017
	
8018
	
8019
	/**
8020
	 * http://dev.eclipse.org/bugs/show_bug.cgi?id=148224
8021
	 */
8022
	public void test0654() throws JavaModelException {
8023
		ICompilationUnit workingCopy = null;
8024
		try {
8025
			String contents =
8026
				"public class X {\n" +
8027
				"	int i;\n" +
8028
				"	public void foo(int[] a) {\n" + 
8029
				"	}\n" + 
8030
				"	String s;\n" +
8031
				"	public String[][] bar() {\n" + 
8032
				"		return null;\n" +
8033
				"	}\n" + 
8034
				"}";
8035
			workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
8036
			ASTNode node = buildAST(
8037
				contents,
8038
				workingCopy,
8039
				false,
8040
				true);
8041
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
8042
			CompilationUnit unit = (CompilationUnit) node;
8043
			assertProblemsSize(unit, 0);
8044
			node = getASTNode(unit, 0, 0);
8045
			assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
8046
			FieldDeclaration declaration = (FieldDeclaration) node;
8047
			Type type = declaration.getType();
8048
			ITypeBinding typeBinding = type.resolveBinding();
8049
			assertTrue("Not a primitive type", typeBinding.isPrimitive());
8050
			assertEquals("Not int", "int", typeBinding.getName());
8051
			AST localAst = unit.getAST();
8052
			try {
8053
				localAst.resolveArrayType(typeBinding, -1);
8054
				assertTrue("Should throw an exception", false);
8055
			} catch(IllegalArgumentException exception) {
8056
				// ignore
8057
			}
8058
			try {
8059
				localAst.resolveArrayType(typeBinding, 0);
8060
				assertTrue("Should throw an exception", false);
8061
			} catch(IllegalArgumentException exception) {
8062
				// ignore
8063
			}
8064
			try {
8065
				localAst.resolveArrayType(typeBinding, 256);
8066
				assertTrue("Should throw an exception", false);
8067
			} catch(IllegalArgumentException exception) {
8068
				// ignore
8069
			}
8070
			ITypeBinding binding = localAst.resolveArrayType(typeBinding, 2);
8071
			assertEquals("Wrong dimensions", 2, binding.getDimensions());
8072
			assertTrue("Not an array type binding", binding.isArray());
8073
			ITypeBinding componentType = binding.getComponentType();
8074
			assertTrue("Not an array type binding", componentType.isArray());
8075
			assertEquals("Wrong dimensions", 1, componentType.getDimensions());
8076
			componentType = componentType.getComponentType();
8077
			assertFalse("An array type binding", componentType.isArray());
8078
			assertEquals("Wrong dimensions", 0, componentType.getDimensions());
8079
			
8080
			binding = localAst.resolveArrayType(typeBinding, 1);
8081
			node = getASTNode(unit, 0, 1);
8082
			assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
8083
			MethodDeclaration methodDeclaration = (MethodDeclaration) node;
8084
			List parameters = methodDeclaration.parameters();
8085
			assertEquals("Wrong size", 1, parameters.size());
8086
			SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0);
8087
			Type type2 = parameter.getType();
8088
			ITypeBinding typeBinding2 = type2.resolveBinding();
8089
			assertNotNull("No binding", typeBinding2);
8090
			assertTrue("Not an array binding", typeBinding2.isArray());
8091
			assertEquals("Wrong dimension", 1, typeBinding2.getDimensions());
8092
			assertEquals("Wrong type", "int", typeBinding2.getElementType().getName());
8093
			assertTrue("Should be equals", binding == typeBinding2);
8094
8095
			node = getASTNode(unit, 0, 2);
8096
			assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
8097
			declaration = (FieldDeclaration) node;
8098
			type = declaration.getType();
8099
			typeBinding = type.resolveBinding();
8100
			assertTrue("A primitive type", !typeBinding.isPrimitive());
8101
			assertEquals("Not String", "String", typeBinding.getName());
8102
8103
			binding = localAst.resolveArrayType(typeBinding, 1);
8104
			node = getASTNode(unit, 0, 3);
8105
			assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
8106
			methodDeclaration = (MethodDeclaration) node;
8107
			type = methodDeclaration.getReturnType2();
8108
			assertNotNull("No return type", type);
8109
			typeBinding2 = type.resolveBinding();
8110
			assertNotNull("No binding", typeBinding2);
8111
			assertTrue("Not an array binding", typeBinding2.isArray());
8112
			assertEquals("Wrong dimension", 2, typeBinding2.getDimensions());
8113
			assertEquals("Wrong type", "String", typeBinding2.getElementType().getName());
8114
			typeBinding2 = typeBinding2.getComponentType();
8115
			assertTrue("Not an array binding", typeBinding2.isArray());
8116
			assertEquals("Wrong dimension", 1, typeBinding2.getDimensions());
8117
			assertTrue("Should be equals", binding == typeBinding2);
8118
		} finally {
8119
			if (workingCopy != null)
8120
				workingCopy.discardWorkingCopy();
8121
		}
8122
	}
8017
}
8123
}

Return to bug 148224