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

org.jannocessor.adapter.structure.AbstractJavaStructureAdapter Maven / Gradle / Ivy

There is a newer version: 0.7.4
Show newest version
/**
 * Copyright 2011 Nikolche Mihajlovski
 *
 * This file is part of JAnnocessor.
 *
 * JAnnocessor is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JAnnocessor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JAnnocessor.  If not, see .
 */

package org.jannocessor.adapter.structure;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;

import org.jannocessor.adapter.JavaElementAdapter;
import org.jannocessor.collection.Power;
import org.jannocessor.collection.api.PowerList;
import org.jannocessor.model.Name;
import org.jannocessor.model.executable.JavaMethod;
import org.jannocessor.model.structure.AbstractJavaStructure;
import org.jannocessor.model.structure.JavaMetadata;
import org.jannocessor.model.structure.JavaNestedAnnotation;
import org.jannocessor.model.structure.JavaNestedClass;
import org.jannocessor.model.structure.JavaNestedEnum;
import org.jannocessor.model.structure.JavaNestedInterface;
import org.jannocessor.model.type.JavaType;

abstract class AbstractJavaStructureAdapter extends JavaElementAdapter
		implements AbstractJavaStructure {

	private static final long serialVersionUID = -1171708337294305207L;
	private final TypeElement type;

	public AbstractJavaStructureAdapter(TypeElement type,
			Elements elementUtils, Types typeUtils) {
		super(type, elementUtils, typeUtils);
		this.type = type;
	}

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

	@Override
	public Name getQualifiedName() {
		return getNameAdapter(type.getQualifiedName().toString());
	}

	@Override
	public JavaType getSuperclass() {
		return getTypeAdapter(type.getSuperclass());
	}

	@Override
	public PowerList getMetadata() {
		return getAnnotatedMetadata();
	}

	@Override
	public PowerList getAllMetadata() {
		PowerList results = Power.list();

		for (AnnotationMirror annotationMirror : getElementUtils()
				.getAllAnnotationMirrors(type)) {
			results.add(getMetadataAdapter(annotationMirror));
		}

		return results;
	}

	@Override
	public PowerList getInterfaces() {
		PowerList adapters = Power.list();

		for (TypeMirror tinterface : type.getInterfaces()) {
			adapters.add(getTypeAdapter(tinterface));
		}

		return adapters;
	}

	@Override
	public PowerList getMethods() {
		return findChildrenByType(JavaMethod.class);
	}

	@Override
	public PowerList getNestedClasses() {
		return findChildrenByType(JavaNestedClass.class);
	}

	@Override
	public PowerList getNestedEnums() {
		return findChildrenByType(JavaNestedEnum.class);
	}

	@Override
	public PowerList getNestedInterfaces() {
		return findChildrenByType(JavaNestedInterface.class);
	}

	@Override
	public PowerList getNestedAnnotations() {
		return findChildrenByType(JavaNestedAnnotation.class);
	}

	@Override
	protected Class getAdaptedInterface() {
		return AbstractJavaStructure.class;
	}

	@Override
	public AbstractJavaStructure copy() {
		throw calculatedMethodException();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy