org.eclipse.ltk.core.refactoring.participants.RenameArguments Java Examples

The following examples show how to use org.eclipse.ltk.core.refactoring.participants.RenameArguments. 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: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addAllResourceModifications(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages, IPackageFragment[] allSubPackages) throws CoreException {
	IFolder target= addResourceModifications(rootPackage, args, rootPackage, renameSubPackages);
	if (renameSubPackages) {
		IContainer container= (IContainer) rootPackage.getResource();
		if (container == null)
			return;
		boolean removeContainer= ! container.contains(target);
		for (int i= 0; i < allSubPackages.length; i++) {
			IPackageFragment pack= allSubPackages[i];
			IFolder subTarget= addResourceModifications(rootPackage, args, pack, renameSubPackages);
			if (container.contains(subTarget))
				removeContainer= false;
		}
		if (removeContainer) {
			getResourceModifications().addDelete(container);
		}
	}
}
 
Example #2
Source File: RenameFieldProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	result.rename(fField, new RenameArguments(getNewElementName(), getUpdateReferences()));
	if (fRenameGetter) {
		IMethod getter= getGetter();
		if (getter != null) {
			result.rename(getter, new RenameArguments(getNewGetterName(), getUpdateReferences()));
		}
	}
	if (fRenameSetter) {
		IMethod setter= getSetter();
		if (setter != null) {
			result.rename(setter, new RenameArguments(getNewSetterName(), getUpdateReferences()));
		}
	}
	return result;
}
 
Example #3
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private void addAllResourceModifications(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages, IPackageFragment[] allSubPackages) throws CoreException {
	IFolder target= addResourceModifications(rootPackage, args, rootPackage, renameSubPackages);
	if (renameSubPackages) {
		IContainer container= (IContainer) rootPackage.getResource();
		if (container == null) {
			return;
		}
		boolean removeContainer= ! container.contains(target);
		for (int i= 0; i < allSubPackages.length; i++) {
			IPackageFragment pack= allSubPackages[i];
			IFolder subTarget= addResourceModifications(rootPackage, args, pack, renameSubPackages);
			if (container.contains(subTarget)) {
				removeContainer= false;
			}
		}
		if (removeContainer) {
			getResourceModifications().addDelete(container);
		}
	}
}
 
Example #4
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IFolder addResourceModifications(IPackageFragment rootPackage, RenameArguments args, IPackageFragment pack, boolean renameSubPackages) throws CoreException {
	IContainer container= (IContainer)pack.getResource();
	if (container == null)
		return null;
	IFolder target= computeTargetFolder(rootPackage, args, pack);
	createIncludingParents(target);
	MoveArguments arguments= new MoveArguments(target, args.getUpdateReferences());
	IResource[] resourcesToMove= collectResourcesOfInterest(pack);
	Set<IResource> allMembers= new HashSet<IResource>(Arrays.asList(container.members()));
	for (int i= 0; i < resourcesToMove.length; i++) {
		IResource toMove= resourcesToMove[i];
		getResourceModifications().addMove(toMove, arguments);
		allMembers.remove(toMove);
	}
	for (Iterator<IResource> iter= allMembers.iterator(); iter.hasNext();) {
		IResource element= iter.next();
		if (element instanceof IFile) {
			getResourceModifications().addDelete(element);
			iter.remove();
		}
	}
	if (! renameSubPackages && allMembers.isEmpty()) {
		getResourceModifications().addDelete(container);
	}
	return target;
}
 
Example #5
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	result.rename(fField, new RenameArguments(getNewElementName(), getUpdateReferences()));
	if (fRenameGetter) {
		IMethod getter= getGetter();
		if (getter != null) {
			result.rename(getter, new RenameArguments(getNewGetterName(), getUpdateReferences()));
		}
	}
	if (fRenameSetter) {
		IMethod setter= getSetter();
		if (setter != null) {
			result.rename(setter, new RenameArguments(getNewSetterName(), getUpdateReferences()));
		}
	}
	return result;
}
 
Example #6
Source File: RenameMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	RenameArguments args= new RenameArguments(getNewElementName(), getUpdateReferences());
	for (Iterator<IMethod> iter= fMethodsToRename.iterator(); iter.hasNext();) {
		IMethod method= iter.next();
		result.rename(method, args);
	}
	return result;
}
 
Example #7
Source File: RenameCompilationUnitProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() {
	RenameModifications result= new RenameModifications();
	result.rename(fCu, new RenameArguments(getNewElementName(), getUpdateReferences()));
	if (fRenameTypeProcessor != null) {
		String newTypeName= removeFileNameExtension(getNewElementName());
		RenameTypeArguments arguments= new RenameTypeArguments(newTypeName, getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements());
		result.rename(fRenameTypeProcessor.getType(), arguments, getUpdateSimilarDeclarations()
			? new RenameTypeProcessor.ParticipantDescriptorFilter()
			: null);
	}
	return result;
}
 
Example #8
Source File: RenameTypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() {
	RenameModifications result= new RenameModifications();
	result.rename(fType, new RenameTypeArguments(getNewElementName(), getUpdateReferences(),
		getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter());
	if (isPrimaryType()) {
		ICompilationUnit cu= fType.getCompilationUnit();
		String newCUName= getNewCompilationUnit().getElementName();
		result.rename(cu, new RenameArguments(newCUName, getUpdateReferences()));
	}
	return result;
}
 
Example #9
Source File: ResourceModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds the given resource to the list of renamed
 * resources.
 *
 * @param rename the resource to be renamed
 * @param arguments the arguments of the rename
 */
public void addRename(IResource rename, RenameArguments arguments) {
	Assert.isNotNull(rename);
	Assert.isNotNull(arguments);
	if (fRename == null) {
		fRename= new ArrayList<IResource>(2);
		fRenameArguments= new ArrayList<RenameArguments>(2);
	}
	fRename.add(rename);
	fRenameArguments.add(arguments);
	if (fIgnoreCount == 0) {
		IPath newPath= rename.getFullPath().removeLastSegments(1).append(arguments.getNewName());
		internalAdd(new MoveDescription(rename, newPath));
	}
}
 
Example #10
Source File: XtextRenameResourceParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addElement(Object element, RefactoringArguments arguments) {
	if (arguments instanceof RenameArguments) {
		if (element instanceof IResource) {
			IPath oldPath = ((IResource) element).getFullPath();
			IPath newPath = oldPath.removeLastSegments(1).append(((RenameArguments) arguments).getNewName());
			processor.addChangedResource(((IResource) element), oldPath, newPath);
		}
	}
}
 
Example #11
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public RefactoringParticipant[] loadParticipants(RefactoringStatus status, RefactoringProcessor owner, String[] natures, SharableParticipants shared) {
	List<RefactoringParticipant> result= new ArrayList<RefactoringParticipant>();
	for (int i= 0; i < fRename.size(); i++) {
		result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status,
			owner, fRename.get(i),
			(RenameArguments) fRenameArguments.get(i),
			fParticipantDescriptorFilter.get(i),
			natures, shared)));
	}
	result.addAll(Arrays.asList(getResourceModifications().getParticipants(status, owner, natures, shared)));
	return result.toArray(new RefactoringParticipant[result.size()]);
}
 
Example #12
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void buildDelta(IResourceChangeDescriptionFactory builder) {
	for (int i= 0; i < fRename.size(); i++) {
		Object element= fRename.get(i);
		if (element instanceof IResource) {
			ResourceModifications.buildMoveDelta(builder, (IResource) element, (RenameArguments) fRenameArguments.get(i));
		}
	}
	getResourceModifications().buildDelta(builder);
}
 
Example #13
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void rename(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages) throws CoreException {
	add(rootPackage, args, null);
	IPackageFragment[] allSubPackages= null;
	if (renameSubPackages) {
		allSubPackages= getSubpackages(rootPackage);
		for (int i= 0; i < allSubPackages.length; i++) {
			IPackageFragment pack= allSubPackages[i];
			RenameArguments subArgs= new RenameArguments(
				getNewPackageName(rootPackage, args.getNewName(), pack.getElementName()),
				args.getUpdateReferences());
			add(pack, subArgs, null);
		}
	}
	IContainer container= (IContainer)rootPackage.getResource();
	if (container == null)
		return;
	IContainer target= (IContainer) ((IPackageFragmentRoot)rootPackage.getParent()).
		getPackageFragment(args.getNewName()).getResource();
	if ((!rootPackage.hasSubpackages() || renameSubPackages) && canMove(container, target)) {
		createIncludingParents(target.getParent());
		if (container.getParent().equals(target.getParent())) {
			getResourceModifications().addRename(container, new RenameArguments(target.getName(), args.getUpdateReferences()));
		} else {
			// This is a little tricky. The problem is that the refactoring participants
			// don't support a generic move like the resource API does. So for the delta
			// we generate one move, however for the participants we have to generate single
			// moves and deletes.
			try {
				getResourceModifications().ignoreForDelta();
				addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
			} finally {
				getResourceModifications().trackForDelta();
			}
			getResourceModifications().addDelta(new ResourceModifications.MoveDescription(container, target.getFullPath()));
		}
	} else {
		addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
	}
}
 
Example #14
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void rename(IJavaProject project, RenameArguments args) {
	add(project, args, null);
	IProject rProject= project.getProject();
	if (rProject != null) {
		getResourceModifications().addRename(rProject, args);
		IProject[] referencingProjects= rProject.getReferencingProjects();
		for (int i= 0; i < referencingProjects.length; i++) {
			IFile classpath= getClasspathFile(referencingProjects[i]);
			if (classpath != null) {
				getResourceModifications().addChanged(classpath);
			}
		}
	}
}
 
Example #15
Source File: NLSAccessorFieldRenameParticipant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean initialize(RefactoringProcessor processor, Object element, RefactoringArguments arguments) {
	fNewName= ((RenameArguments) arguments).getNewName();

	return super.initialize(processor, element, arguments);
}
 
Example #16
Source File: ResourceModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds the given resource to the list of renamed
 * resources.
 *
 * @param rename the resource to be renamed
 * @param arguments the arguments of the rename
 */
public void addRename(IResource rename, RenameArguments arguments) {
	Assert.isNotNull(rename);
	Assert.isNotNull(arguments);
	if (fRename == null) {
		fRename= new ArrayList<>(2);
		fRenameArguments= new ArrayList<>(2);
	}
	fRename.add(rename);
	fRenameArguments.add(arguments);
	if (fIgnoreCount == 0) {
		IPath newPath= rename.getFullPath().removeLastSegments(1).append(arguments.getNewName());
		internalAdd(new MoveDescription(rename, newPath));
	}
}
 
Example #17
Source File: RenameTypeProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() {
	RenameModifications result = new RenameModifications();
	result.rename(fType, new RenameTypeArguments(getNewElementName(), getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements()), createParticipantDescriptorFilter());
	if (isPrimaryType()) {
		ICompilationUnit cu = fType.getCompilationUnit();
		String newCUName = getNewCompilationUnit().getElementName();
		result.rename(cu, new RenameArguments(newCUName, getUpdateReferences()));
	}
	return result;
}
 
Example #18
Source File: RenameMethodProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	RenameArguments args= new RenameArguments(getNewElementName(), getUpdateReferences());
	for (Iterator<IMethod> iter= fMethodsToRename.iterator(); iter.hasNext();) {
		IMethod method= iter.next();
		result.rename(method, args);
	}
	return result;
}
 
Example #19
Source File: ArtifactProjectRenameRefactorParticipant.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean initialize(Object arg0) {
	if (arg0 instanceof IProject) {
		originalProject = (IProject) arg0;
		RenameArguments arguments = getArguments();
		latestName = arguments.getNewName();
		return true;
	}
	return false;
}
 
Example #20
Source File: RenameElementProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants)
		throws CoreException {
	RenameParticipant[] renameParticipants = ParticipantManager.loadRenameParticipants(status, this,
			renameElementContext, new RenameArguments(newName, true),
			new String[] { XtextProjectHelper.NATURE_ID }, sharedParticipants);
	return renameParticipants;
}
 
Example #21
Source File: RenameCompilationUnitProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() {
	RenameModifications result= new RenameModifications();
	result.rename(fCu, new RenameArguments(getNewElementName(), getUpdateReferences()));
	if (fRenameTypeProcessor != null) {
		String newTypeName= removeFileNameExtension(getNewElementName());
		RenameTypeArguments arguments= new RenameTypeArguments(newTypeName, getUpdateReferences(), getUpdateSimilarDeclarations(), getSimilarElements());
		result.rename(fRenameTypeProcessor.getType(), arguments, getUpdateSimilarDeclarations()
				? new RenameTypeProcessor.ParticipantDescriptorFilter()
			: null);
	}
	return result;
}
 
Example #22
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private IFolder addResourceModifications(IPackageFragment rootPackage, RenameArguments args, IPackageFragment pack, boolean renameSubPackages) throws CoreException {
	IContainer container= (IContainer)pack.getResource();
	if (container == null) {
		return null;
	}
	IFolder target= computeTargetFolder(rootPackage, args, pack);
	createIncludingParents(target);
	MoveArguments arguments= new MoveArguments(target, args.getUpdateReferences());
	IResource[] resourcesToMove= collectResourcesOfInterest(pack);
	Set<IResource> allMembers= new HashSet<>(Arrays.asList(container.members()));
	for (int i= 0; i < resourcesToMove.length; i++) {
		IResource toMove= resourcesToMove[i];
		getResourceModifications().addMove(toMove, arguments);
		allMembers.remove(toMove);
	}
	for (Iterator<IResource> iter= allMembers.iterator(); iter.hasNext();) {
		IResource element= iter.next();
		if (element instanceof IFile) {
			getResourceModifications().addDelete(element);
			iter.remove();
		}
	}
	if (! renameSubPackages && allMembers.isEmpty()) {
		getResourceModifications().addDelete(container);
	}
	return target;
}
 
Example #23
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public RefactoringParticipant[] loadParticipants(RefactoringStatus status, RefactoringProcessor owner, String[] natures, SharableParticipants shared) {
	List<RefactoringParticipant> result= new ArrayList<>();
	for (int i= 0; i < fRename.size(); i++) {
		result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status,
			owner, fRename.get(i),
			(RenameArguments) fRenameArguments.get(i),
			fParticipantDescriptorFilter.get(i),
			natures, shared)));
	}
	result.addAll(Arrays.asList(getResourceModifications().getParticipants(status, owner, natures, shared)));
	return result.toArray(new RefactoringParticipant[result.size()]);
}
 
Example #24
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void rename(IJavaProject project, RenameArguments args) {
	add(project, args, null);
	IProject rProject= project.getProject();
	if (rProject != null) {
		getResourceModifications().addRename(rProject, args);
		IProject[] referencingProjects= rProject.getReferencingProjects();
		for (int i= 0; i < referencingProjects.length; i++) {
			IFile classpath= getClasspathFile(referencingProjects[i]);
			if (classpath != null) {
				getResourceModifications().addChanged(classpath);
			}
		}
	}
}
 
Example #25
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void buildDelta(IResourceChangeDescriptionFactory builder) {
	for (int i= 0; i < fRename.size(); i++) {
		Object element= fRename.get(i);
		if (element instanceof IResource) {
			ResourceModifications.buildMoveDelta(builder, (IResource) element, (RenameArguments) fRenameArguments.get(i));
		}
	}
	getResourceModifications().buildDelta(builder);
}
 
Example #26
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void rename(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages) throws CoreException {
	add(rootPackage, args, null);
	IPackageFragment[] allSubPackages= null;
	if (renameSubPackages) {
		allSubPackages= getSubpackages(rootPackage);
		for (int i= 0; i < allSubPackages.length; i++) {
			IPackageFragment pack= allSubPackages[i];
			RenameArguments subArgs= new RenameArguments(
				getNewPackageName(rootPackage, args.getNewName(), pack.getElementName()),
				args.getUpdateReferences());
			add(pack, subArgs, null);
		}
	}
	IContainer container= (IContainer)rootPackage.getResource();
	if (container == null) {
		return;
	}
	IContainer target= (IContainer) ((IPackageFragmentRoot)rootPackage.getParent()).
		getPackageFragment(args.getNewName()).getResource();
	if ((!rootPackage.hasSubpackages() || renameSubPackages) && canMove(container, target)) {
		createIncludingParents(target.getParent());
		if (container.getParent().equals(target.getParent())) {
			getResourceModifications().addRename(container, new RenameArguments(target.getName(), args.getUpdateReferences()));
		} else {
			// This is a little tricky. The problem is that the refactoring participants
			// don't support a generic move like the resource API does. So for the delta
			// we generate one move, however for the participants we have to generate single
			// moves and deletes.
			try {
				getResourceModifications().ignoreForDelta();
				addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
			} finally {
				getResourceModifications().trackForDelta();
			}
			getResourceModifications().addDelta(new ResourceModifications.MoveDescription(container, target.getFullPath()));
		}
	} else {
		addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
	}
}
 
Example #27
Source File: RenameModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IFolder computeTargetFolder(IPackageFragment rootPackage, RenameArguments args, IPackageFragment pack) {
	IPath path= pack.getParent().getPath();
	path= path.append(getNewPackageName(rootPackage, args.getNewName(),  pack.getElementName()).replace('.', IPath.SEPARATOR));
	IFolder target= ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
	return target;
}
 
Example #28
Source File: RenameModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public void rename(ILocalVariable variable, RenameArguments args) {
	add(variable, args, null);
}
 
Example #29
Source File: RenameSourceFolderProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	result.rename(fSourceFolder, new RenameArguments(getNewElementName(), getUpdateReferences()));
	return result;
}
 
Example #30
Source File: RenameLocalVariableProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected RenameModifications computeRenameModifications() throws CoreException {
	RenameModifications result= new RenameModifications();
	result.rename(fLocalVariable, new RenameArguments(getNewElementName(), getUpdateReferences()));
	return result;
}