diff --git a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend index 9da0fe96f12..a869fddfc59 100644 --- a/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend +++ b/org.eclipse.xtend.ide.tests/src/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.xtend @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2026 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -61,6 +61,7 @@ class JavaVersionSettingTest extends Assert { @Test def void testCompileWithJava8() { workbenchTestHelper.tearDown WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA8) + waitForJdtIndex() val xtendFile = workbenchTestHelper.createFile('mypackage/OverrideTest.xtend', ''' package mypackage class B implements A { @@ -94,4 +95,4 @@ class JavaVersionSettingTest extends Assert { } } -} \ No newline at end of file +} diff --git a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java index 501fe0a1e82..4c357bb0c3a 100644 --- a/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java +++ b/org.eclipse.xtend.ide.tests/xtend-gen/org/eclipse/xtend/ide/tests/compiler/JavaVersionSettingTest.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others. + * Copyright (c) 2015, 2026 itemis AG (http://www.itemis.eu) and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. @@ -68,6 +68,7 @@ public void testCompileWithJava8() { try { this.workbenchTestHelper.tearDown(); WorkbenchTestHelper.createPluginProject(WorkbenchTestHelper.TESTPROJECT_NAME, JavaVersion.JAVA8); + IResourcesSetupUtil.waitForJdtIndex(); StringConcatenation _builder = new StringConcatenation(); _builder.append("package mypackage"); _builder.newLine(); diff --git a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/ui/notification/TypeResourceUnloaderTest.java b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/ui/notification/TypeResourceUnloaderTest.java index 75648478d47..739207b369c 100644 --- a/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/ui/notification/TypeResourceUnloaderTest.java +++ b/org.eclipse.xtext.common.types.eclipse.tests/tests/org/eclipse/xtext/common/types/ui/notification/TypeResourceUnloaderTest.java @@ -32,6 +32,7 @@ import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.resource.IResourceDescription; import org.eclipse.xtext.ui.notification.IStateChangeEventBroker; +import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil; import org.eclipse.xtext.xbase.lib.Procedures; import org.eclipse.xtext.xbase.lib.Procedures.Procedure0; import org.junit.After; @@ -78,8 +79,14 @@ public void setUp() throws Exception { projectProvider = new MockJavaProjectProvider(); projectProvider.setUseSource(true); project = projectProvider.getJavaProject(null); + // Ensure the JDT incremental builder state is fully populated before the test starts. + // Without this, JavaBuilderState.getDefinedTypeNamesFor(typeLocator) may return null + // and convertRemovedTypes(...) will only emit a delta for the primary type, causing + // e.g. testRenameClass to see 4 deltas instead of the expected 6. + IResourcesSetupUtil.waitForBuild(); type = project.findType(NESTED_TYPES); compilationUnit = type.getCompilationUnit(); + assertBuilderStateContainsNestedTypes(); compilationUnit.becomeWorkingCopy(null); // wait until the BackgroundThread for the reconciler was started @@ -105,6 +112,9 @@ public void tearDown() throws Exception { eventBroker = null; projectProvider = null; compilationUnit.discardWorkingCopy(); + // Make sure the rebuild triggered by doSave above is finished before the next + // @Before runs, so that JavaBuilderState is consistent for the following test. + IResourcesSetupUtil.waitForBuild(); compilationUnit = null; editor = null; type = null; @@ -112,6 +122,23 @@ public void tearDown() throws Exception { event = null; subsequentEvents = null; } + + /** + * Sanity check that the JDT builder state knows about all three nested types defined in + * {@code NestedTypes.java}. If this fails, the test environment is racing with the Java + * builder and the actual test assertions would be misleading. + */ + private void assertBuilderStateContainsNestedTypes() { + JavaBuilderState builderState = JavaBuilderState.getLastBuiltState(project.getProject()); + assertNotNull("No JDT builder state available for project " + project.getElementName(), builderState); + TypeNames typeNames = builderState.getQualifiedTypeNames(compilationUnit); + Collection names = typeNames.getTypeNames(); + assertTrue("Builder state is missing " + NESTED_TYPES + ", was: " + names, names.contains(NESTED_TYPES)); + assertTrue("Builder state is missing " + NESTED_TYPES + "$Outer, was: " + names, + names.contains(NESTED_TYPES + "$Outer")); + assertTrue("Builder state is missing " + NESTED_TYPES + "$Outer$Inner, was: " + names, + names.contains(NESTED_TYPES + "$Outer$Inner")); + } @Test public void testNullChange() throws BadLocationException, InterruptedException { waitForEvent(new Procedure0() {