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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/OverflowingCacheTests.java (-6 / +5 lines)
Lines 18-32 Link Here
18
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.core.runtime.Path;
22
import org.eclipse.jdt.core.*;
23
import org.eclipse.jdt.core.*;
23
import org.eclipse.jdt.core.IBuffer;
24
import org.eclipse.jdt.core.IBufferChangedListener;
25
import org.eclipse.jdt.core.IOpenable;
26
import org.eclipse.jdt.internal.core.*;
24
import org.eclipse.jdt.internal.core.*;
27
import org.eclipse.jdt.internal.core.BufferCache;
28
import org.eclipse.jdt.internal.core.Openable;
29
import org.eclipse.jdt.internal.core.OverflowingLRUCache;
30
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
25
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
31
26
32
import junit.framework.Test;
27
import junit.framework.Test;
Lines 265-270 Link Here
265
		public void save(IProgressMonitor pm, boolean force) {
260
		public void save(IProgressMonitor pm, boolean force) {
266
			this.buffer.hasUnsavedChanges = false;
261
			this.buffer.hasUnsavedChanges = false;
267
		}
262
		}
263
		
264
		protected IStatus validateExistence(IResource underlyingResource) {
265
			return null;
266
		}
268
	}
267
	}
269
268
270
	public static Test suite() {
269
	public static Test suite() {
(-)src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java (-21 / +21 lines)
Lines 116-122 Link Here
116
116
117
	// test javadoc for a package fragment
117
	// test javadoc for a package fragment
118
	public void test001() throws JavaModelException {
118
	public void test001() throws JavaModelException {
119
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
119
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
120
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
120
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
121
		String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
121
		String javadoc = packageFragment.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
122
		assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
122
		assertNotNull("Should have a javadoc", javadoc); //$NON-NLS-1$
Lines 124-130 Link Here
124
124
125
	// for a class file
125
	// for a class file
126
	public void test002() throws JavaModelException {
126
	public void test002() throws JavaModelException {
127
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
127
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
128
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
128
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
129
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
129
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
130
		assertNotNull(classFile);
130
		assertNotNull(classFile);
Lines 134-140 Link Here
134
134
135
	// for a field
135
	// for a field
136
	public void test003() throws JavaModelException {
136
	public void test003() throws JavaModelException {
137
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
137
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
138
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
138
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
139
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
139
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
140
		assertNotNull(classFile);
140
		assertNotNull(classFile);
Lines 147-153 Link Here
147
147
148
	// for a method
148
	// for a method
149
	public void test004() throws JavaModelException {
149
	public void test004() throws JavaModelException {
150
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
150
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
151
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
151
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
152
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
152
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
153
		assertNotNull(classFile);
153
		assertNotNull(classFile);
Lines 166-172 Link Here
166
166
167
	// for a constructor
167
	// for a constructor
168
	public void test005() throws JavaModelException {
168
	public void test005() throws JavaModelException {
169
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
169
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
170
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
170
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
171
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
171
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
172
		assertNotNull(classFile);
172
		assertNotNull(classFile);
Lines 183-189 Link Here
183
	
183
	
184
	// for a member type
184
	// for a member type
185
	public void test006() throws JavaModelException {
185
	public void test006() throws JavaModelException {
186
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
186
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
187
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
187
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
188
		IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
188
		IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
189
		assertNotNull(classFile);
189
		assertNotNull(classFile);
Lines 193-199 Link Here
193
	
193
	
194
	// for a constructor
194
	// for a constructor
195
	public void test007() throws JavaModelException {
195
	public void test007() throws JavaModelException {
196
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
196
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
197
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
197
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
198
		IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
198
		IClassFile classFile = packageFragment.getClassFile("X$A.class"); //$NON-NLS-1$
199
		assertNotNull(classFile);
199
		assertNotNull(classFile);
Lines 210-216 Link Here
210
	
210
	
211
	// for a method foo2
211
	// for a method foo2
212
	public void test008() throws JavaModelException {
212
	public void test008() throws JavaModelException {
213
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
213
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
214
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
214
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
215
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
215
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
216
		assertNotNull(classFile);
216
		assertNotNull(classFile);
Lines 226-232 Link Here
226
	
226
	
227
	// for a field f2
227
	// for a field f2
228
	public void test009() throws JavaModelException {
228
	public void test009() throws JavaModelException {
229
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
229
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
230
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
230
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
231
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
231
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
232
		assertNotNull(classFile);
232
		assertNotNull(classFile);
Lines 267-273 Link Here
267
				}
267
				}
268
			}
268
			}
269
			this.project.setRawClasspath(entries, null);
269
			this.project.setRawClasspath(entries, null);
270
			IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
270
			IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
271
			assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
271
			assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
272
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
272
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
273
			assertNotNull(classFile);
273
			assertNotNull(classFile);
Lines 286-292 Link Here
286
	
286
	
287
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120597
287
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120597
288
	public void test011() throws JavaModelException {
288
	public void test011() throws JavaModelException {
289
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
289
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
290
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
290
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
291
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
291
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
292
		assertNotNull(classFile);
292
		assertNotNull(classFile);
Lines 299-305 Link Here
299
	
299
	
300
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
300
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
301
	public void test012() throws JavaModelException {
301
	public void test012() throws JavaModelException {
302
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
302
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
303
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
303
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
304
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
304
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
305
		assertNotNull(classFile);
305
		assertNotNull(classFile);
Lines 310-316 Link Here
310
	
310
	
311
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559
311
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120559
312
	public void test013() throws JavaModelException {
312
	public void test013() throws JavaModelException {
313
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
313
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
314
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
314
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
315
		IClassFile classFile = packageFragment.getClassFile("W.class"); //$NON-NLS-1$
315
		IClassFile classFile = packageFragment.getClassFile("W.class"); //$NON-NLS-1$
316
		assertNotNull(classFile);
316
		assertNotNull(classFile);
Lines 320-326 Link Here
320
	
320
	
321
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
321
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
322
	public void test014() throws JavaModelException {
322
	public void test014() throws JavaModelException {
323
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
323
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
324
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
324
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
325
		IClassFile classFile = packageFragment.getClassFile("E.class"); //$NON-NLS-1$
325
		IClassFile classFile = packageFragment.getClassFile("E.class"); //$NON-NLS-1$
326
		assertNotNull(classFile);
326
		assertNotNull(classFile);
Lines 331-337 Link Here
331
	
331
	
332
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
332
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120637
333
	public void test015() throws JavaModelException {
333
	public void test015() throws JavaModelException {
334
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
334
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
335
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
335
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
336
		IClassFile classFile = packageFragment.getClassFile("Annot.class"); //$NON-NLS-1$
336
		IClassFile classFile = packageFragment.getClassFile("Annot.class"); //$NON-NLS-1$
337
		assertNotNull(classFile);
337
		assertNotNull(classFile);
Lines 356-362 Link Here
356
				}
356
				}
357
			}
357
			}
358
			this.project.setRawClasspath(entries, null);
358
			this.project.setRawClasspath(entries, null);
359
			IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
359
			IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
360
			assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
360
			assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
361
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
361
			IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
362
			assertNotNull(classFile);
362
			assertNotNull(classFile);
Lines 378-384 Link Here
378
	
378
	
379
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120875
379
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120875
380
	public void test017() throws JavaModelException {
380
	public void test017() throws JavaModelException {
381
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
381
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
382
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
382
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
383
		IClassFile classFile = packageFragment.getClassFile("Annot2.class"); //$NON-NLS-1$
383
		IClassFile classFile = packageFragment.getClassFile("Annot2.class"); //$NON-NLS-1$
384
		assertNotNull(classFile);
384
		assertNotNull(classFile);
Lines 389-395 Link Here
389
	
389
	
390
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
390
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
391
	public void test018() throws JavaModelException {
391
	public void test018() throws JavaModelException {
392
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2/p3"); //$NON-NLS-1$
392
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$
393
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
393
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
394
		IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
394
		IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
395
		assertNotNull(classFile);
395
		assertNotNull(classFile);
Lines 407-413 Link Here
407
	
407
	
408
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
408
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=138167
409
	public void test019() throws JavaModelException {
409
	public void test019() throws JavaModelException {
410
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2/p3"); //$NON-NLS-1$
410
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2.p3"); //$NON-NLS-1$
411
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
411
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
412
		IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
412
		IClassFile classFile = packageFragment.getClassFile("C.class"); //$NON-NLS-1$
413
		assertNotNull(classFile);
413
		assertNotNull(classFile);
Lines 426-432 Link Here
426
	
426
	
427
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160
427
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=139160
428
	public void test020() throws JavaModelException {
428
	public void test020() throws JavaModelException {
429
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
429
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
430
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
430
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
431
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
431
		IClassFile classFile = packageFragment.getClassFile("Z.class"); //$NON-NLS-1$
432
		assertNotNull(classFile);
432
		assertNotNull(classFile);
Lines 484-490 Link Here
484
484
485
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149154
485
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149154
486
	public void test022() throws JavaModelException {
486
	public void test022() throws JavaModelException {
487
		IPackageFragment packageFragment = this.root.getPackageFragment("p1/p2"); //$NON-NLS-1$
487
		IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
488
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
488
		assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
489
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
489
		IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
490
		assertNotNull(classFile);
490
		assertNotNull(classFile);
(-)model/org/eclipse/jdt/internal/core/ExternalJavaProject.java (+5 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.ResourcesPlugin;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.JavaCore;
18
import org.eclipse.jdt.core.JavaCore;
Lines 59-62 Link Here
59
		return false;
60
		return false;
60
	}
61
	}
61
62
63
	protected IStatus validateExistence(IResource underlyingResource) {
64
		// allow opening of external project
65
		return JavaModelStatus.VERIFIED_OK;
66
	}
62
}
67
}
(-)model/org/eclipse/jdt/internal/core/JavaModel.java (+6 lines)
Lines 25-30 Link Here
25
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.Assert;
26
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.Path;
29
import org.eclipse.core.runtime.Path;
29
import org.eclipse.jdt.core.*;
30
import org.eclipse.jdt.core.*;
30
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
31
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
Lines 377-380 Link Here
377
	
378
	
378
	return null;
379
	return null;
379
}
380
}
381
382
protected IStatus validateExistence(IResource underlyingResource) {
383
	// Java model always exists
384
	return JavaModelStatus.VERIFIED_OK;
385
}
380
}
386
}
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-8 / +10 lines)
Lines 79-89 Link Here
79
 * @see Signature
79
 * @see Signature
80
 */
80
 */
81
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
81
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
82
	// check whether the class file can be opened
83
	IStatus status = validateClassFile();
84
	if (!status.isOK()) throw newJavaModelException(status);
85
	if (underlyingResource != null && !underlyingResource.isAccessible()) throw newNotPresentException();
86
87
	IBinaryType typeInfo = getBinaryTypeInfo((IFile) underlyingResource);
82
	IBinaryType typeInfo = getBinaryTypeInfo((IFile) underlyingResource);
88
	if (typeInfo == null) {
83
	if (typeInfo == null) {
89
		// The structure of a class file is unknown if a class file format errors occurred
84
		// The structure of a class file is unknown if a class file format errors occurred
Lines 176-184 Link Here
176
	ClassFile other = (ClassFile) o;
171
	ClassFile other = (ClassFile) o;
177
	return this.name.equals(other.name) && this.parent.equals(other.parent);
172
	return this.name.equals(other.name) && this.parent.equals(other.parent);
178
}
173
}
179
public boolean exists() {
180
	return super.exists() && validateClassFile().isOK();
181
}
182
public boolean existsUsingJarTypeCache() {
174
public boolean existsUsingJarTypeCache() {
183
	if (getPackageFragmentRoot().isArchive()) {
175
	if (getPackageFragmentRoot().isArchive()) {
184
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
176
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
Lines 793-796 Link Here
793
			}
785
			}
794
		});
786
		});
795
}
787
}
788
789
protected IStatus validateExistence(IResource underlyingResource) {
790
	// check whether the class file can be opened
791
	IStatus status = validateClassFile();
792
	if (!status.isOK()) 
793
		return status;
794
	if (underlyingResource != null && !underlyingResource.isAccessible()) 
795
		return newDoesNotExistStatus();
796
	return JavaModelStatus.VERIFIED_OK;
797
}
796
}
798
}
(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-13 / +24 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.OperationCanceledException;
25
import org.eclipse.core.runtime.OperationCanceledException;
25
import org.eclipse.core.runtime.Path;
26
import org.eclipse.core.runtime.Path;
26
import org.eclipse.jdt.core.IClassFile;
27
import org.eclipse.jdt.core.IClassFile;
Lines 64-84 Link Here
64
 * @see Openable
65
 * @see Openable
65
 */
66
 */
66
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
67
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
67
68
	// check whether this pkg can be opened
69
	if (!underlyingResource.isAccessible()) throw newNotPresentException();
70
	
71
	// check that it is not excluded (https://bugs.eclipse.org/bugs/show_bug.cgi?id=138577)
72
	int kind = getKind();
73
	if (kind == IPackageFragmentRoot.K_SOURCE && Util.isExcluded(this)) 
74
		throw newNotPresentException();
75
76
	// check that the name of the package is valid (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108456)
77
	if (!isValidPackageName())
78
		throw newNotPresentException();
79
80
	// add compilation units/class files from resources
68
	// add compilation units/class files from resources
81
	HashSet vChildren = new HashSet();
69
	HashSet vChildren = new HashSet();
70
	int kind = getKind();
82
	try {
71
	try {
83
	    PackageFragmentRoot root = getPackageFragmentRoot();
72
	    PackageFragmentRoot root = getPackageFragmentRoot();
84
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
73
		char[][] inclusionPatterns = root.fullInclusionPatternChars();
Lines 506-509 Link Here
506
	}
495
	}
507
	return contents;
496
	return contents;
508
}
497
}
498
499
protected IStatus validateExistence(IResource underlyingResource) {
500
	// check that the name of the package is valid (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=108456)
501
	if (!isValidPackageName())
502
		return newDoesNotExistStatus();
503
504
	// check whether this pkg can be opened
505
	if (underlyingResource != null && !resourceExists(underlyingResource)) 
506
		return newDoesNotExistStatus();
507
	
508
	// check that it is not excluded (https://bugs.eclipse.org/bugs/show_bug.cgi?id=138577)
509
	int kind;
510
	try {
511
		kind = getKind();
512
	} catch (JavaModelException e) {
513
		return e.getStatus();
514
	}
515
	if (kind == IPackageFragmentRoot.K_SOURCE && Util.isExcluded(this)) 
516
		return newDoesNotExistStatus();
517
	
518
	return JavaModelStatus.VERIFIED_OK;
519
}
509
}
520
}
(-)model/org/eclipse/jdt/internal/core/Openable.java (-41 / +39 lines)
Lines 16-21 Link Here
16
16
17
import org.eclipse.core.resources.*;
17
import org.eclipse.core.resources.*;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.core.runtime.PerformanceStats;
21
import org.eclipse.core.runtime.PerformanceStats;
21
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.*;
Lines 173-187 Link Here
173
 * @see IJavaElement
174
 * @see IJavaElement
174
 */
175
 */
175
public boolean exists() {
176
public boolean exists() {
176
	JavaModelManager manager = JavaModelManager.getJavaModelManager();
177
	if (JavaModelManager.getJavaModelManager().getInfo(this) != null) 
177
	if (manager.getInfo(this) != null) return true;
178
		return true;
178
	if (!parentExists()) return false;
179
	switch (getElementType()) {
179
	PackageFragmentRoot root = getPackageFragmentRoot();
180
		case IJavaElement.PACKAGE_FRAGMENT:
180
	if (root != null
181
		case IJavaElement.CLASS_FILE:
181
			&& (root == this || !root.isArchive())) {
182
			if (getPackageFragmentRoot().isArchive()) {
182
		return resourceExists();
183
				// pkg or class file in a jar -> need to open it to know if it exists
184
				return super.exists();
185
			}
186
			break;
183
	}
187
	}
184
	return super.exists();
188
	return validateExistence(getResource()).isOK();
185
}
189
}
186
public String findRecommendedLineSeparator() throws JavaModelException {
190
public String findRecommendedLineSeparator() throws JavaModelException {
187
	IBuffer buffer = getBuffer();
191
	IBuffer buffer = getBuffer();
Lines 214-221 Link Here
214
		System.out.println(Thread.currentThread() +" OPENING " + element + " " + this.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
218
		System.out.println(Thread.currentThread() +" OPENING " + element + " " + this.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
215
	}
219
	}
216
	
220
	
217
	// open the parent if necessary
221
	// open its ancestors if needed
218
	openParent(info, newElements, monitor);
222
	openAncestors(newElements, monitor);
223
	
224
	// validate existence
225
	IResource underlResource = getResource();
226
	IStatus status = validateExistence(underlResource);
227
	if (!status.isOK())
228
		throw newJavaModelException(status);
229
	
219
	if (monitor != null && monitor.isCanceled()) 
230
	if (monitor != null && monitor.isCanceled()) 
220
		throw new OperationCanceledException();
231
		throw new OperationCanceledException();
221
232
Lines 226-232 Link Here
226
	// build the structure of the openable (this will open the buffer if needed)
237
	// build the structure of the openable (this will open the buffer if needed)
227
	try {
238
	try {
228
		OpenableElementInfo openableElementInfo = (OpenableElementInfo)info;
239
		OpenableElementInfo openableElementInfo = (OpenableElementInfo)info;
229
		boolean isStructureKnown = buildStructure(openableElementInfo, monitor, newElements, getResource());
240
		boolean isStructureKnown = buildStructure(openableElementInfo, monitor, newElements, underlResource);
230
		openableElementInfo.setIsStructureKnown(isStructureKnown);
241
		openableElementInfo.setIsStructureKnown(isStructureKnown);
231
	} catch (JavaModelException e) {
242
	} catch (JavaModelException e) {
232
		newElements.remove(this);
243
		newElements.remove(this);
Lines 414-451 Link Here
414
}
425
}
415
426
416
/**
427
/**
417
 * Open the parent element if necessary.
418
 */
419
protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
420
421
	Openable openableParent = (Openable)getOpenableParent();
422
	if (openableParent != null && !openableParent.isOpen()){
423
		openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
424
	}
425
}
426
427
/**
428
 *  Answers true if the parent exists (null parent is answering true)
429
 * 
430
 */
431
protected boolean parentExists(){
432
	
433
	IJavaElement parentElement = getParent();
434
	if (parentElement == null) return true;
435
	return parentElement.exists();
436
}
437
438
/**
439
 * Returns whether the corresponding resource or associated file exists
428
 * Returns whether the corresponding resource or associated file exists
440
 */
429
 */
441
protected boolean resourceExists() {
430
protected boolean resourceExists(IResource underlyingResource) {
442
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
431
	return underlyingResource.isAccessible();
443
	if (workspace == null) return false; // workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=34069
444
	return 
445
		JavaModel.getTarget(
446
			workspace.getRoot(), 
447
			this.getPath().makeRelative(), // ensure path is relative (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
448
			true) != null;
449
}
432
}
450
433
451
/**
434
/**
Lines 469-472 Link Here
469
	return (PackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
452
	return (PackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
470
}
453
}
471
454
455
/*
456
 * Validates the existence of this openable. Returns a non ok status if it doesn't exist.
457
 */
458
abstract protected IStatus validateExistence(IResource underlyingResource);
459
460
/*
461
 * Opens the ancestors of this openable that are not yet opened, validating their existence.
462
 */
463
protected void openAncestors(HashMap newElements, IProgressMonitor monitor) throws JavaModelException {
464
	Openable openableParent = (Openable)getOpenableParent();
465
	if (openableParent != null && !openableParent.isOpen()) {
466
		openableParent.generateInfos(openableParent.createElementInfo(), newElements, monitor);
467
	}
468
}
469
472
}
470
}
(-)model/org/eclipse/jdt/internal/core/JarPackageFragment.java (-86 / +84 lines)
Lines 41-135 Link Here
41
	super(root, names);
41
	super(root, names);
42
}
42
}
43
/**
43
/**
44
 * @see Openable
45
 */
46
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
47
	JarPackageFragmentRoot root = (JarPackageFragmentRoot) getParent();
48
	JarPackageFragmentRootInfo parentInfo = (JarPackageFragmentRootInfo) root.getElementInfo();
49
	ArrayList[] entries = (ArrayList[]) parentInfo.rawPackageInfo.get(this.names);
50
	if (entries == null)
51
		throw newNotPresentException();
52
	JarPackageFragmentInfo fragInfo = (JarPackageFragmentInfo) info;
53
	
54
	// compute children
55
	fragInfo.setChildren(computeChildren(entries[0/*class files*/]));
56
57
	// compute non-Java resources
58
	fragInfo.setNonJavaResources(computeNonJavaResources(entries[1/*non Java resources*/]));
59
	
60
	newElements.put(this, fragInfo);
61
	return true;
62
}
63
/**
44
 * Compute the children of this package fragment. Children of jar package fragments
64
 * Compute the children of this package fragment. Children of jar package fragments
45
 * can only be IClassFile (representing .class files).
65
 * can only be IClassFile (representing .class files).
46
 */
66
 */
47
protected boolean computeChildren(OpenableElementInfo info, ArrayList entryNames) {
67
private IJavaElement[] computeChildren(ArrayList namesWithoutExtension) {
48
	if (entryNames != null && entryNames.size() > 0) {
68
	int size = namesWithoutExtension.size();
49
		ArrayList vChildren = new ArrayList();
69
	if (size == 0)
50
		for (Iterator iter = entryNames.iterator(); iter.hasNext();) {
70
		return NO_ELEMENTS;
51
			String child = (String) iter.next();
71
	IJavaElement[] children = new IJavaElement[size];
52
			IClassFile classFile = getClassFile(child);
72
	for (int i = 0; i < size; i++) {
53
			vChildren.add(classFile);
73
		String nameWithoutExtension = (String) namesWithoutExtension.get(i);
54
		}
74
		children[i] = new ClassFile(this, nameWithoutExtension);
55
		IJavaElement[] children= new IJavaElement[vChildren.size()];
56
		vChildren.toArray(children);
57
		info.setChildren(children);
58
	} else {
59
		info.setChildren(NO_ELEMENTS);
60
	}
75
	}
61
	return true;
76
	return children;
62
}
77
}
63
/**
78
/**
64
 * Compute all the non-java resources according to the entry name found in the jar file.
79
 * Compute all the non-java resources according to the given entry names.
65
 */
80
 */
66
/* package */ void computeNonJavaResources(String[] resNames, JarPackageFragment pkg, JarPackageFragmentInfo info, String zipName) {
81
private Object[] computeNonJavaResources(ArrayList entryNames) {
67
	if (resNames == null) {
82
	int length = entryNames.size();
68
		info.setNonJavaResources(null);
83
	if (length == 0)
69
		return;
84
		return JavaElementInfo.NO_NON_JAVA_RESOURCES;
70
	}
85
	HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
71
	int max = resNames.length;
86
	HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>
72
	if (max == 0) {
87
	ArrayList topJarEntries = new ArrayList();
73
	    info.setNonJavaResources(JavaElementInfo.NO_NON_JAVA_RESOURCES);
88
	for (int i = 0; i < length; i++) {
74
	} else {
89
		String resName = (String) entryNames.get(i);
75
		HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
90
		// consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
76
		HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>
91
		if (!Util.isJavaLikeFileName(resName)) {
77
		ArrayList topJarEntries = new ArrayList();
92
			IPath filePath = new Path(resName);
78
		for (int i = 0; i < max; i++) {
93
			IPath childPath = filePath.removeFirstSegments(this.names.length);
79
			String resName = resNames[i];
94
			JarEntryFile file = new JarEntryFile(filePath.lastSegment());
80
			// consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
95
			jarEntries.put(childPath, file);
81
			if (!Util.isJavaLikeFileName(resName)) {
96
			if (childPath.segmentCount() == 1) {
82
				IPath filePath = new Path(resName);
97
				file.setParent(this);
83
				IPath childPath = filePath.removeFirstSegments(this.names.length);
98
				topJarEntries.add(file);
84
				JarEntryFile file = new JarEntryFile(filePath.lastSegment());
99
			} else {
85
				jarEntries.put(childPath, file);
100
				IPath parentPath = childPath.removeLastSegments(1);
86
				if (childPath.segmentCount() == 1) {
101
				while (parentPath.segmentCount() > 0) {
87
					file.setParent(pkg);
102
					ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
88
					topJarEntries.add(file);
103
					if (parentChildren == null) {
89
				} else {
104
						Object dir = new JarEntryDirectory(parentPath.lastSegment());
90
					IPath parentPath = childPath.removeLastSegments(1);
105
						jarEntries.put(parentPath, dir);
91
					while (parentPath.segmentCount() > 0) {
106
						childrenMap.put(parentPath, parentChildren = new ArrayList());
92
						ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
107
						parentChildren.add(childPath);
93
						if (parentChildren == null) {
108
						if (parentPath.segmentCount() == 1) {
94
							Object dir = new JarEntryDirectory(parentPath.lastSegment());
109
							topJarEntries.add(dir);
95
							jarEntries.put(parentPath, dir);
110
							break;
96
							childrenMap.put(parentPath, parentChildren = new ArrayList());
97
							parentChildren.add(childPath);
98
							if (parentPath.segmentCount() == 1) {
99
								topJarEntries.add(dir);
100
								break;
101
							}
102
							childPath = parentPath;
103
							parentPath = childPath.removeLastSegments(1);
104
						} else {
105
							parentChildren.add(childPath);
106
							break; // all parents are already registered
107
						}
111
						}
112
						childPath = parentPath;
113
						parentPath = childPath.removeLastSegments(1);
114
					} else {
115
						parentChildren.add(childPath);
116
						break; // all parents are already registered
108
					}
117
					}
109
				}
118
				}
110
			}
119
			}
111
		}
120
		}
112
		Iterator entries = childrenMap.entrySet().iterator();
121
	}
113
		while (entries.hasNext()) {
122
	Iterator entries = childrenMap.entrySet().iterator();
114
			Map.Entry entry = (Map.Entry) entries.next();
123
	while (entries.hasNext()) {
115
			IPath entryPath = (IPath) entry.getKey();
124
		Map.Entry entry = (Map.Entry) entries.next();
116
			ArrayList entryValue =  (ArrayList) entry.getValue();
125
		IPath entryPath = (IPath) entry.getKey();
117
			JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
126
		ArrayList entryValue =  (ArrayList) entry.getValue();
118
			int size = entryValue.size();
127
		JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
119
			IJarEntryResource[] children = new IJarEntryResource[size];
128
		int size = entryValue.size();
120
			for (int i = 0; i < size; i++) {
129
		IJarEntryResource[] children = new IJarEntryResource[size];
121
				JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
130
		for (int i = 0; i < size; i++) {
122
				child.setParent(jarEntryDirectory);
131
			JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
123
				children[i] = child;
132
			child.setParent(jarEntryDirectory);
124
			}
133
			children[i] = child;
125
			jarEntryDirectory.setChildren(children);
134
		}
126
			if (entryPath.segmentCount() == 1) {
135
		jarEntryDirectory.setChildren(children);
127
				jarEntryDirectory.setParent(pkg);
136
		if (entryPath.segmentCount() == 1) {
128
			}
137
			jarEntryDirectory.setParent(this);
129
		}
138
		}
130
		Object[] res = topJarEntries.toArray(new Object[topJarEntries.size()]);
131
		info.setNonJavaResources(res);
132
	}
139
	}
140
	return topJarEntries.toArray(new Object[topJarEntries.size()]);
133
}
141
}
134
/**
142
/**
135
 * Returns true if this fragment contains at least one java resource.
143
 * Returns true if this fragment contains at least one java resource.
Lines 148-164 Link Here
148
 * @see JavaElement
156
 * @see JavaElement
149
 */
157
 */
150
protected Object createElementInfo() {
158
protected Object createElementInfo() {
151
	return null; // not used for JarPackageFragments: info is created when jar is opened
159
	return new JarPackageFragmentInfo();
152
}
153
/*
154
 * @see JavaElement#generateInfos
155
 */
156
protected void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
157
	// Open my jar: this creates all the pkg infos
158
	Openable openableParent = (Openable)this.parent;
159
	if (!openableParent.isOpen()) {
160
		openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
161
	}
162
}
160
}
163
/**
161
/**
164
 * @see org.eclipse.jdt.core.IPackageFragment
162
 * @see org.eclipse.jdt.core.IPackageFragment
(-)model/org/eclipse/jdt/internal/core/JavaElement.java (-1 / +4 lines)
Lines 482-488 Link Here
482
	 * Creates and returns a new not present exception for this element.
482
	 * Creates and returns a new not present exception for this element.
483
	 */
483
	 */
484
	public JavaModelException newNotPresentException() {
484
	public JavaModelException newNotPresentException() {
485
		return new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
485
		return new JavaModelException(newDoesNotExistStatus());
486
	}
487
	protected JavaModelStatus newDoesNotExistStatus() {
488
		return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this);
486
	}
489
	}
487
	/**
490
	/**
488
	 * Creates and returns a new Java model exception for this element with the given status.
491
	 * Creates and returns a new Java model exception for this element with the given status.
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-13 / +10 lines)
Lines 152-163 Link Here
152
 * @see Openable
152
 * @see Openable
153
 */
153
 */
154
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
154
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
155
	
156
	// check whether this pkg fragment root can be opened
157
	IStatus status = validateOnClasspath();
158
	if (!status.isOK()) throw newJavaModelException(status);
159
	if (!resourceExists()) throw newNotPresentException();
160
161
	((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
155
	((PackageFragmentRootInfo) info).setRootKind(determineKind(underlyingResource));
162
	return computeChildren(info, newElements);
156
	return computeChildren(info, newElements);
163
}
157
}
Lines 334-346 Link Here
334
			this.parent.equals(other.parent);
328
			this.parent.equals(other.parent);
335
}
329
}
336
330
337
/**
338
 * @see IJavaElement
339
 */
340
public boolean exists() {
341
	return super.exists() && validateOnClasspath().isOK();
342
}
343
344
private IClasspathEntry findSourceAttachmentRecommendation() {
331
private IClasspathEntry findSourceAttachmentRecommendation() {
345
	try {
332
	try {
346
		IPath rootPath = this.getPath();
333
		IPath rootPath = this.getPath();
Lines 792-797 Link Here
792
	}
779
	}
793
}
780
}
794
781
782
protected IStatus validateExistence(IResource underlyingResource) {
783
	// check whether this pkg fragment root can be opened
784
	IStatus status = validateOnClasspath();
785
	if (!status.isOK()) 
786
		return status;
787
	if (!resourceExists(underlyingResource)) 
788
		return newDoesNotExistStatus();
789
	return JavaModelStatus.VERIFIED_OK;
790
}
791
795
/**
792
/**
796
 * Possible failures: <ul>
793
 * Possible failures: <ul>
797
 *  <li>ELEMENT_NOT_PRESENT - the root supplied to the operation
794
 *  <li>ELEMENT_NOT_PRESENT - the root supplied to the operation
(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-23 / +21 lines)
Lines 76-93 Link Here
76
	becomeWorkingCopy(requestor, monitor);
76
	becomeWorkingCopy(requestor, monitor);
77
}
77
}
78
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
78
protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
79
80
	// check if this compilation unit can be opened
81
	if (!isWorkingCopy()) { // no check is done on root kind or exclusion pattern for working copies
82
		IStatus status = validateCompilationUnit(underlyingResource);
83
		if (!status.isOK()) throw newJavaModelException(status);
84
	}
85
	
86
	// prevents reopening of non-primary working copies (they are closed when they are discarded and should not be reopened)
87
	if (!isPrimary() && getPerWorkingCopyInfo() == null) {
88
		throw newNotPresentException();
89
	}
90
91
	CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info;
79
	CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info;
92
80
93
	// get buffer contents
81
	// get buffer contents
Lines 464-476 Link Here
464
	CompilationUnit other = (CompilationUnit)obj;
452
	CompilationUnit other = (CompilationUnit)obj;
465
	return this.owner.equals(other.owner) && super.equals(obj);
453
	return this.owner.equals(other.owner) && super.equals(obj);
466
}
454
}
467
public boolean exists() {
468
	// working copy always exists in the model until it is gotten rid of (even if not on classpath)
469
	if (getPerWorkingCopyInfo() != null) return true;	
470
	
471
	// if not a working copy, it exists only if it is a primary compilation unit
472
	return isPrimary() && validateCompilationUnit(getResource()).isOK();
473
}
474
/**
455
/**
475
 * @see ICompilationUnit#findElements(IJavaElement)
456
 * @see ICompilationUnit#findElements(IJavaElement)
476
 */
457
 */
Lines 1097-1106 Link Here
1097
	}	
1078
	}	
1098
	return buffer;
1079
	return buffer;
1099
}
1080
}
1100
protected void openParent(Object childInfo, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
1081
protected void openAncestors(HashMap newElements, IProgressMonitor monitor) throws JavaModelException {
1101
	if (!isWorkingCopy())
1082
	if (!isWorkingCopy()) {
1102
		super.openParent(childInfo, newElements, pm);
1083
		super.openAncestors(newElements, monitor);
1103
	// don't open parent for a working copy to speed up the first becomeWorkingCopy
1084
	} 
1085
	// else don't open ancestors for a working copy to speed up the first becomeWorkingCopy
1104
	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411)
1086
	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89411)
1105
}
1087
}
1106
/**
1088
/**
Lines 1249-1252 Link Here
1249
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1231
	((CompilationUnitElementInfo) getElementInfo()).timestamp = timeStamp;
1250
}
1232
}
1251
1233
1234
protected IStatus validateExistence(IResource underlyingResource) {
1235
	// check if this compilation unit can be opened
1236
	if (!isWorkingCopy()) { // no check is done on root kind or exclusion pattern for working copies
1237
		IStatus status = validateCompilationUnit(underlyingResource);
1238
		if (!status.isOK()) 
1239
			return status;
1240
	}
1241
	
1242
	// prevents reopening of non-primary working copies (they are closed when they are discarded and should not be reopened)
1243
	if (!isPrimary() && getPerWorkingCopyInfo() == null) {
1244
		return newDoesNotExistStatus();
1245
	}
1246
	
1247
	return JavaModelStatus.VERIFIED_OK;
1248
}
1249
1252
}
1250
}
(-)model/org/eclipse/jdt/internal/core/ElementCache.java (-10 / +4 lines)
Lines 46-59 Link Here
46
		if (!element.canBeRemovedFromCache()) {
46
		if (!element.canBeRemovedFromCache()) {
47
			return false;
47
			return false;
48
		} else {
48
		} else {
49
			// We must close an entire JarPackageFragmentRoot at once.
49
			element.close();
50
			if (element instanceof JarPackageFragment) {
51
				JarPackageFragment packageFragment= (JarPackageFragment) element;
52
				JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent();
53
				root.close();
54
			} else {
55
				element.close();
56
			}
57
			return true;
50
			return true;
58
		}
51
		}
59
	} catch (JavaModelException npe) {
52
	} catch (JavaModelException npe) {
Lines 62-72 Link Here
62
}
55
}
63
56
64
/*
57
/*
65
 * Ensures that there is enough room for adding the given number of children.
58
 * Ensures that there is enough room for adding the children of the given info.
66
 * If the space limit must be increased, record the parent that needed this space limit.
59
 * If the space limit must be increased, record the parent that needed this space limit.
67
 */
60
 */
68
protected void ensureSpaceLimit(int childrenSize, IJavaElement parent) {
61
protected void ensureSpaceLimit(Object info, IJavaElement parent) {
69
	// ensure the children can be put without closing other elements
62
	// ensure the children can be put without closing other elements
63
	int childrenSize = ((JavaElementInfo) info).children.length;
70
	int spaceNeeded = 1 + (int)((1 + fLoadFactor) * (childrenSize + fOverflow));
64
	int spaceNeeded = 1 + (int)((1 + fLoadFactor) * (childrenSize + fOverflow));
71
	if (fSpaceLimit < spaceNeeded) {
65
	if (fSpaceLimit < spaceNeeded) {
72
		// parent is being opened with more children than the space limit
66
		// parent is being opened with more children than the space limit
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-15 / +11 lines)
Lines 385-396 Link Here
385
	 * @see Openable
385
	 * @see Openable
386
	 */
386
	 */
387
	protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
387
	protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException {
388
	
389
		// check whether the java project can be opened
390
		if (!hasJavaNature((IProject) underlyingResource)) {
391
			throw newNotPresentException();
392
		}
393
		
394
		// cannot refresh cp markers on opening (emulate cp check on startup) since can create deadlocks (see bug 37274)
388
		// cannot refresh cp markers on opening (emulate cp check on startup) since can create deadlocks (see bug 37274)
395
		IClasspathEntry[] resolvedClasspath = getResolvedClasspath();
389
		IClasspathEntry[] resolvedClasspath = getResolvedClasspath();
396
390
Lines 1008-1022 Link Here
1008
		return this.project.equals(other.getProject());
1002
		return this.project.equals(other.getProject());
1009
	}
1003
	}
1010
1004
1011
	public boolean exists() {
1012
		try {
1013
			return this.project.hasNature(JavaCore.NATURE_ID);
1014
		} catch (CoreException e) {
1015
			// project does not exist or is not open
1016
		}
1017
		return false;
1018
	}
1019
1020
	/**
1005
	/**
1021
	 * @see IJavaProject#findElement(IPath)
1006
	 * @see IJavaProject#findElement(IPath)
1022
	 */
1007
	 */
Lines 2967-2970 Link Here
2967
			}
2952
			}
2968
		}
2953
		}
2969
	 }
2954
	 }
2955
	 
2956
	protected IStatus validateExistence(IResource underlyingResource) {
2957
		// check whether the java project can be opened
2958
		try {
2959
			if (!((IProject) underlyingResource).hasNature(JavaCore.NATURE_ID))
2960
				return newDoesNotExistStatus();
2961
		} catch (CoreException e) {
2962
			return newDoesNotExistStatus();
2963
		}
2964
		return JavaModelStatus.VERIFIED_OK;
2965
	}
2970
}
2966
}
(-)model/org/eclipse/jdt/internal/core/JavaModelCache.java (-5 / +5 lines)
Lines 37-43 Link Here
37
	/**
37
	/**
38
	 * Active Java Model Info
38
	 * Active Java Model Info
39
	 */
39
	 */
40
	protected JavaModelInfo modelInfo;
40
	protected Object modelInfo;
41
	
41
	
42
	/**
42
	/**
43
	 * Cache of open projects.
43
	 * Cache of open projects.
Lines 157-175 Link Here
157
protected void putInfo(IJavaElement element, Object info) {
157
protected void putInfo(IJavaElement element, Object info) {
158
	switch (element.getElementType()) {
158
	switch (element.getElementType()) {
159
		case IJavaElement.JAVA_MODEL:
159
		case IJavaElement.JAVA_MODEL:
160
			this.modelInfo = (JavaModelInfo) info;
160
			this.modelInfo = info;
161
			break;
161
			break;
162
		case IJavaElement.JAVA_PROJECT:
162
		case IJavaElement.JAVA_PROJECT:
163
			this.projectCache.put(element, info);
163
			this.projectCache.put(element, info);
164
			this.rootCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element);
164
			this.rootCache.ensureSpaceLimit(info, element);
165
			break;
165
			break;
166
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
166
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
167
			this.rootCache.put(element, info);
167
			this.rootCache.put(element, info);
168
			this.pkgCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element);
168
			this.pkgCache.ensureSpaceLimit(info, element);
169
			break;
169
			break;
170
		case IJavaElement.PACKAGE_FRAGMENT:
170
		case IJavaElement.PACKAGE_FRAGMENT:
171
			this.pkgCache.put(element, info);
171
			this.pkgCache.put(element, info);
172
			this.openableCache.ensureSpaceLimit(((JavaElementInfo) info).children.length, element);
172
			this.openableCache.ensureSpaceLimit(info, element);
173
			break;
173
			break;
174
		case IJavaElement.COMPILATION_UNIT:
174
		case IJavaElement.COMPILATION_UNIT:
175
		case IJavaElement.CLASS_FILE:
175
		case IJavaElement.CLASS_FILE:
(-)model/org/eclipse/jdt/internal/core/JarPackageFragmentRootInfo.java (+4 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
14
13
/**
15
/**
14
 * The element info for <code>JarPackageFragmentRoot</code>s.
16
 * The element info for <code>JarPackageFragmentRoot</code>s.
15
 */
17
 */
16
class JarPackageFragmentRootInfo extends PackageFragmentRootInfo {
18
class JarPackageFragmentRootInfo extends PackageFragmentRootInfo {
19
	// a map from package name (String[]) to a size-2 array of Array<String>, the first element being the .class file names, and the second element being the non-Java resource names
20
	HashtableOfArrayToObject rawPackageInfo; 
17
/**
21
/**
18
 * Returns an array of non-java resources contained in the receiver.
22
 * Returns an array of non-java resources contained in the receiver.
19
 */
23
 */
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-23 / +22 lines)
Lines 2942-2980 Link Here
2942
	/*
2942
	/*
2943
	 * Puts the infos in the given map (keys are IJavaElements and values are JavaElementInfos)
2943
	 * Puts the infos in the given map (keys are IJavaElements and values are JavaElementInfos)
2944
	 * in the Java model cache in an atomic way.
2944
	 * in the Java model cache in an atomic way.
2945
	 * First checks that the info for the opened element (or one of its ancestors) has not been 
2946
	 * added to the cache. If it is the case, another thread has opened the element (or one of
2947
	 * its ancestors). So returns without updating the cache.
2948
	 */
2945
	 */
2949
	protected synchronized void putInfos(IJavaElement openedElement, Map newElements) {
2946
	protected synchronized void putInfos(IJavaElement openedElement, Map newElements) {
2950
		// remove children
2947
		// remove existing children as the are replaced with the new children contained in newElements
2951
		Object existingInfo = this.cache.peekAtInfo(openedElement);
2948
		Object existingInfo = this.cache.peekAtInfo(openedElement);
2952
		if (openedElement instanceof IParent && existingInfo instanceof JavaElementInfo) {
2949
		if (openedElement instanceof IParent) {
2953
			IJavaElement[] children = ((JavaElementInfo)existingInfo).getChildren();
2950
			closeChildren(existingInfo);
2954
			for (int i = 0, size = children.length; i < size; ++i) {
2955
				JavaElement child = (JavaElement) children[i];
2956
				try {
2957
					child.close();
2958
				} catch (JavaModelException e) {
2959
					// ignore
2960
				}
2961
			}
2962
		}
2951
		}
2963
		
2952
		
2964
		// Need to put any JarPackageFragmentRoot in first.
2953
		// Need to put any JarPackageFragmentRoot in first.
2965
		// This is due to the way the LRU cache flushes entries.
2954
		// This is due to the way the LRU cache flushes entries.
2966
		// When a JarPackageFragment is flused from the LRU cache, the entire
2955
		// When a JarPackageFragment is flushed from the LRU cache, the entire
2967
		// jar is flushed by removing the JarPackageFragmentRoot and all of its
2956
		// jar is flushed by removing the JarPackageFragmentRoot and all of its
2968
		// children (see ElementCache.close()). If we flush the JarPackageFragment 
2957
		// children (see ElementCache.close()). If we flush the JarPackageFragment 
2969
		// when its JarPackageFragmentRoot is not in the cache and the root is about to be 
2958
		// when its JarPackageFragmentRoot is not in the cache and the root is about to be 
2970
		// added (during the 'while' loop), we will end up in an inconsist state. 
2959
		// added (during the 'while' loop), we will end up in an inconsistent state. 
2971
		// Subsequent resolution against package in the jar would fail as a result.
2960
		// Subsequent resolution against package in the jar would fail as a result.
2972
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422
2961
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102422
2973
		// (theodora)
2962
		// (theodora)
2974
		for(Iterator it = newElements.entrySet().iterator(); it.hasNext(); ) {
2963
		for(Iterator it = newElements.entrySet().iterator(); it.hasNext(); ) {
2975
			Map.Entry entry = (Map.Entry)it.next();
2964
			Map.Entry entry = (Map.Entry)it.next();
2976
			IJavaElement element = (IJavaElement)entry.getKey();
2965
			IJavaElement element = (IJavaElement)entry.getKey();
2977
			if( element instanceof JarPackageFragmentRoot ){
2966
			if (element instanceof JarPackageFragmentRoot) {
2978
				Object info = entry.getValue();
2967
				Object info = entry.getValue();
2979
				it.remove();
2968
				it.remove();
2980
				this.cache.putInfo(element, info);
2969
				this.cache.putInfo(element, info);
Lines 2987-2992 Link Here
2987
			this.cache.putInfo((IJavaElement) entry.getKey(), entry.getValue());
2976
			this.cache.putInfo((IJavaElement) entry.getKey(), entry.getValue());
2988
		}
2977
		}
2989
	}
2978
	}
2979
2980
	private void closeChildren(Object info) {
2981
		if (info instanceof JavaElementInfo) {
2982
			IJavaElement[] children = ((JavaElementInfo)info).getChildren();
2983
			for (int i = 0, size = children.length; i < size; ++i) {
2984
				JavaElement child = (JavaElement) children[i];
2985
				try {
2986
					child.close();
2987
				} catch (JavaModelException e) {
2988
					// ignore
2989
				}
2990
			}
2991
		}
2992
	}
2990
	
2993
	
2991
	/*
2994
	/*
2992
	 * Remember the info for the jar binary type
2995
	 * Remember the info for the jar binary type
Lines 3132-3143 Link Here
3132
					JavaModelCache.VERBOSE = false;
3135
					JavaModelCache.VERBOSE = false;
3133
				}
3136
				}
3134
				element.closing(info);
3137
				element.closing(info);
3135
				if (element instanceof IParent && info instanceof JavaElementInfo) {
3138
				if (element instanceof IParent) {
3136
					IJavaElement[] children = ((JavaElementInfo)info).getChildren();
3139
					closeChildren(info);
3137
					for (int i = 0, size = children.length; i < size; ++i) {
3138
						JavaElement child = (JavaElement) children[i];
3139
						child.close();
3140
					}
3141
				}
3140
				}
3142
				this.cache.removeInfo(element);
3141
				this.cache.removeInfo(element);
3143
				if (wasVerbose) {
3142
				if (wasVerbose) {
(-)model/org/eclipse/jdt/internal/core/JarPackageFragmentRoot.java (-47 / +30 lines)
Lines 35-41 Link Here
35
 */
35
 */
36
public class JarPackageFragmentRoot extends PackageFragmentRoot {
36
public class JarPackageFragmentRoot extends PackageFragmentRoot {
37
	
37
	
38
	public final static ArrayList EMPTY_LIST = new ArrayList();
38
	private final static ArrayList EMPTY_LIST = new ArrayList();
39
	
39
	
40
	/**
40
	/**
41
	 * The path to the jar file
41
	 * The path to the jar file
Lines 69-112 Link Here
69
	 * Has the side effect of opening the package fragment children.
69
	 * Has the side effect of opening the package fragment children.
70
	 */
70
	 */
71
	protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException {
71
	protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws JavaModelException {
72
		
72
		ArrayList children = new ArrayList();
73
		ArrayList vChildren= new ArrayList();
73
		HashtableOfArrayToObject rawPackageInfo = new HashtableOfArrayToObject();
74
		final int JAVA = 0;
74
		ZipFile jar = null;
75
		final int NON_JAVA = 1;
76
		ZipFile jar= null;
77
		try {
75
		try {
78
			jar= getJar();
79
	
80
			HashtableOfArrayToObject packageFragToTypes= new HashtableOfArrayToObject();
81
	
82
			// always create the default package
76
			// always create the default package
83
			packageFragToTypes.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
77
			rawPackageInfo.put(CharOperation.NO_STRINGS, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
84
	
78
	
79
			IJavaProject project = getJavaProject();
80
			String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
81
			String compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
82
			jar = getJar();
85
			for (Enumeration e= jar.entries(); e.hasMoreElements();) {
83
			for (Enumeration e= jar.entries(); e.hasMoreElements();) {
86
				ZipEntry member= (ZipEntry) e.nextElement();
84
				ZipEntry member= (ZipEntry) e.nextElement();
87
				initPackageFragToTypes(packageFragToTypes, member.getName(), member.isDirectory());
85
				initRawPackageInfo(rawPackageInfo, member.getName(), member.isDirectory(), sourceLevel, compliance);
88
			}
86
			}
89
			
87
			
90
			//loop through all of referenced packages, creating package fragments if necessary
88
			//loop through all of referenced packages, creating package fragments if necessary
91
			// and cache the entry names in the infos created for those package fragments
89
			// and cache the entry names in the rawPackageInfo table
92
			for (int i = 0, length = packageFragToTypes.keyTable.length; i < length; i++) {
90
			for (int i = 0, length = rawPackageInfo.keyTable.length; i < length; i++) {
93
				String[] pkgName = (String[]) packageFragToTypes.keyTable[i];
91
				String[] pkgName = (String[]) rawPackageInfo.keyTable[i];
94
				if (pkgName == null) continue;
92
				if (pkgName == null) continue;
95
				
96
				ArrayList[] entries= (ArrayList[]) packageFragToTypes.get(pkgName);
97
				JarPackageFragment packFrag= (JarPackageFragment) getPackageFragment(pkgName);
93
				JarPackageFragment packFrag= (JarPackageFragment) getPackageFragment(pkgName);
98
				JarPackageFragmentInfo fragInfo= new JarPackageFragmentInfo();
94
				children.add(packFrag);
99
				int resLength= entries[NON_JAVA].size();
100
				if (resLength == 0) {
101
					packFrag.computeNonJavaResources(CharOperation.NO_STRINGS, packFrag, fragInfo, jar.getName());
102
				} else {
103
					String[] resNames= new String[resLength];
104
					entries[NON_JAVA].toArray(resNames);
105
					packFrag.computeNonJavaResources(resNames, packFrag, fragInfo, jar.getName());
106
				}
107
				packFrag.computeChildren(fragInfo, entries[JAVA]);
108
				newElements.put(packFrag, fragInfo);
109
				vChildren.add(packFrag);
110
			}
95
			}
111
		} catch (CoreException e) {
96
		} catch (CoreException e) {
112
			if (e instanceof JavaModelException) throw (JavaModelException)e;
97
			if (e instanceof JavaModelException) throw (JavaModelException)e;
Lines 114-124 Link Here
114
		} finally {
99
		} finally {
115
			JavaModelManager.getJavaModelManager().closeZipFile(jar);
100
			JavaModelManager.getJavaModelManager().closeZipFile(jar);
116
		}
101
		}
117
102
		
118
103
		IJavaElement[] pkgs = (IJavaElement[]) children.toArray(new IJavaElement[children.size()]);
119
		IJavaElement[] children= new IJavaElement[vChildren.size()];
104
		info.setChildren(pkgs);
120
		vChildren.toArray(children);
105
		((JarPackageFragmentRootInfo) info).rawPackageInfo = rawPackageInfo;
121
		info.setChildren(children);
122
		return true;
106
		return true;
123
	}
107
	}
124
	/**
108
	/**
Lines 222-249 Link Here
222
	public int hashCode() {
206
	public int hashCode() {
223
		return this.jarPath.hashCode();
207
		return this.jarPath.hashCode();
224
	}
208
	}
225
	private void initPackageFragToTypes(HashtableOfArrayToObject packageFragToTypes, String entryName, boolean isDirectory) {
209
	private void initRawPackageInfo(HashtableOfArrayToObject rawPackageInfo, String entryName, boolean isDirectory, String sourceLevel, String compliance) {
226
		int lastSeparator = isDirectory ? entryName.length()-1 : entryName.lastIndexOf('/');
210
		int lastSeparator = isDirectory ? entryName.length()-1 : entryName.lastIndexOf('/');
227
		String[] pkgName = Util.splitOn('/', entryName, 0, lastSeparator);
211
		String[] pkgName = Util.splitOn('/', entryName, 0, lastSeparator);
228
		String[] existing = null;
212
		String[] existing = null;
229
		int length = pkgName.length;
213
		int length = pkgName.length;
230
		int existingLength = length;
214
		int existingLength = length;
231
		while (existingLength >= 0) {
215
		while (existingLength >= 0) {
232
			existing = (String[]) packageFragToTypes.getKey(pkgName, existingLength);
216
			existing = (String[]) rawPackageInfo.getKey(pkgName, existingLength);
233
			if (existing != null) break;
217
			if (existing != null) break;
234
			existingLength--;
218
			existingLength--;
235
		}
219
		}
236
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
220
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
237
		IJavaProject project = getJavaProject();
238
		for (int i = existingLength; i < length; i++) {
221
		for (int i = existingLength; i < length; i++) {
239
			if (Util.isValidFolderNameForPackage(pkgName[i], project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true))) {
222
			if (Util.isValidFolderNameForPackage(pkgName[i], sourceLevel, compliance)) {
240
				System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
223
				System.arraycopy(existing, 0, existing = new String[i+1], 0, i);
241
				existing[i] = manager.intern(pkgName[i]);
224
				existing[i] = manager.intern(pkgName[i]);
242
				packageFragToTypes.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
225
				rawPackageInfo.put(existing, new ArrayList[] { EMPTY_LIST, EMPTY_LIST });
243
			} else {
226
			} else {
244
				// non-Java resource folder
227
				// non-Java resource folder
245
				if (!isDirectory) {
228
				if (!isDirectory) {
246
					ArrayList[] children = (ArrayList[]) packageFragToTypes.get(existing);
229
					ArrayList[] children = (ArrayList[]) rawPackageInfo.get(existing);
247
					if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList();
230
					if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList();
248
					children[1/*NON_JAVA*/].add(entryName);
231
					children[1/*NON_JAVA*/].add(entryName);
249
				}
232
				}
Lines 254-264 Link Here
254
			return;
237
			return;
255
		
238
		
256
		// add classfile info amongst children
239
		// add classfile info amongst children
257
		ArrayList[] children = (ArrayList[]) packageFragToTypes.get(pkgName);
240
		ArrayList[] children = (ArrayList[]) rawPackageInfo.get(pkgName);
258
		if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
241
		if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
259
			if (children[0/*JAVA*/] == EMPTY_LIST) children[0/*JAVA*/] = new ArrayList();
242
			if (children[0/*JAVA*/] == EMPTY_LIST) children[0/*JAVA*/] = new ArrayList();
260
			String fileName = entryName.substring(lastSeparator + 1);
243
			String nameWithoutExtension = entryName.substring(lastSeparator + 1, entryName.length() - 6);
261
			children[0/*JAVA*/].add(fileName);
244
			children[0/*JAVA*/].add(nameWithoutExtension);
262
		} else {
245
		} else {
263
			if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList();
246
			if (children[1/*NON_JAVA*/] == EMPTY_LIST) children[1/*NON_JAVA*/] = new ArrayList();
264
			children[1/*NON_JAVA*/].add(entryName);
247
			children[1/*NON_JAVA*/].add(entryName);
Lines 287-301 Link Here
287
	/**
270
	/**
288
 * Returns whether the corresponding resource or associated file exists
271
 * Returns whether the corresponding resource or associated file exists
289
 */
272
 */
290
protected boolean resourceExists() {
273
protected boolean resourceExists(IResource underlyingResource) {
291
	if (this.isExternal()) {
274
	if (underlyingResource == null) {
292
		return 
275
		return 
293
			JavaModel.getTarget(
276
			JavaModel.getTarget(
294
				ResourcesPlugin.getWorkspace().getRoot(), 
277
				ResourcesPlugin.getWorkspace().getRoot(), 
295
				this.getPath(), // don't make the path relative as this is an external archive
278
				getPath(), // don't make the path relative as this is an external archive
296
				true) != null;
279
				true) != null;
297
	} else {
280
	} else {
298
		return super.resourceExists();
281
		return super.resourceExists(underlyingResource);
299
	}
282
	}
300
}
283
}
301
protected void toStringAncestors(StringBuffer buffer) {
284
protected void toStringAncestors(StringBuffer buffer) {
(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceModelTests.java (+84 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProjectDescription;
23
import org.eclipse.core.resources.IProjectDescription;
24
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IWorkspace;
25
import org.eclipse.core.resources.IWorkspace;
25
import org.eclipse.core.resources.IWorkspaceRoot;
26
import org.eclipse.core.resources.IWorkspaceRoot;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.resources.ResourcesPlugin;
Lines 83-88 Link Here
83
protected void setUp() throws Exception {
84
protected void setUp() throws Exception {
84
	super.setUp();
85
	super.setUp();
85
	setUpBigProject();
86
	setUpBigProject();
87
	setUpBigJars();
86
}
88
}
87
private void setUpBigProject() throws CoreException, IOException {
89
private void setUpBigProject() throws CoreException, IOException {
88
	try {
90
	try {
Lines 171-176 Link Here
171
	}
173
	}
172
	
174
	
173
}
175
}
176
private void setUpBigJars() throws Exception {
177
	String bigProjectLocation = BIG_PROJECT.getResource().getLocation().toOSString();
178
	int size = PACKAGES_COUNT * 10;
179
	File bigJar1 = new File(bigProjectLocation, BIG_JAR1_NAME);
180
	if (!bigJar1.exists()) {
181
		String[] pathAndContents = new String[size * 2];
182
		for (int i = 0; i < size; i++) {
183
			pathAndContents[i*2] = "/p" + i + "/X" + i + ".java";
184
			pathAndContents[i*2 + 1] = 
185
				"package p" + i + ";\n" +
186
				"public class X" + i + "{\n" +
187
				"}";
188
		}
189
		org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, bigJar1.getPath(), "1.3");
190
		BIG_PROJECT.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
191
	}
192
	File bigJar2 = new File(bigProjectLocation, BIG_JAR2_NAME);
193
	if (!bigJar2.exists()) {
194
		String[] pathAndContents = new String[size * 2];
195
		for (int i = 0; i < size; i++) {
196
			pathAndContents[i*2] = "/q" + i + "/Y" + i + ".java";
197
			pathAndContents[i*2 + 1] = 
198
				"package q" + i + ";\n" +
199
				"public class Y" + i + "{\n" +
200
				"}";
201
		}
202
		org.eclipse.jdt.core.tests.util.Util.createJar(pathAndContents, bigJar2.getPath(), "1.3");
203
		BIG_PROJECT.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
204
	}
205
}
174
/* (non-Javadoc)
206
/* (non-Javadoc)
175
 * @see junit.framework.TestCase#tearDown()
207
 * @see junit.framework.TestCase#tearDown()
176
 */
208
 */
Lines 742-747 Link Here
742
}
774
}
743
775
744
/*
776
/*
777
 * Performance test for the opening of class files in 2 big jars (that each would fill the Java model cache if all pkgs were opened).
778
 * (see bug 190094 Java Outline Causes Eclipse Lock-up.)
779
 */
780
public void testPopulateTwoBigJars() throws CoreException {
781
	
782
	IJavaProject project = null;
783
	try {
784
		project = createJavaProject("HugeJarProject");
785
		IFile bigJar1 = BIG_PROJECT.getProject().getFile(BIG_JAR1_NAME);
786
		IFile bigJar2 = BIG_PROJECT.getProject().getFile(BIG_JAR2_NAME);
787
		project.setRawClasspath(
788
			new IClasspathEntry[] {
789
				JavaCore.newLibraryEntry(bigJar1.getFullPath(), null, null),
790
				JavaCore.newLibraryEntry(bigJar2.getFullPath(), null, null),
791
			}, null);
792
		AbstractJavaModelTests.waitUntilIndexesReady();
793
		AbstractJavaModelTests.waitForAutoBuild();
794
		IPackageFragmentRoot root1 = project.getPackageFragmentRoot(bigJar1);
795
		IPackageFragmentRoot root2 = project.getPackageFragmentRoot(bigJar2);
796
		
797
		// warm up
798
		int max = 20;
799
		int warmup = WARMUP_COUNT / 10;
800
		for (int i = 0; i < warmup; i++) {
801
			project.close();
802
			for (int j = 0; j < max; j++) {
803
				root1.getPackageFragment("p" + j).open(null);
804
				root2.getPackageFragment("q" + j).open(null);
805
			}
806
		}
807
			
808
		// measure performance
809
		for (int i = 0; i < MEASURES_COUNT; i++) {
810
			project.close();
811
			runGc();
812
			startMeasuring();
813
			for (int j = 0; j < max; j++) {
814
				root1.getPackageFragment("p" + j).open(null);
815
				root2.getPackageFragment("q" + j).open(null);
816
			}
817
			stopMeasuring();
818
		}
819
	
820
		commitMeasurements();
821
		assertPerformance();
822
	} finally {
823
		if (project != null)
824
			project.getProject().delete(false, null);
825
	}
826
}
827
828
/*
745
 * Performance test for looking up package fragments
829
 * Performance test for looking up package fragments
746
 * (see bug 72683 Slow code assist in Display view)
830
 * (see bug 72683 Slow code assist in Display view)
747
 */
831
 */
(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java (+2 lines)
Lines 99-104 Link Here
99
	protected static ICompilationUnit PARSER_WORKING_COPY;
99
	protected static ICompilationUnit PARSER_WORKING_COPY;
100
	protected final static String BIG_PROJECT_NAME = "BigProject";
100
	protected final static String BIG_PROJECT_NAME = "BigProject";
101
	protected static JavaProject BIG_PROJECT;
101
	protected static JavaProject BIG_PROJECT;
102
	protected static final String BIG_JAR1_NAME = "big1.jar";
103
	protected static final String BIG_JAR2_NAME = "big2.jar";
102
//	protected final static String JUNIT_PROJECT_NAME = "junit";
104
//	protected final static String JUNIT_PROJECT_NAME = "junit";
103
//	protected static IJavaProject JUNIT_PROJECT;
105
//	protected static IJavaProject JUNIT_PROJECT;
104
	
106
	

Return to bug 190094