Skip to content

Commit

Permalink
Module statements -> directives
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Aug 16, 2018
1 parent 999c27a commit 6d06ae9
Show file tree
Hide file tree
Showing 50 changed files with 794 additions and 595 deletions.
Expand Up @@ -22,7 +22,7 @@ public class TypeCastingGenerator extends NodeGenerator {
JavaParserMetaModel.statementMetaModel,
JavaParserMetaModel.expressionMetaModel,
JavaParserMetaModel.typeMetaModel,
JavaParserMetaModel.moduleStmtMetaModel,
JavaParserMetaModel.moduleDirectiveMetaModel,
JavaParserMetaModel.bodyDeclarationMetaModel,
JavaParserMetaModel.commentMetaModel
);
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class MetaModelGenerator {
add(StringLiteralExpr.class);

add(ModuleDeclaration.class);
add(ModuleStmt.class);
add(ModuleDirective.class);

//
add(ArrayCreationLevel.class);
Expand Down Expand Up @@ -142,11 +142,11 @@ public class MetaModelGenerator {
add(WildcardType.class);
add(VarType.class);

add(ModuleRequiresStmt.class);
add(ModuleExportsStmt.class);
add(ModuleProvidesStmt.class);
add(ModuleUsesStmt.class);
add(ModuleOpensStmt.class);
add(ModuleRequiresDirective.class);
add(ModuleExportsDirective.class);
add(ModuleProvidesDirective.class);
add(ModuleUsesDirective.class);
add(ModuleOpensDirective.class);
}};

static String METAMODEL_PACKAGE = "com.github.javaparser.metamodel";
Expand Down
Expand Up @@ -7,12 +7,10 @@
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr;
import com.github.javaparser.ast.modules.*;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.printer.ConcreteSyntaxModel;
import org.junit.Test;

import static com.github.javaparser.GeneratedJavaParserConstants.IDENTIFIER;
import static com.github.javaparser.JavaParser.parseClassOrInterfaceType;
import static com.github.javaparser.JavaParser.parseName;
import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9;
import static com.github.javaparser.Providers.provider;
Expand Down Expand Up @@ -42,7 +40,7 @@ public void moduleInfoKeywordsAreSeenAsIdentifiers() {
@Test
public void issue988RequireTransitiveShouldRequireAModuleCalledTransitive() {
CompilationUnit cu = parse("module X { requires transitive; }");
ModuleRequiresStmt requiresTransitive = (ModuleRequiresStmt) cu.getModule().get().getModuleStmts().get(0);
ModuleRequiresDirective requiresTransitive = (ModuleRequiresDirective) cu.getModule().get().getDirectives().get(0);
assertEquals("transitive", requiresTransitive.getNameAsString());
assertEquals(IDENTIFIER, requiresTransitive.getName().getTokenRange().get().getBegin().getKind());
}
Expand Down Expand Up @@ -75,22 +73,22 @@ public void jlsExample1() {
new SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("2")),
new MarkerAnnotationExpr(new Name("Bar")));

ModuleRequiresStmt moduleRequiresStmt = module.getModuleStmts().get(0).asModuleRequiresStmt();
ModuleRequiresDirective moduleRequiresStmt = module.getDirectives().get(0).asModuleRequiresStmt();
assertThat(moduleRequiresStmt.getNameAsString()).isEqualTo("A.B");
assertThat(moduleRequiresStmt.getModifiers()).isEmpty();

ModuleExportsStmt moduleExportsStmt = module.getModuleStmts().get(5).asModuleExportsStmt();
ModuleExportsDirective moduleExportsStmt = module.getDirectives().get(5).asModuleExportsStmt();
assertThat(moduleExportsStmt.getNameAsString()).isEqualTo("R.S");
assertThat(moduleExportsStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));

ModuleOpensStmt moduleOpensStmt = module.getModuleStmts().get(7).asModuleOpensStmt();
ModuleOpensDirective moduleOpensStmt = module.getDirectives().get(7).asModuleOpensStmt();
assertThat(moduleOpensStmt.getNameAsString()).isEqualTo("R.S");
assertThat(moduleOpensStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));

ModuleUsesStmt moduleUsesStmt = module.getModuleStmts().get(8).asModuleUsesStmt();
ModuleUsesDirective moduleUsesStmt = module.getDirectives().get(8).asModuleUsesStmt();
assertThat(moduleUsesStmt.getNameAsString()).isEqualTo("V.W");

ModuleProvidesStmt moduleProvidesStmt = module.getModuleStmts().get(9).asModuleProvidesStmt();
ModuleProvidesDirective moduleProvidesStmt = module.getDirectives().get(9).asModuleProvidesStmt();
assertThat(moduleProvidesStmt.getNameAsString()).isEqualTo("X.Y");
assertThat(moduleProvidesStmt.getWith()).containsExactly(
parseName("Z1.Z2"),
Expand Down Expand Up @@ -195,15 +193,15 @@ public void fluentInterface() {
.addDirective("exports com.laamella.base.entity.channel.internal to com.laamella.core;")
.addDirective("uses com.laamella.base.util.internal.FactoryDelegate;");

moduleDeclaration.getModuleStmts()
.addLast(new ModuleExportsStmt()
moduleDeclaration.getDirectives()
.addLast(new ModuleExportsDirective()
.setName("foo.bar")
.addModuleName("other.foo")
.addModuleName("other.bar")
);

moduleDeclaration
.addDirective(new ModuleExportsStmt()
.addDirective(new ModuleExportsDirective()
.setName("foo.bar.x")
.addModuleName("other.foo")
.addModuleName("other.bar")
Expand Down
Expand Up @@ -30,7 +30,7 @@
import com.github.javaparser.ast.body.TypeDeclaration;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.modules.ModuleDeclaration;
import com.github.javaparser.ast.modules.ModuleStmt;
import com.github.javaparser.ast.modules.ModuleDirective;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import com.github.javaparser.ast.stmt.Statement;
Expand Down Expand Up @@ -547,14 +547,14 @@ public static ModuleDeclaration parseModuleDeclaration(String moduleDeclaration)
}

/**
* Parses a module directive and returns it as a ModuleStmt.
* Parses a module directive and returns it as a ModuleDirective.
*
* @param moduleDirective a directive like "opens C;"
* @return the AST for the module directive
* @throws ParseProblemException if the source code has parser errors
* @see ModuleStmt
* @see ModuleDirective
*/
public static ModuleStmt parseModuleDirective(String moduleDirective) {
public static ModuleDirective parseModuleDirective(String moduleDirective) {
return simplifiedParse(MODULE_DIRECTIVE, provider(moduleDirective));
}

Expand Down
Expand Up @@ -29,7 +29,7 @@
import com.github.javaparser.ast.body.TypeDeclaration;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.modules.ModuleDeclaration;
import com.github.javaparser.ast.modules.ModuleStmt;
import com.github.javaparser.ast.modules.ModuleDirective;
import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import com.github.javaparser.ast.stmt.Statement;
Expand Down Expand Up @@ -67,7 +67,7 @@ public interface ParseStart<R> {
ParseStart<PackageDeclaration> PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart;
ParseStart<TypeDeclaration<?>> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart;
ParseStart<ModuleDeclaration> MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart;
ParseStart<ModuleStmt> MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart;
ParseStart<ModuleDirective> MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart;

R parse(GeneratedJavaParser parser) throws ParseException;
}
Expand Up @@ -35,10 +35,8 @@
import com.github.javaparser.metamodel.NameMetaModel;
import com.github.javaparser.metamodel.NonEmptyProperty;
import com.github.javaparser.metamodel.OptionalProperty;

import javax.annotation.Generated;
import java.util.Optional;

import static com.github.javaparser.utils.Utils.assertNonEmpty;
import static com.github.javaparser.utils.Utils.assertNotNull;

Expand Down Expand Up @@ -250,8 +248,6 @@ public boolean isTopLevel() {
* An internal name is a name that constitutes a part of a larger Name instance.
*/
public boolean isInternal() {
return getParentNode()
.filter(parent -> parent instanceof Name)
.isPresent();
return getParentNode().filter(parent -> parent instanceof Name).isPresent();
}
}
Expand Up @@ -14,8 +14,6 @@
import com.github.javaparser.ast.visitor.VoidVisitor;
import com.github.javaparser.metamodel.JavaParserMetaModel;
import com.github.javaparser.metamodel.ModuleDeclarationMetaModel;
import java.util.Arrays;
import java.util.List;
import static com.github.javaparser.utils.Utils.assertNotNull;
import javax.annotation.Generated;
import com.github.javaparser.TokenRange;
Expand All @@ -31,7 +29,7 @@ public final class ModuleDeclaration extends Node implements NodeWithName<Module

private boolean isOpen;

private NodeList<ModuleStmt> moduleStmts;
private NodeList<ModuleDirective> directives;

public ModuleDeclaration() {
this(null, new NodeList<>(), new Name(), false, new NodeList<>());
Expand All @@ -42,20 +40,20 @@ public ModuleDeclaration(Name name, boolean isOpen) {
}

@AllFieldsConstructor
public ModuleDeclaration(NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> moduleStmts) {
this(null, annotations, name, isOpen, moduleStmts);
public ModuleDeclaration(NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleDirective> directives) {
this(null, annotations, name, isOpen, directives);
}

/**
* This constructor is used by the parser and is considered private.
*/
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
public ModuleDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> moduleStmts) {
public ModuleDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleDirective> directives) {
super(tokenRange);
setAnnotations(annotations);
setName(name);
setOpen(isOpen);
setModuleStmts(moduleStmts);
setDirectives(directives);
customInitialization();
}

Expand Down Expand Up @@ -120,9 +118,9 @@ public boolean remove(Node node) {
return true;
}
}
for (int i = 0; i < moduleStmts.size(); i++) {
if (moduleStmts.get(i) == node) {
moduleStmts.remove(i);
for (int i = 0; i < directives.size(); i++) {
if (directives.get(i) == node) {
directives.remove(i);
return true;
}
}
Expand All @@ -145,21 +143,21 @@ public ModuleDeclaration setOpen(final boolean isOpen) {
}

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public NodeList<ModuleStmt> getModuleStmts() {
return moduleStmts;
public NodeList<ModuleDirective> getDirectives() {
return directives;
}

@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public ModuleDeclaration setModuleStmts(final NodeList<ModuleStmt> moduleStmts) {
assertNotNull(moduleStmts);
if (moduleStmts == this.moduleStmts) {
public ModuleDeclaration setDirectives(final NodeList<ModuleDirective> directives) {
assertNotNull(directives);
if (directives == this.directives) {
return (ModuleDeclaration) this;
}
notifyPropertyChange(ObservableProperty.MODULE_STMTS, this.moduleStmts, moduleStmts);
if (this.moduleStmts != null)
this.moduleStmts.setParentNode(null);
this.moduleStmts = moduleStmts;
setAsParentNodeOf(moduleStmts);
notifyPropertyChange(ObservableProperty.DIRECTIVES, this.directives, directives);
if (this.directives != null)
this.directives.setParentNode(null);
this.directives = directives;
setAsParentNodeOf(directives);
return this;
}

Expand All @@ -186,9 +184,9 @@ public boolean replace(Node node, Node replacementNode) {
return true;
}
}
for (int i = 0; i < moduleStmts.size(); i++) {
if (moduleStmts.get(i) == node) {
moduleStmts.set(i, (ModuleStmt) replacementNode);
for (int i = 0; i < directives.size(); i++) {
if (directives.get(i) == node) {
directives.set(i, (ModuleDirective) replacementNode);
return true;
}
}
Expand All @@ -206,8 +204,8 @@ public ModuleDeclaration addDirective(String directive) {
return addDirective(JavaParser.parseModuleDirective(directive));
}

public ModuleDeclaration addDirective(ModuleStmt directive) {
getModuleStmts().add(directive);
public ModuleDeclaration addDirective(ModuleDirective directive) {
getDirectives().add(directive);
return this;
}
}

0 comments on commit 6d06ae9

Please sign in to comment.