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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/Compiler.java (-3 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 352-357 Link Here
352
		ICompilationUnit sourceUnit,
352
		ICompilationUnit sourceUnit,
353
		CompilationUnitDeclaration parsedUnit) {
353
		CompilationUnitDeclaration parsedUnit) {
354
354
355
		if (this.unitsToProcess == null)
356
			return; // not collecting units
357
		
355
		// append the unit to the list of ones to process later on
358
		// append the unit to the list of ones to process later on
356
		int size = this.unitsToProcess.length;
359
		int size = this.unitsToProcess.length;
357
		if (this.totalUnits == size)
360
		if (this.totalUnits == size)
Lines 876-883 Link Here
876
				// build and record parsed units
879
				// build and record parsed units
877
				this.parseThreshold = 0; // will request a full parse
880
				this.parseThreshold = 0; // will request a full parse
878
				beginToCompile(new ICompilationUnit[] { sourceUnit });
881
				beginToCompile(new ICompilationUnit[] { sourceUnit });
879
				// process all units (some more could be injected in the loop by the lookup environment)
882
				// find the right unit from what was injected via accept(ICompilationUnit,..):
880
				unit = this.unitsToProcess[0];
883
				for (int i=0; i<this.totalUnits; i++) {
884
					if (   this.unitsToProcess[i] != null
885
						&& this.unitsToProcess[i].compilationResult.compilationUnit == sourceUnit) 
886
					{
887
						unit = this.unitsToProcess[i];
888
						break;
889
					}						
890
				}
891
				if (unit == null)
892
					unit = this.unitsToProcess[0]; // fall back to old behavior
893
881
			} else {
894
			} else {
882
				// initial type binding creation
895
				// initial type binding creation
883
				this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/);
896
				this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/);
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (-1 / +8 lines)
Lines 24-29 Link Here
24
import org.eclipse.jdt.internal.compiler.env.*;
24
import org.eclipse.jdt.internal.compiler.env.*;
25
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
25
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
26
import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor;
26
import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor;
27
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
27
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
28
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
28
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage;
29
import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage;
29
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
30
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
Lines 136-142 Link Here
136
		this.typeRequestor.accept(answer.getBinaryType(), packageBinding, answer.getAccessRestriction());
137
		this.typeRequestor.accept(answer.getBinaryType(), packageBinding, answer.getAccessRestriction());
137
	} else if (answer.isCompilationUnit()) {
138
	} else if (answer.isCompilationUnit()) {
138
		// the type was found as a .java file, try to build it then search the cache
139
		// the type was found as a .java file, try to build it then search the cache
139
		this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction());
140
		try {
141
			this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction());
142
		} catch (AbortCompilation abort) {
143
			if (CharOperation.equals(name, TypeConstants.PACKAGE_INFO_NAME))
144
				return null; // silently, requestor may not be able to handle compilation units (HierarchyResolver)
145
			throw abort;
146
		}
140
	} else if (answer.isSourceType()) {
147
	} else if (answer.isSourceType()) {
141
		// the type was found as a source model
148
		// the type was found as a source model
142
		this.typeRequestor.accept(answer.getSourceTypes(), packageBinding, answer.getAccessRestriction());
149
		this.typeRequestor.accept(answer.getSourceTypes(), packageBinding, answer.getAccessRestriction());
(-)model/org/eclipse/jdt/internal/core/SearchableEnvironment.java (-3 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-27 Link Here
22
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
22
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
23
import org.eclipse.jdt.internal.compiler.env.ISourceType;
23
import org.eclipse.jdt.internal.compiler.env.ISourceType;
24
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
24
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
25
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
25
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
26
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
26
import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor;
27
import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor;
27
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
28
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
Lines 134-141 Link Here
134
							sourceTypes[index++] = otherType;
135
							sourceTypes[index++] = otherType;
135
					}
136
					}
136
					return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
137
					return new NameEnvironmentAnswer(sourceTypes, answer.restriction);
137
				} catch (JavaModelException npe) {
138
				} catch (JavaModelException jme) {
138
					// fall back to using owner
139
					if (String.valueOf(TypeConstants.PACKAGE_INFO_NAME).equals(typeName)) {
140
						// in case of package-info.java the type doesn't exist in the model,
141
						// but the CU may still help in order to fetch package level annotations.
142
						return new NameEnvironmentAnswer((ICompilationUnit)answer.type.getParent(), answer.restriction);
143
					}
144
					// no usable answer
139
				}
145
				}
140
			}
146
			}
141
		}
147
		}
(-)src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java (-1 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 23-28 Link Here
23
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.*;
26
import org.eclipse.jdt.core.compiler.IProblem;
27
import org.eclipse.jdt.core.dom.AST;
28
import org.eclipse.jdt.core.dom.ASTParser;
26
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
29
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
27
import org.eclipse.jdt.internal.core.Buffer;
30
import org.eclipse.jdt.internal.core.Buffer;
28
import org.eclipse.jdt.internal.core.CompilationUnit;
31
import org.eclipse.jdt.internal.core.CompilationUnit;
Lines 478-483 Link Here
478
}
481
}
479
482
480
/*
483
/*
484
 * Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment 
485
 * Ensure that package level annotation is evaluated during AST creation.
486
 */
487
public void testDeprecatedFlag10() throws CoreException {
488
	createFolder("/P/src/p2");
489
490
	createFile(
491
			"/P/src/p2/package-info.java",
492
			"@java.lang.Deprecated package p2;\n"
493
		);
494
	
495
	// workaround for missing type in jclMin:
496
	createFolder("/P/src/java/lang");
497
	createFile(
498
			"/P/src/java/lang/Deprecated.java",
499
			"package java.lang;\n" +
500
			"@Retention(RetentionPolicy.RUNTIME)\n" + 
501
			"public @interface Deprecated {\n" + 
502
			"}\n"
503
		);
504
505
	createFile("/P/src/p2/C.java", 
506
			"package p2;\n" +
507
			"public class C {}\n");
508
509
	createFile("/P/src/p/D.java", 
510
			"package p;\n" +
511
			"public class D extends p2.C {}\n");
512
	ICompilationUnit cuD = getCompilationUnit("/P/src/p/D.java");
513
	
514
	ASTParser parser = ASTParser.newParser(AST.JLS3);
515
	parser.setProject(this.testProject);
516
	parser.setSource(cuD);
517
	parser.setResolveBindings(true);
518
	org.eclipse.jdt.core.dom.CompilationUnit cuAST = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
519
	IProblem[] problems = cuAST.getProblems();
520
	assertEquals("Should have 1 problem", 1, problems.length);
521
	assertEquals("Should have a deprecation warning", "The type C is deprecated", problems[0].getMessage());
522
}
523
/*
481
 * Ensures that the primary type of a cu can be found.
524
 * Ensures that the primary type of a cu can be found.
482
 */
525
 */
483
public void testFindPrimaryType1() throws JavaModelException {
526
public void testFindPrimaryType1() throws JavaModelException {
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+34 lines)
Lines 772-777 Link Here
772
			annotation.discardWorkingCopy();
772
			annotation.discardWorkingCopy();
773
	}
773
	}
774
}
774
}
775
776
/*
777
 * Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment
778
 * Ensures that an annotated package-info.java doesn't confuse the reconciler.
779
 */
780
public void testAnnotations6() throws CoreException {
781
782
	createFolder("/Reconciler15/src/p1");
783
784
	createFile("/Reconciler15/src/p1/package-info.java", "@java.lang.Deprecated package p1;");
785
	createFile("/Reconciler15/src/p1/C.java",
786
			"package p1;\n" +
787
			"public class C {\n" +
788
			"  static class Y extends C {}\n" +
789
			"}"
790
	);
791
	ICompilationUnit myWC = getCompilationUnit("/Reconciler15/src/p1/C.java").getWorkingCopy(this.wcOwner, null);
792
	org.eclipse.jdt.core.dom.CompilationUnit unit = myWC.reconcile(AST.JLS3, true, this.wcOwner, null);
793
	assertProblems(
794
			"Unexpected problems",
795
			"----------\n" + 
796
			"----------\n" + 
797
			"----------\n" + 
798
			"----------\n"
799
	);
800
	assertASTNodeEquals(
801
			"Unexpected ast",
802
			"package p1;\n" + 
803
			"public class C {\n" + 
804
			"static class Y extends C {\n" + 
805
			"  }\n" + 
806
			"}\n",
807
			unit);
808
}
775
/*
809
/*
776
 * Ensures that the AST broadcasted during a reconcile operation is correct.
810
 * Ensures that the AST broadcasted during a reconcile operation is correct.
777
 * (case of a working copy being reconciled with changes, creating AST and no problem detection)
811
 * (case of a working copy being reconciled with changes, creating AST and no problem detection)
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-1 / +37 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 2518-2521 Link Here
2518
	deleteProject("P2");
2518
	deleteProject("P2");
2519
}
2519
}
2520
}
2520
}
2521
// Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment
2522
// Ensure that package-info doesn't cause AbortCompilation from the HierarchyResolver.
2523
public void testPackageInfo01() throws CoreException {
2524
	try {
2525
		createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB"}, new String[0], "bin");
2526
2527
		createFolder("/P/src/p");
2528
		createFile(
2529
				"/P/src/p/package-info.java",
2530
				"/** Doc comment*/ package p;\n"
2531
			);
2532
		createFile(
2533
				"/P/src/p/A.java",
2534
				"package p;\n" +
2535
				"public class A {\n" +
2536
				"}\n"
2537
			);
2538
		createFile(
2539
				"/P/src/p/C.java",
2540
				"package p;\n" +
2541
				"public class C extends A {\n" +
2542
				"    void foo() {\n" +
2543
				"        class Bar extends C {}\n" +
2544
				"    }\n" +
2545
				"}\n"
2546
			);
2547
		ICompilationUnit cu = getCompilationUnit("/P/src/p/C.java");
2548
		IType type = cu.getType("C");
2549
		IMethod method = type.getMethod("foo", new String[0]);
2550
		IType local = method.getType("Bar", 1);
2551
		ITypeHierarchy cHierarchy = type.newTypeHierarchy(null);
2552
		assertTrue("Local type should be in the hierarchy", cHierarchy.contains(local));
2553
	} finally {
2554
		deleteProject("P");
2555
	}	
2556
}
2521
}
2557
}

Return to bug 337868