Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(java): Reduce guava TypeToken dependency #1273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nandakumar131
Copy link
Contributor

What do these changes do?

This change reduces the dependency on guava TypeToken. This PR doesn't completely remove the dependency, follow-up PR is required to complete the work.

Related issue number

#1113

LICENSE Outdated Show resolved Hide resolved
* Contains static utility methods pertaining to primitive types and their corresponding wrapper
* types.
*/
public final class Primitives {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use or extend org.apache.fury.type.TypeUtils instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reused TypeUtils and removed Primitives.

*/
public Class<? super T> getRawType() {
// For wildcard or type variable, the first bound determines the runtime type.
Class<?> rawType = getRawTypes(type).iterator().next();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may be expensive. Fury init will invoke this API many times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rewrite and update the patch.


package org.apache.fury.reflect;

import com.google.common.reflect.TypeParameter;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we implement TypeToken by ourself without depending on any guava API. org.apache.fury.type.GenericType#build(java.lang.reflect.Type, java.util.function.Predicate<java.lang.reflect.Type>) can be taken as an example.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fury use TypeToken to capture generic info and for Generic Type resolve only. We don't need all features of TypeToken

Copy link
Collaborator

Choose a reason for hiding this comment

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

For Generic Type resolve, Fury use TypeToken to:

  • Resolve covariantType/invariantType
  • Create new generic Type based on other generic Types:
new TypeToken<Map<K, V>>() {}.where(new TypeParameter<K>() {}, keyType)
        .where(new TypeParameter<V>() {}, valueType);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need more time to go over the code and understand the usage properly. Can this be done in follow-up PR?

@PragmaTwice PragmaTwice changed the title [Java] Reduce guava TypeToken dependency chore(java): Reduce guava TypeToken dependency Jan 6, 2024
@chaokunyang
Copy link
Collaborator

Hi @nandakumar131 , are you still working on this? If not, I'd like to take over it. We're planing to make a release in next weeks. It would be great to include this change.

@nandakumar131
Copy link
Contributor Author

@chaokunyang, sorry about the delay.
Let me work over this weekend and update the PR.

@chaokunyang
Copy link
Collaborator

chaokunyang commented Feb 9, 2024

Let me work over this weekend and update the PR.

Awesome! This is not urgent, you can take your time.

@AkiChase
Copy link

Any update? Thanks

@chaokunyang
Copy link
Collaborator

@AkiChase I'm working on first release of Fury under asf. If Nandakumar doesn't have time for this, I should be able to take over it in next two weeks.

chaokunyang pushed a commit that referenced this pull request Apr 26, 2024

## What does this PR do?

Removes Guava's `TypeToken` usages and replaces it with a hand-made
`TypeToken` implementation.
To be honest, this is mostly a copy-paste of Guava's TypeToken with
removing some unnecessary stuff. This implementation can be improved and
optimized.

## Related issues

#1113
#1273

---------

Co-authored-by: Nandakumar Vadivelu <nanda@apache.org>
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.

None yet

4 participants