From 10b17de850de9df3013f400bb3090ad60d61670f Mon Sep 17 00:00:00 2001 From: Nima Karimipour Date: Mon, 10 Jun 2024 14:13:02 -0700 Subject: [PATCH] optimize memory usage for FieldDeclarationNode --- .../core/registries/field/ClassFieldRecord.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/field/ClassFieldRecord.java b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/field/ClassFieldRecord.java index 0e6325572..5f26df46e 100644 --- a/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/field/ClassFieldRecord.java +++ b/annotator-core/src/main/java/edu/ucr/cs/riple/core/registries/field/ClassFieldRecord.java @@ -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; @@ -120,10 +119,10 @@ public static class FieldDeclarationRecord { /** Name of all fields declared within the same statement. */ public final ImmutableSet 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 = @@ -131,8 +130,9 @@ public FieldDeclarationRecord(FieldDeclaration fieldDeclaration) { .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(); } /** @@ -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; } } }