Skip to content

Commit

Permalink
Validate module support
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Mar 23, 2017
1 parent 20afdb8 commit 60236c6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
Expand Up @@ -10,6 +10,7 @@
import com.github.javaparser.ast.expr.ClassExpr; import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.LambdaExpr;
import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.ast.expr.StringLiteralExpr;
import com.github.javaparser.ast.modules.ModuleDeclaration;
import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters; import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters;
import com.github.javaparser.ast.stmt.AssertStmt; import com.github.javaparser.ast.stmt.AssertStmt;
Expand Down Expand Up @@ -90,11 +91,14 @@ public class Java1_0Validator extends Validators {
n -> true, n -> true,
(n, reporter) -> reporter.report(n, "Multi-catch is not supported.") (n, reporter) -> reporter.report(n, "Multi-catch is not supported.")
); );
protected final Validator noLambdas= new SimpleValidator<>(LambdaExpr.class, protected final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class,
n -> true, n -> true,
(n, reporter) -> reporter.report(n, "Lambdas are not supported.") (n, reporter) -> reporter.report(n, "Lambdas are not supported.")
); );

protected final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class,
n -> true,
(n, reporter) -> reporter.report(n, "Modules are not supported.")
);




public Java1_0Validator() { public Java1_0Validator() {
Expand All @@ -115,7 +119,7 @@ public Java1_0Validator() {
add(noUnderscoresInIntegerLiterals); add(noUnderscoresInIntegerLiterals);
add(noMultiCatch); add(noMultiCatch);
add(noLambdas); add(noLambdas);
// TODO validate "no modules" add(noModules);
// TODO validate "no default interface methods" // TODO validate "no default interface methods"
// TODO validate "no private interface methods" // TODO validate "no private interface methods"
} }
Expand Down
Expand Up @@ -12,7 +12,7 @@ public Java9Validator() {
super(); super();
add(underscoreKeywordValidator); add(underscoreKeywordValidator);
remove(noLambdas); remove(noLambdas);
// TODO validate modules remove(noModules);
// TODO validate private interface methods // TODO validate private interface methods
} }
} }
Expand Up @@ -110,26 +110,6 @@ public void nestedInterface() {
); );
} }


@Test
public void moduleRequires() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("module x{requires " + allModifiers + " a;}"));
assertProblems(result,
"(line 1,col 10) Can have only one of 'public', 'protected', 'private'.",
"(line 1,col 10) Can have only one of 'final', 'abstract'.",
"(line 1,col 10) 'transient' is not allowed here.",
"(line 1,col 10) 'volatile' is not allowed here.",
"(line 1,col 10) 'final' is not allowed here.",
"(line 1,col 10) 'synchronized' is not allowed here.",
"(line 1,col 10) 'default' is not allowed here.",
"(line 1,col 10) 'native' is not allowed here.",
"(line 1,col 10) 'private' is not allowed here.",
"(line 1,col 10) 'protected' is not allowed here.",
"(line 1,col 10) 'strictfp' is not allowed here.",
"(line 1,col 10) 'abstract' is not allowed here.",
"(line 1,col 10) 'public' is not allowed here."
);
}

@Test @Test
public void constructor() { public void constructor() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X{" + allModifiers + "X(){};}")); ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X{" + allModifiers + "X(){};}"));
Expand Down
Expand Up @@ -107,27 +107,6 @@ public void nestedInterface() {
); );
} }


@Test
public void moduleRequires() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("module x{requires " + allModifiers + " a;}"));
assertProblems(result,
"(line 1,col 10) Can have only one of 'public', 'protected', 'private'.",
"(line 1,col 10) Can have only one of 'final', 'abstract'.",
"(line 1,col 10) Can have only one of 'native', 'strictfp'.",
"(line 1,col 10) 'transient' is not allowed here.",
"(line 1,col 10) 'volatile' is not allowed here.",
"(line 1,col 10) 'final' is not allowed here.",
"(line 1,col 10) 'synchronized' is not allowed here.",
"(line 1,col 10) 'default' is not allowed here.",
"(line 1,col 10) 'native' is not allowed here.",
"(line 1,col 10) 'private' is not allowed here.",
"(line 1,col 10) 'protected' is not allowed here.",
"(line 1,col 10) 'strictfp' is not allowed here.",
"(line 1,col 10) 'abstract' is not allowed here.",
"(line 1,col 10) 'public' is not allowed here."
);
}

@Test @Test
public void constructor() { public void constructor() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X{" + allModifiers + "X(){};}")); ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("class X{" + allModifiers + "X(){};}"));
Expand Down
Expand Up @@ -57,4 +57,10 @@ public void lambdas() {
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("a(() -> 1);")); ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("a(() -> 1);"));
assertNoProblems(result); assertNoProblems(result);
} }

@Test
public void noModules() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("open module x {}"));
assertProblems(result, "(line 1,col 1) Modules are not supported.");
}
} }
Expand Up @@ -3,18 +3,22 @@
import com.github.javaparser.JavaParser; import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult; import com.github.javaparser.ParseResult;
import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.stmt.Statement; import com.github.javaparser.ast.stmt.Statement;
import org.junit.Test; import org.junit.Test;


import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
import static com.github.javaparser.ParseStart.STATEMENT; import static com.github.javaparser.ParseStart.STATEMENT;
import static com.github.javaparser.Providers.provider; import static com.github.javaparser.Providers.provider;
import static com.github.javaparser.ast.validator.Java1_1ValidatorTest.allModifiers;
import static com.github.javaparser.utils.TestUtils.assertNoProblems;
import static com.github.javaparser.utils.TestUtils.assertProblems; import static com.github.javaparser.utils.TestUtils.assertProblems;


public class Java9ValidatorTest { public class Java9ValidatorTest {
public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setValidator(new Java9Validator())); public static final JavaParser javaParser = new JavaParser(new ParserConfiguration().setValidator(new Java9Validator()));


@Test @Test
public void tryUnderscoreIdentifiers() { public void underscoreIdentifiers() {
ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("a.b._.c.d = act(_, _ -> _);")); ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("a.b._.c.d = act(_, _ -> _);"));
assertProblems(result, assertProblems(result,
"(line 1,col 5) '_' is a reserved keyword.", "(line 1,col 5) '_' is a reserved keyword.",
Expand All @@ -23,4 +27,31 @@ public void tryUnderscoreIdentifiers() {
"(line 1,col 25) '_' is a reserved keyword." "(line 1,col 25) '_' is a reserved keyword."
); );
} }

@Test
public void moduleRequires() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("module x{requires " + allModifiers + " a;}"));
assertProblems(result,
"(line 1,col 10) Can have only one of 'public', 'protected', 'private'.",
"(line 1,col 10) Can have only one of 'final', 'abstract'.",
"(line 1,col 10) Can have only one of 'native', 'strictfp'.",
"(line 1,col 10) 'transient' is not allowed here.",
"(line 1,col 10) 'volatile' is not allowed here.",
"(line 1,col 10) 'final' is not allowed here.",
"(line 1,col 10) 'synchronized' is not allowed here.",
"(line 1,col 10) 'default' is not allowed here.",
"(line 1,col 10) 'native' is not allowed here.",
"(line 1,col 10) 'private' is not allowed here.",
"(line 1,col 10) 'protected' is not allowed here.",
"(line 1,col 10) 'strictfp' is not allowed here.",
"(line 1,col 10) 'abstract' is not allowed here.",
"(line 1,col 10) 'public' is not allowed here."
);
}

@Test
public void modules() {
ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider("open module x {}"));
assertNoProblems(result);
}
} }

0 comments on commit 60236c6

Please sign in to comment.