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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (+34 lines)
Lines 2389-2394 Link Here
2389
		return new ProblemReferenceBinding(compoundName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound);
2389
		return new ProblemReferenceBinding(compoundName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound);
2390
	}
2390
	}
2391
2391
2392
	/* Answer the package from the compoundName or null if it begins with a type.
2393
	* Intended to be used while resolving a package name only.
2394
	* 
2395
	* Internal use only
2396
	*/
2397
	public final Binding getOnlyPackage(char[][] compoundName) {
2398
 		compilationUnitScope().recordQualifiedReference(compoundName);
2399
		Binding binding = getTypeOrPackage(compoundName[0], Binding.PACKAGE, true);
2400
		if (binding == null || !binding.isValidBinding()) {
2401
			char[][] qName = new char[][] { compoundName[0] };
2402
			return new ProblemReferenceBinding(qName, null /* no closest match since search for pkg*/, ProblemReasons.NotFound);
2403
		}
2404
		if (!(binding instanceof PackageBinding)) {
2405
			return null; // compoundName does not start with a package
2406
		}
2407
2408
		int currentIndex = 1, length = compoundName.length;
2409
		PackageBinding packageBinding = (PackageBinding) binding;
2410
		while (currentIndex < length) {
2411
			binding = packageBinding.getPackage(compoundName[currentIndex++]);
2412
			if (binding == null) {
2413
				return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, currentIndex), null /* no closest match since search for pkg*/, ProblemReasons.NotFound);
2414
			}
2415
			if (!binding.isValidBinding()) {
2416
				return new ProblemReferenceBinding(
2417
					CharOperation.subarray(compoundName, 0, currentIndex),
2418
					binding instanceof ReferenceBinding ? (ReferenceBinding)((ReferenceBinding)binding).closestMatch() : null,
2419
					binding.problemId());
2420
			}
2421
			packageBinding = (PackageBinding) binding;
2422
		}
2423
		return packageBinding;
2424
	}
2425
2392
	/* Answer the type binding that corresponds the given name, starting the lookup in the receiver.
2426
	/* Answer the type binding that corresponds the given name, starting the lookup in the receiver.
2393
	* The name provided is a simple source name (e.g., "Object" , "Point", ...)
2427
	* The name provided is a simple source name (e.g., "Object" , "Point", ...)
2394
	*/
2428
	*/
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-1 / +1 lines)
Lines 1384-1390 Link Here
1384
			org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
1384
			org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
1385
			if (node instanceof ImportReference) {
1385
			if (node instanceof ImportReference) {
1386
				ImportReference importReference = (ImportReference) node;
1386
				ImportReference importReference = (ImportReference) node;
1387
				Binding binding = this.scope.getTypeOrPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
1387
				Binding binding = this.scope.getOnlyPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
1388
				if ((binding != null) && (binding.isValidBinding())) {
1388
				if ((binding != null) && (binding.isValidBinding())) {
1389
					if (binding instanceof ReferenceBinding) {
1389
					if (binding instanceof ReferenceBinding) {
1390
						// this only happens if a type name has the same name as its package
1390
						// this only happens if a type name has the same name as its package
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java (-1 / +44 lines)
Lines 122-128 Link Here
122
	static {
122
	static {
123
//		TESTS_NAMES = new String[] {"test0602"};
123
//		TESTS_NAMES = new String[] {"test0602"};
124
//		TESTS_RANGE = new int[] { 721, -1 };
124
//		TESTS_RANGE = new int[] { 721, -1 };
125
//		TESTS_NUMBERS =  new int[] { 723, 724 };
125
//		TESTS_NUMBERS =  new int[] { 725 };
126
	}
126
	}
127
	public static Test suite() {
127
	public static Test suite() {
128
		return buildModelTestSuite(ASTConverterTestAST4_2.class);
128
		return buildModelTestSuite(ASTConverterTestAST4_2.class);
Lines 10684-10687 Link Here
10684
		assertFalse(isRecovered((ASTNode) statements.get(1)));
10684
		assertFalse(isRecovered((ASTNode) statements.get(1)));
10685
		assertFalse(isRecovered((ASTNode) statements.get(2)));
10685
		assertFalse(isRecovered((ASTNode) statements.get(2)));
10686
	}
10686
	}
10687
	/*
10688
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=357471
10689
	 */
10690
	public void test0725() throws JavaModelException {
10691
		ICompilationUnit workingCopy = null;
10692
		try {
10693
			String contents =
10694
				"package one.two;\n" +
10695
				"public class one {}";
10696
			workingCopy = getWorkingCopy("/Converter/src/one/two/one.java", true/*resolve*/);
10697
			CompilationUnit unit = (CompilationUnit) buildAST(
10698
				AST.JLS3,
10699
				contents,
10700
				workingCopy,
10701
				true,
10702
				true,
10703
				true);
10704
			PackageDeclaration packageDeclaration = unit.getPackage();
10705
			IPackageBinding packageBinding = packageDeclaration.resolveBinding();
10706
			assertNotNull("No binding", packageBinding);
10707
			assertEquals("Wrong name", "one.two", packageBinding.getName());
10708
			Name packageName = packageDeclaration.getName();
10709
			IBinding binding = packageName.resolveBinding();
10710
			assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
10711
			packageBinding = (IPackageBinding) binding;
10712
			assertEquals("Wrong name", "one.two", packageBinding.getName());
10713
			packageName = ((QualifiedName) packageName).getQualifier();
10714
			binding = packageName.resolveBinding();
10715
			assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
10716
			packageBinding = (IPackageBinding) binding;
10717
			assertEquals("Wrong name", "one", packageBinding.getName());
10718
			packageName = packageDeclaration.getName();
10719
			packageName = ((QualifiedName) packageName).getName();
10720
			binding = packageName.resolveBinding();
10721
			assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
10722
			packageBinding = (IPackageBinding) binding;
10723
			assertEquals("Wrong name", "one.two", packageBinding.getName());
10724
		} finally {
10725
			if (workingCopy != null) {
10726
				workingCopy.discardWorkingCopy();
10727
			}
10728
		}
10729
	}
10687
}
10730
}

Return to bug 357471