Skip to content

Commit

Permalink
Removed last remaining custom field locator and replaced it with the …
Browse files Browse the repository at this point in the history
…general component.
  • Loading branch information
raphw committed Mar 20, 2016
1 parent c7dd50b commit 0dcf6ac
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 247 deletions.
Expand Up @@ -127,16 +127,35 @@ public String toString() {
} }
} }


/**
* A factory for creating a {@link FieldLocator}.
*/
interface Factory {

/**
* Creates a field locator for a given type.
*
* @param typeDescription The type for which to create a field locator.
* @return A suitable field locator.
*/
FieldLocator make(TypeDescription typeDescription);
}

/** /**
* A field locator that never discovers a field. * A field locator that never discovers a field.
*/ */
enum NoOp implements FieldLocator { enum NoOp implements FieldLocator, Factory {


/** /**
* The singleton instance. * The singleton instance.
*/ */
INSTANCE; INSTANCE;


@Override
public FieldLocator make(TypeDescription typeDescription) {
return this;
}

@Override @Override
public Resolution locate(String name) { public Resolution locate(String name) {
return Resolution.Illegal.INSTANCE; return Resolution.Illegal.INSTANCE;
Expand Down Expand Up @@ -268,6 +287,51 @@ public String toString() {
", typeDescription=" + typeDescription + ", typeDescription=" + typeDescription +
'}'; '}';
} }

/**
* A factory for creating a {@link ForExactType}.
*/
public static class Factory implements FieldLocator.Factory {

/**
* The type for which to locate a field.
*/
private final TypeDescription typeDescription;

/**
* Creates a new factory for a field locator that locates a field for an exact type.
*
* @param typeDescription The type for which to locate a field.
*/
public Factory(TypeDescription typeDescription) {
this.typeDescription = typeDescription;
}

@Override
public FieldLocator make(TypeDescription typeDescription) {
return new ForExactType(this.typeDescription, typeDescription);
}

@Override
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
Factory factory = (Factory) object;
return typeDescription.equals(factory.typeDescription);
}

@Override
public int hashCode() {
return typeDescription.hashCode();
}

@Override
public String toString() {
return "FieldLocator.ForExactType.Factory{" +
"typeDescription=" + typeDescription +
'}';
}
}
} }


/** /**
Expand Down Expand Up @@ -334,5 +398,26 @@ public String toString() {
", typeDescription=" + typeDescription + ", typeDescription=" + typeDescription +
'}'; '}';
} }

/**
* A factory for creating a {@link ForClassHierarchy}.
*/
public enum Factory implements FieldLocator.Factory {

/**
* The singleton instance.
*/
INSTANCE;

@Override
public FieldLocator make(TypeDescription typeDescription) {
return new ForClassHierarchy(typeDescription);
}

@Override
public String toString() {
return "FieldLocator.ForClassHierarchy.Factory." + name();
}
}
} }
} }

0 comments on commit 0dcf6ac

Please sign in to comment.