Search in sources :

Example 1 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsModuleGeneratedObjectFactoryTest method parseGeneratedFile.

private void parseGeneratedFile(ModuleMXBeanEntry moduleMXBeanEntry) throws IOException {
    Optional<String> copyright = Optional.absent();
    GeneratedObject generatedObject = new AbsModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright);
    Entry<FullyQualifiedName, File> entry = generatedObject.persist(generatorOutputPath).get();
    File dstFile = entry.getValue();
    parse(dstFile);
}
Also used : FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) AbsModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory) File(java.io.File)

Example 2 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class ConcreteModuleGeneratedObjectFactoryTest method test.

@Test
public void test() throws Exception {
    FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
    FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
    String nullableDescription = null;
    ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
    Optional<String> copyright = Optional.absent();
    Optional<String> header = Optional.absent();
    GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
    Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
    File dstFile = entry.getValue();
    Node c = parse(dstFile);
    assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
    assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
    assertHasMethodNamed(c, "customValidation");
    assertHasMethodNamed(c, "createInstance");
}
Also used : ConcreteModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Node(net.sourceforge.pmd.lang.ast.Node) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) File(java.io.File) AbstractGeneratedObjectTest(org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest) Test(org.junit.Test)

Example 3 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsFactoryGeneratedObjectFactory method getServiceIfcsInitialization.

private static String getServiceIfcsInitialization(List<FullyQualifiedName> providedServices) {
    String generic = format("Class<? extends %s>", AbstractServiceInterface.class.getCanonicalName());
    StringBuilder result = new StringBuilder("static {\n");
    if (!providedServices.isEmpty()) {
        result.append(format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<>();\n", generic));
        for (FullyQualifiedName fqn : providedServices) {
            result.append(format("serviceIfcs2.add(%s.class);\n", fqn));
        }
        result.append("serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);\n");
    } else {
        result.append("serviceIfcs = java.util.Collections.emptySet();\n");
    }
    result.append("}\n");
    // add isModuleImplementingServiceInterface and getImplementedServiceIntefaces methods
    result.append(format("\n" + "@Override\n" + "public final boolean isModuleImplementingServiceInterface(Class<? extends %1$s> serviceInterface) " + "{\n" + "for (Class<?> ifc: serviceIfcs) {\n" + "if (serviceInterface.isAssignableFrom(ifc)){\n" + "return true;\n" + "}\n" + "}\n" + "return false;\n" + "}\n" + "\n" + "@Override\n" + "public java.util.Set<Class<? extends %1$s>> getImplementedServiceIntefaces() {\n" + "return serviceIfcs;\n" + "}\n", AbstractServiceInterface.class.getCanonicalName()));
    return result.toString();
}
Also used : FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) AbstractServiceInterface(org.opendaylight.controller.config.api.annotations.AbstractServiceInterface)

Example 4 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsModuleGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(FullyQualifiedName abstractFQN, Optional<String> copyright, Optional<String> header, Optional<String> classJavaDoc, Optional<FullyQualifiedName> extended, List<FullyQualifiedName> implementedInterfaces, List<ModuleField> moduleFields, Optional<FullyQualifiedName> maybeRegistratorType, List<? extends Method> methods, QName yangModuleQName) {
    JavaFileInputBuilder b = new JavaFileInputBuilder();
    Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName);
    b.addClassAnnotation(moduleQNameAnnotation);
    b.setFqn(abstractFQN);
    b.setTypeName(TypeName.absClassType);
    b.setCopyright(copyright);
    b.setHeader(header);
    b.setClassJavaDoc(classJavaDoc);
    for (FullyQualifiedName implemented : implementedInterfaces) {
        b.addImplementsFQN(implemented);
    }
    if (extended.isPresent()) {
        b.addExtendsFQN(extended.get());
    }
    if (classJavaDoc.isPresent()) {
        b.addClassAnnotation(format("@%s(value=\"%s\")", Description.class.getCanonicalName(), classJavaDoc.get()));
    }
    // add logger:
    b.addToBody(getLoggerDefinition(abstractFQN));
    b.addToBody("//attributes start");
    for (ModuleField moduleField : moduleFields) {
        b.addToBody(moduleField.toString() + "\n");
    }
    b.addToBody("//attributes end");
    b.addToBody(getNewConstructor(abstractFQN));
    b.addToBody(getCopyFromOldConstructor(abstractFQN));
    b.addToBody(getRuntimeRegistratorCode(maybeRegistratorType));
    b.addToBody(getValidationMethods(moduleFields));
    b.addToBody(getCachesOfResolvedDependencies(moduleFields));
    b.addToBody(getCachesOfResolvedIdentityRefs(moduleFields));
    b.addToBody(getResolveDependencies(moduleFields));
    b.addToBody(getReuseLogic(moduleFields, abstractFQN));
    b.addToBody(getEqualsAndHashCode(abstractFQN));
    b.addToBody(getMethods(methods));
    b.addToBody(getGetLogger());
    return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
Also used : ModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField) IdentityRefModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField) GeneratedObjectBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) Annotation(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation) JavaFileInputBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)

Example 5 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsFactoryGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
    FullyQualifiedName absFactoryFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractFactoryName());
    FullyQualifiedName moduleFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getStubModuleName());
    Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription());
    AbstractFactoryTemplate abstractFactoryTemplate = TemplateFactory.abstractFactoryTemplateFromMbe(mbe);
    Optional<String> header = abstractFactoryTemplate.getHeaderString();
    List<FullyQualifiedName> providedServices = new ArrayList<>();
    for (String providedService : mbe.getProvidedServices().keySet()) {
        providedServices.add(FullyQualifiedName.fromString(providedService));
    }
    return toGeneratedObject(absFactoryFQN, copyright, header, classJavaDoc, mbe.getYangModuleQName(), mbe.getGloballyUniqueName(), providedServices, moduleFQN, abstractFactoryTemplate.getFields());
}
Also used : AbstractFactoryTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractFactoryTemplate) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) ArrayList(java.util.ArrayList)

Aggregations

FullyQualifiedName (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)9 Annotation (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation)3 GeneratedObjectBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder)3 JavaFileInputBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)3 File (java.io.File)2 GeneratedObject (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject)2 ArrayList (java.util.ArrayList)1 Node (net.sourceforge.pmd.lang.ast.Node)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 Test (org.junit.Test)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 AbstractServiceInterface (org.opendaylight.controller.config.api.annotations.AbstractServiceInterface)1 Module (org.opendaylight.controller.config.spi.Module)1 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)1 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)1 AbstractFactoryTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractFactoryTemplate)1 AbstractModuleTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractModuleTemplate)1 Constructor (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1 IdentityRefModuleField (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField)1