org.eclipse.xtext.ide.refactoring.IRenameStrategy2 Java Examples

The following examples show how to use org.eclipse.xtext.ide.refactoring.IRenameStrategy2. 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: DefaultRenameElementHandler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isRefactoringEnabled(IRenameElementContext renameElementContext, XtextResource resource) {
	ResourceSet resourceSet = resource.getResourceSet();
	if (renameElementContext != null && resourceSet != null) {
		EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
		if (targetElement != null && !targetElement.eIsProxy()) {
			if(targetElement.eResource() == resource && renameElementContext.getTriggeringEditorSelection() instanceof ITextSelection) {
				ITextSelection textSelection = (ITextSelection) renameElementContext.getTriggeringEditorSelection();
				ITextRegion selectedRegion = new TextRegion(textSelection.getOffset(), textSelection.getLength());
				INode crossReferenceNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, selectedRegion);
				if(crossReferenceNode == null) {
					// selection is on the declaration. make sure it's the name
					ITextRegion significantRegion = locationInFileProvider.getSignificantTextRegion(targetElement);
					if(!significantRegion.contains(selectedRegion)) 
						return false;
				}
			}
			IRenameStrategy.Provider renameStrategyProvider = globalServiceProvider.findService(targetElement,
					IRenameStrategy.Provider.class);
			try {
				if (renameStrategyProvider.get(targetElement, renameElementContext) != null) {
					return true;
				} else {
					IRenameStrategy2 strategy2 = globalServiceProvider.findService(targetElement, IRenameStrategy2.class); 
					ISimpleNameProvider simpleNameProvider = globalServiceProvider.findService(targetElement, ISimpleNameProvider.class); 
					return strategy2 != null && simpleNameProvider.canRename(targetElement);
				}
					
			} catch (NoSuchStrategyException e) {
				MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Cannot rename element",
						e.getMessage());
			}
		}
	}
	return false;
}
 
Example #2
Source File: AbstractTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #3
Source File: AbstractCodetemplatesIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #4
Source File: AbstractSingleCodetemplateIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #5
Source File: AbstractXtendIdeModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #6
Source File: AbstractRenameTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #7
Source File: AbstractIndentationAwareUiTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #8
Source File: AbstractPartialSerializationTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #9
Source File: AbstractPartialContentAssistTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #10
Source File: DefaultLinkedPositionGroupCalculator2.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@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));
	};
}
 
Example #11
Source File: AbstractXtextIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #12
Source File: AbstractFileAwareTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #13
Source File: AbstractXtextGrammarTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #14
Source File: AbstractNoJdtTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #15
Source File: AbstractNestedRefsTestLanguageIdeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #16
Source File: AbstractHelloWorldIdeModule.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #17
Source File: AbstractGamlIdeModule.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #18
Source File: AbstractSARLIdeModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #19
Source File: AbstractRefactoringTestLanguageIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #20
Source File: AbstractN4JSIdeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #21
Source File: AbstractJSONIdeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #22
Source File: AbstractTypesIdeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #23
Source File: AbstractBromiumIdeModule.java    From bromium with MIT License 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #24
Source File: AbstractPureXbaseIdeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #25
Source File: AbstractFileAwareTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #26
Source File: AbstractXmlIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #27
Source File: AbstractReferringTestLanguageIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #28
Source File: AbstractRegularExpressionIdeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #29
Source File: AbstractEcore2XtextTestIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}
 
Example #30
Source File: AbstractRefactoringTestLanguage2IdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
	return IRenameStrategy2.DefaultImpl.class;
}