Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark RequiresDirective's name as MANDATORY #3479

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,39 @@ public class Client {
deleteProject("P2");
}
}
public void testRequiresDirectiveNameIsMandatory() throws JavaModelException, CoreException {
try {
assertTrue(RequiresDirective.NAME_PROPERTY.isMandatory());

IJavaProject project1 = createJavaProject("ASTParserModelTests", new String[] { "src" },
new String[] { "CONVERTER_JCL9_LIB" }, "bin", "9");
project1.open(null);
addClasspathEntry(project1, JavaCore.newContainerEntry(new Path("org.eclipse.jdt.MODULE_PATH")));
String content = """
module first {
requires other;
}
""";
createFile("/ASTParserModelTests/src/module-info.java", content);
this.workingCopy = getCompilationUnit("/ASTParserModelTests/src/module-info.java");

ASTParser astParser = ASTParser.newParser(AST.getJLSLatest());
astParser.setSource(this.workingCopy);
astParser.setResolveBindings(true);
astParser.setStatementsRecovery(true);
CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(new NullProgressMonitor());
ModuleDeclaration moduleDeclaration = compilationUnit.getModule();
RequiresDirective requiresDirective = (RequiresDirective)moduleDeclaration.moduleStatements().get(0);
try {
requiresDirective.setName(null);
fail("Expected an IllegalArgumentException to be thrown");
} catch (IllegalArgumentException e) {
// do nothing
}
} finally {
deleteProject("ASTParserModelTests");
}
}

// Add new tests here
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class RequiresDirective extends ModuleDirective {
* The module structural property of this node type (child type: {@link Name}).
*/
public static final ChildPropertyDescriptor NAME_PROPERTY =
new ChildPropertyDescriptor(RequiresDirective.class, "name", Name.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
new ChildPropertyDescriptor(RequiresDirective.class, "name", Name.class, MANDATORY, NO_CYCLE_RISK); //$NON-NLS-1$
mpalat marked this conversation as resolved.
Show resolved Hide resolved

/**
* A list of property descriptors (element type:
Expand Down Expand Up @@ -204,8 +204,7 @@ public Name getName() {
synchronized (this) {
if (this.name == null) {
preLazyInit();
this.name = postLazyInit(
this.ast.newQualifiedName(new SimpleName(this.ast), new SimpleName(this.ast)),
this.name = postLazyInit(new SimpleName(this.ast),
NAME_PROPERTY);
}
}
Expand All @@ -221,6 +220,7 @@ public Name getName() {
* <ul>
* <li>the node belongs to a different AST</li>
* <li>the node already has a parent</li>
* <li>the node is null</li>
* </ul>
*/
public void setName(Name name) {
Expand Down
Loading