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

Optimize memory usage for FieldDeclarationNode #233

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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 @@ -26,7 +26,6 @@

import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
import com.github.javaparser.ast.type.Type;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import java.nio.file.Path;
Expand Down Expand Up @@ -120,19 +119,20 @@ public static class FieldDeclarationRecord {

/** Name of all fields declared within the same statement. */
public final ImmutableSet<String> names;
/** Type of the field. */
public final Type type;
/** Field declaration node. */
public final FieldDeclaration fieldDeclaration;
/** True if the field declaration is of primitive type, false otherwise. */
public final boolean isPrimitiveType;
/** True if the field declaration is public, false otherwise. */
public final boolean isPublic;

public FieldDeclarationRecord(FieldDeclaration fieldDeclaration) {
this.names =
fieldDeclaration.getVariables().stream()
.map(NodeWithSimpleName::getNameAsString)
.collect(ImmutableSet.toImmutableSet());
Preconditions.checkArgument(fieldDeclaration.getVariables().getFirst().isPresent());
this.type = fieldDeclaration.getVariables().getFirst().get().getType();
this.fieldDeclaration = fieldDeclaration;
this.isPrimitiveType =
fieldDeclaration.getVariables().getFirst().get().getType().isPrimitiveType();
this.isPublic = fieldDeclaration.isPublic();
}

/**
Expand All @@ -141,7 +141,7 @@ public FieldDeclarationRecord(FieldDeclaration fieldDeclaration) {
* @return true, if the field declaration is public and has non-primitive type.
*/
public boolean isPublicFieldWithNonPrimitiveType() {
return fieldDeclaration.isPublic() && !type.isPrimitiveType();
return isPublic && !isPrimitiveType;
}
}
}
Loading