Add unit tests for the LSP code actions (AddBehaviorKeyword, AddNameToClauseOrContract,
AddQuantification, AddStubs, CreateKeyProjectFile, VerifyAgainstParent,
WellDefinednessCheck, GsonHelper, LspAction defaults), the CodeActionCollector,
and the JML/KeY symbol providers. Tests parse JML sources directly via a shared
JmlTestSupport helper and exercise symbol collection over classes, interfaces,
enums, annotations, workspace fixtures and a minimal KeY rule file.
The new tests exposed several bugs in the code under test, all fixed here:
- AddBehaviorKeyword offered the action when the contract already carried a
behavior keyword (inverted condition); now it is offered only when the
contract has no keyword or JmlBehaviorKeyword.NONE.
- CodeActionCollector.collect applied the root node instead of each walked
node (callback captured the root), so only the document root ever produced
actions.
- WellDefinednessCheck.isCallableForNode compared nodes against Class objects
via `when`, which is always false; switched to `is` type checks.
- AddStubs.createCodeLens cast TypeDeclaration to NodeWithName, which the
type hierarchy does not implement (NodeWithSimpleName instead); the command
is now built from the declaration's own name range.
- VerifyAgainstParent returned an action for every node; now gated on
JmlContract.
- JmlCatchSymbols dropped enum constants (entries vs members).
- KeyCatchSymbols' ANTLR visitor NPE'd on files with functions/predicates/
rules (unoverridden leaf productions); added visitFunc_decl, visitPred_decls,
visitPred_decl, visitTaclet and a safe visitSchema_var_decls.
LSP test suite grows from 17 to 53 tests (0 failures) and instruction coverage
for :tools:lsp rises from 39.6% to 61.6% (lines 41.6% to 64.3%).
Summary
Improvements to the JML parser/AST in
javaparser-coreand to the jmltk LSP server (tools/lsp), with follow-up updates across thelint,stat,redux,jmlstub, andutilstools.JavaParser / JML AST (
javaparser-core)JmlKeywordNode(implementsJmlish) carries keyword values modelled by theJmlKeywordinterface (jmlSymbol()/asString()):JmlContractBehaviorholds the behavior keyword introducing a contract (behavior,normal_behavior,exceptional_behavior,model_behavior,break/continue/return/abrupt_behavior, …), resolving from the parsed token incl. British spellings (*_behaviour) andfeasible_behavior→behavior.JmlClauseKind(wrappingJmlClauseKeyword, e.g.requires/ensures/assignable/signals/forall) andJmlBodyClauseKind(wrappingJmlBodyClauseKeyword, e.g.invariant/constraint/axiom/initially). This gives every keyword a token range, which the LSP uses for document symbols and code actions.com.github.javaparser.ast.stmt.Behavioris removed;JmlContractnow stores aJmlContractBehaviornode ornullinstead ofBehavior.NONEfor contracts without a behavior keyword.JmlContract.getBehavior()returnsOptional<JmlContractBehavior>,behavior()is now@Nullable.JmlClausesubclasses no longer keep their ownkindfield; the keyword node is a regular child (getKind()returns theJmlClauseKind/JmlBodyClauseKindnode), so child-node counts of clauses change by one.abrupt_behaviornow maps to its ownJmlBehaviorKeyword.ABRUPTinstead of being folded intoBREAK.Node.associatedSpecificationCommentsandObservableProperty.ASSOCIATED_SPECIFICATION_COMMENTSare removed (the parser never populated them).Node.treeIteratoris now public.java.jj): clause productions forforall,signals,signals_onlyand the behavior productions now build the keyword nodes; loop/model contracts passnullbehavior where none is present.BlockStatementlookahead for variable declarations was rewritten toModifiers() Type() Identifier() (ArrayBracketPair())* ("," | "=" | ";"), so a syntactic lookahead no longer swallows the parse error. Malformed declarations such asint i = ;are now reported at the offending token instead of the statement start (regression testVariableDeclarationErrorPositionTest, jmltk#71).JavaParserMetaModel, visitors, and pretty-printers (DefaultPrettyPrinterVisitor,PrettyPrintVisitor,ConcreteSyntaxModel— the keyword nodes print theirvaluesymbol).JmlContainer,NodeWithContracts,HasJmlTags, …); metamodel generator registers the new node types and drops dead commented-out entries.DefaultVisitorAdapterhandles the new keyword nodes) and lexical-preservation test fix (Issue2620Test).LSP server (
tools/lsp)LspActioninterface discovered viaServiceLoader(registered inMETA-INF/services), supporting both client-applied snippet edits (SnippetTextEdit) and server commands.AddBehaviorKeyword— inserts a missing behavior keyword before a contract (snippet with choices).AddNameToClauseOrContract— insertsname:labels for unnamed contracts, clauses and class-level declarations.AddQuantification— wraps a JML expression around the cursor into(\forall <type> <name>; …).AddStubs— code lens on types (stub generation, still to be implemented).WellDefinednessCheck,VerifyAgainstParent,CreateKeyProjectFile(now writesproject.keyinto the workspace root);StartKeyremoved.JmlCatchSymbols(contracts, clauses, JML fields/represents/accessible declarations) andKeyCatchSymbols(function declarations, predicates, schema variables, taclets).Launcherconstruction with executor service, message validation, new--trace [-|file]option,tcpNoDelay+keepAliveon sockets (stdio/server/client modes).**/*.{jml,java}and**/*.key.doc.md(JML clause reference), newsol.md(KeY sol-terms reference); addedeglot.elfor editor testing.Other tools
lint: rules adapted to the keyword nodes (AllowedJmlClauses,AssignableValidator,ResultVarCheck);ContextSensitiveForbiddenFunctionsValidatormoved to theio.github.jmltoolkit.lint.rulespackage (service registration updated).stat:StatVisitor/Statistics/StatisticKeysuse the renamed keyword nodes.redux:RecordClassBuilderbuildsJmlBodyClauseKindnodes for the generatedequals/hashCodeinvariants.jmlstub:JREClassStubGeneratoremitsJmlContractBehavior/JmlBehaviorKeyword.utils: newJMLUtils.isInJML,findTopMostAncestor[Consecutive], andHelper.findAllhelpers.Tests
VariableDeclarationErrorPositionTest(grammar error positions),CodeActionsUnitTest(all new actions + collector defaults),JmlCatchSymbolsTest,KeyCatchSymbolsTest,CodeActionCollectorTest.JKIssue(clauses now carry the keyword node as child),JmlLambdaExprTests,JmlStatisticsReporterTest.Known limitations
WellDefinednessCheckandAddStubsare advertised but not yet implemented (executing them reports "not yet implemented"); the snippet insertion ofAddBehaviorKeywordstill needs polishing.