changes to method visibility

This commit is contained in:
Timo Westkämper 2011-08-08 09:11:52 +03:00
parent 5518c0e33e
commit e5550a55ff
3 changed files with 95 additions and 91 deletions

View File

@ -103,6 +103,7 @@ public class DefaultConfiguration implements Configuration {
boolean listAccessors = false;
boolean mapAccessors = false;
boolean createDefaultVariable = true;
if (options.containsKey(QUERYDSL_ENTITY_ACCESSORS)){
entityAccessors = Boolean.valueOf(options.get(QUERYDSL_ENTITY_ACCESSORS));
}
@ -255,8 +256,8 @@ public class DefaultConfiguration implements Configuration {
return false;
}else{
return field.getAnnotation(skipAnn) != null
|| field.getModifiers().contains(Modifier.TRANSIENT)
|| field.getModifiers().contains(Modifier.STATIC);
|| field.getModifiers().contains(Modifier.TRANSIENT)
|| field.getModifiers().contains(Modifier.STATIC);
}
}

View File

@ -40,6 +40,7 @@ import com.mysema.util.BeanUtils;
*
*/
@Immutable
// TODO : rename
public final class ElementHandler{
private final TypeMappings typeMappings;
@ -57,90 +58,9 @@ public final class ElementHandler{
this.typeMappings = typeMappings;
this.queryTypeFactory = queryTypeFactory;
}
private Type getType(VariableElement element){
Type rv = typeFactory.getType(element.asType(), true);
if (element.getAnnotation(QueryType.class) != null){
QueryType qt = element.getAnnotation(QueryType.class);
if (qt.value() != PropertyType.NONE){
TypeCategory typeCategory = qt.value().getCategory();
rv = rv.as(typeCategory);
}
}
return rv;
}
public void handleConstructors(EntityType entityType, List<? extends Element> elements) {
for (ExecutableElement constructor : ElementFilter.constructorsIn(elements)){
if (configuration.isValidConstructor(constructor)){
List<Parameter> parameters = transformParams(constructor.getParameters());
entityType.addConstructor(new Constructor(parameters));
}
}
}
public void handleFieldProperty(EntityType entityType, VariableElement field,
Map<String, Property> properties,
Set<String> blockedProperties,
Map<String, TypeCategory> types) {
String name = field.getSimpleName().toString();
try{
Type fieldType = typeFactory.getType(field.asType(), true);
if (field.getAnnotation(QueryType.class) != null){
TypeCategory typeCategory = field.getAnnotation(QueryType.class).value().getCategory();
if (typeCategory == null){
blockedProperties.add(name);
return;
}
fieldType = fieldType.as(typeCategory);
types.put(name, typeCategory);
}
String[] inits = new String[0];
if (field.getAnnotation(QueryInit.class) != null){
inits = field.getAnnotation(QueryInit.class).value();
}
properties.put(name, new Property(entityType, name, fieldType, inits));
}catch(IllegalArgumentException ex){
StringBuilder builder = new StringBuilder();
builder.append("Caught exception for field ");
builder.append(entityType.getFullName()).append("#").append(field.getSimpleName());
throw new APTException(builder.toString(), ex);
}
}
public void handleMethodProperty(EntityType entityType, String propertyName,
ExecutableElement method,
Map<String, Property> properties, Set<String> blockedProperties,
Map<String, TypeCategory> types) {
try{
Type propertyType = typeFactory.getType(method.getReturnType(), true);
if (method.getAnnotation(QueryType.class) != null){
TypeCategory typeCategory = method.getAnnotation(QueryType.class).value().getCategory();
if (typeCategory == null){
blockedProperties.add(propertyName);
return;
}else if (blockedProperties.contains(propertyName)){
return;
}
propertyType = propertyType.as(typeCategory);
}else if (types.containsKey(propertyName)){
propertyType = propertyType.as(types.get(propertyName));
}
String[] inits = new String[0];
if (method.getAnnotation(QueryInit.class) != null){
inits = method.getAnnotation(QueryInit.class).value();
}
properties.put(propertyName, new Property(entityType, propertyName, propertyType, inits));
}catch(IllegalArgumentException ex){
StringBuilder builder = new StringBuilder();
builder.append("Caught exception for method ");
builder.append(entityType.getFullName()).append("#").append(method.getSimpleName());
throw new APTException(builder.toString(), ex);
}
}
public EntityType handleNormalType(TypeElement e) {
public EntityType handleEntityType(TypeElement e) {
EntityType entityType = typeFactory.getEntityType(e.asType(), true);
List<? extends Element> elements = e.getEnclosedElements();
VisitorConfig config = configuration.getConfig(e, elements);
@ -204,6 +124,89 @@ public final class ElementHandler{
return entityType;
}
private Type getType(VariableElement element){
Type rv = typeFactory.getType(element.asType(), true);
if (element.getAnnotation(QueryType.class) != null){
QueryType qt = element.getAnnotation(QueryType.class);
if (qt.value() != PropertyType.NONE){
TypeCategory typeCategory = qt.value().getCategory();
rv = rv.as(typeCategory);
}
}
return rv;
}
private void handleConstructors(EntityType entityType, List<? extends Element> elements) {
for (ExecutableElement constructor : ElementFilter.constructorsIn(elements)){
if (configuration.isValidConstructor(constructor)){
List<Parameter> parameters = transformParams(constructor.getParameters());
entityType.addConstructor(new Constructor(parameters));
}
}
}
private void handleFieldProperty(EntityType entityType, VariableElement field,
Map<String, Property> properties,
Set<String> blockedProperties,
Map<String, TypeCategory> types) {
String name = field.getSimpleName().toString();
try{
Type fieldType = typeFactory.getType(field.asType(), true);
if (field.getAnnotation(QueryType.class) != null){
TypeCategory typeCategory = field.getAnnotation(QueryType.class).value().getCategory();
if (typeCategory == null){
blockedProperties.add(name);
return;
}
fieldType = fieldType.as(typeCategory);
types.put(name, typeCategory);
}
String[] inits = new String[0];
if (field.getAnnotation(QueryInit.class) != null){
inits = field.getAnnotation(QueryInit.class).value();
}
properties.put(name, new Property(entityType, name, fieldType, inits));
}catch(IllegalArgumentException ex){
StringBuilder builder = new StringBuilder();
builder.append("Caught exception for field ");
builder.append(entityType.getFullName()).append("#").append(field.getSimpleName());
throw new APTException(builder.toString(), ex);
}
}
private void handleMethodProperty(EntityType entityType, String propertyName,
ExecutableElement method,
Map<String, Property> properties, Set<String> blockedProperties,
Map<String, TypeCategory> types) {
try{
Type propertyType = typeFactory.getType(method.getReturnType(), true);
if (method.getAnnotation(QueryType.class) != null){
TypeCategory typeCategory = method.getAnnotation(QueryType.class).value().getCategory();
if (typeCategory == null){
blockedProperties.add(propertyName);
return;
}else if (blockedProperties.contains(propertyName)){
return;
}
propertyType = propertyType.as(typeCategory);
}else if (types.containsKey(propertyName)){
propertyType = propertyType.as(types.get(propertyName));
}
String[] inits = new String[0];
if (method.getAnnotation(QueryInit.class) != null){
inits = method.getAnnotation(QueryInit.class).value();
}
properties.put(propertyName, new Property(entityType, propertyName, propertyType, inits));
}catch(IllegalArgumentException ex){
StringBuilder builder = new StringBuilder();
builder.append("Caught exception for method ");
builder.append(entityType.getFullName()).append("#").append(method.getSimpleName());
throw new APTException(builder.toString(), ex);
}
}
public List<Parameter> transformParams(List<? extends VariableElement> params){
List<Parameter> parameters = new ArrayList<Parameter>(params.size());
for (VariableElement param : params){

View File

@ -266,7 +266,7 @@ public class Processor {
for (TypeElement element : types){
if (typeMirrors.contains(element.asType())){
EntityType model = elementHandler.handleNormalType(element);
EntityType model = elementHandler.handleEntityType(element);
registerTypeElement(model.getFullName(), element);
embeddables.put(model.getFullName(), model);
}
@ -416,7 +416,7 @@ public class Processor {
if (typeElement == null){
throw new IllegalStateException("Found no type for " + superType.getFullName());
}
EntityType entityType = elementHandler.handleNormalType(typeElement);
EntityType entityType = elementHandler.handleEntityType(typeElement);
if (entityType.getSuperType() != null){
superTypes.push(entityType.getSuperType().getType());
}
@ -463,7 +463,7 @@ public class Processor {
// get annotated types
for (Element element : elements) {
EntityType model = elementHandler.handleNormalType((TypeElement) element);
EntityType model = elementHandler.handleEntityType((TypeElement) element);
registerTypeElement(model.getFullName(), (TypeElement)element);
types.put(model.getFullName(), model);
if (model.getSuperType() != null){
@ -576,7 +576,7 @@ public class Processor {
}
for (Element element : elements) {
EntityType model = elementHandler.handleNormalType((TypeElement) element);
EntityType model = elementHandler.handleEntityType((TypeElement) element);
registerTypeElement(model.getFullName(), (TypeElement)element);
embeddables.put(model.getFullName(), model);
}
@ -652,7 +652,7 @@ public class Processor {
continue;
}
EntityType model = elementHandler.handleNormalType(typeElement);
EntityType model = elementHandler.handleEntityType(typeElement);
registerTypeElement(model.getFullName(), typeElement);
embeddables.put(model.getFullName(), model);
}
@ -699,7 +699,7 @@ public class Processor {
for (TypeMirror mirror : typeMirrors){
typeFactory.getEntityType(mirror, true);
TypeElement element = (TypeElement) env.getTypeUtils().asElement(mirror);
EntityType model = elementHandler.handleNormalType(element);
EntityType model = elementHandler.handleEntityType(element);
registerTypeElement(model.getFullName(), element);
types.put(model.getFullName(), model);
if (model.getSuperType() != null){