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.statementMetaModel,
JavaParserMetaModel.expressionMetaModel, JavaParserMetaModel.expressionMetaModel,
JavaParserMetaModel.typeMetaModel, JavaParserMetaModel.typeMetaModel,
JavaParserMetaModel.moduleStmtMetaModel, JavaParserMetaModel.moduleDirectiveMetaModel,
JavaParserMetaModel.bodyDeclarationMetaModel, JavaParserMetaModel.bodyDeclarationMetaModel,
JavaParserMetaModel.commentMetaModel JavaParserMetaModel.commentMetaModel
); );
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class MetaModelGenerator {
add(StringLiteralExpr.class); add(StringLiteralExpr.class);


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


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


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


static String METAMODEL_PACKAGE = "com.github.javaparser.metamodel"; 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.Name;
import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr; import com.github.javaparser.ast.expr.SingleMemberAnnotationExpr;
import com.github.javaparser.ast.modules.*; import com.github.javaparser.ast.modules.*;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.printer.ConcreteSyntaxModel; import com.github.javaparser.printer.ConcreteSyntaxModel;
import org.junit.Test; import org.junit.Test;


import static com.github.javaparser.GeneratedJavaParserConstants.IDENTIFIER; 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.JavaParser.parseName;
import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9; import static com.github.javaparser.ParserConfiguration.LanguageLevel.JAVA_9;
import static com.github.javaparser.Providers.provider; import static com.github.javaparser.Providers.provider;
Expand Down Expand Up @@ -42,7 +40,7 @@ public void moduleInfoKeywordsAreSeenAsIdentifiers() {
@Test @Test
public void issue988RequireTransitiveShouldRequireAModuleCalledTransitive() { public void issue988RequireTransitiveShouldRequireAModuleCalledTransitive() {
CompilationUnit cu = parse("module X { requires transitive; }"); 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("transitive", requiresTransitive.getNameAsString());
assertEquals(IDENTIFIER, requiresTransitive.getName().getTokenRange().get().getBegin().getKind()); 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 SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("2")),
new MarkerAnnotationExpr(new Name("Bar"))); 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.getNameAsString()).isEqualTo("A.B");
assertThat(moduleRequiresStmt.getModifiers()).isEmpty(); 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.getNameAsString()).isEqualTo("R.S");
assertThat(moduleExportsStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2")); 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.getNameAsString()).isEqualTo("R.S");
assertThat(moduleOpensStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2")); 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"); 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.getNameAsString()).isEqualTo("X.Y");
assertThat(moduleProvidesStmt.getWith()).containsExactly( assertThat(moduleProvidesStmt.getWith()).containsExactly(
parseName("Z1.Z2"), 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("exports com.laamella.base.entity.channel.internal to com.laamella.core;")
.addDirective("uses com.laamella.base.util.internal.FactoryDelegate;"); .addDirective("uses com.laamella.base.util.internal.FactoryDelegate;");


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


moduleDeclaration moduleDeclaration
.addDirective(new ModuleExportsStmt() .addDirective(new ModuleExportsDirective()
.setName("foo.bar.x") .setName("foo.bar.x")
.addModuleName("other.foo") .addModuleName("other.foo")
.addModuleName("other.bar") .addModuleName("other.bar")
Expand Down
Expand Up @@ -30,7 +30,7 @@
import com.github.javaparser.ast.body.TypeDeclaration; import com.github.javaparser.ast.body.TypeDeclaration;
import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.modules.ModuleDeclaration; 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.BlockStmt;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import com.github.javaparser.ast.stmt.Statement; 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;" * @param moduleDirective a directive like "opens C;"
* @return the AST for the module directive * @return the AST for the module directive
* @throws ParseProblemException if the source code has parser errors * @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)); 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.body.TypeDeclaration;
import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.modules.ModuleDeclaration; 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.BlockStmt;
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt; import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
import com.github.javaparser.ast.stmt.Statement; 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<PackageDeclaration> PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart;
ParseStart<TypeDeclaration<?>> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart; ParseStart<TypeDeclaration<?>> TYPE_DECLARATION = GeneratedJavaParser::TypeDeclarationParseStart;
ParseStart<ModuleDeclaration> MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart; ParseStart<ModuleDeclaration> MODULE_DECLARATION = GeneratedJavaParser::ModuleDeclarationParseStart;
ParseStart<ModuleStmt> MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart; ParseStart<ModuleDirective> MODULE_DIRECTIVE = GeneratedJavaParser::ModuleDirectiveParseStart;


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

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

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


private boolean isOpen; private boolean isOpen;


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


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


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


/** /**
* This constructor is used by the parser and is considered private. * This constructor is used by the parser and is considered private.
*/ */
@Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") @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); super(tokenRange);
setAnnotations(annotations); setAnnotations(annotations);
setName(name); setName(name);
setOpen(isOpen); setOpen(isOpen);
setModuleStmts(moduleStmts); setDirectives(directives);
customInitialization(); customInitialization();
} }


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


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


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


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


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

0 comments on commit 6d06ae9

Please sign in to comment.