public static void addChangeIdentifierCaseProposal( Node node, Collection<ICompletionProposal> proposals, IFile file) { Tree.Identifier identifier = null; if (node instanceof Tree.TypeDeclaration) { identifier = ((Tree.TypeDeclaration) node).getIdentifier(); } else if (node instanceof Tree.TypeParameterDeclaration) { identifier = ((Tree.TypeParameterDeclaration) node).getIdentifier(); } else if (node instanceof Tree.TypedDeclaration) { identifier = ((Tree.TypedDeclaration) node).getIdentifier(); } else if (node instanceof Tree.ImportPath) { List<Identifier> importIdentifiers = ((Tree.ImportPath) node).getIdentifiers(); for (Identifier importIdentifier : importIdentifiers) { if (importIdentifier.getText() != null && !importIdentifier.getText().isEmpty() && Character.isUpperCase(importIdentifier.getText().charAt(0))) { identifier = importIdentifier; break; } } } if (identifier != null && !identifier.getText().isEmpty()) { addProposal(identifier, proposals, file); } }
private static void addProposal( Identifier identifier, Collection<ICompletionProposal> proposals, IFile file) { String oldIdentifier = identifier.getText(); int first = oldIdentifier.codePointAt(0); int newFirst = isUpperCase(first) ? toLowerCase(first) : toUpperCase(first); String newFirstLetter = new String(toChars(newFirst)); String newIdentifier = newFirstLetter + oldIdentifier.substring(charCount(first)); TextFileChange change = new TextFileChange("Change initial case of identifier", file); change.setEdit(new ReplaceEdit(identifier.getStartIndex(), 1, newFirstLetter)); ChangeInitialCaseOfIdentifierInDeclaration proposal = new ChangeInitialCaseOfIdentifierInDeclaration(newIdentifier, change); if (!proposals.contains(proposal)) { proposals.add(proposal); } }