com.github.vsspt.xjc.model.ClassRepresentation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxb-ri-xjc Show documentation
Show all versions of jaxb-ri-xjc Show documentation
Generates toString, setter, equals and hashCode methods on JAXB generated classes.
package com.github.vsspt.xjc.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JFieldVar;
import com.sun.tools.xjc.outline.ClassOutline;
public class ClassRepresentation {
private final ClassOutline classOutline;
private final String annotationOption;
private final String name;
private final List classFields = new ArrayList();
private final List fieldsFromAnnotations = new ArrayList();
private final boolean checkAnnotationfields;
public ClassRepresentation(final ClassOutline classOutline, final String annotationOption, final boolean checkAnnotationfields) {
this.classOutline = classOutline;
this.annotationOption = annotationOption;
name = classOutline.implClass.name();
this.checkAnnotationfields = checkAnnotationfields;
process();
}
public ClassOutline getClassOutline() {
return classOutline;
}
public String getName() {
return name;
}
public List getClassFields() {
return classFields;
}
public List getFieldsFromAnnotations() {
return fieldsFromAnnotations;
}
public boolean isValidForAugument() {
return checkAnnotationfields == false ? true : !fieldsFromAnnotations.isEmpty();
}
@Override
public String toString() {
return "Name = " + name + ", classFields = " + classFields + ", fieldsFromAnnotations= " + fieldsFromAnnotations;
}
private void process() {
for (final JFieldVar jfield : classOutline.implClass.fields().values()) {
final Collection annotations = jfield.annotations();
for (final JAnnotationUse annotation : annotations) {
final String fullclassName = annotation.getAnnotationClass().fullName();
if (isAnnotationEligible(fullclassName) && !fieldsFromAnnotations.contains(fullclassName)) {
fieldsFromAnnotations.add(jfield.name());
}
}
final String checkedValue = jfield.name();
if (!classFields.contains(checkedValue)) {
classFields.add(checkedValue);
}
}
}
private boolean isAnnotationEligible(final String annotationName) {
return annotationOption == null ? false : annotationOption.equals(annotationName);
}
}