Java Code Examples for org.eclipse.ltk.core.refactoring.TextChange#setKeepPreviewEdits()

The following examples show how to use org.eclipse.ltk.core.refactoring.TextChange#setKeepPreviewEdits() . 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: CUCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	StringBuffer buf= new StringBuffer();
	try {
		TextChange change= getTextChange();
		change.setKeepPreviewEdits(true);
		IDocument previewDocument= change.getPreviewDocument(monitor);
		TextEdit rootEdit= change.getPreviewEdit(change.getEdit());

		EditAnnotator ea= new EditAnnotator(buf, previewDocument);
		rootEdit.accept(ea);
		ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return buf.toString();
}
 
Example 2
Source File: RenameTypeProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void checkCUCompleteConditions(final RefactoringStatus status, CompilationUnit currentResolvedCU, ICompilationUnit currentCU, List<RefactoringProcessor> processors) throws CoreException {

		// check local variable conditions
		List<RefactoringProcessor> locals = getProcessorsOfType(processors, RenameLocalVariableProcessor.class);
		if (!locals.isEmpty()) {
			RenameAnalyzeUtil.LocalAnalyzePackage[] analyzePackages = new RenameAnalyzeUtil.LocalAnalyzePackage[locals.size()];
			TextChangeManager manager = new TextChangeManager();
			int current = 0;
			TextChange textChange = manager.get(currentCU);
			textChange.setKeepPreviewEdits(true);
			for (Iterator<RefactoringProcessor> iterator = locals.iterator(); iterator.hasNext();) {
				RenameLocalVariableProcessor localProcessor = (RenameLocalVariableProcessor) iterator.next();
				RenameAnalyzeUtil.LocalAnalyzePackage analyzePackage = localProcessor.getLocalAnalyzePackage();
				analyzePackages[current] = analyzePackage;
				for (int i = 0; i < analyzePackage.fOccurenceEdits.length; i++) {
					TextChangeCompatibility.addTextEdit(textChange, "", analyzePackage.fOccurenceEdits[i], GroupCategorySet.NONE); //$NON-NLS-1$
				}
				current++;
			}
			status.merge(RenameAnalyzeUtil.analyzeLocalRenames(analyzePackages, textChange, currentResolvedCU, false));
		}

		/*
		 * There is room for performance improvement here: One could move
		 * shadowing analyzes out of the field and method processors and perform
		 * it here, thus saving on working copy creation. Drawback is increased
		 * heap consumption.
		 */
	}
 
Example 3
Source File: RenameTypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkCUCompleteConditions(final RefactoringStatus status, CompilationUnit currentResolvedCU, ICompilationUnit currentCU, List<RefactoringProcessor> processors) throws CoreException {

		// check local variable conditions
		List<RefactoringProcessor> locals= getProcessorsOfType(processors, RenameLocalVariableProcessor.class);
		if (!locals.isEmpty()) {
			RenameAnalyzeUtil.LocalAnalyzePackage[] analyzePackages= new RenameAnalyzeUtil.LocalAnalyzePackage[locals.size()];
			TextChangeManager manager= new TextChangeManager();
			int current= 0;
			TextChange textChange= manager.get(currentCU);
			textChange.setKeepPreviewEdits(true);
			for (Iterator<RefactoringProcessor> iterator= locals.iterator(); iterator.hasNext();) {
				RenameLocalVariableProcessor localProcessor= (RenameLocalVariableProcessor) iterator.next();
				RenameAnalyzeUtil.LocalAnalyzePackage analyzePackage= localProcessor.getLocalAnalyzePackage();
				analyzePackages[current]= analyzePackage;
				for (int i= 0; i < analyzePackage.fOccurenceEdits.length; i++) {
					TextChangeCompatibility.addTextEdit(textChange, "", analyzePackage.fOccurenceEdits[i], GroupCategorySet.NONE); //$NON-NLS-1$
				}
				current++;
			}
			status.merge(RenameAnalyzeUtil.analyzeLocalRenames(analyzePackages, textChange, currentResolvedCU, false));
		}

		/*
		 * There is room for performance improvement here: One could move
		 * shadowing analyzes out of the field and method processors and perform
		 * it here, thus saving on working copy creation. Drawback is increased
		 * heap consumption.
		 */
	}
 
Example 4
Source File: PropertiesQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	final StringBuffer buf= new StringBuffer();

	try {
		for (int i= 0; i < fChanges.length; i++) {
			if (fChanges[i] instanceof TextChange) {
				TextChange change= (TextChange) fChanges[i];
				String filename= getFileName(change);
				if (filename != null) {
					buf.append("<b>"); //$NON-NLS-1$
					buf.append(filename);
					buf.append("</b>"); //$NON-NLS-1$
					buf.append("<br>"); //$NON-NLS-1$
				}
				change.setKeepPreviewEdits(true);
				IDocument currentContent= change.getCurrentDocument(monitor);

				TextEdit rootEdit= change.getEdit();

				EditAnnotator ea= new EditAnnotator(buf, currentContent) {
					@Override
					protected boolean rangeRemoved(TextEdit edit) {
						return annotateEdit(edit, "<del>", "</del>"); //$NON-NLS-1$ //$NON-NLS-2$
					}
				};
				rootEdit.accept(ea);
				ea.unchangedUntil(currentContent.getLength()); // Final pre-existing region
				buf.append("<br><br>"); //$NON-NLS-1$
			}
		}

	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return buf.toString();
}