Clean up the Java AST: Avoid sub-classes in favor of Enum - #3803
Conversation
297144d to
170d60f
Compare
40cf2db to
73ee6c3
Compare
ebe3518 to
e16d713
Compare
f77432f to
719bcf3
Compare
6f09014 to
1c217f9
Compare
25a749a to
498bb59
Compare
498bb59 to
81fa5b7
Compare
|
I tried to fix some of the NPEs. The visibility modifier package private is being modelled as 'null', hence checking if inheritance is allowed threw NPEs. There seem (some pre-existing) inconsistencies. I grouped all vis changes in 796c1f0 for checking |
|
The matching works now for the new AST and I hand the branch back to you. |
0da864b to
b8a4799
Compare
There was a problem hiding this comment.
Not necessary something to change, but please check:
The only issue I still see is that there are now two visibility modelings for "package private"
- 'null' for the Java side
- 'JML_PACKAGE' for the JML side
The different representations mean that one has to consider both when checking visibility properties. The 'moreRestrictive' implementation needed by RepresentsAxiom is therefore not symmetric.
Did not find a better way around. In any case the behavior should be now as for main.
A more unified solution would be to either have just one PACKAGE modifier used by both or the JML_PACKAGE modifier to be discarded and the annotated elements get as visibility modifier null (like in main). In any case, what and how to do (if anything), you are the better one to judge. Also with respect to jmltoolkit and preparations for that.
In any case thanks a lot and I approved but disabled auto-merge, so you can look at it first (as said one can leave it as it is, but it has this kind of asymmetry).
…for program elements that have a kind)
… traversal in equals methods (super.eausl already traverses the children)
1b8cd31 to
3fafbfd
Compare
But there is also a difference between specifying package-private and not specifying it syntactically. What is the default modifier for contracts? Does it not follow the visibility of the method? |
Java AST Enum Refactoring
Overview
This PR performs a major refactoring of the Java AST structure by converting
ModifierandOperatorclasses from individual class-based implementations to enum-based representations. This change significantly reduces code complexity and improves maintainability.Key Changes
1. Modifier Refactoring
ModifierKindenum (ModifierKind.java) - Centralizes all modifier kinds as enum constantsAbstract,Final,Ghost,Model,Native,NoState,Private,Protected,Public,Static,StrictFp,Synchronized,Transient,TwoState,VolatileAnnotationUseSpecification,Modifiers,VisibilityModifierModifierclass now usesModifierKindenum instead of subclassing2. Operator Refactoring
New: Operator kind enums:
BinaryOperatorKind.java- All binary operator typesUnaryOperatorKind.java- All unary operator typesAssignmentKind.java- All assignment operator typesLogicFunctionalOperator.java- New interface for logical/functional operatorsNew: Assignment hierarchy:
UnaryAssignment.java- Interface for unary assignments (++, --)BinaryAssignment.java- Class for binary assignments (+=, -=, etc.)Removed: Individual operator classes (~60 files):
BinaryAnd,BinaryOr,BinaryXOr,BinaryNot,Divide,Equals,GreaterThan,GreaterOrEquals,LessThan,LessOrEquals,LogicalAnd,LogicalOr,Minus,Modulo,Plus,Times, etc.BinaryAndAssignment,BinaryOrAssignment,BinaryXOrAssignment,DivideAssignment,MinusAssignment,ModuloAssignment,PlusAssignment,ShiftLeftAssignment,ShiftRightAssignment,TimesAssignment, etc.Negative,Positive,LogicalNot,PostIncrement,PostDecrement,PreIncrement,PreDecrement,ShiftLeft,ShiftRight,UnsignedShiftRight, etc.AllFields,AllObjects,SeqConcat,SeqGet,SeqIndexOf,SeqLength,SeqPut,SeqReverse,SeqSingleton,SeqSub,SetMinus,SetUnion,Singleton, etc.Updated:
BinaryOperator.java- Now usesBinaryOperatorKindenumUnaryOperator.java- Now usesUnaryOperatorKindenum, removedExpressionStatementparentAssignment.java- Refactored to use new kind system3. Performance Improvements
equals()methods (super.equals() already traverses children)4. Bug Fixes
LocSetLDTandSeqLDTinconsistencies inresponsibleFor/getFunctionForJavaASTVisitorimplementationsCreatingASTVisitorissues5. Cleanups
StrategyPresetsSettingsand related UI componentsIsBoundedByInequationFeatureandRelevantSequentFormulasGeneratorImpact Statistics
Files Modified
Core AST Changes
KeYJavaASTFactory.java- Major refactoring (-1002 lines)Modifier.java,ModifierKind.java(new)BinaryOperator.java,UnaryOperator.java,Assignment.javaBinaryOperatorKind.java(new),UnaryOperatorKind.java(new),AssignmentKind.java(new)BinaryAssignment.java(new),UnaryAssignment.java(new)Visitor Updates
CreatingASTVisitor.java- Updated for new AST structure (-520 lines)JavaASTVisitor.java- Updated visitor interface (-322 lines)Visitor.java- Updated base visitorPrettyPrinter.java- Updated printing logic (-354 lines)Related Components
JP2KeYConverter.java- Updated for new operator/modifier structureTypeConverter.java- Updated type conversionsJavaInfo.java,JavaService.java- Updated servicesLocSetLDT,SeqLDT,FloatLDT,DoubleLDT,SortLDTUI Changes
StrategySelectionView.java- Removed strategy presets UI (-593 lines)MainWindow.java- Minor updatesIconFactory.java- Updated iconsTesting
JavaMatchingTests.java(442 lines)Migration Notes
For developers:
Modifier.kind()instead ofinstanceofchecksUnaryAssignmentandBinaryAssignmentRelated Issues
Checklist