Java Code Examples for org.eclipse.xtext.ui.refactoring.IRefactoringUpdateAcceptor#accept()

The following examples show how to use org.eclipse.xtext.ui.refactoring.IRefactoringUpdateAcceptor#accept() . 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: N4JSRenameStrategy.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Custom logics for creating text edits for definitions of composed members
 */
@Override
public void createDeclarationUpdates(String newName, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {

	EObject targetElement = resourceSet.getEObject(getTargetElementOriginalURI(), true);
	if (TypeModelUtils.isComposedTElement(targetElement)) {
		// If target element is a composed element, create updates for its constituent members
		List<TMember> constituentMembers = ((TMember) targetElement).getConstituentMembers();
		for (TMember constituentMember : constituentMembers) {
			String text = newName;
			EAttribute att = getNameAttribute(constituentMember);
			ITextRegion nameRegion = getOriginalNameRegion(constituentMember, att);
			ReplaceEdit replaceEdit = new ReplaceEdit(nameRegion.getOffset(), nameRegion.getLength(), text);
			updateAcceptor.accept(EcoreUtil.getURI(constituentMember).trimFragment(),
					replaceEdit);
		}
	} else {
		updateAcceptor.accept(getTargetElementOriginalURI().trimFragment(), getDeclarationTextEdit(newName));
	}
}
 
Example 2
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void processReferringResource(Resource referringResource,
		Iterable<IReferenceDescription> referenceDescriptions, ElementRenameArguments elementRenameArguments,
		IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
	ImportAwareUpdateAcceptor importAwareUpdateAcceptor = createUpdateAcceptor(referringResource, updateAcceptor);
	
	Iterable<IReferenceDescription> importTypeReferences = getImportTypeReferences(referenceDescriptions);
	super.processReferringResource(referringResource, importTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor);
	
	importAwareUpdateAcceptor.getImportSection().update();
	
	Iterable<IReferenceDescription> notImportTypeReferences = getNotImportTypeReferences(referenceDescriptions);
	super.processReferringResource(referringResource, notImportTypeReferences, elementRenameArguments, importAwareUpdateAcceptor, monitor);
	
	List<ReplaceRegion> importChanges = importAwareUpdateAcceptor.getImportSection().rewrite();
	TextEdit importChangeEdit = replaceConverter.convertToTextEdit(importChanges);
	if(importChangeEdit != null) 
		updateAcceptor.accept(referringResource.getURI(), importChangeEdit);
}
 
Example 3
Source File: DotRenameStrategy.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void createDeclarationUpdates(String newName,
		ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	super.createDeclarationUpdates(newName, resourceSet, updateAcceptor);

	// perform renaming of the dependent element
	if (targetElement instanceof NodeId) {
		URI resourceURI = getTargetElementOriginalURI().trimFragment();

		NodeId targetNodeId = (NodeId) targetElement;
		List<NodeId> dependentNodeIds = DotAstHelper
				.getAllNodeIds(targetNodeId);

		for (NodeId dependentNodeId : dependentNodeIds) {
			ITextRegion dependentNodeIdTextRegion = locationInFileProvider
					.getFullTextRegion(dependentNodeId);
			TextEdit referenceEdit = new ReplaceEdit(
					dependentNodeIdTextRegion.getOffset(),
					dependentNodeIdTextRegion.getLength(), newName);
			updateAcceptor.accept(resourceURI, referenceEdit);
		}
	}
}
 
Example 4
Source File: EmfResourceChangeUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void addSaveAsUpdate(Resource resource, IRefactoringUpdateAcceptor updateAcceptor) throws IOException {
	IRefactoringDocument document = updateAcceptor.getDocument(resource.getURI());
	if (document == null) return;

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	resource.save(outputStream, null);
	String newContent = new String(outputStream.toByteArray(), encodingProvider.getEncoding(resource.getURI()));
	updateAcceptor.accept(resource.getURI(),
			new ReplaceEdit(0, document.getOriginalContents().length(), newContent));
}
 
Example 5
Source File: DefaultReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void createTextChange(ITextRegion referenceTextRegion, String newReferenceText,
		EObject referringElement, EObject newTargetElement, EReference reference, 
		URI referringResourceURI, IRefactoringUpdateAcceptor updateAcceptor) {
	if (newReferenceText != null) {
		TextEdit referenceEdit = new ReplaceEdit(referenceTextRegion.getOffset(),
				referenceTextRegion.getLength(), newReferenceText);
		updateAcceptor.accept(referringResourceURI, referenceEdit);
	}
}
 
Example 6
Source File: DotHtmlLabelRenameStrategy.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createDeclarationUpdates(String newName,
		ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	super.createDeclarationUpdates(newName, resourceSet, updateAcceptor);

	// perform renaming of the dependent element
	URI resourceURI = getTargetElementOriginalURI().trimFragment();

	if (targetElement instanceof HtmlTag) {
		HtmlTag htmlTag = (HtmlTag) targetElement;
		if (!htmlTag.isSelfClosing()) {
			List<INode> nodes = NodeModelUtils.findNodesForFeature(htmlTag,
					HtmllabelPackage.Literals.HTML_TAG__CLOSE_NAME);
			if (nodes.size() == 1) {
				INode node = nodes.get(0);
				TextEdit referenceEdit = new ReplaceEdit(node.getOffset(),
						node.getLength(), newName);
				updateAcceptor.accept(resourceURI, referenceEdit);
			} else {
				System.err.println(
						"Exact 1 node is expected for the name of the html closing tag, but got " //$NON-NLS-1$
								+ nodes.size());
			}

		}
	}
}
 
Example 7
Source File: XtendRenameStrategy.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void createDeclarationUpdates(String newName, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	super.createDeclarationUpdates(newName, resourceSet, updateAcceptor);
	IPath path = getPathToRename(getTargetElementOriginalURI(), resourceSet);
	if (path != null && path.lastSegment().equals(this.getOriginalName()+".xtend"))
		updateAcceptor.accept(getTargetElementOriginalURI().trimFragment(), new RenameResourceChange(path, newName
				+ "." + path.getFileExtension()));
}
 
Example 8
Source File: DefaultRenameStrategy.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createDeclarationUpdates(String newName, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	updateAcceptor.accept(getTargetElementOriginalURI().trimFragment(), getDeclarationTextEdit(newName));
}
 
Example 9
Source File: EcorePackageRenameStrategy.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public void createDeclarationUpdates(String newName, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor) {
	updateAcceptor.accept(this.uriProvider.apply(resourceSet),
			getDeclarationTextEdit(newName, resourceSet));
}