Java Code Examples for org.eclipse.ltk.core.refactoring.TextFileChange#setSaveMode()

The following examples show how to use org.eclipse.ltk.core.refactoring.TextFileChange#setSaveMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteChangeCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException {
	try {
		ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu);
		TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true));
		TextChange textChange= manager.get(cu);
		if (textChange instanceof TextFileChange) {
			TextFileChange tfc= (TextFileChange) textChange;
			tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
		}
		String message= RefactoringCoreMessages.DeleteChangeCreator_1;
		TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits);
		return textChange;
	} finally {
		RefactoringFileBuffers.release(cu);
	}
}
 
Example 2
Source File: DeleteChangeCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException {
	try {
		ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu);
		TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true));
		TextChange textChange= manager.get(cu);
		if (textChange instanceof TextFileChange) {
			TextFileChange tfc= (TextFileChange) textChange;
			tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE);
		}
		String message= RefactoringCoreMessages.DeleteChangeCreator_1;
		TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits);
		return textChange;
	} finally {
		RefactoringFileBuffers.release(cu);
	}
}
 
Example 3
Source File: ChangeConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _handleReplacements(ITextDocumentChange change) {
	if (!change.getReplacements().isEmpty()) {
		IFile file = resourceUriConverter.toFile(change.getOldURI());
		if (!canWrite(file)) {
			issues.add(RefactoringIssueAcceptor.Severity.FATAL, "Affected file '" + file.getFullPath() + "' is read-only");
		}
		checkDerived(file);
		List<ReplaceEdit> textEdits = change.getReplacements().stream().map(replacement -> {
			return new ReplaceEdit(replacement.getOffset(), replacement.getLength(), replacement.getReplacementText());
		}).collect(Collectors.toList());

		MultiTextEdit textEdit = new MultiTextEdit();
		textEdit.addChildren(textEdits.toArray(new TextEdit[textEdits.size()]));
		ITextEditor openEditor = findOpenEditor(file);
		final TextChange ltkChange;
		if (openEditor == null) {
			TextFileChange textFileChange = new TextFileChange(change.getOldURI().lastSegment(), file);
			textFileChange.setSaveMode(TextFileChange.FORCE_SAVE);
			ltkChange = textFileChange;
		} else {
			ltkChange = new EditorDocumentChange(currentChange.getName(), openEditor, false);
		}
		ltkChange.setEdit(textEdit);
		ltkChange.setTextType(change.getOldURI().fileExtension());
		addChange(ltkChange);
	}
}
 
Example 4
Source File: DefaultRefactoringDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(String name, TextEdit textEdit) {
	TextFileChange textFileChange = new TextFileChange(name, file);
	textFileChange.setSaveMode(TextFileChange.FORCE_SAVE);
	textFileChange.setEdit(textEdit);
	textFileChange.setTextType(getURI().fileExtension());
	return textFileChange;
}
 
Example 5
Source File: DefaultRefactoringDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(String name, TextEdit textEdit) {
	TextFileChange textFileChange = new TextFileChange(name, redirectedFile);
	textFileChange.setSaveMode(TextFileChange.FORCE_SAVE);
	textFileChange.setEdit(textEdit);
	textFileChange.setTextType(getURI().fileExtension());
	return textFileChange;
}