Skip to content

Conversation

yarinvak
Copy link
Member

@yarinvak yarinvak commented Jun 8, 2018

fix #174

@yarinvak yarinvak requested a review from guy120494 June 8, 2018 06:29
Field field = source.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(source);
private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate to few methods, one that deals with fields and one that deals with methods

return field.get(source);
private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException {
Method method = getMethod(source.getClass(), fieldName, "");
Method getMethod = getMethod(source.getClass(), fieldName, "get");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this method only if necessary (reflection takes a lot of time)

private Object getGraphQLFieldValue(Object source, String fieldName) throws IllegalAccessException, NoSuchFieldException, InvocationTargetException {
Method method = getMethod(source.getClass(), fieldName, "");
Method getMethod = getMethod(source.getClass(), fieldName, "get");
Method isMethod = getMethod(source.getClass(), fieldName, "is");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this method only if necessary (reflection takes a lot of time)

package graphql.annotations.processor.util;

public class PrefixesUtil {
public static String createPrefix(String prefix, String propertyName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the function doesn't explain what the function does

Field field = null;
while (clazz != null && field == null) {
try {
field = clazz.getDeclaredField(name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be "getDeclaredField" or "getField"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getField returns only public fields (but for entire hirearchy), but we need private ones as well. So this method runs over the entire hirearchy and searches for private methods with this name.

@yarinvak yarinvak merged commit 6f33220 into Enigmatis:master Jun 23, 2018
@yarinvak yarinvak deleted the fix-method-data-fetcher branch January 17, 2020 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants