Skip to content

Commit

Permalink
Get the first postion according to the sequence rank
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored and fbricon committed Sep 17, 2019
1 parent 7cef32f commit 8c3859b
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ public static RefactorWorkspaceEdit getEditsForRefactor(GetRefactorEditParams pa
Command additionalCommand = null;
if (linkedProposalModel != null) {
LinkedProposalPositionGroupCore linkedPositionGroup = linkedProposalModel.getPositionGroup(positionKey, false);
PositionInformation highlightPosition = getFirstTrackedNodePosition(linkedPositionGroup);
PositionInformation highlightPosition;
if (QuickAssistProcessor.CONVERT_ANONYMOUS_CLASS_TO_NESTED_COMMAND.equals(params.command)) {
highlightPosition = getFirstTrackedNodePositionBySequenceRank(linkedPositionGroup);
} else {
highlightPosition = getFirstTrackedNodePosition(linkedPositionGroup);
}
if (highlightPosition != null) {
int offset = highlightPosition.getOffset();
int length = highlightPosition.getLength();
Expand Down Expand Up @@ -117,6 +122,26 @@ private static PositionInformation getFirstTrackedNodePosition(LinkedProposalPos
return positions[0];
}

private static PositionInformation getFirstTrackedNodePositionBySequenceRank(LinkedProposalPositionGroupCore positionGroup) {
if (positionGroup == null) {
return null;
}

PositionInformation[] positions = positionGroup.getPositions();
if (positions == null || positions.length == 0) {
return null;
}

PositionInformation targetPosition = positions[0];

for (int i = 1; i < positions.length; i++) {
if (positions[i].getSequenceRank() < targetPosition.getSequenceRank()) {
targetPosition = positions[i];
}
}
return targetPosition;
}

private static CUCorrectionProposal getExtractVariableProposal(CodeActionParams params, IInvocationContext context, boolean problemsAtLocation, String refactorType, Map formatterOptions) throws CoreException {
if (RefactorProposalUtility.EXTRACT_VARIABLE_ALL_OCCURRENCE_COMMAND.equals(refactorType)) {
return RefactorProposalUtility.getExtractVariableAllOccurrenceProposal(params, context, problemsAtLocation, formatterOptions, false);
Expand Down

0 comments on commit 8c3859b

Please sign in to comment.