Search in sources :

Example 11 with CompilationUnitChange

use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.

the class CompilationUnitRewriteOperationsFix method createChange.

//	/**
//	 * {@inheritDoc}
//	 */
//	@Override
//	public LinkedProposalModel getLinkedPositions() {
//		if (!fLinkedProposalModel.hasLinkedPositions())
//			return null;
//
//		return fLinkedProposalModel;
//	}
/**
	 * {@inheritDoc}
	 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
    CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite((ICompilationUnit) fCompilationUnit.getJavaElement(), fCompilationUnit);
    fLinkedProposalModel.clear();
    for (int i = 0; i < fOperations.length; i++) {
        CompilationUnitRewriteOperation operation = fOperations[i];
        operation.rewriteAST(cuRewrite, fLinkedProposalModel);
    }
    CompilationUnitChange result = cuRewrite.createChange(getDisplayString(), true, null);
    if (result == null)
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.ID_PLUGIN, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));
    return result;
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 12 with CompilationUnitChange

use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.

the class StringFix method createChange.

/**
	 * {@inheritDoc}
	 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
    if (fEditGroups == null || fEditGroups.length == 0)
        return null;
    CompilationUnitChange result = new CompilationUnitChange(getDisplayString(), fCompilationUnit);
    for (int i = 0; i < fEditGroups.length; i++) {
        TextEdit[] edits = fEditGroups[i].getTextEdits();
        String groupName = fEditGroups[i].getName();
        for (int j = 0; j < edits.length; j++) {
            TextChangeCompatibility.addTextEdit(result, groupName, edits[j]);
        }
    }
    return result;
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 13 with CompilationUnitChange

use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.

the class CompilationUnitRewrite method createChange.

/**
	 * Creates a compilation unit change based on the events recorded by this compilation unit rewrite.
	 * @param name the name of the change to create
	 * @param generateGroups <code>true</code> to generate text edit groups, <code>false</code> otherwise
	 * @param monitor the progress monitor or <code>null</code>
	 * @return a {@link CompilationUnitChange}, or <code>null</code> for an empty change
	 * @throws CoreException when text buffer acquisition or import rewrite text edit creation fails
	 * @throws IllegalArgumentException when the AST rewrite encounters problems
	 */
public CompilationUnitChange createChange(String name, boolean generateGroups, IProgressMonitor monitor) throws CoreException {
    CompilationUnitChange cuChange = new CompilationUnitChange(name, fCu);
    MultiTextEdit multiEdit = new MultiTextEdit();
    cuChange.setEdit(multiEdit);
    return attachChange(cuChange, generateGroups, monitor);
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 14 with CompilationUnitChange

use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.

the class CUCorrectionProposal method createTextChange.

/**
	 * Creates the text change for this proposal.
	 * This method is only called once and only when no text change has been passed in
	 * {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}.
	 *
	 * @return the created text change
	 * @throws CoreException if the creation of the text change failed
	 */
protected TextChange createTextChange() throws CoreException {
    ICompilationUnit cu = getCompilationUnit();
    String name = getName();
    TextChange change;
    if (!cu.getResource().exists()) {
        String source;
        try {
            source = cu.getSource();
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
            // empty
            source = new String();
        }
        Document document = new Document(source);
        document.setInitialLineDelimiter(StubUtility.getLineDelimiterUsed(cu));
        change = new DocumentChange(name, document);
    } else {
        CompilationUnitChange cuChange = new CompilationUnitChange(name, cu);
        cuChange.setSaveMode(TextFileChange.LEAVE_DIRTY);
        change = cuChange;
    }
    TextEdit rootEdit = new MultiTextEdit();
    change.setEdit(rootEdit);
    // initialize text change
    IDocument document = change.getCurrentDocument(new NullProgressMonitor());
    addEdits(document, rootEdit);
    return change;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) TextChange(org.eclipse.ltk.core.refactoring.TextChange) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) IDocument(org.eclipse.jface.text.IDocument) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Example 15 with CompilationUnitChange

use of org.eclipse.jdt.core.refactoring.CompilationUnitChange in project che by eclipse.

the class ConvertAnonymousToNestedRefactoring method createChange.

/*
	 * @see org.eclipse.jdt.internal.corext.refactoring.base.IRefactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    final CompilationUnitChange result = createCompilationUnitChange(pm);
    result.setDescriptor(createRefactoringDescriptor());
    return result;
}
Also used : CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange)

Aggregations

CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)24 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)9 TextEdit (org.eclipse.text.edits.TextEdit)9 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)8 CompilationUnitRewrite (org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 TextEditGroup (org.eclipse.text.edits.TextEditGroup)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)3 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)3 RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)3 TextChange (org.eclipse.ltk.core.refactoring.TextChange)3 HashMap (java.util.HashMap)2 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2