use of org.eclipse.jdt.ls.core.internal.corext.fix.LinkedProposalPositionGroup in project eclipse.jdt.ls by eclipse.
the class ExtractTempRefactoring method createTempDeclaration.
private VariableDeclarationStatement createTempDeclaration(Expression initializer) throws CoreException {
AST ast = fCURewrite.getAST();
VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(ast.newSimpleName(fTempName));
vdf.setInitializer(initializer);
VariableDeclarationStatement vds = ast.newVariableDeclarationStatement(vdf);
if (fDeclareFinal) {
vds.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
}
vds.setType(createTempType());
if (fLinkedProposalModel != null) {
ASTRewrite rewrite = fCURewrite.getASTRewrite();
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(rewrite.track(vdf.getName()), true);
String[] nameSuggestions = guessTempNames();
if (nameSuggestions.length > 0 && !nameSuggestions[0].equals(fTempName)) {
nameGroup.addProposal(fTempName, nameSuggestions.length + 1);
}
for (int i = 0; i < nameSuggestions.length; i++) {
nameGroup.addProposal(nameSuggestions[i], nameSuggestions.length - i);
}
}
return vds;
}
Aggregations