Skip to content

Commit eb23865

Browse files
Wrong module description assigned to project (when reconciling with DOM) (eclipse-jdt#4264)
The DOMToModelPopulator was sometimes setting the wrong module description on the project as it was not checking whether the provided file is actually the right one to use.
1 parent a89bbec commit eb23865

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DOMToModelPopulator.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@
1515
import java.util.Map.Entry;
1616
import java.util.stream.Stream;
1717
import org.eclipse.core.runtime.ILog;
18-
import org.eclipse.jdt.core.Flags;
19-
import org.eclipse.jdt.core.IAnnotation;
20-
import org.eclipse.jdt.core.IImportDeclaration;
21-
import org.eclipse.jdt.core.IJavaElement;
22-
import org.eclipse.jdt.core.ILocalVariable;
23-
import org.eclipse.jdt.core.IMemberValuePair;
24-
import org.eclipse.jdt.core.JavaModelException;
25-
import org.eclipse.jdt.core.Signature;
18+
import org.eclipse.jdt.core.*;
2619
import org.eclipse.jdt.core.compiler.CharOperation;
2720
import org.eclipse.jdt.core.compiler.InvalidInputException;
2821
import org.eclipse.jdt.core.dom.*;
@@ -1039,7 +1032,11 @@ public boolean visit(ModuleDeclaration node) {
10391032

10401033
this.unitInfo.setModule(newElement);
10411034
try {
1042-
this.root.getJavaProject().setModuleDescription(newElement);
1035+
if (this.root.getPackageFragmentRoot().getResolvedClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE
1036+
&& this.root.getParent() instanceof IPackageFragment packageFragment
1037+
&& packageFragment.getElementName().isEmpty()) {
1038+
this.root.getJavaProject().setModuleDescription(newElement);
1039+
}
10431040
} catch (JavaModelException e) {
10441041
ILog.get().error(e.getMessage(), e);
10451042
}

0 commit comments

Comments
 (0)