Skip to content

Commit

Permalink
FORGE-1720: Property now extends AnnotationTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 1, 2014
1 parent 476fd04 commit 40d3024
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/jboss/forge/roaster/model/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

/**
* A {@link Property} is a convenience construct depicting a simple Java bean property.
*
*
* @param <O>
*/
public interface Property<O extends JavaType<O>> extends Internal, Origin<O>, Named
public interface Property<O extends JavaType<O>> extends Internal, Origin<O>, Named, AnnotationTarget<O>
{
/**
* Get this property's {@link Type}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public <T extends Enum<T>> DefaultValue setEnum(T values)
return setEnumArray(values);
}

@SuppressWarnings("unchecked")
@Override
public <T extends Enum<T>> DefaultValue setEnumArray(T... values)
{
Expand Down Expand Up @@ -221,7 +222,7 @@ private <E extends Enum<E>> E convertLiteralToEnum(final Class<E> type, String l
}
}
return null;

}

@Override
Expand Down Expand Up @@ -256,7 +257,7 @@ public Class<?>[] getClassArray()
}
return null;
}

private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral)
{
final Type<JavaAnnotationSource> type = new TypeImpl<JavaAnnotationSource>(getOrigin(), typeLiteral.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
package org.jboss.forge.roaster.model.impl;

import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TextElement;
import org.jboss.forge.roaster.model.Annotation;
import org.jboss.forge.roaster.model.JavaType;
import org.jboss.forge.roaster.model.Method;
import org.jboss.forge.roaster.model.Type;
import org.jboss.forge.roaster.model.Visibility;
import org.jboss.forge.roaster.model.source.AnnotationSource;
import org.jboss.forge.roaster.model.source.FieldSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.jboss.forge.roaster.model.source.MethodSource;
Expand All @@ -28,9 +32,10 @@

/**
* Implementation of PropertySource.
*
*
* @author mbenson
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*
* @param <O>
*/
class PropertyImpl<O extends JavaSource<O> & PropertyHolderSource<O>> implements PropertySource<O>
Expand Down Expand Up @@ -389,7 +394,7 @@ public PropertySource<O> setMutable(boolean mutable)
}
return this;
}

private PropertySource<O> removeAccessor()
{
if (isAccessible())
Expand Down Expand Up @@ -496,4 +501,140 @@ private static String methodName(String prefix, String property)
return prefix + Strings.capitalize(property);
}

@Override
public Annotation<O> getAnnotation(Class<? extends java.lang.annotation.Annotation> type)
{
Annotation<O> ann = null;
FieldSource<O> field = getField();
if (field != null)
{
ann = field.getAnnotation(type);
}
if (ann == null)
{
MethodSource<O> accessor = getAccessor();
if (accessor != null)
{
ann = accessor.getAnnotation(type);
}
}
if (ann == null)
{
MethodSource<O> mutator = getMutator();
if (mutator != null)
{
ann = mutator.getAnnotation(type);
}
}
return ann;
}

@Override
public Annotation<O> getAnnotation(String type)
{
Annotation<O> ann = null;
FieldSource<O> field = getField();
if (field != null)
{
ann = field.getAnnotation(type);
}
if (ann == null)
{
MethodSource<O> accessor = getAccessor();
if (accessor != null)
{
ann = accessor.getAnnotation(type);
}
}
if (ann == null)
{
MethodSource<O> mutator = getMutator();
if (mutator != null)
{
ann = mutator.getAnnotation(type);
}
}
return ann;
}

@Override
public List<? extends Annotation<O>> getAnnotations()
{
List<Annotation<O>> annotations = new ArrayList<>();
FieldSource<O> field = getField();
if (field != null)
{
List<AnnotationSource<O>> fieldAnnotations = field.getAnnotations();
annotations.addAll(fieldAnnotations);
}
MethodSource<O> accessor = getAccessor();
if (accessor != null)
{
List<AnnotationSource<O>> accessorAnnotations = accessor.getAnnotations();
annotations.addAll(accessorAnnotations);
}
MethodSource<O> mutator = getMutator();
if (mutator != null)
{
List<AnnotationSource<O>> mutatorAnnotations = mutator.getAnnotations();
annotations.addAll(mutatorAnnotations);
}
return annotations;
}

@Override
public boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type)
{
boolean hasAnnotation = false;
FieldSource<O> field = getField();
if (field != null)
{
hasAnnotation = field.hasAnnotation(type);
}
if (!hasAnnotation)
{
MethodSource<O> accessor = getAccessor();
if (accessor != null)
{
hasAnnotation = accessor.hasAnnotation(type);
}
}
if (!hasAnnotation)
{
MethodSource<O> mutator = getMutator();
if (mutator != null)
{
hasAnnotation = mutator.hasAnnotation(type);
}
}
return hasAnnotation;
}

@Override
public boolean hasAnnotation(String type)
{
boolean hasAnnotation = false;
FieldSource<O> field = getField();
if (field != null)
{
hasAnnotation = field.hasAnnotation(type);
}
if (!hasAnnotation)
{
MethodSource<O> accessor = getAccessor();
if (accessor != null)
{
hasAnnotation = accessor.hasAnnotation(type);
}
}
if (!hasAnnotation)
{
MethodSource<O> mutator = getMutator();
if (mutator != null)
{
hasAnnotation = mutator.hasAnnotation(type);
}
}
return hasAnnotation;
}
}
Loading

0 comments on commit 40d3024

Please sign in to comment.