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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+79 lines)
Lines 16-21 Link Here
16
16
17
import junit.framework.Test;
17
import junit.framework.Test;
18
18
19
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IWorkspaceRunnable;
20
import org.eclipse.core.resources.IWorkspaceRunnable;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.ILogListener;
22
import org.eclipse.core.runtime.ILogListener;
Lines 870-875 Link Here
870
	}
871
	}
871
}
872
}
872
/**
873
/**
874
 * @bug 162621: [model][delta] Validation errors do not clear after replacing jar file
875
 * @test Ensures that changing an internal jar and refreshing takes the change into account
876
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
877
 */
878
public void testChangeInternalJar() throws CoreException, IOException {
879
	IJavaProject project = getJavaProject("Reconciler");
880
	String jarName = "b162621.jar";
881
	try {
882
		String[] pathAndContents = new String[] {
883
			"test/before/Foo.java",
884
			"package test.before;\n" + 
885
			"public class Foo {\n" + 
886
			"}\n"
887
		};
888
		addLibrary(project, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
889
890
		// Set working copy content with no error
891
		setUpWorkingCopy("/Reconciler/src/test/Test.java",
892
			"package test;\n" + 
893
			"import test.before.Foo;\n" + 
894
			"public class Test {\n" + 
895
			"	Foo f;\n" + 
896
			"}\n"
897
		);
898
		assertProblems(
899
			"Unexpected problems", 
900
			"----------\n" + 
901
			"----------\n"
902
		);
903
904
		// Update working copy with Jar expected changes
905
		String contents = "package test;\n" + 
906
			"import test.after.Foo;\n" + 
907
			"public class Test {\n" + 
908
			"	Foo f;\n" + 
909
			"}\n";
910
		setWorkingCopyContents(contents);
911
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true, null, null);
912
		assertProblems(
913
			"Wrong expected problems", 
914
			"----------\n" + 
915
			"1. ERROR in /Reconciler/src/test/Test.java (at line 2)\n" + 
916
			"	import test.after.Foo;\n" + 
917
			"	       ^^^^^^^^^^\n" + 
918
			"The import test.after cannot be resolved\n" + 
919
			"----------\n" + 
920
			"2. ERROR in /Reconciler/src/test/Test.java (at line 4)\n" + 
921
			"	Foo f;\n" + 
922
			"	^^^\n" + 
923
			"Foo cannot be resolved to a type\n" + 
924
			"----------\n"
925
		);
926
		
927
		// change jar and refresh
928
		String projectLocation = project.getProject().getLocation().toOSString();
929
		String jarPath = projectLocation + File.separator + jarName;
930
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
931
			"test/after/Foo.java",
932
			"package test.after;\n" + 
933
			"public class Foo {\n" + 
934
			"}\n"
935
		}, jarPath, "1.4");
936
		project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
937
938
		// Verify that error is gone
939
		this.problemRequestor.initialize(contents.toCharArray());
940
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true, null, null);
941
		assertProblems(
942
			"Unexpected problems", 
943
			"----------\n" + 
944
			"----------\n"
945
		);
946
	} finally {
947
		removeLibraryEntry(project, new Path(jarName));
948
		deleteFile(new File(jarName));
949
	}
950
}
951
/**
873
 * Ensures that the reconciler reconciles the new contents with the current
952
 * Ensures that the reconciler reconciles the new contents with the current
874
 * contents,updating the structure of this reconciler's compilation
953
 * contents,updating the structure of this reconciler's compilation
875
 * unit, and fires the Java element deltas for the structural changes
954
 * unit, and fires the Java element deltas for the structural changes
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests2.java (+71 lines)
Lines 20-25 Link Here
20
20
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.IResource;
23
import org.eclipse.core.resources.IWorkspaceRunnable;
24
import org.eclipse.core.resources.IWorkspaceRunnable;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IPath;
26
import org.eclipse.core.runtime.IPath;
Lines 2249-2252 Link Here
2249
		this.deleteProject("P2");
2250
		this.deleteProject("P2");
2250
	}
2251
	}
2251
}
2252
}
2253
/**
2254
 * @bug 162621: [model][delta] Validation errors do not clear after replacing jar file
2255
 * @test Ensures that changing an internal jar and refreshing takes the change into account
2256
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
2257
 */
2258
public void testChangeInternalJar() throws CoreException, IOException {
2259
	String jarName = "b162621.jar";
2260
	try {
2261
		// Create jar file with a class with 2 methods doXXX
2262
		String[] pathAndContents = new String[] {
2263
			"pack/Util.java",
2264
			"package pack;\n" + 
2265
			"public class Util {\n" + 
2266
			"    public void doit2A(int x, int y) { }\n" + 
2267
			"    public void doit2B(int x) { }\n" + 
2268
			"}\n"
2269
		};
2270
		addLibrary(jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
2271
2272
		// Create compilation unit in which completion occurs
2273
		String path = "/Completion/src/test/Test.java";
2274
		String source = "package test;\n" + 
2275
			"import pack.*;\n" + 
2276
			"public class Test {\n" + 
2277
			"	public void foo() {\n" + 
2278
			"		Util test = new Util();\n" + 
2279
			"		test.doit2A(1, 2);\n" + 
2280
			"	}\n" + 
2281
			"}\n";
2282
		createFolder("/Completion/src/test");
2283
		createFile(path, source);
2284
2285
		// first completion
2286
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
2287
		ICompilationUnit unit = getCompilationUnit(path);
2288
		String completeBehind = "test.do";
2289
		int cursorLocation = source.lastIndexOf(completeBehind) + completeBehind.length();
2290
		unit.codeComplete(cursorLocation, requestor);
2291
		assertResults(
2292
			"doit2A[METHOD_REF]{doit2A, Lpack.Util;, (II)V, doit2A, "+(R_DEFAULT + R_CASE + R_INTERESTING + R_NON_RESTRICTED + R_NON_STATIC) + "}\n" +
2293
			"doit2B[METHOD_REF]{doit2B, Lpack.Util;, (I)V, doit2B, "+(R_DEFAULT + R_CASE + R_INTERESTING + R_NON_RESTRICTED + R_NON_STATIC) + "}",
2294
			requestor.getResults());
2295
2296
		// change class file to add a third doXXX method and refresh
2297
		String projectLocation = this.currentProject.getProject().getLocation().toOSString();
2298
		String jarPath = projectLocation + File.separator + jarName;
2299
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
2300
			"pack/Util.java",
2301
			"package pack;\n" + 
2302
			"public class Util {\n" + 
2303
			"    public void doit2A(int x, int y) { }\n" + 
2304
			"    public void doit2B(int x) { }\n" + 
2305
			"    public void doit2C(int x) { }\n" + 
2306
			"}\n"
2307
		}, jarPath, "1.4");
2308
		this.currentProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
2309
2310
		// second completion
2311
		requestor = new CompletionTestsRequestor2();
2312
		unit.codeComplete(cursorLocation, requestor);
2313
		assertResults(
2314
			"doit2A[METHOD_REF]{doit2A, Lpack.Util;, (II)V, doit2A, "+(R_DEFAULT + R_CASE + R_INTERESTING + R_NON_RESTRICTED + R_NON_STATIC) + "}\n" +
2315
			"doit2B[METHOD_REF]{doit2B, Lpack.Util;, (I)V, doit2B, "+(R_DEFAULT + R_CASE + R_INTERESTING + R_NON_RESTRICTED + R_NON_STATIC) + "}\n" +
2316
			"doit2C[METHOD_REF]{doit2C, Lpack.Util;, (I)V, doit2C, "+(R_DEFAULT + R_CASE + R_INTERESTING + R_NON_RESTRICTED + R_NON_STATIC) + "}",
2317
			requestor.getResults());
2318
	} finally {
2319
		removeLibraryEntry(this.currentProject, new Path(jarName));
2320
		deleteFile(new File(jarName));
2321
	}
2322
}
2252
}
2323
}
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (+3 lines)
Lines 624-629 Link Here
624
			int flags = IJavaElementDelta.F_CONTENT;
624
			int flags = IJavaElementDelta.F_CONTENT;
625
			if (element instanceof JarPackageFragmentRoot){
625
			if (element instanceof JarPackageFragmentRoot){
626
				flags |= IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED;
626
				flags |= IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED;
627
				// need also to reset project cache otherwise it will be out-of-date
628
				// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621
629
				this.projectCachesToReset.add(element.getJavaProject());
627
			}
630
			}
628
			if (isPrimary) {
631
			if (isPrimary) {
629
				flags |= IJavaElementDelta.F_PRIMARY_RESOURCE;
632
				flags |= IJavaElementDelta.F_PRIMARY_RESOURCE;

Return to bug 162621