Skip to content

Commit

Permalink
Implement Java 9 module info
Browse files Browse the repository at this point in the history
  • Loading branch information
matozoid committed Feb 24, 2017
1 parent 8771897 commit 88d5ca0
Show file tree
Hide file tree
Showing 48 changed files with 6,325 additions and 1,026 deletions.
Expand Up @@ -4,6 +4,8 @@
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.MarkerAnnotationExpr;
import com.github.javaparser.ast.expr.Name;
import com.github.javaparser.metamodel.BaseNodeMetaModel;
import com.github.javaparser.metamodel.JavaParserMetaModel;
import com.github.javaparser.utils.Log;
Expand Down Expand Up @@ -64,10 +66,15 @@ private void generateVisitMethodForNode(BaseNodeMetaModel node, ClassOrInterface
if (visitMethod.isPresent()) {
generateVisitMethodBody(node, visitMethod.get(), compilationUnit);
} else if (createMissingVisitMethods) {
MethodDeclaration methodDeclaration = visitorClass.addMethod("visit", PUBLIC)
MethodDeclaration methodDeclaration = visitorClass.addMethod("visit")
.addParameter(node.getTypeNameGenerified(), "n")
.addParameter(argumentType, "arg")
.setType(returnType);
if (!visitorClass.isInterface()) {
methodDeclaration
.addAnnotation(new MarkerAnnotationExpr(new Name("Override")))
.addModifier(PUBLIC);
}
generateVisitMethodBody(node, methodDeclaration, compilationUnit);
}
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
*/
public class CloneVisitorGenerator extends VisitorGenerator {
public CloneVisitorGenerator(JavaParser javaParser, SourceRoot sourceRoot) {
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "CloneVisitor", "void", "A", true);
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "CloneVisitor", "Visitable", "Object", true);
}

@Override
Expand All @@ -29,25 +29,25 @@ protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration
final String getter = field.getGetterMethodName() + "()";
if (field.getNodeReference().isPresent()) {
if (field.isOptional() && field.isNodeList()) {
body.addStatement(f("NodeList<%s> %s = cloneList(_n.%s.orElse(null), _arg);", field.getTypeNameGenerified(), field.getName(), getter));
body.addStatement(f("NodeList<%s> %s = cloneList(n.%s.orElse(null), arg);", field.getTypeNameGenerified(), field.getName(), getter));
} else if (field.isNodeList()) {
body.addStatement(f("NodeList<%s> %s = cloneList(_n.%s, _arg);", field.getTypeNameGenerified(), field.getName(), getter));
body.addStatement(f("NodeList<%s> %s = cloneList(n.%s, arg);", field.getTypeNameGenerified(), field.getName(), getter));
} else {
body.addStatement(f("%s %s = cloneNode(_n.%s, _arg);", field.getTypeNameGenerified(), field.getName(), getter));
body.addStatement(f("%s %s = cloneNode(n.%s, arg);", field.getTypeNameGenerified(), field.getName(), getter));
}
}
}

SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder(f("%s r = new %s(", node.getTypeNameGenerified(), node.getTypeNameGenerified()), ",", ");");
builder.append("_n.getRange().orElse(null)");
builder.append("n.getRange().orElse(null)");
for (PropertyMetaModel field : node.getConstructorParameters()) {
if (field.getName().equals("comment")) {
continue;
}
if (field.getNodeReference().isPresent()) {
builder.append(field.getName());
} else {
builder.append(f("_n.%s()", field.getGetterMethodName()));
builder.append(f("n.%s()", field.getGetterMethodName()));
}
}

Expand Down
Expand Up @@ -16,7 +16,7 @@
*/
public class EqualsVisitorGenerator extends VisitorGenerator {
public EqualsVisitorGenerator(JavaParser javaParser, SourceRoot sourceRoot) {
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "EqualsVisitor", "Boolean", "Node", true);
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "EqualsVisitor", "Boolean", "Visitable", true);
}

@Override
Expand All @@ -30,12 +30,12 @@ protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration
final String getter = field.getGetterMethodName() + "()";
if (field.getNodeReference().isPresent()) {
if (field.isNodeList()) {
body.addStatement(f("if (!nodesEquals(n1.%s, n2.%s)) return false;", getter, getter));
body.addStatement(f("if (!nodesEquals(n.%s, n2.%s)) return false;", getter, getter));
} else {
body.addStatement(f("if (!nodeEquals(n1.%s, n2.%s)) return false;", getter, getter));
body.addStatement(f("if (!nodeEquals(n.%s, n2.%s)) return false;", getter, getter));
}
} else {
body.addStatement(f("if (!objEquals(n1.%s, n2.%s)) return false;", getter, getter));
body.addStatement(f("if (!objEquals(n.%s, n2.%s)) return false;", getter, getter));
}
}
if (body.getStatements().size() == 1) {
Expand Down
Expand Up @@ -16,7 +16,7 @@
*/
public class GenericVisitorAdapterGenerator extends VisitorGenerator {
public GenericVisitorAdapterGenerator(JavaParser javaParser, SourceRoot sourceRoot) {
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "GenericVisitorAdapter", "void", "A", true);
super(javaParser, sourceRoot, "com.github.javaparser.ast.visitor", "GenericVisitorAdapter", "R", "A", true);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions javaparser-core/bnd.bnd
Expand Up @@ -6,12 +6,15 @@ Bundle-SymbolicName: com.github.javaparser.javaparser-core
com.github.javaparser, \
com.github.javaparser.javadoc, \
com.github.javaparser.javadoc.description, \
com.github.javaparser.metamodel, \
com.github.javaparser.printer, \
com.github.javaparser.printer.concretesyntaxmodel, \
com.github.javaparser.utils, \
com.github.javaparser.ast, \
com.github.javaparser.ast.body, \
com.github.javaparser.ast.imports, \
com.github.javaparser.ast.comments, \
com.github.javaparser.ast.modules, \
com.github.javaparser.ast.nodeTypes, \
com.github.javaparser.ast.expr, \
com.github.javaparser.ast.stmt, \
Expand Down
Expand Up @@ -52,7 +52,7 @@ public final class JavaParser {
private final CommentsInserter commentsInserter;
private final ParserConfiguration configuration;

private ASTParser astParser = null;
private GeneratedJavaParser astParser = null;

/**
* Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on
Expand All @@ -72,9 +72,9 @@ public JavaParser(ParserConfiguration configuration) {
commentsInserter = new CommentsInserter(configuration);
}

private ASTParser getParserForProvider(Provider provider) {
private GeneratedJavaParser getParserForProvider(Provider provider) {
if (astParser == null) {
astParser = new ASTParser(provider);
astParser = new GeneratedJavaParser(provider);
} else {
astParser.reset(provider);
}
Expand All @@ -96,7 +96,7 @@ public <N extends Node> ParseResult<N> parse(ParseStart<N> start, Provider provi
assertNotNull(start);
assertNotNull(provider);
try {
final ASTParser parser = getParserForProvider(provider);
final GeneratedJavaParser parser = getParserForProvider(provider);
N resultNode = start.parse(parser);
if (configuration.isAttributeComments()) {
final CommentsCollection comments = parser.getCommentsCollection();
Expand Down Expand Up @@ -293,10 +293,7 @@ public static Statement parseStatement(final String statement) {

private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) {
ParseResult<T> result = new JavaParser(new ParserConfiguration()).parse(context, provider);
if (result.isSuccessful()) {
return result.getResult().get();
}
throw new ParseProblemException(result.getProblems());
return result.getResult().orElseThrow(() -> new ParseProblemException(result.getProblems()));
}

/**
Expand Down Expand Up @@ -415,4 +412,5 @@ public static Javadoc parseJavadoc(String content) {
public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) {
return simplifiedParse(EXPLICIT_CONSTRUCTOR_INVOCATION_STMT, provider(statement));
}

}

0 comments on commit 88d5ca0

Please sign in to comment.