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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java (+1 lines)
Lines 27-32 Link Here
27
	return new Class[] {
27
	return new Class[] {
28
		ASTConverterTest.class,		
28
		ASTConverterTest.class,		
29
		ASTConverterTest2.class,
29
		ASTConverterTest2.class,
30
		ASTConverterBugsTest.class,		
30
		ASTConverterJavadocTest.class,
31
		ASTConverterJavadocTest.class,
31
		ASTConverter15Test.class,
32
		ASTConverter15Test.class,
32
		ASTConverter16Test.class,
33
		ASTConverter16Test.class,
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java (+131 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.dom;
12
13
import java.io.IOException;
14
15
import junit.framework.Test;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.dom.AST;
20
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
21
import org.eclipse.jdt.core.dom.CompilationUnit;
22
import org.eclipse.jdt.core.dom.FieldDeclaration;
23
import org.eclipse.jdt.core.dom.ITypeBinding;
24
import org.eclipse.jdt.core.dom.Type;
25
26
public class ASTConverterBugsTest extends ConverterTestSetup {
27
	
28
	public void setUpSuite() throws Exception {
29
		PROJECT_SETUP = true; // do not copy Converter* directories
30
		super.setUpSuite();
31
		waitUntilIndexesReady();
32
	}
33
34
	public ASTConverterBugsTest(String name) {
35
		super(name);
36
	}
37
38
	public static Test suite() {
39
		return buildModelTestSuite(ASTConverterBugsTest.class);
40
	}
41
	
42
	/**
43
	 * @bug 186410: [dom] StackOverflowError due to endless superclass bindings hierarchy
44
	 * @test Ensures that the superclass of "java.lang.Object" class is null even when it's a recovered binding
45
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186410"
46
	 */
47
	public void testBug186410() throws CoreException, IOException {
48
		try {
49
			createJavaProject("P", new String[] {""}, new String[0], "");
50
			createFile("P/A.java",
51
				"public class A {\n" +
52
				"	void method(){}\n" +
53
				"}"
54
			);
55
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
56
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
57
			AbstractTypeDeclaration typeA = (AbstractTypeDeclaration)unitA.types().get(0);
58
			ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
59
			assertEquals("Unexpected superclass", "Object", objectType .getName());
60
			ITypeBinding objectSuperclass = objectType.getSuperclass();
61
			assertNull("java.lang.Object should  not have any superclass", objectSuperclass);
62
		} finally {
63
			deleteProject("P");
64
		}
65
	}
66
	public void testBug186410b() throws CoreException, IOException {
67
		try {
68
			createJavaProject("P", new String[] {""}, new String[0], "");
69
			createFile("P/A.java",
70
				"public class A {\n" +
71
				"	Object field;\n" +
72
				"}"
73
			);
74
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
75
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
76
			AbstractTypeDeclaration type = (AbstractTypeDeclaration)unitA.types().get(0);
77
			FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
78
			Type fieldType = field.getType();
79
			ITypeBinding typeBinding = fieldType.resolveBinding();
80
			ITypeBinding objectType = typeBinding.createArrayType(2).getElementType();
81
			assertEquals("Unexpected superclass", "Object", objectType.getName());
82
			ITypeBinding objectSuperclass = objectType.getSuperclass();
83
			assertNull("java.lang.Object should  not have any superclass", objectSuperclass);
84
		} finally {
85
			deleteProject("P");
86
		}
87
	}
88
	
89
	/**
90
	 * @bug 209510: [dom] Recovered type binding for "java.lang.Object" information are not complete
91
	 * @test Ensures that getPackage() and getQualifiedName() works properly for the "java.lang.Object" recovered binding
92
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209510"
93
	 */
94
	public void testBug209510a() throws CoreException, IOException {
95
		try {
96
			createJavaProject("P", new String[] {""}, new String[0], "");
97
			createFile("P/A.java",
98
				"public class A {\n" +
99
				"	void method(){}\n" +
100
				"}"
101
			);
102
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
103
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
104
			AbstractTypeDeclaration typeA = (AbstractTypeDeclaration)unitA.types().get(0);
105
			ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
106
			assertTrue("'java.lang.Object' should be recovered!", objectType.isRecovered());
107
			assertEquals("Unexpected package for recovered 'java.lang.Object'", "java.lang", objectType .getPackage().getName());
108
		} finally {
109
			deleteProject("P");
110
		}
111
	}
112
	public void testBug209510b() throws CoreException, IOException {
113
		try {
114
			createJavaProject("P", new String[] {""}, new String[0], "");
115
			createFile("P/A.java",
116
				"public class A {\n" +
117
				"	void method(){}\n" +
118
				"}"
119
			);
120
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
121
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
122
			AbstractTypeDeclaration typeA = (AbstractTypeDeclaration)unitA.types().get(0);
123
			ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
124
			assertTrue("'java.lang.Object' should be recovered!", objectType.isRecovered());
125
			assertEquals("Unexpected qualified name for recovered 'java.lang.Object'", "java.lang.Object", objectType .getQualifiedName());
126
		} finally {
127
			deleteProject("P");
128
		}
129
	}
130
	
131
}
(-)dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java (-35 / +54 lines)
Lines 15-22 Link Here
15
15
16
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
20
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
21
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
20
import org.eclipse.jdt.internal.compiler.util.Util;
22
import org.eclipse.jdt.internal.compiler.util.Util;
21
import org.eclipse.jdt.internal.core.CompilationUnit;
23
import org.eclipse.jdt.internal.core.CompilationUnit;
22
import org.eclipse.jdt.internal.core.PackageFragment;
24
import org.eclipse.jdt.internal.core.PackageFragment;
Lines 32-38 Link Here
32
	private int dimensions;
34
	private int dimensions;
33
	private RecoveredTypeBinding innerTypeBinding;
35
	private RecoveredTypeBinding innerTypeBinding;
34
	private ITypeBinding[] typeArguments;
36
	private ITypeBinding[] typeArguments;
35
	private org.eclipse.jdt.internal.compiler.lookup.TypeBinding referenceBinding;
37
	private org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding;
36
38
37
	RecoveredTypeBinding(BindingResolver resolver, VariableDeclaration variableDeclaration) {
39
	RecoveredTypeBinding(BindingResolver resolver, VariableDeclaration variableDeclaration) {
38
		this.variableDeclaration = variableDeclaration;
40
		this.variableDeclaration = variableDeclaration;
Lines 44-53 Link Here
44
		}
46
		}
45
	}
47
	}
46
48
47
	RecoveredTypeBinding(BindingResolver resolver, org.eclipse.jdt.internal.compiler.lookup.TypeBinding referenceBinding) {
49
	RecoveredTypeBinding(BindingResolver resolver, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding) {
48
		this.resolver = resolver;
50
		this.resolver = resolver;
49
		this.dimensions = referenceBinding.dimensions();
51
		this.dimensions = typeBinding.dimensions();
50
		this.referenceBinding = referenceBinding;
52
		this.typeBinding = typeBinding;
51
	}
53
	}
52
54
53
	RecoveredTypeBinding(BindingResolver resolver, Type type) {
55
	RecoveredTypeBinding(BindingResolver resolver, Type type) {
Lines 147-158 Link Here
147
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getElementType()
149
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getElementType()
148
	 */
150
	 */
149
	public ITypeBinding getElementType() {
151
	public ITypeBinding getElementType() {
150
		if (this.referenceBinding != null) {
152
		if (this.typeBinding != null) {
151
			if (this.referenceBinding.isArrayType()) {
153
			if (this.typeBinding.isArrayType()) {
152
				ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
154
				ArrayBinding arrayBinding = (ArrayBinding) this.typeBinding;
153
				return new RecoveredTypeBinding(this.resolver, arrayBinding.leafComponentType);
155
				return new RecoveredTypeBinding(this.resolver, arrayBinding.leafComponentType);
154
			} else {
156
			} else {
155
				return new RecoveredTypeBinding(this.resolver, this.referenceBinding);
157
				return new RecoveredTypeBinding(this.resolver, this.typeBinding);
156
			}
158
			}
157
		}
159
		}
158
		if (this.innerTypeBinding != null) {
160
		if (this.innerTypeBinding != null) {
Lines 205-223 Link Here
205
	private String getInternalName() {
207
	private String getInternalName() {
206
		if (this.innerTypeBinding != null) {
208
		if (this.innerTypeBinding != null) {
207
			return this.innerTypeBinding.getInternalName();
209
			return this.innerTypeBinding.getInternalName();
208
		} else if (this.referenceBinding != null) {
210
		}
209
			org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding typeBinding = null;
211
		ReferenceBinding referenceBinding = getReferenceBinding();
210
			if (this.referenceBinding.isArrayType()) {
212
		if (referenceBinding != null) {
211
				ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
213
			return new String(referenceBinding.compoundName[referenceBinding.compoundName.length - 1]);
212
				if (arrayBinding.leafComponentType instanceof org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) {
213
					typeBinding = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) arrayBinding.leafComponentType;
214
				}
215
			} else if (this.referenceBinding instanceof org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) {
216
				typeBinding = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.referenceBinding;
217
			}
218
			if (typeBinding != null) {
219
				return new String(typeBinding.compoundName[typeBinding.compoundName.length - 1]);
220
			}
221
		}
214
		}
222
		return this.getTypeNameFrom(getType());
215
		return this.getTypeNameFrom(getType());
223
	}
216
	}
Lines 226-231 Link Here
226
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getPackage()
219
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getPackage()
227
	 */
220
	 */
228
	public IPackageBinding getPackage() {
221
	public IPackageBinding getPackage() {
222
		ReferenceBinding referenceBinding = getReferenceBinding();
223
		if (referenceBinding != null) {
224
			IPackageBinding packageBinding = this.resolver.getPackageBinding(referenceBinding.fPackage);
225
			if (packageBinding != null) return packageBinding;
226
		}
229
		CompilationUnitScope scope = this.resolver.scope();
227
		CompilationUnitScope scope = this.resolver.scope();
230
		if (scope != null) {
228
		if (scope != null) {
231
			return this.resolver.getPackageBinding(scope.getCurrentPackage());
229
			return this.resolver.getPackageBinding(scope.getCurrentPackage());
Lines 237-249 Link Here
237
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getQualifiedName()
235
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getQualifiedName()
238
	 */
236
	 */
239
	public String getQualifiedName() {
237
	public String getQualifiedName() {
240
		return this.getName();
238
		ReferenceBinding referenceBinding = getReferenceBinding();
239
		if (referenceBinding != null) {
240
			return CharOperation.toString(referenceBinding.compoundName);
241
		}
242
		return getName();
243
	}
244
245
	private ReferenceBinding getReferenceBinding() {
246
		if (this.typeBinding != null) {
247
			if (this.typeBinding.isArrayType()) {
248
				ArrayBinding arrayBinding = (ArrayBinding) this.typeBinding;
249
				if (arrayBinding.leafComponentType instanceof ReferenceBinding) {
250
					return (ReferenceBinding) arrayBinding.leafComponentType;
251
				}
252
			} else if (this.typeBinding instanceof ReferenceBinding) {
253
				return (ReferenceBinding) this.typeBinding;
254
			}
255
		}
256
		return null;
241
	}
257
	}
242
258
243
	/* (non-Javadoc)
259
	/* (non-Javadoc)
244
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass()
260
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass()
245
	 */
261
	 */
246
	public ITypeBinding getSuperclass() {
262
	public ITypeBinding getSuperclass() {
263
		if (getQualifiedName().equals("java.lang.Object")) {	//$NON-NLS-1$
264
			return null;
265
		}
247
		return this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
266
		return this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
248
	}
267
	}
249
268
Lines 251-257 Link Here
251
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getTypeArguments()
270
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getTypeArguments()
252
	 */
271
	 */
253
	public ITypeBinding[] getTypeArguments() {
272
	public ITypeBinding[] getTypeArguments() {
254
		if (this.referenceBinding != null) {
273
		if (this.typeBinding != null) {
255
			return this.typeArguments = TypeBinding.NO_TYPE_BINDINGS;
274
			return this.typeArguments = TypeBinding.NO_TYPE_BINDINGS;
256
		}
275
		}
257
		if (this.typeArguments != null) {
276
		if (this.typeArguments != null) {
Lines 331-342 Link Here
331
	/* (non-Javadoc)
350
	/* (non-Javadoc)
332
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isAssignmentCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
351
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isAssignmentCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
333
	 */
352
	 */
334
	public boolean isAssignmentCompatible(ITypeBinding typeBinding) {
353
	public boolean isAssignmentCompatible(ITypeBinding binding) {
335
		if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
354
		if ("java.lang.Object".equals(binding.getQualifiedName())) { //$NON-NLS-1$
336
			return true;
355
			return true;
337
		}
356
		}
338
		// since recovered binding are not unique isEqualTo is required
357
		// since recovered binding are not unique isEqualTo is required
339
		return this.isEqualTo(typeBinding);
358
		return this.isEqualTo(binding);
340
	}
359
	}
341
360
342
	/* (non-Javadoc)
361
	/* (non-Javadoc)
Lines 349-360 Link Here
349
	/* (non-Javadoc)
368
	/* (non-Javadoc)
350
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isCastCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
369
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isCastCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
351
	 */
370
	 */
352
	public boolean isCastCompatible(ITypeBinding typeBinding) {
371
	public boolean isCastCompatible(ITypeBinding binding) {
353
		if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
372
		if ("java.lang.Object".equals(binding.getQualifiedName())) { //$NON-NLS-1$
354
			return true;
373
			return true;
355
		}
374
		}
356
		// since recovered binding are not unique isEqualTo is required
375
		// since recovered binding are not unique isEqualTo is required
357
		return this.isEqualTo(typeBinding);
376
		return this.isEqualTo(binding);
358
	}
377
	}
359
378
360
	/* (non-Javadoc)
379
	/* (non-Javadoc)
Lines 450-461 Link Here
450
	/* (non-Javadoc)
469
	/* (non-Javadoc)
451
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isSubTypeCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
470
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#isSubTypeCompatible(org.eclipse.jdt.core.dom.ITypeBinding)
452
	 */
471
	 */
453
	public boolean isSubTypeCompatible(ITypeBinding typeBinding) {
472
	public boolean isSubTypeCompatible(ITypeBinding binding) {
454
		if ("java.lang.Object".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$
473
		if ("java.lang.Object".equals(binding.getQualifiedName())) { //$NON-NLS-1$
455
			return true;
474
			return true;
456
		}
475
		}
457
		// since recovered binding are not unique isEqualTo is required
476
		// since recovered binding are not unique isEqualTo is required
458
		return this.isEqualTo(typeBinding);
477
		return this.isEqualTo(binding);
459
	}
478
	}
460
479
461
	/* (non-Javadoc)
480
	/* (non-Javadoc)
Lines 523-531 Link Here
523
		} else if (this.currentType != null) {
542
		} else if (this.currentType != null) {
524
			buffer.append("currentType") //$NON-NLS-1$
543
			buffer.append("currentType") //$NON-NLS-1$
525
			      .append(this.currentType.toString());
544
			      .append(this.currentType.toString());
526
		} else if (this.referenceBinding != null) {
545
		} else if (this.typeBinding != null) {
527
			buffer.append("referenceBinding") //$NON-NLS-1$
546
			buffer.append("typeBinding") //$NON-NLS-1$
528
				  .append(this.referenceBinding.computeUniqueKey());
547
				  .append(this.typeBinding.computeUniqueKey());
529
		} else if (variableDeclaration != null) {
548
		} else if (variableDeclaration != null) {
530
			buffer
549
			buffer
531
				.append("variableDeclaration") //$NON-NLS-1$
550
				.append("variableDeclaration") //$NON-NLS-1$

Return to bug 186410