@Test public void testSuperClassHandleMethods() { LogStub.init(); LogStub.enableFailQuick(false); GlobalExtensionManagement glex = new GlobalExtensionManagement(); ASTCDCompilationUnit decoratedCompilationUnit = this.parse("de", "monticore", "codegen", "_ast_emf", "Automata"); glex.setGlobalValue("service", new VisitorService(decoratedCompilationUnit)); VisitorService visitorService = new VisitorService(decoratedCompilationUnit); SymbolTableService symbolTableService = new SymbolTableService(decoratedCompilationUnit); InheritanceVisitorDecorator decorator = new InheritanceVisitorDecorator(this.glex, visitorService, symbolTableService); ASTCDInterface visitorInterface = decorator.decorate(decoratedCompilationUnit); assertEquals(11, visitorInterface.sizeCDMethods()); List<ASTCDMethod> handleMethods = getMethodsBy("handle", 1, visitorInterface); ASTMCType astType = this.mcTypeFacade.createQualifiedType("de.monticore.codegen._ast_emf.automata._ast.ASTTransitionWithAction"); assertTrue(handleMethods.stream().anyMatch(m -> astType.deepEquals(m.getCDParameter(0).getMCType()))); assertEquals(1, handleMethods.stream().filter(m -> astType.deepEquals(m.getCDParameter(0).getMCType())).count()); ASTCDMethod method = handleMethods.stream().filter(m -> astType.deepEquals(m.getCDParameter(0).getMCType())).findFirst().get(); assertDeepEquals(PUBLIC, method.getModifier()); assertTrue(method.getMCReturnType().isPresentMCVoidType()); }
@Override public ASTCDInterface decorate(ASTCDCompilationUnit input) { ASTCDDefinition cdDefinition = input.deepClone().getCDDefinition(); ASTCDCompilationUnit compilationUnit = visitorService.calculateCDTypeNamesWithASTPackage(input); String languageInterfaceName = visitorService.getLanguageInterfaceName(); String visitorSimpleTypeName = visitorService.getVisitorSimpleName(); return CD4CodeMill.cDInterfaceBuilder() .setName(visitorService.getInheritanceVisitorSimpleName()) .setModifier(PUBLIC.build()) .addInterface(visitorService.getVisitorType()) .addAllInterface(visitorService.getSuperInheritanceVisitors()) .addAllCDMethods(getASTHandleMethods(compilationUnit.getCDDefinition(), visitorSimpleTypeName, languageInterfaceName)) .addAllCDMethods(getScopeHandleMethods(cdDefinition, visitorSimpleTypeName)) .addAllCDMethods(getSymbolHandleMethods(cdDefinition, visitorSimpleTypeName)) .build(); }
InheritanceVisitorDecorator extends AbstractCreator<ASTCDCompilationUnit, ASTCDInterface> { @Override public ASTCDInterface decorate(ASTCDCompilationUnit input) { ASTCDDefinition cdDefinition = input.deepClone().getCDDefinition(); ASTCDCompilationUnit compilationUnit = visitorService.calculateCDTypeNamesWithASTPackage(input); String languageInterfaceName = visitorService.getLanguageInterfaceName(); String visitorSimpleTypeName = visitorService.getVisitorSimpleName(); return CD4CodeMill.cDInterfaceBuilder() .setName(visitorService.getInheritanceVisitorSimpleName()) .setModifier(PUBLIC.build()) .addInterface(visitorService.getVisitorType()) .addAllInterface(visitorService.getSuperInheritanceVisitors()) .addAllCDMethods(getASTHandleMethods(compilationUnit.getCDDefinition(), visitorSimpleTypeName, languageInterfaceName)) .addAllCDMethods(getScopeHandleMethods(cdDefinition, visitorSimpleTypeName)) .addAllCDMethods(getSymbolHandleMethods(cdDefinition, visitorSimpleTypeName)) .build(); } }
InheritanceVisitorDecorator extends AbstractCreator<ASTCDCompilationUnit, ASTCDInterface> { @Override public ASTCDInterface decorate(ASTCDCompilationUnit input) { ASTCDDefinition cdDefinition = input.deepClone().getCDDefinition(); ASTCDCompilationUnit compilationUnit = visitorService.calculateCDTypeNamesWithASTPackage(input); String languageInterfaceName = visitorService.getLanguageInterfaceName(); String visitorSimpleTypeName = visitorService.getVisitorSimpleName(); return CD4CodeMill.cDInterfaceBuilder() .setName(visitorService.getInheritanceVisitorSimpleName()) .setModifier(PUBLIC.build()) .addInterface(visitorService.getVisitorType()) .addAllInterface(visitorService.getSuperInheritanceVisitors()) .addAllCDMethods(getASTHandleMethods(compilationUnit.getCDDefinition(), visitorSimpleTypeName, languageInterfaceName)) .addAllCDMethods(getScopeHandleMethods(cdDefinition, visitorSimpleTypeName)) .addAllCDMethods(getSymbolHandleMethods(cdDefinition, visitorSimpleTypeName)) .build(); } InheritanceVisitorDecorator(final GlobalExtensionManagement glex,
                                     final VisitorService visitorService,
                                     final SymbolTableService symbolTableService); }
InheritanceVisitorDecorator extends AbstractCreator<ASTCDCompilationUnit, ASTCDInterface> { @Override public ASTCDInterface decorate(ASTCDCompilationUnit input) { ASTCDDefinition cdDefinition = input.deepClone().getCDDefinition(); ASTCDCompilationUnit compilationUnit = visitorService.calculateCDTypeNamesWithASTPackage(input); String languageInterfaceName = visitorService.getLanguageInterfaceName(); String visitorSimpleTypeName = visitorService.getVisitorSimpleName(); return CD4CodeMill.cDInterfaceBuilder() .setName(visitorService.getInheritanceVisitorSimpleName()) .setModifier(PUBLIC.build()) .addInterface(visitorService.getVisitorType()) .addAllInterface(visitorService.getSuperInheritanceVisitors()) .addAllCDMethods(getASTHandleMethods(compilationUnit.getCDDefinition(), visitorSimpleTypeName, languageInterfaceName)) .addAllCDMethods(getScopeHandleMethods(cdDefinition, visitorSimpleTypeName)) .addAllCDMethods(getSymbolHandleMethods(cdDefinition, visitorSimpleTypeName)) .build(); } InheritanceVisitorDecorator(final GlobalExtensionManagement glex,
                                     final VisitorService visitorService,
                                     final SymbolTableService symbolTableService); @Override ASTCDInterface decorate(ASTCDCompilationUnit input); }
InheritanceVisitorDecorator extends AbstractCreator<ASTCDCompilationUnit, ASTCDInterface> { @Override public ASTCDInterface decorate(ASTCDCompilationUnit input) { ASTCDDefinition cdDefinition = input.deepClone().getCDDefinition(); ASTCDCompilationUnit compilationUnit = visitorService.calculateCDTypeNamesWithASTPackage(input); String languageInterfaceName = visitorService.getLanguageInterfaceName(); String visitorSimpleTypeName = visitorService.getVisitorSimpleName(); return CD4CodeMill.cDInterfaceBuilder() .setName(visitorService.getInheritanceVisitorSimpleName()) .setModifier(PUBLIC.build()) .addInterface(visitorService.getVisitorType()) .addAllInterface(visitorService.getSuperInheritanceVisitors()) .addAllCDMethods(getASTHandleMethods(compilationUnit.getCDDefinition(), visitorSimpleTypeName, languageInterfaceName)) .addAllCDMethods(getScopeHandleMethods(cdDefinition, visitorSimpleTypeName)) .addAllCDMethods(getSymbolHandleMethods(cdDefinition, visitorSimpleTypeName)) .build(); } InheritanceVisitorDecorator(final GlobalExtensionManagement glex,
                                     final VisitorService visitorService,
                                     final SymbolTableService symbolTableService); @Override ASTCDInterface decorate(ASTCDCompilationUnit input);  }