Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.refactoring.impl;
  
 import static com.google.common.collect.Iterables.*;
 import static com.google.common.collect.Lists.*;
 import static org.eclipse.ltk.core.refactoring.RefactoringStatus.*;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.eclipse.core.resources.IFile;
 import  org.eclipse.core.resources.IProject;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IProgressMonitor;
 import  org.eclipse.core.runtime.OperationCanceledException;
 import  org.eclipse.core.runtime.SubMonitor;
 import  org.eclipse.ltk.core.refactoring.Change;
 import  org.eclipse.ltk.core.refactoring.RefactoringStatus;
 import  org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
 import  org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
 import  org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
 import  org.eclipse.ltk.core.refactoring.participants.RenameArguments;
 import  org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
 import  org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
 
LTK org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor for an Xtext element rename refactoring.

Author(s):
Jan Koehnlein - Initial contribution and API
Holger Schill
 
 
 	protected static final Logger LOG = Logger.getLogger(RenameElementProcessor.class);
 
 
 
 
 
 
 
 	private String languageName;
 
 
 	private StatusWrapper status;
 
 	private URI targetElementURI;
 	private EObject targetElement;
 	private String newName;
 
	public boolean initialize(final IRenameElementContext renameElementContext) {
		try {
			this. = renameElementContext;
			this. = renameElementContext.getTargetElementURI();
			 = getResourceSet(renameElementContext);
			if ( == null) {
				.add(FATAL, "Rename target element {0} can not be resolved");
else {
				if (this. == null)
					return false;
			}
catch (NoSuchStrategyException e) {
			.add(FATAL, e.getMessage());
catch (Exception e) {
			throw (e instanceof RuntimeException) ? (RuntimeExceptione : new WrappedException(e);
		}
		return true;
	}
	protected ResourceSet getResourceSet(IRenameElementContext renameElementContext) {
		if ( == null)
			 = createResourceSet(renameElementContext);
		return ;
	}
	protected ResourceSet createResourceSet(IRenameElementContext renameElementContext) {
		IProject project = .getProject(renameElementContext.getTargetElementURI());
		if (project == null) {
			.add(FATAL, "Could not find project for "renameElementContext.getTargetElementURI());
			return null;
		}
		return  = .get(project);
	}
	protected boolean isValidTargetFile(Resource resourceStatusWrapper status) {
		IFile targetFile = .findFileStorage(resource.getURI(), true);
		if (targetFile != null)
			return true;
		String path = (resource.getURI().isPlatformResource()) 
resource.getURI().toPlatformString(true)
resource.getURI().toString();
		status.add(FATAL, "Rename target file '" + path + "' cannot be accessed"resource.getURI());
		return false;
	}
			IRenameElementContext renameElementContextthrows NoSuchStrategyException {
		IRenameStrategy result = .get(targetElementrenameElementContext);
		return result;
	}
	}
	public Object[] getElements() {
		return new Object[] {  };
	}
	public String getOriginalName() {
	}
	public RefactoringStatus validateNewName(String newName) {
	}
	protected String getLanguageName() {
		return ;
	}
	public String getIdentifier() {
		return getLanguageName() + ".ui.refactoring.Processor";
	}
		return "Rename element";
	}
	public boolean isApplicable() throws CoreException {
		return true;
	}
	public void setNewName(String newName) {
		this. = newName;
	}
	public String getNewName() {
		return ;
	}
	public RefactoringStatus checkInitialConditions(IProgressMonitor pmthrows CoreException,
			OperationCanceledException {
		if(!.getRefactoringStatus().hasFatalError())
	}
	protected Iterable<URIgetElementURIs() {
		List<URIelementURIs = newArrayList();
		for(Object elementgetElements()) {
			if(element instanceof URI
				elementURIs.add((URIelement);
		}
		return elementURIs;
	}
	public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context)
			throws CoreException, OperationCanceledException {
		SubMonitor progress = SubMonitor.convert(monitor, 100);
		try {
			Iterable<URIdependentElementURIs = .getDependentElementURIs(progress.newChild(1));
			Map<URIURIoriginal2newElementURIs = .renameAndTrack(
					concat(getElementURIs(), dependentElementURIs),
					progress.newChild(1));
			if (progress.isCanceled()) {
				throw new OperationCanceledException();
			}
					original2newElementURIs,
			if (progress.isCanceled()) {
				throw new OperationCanceledException();
			}
					progress.newChild(98));
catch (OperationCanceledException e) {
			throw e;
catch (Exception exc) {
		}
	}
	protected void transferChangeRedirector(IRefactoringUpdateAcceptor currentUpdateAcceptor2) {
	}
	public Change createChange(IProgressMonitor monitorthrows CoreException, OperationCanceledException {
monitor);
	}
	public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants)
			throws CoreException {
		RenameParticipant[] renameParticipants = ParticipantManager.loadRenameParticipants(statusthis,
				new RenameArguments(true),
				new String[] { . }, sharedParticipants);
		return renameParticipants;
	}
	protected void handleException(Exception excStatusWrapper status) {
		status.add(FATAL, "Error during refactoring: {0}"exc);
	}
	}
	}
	}
	protected EObject getTargetElement() {
	}
	}
New to GrepCode? Check out our FAQ X