Search in sources :

Example 1 with CategorizedTextEditGroup

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);
    }
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)

Example 2 with CategorizedTextEditGroup

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;
}
Also used : CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)

Example 3 with CategorizedTextEditGroup

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;
}
Also used : GroupCategorySet(org.eclipse.ltk.core.refactoring.GroupCategorySet) GroupCategory(org.eclipse.ltk.core.refactoring.GroupCategory) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)

Example 4 with CategorizedTextEditGroup

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)));
}
Also used : TextEditChangeGroup(org.eclipse.ltk.core.refactoring.TextEditChangeGroup) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)

Example 5 with CategorizedTextEditGroup

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()]));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) GroupCategorySet(org.eclipse.ltk.core.refactoring.GroupCategorySet) GroupCategory(org.eclipse.ltk.core.refactoring.GroupCategory) ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IBuffer(org.eclipse.jdt.core.IBuffer) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup) TextEdit(org.eclipse.text.edits.TextEdit) CategorizedTextEditGroup(org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Aggregations

CategorizedTextEditGroup (org.eclipse.ltk.core.refactoring.CategorizedTextEditGroup)6 TextEdit (org.eclipse.text.edits.TextEdit)3 GroupCategory (org.eclipse.ltk.core.refactoring.GroupCategory)2 GroupCategorySet (org.eclipse.ltk.core.refactoring.GroupCategorySet)2 ArrayList (java.util.ArrayList)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)1 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 TextEditChangeGroup (org.eclipse.ltk.core.refactoring.TextEditChangeGroup)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 TextEditGroup (org.eclipse.text.edits.TextEditGroup)1