use of org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup in project che by eclipse.
the class DelegateCreator method createEdit.
/**
* Performs the actual rewriting and adds an edit to the ASTRewrite set with
* {@link #setSourceRewrite(CompilationUnitRewrite)}.
*
* @throws JavaModelException
*/
public void createEdit() throws JavaModelException {
try {
IDocument document = new Document(fDelegateRewrite.getCu().getBuffer().getContents());
TextEdit edit = fDelegateRewrite.getASTRewrite().rewriteAST(document, fDelegateRewrite.getCu().getJavaProject().getOptions(true));
edit.apply(document, TextEdit.UPDATE_REGIONS);
String newSource = Strings.trimIndentation(document.get(fTrackedPosition.getStartPosition(), fTrackedPosition.getLength()), fPreferences.tabWidth, fPreferences.indentWidth, false);
ASTNode placeholder = fOriginalRewrite.getASTRewrite().createStringPlaceholder(newSource, fDeclaration.getNodeType());
CategorizedTextEditGroup groupDescription = fOriginalRewrite.createCategorizedGroupDescription(getTextEditGroupLabel(), CATEGORY_DELEGATE);
ListRewrite bodyDeclarationsListRewrite = fOriginalRewrite.getASTRewrite().getListRewrite(fDeclaration.getParent(), getTypeBodyDeclarationsProperty());
if (fCopy)
if (fInsertBefore)
bodyDeclarationsListRewrite.insertBefore(placeholder, fDeclaration, groupDescription);
else
bodyDeclarationsListRewrite.insertAfter(placeholder, fDeclaration, groupDescription);
else
bodyDeclarationsListRewrite.replace(fDeclaration, placeholder, groupDescription);
} catch (BadLocationException e) {
JavaPlugin.log(e);
}
}
use of org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup in project eclipse.jdt.ls by eclipse.
the class CompilationUnitRewrite method createCategorizedGroupDescription.
public CategorizedTextEditGroup createCategorizedGroupDescription(String name, GroupCategorySet set) {
CategorizedTextEditGroup result = new CategorizedTextEditGroup(name, set);
fTextEditGroups.add(result);
return result;
}
use of org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup in project che by eclipse.
the class TextEditFix method createChange.
/**
* {@inheritDoc}
*/
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
String label = fChangeDescription;
CompilationUnitChange result = new CompilationUnitChange(label, fUnit);
result.setEdit(fEdit);
result.addTextEditGroup(new CategorizedTextEditGroup(label, new GroupCategorySet(new GroupCategory(label, label, label))));
return result;
}
use of org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup in project che by eclipse.
the class TextChangeCompatibility method addTextEdit.
public static void addTextEdit(TextChange change, String name, TextEdit edit, GroupCategorySet groupCategories) throws MalformedTreeException {
Assert.isNotNull(change);
Assert.isNotNull(name);
Assert.isNotNull(edit);
TextEdit root = change.getEdit();
if (root == null) {
root = new MultiTextEdit();
change.setEdit(root);
}
insert(root, edit);
change.addTextEditChangeGroup(new TextEditChangeGroup(change, new CategorizedTextEditGroup(name, edit, groupCategories)));
}
use of org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup in project che by eclipse.
the class StringFix method createCleanUp.
private static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addNLSTag, boolean removeNLSTag, IProblemLocation[] problems) throws CoreException, JavaModelException {
ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
if (!cu.isStructureKnown())
//[clean up] 'Remove unnecessary $NLS-TAGS$' removes necessary ones in case of syntax errors: https://bugs.eclipse.org/bugs/show_bug.cgi?id=285814 :
return null;
List<CategorizedTextEditGroup> result = new ArrayList<CategorizedTextEditGroup>();
List<IProblemLocation> missingNLSProblems = new ArrayList<IProblemLocation>();
for (int i = 0; i < problems.length; i++) {
IProblemLocation problem = problems[i];
if (addNLSTag && problem.getProblemId() == IProblem.NonExternalizedStringLiteral) {
missingNLSProblems.add(problem);
}
if (removeNLSTag && problem.getProblemId() == IProblem.UnnecessaryNLSTag) {
IBuffer buffer = cu.getBuffer();
if (buffer != null) {
TextEdit edit = StringFix.getReplace(problem.getOffset(), problem.getLength(), buffer, false);
if (edit != null) {
String label = FixMessages.StringFix_RemoveNonNls_description;
result.add(new CategorizedTextEditGroup(label, edit, new GroupCategorySet(new GroupCategory(label, label, label))));
}
}
}
}
if (!missingNLSProblems.isEmpty()) {
int[] positions = new int[missingNLSProblems.size()];
int i = 0;
for (Iterator<IProblemLocation> iter = missingNLSProblems.iterator(); iter.hasNext(); ) {
IProblemLocation problem = iter.next();
positions[i] = problem.getOffset();
i++;
}
//TODO nls
//NLSUtil.createNLSEdits(cu, positions);
TextEdit[] edits = null;
if (edits != null) {
for (int j = 0; j < edits.length; j++) {
String label = FixMessages.StringFix_AddNonNls_description;
result.add(new CategorizedTextEditGroup(label, edits[j], new GroupCategorySet(new GroupCategory(label, label, label))));
}
}
}
if (result.isEmpty())
return null;
//$NON-NLS-1$
return new StringFix("", compilationUnit, result.toArray(new TextEditGroup[result.size()]));
}
Aggregations