Skip to content

Commit

Permalink
regeneration of the meta-model and model
Browse files Browse the repository at this point in the history
  • Loading branch information
wadoon committed Apr 29, 2024
1 parent 36fb18b commit 30ce079
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .run/CoreGenerator.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.github.javaparser.generator.core.CoreGenerator"/>
<module name="jmlparser-core-generators"/>
<option name="PROGRAM_PARAMETERS" value="$ContentRoot$"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/javaparser-core-metamodel-generator"/>
<option name="PROGRAM_PARAMETERS" value="$PROJECT_DIR$/stupid/"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.github.javaparser.generator.metamodel.*"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ public static void main(String[] args) throws Exception {
throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
}
Log.setAdapter(new Log.StandardOutStandardErrorAdapter());
final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
final var project = Paths.get(args[0]).getParent();
final Path root = project.resolve(Paths.get("javaparser-core", "src", "main", "java"));
final SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration)
// .setPrinter(LexicalPreservingPrinter::print)
;
StaticJavaParser.setConfiguration(parserConfiguration);

final Path generatedJavaCcRoot = Paths.get(args[0], "..", "javaparser-core", "target", "generated-sources", "javacc");
final Path generatedJavaCcRoot = project.resolve(Paths.get("javaparser-core", "target", "generated-sources", "javacc"));
final SourceRoot generatedJavaCcSourceRoot = new SourceRoot(generatedJavaCcRoot, parserConfiguration)
// .setPrinter(LexicalPreservingPrinter::print)
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.util.Optional;
import java.util.function.Predicate;

import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.observer.Observable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@
import com.github.javaparser.metamodel.OptionalProperty;
import com.github.javaparser.resolution.Resolvable;
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

import static com.github.javaparser.ast.Modifier.DefaultKeyword.*;
import static com.github.javaparser.utils.Utils.assertNotNull;

Expand Down Expand Up @@ -266,10 +264,7 @@ public boolean isPublic() {
}

private boolean isImplicitlyPublic() {
return getAccessSpecifier() == AccessSpecifier.NONE
&& hasParentNode()
&& getParentNode().get() instanceof ClassOrInterfaceDeclaration
&& ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface();
return getAccessSpecifier() == AccessSpecifier.NONE && hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface();
}

/*
Expand All @@ -282,13 +277,9 @@ public boolean isAbstract() {
}

private boolean isImplicitlyAbstract() {
return hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration
&& ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface()
&& Arrays.asList(STATIC, DEFAULT, PRIVATE).stream()
.noneMatch(modifier -> hasModifier(modifier));
return hasParentNode() && getParentNode().get() instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) getParentNode().get()).isInterface() && Arrays.asList(STATIC, DEFAULT, PRIVATE).stream().noneMatch(modifier -> hasModifier(modifier));
}


public boolean isNative() {
return hasModifier(Modifier.DefaultKeyword.NATIVE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
package com.github.javaparser.ast.expr;

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

import java.util.Optional;
import java.util.function.Consumer;

import com.github.javaparser.TokenRange;
import com.github.javaparser.ast.AllFieldsConstructor;
import com.github.javaparser.ast.Generated;
Expand Down Expand Up @@ -117,13 +115,11 @@ public LambdaExpr(TokenRange tokenRange, NodeList<Parameter> parameters, Stateme
customInitialization();
}

@Override
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public NodeList<Parameter> getParameters() {
return parameters;
}

@Override
@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
public LambdaExpr setParameters(final NodeList<Parameter> parameters) {
assertNotNull(parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ default boolean hasParametersOfType(String... paramTypes) {
*/
default boolean hasParametersOfType(Class<?>... paramTypes) {
return // if p.getType() is a class or interface type, we want to consider its erasure, i.e., if the parameter
getParameters().stream().// is "List<String>", we want to consider it as "List", so we need to call getName()
map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElseGet(() -> p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList()));
// is "List<String>", we want to consider it as "List", so we need to call getName()
getParameters().stream().map(p -> p.getType().toClassOrInterfaceType().map(NodeWithSimpleName::getNameAsString).orElseGet(() -> p.getType().asString())).collect(toList()).equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.type.VarType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -40,6 +39,7 @@ public class Java10PostProcessor extends PostProcessors {
// List of parent contexts in which a var type must not be detected.
// for example: in this statement var.class.getCanonicalName(), var must not be considered as a VarType
private static List<Class> FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE = new ArrayList<>();

static {
FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.addAll(Arrays.asList(ClassExpr.class));
}
Expand All @@ -49,23 +49,19 @@ public class Java10PostProcessor extends PostProcessors {
@Override
public void postProcess(ParseResult<? extends Node> result, ParserConfiguration configuration) {
result.getResult().ifPresent(node -> {
node.findAll(ClassOrInterfaceType.class)
.forEach(n -> {
if ("var".equals(n.getNameAsString())
&& !matchForbiddenContext(n)) {
n.replace(new VarType(n.getTokenRange().orElse(null)));
}
node.findAll(ClassOrInterfaceType.class).forEach(n -> {
if ("var".equals(n.getNameAsString()) && !matchForbiddenContext(n)) {
n.replace(new VarType(n.getTokenRange().orElse(null)));
}
});
});
}

private boolean matchForbiddenContext(ClassOrInterfaceType cit) {
return cit.getParentNode().isPresent()
&& FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.stream().anyMatch(cl -> cl.isInstance(cit.getParentNode().get()));
return cit.getParentNode().isPresent() && FORBIDEN_PARENT_CONTEXT_TO_DETECT_POTENTIAL_VAR_TYPE.stream().anyMatch(cl -> cl.isInstance(cit.getParentNode().get()));
}
};


public Java10PostProcessor() {
add(varNodeCreator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.github.javaparser.ast.visitor;

import java.util.Optional;

import com.github.javaparser.ast.*;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.comments.BlockComment;
Expand All @@ -41,6 +40,7 @@
import com.github.javaparser.ast.modules.*;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.type.*;

/**
* A visitor that clones (copies) a node and all its children.
*/
Expand Down Expand Up @@ -268,6 +268,7 @@ public Visitable visit(final Parameter n, final Object arg) {
@Override
public Visitable visit(final InitializerDeclaration n, final Object arg) {
BlockStmt body = cloneNode(n.getBody(), arg);
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body);
r.setComment(comment);
Expand Down Expand Up @@ -338,6 +339,7 @@ public Visitable visit(final ArrayCreationLevel n, final Object arg) {
@Override
public Visitable visit(final IntersectionType n, final Object arg) {
NodeList<ReferenceType> elements = cloneList(n.getElements(), arg);
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements);
r.setComment(comment);
Expand All @@ -349,6 +351,7 @@ public Visitable visit(final IntersectionType n, final Object arg) {
@Override
public Visitable visit(final UnionType n, final Object arg) {
NodeList<ReferenceType> elements = cloneList(n.getElements(), arg);
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
UnionType r = new UnionType(n.getTokenRange().orElse(null), elements);
r.setComment(comment);
Expand All @@ -359,6 +362,7 @@ public Visitable visit(final UnionType n, final Object arg) {

@Override
public Visitable visit(final VoidType n, final Object arg) {
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
VoidType r = new VoidType(n.getTokenRange().orElse(null));
r.setComment(comment);
Expand All @@ -382,6 +386,7 @@ public Visitable visit(final WildcardType n, final Object arg) {

@Override
public Visitable visit(final UnknownType n, final Object arg) {
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
UnknownType r = new UnknownType(n.getTokenRange().orElse(null));
r.setComment(comment);
Expand Down Expand Up @@ -1199,6 +1204,7 @@ public Visitable visit(final ReceiverParameter n, final Object arg) {

@Override
public Visitable visit(final VarType n, final Object arg) {
NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
Comment comment = cloneNode(n.getComment(), arg);
VarType r = new VarType(n.getTokenRange().orElse(null));
r.setComment(comment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public JmlDocDeclaration visit(JmlDocDeclaration n, Void arg) {
setJmlTags(t);
TypeDeclaration<?> parent = (TypeDeclaration<?>) n.getParentNode().get();
NodeList<BodyDeclaration<?>> members = parent.getMembers();
int pos = IntStream.range(0, members.size())
.filter(i -> members.get(i) == n)
.findFirst().orElse(-1);
int pos = IntStream.range(0, members.size()).filter(i -> members.get(i) == n).findFirst().orElse(-1);
assert pos >= 0;
if (pos + 1 >= members.size()) {
//JML Documentation is last element, therefore it can only refer to upper element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ private static CsmElement typeArguments() {
// FIXME: we should introduce a derived property
// FIXME: we should introduce a derived property
// FIXME: we should introduce a derived property
// FIXME: we should introduce a derived property
concreteSyntaxModelByClass.// FIXME: we should introduce a derived property
put(// FIXME: we should introduce a derived property
VariableDeclarator.class, // list(ObservableProperty.EXTRA_ARRAY_LEVELS),
sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER)))));
put(// list(ObservableProperty.EXTRA_ARRAY_LEVELS),
VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER)))));
// /
// / Expressions
// /
Expand Down Expand Up @@ -211,12 +211,12 @@ private static CsmElement typeArguments() {
concreteSyntaxModelByClass.put(JmlMultiExprClause.class, sequence(child(ObservableProperty.KIND), child(HEAPS), space(), child(EXPRESSION), semicolon(), newline()));
concreteSyntaxModelByClass.put(JmlClauseLabel.class, sequence(child(ObservableProperty.KIND), token(LPAREN), child(LABEL), token(RPAREN), space(), child(EXPRESSION), semicolon(), newline()));
//space(),
//space(),
concreteSyntaxModelByClass.//space(),
put(//space(),
JmlCallableClause.class, //space(),
sequence(//space(),
child(MODIFIERS), //child(EXPRESSION),
token(CALLABLE), semicolon()));
sequence(//child(EXPRESSION),
child(MODIFIERS), token(CALLABLE), semicolon()));
concreteSyntaxModelByClass.put(JmlClassExprDeclaration.class, sequence(child(MODIFIERS), attribute(KIND), space(), attribute(NAME), token(COLON), child(EXPRESSION), semicolon()));
concreteSyntaxModelByClass.put(JmlBodyDeclaration.class, sequence());
concreteSyntaxModelByClass.put(JmlClassAccessibleDeclaration.class, sequence());
Expand Down
Loading

0 comments on commit 30ce079

Please sign in to comment.