Search in sources :

Example 1 with GroupCategory

use of org.eclipse.ltk.core.refactoring.GroupCategory 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 2 with GroupCategory

use of org.eclipse.ltk.core.refactoring.GroupCategory 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)2 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 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)1 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)1 TextEdit (org.eclipse.text.edits.TextEdit)1 TextEditGroup (org.eclipse.text.edits.TextEditGroup)1