diff --git a/JmlMetaModel.plantuml b/JmlMetaModel.plantuml index c06eefbdc5..490440578b 100644 --- a/JmlMetaModel.plantuml +++ b/JmlMetaModel.plantuml @@ -148,10 +148,16 @@ enum JmlClauseKind { DIVERGES_REDUNDANTLY DURATION DURATION_REDUNDANTLY + WHEN + WHEN_REDUNDANTLY NONE + } -class JmlClauseIf extends JmlClause +class JmlClauseIf extends JmlClause { + then : Java.Expression + cond : Java.Expression +} class JmlMultiExprClause extends JmlClause { heaps : NodeList } @@ -174,12 +180,12 @@ class JmlOldClause extends JmlClause { declarations : Java.VariableDeclarationExpr } class JmlCallableClause extends JmlClause { - + pre : Java.Expression + methodCalls : List } class JmlForallClause extends JmlClause { boundedVariables : NodeList } -class JmlCapturesClause extends JmlClause class JmlSignalsClause extends JmlClause { parameter: Java.Parameter expression: Java.Expression diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 2d280afdcd..4b49b9f941 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -4,7 +4,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index f773a55596..93580165d1 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -4,7 +4,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java index 8aae3a39c8..1c466934ed 100644 --- a/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java +++ b/javaparser-core-metamodel-generator/src/main/java/com/github/javaparser/generator/metamodel/MetaModelGenerator.java @@ -216,6 +216,8 @@ public class MetaModelGenerator extends AbstractGenerator { add(JmlForallClause.class); add(JmlOldClause.class); add(JmlCallableClause.class); + add(JmlClauseIf.class); + add(JmlMethodSignature.class); add(com.github.javaparser.ast.jml.clauses.JmlContract.class); //add(com.github.javaparser.ast.JmlBoundVariable.class); diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index 9ea446e4dd..579331d579 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -3,7 +3,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 6f0b8e8e04..4514bd06db 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -3,7 +3,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index b4d57eac35..cb9f998160 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -3,7 +3,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index 49fece578c..f9d496a33a 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -3,7 +3,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java index 838da862bf..cbe45ec4f6 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java @@ -214,12 +214,10 @@ public boolean remove(Node node) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } for (int i = 0; i < modifiers.size(); i++) { @@ -355,12 +353,10 @@ public boolean replace(Node node, Node replacementNode) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } for (int i = 0; i < modifiers.size(); i++) { @@ -456,6 +452,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") @SuppressWarnings("unchecked") public T setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return (T) this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java index 10781f281e..865964afca 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java @@ -193,6 +193,12 @@ public boolean remove(Node node) { if (node == null) { return false; } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; + } + } for (int i = 0; i < parameters.size(); i++) { if (parameters.get(i) == node) { parameters.remove(i); @@ -236,6 +242,12 @@ public boolean replace(Node node, Node replacementNode) { setBody((Statement) replacementNode); return true; } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; + } + } for (int i = 0; i < parameters.size(); i++) { if (parameters.get(i) == node) { parameters.set(i, (Parameter) replacementNode); @@ -284,14 +296,22 @@ public boolean isExplicitlyTyped() { return getParameters().stream().allMatch(p -> !(p.getType().isUnknownType())); } - @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public NodeList getContracts() { return contracts; } - @Override - public LambdaExpr setContracts(NodeList contracts) { + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public LambdaExpr setContracts(final NodeList contracts) { + assertNotNull(contracts); + if (contracts == this.contracts) { + return this; + } + notifyPropertyChange(ObservableProperty.CONTRACTS, this.contracts, contracts); + if (this.contracts != null) + this.contracts.setParentNode(null); this.contracts = contracts; + setAsParentNodeOf(contracts); return this; } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCallableClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCallableClause.java index bd56a790a2..edc70a7908 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCallableClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCallableClause.java @@ -3,25 +3,32 @@ import com.github.javaparser.TokenRange; import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.SimpleName; import com.github.javaparser.ast.visitor.CloneVisitor; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JmlCallableClauseMetaModel; import com.github.javaparser.ast.Node; - import java.util.Optional; import java.util.function.Consumer; +import com.github.javaparser.ast.observer.ObservableProperty; + +import static com.github.javaparser.utils.Utils.assertNotNull; + /** * @author Alexander Weigl * @version 1 (2/22/21) */ public class JmlCallableClause extends JmlClause { + private NodeList methodSignatures = new NodeList(); + @AllFieldsConstructor - public JmlCallableClause() { - this(null); + public JmlCallableClause(SimpleName name, NodeList methodSignatures) { + super(name); } /** @@ -63,21 +70,85 @@ public JmlClauseKind getKind() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlCallableClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlCallableClause asJmlCallableClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlCallableClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlCallableClause(Consumer action) { action.accept(this); } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getMethodSignatures() { + return methodSignatures; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlCallableClause setMethodSignatures(final NodeList methodSignatures) { + assertNotNull(methodSignatures); + if (methodSignatures == this.methodSignatures) { + return this; + } + notifyPropertyChange(ObservableProperty.METHOD_SIGNATURES, this.methodSignatures, methodSignatures); + if (this.methodSignatures != null) + this.methodSignatures.setParentNode(null); + this.methodSignatures = methodSignatures; + setAsParentNodeOf(methodSignatures); + return this; + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) { + return false; + } + for (int i = 0; i < methodSignatures.size(); i++) { + if (methodSignatures.get(i) == node) { + methodSignatures.remove(i); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) { + return false; + } + for (int i = 0; i < methodSignatures.size(); i++) { + if (methodSignatures.get(i) == node) { + methodSignatures.set(i, (JmlMethodSignature) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public JmlCallableClause(TokenRange tokenRange, SimpleName name, NodeList methodSignatures) { + super(tokenRange, name); + setMethodSignatures(methodSignatures); + customInitialization(); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCapturesClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCapturesClause.java index aa1f8006a1..d28fcd8238 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCapturesClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlCapturesClause.java @@ -12,6 +12,8 @@ * @author Alexander Weigl * @version 1 (2/22/21) */ +// in favour of JmlMultiExprClause +@Deprecated() public class JmlCapturesClause extends JmlClause { @AllFieldsConstructor diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClause.java index 5d1986af84..3c419d5fdf 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClause.java @@ -12,9 +12,7 @@ import com.github.javaparser.metamodel.JmlClauseMetaModel; import com.github.javaparser.metamodel.OptionalProperty; import java.util.Optional; - import static com.github.javaparser.utils.CodeGenerationUtils.f; - import java.util.function.Consumer; /** @@ -121,123 +119,170 @@ public boolean replace(Node node, Node replacementNode) { return super.replace(node, replacementNode); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlCallableClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlCallableClause asJmlCallableClause() { throw new IllegalStateException(f("%s is not JmlCallableClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlCallableClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlCallableClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlClauseLabel() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlClauseLabel asJmlClauseLabel() { throw new IllegalStateException(f("%s is not JmlClauseLabel, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlClauseLabel() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlClauseLabel(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlForallClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlForallClause asJmlForallClause() { throw new IllegalStateException(f("%s is not JmlForallClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlForallClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlForallClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlMultiExprClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlMultiExprClause asJmlMultiExprClause() { throw new IllegalStateException(f("%s is not JmlMultiExprClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlMultiExprClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlMultiExprClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlOldClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlOldClause asJmlOldClause() { throw new IllegalStateException(f("%s is not JmlOldClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlOldClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlOldClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSignalsClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSignalsClause asJmlSignalsClause() { throw new IllegalStateException(f("%s is not JmlSignalsClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSignalsClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSignalsClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSignalsOnlyClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSignalsOnlyClause asJmlSignalsOnlyClause() { throw new IllegalStateException(f("%s is not JmlSignalsOnlyClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSignalsOnlyClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSignalsOnlyClause(Consumer action) { } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSimpleExprClause() { return false; } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSimpleExprClause asJmlSimpleExprClause() { throw new IllegalStateException(f("%s is not JmlSimpleExprClause, it is %s", this, this.getClass().getSimpleName())); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSimpleExprClause() { return Optional.empty(); } + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSimpleExprClause(Consumer action) { } + + public boolean isJmlClauseIf() { + return false; + } + + public JmlClauseIf asJmlClauseIf() { + throw new IllegalStateException(f("%s is not JmlClauseIf, it is %s", this, this.getClass().getSimpleName())); + } + + public Optional toJmlClauseIf() { + return Optional.empty(); + } + + public void ifJmlClauseIf(Consumer action) { + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseIf.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseIf.java index abd08bb74c..c2e0916d85 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseIf.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseIf.java @@ -4,19 +4,37 @@ import com.github.javaparser.ast.AllFieldsConstructor; import com.github.javaparser.ast.Generated; import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.SimpleName; import com.github.javaparser.ast.visitor.CloneVisitor; import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; +import java.util.Optional; +import java.util.function.Consumer; + +import com.github.javaparser.ast.observer.ObservableProperty; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +import com.github.javaparser.metamodel.JmlClauseIfMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; + /** * @author Alexander Weigl * @version 1 (2/22/21) */ public class JmlClauseIf extends JmlClause implements MethodContractable { + private JmlClauseKind kind; + + private Expression then; + + private Expression condition; + @AllFieldsConstructor - public JmlClauseIf() { - this(null); + public JmlClauseIf(SimpleName name, Expression condition, JmlClauseKind kind, Expression then) { + this(null, name, condition, kind, then); } /** @@ -28,19 +46,20 @@ public JmlClauseIf(TokenRange tokenRange) { customInitialization(); } - @Override - @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") - public boolean remove(Node node) { - if (node == null) - return false; - return super.remove(node); - } - @Override @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") public boolean replace(Node node, Node replacementNode) { - if (node == null) + if (node == null) { return false; + } + if (node == condition) { + setCondition((Expression) replacementNode); + return true; + } + if (node == then) { + setThen((Expression) replacementNode); + return true; + } return super.replace(node, replacementNode); } @@ -51,8 +70,9 @@ public JmlClauseIf clone() { } @Override + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public JmlClauseKind getKind() { - return JmlClauseKind.WORKING_SPACE; + return kind; } @Override @@ -66,4 +86,88 @@ public R accept(final GenericVisitor v, final A arg) { public void accept(final VoidVisitor v, final A arg) { v.visit(this, arg); } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getCondition() { + return condition; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlClauseIf setCondition(final Expression condition) { + assertNotNull(condition); + if (condition == this.condition) { + return this; + } + notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition); + if (this.condition != null) + this.condition.setParentNode(null); + this.condition = condition; + setAsParentNodeOf(condition); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlClauseIf setKind(final JmlClauseKind kind) { + assertNotNull(kind); + if (kind == this.kind) { + return this; + } + notifyPropertyChange(ObservableProperty.KIND, this.kind, kind); + this.kind = kind; + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Expression getThen() { + return then; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlClauseIf setThen(final Expression then) { + assertNotNull(then); + if (then == this.then) { + return this; + } + notifyPropertyChange(ObservableProperty.THEN, this.then, then); + if (this.then != null) + this.then.setParentNode(null); + this.then = then; + setAsParentNodeOf(then); + return this; + } + + @Override + public boolean isJmlClauseIf() { + return true; + } + + @Override + public JmlClauseIf asJmlClauseIf() { + return this; + } + + @Override + public Optional toJmlClauseIf() { + return Optional.of(this); + } + + public void ifJmlClauseIf(Consumer action) { + action.accept(this); + } + + @Override + public JmlClauseIfMetaModel getMetaModel() { + return JavaParserMetaModel.jmlClauseIfMetaModel; + } + + /** + * This constructor is used by the parser and is considered private. + */ + public JmlClauseIf(TokenRange tokenRange, SimpleName name, Expression condition, JmlClauseKind kind, Expression then) { + super(tokenRange, name); + setCondition(condition); + setKind(kind); + setThen(then); + customInitialization(); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseLabel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseLabel.java index 66c92aa350..9034ab1aa4 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseLabel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlClauseLabel.java @@ -17,7 +17,6 @@ import com.github.javaparser.metamodel.OptionalProperty; import java.util.Optional; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.function.Consumer; /** @@ -189,20 +188,25 @@ public JmlClauseLabel setKind(final JmlClauseKind kind) { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlClauseLabel() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlClauseLabel asJmlClauseLabel() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlClauseLabel() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlClauseLabel(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlForallClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlForallClause.java index 5c4f7b5417..987d18217b 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlForallClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlForallClause.java @@ -13,7 +13,6 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JmlForallClauseMetaModel; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Optional; import java.util.function.Consumer; @@ -119,20 +118,25 @@ public JmlClauseKind getKind() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlForallClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlForallClause asJmlForallClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlForallClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlForallClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMethodSignature.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMethodSignature.java new file mode 100644 index 0000000000..fcdb703839 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMethodSignature.java @@ -0,0 +1,184 @@ +package com.github.javaparser.ast.jml.clauses; + +import com.github.javaparser.ast.AllFieldsConstructor; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.SimpleName; +import com.github.javaparser.ast.type.Type; +import com.github.javaparser.ast.visitor.GenericVisitor; +import com.github.javaparser.ast.visitor.VoidVisitor; +import com.github.javaparser.metamodel.OptionalProperty; +import com.github.javaparser.quality.Nullable; +import com.github.javaparser.ast.observer.ObservableProperty; + +import static com.github.javaparser.utils.Utils.assertNotNull; + +import java.util.Optional; + +import com.github.javaparser.ast.visitor.CloneVisitor; +import com.github.javaparser.metamodel.JmlMethodSignatureMetaModel; +import com.github.javaparser.metamodel.JavaParserMetaModel; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.Generated; + +/** + * @author Alexander Weigl + * @version 1 (02.05.24) + */ +public class JmlMethodSignature extends Node { + + @OptionalProperty + private Type receiver; + + private SimpleName name; + + private NodeList argumentTypes = new NodeList<>(); + + @AllFieldsConstructor + private JmlMethodSignature(@Nullable Type receiver, SimpleName name, NodeList argumentTypes) { + super(null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public R accept(final GenericVisitor v, final A arg) { + return v.visit(this, arg); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.AcceptGenerator") + public void accept(final VoidVisitor v, final A arg) { + v.visit(this, arg); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public NodeList getArgumentTypes() { + return argumentTypes; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlMethodSignature setArgumentTypes(final NodeList argumentTypes) { + assertNotNull(argumentTypes); + if (argumentTypes == this.argumentTypes) { + return this; + } + notifyPropertyChange(ObservableProperty.ARGUMENT_TYPES, this.argumentTypes, argumentTypes); + if (this.argumentTypes != null) + this.argumentTypes.setParentNode(null); + this.argumentTypes = argumentTypes; + setAsParentNodeOf(argumentTypes); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public SimpleName getName() { + return name; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlMethodSignature setName(final SimpleName name) { + assertNotNull(name); + if (name == this.name) { + return this; + } + notifyPropertyChange(ObservableProperty.NAME, this.name, name); + if (this.name != null) + this.name.setParentNode(null); + this.name = name; + setAsParentNodeOf(name); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public Optional getReceiver() { + return Optional.ofNullable(receiver); + } + + @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") + public JmlMethodSignature setReceiver(final Type receiver) { + if (receiver == this.receiver) { + return this; + } + notifyPropertyChange(ObservableProperty.RECEIVER, this.receiver, receiver); + if (this.receiver != null) + this.receiver.setParentNode(null); + this.receiver = receiver; + setAsParentNodeOf(receiver); + return this; + } + + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public JmlMethodSignature removeReceiver() { + return setReceiver((Type) null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator") + public boolean remove(Node node) { + if (node == null) { + return false; + } + for (int i = 0; i < argumentTypes.size(); i++) { + if (argumentTypes.get(i) == node) { + argumentTypes.remove(i); + return true; + } + } + if (receiver != null) { + if (node == receiver) { + removeReceiver(); + return true; + } + } + return super.remove(node); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator") + public boolean replace(Node node, Node replacementNode) { + if (node == null) { + return false; + } + for (int i = 0; i < argumentTypes.size(); i++) { + if (argumentTypes.get(i) == node) { + argumentTypes.set(i, (Type) replacementNode); + return true; + } + } + if (node == name) { + setName((SimpleName) replacementNode); + return true; + } + if (receiver != null) { + if (node == receiver) { + setReceiver((Type) replacementNode); + return true; + } + } + return super.replace(node, replacementNode); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.CloneGenerator") + public JmlMethodSignature clone() { + return (JmlMethodSignature) accept(new CloneVisitor(), null); + } + + @Override + @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator") + public JmlMethodSignatureMetaModel getMetaModel() { + return JavaParserMetaModel.jmlMethodSignatureMetaModel; + } + + /** + * This constructor is used by the parser and is considered private. + */ + @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator") + public JmlMethodSignature(TokenRange tokenRange, Type receiver, SimpleName name, NodeList argumentTypes) { + super(tokenRange); + setReceiver(receiver); + setName(name); + setArgumentTypes(argumentTypes); + customInitialization(); + } +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMultiExprClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMultiExprClause.java index bb4eedc342..7d13050e81 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMultiExprClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlMultiExprClause.java @@ -17,7 +17,6 @@ import com.github.javaparser.metamodel.OptionalProperty; import java.util.Optional; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.function.Consumer; /** @@ -196,20 +195,25 @@ public JmlMultiExprClause setExpression(final NodeList expressions) } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlMultiExprClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlMultiExprClause asJmlMultiExprClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlMultiExprClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlMultiExprClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlOldClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlOldClause.java index 846094f4af..2c631aad53 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlOldClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlOldClause.java @@ -12,7 +12,6 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JmlOldClauseMetaModel; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Optional; import java.util.function.Consumer; @@ -106,20 +105,25 @@ public JmlClauseKind getKind() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlOldClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlOldClause asJmlOldClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlOldClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlOldClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsClause.java index 0457bf6768..ebd2c9bb92 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsClause.java @@ -14,7 +14,6 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JmlSignalsClauseMetaModel; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Optional; import java.util.function.Consumer; @@ -138,20 +137,25 @@ public JmlSignalsClause clone() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSignalsClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSignalsClause asJmlSignalsClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSignalsClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSignalsClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsOnlyClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsOnlyClause.java index a1da71729a..db883885dd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsOnlyClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSignalsOnlyClause.java @@ -13,7 +13,6 @@ import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.JmlSignalsOnlyClauseMetaModel; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.Optional; import java.util.function.Consumer; @@ -136,20 +135,25 @@ public JmlClauseKind getKind() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSignalsOnlyClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSignalsOnlyClause asJmlSignalsOnlyClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSignalsOnlyClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSignalsOnlyClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSimpleExprClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSimpleExprClause.java index 5152600ba7..ba1e7f32c9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSimpleExprClause.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/jml/clauses/JmlSimpleExprClause.java @@ -17,7 +17,6 @@ import com.github.javaparser.metamodel.OptionalProperty; import java.util.Optional; import static com.github.javaparser.utils.Utils.assertNotNull; - import java.util.function.Consumer; /** @@ -205,20 +204,25 @@ public JmlSimpleExprClauseMetaModel getMetaModel() { } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public boolean isJmlSimpleExprClause() { return true; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public JmlSimpleExprClause asJmlSimpleExprClause() { return this; } @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public Optional toJmlSimpleExprClause() { return Optional.of(this); } + @Override + @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator") public void ifJmlSimpleExprClause(Consumer action) { action.accept(this); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java index 2aad25a4b0..3502ca0ee9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java @@ -38,6 +38,7 @@ public enum ObservableProperty { ANNOTATIONS(Type.MULTIPLE_REFERENCE), ANONYMOUS_CLASS_BODY(Type.MULTIPLE_REFERENCE), ARGUMENTS(Type.MULTIPLE_REFERENCE), + ARGUMENT_TYPES(Type.MULTIPLE_REFERENCE), ASTERISK(Type.SINGLE_ATTRIBUTE), BEHAVIOR(Type.SINGLE_ATTRIBUTE), BINDER(Type.SINGLE_ATTRIBUTE), @@ -98,6 +99,7 @@ public enum ObservableProperty { MEMBER_VALUE(Type.SINGLE_REFERENCE), MESSAGE(Type.SINGLE_REFERENCE), METHOD_DECLARATION(Type.SINGLE_REFERENCE), + METHOD_SIGNATURES(Type.MULTIPLE_REFERENCE), MODIFIERS(Type.MULTIPLE_REFERENCE), MODULE(Type.SINGLE_REFERENCE), MODULE_NAMES(Type.MULTIPLE_REFERENCE), @@ -114,6 +116,7 @@ public enum ObservableProperty { PERMITTED_TYPES(Type.MULTIPLE_REFERENCE), PREDICATE(Type.SINGLE_REFERENCE), QUALIFIER(Type.SINGLE_REFERENCE), + RECEIVER(Type.SINGLE_REFERENCE), RECEIVER_PARAMETER(Type.SINGLE_REFERENCE), RECORD_DECLARATION(Type.SINGLE_REFERENCE), RESOURCES(Type.MULTIPLE_REFERENCE), @@ -127,6 +130,7 @@ public enum ObservableProperty { SUB_CONTRACTS(Type.MULTIPLE_REFERENCE), SUPER_TYPE(Type.SINGLE_REFERENCE), TARGET(Type.SINGLE_REFERENCE), + THEN(Type.SINGLE_REFERENCE), THEN_EXPR(Type.SINGLE_REFERENCE), THEN_STMT(Type.SINGLE_REFERENCE), THIS(Type.SINGLE_ATTRIBUTE), diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java index 53913e22e6..8a6b2aa164 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java @@ -48,7 +48,6 @@ public class BlockStmt extends Statement implements NodeWithStatements statements; - @OptionalProperty private NodeList contracts = new NodeList<>(); public BlockStmt() { @@ -116,12 +115,10 @@ public boolean remove(Node node) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } for (int i = 0; i < statements.size(); i++) { @@ -151,12 +148,10 @@ public boolean replace(Node node, Node replacementNode) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } for (int i = 0; i < statements.size(); i++) { @@ -199,6 +194,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public BlockStmt setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java index 4c398a170b..22e4b775f9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java @@ -38,10 +38,8 @@ import com.github.javaparser.metamodel.DoStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; - import java.util.Optional; import java.util.function.Consumer; - import static com.github.javaparser.utils.Utils.assertNotNull; /** @@ -52,7 +50,6 @@ */ public class DoStmt extends Statement implements NodeWithBody, NodeWithCondition, NodeWithContracts { - @OptionalProperty private NodeList contracts; private Statement body; @@ -144,12 +141,10 @@ public boolean remove(Node node) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } return super.remove(node); @@ -181,12 +176,10 @@ public boolean replace(Node node, Node replacementNode) { setCondition((Expression) replacementNode); return true; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } return super.replace(node, replacementNode); @@ -223,6 +216,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public DoStmt setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForEachStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForEachStmt.java index c4981138bd..67085b3e44 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForEachStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForEachStmt.java @@ -35,7 +35,6 @@ import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.ForEachStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; -import com.github.javaparser.metamodel.OptionalProperty; import java.util.Optional; import java.util.function.Consumer; import static com.github.javaparser.utils.Utils.assertNotNull; @@ -49,8 +48,7 @@ */ public class ForEachStmt extends Statement implements NodeWithBody, NodeWithContracts { - @OptionalProperty - private NodeList contracts; + private NodeList contracts = new NodeList<>(); private VariableDeclarationExpr variable; @@ -192,12 +190,10 @@ public boolean remove(Node node) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } return super.remove(node); @@ -219,12 +215,10 @@ public boolean replace(Node node, Node replacementNode) { setBody((Statement) replacementNode); return true; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } if (node == iterable) { @@ -287,6 +281,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ForEachStmt setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java index 6ee78733d3..97bfd8e9bb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java @@ -37,10 +37,8 @@ import com.github.javaparser.metamodel.ForStmtMetaModel; import com.github.javaparser.metamodel.JavaParserMetaModel; import com.github.javaparser.metamodel.OptionalProperty; - import java.util.Optional; import java.util.function.Consumer; - import static com.github.javaparser.utils.Utils.assertNotNull; /** @@ -72,7 +70,6 @@ */ public class ForStmt extends Statement implements NodeWithBody, NodeWithContracts { - @OptionalProperty private NodeList contracts; private NodeList initialization; @@ -220,12 +217,10 @@ public boolean remove(Node node) { return true; } } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } for (int i = 0; i < initialization.size(); i++) { @@ -276,12 +271,10 @@ public boolean replace(Node node, Node replacementNode) { return true; } } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } for (int i = 0; i < initialization.size(); i++) { @@ -330,6 +323,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public ForStmt setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java index 2dddd87fd2..3e291e06a8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java @@ -36,7 +36,6 @@ import com.github.javaparser.ast.visitor.GenericVisitor; import com.github.javaparser.ast.visitor.VoidVisitor; import com.github.javaparser.metamodel.JavaParserMetaModel; -import com.github.javaparser.metamodel.OptionalProperty; import com.github.javaparser.metamodel.WhileStmtMetaModel; import java.util.Optional; import java.util.function.Consumer; @@ -50,7 +49,6 @@ */ public class WhileStmt extends Statement implements NodeWithBody, NodeWithCondition, NodeWithContracts { - @OptionalProperty private NodeList contracts; private Expression condition; @@ -142,12 +140,10 @@ public boolean remove(Node node) { if (node == null) { return false; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.remove(i); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.remove(i); + return true; } } return super.remove(node); @@ -179,12 +175,10 @@ public boolean replace(Node node, Node replacementNode) { setCondition((Expression) replacementNode); return true; } - if (contracts != null) { - for (int i = 0; i < contracts.size(); i++) { - if (contracts.get(i) == node) { - contracts.set(i, (JmlContract) replacementNode); - return true; - } + for (int i = 0; i < contracts.size(); i++) { + if (contracts.get(i) == node) { + contracts.set(i, (JmlContract) replacementNode); + return true; } } return super.replace(node, replacementNode); @@ -221,6 +215,7 @@ public NodeList getContracts() { @Generated("com.github.javaparser.generator.core.node.PropertyGenerator") public WhileStmt setContracts(final NodeList contracts) { + assertNotNull(contracts); if (contracts == this.contracts) { return this; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java index bfbffe5a30..6cd86ec85e 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java @@ -1021,6 +1021,7 @@ public Visitable visit(final CatchClause n, final Object arg) { @Override public Visitable visit(final LambdaExpr n, final Object arg) { Statement body = cloneNode(n.getBody(), arg); + NodeList contracts = cloneList(n.getContracts(), arg); NodeList parameters = cloneList(n.getParameters(), arg); Comment comment = cloneNode(n.getComment(), arg); LambdaExpr r = new LambdaExpr(n.getTokenRange().orElse(null), parameters, body, n.isEnclosingParameters()); @@ -1411,9 +1412,10 @@ public Visitable visit(final JmlUnreachableStmt n, final Object arg) { @Override public Visitable visit(final JmlCallableClause n, final Object arg) { + NodeList methodSignatures = cloneList(n.getMethodSignatures(), arg); SimpleName name = cloneNode(n.getName(), arg); Comment comment = cloneNode(n.getComment(), arg); - JmlCallableClause r = new JmlCallableClause(n.getTokenRange().orElse(null)); + JmlCallableClause r = new JmlCallableClause(n.getTokenRange().orElse(null), name, methodSignatures); r.setComment(comment); n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); copyData(n, r); @@ -1455,8 +1457,11 @@ public Visitable visit(final JmlRefiningStmt n, final Object arg) { @Override public Visitable visit(final JmlClauseIf n, final Object arg) { + Expression condition = cloneNode(n.getCondition(), arg); + Expression then = cloneNode(n.getThen(), arg); + SimpleName name = cloneNode(n.getName(), arg); Comment comment = cloneNode(n.getComment(), arg); - JmlClauseIf r = new JmlClauseIf(n.getTokenRange().orElse(null)); + JmlClauseIf r = new JmlClauseIf(n.getTokenRange().orElse(null), name, condition, n.getKind(), then); r.setComment(comment); n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); copyData(n, r); @@ -1765,4 +1770,17 @@ public Visitable visit(final JmlLabelStmt n, final Object arg) { copyData(n, r); return r; } + + @Override + public Visitable visit(final JmlMethodSignature n, final Object arg) { + NodeList argumentTypes = cloneList(n.getArgumentTypes(), arg); + SimpleName name = cloneNode(n.getName(), arg); + Type receiver = cloneNode(n.getReceiver(), arg); + Comment comment = cloneNode(n.getComment(), arg); + JmlMethodSignature r = new JmlMethodSignature(n.getTokenRange().orElse(null), receiver, name, argumentTypes); + r.setComment(comment); + n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment); + copyData(n, r); + return r; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java index 78c3d3fee0..4a253c5374 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java @@ -1176,6 +1176,8 @@ public Boolean visit(final LambdaExpr n, final Visitable arg) { final LambdaExpr n2 = (LambdaExpr) arg; if (!nodeEquals(n.getBody(), n2.getBody())) return false; + if (!nodesEquals(n.getContracts(), n2.getContracts())) + return false; if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters())) return false; if (!nodesEquals(n.getParameters(), n2.getParameters())) @@ -1543,6 +1545,8 @@ public Boolean visit(final JmlUnreachableStmt n, final Visitable arg) { @Override public Boolean visit(final JmlCallableClause n, final Visitable arg) { final JmlCallableClause n2 = (JmlCallableClause) arg; + if (!nodesEquals(n.getMethodSignatures(), n2.getMethodSignatures())) + return false; if (!nodeEquals(n.getName(), n2.getName())) return false; if (!nodeEquals(n.getComment(), n2.getComment())) @@ -1583,9 +1587,17 @@ public Boolean visit(final JmlRefiningStmt n, final Visitable arg) { @Override public Boolean visit(final JmlClauseIf n, final Visitable arg) { final JmlClauseIf n2 = (JmlClauseIf) arg; + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; if (!objEquals(n.getKind(), n2.getKind())) return false; - return nodeEquals(n.getComment(), n2.getComment()); + if (!nodeEquals(n.getThen(), n2.getThen())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; } @Override @@ -1929,4 +1941,18 @@ public Boolean visit(final JmlLabelStmt n, final Visitable arg) { return false; return true; } + + @Override + public Boolean visit(final JmlMethodSignature n, final Visitable arg) { + final JmlMethodSignature n2 = (JmlMethodSignature) arg; + if (!nodesEquals(n.getArgumentTypes(), n2.getArgumentTypes())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getReceiver(), n2.getReceiver())) + return false; + if (!nodeEquals(n.getComment(), n2.getComment())) + return false; + return true; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java index 5b7a591e7d..74ca070669 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java @@ -313,7 +313,7 @@ public List visit(final BlockComment n, final A arg) { public List visit(final BlockStmt n, final A arg) { List result = new ArrayList<>(); List tmp; - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -585,7 +585,7 @@ public List visit(final ConstructorDeclaration n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -664,7 +664,7 @@ public List visit(final DoStmt n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -904,7 +904,7 @@ public List visit(final ForStmt n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -936,7 +936,7 @@ public List visit(final ForEachStmt n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -1129,6 +1129,11 @@ public List visit(final LambdaExpr n, final A arg) { if (tmp != null) result.addAll(tmp); } + { + tmp = n.getContracts().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } { tmp = n.getParameters().accept(this, arg); if (tmp != null) @@ -1285,7 +1290,7 @@ public List visit(final MethodDeclaration n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -1933,7 +1938,7 @@ public List visit(final WhileStmt n, final A arg) { if (tmp != null) result.addAll(tmp); } - if (n.getContracts() != null) { + { tmp = n.getContracts().accept(this, arg); if (tmp != null) result.addAll(tmp); @@ -2512,6 +2517,11 @@ public List visit(final JmlUnreachableStmt n, final A arg) { public List visit(final JmlCallableClause n, final A arg) { List result = new ArrayList<>(); List tmp; + { + tmp = n.getMethodSignatures().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } if (n.getName().isPresent()) { tmp = n.getName().get().accept(this, arg); if (tmp != null) @@ -2580,6 +2590,21 @@ public List visit(final JmlRefiningStmt n, final A arg) { public List visit(final JmlClauseIf n, final A arg) { List result = new ArrayList<>(); List tmp; + { + tmp = n.getCondition().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getThen().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getName().isPresent()) { + tmp = n.getName().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } if (n.getComment().isPresent()) { tmp = n.getComment().get().accept(this, arg); if (tmp != null) @@ -3228,4 +3253,31 @@ public List visit(final JmlLabelStmt n, final A arg) { } return result; } + + @Override + public List visit(final JmlMethodSignature n, final A arg) { + List result = new ArrayList<>(); + List tmp; + { + tmp = n.getArgumentTypes().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + { + tmp = n.getName().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getReceiver().isPresent()) { + tmp = n.getReceiver().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + if (n.getComment().isPresent()) { + tmp = n.getComment().get().accept(this, arg); + if (tmp != null) + result.addAll(tmp); + } + return result; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java index d2ccc8abfa..82bd52e127 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java @@ -324,4 +324,6 @@ public interface GenericVisitor { R visit(JmlEndStmt n, A arg); R visit(JmlLabelStmt n, A arg); + + R visit(JmlMethodSignature n, A arg); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java index 6fac063f67..b35e3dd4cc 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java @@ -244,7 +244,7 @@ public R visit(final BinaryExpr n, final A arg) { @Override public R visit(final BlockStmt n, final A arg) { R result; - if (n.getContracts() != null) { + { result = n.getContracts().accept(this, arg); if (result != null) return result; @@ -505,7 +505,7 @@ public R visit(final ConstructorDeclaration n, final A arg) { if (result != null) return result; } - if (n.getContracts() != null) { + { result = n.getContracts().accept(this, arg); if (result != null) return result; @@ -582,9 +582,11 @@ public R visit(final DoStmt n, final A arg) { if (result != null) return result; } - result = n.getContracts().accept(this, arg); - if (result != null) - return result; + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } if (n.getComment().isPresent()) { result = n.getComment().get().accept(this, arg); if (result != null) @@ -805,9 +807,11 @@ public R visit(final ForEachStmt n, final A arg) { if (result != null) return result; } - result = n.getContracts().accept(this, arg); - if (result != null) - return result; + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } { result = n.getIterable().accept(this, arg); if (result != null) @@ -839,9 +843,11 @@ public R visit(final ForStmt n, final A arg) { if (result != null) return result; } - result = n.getContracts().accept(this, arg); - if (result != null) - return result; + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } { result = n.getInitialization().accept(this, arg); if (result != null) @@ -1068,9 +1074,11 @@ public R visit(final MethodDeclaration n, final A arg) { if (result != null) return result; } - result = n.getContracts().accept(this, arg); - if (result != null) - return result; + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } { result = n.getModifiers().accept(this, arg); if (result != null) @@ -1743,9 +1751,11 @@ public R visit(final WhileStmt n, final A arg) { if (result != null) return result; } - result = n.getContracts().accept(this, arg); - if (result != null) - return result; + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } if (n.getComment().isPresent()) { result = n.getComment().get().accept(this, arg); if (result != null) @@ -1788,6 +1798,11 @@ public R visit(final LambdaExpr n, final A arg) { if (result != null) return result; } + { + result = n.getContracts().accept(this, arg); + if (result != null) + return result; + } { result = n.getParameters().accept(this, arg); if (result != null) @@ -2394,6 +2409,11 @@ public R visit(final JmlUnreachableStmt n, final A arg) { @Override public R visit(final JmlCallableClause n, final A arg) { R result; + { + result = n.getMethodSignatures().accept(this, arg); + if (result != null) + return result; + } if (n.getName().isPresent()) { result = n.getName().get().accept(this, arg); if (result != null) @@ -2457,9 +2477,25 @@ public R visit(final JmlRefiningStmt n, final A arg) { @Override public R visit(final JmlClauseIf n, final A arg) { R result; + { + result = n.getCondition().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getThen().accept(this, arg); + if (result != null) + return result; + } + if (n.getName().isPresent()) { + result = n.getName().get().accept(this, arg); + if (result != null) + return result; + } if (n.getComment().isPresent()) { result = n.getComment().get().accept(this, arg); - return result; + if (result != null) + return result; } return null; } @@ -3080,4 +3116,30 @@ public R visit(final JmlLabelStmt n, final A arg) { } return null; } + + @Override + public R visit(final JmlMethodSignature n, final A arg) { + R result; + { + result = n.getArgumentTypes().accept(this, arg); + if (result != null) + return result; + } + { + result = n.getName().accept(this, arg); + if (result != null) + return result; + } + if (n.getReceiver().isPresent()) { + result = n.getReceiver().get().accept(this, arg); + if (result != null) + return result; + } + if (n.getComment().isPresent()) { + result = n.getComment().get().accept(this, arg); + if (result != null) + return result; + } + return null; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java index a4f0125c00..ae7d53eec3 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java @@ -743,4 +743,9 @@ public R visit(final JmlEndStmt n, final A arg) { public R visit(final JmlLabelStmt n, final A arg) { return defaultAction(n, arg); } + + @Override + public R visit(final JmlMethodSignature n, final A arg) { + return defaultAction(n, arg); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java index 84423d5f5e..e6021d16eb 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java @@ -100,7 +100,7 @@ public Integer visit(final BlockComment n, final Void arg) { } public Integer visit(final BlockStmt n, final Void arg) { - return n.getContracts().accept(this, arg) * 31 + (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getContracts().accept(this, arg)) * 31 + (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final BooleanLiteralExpr n, final Void arg) { @@ -144,7 +144,7 @@ public Integer visit(final ConditionalExpr n, final Void arg) { } public Integer visit(final ConstructorDeclaration n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (true ? n.getContracts().accept(this, arg) : 0) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final ContinueStmt n, final Void arg) { @@ -152,7 +152,7 @@ public Integer visit(final ContinueStmt n, final Void arg) { } public Integer visit(final DoStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final DoubleLiteralExpr n, final Void arg) { @@ -192,11 +192,11 @@ public Integer visit(final FieldDeclaration n, final Void arg) { } public Integer visit(final ForStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (true ? n.getContracts().accept(this, arg) : 0) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final ForEachStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final IfStmt n, final Void arg) { @@ -232,7 +232,7 @@ public Integer visit(final LabeledStmt n, final Void arg) { } public Integer visit(final LambdaExpr n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final LineComment n, final Void arg) { @@ -264,7 +264,7 @@ public Integer visit(final MethodCallExpr n, final Void arg) { } public Integer visit(final MethodDeclaration n, final Void arg) { - return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (true ? n.getContracts().accept(this, arg) : 0) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final MethodReferenceExpr n, final Void arg) { @@ -388,7 +388,7 @@ public Integer visit(final VoidType n, final Void arg) { } public Integer visit(final WhileStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } public Integer visit(final WildcardType n, final Void arg) { @@ -520,7 +520,7 @@ public Integer visit(final JmlUnreachableStmt n, final Void arg) { @Override public Integer visit(final JmlCallableClause n, final Void arg) { - return (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getMethodSignatures().accept(this, arg)) * 31 + (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } @Override @@ -540,7 +540,7 @@ public Integer visit(final JmlRefiningStmt n, final Void arg) { @Override public Integer visit(final JmlClauseIf n, final Void arg) { - return (n.getKind().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + return (n.getCondition().accept(this, arg)) * 31 + (n.getKind().hashCode()) * 31 + (n.getThen().accept(this, arg)) * 31 + (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } @Override @@ -656,4 +656,9 @@ public Integer visit(final JmlEndStmt n, final Void arg) { public Integer visit(final JmlLabelStmt n, final Void arg) { return (n.getJmlTags().accept(this, arg)) * 31 + (n.getLabel().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); } + + @Override + public Integer visit(final JmlMethodSignature n, final Void arg) { + return (n.getArgumentTypes().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getReceiver().isPresent() ? n.getReceiver().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java index c3c880e0f5..4af068af54 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java @@ -1109,11 +1109,13 @@ public Visitable visit(final WildcardType n, final A arg) { @Override public Visitable visit(final LambdaExpr n, final A arg) { Statement body = (Statement) n.getBody().accept(this, arg); + NodeList contracts = modifyList(n.getContracts(), arg); NodeList parameters = modifyList(n.getParameters(), arg); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); if (body == null) return null; n.setBody(body); + n.setContracts(contracts); n.setParameters(parameters); n.setComment(comment); return n; @@ -1500,8 +1502,10 @@ public Visitable visit(final JmlUnreachableStmt n, final A arg) { @Override public Visitable visit(final JmlCallableClause n, final A arg) { + NodeList methodSignatures = modifyList(n.getMethodSignatures(), arg); SimpleName name = n.getName().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + n.setMethodSignatures(methodSignatures); n.setName(name); n.setComment(comment); return n; @@ -1535,8 +1539,18 @@ public Visitable visit(final JmlRefiningStmt n, final A arg) { } @Override - public Visitable visit(JmlClauseIf n, A arg) { - return null; + public Visitable visit(final JmlClauseIf n, final A arg) { + Expression condition = (Expression) n.getCondition().accept(this, arg); + Expression then = (Expression) n.getThen().accept(this, arg); + SimpleName name = n.getName().map(s -> (SimpleName) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (condition == null || then == null) + return null; + n.setCondition(condition); + n.setThen(then); + n.setName(name); + n.setComment(comment); + return n; } @Override @@ -1829,4 +1843,19 @@ public Visitable visit(final JmlLabelStmt n, final A arg) { n.setComment(comment); return n; } + + @Override + public Visitable visit(final JmlMethodSignature n, final A arg) { + NodeList argumentTypes = modifyList(n.getArgumentTypes(), arg); + SimpleName name = (SimpleName) n.getName().accept(this, arg); + Type receiver = n.getReceiver().map(s -> (Type) s.accept(this, arg)).orElse(null); + Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null); + if (name == null) + return null; + n.setArgumentTypes(argumentTypes); + n.setName(name); + n.setReceiver(receiver); + n.setComment(comment); + return n; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java index 1af02c8287..fcce1a37e5 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java @@ -965,6 +965,8 @@ public Boolean visit(final LambdaExpr n, final Visitable arg) { final LambdaExpr n2 = (LambdaExpr) arg; if (!nodeEquals(n.getBody(), n2.getBody())) return false; + if (!nodesEquals(n.getContracts(), n2.getContracts())) + return false; if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters())) return false; if (!nodesEquals(n.getParameters(), n2.getParameters())) @@ -1273,6 +1275,8 @@ public Boolean visit(final JmlUnreachableStmt n, final Visitable arg) { @Override public Boolean visit(final JmlCallableClause n, final Visitable arg) { final JmlCallableClause n2 = (JmlCallableClause) arg; + if (!nodesEquals(n.getMethodSignatures(), n2.getMethodSignatures())) + return false; if (!nodeEquals(n.getName(), n2.getName())) return false; return true; @@ -1305,7 +1309,15 @@ public Boolean visit(final JmlRefiningStmt n, final Visitable arg) { @Override public Boolean visit(final JmlClauseIf n, final Visitable arg) { final JmlClauseIf n2 = (JmlClauseIf) arg; - return objEquals(n.getKind(), n2.getKind()); + if (!nodeEquals(n.getCondition(), n2.getCondition())) + return false; + if (!objEquals(n.getKind(), n2.getKind())) + return false; + if (!nodeEquals(n.getThen(), n2.getThen())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + return true; } @Override @@ -1603,4 +1615,16 @@ public Boolean visit(final JmlLabelStmt n, final Visitable arg) { return false; return true; } + + @Override + public Boolean visit(final JmlMethodSignature n, final Visitable arg) { + final JmlMethodSignature n2 = (JmlMethodSignature) arg; + if (!nodesEquals(n.getArgumentTypes(), n2.getArgumentTypes())) + return false; + if (!nodeEquals(n.getName(), n2.getName())) + return false; + if (!nodeEquals(n.getReceiver(), n2.getReceiver())) + return false; + return true; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java index ea8182d50a..12792ac797 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java @@ -92,7 +92,7 @@ public Integer visit(final BlockComment n, final Void arg) { } public Integer visit(final BlockStmt n, final Void arg) { - return n.getContracts().accept(this, arg) * 31 + (n.getStatements().accept(this, arg)); + return (n.getContracts().accept(this, arg)) * 31 + (n.getStatements().accept(this, arg)); } public Integer visit(final BooleanLiteralExpr n, final Void arg) { @@ -136,7 +136,7 @@ public Integer visit(final ConditionalExpr n, final Void arg) { } public Integer visit(final ConstructorDeclaration n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); } public Integer visit(final ContinueStmt n, final Void arg) { @@ -144,7 +144,7 @@ public Integer visit(final ContinueStmt n, final Void arg) { } public Integer visit(final DoStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + n.getContracts().accept(this, arg); + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)); } public Integer visit(final DoubleLiteralExpr n, final Void arg) { @@ -184,11 +184,11 @@ public Integer visit(final FieldDeclaration n, final Void arg) { } public Integer visit(final ForStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)); + return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg)); } public Integer visit(final ForEachStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)); } public Integer visit(final IfStmt n, final Void arg) { @@ -224,7 +224,7 @@ public Integer visit(final LabeledStmt n, final Void arg) { } public Integer visit(final LambdaExpr n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)); + return (n.getBody().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)); } public Integer visit(final LineComment n, final Void arg) { @@ -257,7 +257,7 @@ public Integer visit(final MethodCallExpr n, final Void arg) { } public Integer visit(final MethodDeclaration n, final Void arg) { - return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + n.getContracts().accept(this, arg) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); + return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)); } public Integer visit(final MethodReferenceExpr n, final Void arg) { @@ -381,7 +381,7 @@ public Integer visit(final VoidType n, final Void arg) { } public Integer visit(final WhileStmt n, final Void arg) { - return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + n.getContracts().accept(this, arg); + return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getContracts().accept(this, arg)); } public Integer visit(final WildcardType n, final Void arg) { @@ -513,7 +513,7 @@ public Integer visit(final JmlUnreachableStmt n, final Void arg) { @Override public Integer visit(final JmlCallableClause n, final Void arg) { - return (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0); + return (n.getMethodSignatures().accept(this, arg)) * 31 + (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0); } @Override @@ -533,7 +533,7 @@ public Integer visit(final JmlRefiningStmt n, final Void arg) { @Override public Integer visit(final JmlClauseIf n, final Void arg) { - return (n.getKind().hashCode()); + return (n.getCondition().accept(this, arg)) * 31 + (n.getKind().hashCode()) * 31 + (n.getThen().accept(this, arg)) * 31 + (n.getName().isPresent() ? n.getName().get().accept(this, arg) : 0); } @Override @@ -649,4 +649,9 @@ public Integer visit(final JmlEndStmt n, final Void arg) { public Integer visit(final JmlLabelStmt n, final Void arg) { return (n.getJmlTags().accept(this, arg)) * 31 + (n.getLabel().accept(this, arg)); } + + @Override + public Integer visit(final JmlMethodSignature n, final Void arg) { + return (n.getArgumentTypes().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getReceiver().isPresent() ? n.getReceiver().get().accept(this, arg) : 0); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java index 26a690bea3..eb2b80895d 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java @@ -736,4 +736,9 @@ public Boolean visit(final JmlEndStmt n, final Visitable arg) { public Boolean visit(final JmlLabelStmt n, final Visitable arg) { return n == arg; } + + @Override + public Boolean visit(final JmlMethodSignature n, final Visitable arg) { + return n == arg; + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java index 9078e3242c..a81dc3ae93 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java @@ -649,4 +649,9 @@ public Integer visit(final JmlEndStmt n, final Void arg) { public Integer visit(final JmlLabelStmt n, final Void arg) { return n.hashCode(); } + + @Override + public Integer visit(final JmlMethodSignature n, final Void arg) { + return n.hashCode(); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java index b76dcc3755..0905557903 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java @@ -319,4 +319,6 @@ public interface VoidVisitor { void visit(JmlEndStmt n, A arg); void visit(JmlLabelStmt n, A arg); + + void visit(JmlMethodSignature n, A arg); } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java index 9eb9ffff81..903781d3e9 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java @@ -121,7 +121,7 @@ public void visit(final BlockComment n, final A arg) { @Override public void visit(final BlockStmt n, final A arg) { - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getStatements().forEach(p -> p.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -204,7 +204,7 @@ public void visit(final ConditionalExpr n, final A arg) { @Override public void visit(final ConstructorDeclaration n, final A arg) { n.getBody().accept(this, arg); - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getModifiers().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); n.getParameters().forEach(p -> p.accept(this, arg)); @@ -225,7 +225,7 @@ public void visit(final ContinueStmt n, final A arg) { public void visit(final DoStmt n, final A arg) { n.getBody().accept(this, arg); n.getCondition().accept(this, arg); - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -298,7 +298,7 @@ public void visit(final FieldDeclaration n, final A arg) { @Override public void visit(final ForEachStmt n, final A arg) { n.getBody().accept(this, arg); - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getIterable().accept(this, arg); n.getVariable().accept(this, arg); n.getComment().ifPresent(l -> l.accept(this, arg)); @@ -308,7 +308,7 @@ public void visit(final ForEachStmt n, final A arg) { public void visit(final ForStmt n, final A arg) { n.getBody().accept(this, arg); n.getCompare().ifPresent(l -> l.accept(this, arg)); - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getInitialization().forEach(p -> p.accept(this, arg)); n.getUpdate().forEach(p -> p.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); @@ -390,7 +390,7 @@ public void visit(final MethodCallExpr n, final A arg) { public void visit(final MethodDeclaration n, final A arg) { n.getBody().ifPresent(l -> l.accept(this, arg)); n.getType().accept(this, arg); - n.getContracts().forEach(v -> v.accept(this, arg)); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getModifiers().forEach(p -> p.accept(this, arg)); n.getName().accept(this, arg); n.getParameters().forEach(p -> p.accept(this, arg)); @@ -609,7 +609,7 @@ public void visit(final VoidType n, final A arg) { public void visit(final WhileStmt n, final A arg) { n.getBody().accept(this, arg); n.getCondition().accept(this, arg); - n.getContracts().accept(this, arg); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -624,6 +624,7 @@ public void visit(final WildcardType n, final A arg) { @Override public void visit(final LambdaExpr n, final A arg) { n.getBody().accept(this, arg); + n.getContracts().forEach(p -> p.accept(this, arg)); n.getParameters().forEach(p -> p.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -825,6 +826,7 @@ public void visit(final JmlUnreachableStmt n, final A arg) { @Override public void visit(final JmlCallableClause n, final A arg) { + n.getMethodSignatures().forEach(p -> p.accept(this, arg)); n.getName().ifPresent(l -> l.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -849,6 +851,9 @@ public void visit(final JmlRefiningStmt n, final A arg) { @Override public void visit(final JmlClauseIf n, final A arg) { + n.getCondition().accept(this, arg); + n.getThen().accept(this, arg); + n.getName().ifPresent(l -> l.accept(this, arg)); n.getComment().ifPresent(l -> l.accept(this, arg)); } @@ -1039,4 +1044,12 @@ public void visit(final JmlLabelStmt n, final A arg) { n.getLabel().accept(this, arg); n.getComment().ifPresent(l -> l.accept(this, arg)); } + + @Override + public void visit(final JmlMethodSignature n, final A arg) { + n.getArgumentTypes().forEach(p -> p.accept(this, arg)); + n.getName().accept(this, arg); + n.getReceiver().ifPresent(l -> l.accept(this, arg)); + n.getComment().ifPresent(l -> l.accept(this, arg)); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java index 05559f1f24..8a9e6523f8 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java +++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java @@ -739,4 +739,9 @@ public void visit(final JmlEndStmt n, final A arg) { public void visit(final JmlLabelStmt n, final A arg) { defaultAction(n, arg); } + + @Override + public void visit(final JmlMethodSignature n, final A arg) { + defaultAction(n, arg); + } } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java index c4906d5e0a..0a63d1623a 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java @@ -334,6 +334,15 @@ private static void initializeConstructorParameters() { jmlClauseLabelMetaModel.getConstructorParameters().add(jmlClauseLabelMetaModel.exprPropertyMetaModel); jmlForallClauseMetaModel.getConstructorParameters().add(jmlForallClauseMetaModel.boundedVariablesPropertyMetaModel); jmlOldClauseMetaModel.getConstructorParameters().add(jmlOldClauseMetaModel.declarationsPropertyMetaModel); + jmlCallableClauseMetaModel.getConstructorParameters().add(jmlClauseMetaModel.namePropertyMetaModel); + jmlCallableClauseMetaModel.getConstructorParameters().add(jmlCallableClauseMetaModel.methodSignaturesPropertyMetaModel); + jmlClauseIfMetaModel.getConstructorParameters().add(jmlClauseMetaModel.namePropertyMetaModel); + jmlClauseIfMetaModel.getConstructorParameters().add(jmlClauseIfMetaModel.conditionPropertyMetaModel); + jmlClauseIfMetaModel.getConstructorParameters().add(jmlClauseIfMetaModel.kindPropertyMetaModel); + jmlClauseIfMetaModel.getConstructorParameters().add(jmlClauseIfMetaModel.thenPropertyMetaModel); + jmlMethodSignatureMetaModel.getConstructorParameters().add(jmlMethodSignatureMetaModel.receiverPropertyMetaModel); + jmlMethodSignatureMetaModel.getConstructorParameters().add(jmlMethodSignatureMetaModel.namePropertyMetaModel); + jmlMethodSignatureMetaModel.getConstructorParameters().add(jmlMethodSignatureMetaModel.argumentTypesPropertyMetaModel); jmlContractMetaModel.getConstructorParameters().add(jmlContractMetaModel.jmlTagsPropertyMetaModel); jmlContractMetaModel.getConstructorParameters().add(jmlContractMetaModel.typePropertyMetaModel); jmlContractMetaModel.getConstructorParameters().add(jmlContractMetaModel.behaviorPropertyMetaModel); @@ -445,6 +454,7 @@ private static void initializeNodeMetaModels() { nodeMetaModels.add(jmlClassAccessibleDeclarationMetaModel); nodeMetaModels.add(jmlClassExprDeclarationMetaModel); nodeMetaModels.add(jmlClassLevelMetaModel); + nodeMetaModels.add(jmlClauseIfMetaModel); nodeMetaModels.add(jmlClauseLabelMetaModel); nodeMetaModels.add(jmlClauseMetaModel); nodeMetaModels.add(jmlContractMetaModel); @@ -461,6 +471,7 @@ private static void initializeNodeMetaModels() { nodeMetaModels.add(jmlLabelStmtMetaModel); nodeMetaModels.add(jmlLetExprMetaModel); nodeMetaModels.add(jmlMethodDeclarationMetaModel); + nodeMetaModels.add(jmlMethodSignatureMetaModel); nodeMetaModels.add(jmlMultiCompareExprMetaModel); nodeMetaModels.add(jmlMultiExprClauseMetaModel); nodeMetaModels.add(jmlOldClauseMetaModel); @@ -545,7 +556,7 @@ private static void initializePropertyMetaModels() { nodeMetaModel.getDeclaredPropertyMetaModels().add(nodeMetaModel.commentPropertyMetaModel); bodyDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(bodyDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false); bodyDeclarationMetaModel.getDeclaredPropertyMetaModels().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel); - callableDeclarationMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + callableDeclarationMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.contractsPropertyMetaModel); callableDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.of(modifierMetaModel), false, false, true, false); callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.modifiersPropertyMetaModel); @@ -749,6 +760,8 @@ private static void initializePropertyMetaModels() { instanceOfExprMetaModel.getDeclaredPropertyMetaModels().add(instanceOfExprMetaModel.typePropertyMetaModel); lambdaExprMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false); lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.bodyPropertyMetaModel); + lambdaExprMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); + lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.contractsPropertyMetaModel); lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "isEnclosingParameters", boolean.class, Optional.empty(), false, false, false, false); lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel); lambdaExprMetaModel.parametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "parameters", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, true, false); @@ -877,7 +890,7 @@ private static void initializePropertyMetaModels() { assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.checkPropertyMetaModel); assertStmtMetaModel.messagePropertyMetaModel = new PropertyMetaModel(assertStmtMetaModel, "message", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false); assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.messagePropertyMetaModel); - blockStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(blockStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + blockStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(blockStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); blockStmtMetaModel.getDeclaredPropertyMetaModels().add(blockStmtMetaModel.contractsPropertyMetaModel); blockStmtMetaModel.statementsPropertyMetaModel = new PropertyMetaModel(blockStmtMetaModel, "statements", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, true, false); blockStmtMetaModel.getDeclaredPropertyMetaModels().add(blockStmtMetaModel.statementsPropertyMetaModel); @@ -893,7 +906,7 @@ private static void initializePropertyMetaModels() { doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.bodyPropertyMetaModel); doStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.conditionPropertyMetaModel); - doStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + doStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.contractsPropertyMetaModel); explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false); explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel); @@ -909,7 +922,7 @@ private static void initializePropertyMetaModels() { expressionStmtMetaModel.getDeclaredPropertyMetaModels().add(expressionStmtMetaModel.expressionPropertyMetaModel); forEachStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(forEachStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false); forEachStmtMetaModel.getDeclaredPropertyMetaModels().add(forEachStmtMetaModel.bodyPropertyMetaModel); - forEachStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(forEachStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + forEachStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(forEachStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); forEachStmtMetaModel.getDeclaredPropertyMetaModels().add(forEachStmtMetaModel.contractsPropertyMetaModel); forEachStmtMetaModel.iterablePropertyMetaModel = new PropertyMetaModel(forEachStmtMetaModel, "iterable", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); forEachStmtMetaModel.getDeclaredPropertyMetaModels().add(forEachStmtMetaModel.iterablePropertyMetaModel); @@ -919,7 +932,7 @@ private static void initializePropertyMetaModels() { forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.bodyPropertyMetaModel); forStmtMetaModel.comparePropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "compare", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false); forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.comparePropertyMetaModel); - forStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + forStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.contractsPropertyMetaModel); forStmtMetaModel.initializationPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "initialization", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false); forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.initializationPropertyMetaModel); @@ -977,7 +990,7 @@ private static void initializePropertyMetaModels() { whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.bodyPropertyMetaModel); whileStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.conditionPropertyMetaModel); - whileStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), true, false, true, false); + whileStmtMetaModel.contractsPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "contracts", com.github.javaparser.ast.jml.clauses.JmlContract.class, Optional.of(jmlContractMetaModel), false, false, true, false); whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.contractsPropertyMetaModel); yieldStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(yieldStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); yieldStmtMetaModel.getDeclaredPropertyMetaModels().add(yieldStmtMetaModel.expressionPropertyMetaModel); @@ -1049,6 +1062,20 @@ private static void initializePropertyMetaModels() { jmlForallClauseMetaModel.getDeclaredPropertyMetaModels().add(jmlForallClauseMetaModel.boundedVariablesPropertyMetaModel); jmlOldClauseMetaModel.declarationsPropertyMetaModel = new PropertyMetaModel(jmlOldClauseMetaModel, "declarations", com.github.javaparser.ast.expr.VariableDeclarationExpr.class, Optional.of(variableDeclarationExprMetaModel), false, false, false, false); jmlOldClauseMetaModel.getDeclaredPropertyMetaModels().add(jmlOldClauseMetaModel.declarationsPropertyMetaModel); + jmlCallableClauseMetaModel.methodSignaturesPropertyMetaModel = new PropertyMetaModel(jmlCallableClauseMetaModel, "methodSignatures", com.github.javaparser.ast.jml.clauses.JmlMethodSignature.class, Optional.of(jmlMethodSignatureMetaModel), false, false, true, false); + jmlCallableClauseMetaModel.getDeclaredPropertyMetaModels().add(jmlCallableClauseMetaModel.methodSignaturesPropertyMetaModel); + jmlClauseIfMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(jmlClauseIfMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); + jmlClauseIfMetaModel.getDeclaredPropertyMetaModels().add(jmlClauseIfMetaModel.conditionPropertyMetaModel); + jmlClauseIfMetaModel.kindPropertyMetaModel = new PropertyMetaModel(jmlClauseIfMetaModel, "kind", com.github.javaparser.ast.jml.clauses.JmlClauseKind.class, Optional.empty(), false, false, false, false); + jmlClauseIfMetaModel.getDeclaredPropertyMetaModels().add(jmlClauseIfMetaModel.kindPropertyMetaModel); + jmlClauseIfMetaModel.thenPropertyMetaModel = new PropertyMetaModel(jmlClauseIfMetaModel, "then", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false); + jmlClauseIfMetaModel.getDeclaredPropertyMetaModels().add(jmlClauseIfMetaModel.thenPropertyMetaModel); + jmlMethodSignatureMetaModel.argumentTypesPropertyMetaModel = new PropertyMetaModel(jmlMethodSignatureMetaModel, "argumentTypes", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, true, false); + jmlMethodSignatureMetaModel.getDeclaredPropertyMetaModels().add(jmlMethodSignatureMetaModel.argumentTypesPropertyMetaModel); + jmlMethodSignatureMetaModel.namePropertyMetaModel = new PropertyMetaModel(jmlMethodSignatureMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false); + jmlMethodSignatureMetaModel.getDeclaredPropertyMetaModels().add(jmlMethodSignatureMetaModel.namePropertyMetaModel); + jmlMethodSignatureMetaModel.receiverPropertyMetaModel = new PropertyMetaModel(jmlMethodSignatureMetaModel, "receiver", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, false, false); + jmlMethodSignatureMetaModel.getDeclaredPropertyMetaModels().add(jmlMethodSignatureMetaModel.receiverPropertyMetaModel); jmlContractMetaModel.behaviorPropertyMetaModel = new PropertyMetaModel(jmlContractMetaModel, "behavior", com.github.javaparser.ast.stmt.Behavior.class, Optional.empty(), false, false, false, false); jmlContractMetaModel.getDeclaredPropertyMetaModels().add(jmlContractMetaModel.behaviorPropertyMetaModel); jmlContractMetaModel.clausesPropertyMetaModel = new PropertyMetaModel(jmlContractMetaModel, "clauses", com.github.javaparser.ast.jml.clauses.JmlClause.class, Optional.of(jmlClauseMetaModel), false, false, true, false); @@ -1533,6 +1560,12 @@ public static Optional getNodeMetaModel(Class c) { @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") public static final JmlCallableClauseMetaModel jmlCallableClauseMetaModel = new JmlCallableClauseMetaModel(Optional.of(jmlClauseMetaModel)); + @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") + public static final JmlClauseIfMetaModel jmlClauseIfMetaModel = new JmlClauseIfMetaModel(Optional.of(jmlClauseMetaModel)); + + @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") + public static final JmlMethodSignatureMetaModel jmlMethodSignatureMetaModel = new JmlMethodSignatureMetaModel(Optional.of(nodeMetaModel)); + @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") public static final JmlContractMetaModel jmlContractMetaModel = new JmlContractMetaModel(Optional.of(nodeMetaModel)); diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlCallableClauseMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlCallableClauseMetaModel.java index fa8133c40f..ac43883409 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlCallableClauseMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlCallableClauseMetaModel.java @@ -40,4 +40,6 @@ public class JmlCallableClauseMetaModel extends JmlClauseMetaModel { JmlCallableClauseMetaModel(Optional superBaseNodeMetaModel) { super(superBaseNodeMetaModel, JmlCallableClause.class, "JmlCallableClause", "com.github.javaparser.ast.jml.clauses", false, false); } + + public PropertyMetaModel methodSignaturesPropertyMetaModel; } diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlClauseIfMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlClauseIfMetaModel.java new file mode 100644 index 0000000000..0cf3038774 --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlClauseIfMetaModel.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2024 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +import com.github.javaparser.ast.jml.clauses.JmlClauseIf; +import com.github.javaparser.ast.Generated; + +/** + * This file, class, and its contents are completely generated based on: + *
    + *
  • The contents and annotations within the package `com.github.javaparser.ast`, and
  • + *
  • `ALL_NODE_CLASSES` within the class `com.github.javaparser.generator.metamodel.MetaModelGenerator`.
  • + *
+ *

+ * For this reason, any changes made directly to this file will be overwritten the next time generators are run. + */ +@Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") +public class JmlClauseIfMetaModel extends JmlClauseMetaModel { + + @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") + JmlClauseIfMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, JmlClauseIf.class, "JmlClauseIf", "com.github.javaparser.ast.jml.clauses", false, false); + } + + public PropertyMetaModel conditionPropertyMetaModel; + + public PropertyMetaModel kindPropertyMetaModel; + + public PropertyMetaModel thenPropertyMetaModel; +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlMethodSignatureMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlMethodSignatureMetaModel.java new file mode 100644 index 0000000000..3743f8a7fc --- /dev/null +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JmlMethodSignatureMetaModel.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007-2010 Júlio Vilmar Gesser. + * Copyright (C) 2011, 2013-2024 The JavaParser Team. + * + * This file is part of JavaParser. + * + * JavaParser can be used either under the terms of + * a) the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * b) the terms of the Apache License + * + * You should have received a copy of both licenses in LICENCE.LGPL and + * LICENCE.APACHE. Please refer to those files for details. + * + * JavaParser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ +package com.github.javaparser.metamodel; + +import java.util.Optional; + +import com.github.javaparser.ast.jml.clauses.JmlMethodSignature; +import com.github.javaparser.ast.Generated; + +/** + * This file, class, and its contents are completely generated based on: + *

    + *
  • The contents and annotations within the package `com.github.javaparser.ast`, and
  • + *
  • `ALL_NODE_CLASSES` within the class `com.github.javaparser.generator.metamodel.MetaModelGenerator`.
  • + *
+ *

+ * For this reason, any changes made directly to this file will be overwritten the next time generators are run. + */ +@Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") +public class JmlMethodSignatureMetaModel extends NodeMetaModel { + + @Generated("com.github.javaparser.generator.metamodel.NodeMetaModelGenerator") + JmlMethodSignatureMetaModel(Optional superBaseNodeMetaModel) { + super(superBaseNodeMetaModel, JmlMethodSignature.class, "JmlMethodSignature", "com.github.javaparser.ast.jml.clauses", false, false); + } + + public PropertyMetaModel argumentTypesPropertyMetaModel; + + public PropertyMetaModel namePropertyMetaModel; + + public PropertyMetaModel receiverPropertyMetaModel; +} diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java index c8ff905a18..4dc883da39 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java @@ -43,6 +43,8 @@ public class LambdaExprMetaModel extends ExpressionMetaModel { public PropertyMetaModel bodyPropertyMetaModel; + public PropertyMetaModel contractsPropertyMetaModel; + public PropertyMetaModel isEnclosingParametersPropertyMetaModel; public PropertyMetaModel parametersPropertyMetaModel; diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java index 458d70f7c6..03971e5116 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java @@ -105,8 +105,8 @@ 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 - concreteSyntaxModelByClass.// list(ObservableProperty.EXTRA_ARRAY_LEVELS), - put(VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER))))); + // list(ObservableProperty.EXTRA_ARRAY_LEVELS), + concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence(comment(), child(ObservableProperty.NAME), conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(), child(ObservableProperty.INITIALIZER))))); // / // / Expressions // / @@ -213,10 +213,10 @@ private static CsmElement typeArguments() { //space(), //space(), //space(), - concreteSyntaxModelByClass.//space(), - put(//space(), - JmlCallableClause.class, //child(EXPRESSION), - sequence(child(MODIFIERS), token(CALLABLE), semicolon())); + //space(), + //space(), + //child(EXPRESSION), + concreteSyntaxModelByClass.put(JmlCallableClause.class, sequence(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()); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java index 36f0f359f4..284d9a9042 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DefaultPrettyPrinterVisitor.java @@ -1161,6 +1161,20 @@ public void visit(JmlLabelStmt n, Void arg) { endJmlComment(); } + @Override + public void visit(JmlMethodSignature n, Void arg) { + printOrphanCommentsBeforeThisChildNode(n); + printComment(n.getComment(), arg); + n.getReceiver().ifPresent(it -> { + it.accept(this, arg); + printer.print("."); + }); + n.getName().accept(this, arg); + printer.print("("); + printList(n.getArgumentTypes(), ", "); + printer.print(")"); + } + @Override public void visit(final CharLiteralExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java index 792d8b9c4a..0c85464d55 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java @@ -905,6 +905,10 @@ public void visit(JmlEndStmt n, Void arg) { public void visit(JmlLabelStmt n, Void arg) { } + @Override + public void visit(JmlMethodSignature n, Void arg) { + } + @Override public void visit(final CharLiteralExpr n, final Void arg) { printOrphanCommentsBeforeThisChildNode(n); diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java index d532d6f930..e75f7c92c0 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java +++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java @@ -136,8 +136,8 @@ public void concretePropertyChange(Node observedNode, ObservableProperty propert // this case corresponds to the addition of a comment // Find the position of the comment node and put in front of it the [...] int // Find the position of the comment node and put in front of it the [...] - index = // - parentNode.isPresent() ? nodeText.findChild(observedNode) : 0; + // + index = parentNode.isPresent() ? nodeText.findChild(observedNode) : 0; /* Add the same indentation to the comment as the previous node * for example if we want to add a comment on the body of the method declaration : * Actual code diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java index ef52d0a053..918903cc32 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java @@ -65,8 +65,8 @@ public static Optional getFunctionalMethod(ResolvedReferenceTypeDec // Consider the case of Comparator which define equals. It would be considered a functional method. // TODO a functional interface can have multiple subsignature method with a return-type-substitutable // TODO a functional interface can have multiple subsignature method with a return-type-substitutable - methods = // TODO a functional interface can have multiple subsignature method with a return-type-substitutable - typeDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().isAbstract()).filter(m -> !isPublicMemberOfObject(m)).collect(Collectors.toSet()); + // TODO a functional interface can have multiple subsignature method with a return-type-substitutable + methods = typeDeclaration.getAllMethods().stream().filter(m -> m.getDeclaration().isAbstract()).filter(m -> !isPublicMemberOfObject(m)).collect(Collectors.toSet()); // see https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.8 if (methods.size() == 0) { return Optional.empty(); diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java index f1ab06d0ab..c7030805bd 100644 --- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java +++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java @@ -511,8 +511,8 @@ public static SymbolReference findMostApplicable(List // Filters out duplicate ResolvedMethodDeclaration by their signature. // Filters out duplicate ResolvedMethodDeclaration by their signature. // Checks if ResolvedMethodDeclaration is applicable to argumentsTypes. - applicableMethods = // Checks if ResolvedMethodDeclaration is applicable to argumentsTypes. - methods.stream().filter(m -> m.getName().equals(name)).filter(distinctByKey(ResolvedMethodDeclaration::getQualifiedSignature)).filter((m) -> isApplicable(m, name, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList()); + // Checks if ResolvedMethodDeclaration is applicable to argumentsTypes. + applicableMethods = methods.stream().filter(m -> m.getName().equals(name)).filter(distinctByKey(ResolvedMethodDeclaration::getQualifiedSignature)).filter((m) -> isApplicable(m, name, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList()); // If no applicable methods found, return as unsolved. if (applicableMethods.isEmpty()) { return SymbolReference.unsolved(); diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index 85d1d50447..8d8b3fdb4c 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -4,7 +4,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index 6d5136aea3..418024aca6 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -4,7 +4,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/jmlparser-jml-tests/pom.xml b/jmlparser-jml-tests/pom.xml index 6f243cb50f..ba1c058692 100644 --- a/jmlparser-jml-tests/pom.xml +++ b/jmlparser-jml-tests/pom.xml @@ -2,7 +2,7 @@ jmlparser-parent io.github.jmltoolkit - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 6cc599f999..3622395648 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ io.github.jmltoolkit jmlparser-parent pom - 3.25.10-SNAPSHOT + 3.25.10-b2-SNAPSHOT jmlparser-parent https://github.com/wadoon/jmlparser