Java Code Examples for org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext#getTargetElementURI()
The following examples show how to use
org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext#getTargetElementURI() .
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: RenameElementProcessor2.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public boolean initialize(IRenameElementContext renameElementContext) { this.renameElementContext = renameElementContext; status = statusProvider.get(); project = projectUtil.getProject(renameElementContext.getTargetElementURI().trimFragment()); if (project == null) { URI targetElementURI = renameElementContext.getTargetElementURI(); status.add(RefactoringIssueAcceptor.Severity.ERROR, // "Cannot determine project from targetURI " + (targetElementURI != null ? targetElementURI.toString() : null), // renameElementContext.getTargetElementURI()); return false; } resourceSet = resourceSetProvider.get(project); EObject target = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true); if (target == null) { status.add(RefactoringIssueAcceptor.Severity.ERROR, "Rename target does not exist", renameElementContext.getTargetElementURI()); } else { originalName = simpleNameProvider.getSimpleName(target); } return true; }
Example 2
Source File: EcorePackageRenameStrategy.java From sarl with Apache License 2.0 | 5 votes |
@Override public boolean initialize(EObject targetEObject, IRenameElementContext renameElementContext) { if (targetEObject instanceof SarlScript) { final SarlScript script = (SarlScript) targetEObject; this.currentPackageName = Strings.emptyIfNull(script.getPackage()); this.uriProvider = it -> renameElementContext.getTargetElementURI(); return true; } return false; }
Example 3
Source File: DefaultLinkedPositionGroupCalculator2.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public Provider<LinkedPositionGroup> getLinkedPositionGroup(IRenameElementContext renameElementContext, IProgressMonitor monitor) { SubMonitor progress = SubMonitor.convert(monitor, 100); XtextEditor editor = (XtextEditor) renameElementContext.getTriggeringEditor(); IProject project = projectUtil.getProject(renameElementContext.getContextResourceURI()); if (project == null) { throw new IllegalStateException( "Could not determine the project for context resource " + renameElementContext.getContextResourceURI()); } CachingResourceSetProvider cachingResourceSetProvider = new CachingResourceSetProvider(resourceSetProvider); ResourceSet resourceSet = cachingResourceSetProvider.get(project); EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true); if (targetElement == null) { throw new IllegalStateException("Target element could not be loaded"); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } IRenameStrategy2 renameStrategy = globalServiceProvider.findService(targetElement, IRenameStrategy2.class); if (renameStrategy == null) { throw new IllegalArgumentException("Cannot find a rename strategy for " + renameElementContext.getTargetElementURI()); } String oldName = simpleNameProvider.getSimpleName(targetElement); String newName = getNewDummyName(oldName); IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry .getResourceServiceProvider(renameElementContext.getTargetElementURI()); LtkIssueAcceptor issues = resourceServiceProvider.get(LtkIssueAcceptor.class); IChangeSerializer changeSerializer = resourceServiceProvider.get(IChangeSerializer.class); changeSerializer.setUpdateRelatedFiles(false); RenameChange change = new RenameChange(newName, renameElementContext.getTargetElementURI()); RenameContext renameContext = new RenameContext(Lists.newArrayList(change), resourceSet, changeSerializer, issues); renameStrategy.applyRename(renameContext); List<ReplaceEdit> replaceEdits = new ArrayList<>(); changeSerializer.applyModifications(c -> { if (c instanceof ITextDocumentChange) { ITextDocumentChange textDocumentChange = (ITextDocumentChange) c; textDocumentChange.getReplacements().forEach(replacement -> { replaceEdits.add(new ReplaceEdit(replacement.getOffset(), replacement.getLength(), replacement.getReplacementText())); }); } }); if (monitor.isCanceled()) { throw new OperationCanceledException(); } return () -> { return createLinkedGroupFromReplaceEdits(replaceEdits, editor, oldName, progress.newChild(10)); }; }