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

Add descriptor for field scheme inside ClassInfo #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/net/neoforged/art/api/ClassProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,20 @@ public interface IClassInfo {
*
* @param name the field name
* @return the field, or an empty optional if it doesn't exist
* @deprecated Use with descriptor
* @see ClassProvider#getField(String, String)
*/
Optional<? extends IFieldInfo> getField(String name); //TODO: Desc?
@Deprecated
Optional<? extends IFieldInfo> getField(String name);

/**
* Queries a field based on its field name and descriptor.
*
* @param name the field name
* @param desc the field descriptor
* @return the field, or an empty optional if it doesn't exist
*/
Optional<? extends IFieldInfo> getField(String name, String desc);
danirod12 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns all the methods declared in this class.
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/net/neoforged/art/internal/ClassProviderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static class ClassInfo implements IClassInfo {

if (!node.fields.isEmpty())
this.fields = Collections.unmodifiableMap(node.fields.stream().map(FieldInfo::new)
.collect(Collectors.toMap(FieldInfo::getName, Function.identity())));
.collect(Collectors.toMap(f -> f.getName() + f.getDescriptor(), Function.identity())));
danirod12 marked this conversation as resolved.
Show resolved Hide resolved
else
this.fields = null;
}
Expand Down Expand Up @@ -179,9 +179,25 @@ public Collection<? extends IFieldInfo> getFields() {
return fieldsView;
}

@Deprecated
@Override
public Optional<? extends IFieldInfo> getField(String name) {
return fields == null ? Optional.empty() : Optional.ofNullable(this.fields.get(name));
if (this.fields != null) {
danirod12 marked this conversation as resolved.
Show resolved Hide resolved
for (Map.Entry<String, FieldInfo> entry : this.fields.entrySet()) {
if (entry.getKey().split(" ")[0].equals(name)) {
// Backwards compatibility not possible when duplication
// on field names, constructor was crashing without descriptor logic
// Let it be any in this case
return Optional.of(entry.getValue());
}
}
}
return Optional.empty();
}

@Override
public Optional<? extends IFieldInfo> getField(String name, String desc) {
return this.fields == null ? Optional.empty() : Optional.ofNullable(this.fields.get(name + " " + desc));
danirod12 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
Loading