Skip to content

Commit

Permalink
Fix #28 Recognize fields that are child types of Property
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacqu committed Nov 27, 2016
1 parent 696e8b6 commit 8ce97ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ private void saveComment(Field field, String path) {
*/
@Nullable
private static Property<?> getPropertyField(Field field) {
field.setAccessible(true);
if (field.isAccessible() && Property.class.equals(field.getType()) && Modifier.isStatic(field.getModifiers())) {
if (Property.class.isAssignableFrom(field.getType()) && Modifier.isStatic(field.getModifiers())) {
try {
return (Property<?>) field.get(null);
} catch (IllegalAccessException e) {
throw new ConfigMeException("Could not fetch field '" + field.getName() + "' from class '"
+ field.getDeclaringClass().getSimpleName() + "'", e);
+ field.getDeclaringClass().getSimpleName() + "'. Is it maybe not public?", e);
}
}
return null;
Expand Down Expand Up @@ -106,7 +105,7 @@ Map<String, String[]> getComments() {
private static Map<String, String[]> callSectionCommentsMethod(Method method) {
if (!Modifier.isStatic(method.getModifiers())) {
throw new ConfigMeException(
"Methods with @SectionComments must be static! Offending method: '" + method + "'");
"Methods with @SectionComments must be static. Offending method: '" + method + "'");
} else if (method.getParameters().length > 0) {
throw new ConfigMeException(
"@SectionComments methods may not have any parameters. Offending method: '" + method + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.authme.configme.Comment;
import com.github.authme.configme.SectionComments;
import com.github.authme.configme.SettingsHolder;
import com.github.authme.configme.properties.IntegerProperty;
import com.github.authme.configme.properties.Property;

import java.util.HashMap;
Expand Down Expand Up @@ -37,8 +38,8 @@ public final class TestConfiguration implements SettingsHolder {
@Comment({
"The version number",
"This is just a random number" })
public static final Property<Integer> VERSION_NUMBER =
newProperty("version", 32046);
public static final IntegerProperty VERSION_NUMBER =
new IntegerProperty("version", 32046);

@Comment("Skip boring features?")
public static final Property<Boolean> SKIP_BORING_FEATURES =
Expand Down

0 comments on commit 8ce97ba

Please sign in to comment.