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

Introduce support for constants in the MDC. #7

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,14 @@ public static class ImmutableFieldData implements MappingDataContainer.FieldData
private final String name;
private final String descriptor;
private final List<String> javadoc;
@Nullable
private final ConstantData constant;

public ImmutableFieldData(String name, String descriptor, List<String> javadoc) {
public ImmutableFieldData(String name, String descriptor, List<String> javadoc, @Nullable ConstantData constant) {
this.name = name;
this.descriptor = descriptor;
this.javadoc = ImmutableList.copyOf(javadoc);
this.constant = constant;
}

/**
Expand All @@ -246,18 +249,36 @@ public List<String> getJavadoc() {
return javadoc;
}

/**
* {@inheritDoc}
*/
@Override
public ConstantData getConstant() {
return constant;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FieldData)) return false;
FieldData that = (FieldData) o;
return getName().equals(that.getName()) && Objects.equals(getDescriptor(), that.getDescriptor())
&& getJavadoc().equals(that.getJavadoc());
if (!(o instanceof ImmutableFieldData)) return false;

ImmutableFieldData that = (ImmutableFieldData) o;
Comment on lines -252 to +265
Copy link
Member

Choose a reason for hiding this comment

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

This change would mean ImmutableFieldData would be incomparable to other FieldData instances (such as mutable ones). It should only check if it is an instance of FieldData.

Same comment on all other similar instances.


if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
if (getDescriptor() != null ? !getDescriptor().equals(that.getDescriptor()) : that.getDescriptor() != null)
return false;
if (getJavadoc() != null ? !getJavadoc().equals(that.getJavadoc()) : that.getJavadoc() != null)
return false;
return getConstant() != null ? getConstant().equals(that.getConstant()) : that.getConstant() == null;
}

@Override
public int hashCode() {
return Objects.hash(getName(), getDescriptor(), getJavadoc());
int result = getName() != null ? getName().hashCode() : 0;
result = 31 * result + (getDescriptor() != null ? getDescriptor().hashCode() : 0);
result = 31 * result + (getJavadoc() != null ? getJavadoc().hashCode() : 0);
result = 31 * result + (getConstant() != null ? getConstant().hashCode() : 0);
return result;
Comment on lines -260 to +281
Copy link
Member

Choose a reason for hiding this comment

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

Why change from Objects.hash? Are there any substantial benefits to hardcoding ourselves to this pattern of hashcoding? (I'd also like a source on how this pattern was decided.)

Same comment on all other similar instances.

}
}

Expand Down Expand Up @@ -344,11 +365,14 @@ public static class ImmutableParameterData implements MappingDataContainer.Param
private final String name;
@Nullable
private final String javadoc;
@Nullable
private final ConstantData constant;

public ImmutableParameterData(byte index, @Nullable String name, @Nullable String javadoc) {
public ImmutableParameterData(byte index, @Nullable String name, @Nullable String javadoc, @Nullable ConstantData constant) {
this.index = index;
this.name = name;
this.javadoc = javadoc;
this.constant = constant;
}

/**
Expand Down Expand Up @@ -377,17 +401,131 @@ public String getJavadoc() {
return javadoc;
}

/**
* {@inheritDoc}
*/
@Override
public ConstantData getConstant() {
return constant;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ImmutableParameterData)) return false;

ImmutableParameterData that = (ImmutableParameterData) o;

if (getIndex() != that.getIndex()) return false;
if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
if (getJavadoc() != null ? !getJavadoc().equals(that.getJavadoc()) : that.getJavadoc() != null)
return false;
return getConstant() != null ? getConstant().equals(that.getConstant()) : that.getConstant() == null;
}

@Override
public int hashCode() {
int result = getIndex();
result = 31 * result + (getName() != null ? getName().hashCode() : 0);
result = 31 * result + (getJavadoc() != null ? getJavadoc().hashCode() : 0);
result = 31 * result + (getConstant() != null ? getConstant().hashCode() : 0);
return result;
}
}

/**
* An immutable {@link MappingDataContainer.ConstantData}.
*/
public static final class ImmutableConstantData implements ConstantData {

private final ConstantType type;
private final List<ConstantValueData> values;

public ImmutableConstantData(ConstantType type, List<ConstantValueData> values) {
this.type = type;
this.values = values;
}

/**
* {@inheritDoc}
*/
@Override
public ConstantType getType() {
return type;
}

/**
* {@inheritDoc}
*/
@Override
public List<ConstantValueData> getValues() {
return values;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ParameterData)) return false;
ParameterData that = (ParameterData) o;
return getIndex() == that.getIndex() && Objects.equals(getName(), that.getName()) && Objects.equals(getJavadoc(), that.getJavadoc());
if (!(o instanceof ImmutableConstantData)) return false;

ImmutableConstantData that = (ImmutableConstantData) o;

if (getType() != that.getType()) return false;
return getValues().equals(that.getValues());
}

@Override
public int hashCode() {
int result = getType().hashCode();
result = 31 * result + getValues().hashCode();
return result;
}
}

/**
* An immutable {@link MappingDataContainer.ConstantValueData}.
*/
public static final class ImmutableConstantValueData implements ConstantValueData {

private final int value;
private final String reference;

public ImmutableConstantValueData(int value, String reference) {
this.value = value;
this.reference = reference;
}

/**
* {@inheritDoc}
*/
@Override
public int getValue() {
return value;
}

/**
* {@inheritDoc}
*/
@Override
public String getReference() {
return reference;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ImmutableConstantValueData)) return false;

ImmutableConstantValueData that = (ImmutableConstantValueData) o;

if (getValue() != that.getValue()) return false;
return getReference().equals(that.getReference());
}

@Override
public int hashCode() {
return Objects.hash(getIndex(), getName(), getJavadoc());
int result = getValue();
result = 31 * result + getReference().hashCode();
return result;
}
}
}
Loading