SymbolTableCreatorDecorator extends AbstractCreator<ASTCDCompilationUnit, Optional<ASTCDClass>> { @Override public Optional<ASTCDClass> decorate(ASTCDCompilationUnit input) { Optional<String> startProd = symbolTableService.getStartProdASTFullName(input.getCDDefinition()); if (startProd.isPresent()) { String astFullName = startProd.get(); String symbolTableCreator = symbolTableService.getSymbolTableCreatorSimpleName(); String visitorName = visitorService.getVisitorFullName(); String scopeInterface = symbolTableService.getScopeInterfaceFullName(); String symTabMillFullName = symbolTableService.getMillFullName(); ASTMCBasicGenericType dequeType = getMCTypeFacade().createBasicGenericTypeOf(DEQUE_TYPE, scopeInterface); ASTMCWildcardTypeArgument wildCardTypeArgument = getMCTypeFacade().createWildCardWithUpperBoundType(scopeInterface); ASTMCBasicGenericType dequeWildcardType = getMCTypeFacade().createBasicGenericTypeOf(DEQUE_TYPE, wildCardTypeArgument); String simpleName = symbolTableService.removeASTPrefix(Names.getSimpleName(startProd.get())); List<ASTCDType> symbolDefiningClasses = symbolTableService.getSymbolDefiningProds(input.getCDDefinition().getCDClassList()); Map<ASTCDClass, String> inheritedSymbolPropertyClasses = symbolTableService.getInheritedSymbolPropertyClasses(input.getCDDefinition().getCDClassList()); List<ASTCDType> noSymbolDefiningClasses = symbolTableService.getNoSymbolAndScopeDefiningClasses(input.getCDDefinition().getCDClassList()); List<ASTCDType> symbolDefiningProds = symbolTableService.getSymbolDefiningProds(input.getCDDefinition()); List<ASTCDType> onlyScopeProds = symbolTableService.getOnlyScopeClasses(input.getCDDefinition()); ASTCDAttribute realThisAttribute = createRealThisAttribute(visitorName); List<ASTCDMethod> realThisMethods = methodDecorator.decorate(realThisAttribute); ASTCDAttribute firstCreatedScopeAttribute = createFirstCreatedScopeAttribute(scopeInterface); List<ASTCDMethod> firstCreatedScopeMethod = methodDecorator.getAccessorDecorator().decorate(firstCreatedScopeAttribute); ASTCDClass symTabCreator = CD4CodeMill.cDClassBuilder() .setName(symbolTableCreator) .setModifier(PUBLIC.build()) .addInterface(getMCTypeFacade().createQualifiedType(visitorName)) .addCDConstructor(createSimpleConstructor(symbolTableCreator, scopeInterface)) .addCDConstructor(createDequeConstructor(symbolTableCreator, dequeWildcardType, dequeType)) .addCDAttribute(createScopeStackAttribute(dequeType)) .addCDAttribute(realThisAttribute) .addAllCDMethods(realThisMethods) .addCDAttribute(firstCreatedScopeAttribute) .addAllCDMethods(firstCreatedScopeMethod) .addCDMethod(createCreateFromASTMethod(astFullName, symbolTableCreator, symTabMillFullName)) .addCDMethod(createPutOnStackMethod(scopeInterface)) .addAllCDMethods(createCurrentScopeMethods(scopeInterface)) .addCDMethod(createSetScopeStackMethod(dequeType, simpleName)) .addCDMethod(createCreateScopeMethod(scopeInterface, input.getCDDefinition().getName())) .addAllCDMethods(createSymbolClassMethods(symbolDefiningClasses, scopeInterface)) .addAllCDMethods(createSymbolClassMethods(inheritedSymbolPropertyClasses, scopeInterface)) .addAllCDMethods(createVisitForNoSymbolMethods(noSymbolDefiningClasses)) .addAllCDMethods(createAddToScopeMethods(symbolDefiningProds)) .addAllCDMethods(createAddToScopeMethodsForSuperSymbols()) .addAllCDMethods(createScopeClassMethods(onlyScopeProds, scopeInterface)) .build(); return Optional.ofNullable(symTabCreator); } return Optional.empty(); } SymbolTableCreatorDecorator(final GlobalExtensionManagement glex,
                                     final SymbolTableService symbolTableService,
                                     final VisitorService visitorService,
                                     final MethodDecorator methodDecorator); @Override Optional<ASTCDClass> decorate(ASTCDCompilationUnit input);  }
@Test public void testNoStartProd() { LogStub.init(); GlobalExtensionManagement glex = new GlobalExtensionManagement(); glex.setGlobalValue("astHelper", DecorationHelper.getInstance()); glex.setGlobalValue("cdPrinter", new CD4CodePrinter()); ASTCDCompilationUnit cd = this.parse("de", "monticore", "codegen", "symboltable", "Automaton"); glex.setGlobalValue("service", new AbstractService(cd)); SymbolTableService mockService = Mockito.spy(new SymbolTableService(cd)); Mockito.doReturn(Optional.empty()).when(mockService).getStartProdASTFullName(Mockito.any(ASTCDDefinition.class)); SymbolTableCreatorDecorator decorator = new SymbolTableCreatorDecorator(glex, mockService, new VisitorService(cd), new MethodDecorator(glex, new SymbolTableService(decoratedCompilationUnit))); Optional<ASTCDClass> optSymTabCreator = decorator.decorate(cd); assertFalse(optSymTabCreator.isPresent()); }