Skip to content

Commit

Permalink
Make AST nodes non-final so that projects extending the grammar can a…
Browse files Browse the repository at this point in the history
…lso extend nodes.
  • Loading branch information
matozoid committed Feb 22, 2019
1 parent cc524c2 commit 61889ee
Show file tree
Hide file tree
Showing 95 changed files with 105 additions and 109 deletions.
Expand Up @@ -71,7 +71,7 @@ private void run(SourceRoot sourceRoot, SourceRoot generatedJavaCcSourceRoot) th
new CloneGenerator(sourceRoot).generate();
new GetMetaModelGenerator(sourceRoot).generate();
new MainConstructorGenerator(sourceRoot).generate();
new FinalGenerator(sourceRoot).generate();
new NodeModifierGenerator(sourceRoot).generate();
new AcceptGenerator(sourceRoot).generate();
new TokenKindGenerator(sourceRoot, generatedJavaCcSourceRoot).generate();
}
Expand Down
Expand Up @@ -6,13 +6,15 @@
import com.github.javaparser.metamodel.BaseNodeMetaModel;
import com.github.javaparser.utils.SourceRoot;

public class FinalGenerator extends NodeGenerator {
public FinalGenerator(SourceRoot sourceRoot) {
public class NodeModifierGenerator extends NodeGenerator {
public NodeModifierGenerator(SourceRoot sourceRoot) {
super(sourceRoot);
}

@Override
protected void generateNode(BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
nodeCoid.setFinal(!nodeMetaModel.isAbstract());
nodeCoid
.setFinal(false)
.setPublic(true);
}
}
Expand Up @@ -42,7 +42,7 @@
* the first one contains the expression "1",
* the second the expression "2".
*/
public final class ArrayCreationLevel extends Node implements NodeWithAnnotations<ArrayCreationLevel> {
public class ArrayCreationLevel extends Node implements NodeWithAnnotations<ArrayCreationLevel> {

@OptionalProperty
private Expression dimension;
Expand Down
Expand Up @@ -59,6 +59,8 @@
import static com.github.javaparser.ast.Modifier.createModifierList;
import static com.github.javaparser.utils.CodeGenerationUtils.subtractPaths;
import static com.github.javaparser.utils.Utils.assertNotNull;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.Generated;

/**
* <p>
Expand All @@ -75,7 +77,7 @@
* @see TypeDeclaration
* @see Storage
*/
public final class CompilationUnit extends Node {
public class CompilationUnit extends Node {

@OptionalProperty
private PackageDeclaration packageDeclaration;
Expand Down
Expand Up @@ -31,6 +31,8 @@
import com.github.javaparser.metamodel.ImportDeclarationMetaModel;
import com.github.javaparser.metamodel.JavaParserMetaModel;
import com.github.javaparser.TokenRange;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.Generated;

/**
* An import declaration.
Expand All @@ -43,7 +45,7 @@
* <p>The name does not include the asterisk or the static keyword.</p>
* @author Julio Vilmar Gesser
*/
public final class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration> {
public class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration> {

private Name name;

Expand Down
Expand Up @@ -36,7 +36,7 @@
/**
* A modifier, like private, public, or volatile.
*/
public final class Modifier extends Node {
public class Modifier extends Node {

public static Modifier publicModifier() {
return new Modifier(Keyword.PUBLIC);
Expand Down
Expand Up @@ -42,7 +42,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class PackageDeclaration extends Node implements NodeWithAnnotations<PackageDeclaration>, NodeWithName<PackageDeclaration> {
public class PackageDeclaration extends Node implements NodeWithAnnotations<PackageDeclaration>, NodeWithName<PackageDeclaration> {

private NodeList<AnnotationExpr> annotations = new NodeList<>();

Expand Down
Expand Up @@ -44,7 +44,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> implements NodeWithAbstractModifier<AnnotationDeclaration>, Resolvable<ResolvedAnnotationDeclaration> {
public class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> implements NodeWithAbstractModifier<AnnotationDeclaration>, Resolvable<ResolvedAnnotationDeclaration> {

public AnnotationDeclaration() {
this(null, new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>());
Expand Down
Expand Up @@ -57,7 +57,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class AnnotationMemberDeclaration extends BodyDeclaration<AnnotationMemberDeclaration> implements NodeWithJavadoc<AnnotationMemberDeclaration>, NodeWithSimpleName<AnnotationMemberDeclaration>, NodeWithType<AnnotationMemberDeclaration, Type>, NodeWithPublicModifier<AnnotationMemberDeclaration>, NodeWithAbstractModifier<AnnotationMemberDeclaration>, Resolvable<ResolvedAnnotationMemberDeclaration> {
public class AnnotationMemberDeclaration extends BodyDeclaration<AnnotationMemberDeclaration> implements NodeWithJavadoc<AnnotationMemberDeclaration>, NodeWithSimpleName<AnnotationMemberDeclaration>, NodeWithType<AnnotationMemberDeclaration, Type>, NodeWithPublicModifier<AnnotationMemberDeclaration>, NodeWithAbstractModifier<AnnotationMemberDeclaration>, Resolvable<ResolvedAnnotationMemberDeclaration> {

private NodeList<Modifier> modifiers;

Expand Down
Expand Up @@ -54,7 +54,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration>, NodeWithTypeParameters<ClassOrInterfaceDeclaration>, NodeWithAbstractModifier<ClassOrInterfaceDeclaration>, NodeWithFinalModifier<ClassOrInterfaceDeclaration>, NodeWithConstructors<ClassOrInterfaceDeclaration>, Resolvable<ResolvedReferenceTypeDeclaration> {
public class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration>, NodeWithTypeParameters<ClassOrInterfaceDeclaration>, NodeWithAbstractModifier<ClassOrInterfaceDeclaration>, NodeWithFinalModifier<ClassOrInterfaceDeclaration>, NodeWithConstructors<ClassOrInterfaceDeclaration>, Resolvable<ResolvedReferenceTypeDeclaration> {

private boolean isInterface;

Expand Down
Expand Up @@ -53,7 +53,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ConstructorDeclaration extends CallableDeclaration<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration>, Resolvable<ResolvedConstructorDeclaration> {
public class ConstructorDeclaration extends CallableDeclaration<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration>, Resolvable<ResolvedConstructorDeclaration> {

private BlockStmt body;

Expand Down
Expand Up @@ -48,7 +48,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> implements NodeWithJavadoc<EnumConstantDeclaration>, NodeWithSimpleName<EnumConstantDeclaration>, NodeWithArguments<EnumConstantDeclaration>, Resolvable<ResolvedEnumConstantDeclaration> {
public class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> implements NodeWithJavadoc<EnumConstantDeclaration>, NodeWithSimpleName<EnumConstantDeclaration>, NodeWithArguments<EnumConstantDeclaration>, Resolvable<ResolvedEnumConstantDeclaration> {

private SimpleName name;

Expand Down
Expand Up @@ -49,7 +49,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class EnumDeclaration extends TypeDeclaration<EnumDeclaration> implements NodeWithImplements<EnumDeclaration>, NodeWithConstructors<EnumDeclaration>, Resolvable<ResolvedEnumDeclaration> {
public class EnumDeclaration extends TypeDeclaration<EnumDeclaration> implements NodeWithImplements<EnumDeclaration>, NodeWithConstructors<EnumDeclaration>, Resolvable<ResolvedEnumDeclaration> {

private NodeList<ClassOrInterfaceType> implementedTypes;

Expand Down
Expand Up @@ -60,7 +60,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration> implements NodeWithJavadoc<FieldDeclaration>, NodeWithVariables<FieldDeclaration>, NodeWithAccessModifiers<FieldDeclaration>, NodeWithStaticModifier<FieldDeclaration>, NodeWithFinalModifier<FieldDeclaration>, Resolvable<ResolvedFieldDeclaration> {
public class FieldDeclaration extends BodyDeclaration<FieldDeclaration> implements NodeWithJavadoc<FieldDeclaration>, NodeWithVariables<FieldDeclaration>, NodeWithAccessModifiers<FieldDeclaration>, NodeWithStaticModifier<FieldDeclaration>, NodeWithFinalModifier<FieldDeclaration>, Resolvable<ResolvedFieldDeclaration> {

private NodeList<Modifier> modifiers;

Expand Down
Expand Up @@ -42,7 +42,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class InitializerDeclaration extends BodyDeclaration<InitializerDeclaration> implements NodeWithJavadoc<InitializerDeclaration>, NodeWithBlockStmt<InitializerDeclaration> {
public class InitializerDeclaration extends BodyDeclaration<InitializerDeclaration> implements NodeWithJavadoc<InitializerDeclaration>, NodeWithBlockStmt<InitializerDeclaration> {

private boolean isStatic;

Expand Down
Expand Up @@ -57,7 +57,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class MethodDeclaration extends CallableDeclaration<MethodDeclaration> implements NodeWithType<MethodDeclaration, Type>, NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithJavadoc<MethodDeclaration>, NodeWithDeclaration, NodeWithSimpleName<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrownExceptions<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration>, NodeWithAccessModifiers<MethodDeclaration>, NodeWithAbstractModifier<MethodDeclaration>, NodeWithStaticModifier<MethodDeclaration>, NodeWithFinalModifier<MethodDeclaration>, NodeWithStrictfpModifier<MethodDeclaration>, Resolvable<ResolvedMethodDeclaration> {
public class MethodDeclaration extends CallableDeclaration<MethodDeclaration> implements NodeWithType<MethodDeclaration, Type>, NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithJavadoc<MethodDeclaration>, NodeWithDeclaration, NodeWithSimpleName<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrownExceptions<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration>, NodeWithAccessModifiers<MethodDeclaration>, NodeWithAbstractModifier<MethodDeclaration>, NodeWithStaticModifier<MethodDeclaration>, NodeWithFinalModifier<MethodDeclaration>, NodeWithStrictfpModifier<MethodDeclaration>, Resolvable<ResolvedMethodDeclaration> {

private Type type;

Expand Down
Expand Up @@ -55,7 +55,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class Parameter extends Node implements NodeWithType<Parameter, Type>, NodeWithAnnotations<Parameter>, NodeWithSimpleName<Parameter>, NodeWithFinalModifier<Parameter>, Resolvable<ResolvedParameterDeclaration> {
public class Parameter extends Node implements NodeWithType<Parameter, Type>, NodeWithAnnotations<Parameter>, NodeWithSimpleName<Parameter>, NodeWithFinalModifier<Parameter>, Resolvable<ResolvedParameterDeclaration> {

private Type type;

Expand Down
Expand Up @@ -48,7 +48,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ReceiverParameter extends Node implements NodeWithType<ReceiverParameter, Type>, NodeWithAnnotations<ReceiverParameter>, NodeWithName<ReceiverParameter> {
public class ReceiverParameter extends Node implements NodeWithType<ReceiverParameter, Type>, NodeWithAnnotations<ReceiverParameter>, NodeWithName<ReceiverParameter> {

private Type type;

Expand Down
Expand Up @@ -56,7 +56,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class VariableDeclarator extends Node implements NodeWithType<VariableDeclarator, Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedValueDeclaration> {
public class VariableDeclarator extends Node implements NodeWithType<VariableDeclarator, Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedValueDeclaration> {

private SimpleName name;

Expand Down
Expand Up @@ -41,7 +41,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class BlockComment extends Comment {
public class BlockComment extends Comment {

public BlockComment() {
this(null, "empty");
Expand Down
Expand Up @@ -32,15 +32,14 @@
import java.util.function.Consumer;
import java.util.Optional;
import com.github.javaparser.ast.Generated;

import static com.github.javaparser.StaticJavaParser.parseJavadoc;

/**
* A Javadoc comment. <code>/&#42;&#42; a comment &#42;/</code>
*
* @author Julio Vilmar Gesser
*/
public final class JavadocComment extends Comment {
public class JavadocComment extends Comment {

public JavadocComment() {
this(null, "empty");
Expand Down
Expand Up @@ -40,7 +40,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class LineComment extends Comment {
public class LineComment extends Comment {

public LineComment() {
this(null, "empty");
Expand Down
Expand Up @@ -40,7 +40,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ArrayAccessExpr extends Expression {
public class ArrayAccessExpr extends Expression {

private Expression name;

Expand Down
Expand Up @@ -32,7 +32,6 @@
import com.github.javaparser.metamodel.JavaParserMetaModel;
import com.github.javaparser.metamodel.NonEmptyProperty;
import java.util.Optional;

import static com.github.javaparser.StaticJavaParser.parseType;
import static com.github.javaparser.utils.Utils.assertNotNull;
import com.github.javaparser.TokenRange;
Expand All @@ -49,7 +48,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ArrayCreationExpr extends Expression {
public class ArrayCreationExpr extends Expression {

@NonEmptyProperty
private NodeList<ArrayCreationLevel> levels;
Expand Down
Expand Up @@ -43,7 +43,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ArrayInitializerExpr extends Expression {
public class ArrayInitializerExpr extends Expression {

private NodeList<Expression> values;

Expand Down
Expand Up @@ -45,7 +45,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class AssignExpr extends Expression {
public class AssignExpr extends Expression {

public enum Operator implements Printable {

Expand Down
Expand Up @@ -43,7 +43,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class BinaryExpr extends Expression {
public class BinaryExpr extends Expression {

public enum Operator implements Printable {

Expand Down
Expand Up @@ -40,7 +40,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class BooleanLiteralExpr extends LiteralExpr {
public class BooleanLiteralExpr extends LiteralExpr {

private boolean value;

Expand Down
Expand Up @@ -43,7 +43,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class CastExpr extends Expression implements NodeWithType<CastExpr, Type>, NodeWithExpression<CastExpr> {
public class CastExpr extends Expression implements NodeWithType<CastExpr, Type>, NodeWithExpression<CastExpr> {

private Type type;

Expand Down
Expand Up @@ -44,7 +44,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class CharLiteralExpr extends LiteralStringValueExpr {
public class CharLiteralExpr extends LiteralStringValueExpr {

public CharLiteralExpr() {
this(null, "?");
Expand Down
Expand Up @@ -43,7 +43,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ClassExpr extends Expression implements NodeWithType<ClassExpr, Type> {
public class ClassExpr extends Expression implements NodeWithType<ClassExpr, Type> {

private Type type;

Expand Down
Expand Up @@ -41,7 +41,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class ConditionalExpr extends Expression implements NodeWithCondition<ConditionalExpr> {
public class ConditionalExpr extends Expression implements NodeWithCondition<ConditionalExpr> {

private Expression condition;

Expand Down
Expand Up @@ -40,7 +40,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class DoubleLiteralExpr extends LiteralStringValueExpr {
public class DoubleLiteralExpr extends LiteralStringValueExpr {

public DoubleLiteralExpr() {
this(null, "0");
Expand Down
Expand Up @@ -40,7 +40,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class EnclosedExpr extends Expression {
public class EnclosedExpr extends Expression {

private Expression inner;

Expand Down
Expand Up @@ -50,7 +50,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class FieldAccessExpr extends Expression implements NodeWithSimpleName<FieldAccessExpr>, NodeWithTypeArguments<FieldAccessExpr>, NodeWithScope<FieldAccessExpr>, Resolvable<ResolvedValueDeclaration> {
public class FieldAccessExpr extends Expression implements NodeWithSimpleName<FieldAccessExpr>, NodeWithTypeArguments<FieldAccessExpr>, NodeWithScope<FieldAccessExpr>, Resolvable<ResolvedValueDeclaration> {

private Expression scope;

Expand Down
Expand Up @@ -44,7 +44,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr, ReferenceType>, NodeWithExpression<InstanceOfExpr> {
public class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr, ReferenceType>, NodeWithExpression<InstanceOfExpr> {

private Expression expression;

Expand Down
Expand Up @@ -42,7 +42,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class IntegerLiteralExpr extends LiteralStringValueExpr {
public class IntegerLiteralExpr extends LiteralStringValueExpr {

public IntegerLiteralExpr() {
this(null, "0");
Expand Down
Expand Up @@ -58,7 +58,7 @@
*
* @author Raquel Pau
*/
public final class LambdaExpr extends Expression implements NodeWithParameters<LambdaExpr> {
public class LambdaExpr extends Expression implements NodeWithParameters<LambdaExpr> {

private NodeList<Parameter> parameters;

Expand Down
Expand Up @@ -42,7 +42,7 @@
*
* @author Julio Vilmar Gesser
*/
public final class LongLiteralExpr extends LiteralStringValueExpr {
public class LongLiteralExpr extends LiteralStringValueExpr {

public LongLiteralExpr() {
this(null, "0");
Expand Down

0 comments on commit 61889ee

Please sign in to comment.