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

cc.catalysts.cdoclet.handler.ClassHandler Maven / Gradle / Ivy

package cc.catalysts.cdoclet.handler;

import java.util.Map;
import java.util.Set;
import java.util.Collection;


import cc.catalysts.cdoclet.generator.Generator;
import cc.catalysts.cdoclet.generator.utils.GeneratorUtils;

import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.MethodDoc;
import com.sun.javadoc.Type;

public class ClassHandler extends AbstractHandler {
	public ClassHandler(Generator generator) {
		super(generator);
	}

// --------------------- Interface Handler ---------------------

	public void process(ClassDoc classDoc) {
		Map commands = TagParser.processClassTags(getGenerator(), classDoc);

		Set ignore = getIgnore(commands);

		cc.catalysts.cdoclet.generator.Type type = GeneratorUtils.getType(classDoc, getGenerator(), ignore);

		getGenerator().beginClass(type);

		processAnnotations(classDoc.annotations());
		processAnnotationCommands(commands);
		processSuperCommands(commands);
		processSuperClass(classDoc, ignore);
		processInterfaces(classDoc, ignore);
		processClassComment(classDoc);
		processClassConstants(type, classDoc, ignore);
		processBeanProperties(type, classDoc, ignore, commands);

		getGenerator().endClass();
	}

	private void processBeanProperties(cc.catalysts.cdoclet.generator.Type type, ClassDoc classDoc, Set ignore, Map commands) {
		for (MethodDoc methodDoc : classDoc.methods()) {
			processBeanProperty(classDoc, type, methodDoc, ignore, commands);
		}
	}

	private void processClassConstants(cc.catalysts.cdoclet.generator.Type classType, ClassDoc classDoc, Collection ignore) {
		for (FieldDoc fieldDoc : classDoc.fields()) {
			if (fieldDoc.isFinal() && fieldDoc.isPublic()) {
				cc.catalysts.cdoclet.generator.Type type = GeneratorUtils.getType(fieldDoc.type(), getGenerator(), ignore);
				getGenerator().addConstant(classType, type, fieldDoc.name(), fieldDoc.constantValueExpression(), fieldDoc.commentText());
			}
		}
	}

	private void processSuperClass(ClassDoc classDoc, Collection ignore) {
		Type type = classDoc.superclassType();
		if ((type != null) && !type.qualifiedTypeName().equals(Object.class.getCanonicalName())) {
			cc.catalysts.cdoclet.generator.Type superClass = GeneratorUtils.getType(type, getGenerator(), ignore);

			if (superClass != cc.catalysts.cdoclet.generator.Type.NULL && !ignore.contains(superClass.getName())) {
				getGenerator().setSuperclass(superClass, isException(classDoc));
			}
		}
	}

	private boolean isException(ClassDoc classDoc) {
		while (classDoc != null) {
			if (Exception.class.getCanonicalName().equals(classDoc.qualifiedTypeName())) return true;
			classDoc = classDoc.superclass();
		}

		return false;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy