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

Insert annotations at the correct position for arrays #251

Merged
merged 10 commits into from
Oct 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github.javaparser.ast.expr.AnnotationExpr;
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
import com.github.javaparser.ast.nodeTypes.NodeWithRange;
import com.github.javaparser.ast.type.ArrayType;
import com.github.javaparser.ast.type.Type;
import com.google.common.collect.ImmutableList;
import edu.ucr.cs.riple.injector.Helper;
Expand Down Expand Up @@ -68,6 +69,13 @@ public Modification computeTextModificationOnType(Type type, AnnotationExpr anno
if (range == null) {
return null;
}

if (type instanceof ArrayType) {
Copy link
Member

Choose a reason for hiding this comment

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

@avenger2597 As mentioned previously in this comment your changes should be in findSimpleNameRangeInTypeName method where we are returning the array's component type as the place to insert / remove annotation for arrays. You should just change the existing case for array and use type.getTokenRange() to compute the range right before the first [.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ArrayType.Origin origin = ((ArrayType) type).getOrigin();
if (origin == ArrayType.Origin.TYPE) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's not worry about this yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

range = range.withBeginColumn(range.end.column + 1);
}
}
return new Insertion(annotationExpr.toString(), range.begin);
}

Expand Down
Loading