All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sundr.examples.codegen.JavaClazz Maven / Gradle / Ivy

There is a newer version: 1.14.0
Show newest version
/*
 * Copyright 2015 The original authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package io.sundr.examples.codegen;

import io.sundr.builder.annotations.Buildable;
import io.sundr.codegen.Clazz;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class JavaClazz extends AttributeSupport implements Clazz {

    private final JavaType type;
    private final Set annotations;
    private final Set methods;
    private final Set constructors;
    private final Set fields;
    private final Set imports;
    private final Set nested;

    @Buildable
    public JavaClazz(JavaType type, Set annotations, Set constructors, Set methods, Set fields, Set imports, Map attributes, Set nested) {
        super(attributes);
        this.type = type;
        this.annotations = annotations;
        this.methods = methods;
        this.constructors = constructors;
        this.fields = fields;
        this.imports = imports;
        this.nested = nested;
    }

    public Set getAnnotations() {
        return annotations;
    }

    private Set getReferencedTypes() {
        return Collections.emptySet();
    }

    public Set getConstructors() {
        return constructors;
    }

    @Override
    public JavaType getType() {
        return type;
    }

    @Override
    public Set getMethods() {
        return methods;
    }

    @Override
    public Set getFields() {
        return fields;
    }

    @Override
    public Set getImports() {
        Set result = new CopyOnWriteArraySet();
        Set tmp = new CopyOnWriteArraySet();
        tmp.addAll(this.imports);
        tmp.addAll(getReferencedTypes());

        for (JavaType t : tmp) {
            if (t.getClassName().equals(getType().getClassName())) {
                continue;
            } else if (t.getPackageName() == null) {
                continue;
            } else if (t.getPackageName().equals("java.lang")) {
                continue;
            } else if (!t.getPackageName().equals(getType().getPackageName())) {
                result.add(t);
            }
        }
        return result;
    }

    public Set getNested() {
        return nested;
    }

    @Override
    public String toString() {
        return type.getClassName();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy