org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor Java Examples

The following examples show how to use org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor. 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: GhidraModuleUtils.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Renames the given Java element to the given new name.  Currently only supports renaming 
 * packages and compilation units.
 * 
 * @param element The Java element to rename.
 * @param newName The desired new name of the element.
 * @param monitor The progress monitor.
 * @throws CoreException If there is an Eclipse-related problem with the rename.
 * @throws IllegalArgumentException If the given Java element is not a package or compilation unit.
 */
private static void renameJavaElement(IJavaElement element, String newName,
		IProgressMonitor monitor) throws CoreException, IllegalArgumentException {
	String id;
	if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
		id = IJavaRefactorings.RENAME_PACKAGE;
	}
	else if (element.getElementType() == IJavaElement.COMPILATION_UNIT) {
		id = IJavaRefactorings.RENAME_COMPILATION_UNIT;
	}
	else {
		throw new IllegalArgumentException("Can only rename packages and compilation units!");
	}
	RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(id);
	RenameJavaElementDescriptor descriptor =
		(RenameJavaElementDescriptor) contribution.createDescriptor();
	descriptor.setProject(element.getResource().getProject().getName());
	descriptor.setNewName(newName);
	descriptor.setJavaElement(element);
	RefactoringStatus status = new RefactoringStatus();
	Refactoring refactoring = descriptor.createRefactoring(status);
	refactoring.checkInitialConditions(monitor);
	refactoring.checkFinalConditions(monitor);
	Change change = refactoring.createChange(monitor);
	change.perform(monitor);
}
 
Example #2
Source File: RenamePackageProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RenameJavaElementDescriptor createRefactoringDescriptor() {
	String project= null;
	IJavaProject javaProject= fPackage.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final String description= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
	final String header= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName()});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	if (fRenameSubpackages)
		comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment.asString());
	descriptor.setFlags(flags);
	descriptor.setJavaElement(fPackage);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
	if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) //$NON-NLS-1$
		descriptor.setFileNamePatterns(fFilePatterns);
	descriptor.setUpdateHierarchy(fRenameSubpackages);
	return descriptor;
}
 
Example #3
Source File: RenamePackageProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
		final RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
		result.addAll(fChangeManager.getAllChanges());
		fRenamePackageChange= new RenamePackageChange( fPackage, getNewElementName(),  fRenameSubpackages);
		result.add(fRenamePackageChange);
		monitor.worked(1);
		return result;
	} finally {
		fChangeManager= null;
		fImportsManager= null;
		monitor.done();
	}
}
 
Example #4
Source File: JvmRenameRefactoringProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ProcessorBasedRefactoring getRenameRefactoring(IRenameElementContext renameElementContext) {
	if (renameElementContext instanceof JdtRefactoringContext) {
		IJavaElement javaElement = ((JdtRefactoringContext) renameElementContext).getJavaElement();
		if (isJavaSource(javaElement)) {
			try {
				RenameJavaElementDescriptor renameDescriptor = createRenameDescriptor(javaElement,
						javaElement.getElementName());
				return (ProcessorBasedRefactoring) renameDescriptor.createRefactoring(new RefactoringStatus());
			} catch (Exception exc) {
				throw new WrappedException(exc);
			}
		}
	}
	return super.getRenameRefactoring(renameElementContext);
}
 
Example #5
Source File: PairedInterfaceRenameParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureDescriptor(RenameJavaElementDescriptor descriptor) {
  descriptor.setJavaElement(pairedType);
  descriptor.setNewName(pairedNewName);
  descriptor.setProject(pairedType.getJavaProject().getProject().getName());

  // getFilePatterns and getMatchStrategy could return uninitialized values
  // if they have not been explicitly set

  String filePatterns = processor.getFilePatterns();
  if (filePatterns != null) {
    descriptor.setFileNamePatterns(filePatterns);
  }

  int strategy = processor.getMatchStrategy();
  if (strategy == RenameJavaElementDescriptor.STRATEGY_EXACT
      || strategy == RenameJavaElementDescriptor.STRATEGY_EMBEDDED
      || strategy == RenameJavaElementDescriptor.STRATEGY_SUFFIX) {
    descriptor.setMatchStrategy(strategy);
  }

  descriptor.setUpdateQualifiedNames(processor.getUpdateQualifiedNames());
  descriptor.setUpdateReferences(processor.getUpdateReferences());
  descriptor.setUpdateSimilarDeclarations(processor.getUpdateSimilarDeclarations());
  descriptor.setUpdateTextualOccurrences(processor.getUpdateTextualMatches());
}
 
Example #6
Source File: RenameLocalVariableProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private RenameJavaElementDescriptor createRefactoringDescriptor() {
	String project= null;
	IJavaProject javaProject= fCu.getJavaProject();
	if (javaProject != null) {
		project= javaProject.getElementName();
	}
	final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)});
	final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(RefactoringDescriptor.NONE);
	descriptor.setJavaElement(fLocalVariable);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	return descriptor;
}
 
Example #7
Source File: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
		final RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
		result.addAll(fChangeManager.getAllChanges());
		fRenamePackageChange= new RenamePackageChange( fPackage, getNewElementName(),  fRenameSubpackages);
		result.add(fRenamePackageChange);
		monitor.worked(1);
		return result;
	} finally {
		fChangeManager= null;
		fImportsManager= null;
		monitor.done();
	}
}
 
Example #8
Source File: RenameJavaProjectProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask("", 1); //$NON-NLS-1$
		final String description= Messages.format(RefactoringCoreMessages.RenameJavaProjectProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fProject.getElementName()));
		final String header= Messages.format(RefactoringCoreMessages.RenameJavaProjectChange_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fProject.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName())});
		final String comment= new JDTRefactoringDescriptorComment(null, this, header).asString();
		final int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.BREAKING_CHANGE;
		final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_JAVA_PROJECT);
		descriptor.setProject(null);
		descriptor.setDescription(description);
		descriptor.setComment(comment);
		descriptor.setFlags(flags);
		descriptor.setJavaElement(fProject);
		descriptor.setNewName(getNewElementName());
		descriptor.setUpdateReferences(fUpdateReferences);
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameJavaProjectRefactoring_rename, new Change[] { new RenameJavaProjectChange(fProject, getNewElementName(), fUpdateReferences)});
	} finally {
		monitor.done();
	}
}
 
Example #9
Source File: RenameSourceFolderProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
	try {
		final IResource resource= fSourceFolder.getResource();
		final String project= resource.getProject().getName();
		final String newName= getNewElementName();
		final String description= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
		final String header= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName)});
		final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
		final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
		descriptor.setProject(project);
		descriptor.setDescription(description);
		descriptor.setComment(comment);
		descriptor.setFlags(RefactoringDescriptor.NONE);
		descriptor.setJavaElement(fSourceFolder);
		descriptor.setNewName(newName);
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName)});
	} finally {
		monitor.done();
	}
}
 
Example #10
Source File: RenameLocalVariableProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RenameJavaElementDescriptor createRefactoringDescriptor() {
	String project= null;
	IJavaProject javaProject= fCu.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)});
	final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(RefactoringDescriptor.NONE);
	descriptor.setJavaElement(fLocalVariable);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	return descriptor;
}
 
Example #11
Source File: PairedInterfaceRenameParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public InterfaceRenameChangeBuilder(IType pairedType, String pairedNewName,
    RenameTypeProcessor processor, IWorkspace workspace) {
  super(RenameJavaElementDescriptor.class, IJavaRefactorings.RENAME_TYPE,
      workspace);

  this.processor = processor;
  this.pairedType = pairedType;
  this.pairedNewName = pairedNewName;
}
 
Example #12
Source File: JdtRenameSupport.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IRenameSupport create(Object context, String newName) {
	if (context instanceof JdtRefactoringContext) {
		try {
			RenameJavaElementDescriptor descriptor = createDescriptor((JdtRefactoringContext) context, newName);
			JdtRenameSupport jdtRenameSupport = jdtRenameSupportProvider.get();
			jdtRenameSupport.initialize((JdtRefactoringContext) context, descriptor);
			return jdtRenameSupport;
		} catch (Exception exc) {
			throw new WrappedException(exc);
		}
	}
	return super.create(context, newName);
}
 
Example #13
Source File: RenameLocalVariableProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameTypeProcessor_creating_changes, 1);

		RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
		return fChange;
	} finally {
		monitor.done();
	}
}
 
Example #14
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
		TextChange[] changes= fChangeManager.getAllChanges();
		RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
	} finally {
		monitor.done();
	}
}
 
Example #15
Source File: RenameEnumConstProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
	final IField field= getField();
	String project= null;
	IJavaProject javaProject= field.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
	final IType declaring= field.getDeclaringType();
	try {
		if (!Flags.isPrivate(declaring.getFlags()))
			flags|= RefactoringDescriptor.MULTI_CHANGE;
		if (declaring.isAnonymous() || declaring.isLocal())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(field.getElementName()), JavaElementLabels.getElementLabel(field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_ENUM_CONSTANT);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(flags);
	descriptor.setJavaElement(field);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	return descriptor;
}
 
Example #16
Source File: RenameTypeParameterProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	try {
		Change change= fChange;
		if (change != null) {
			String project= null;
			IJavaProject javaProject= fTypeParameter.getJavaProject();
			if (javaProject != null)
				project= javaProject.getElementName();
			String description= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()));
			String header= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
			String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
			RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER);
			descriptor.setProject(project);
			descriptor.setDescription(description);
			descriptor.setComment(comment);
			descriptor.setFlags(RefactoringDescriptor.NONE);
			descriptor.setJavaElement(fTypeParameter);
			descriptor.setNewName(getNewElementName());
			descriptor.setUpdateReferences(fUpdateReferences);
			change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change});
		}
		return change;
	} finally {
		fChange= null;
		monitor.done();
	}
}
 
Example #17
Source File: RenameSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RenameSupport(RenameJavaElementDescriptor descriptor) throws CoreException {
	RefactoringStatus refactoringStatus= new RefactoringStatus();
	fRefactoring= (RenameRefactoring) descriptor.createRefactoring(refactoringStatus);
	if (refactoringStatus.hasFatalError()) {
		fPreCheckStatus= refactoringStatus;
	} else {
		preCheck();
		refactoringStatus.merge(fPreCheckStatus);
		fPreCheckStatus= refactoringStatus;
	}
}
 
Example #18
Source File: PairedMethodRenameParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configureDescriptor(RenameJavaElementDescriptor descriptor) {
  descriptor.setJavaElement(method);
  descriptor.setNewName(newName);
  descriptor.setProject(method.getJavaProject().getProject().getName());
  descriptor.setKeepOriginal(processor.getDelegateUpdating());
  descriptor.setDeprecateDelegate(processor.getDeprecateDelegates());
  descriptor.setUpdateReferences(processor.getUpdateReferences());
}
 
Example #19
Source File: PairedMethodRenameParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public MethodRenameChangeBuilder(IMethod method, String newName,
    RenameVirtualMethodProcessor processor, IWorkspace workspace) {
  super(RenameJavaElementDescriptor.class, IJavaRefactorings.RENAME_METHOD,
      workspace);

  this.newName = newName;
  this.processor = processor;
  this.method = method;
}
 
Example #20
Source File: RenamePackageProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RenameJavaElementDescriptor createRefactoringDescriptor() {
	String project= null;
	IJavaProject javaProject= fPackage.getJavaProject();
	if (javaProject != null) {
		project= javaProject.getElementName();
	}
	final int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final String description= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
	final String header= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName()});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	if (fRenameSubpackages) {
		comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
	}
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment.asString());
	descriptor.setFlags(flags);
	descriptor.setJavaElement(fPackage);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
	if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) {
		descriptor.setFileNamePatterns(fFilePatterns);
	}
	descriptor.setUpdateHierarchy(fRenameSubpackages);
	return descriptor;
}
 
Example #21
Source File: RenameTypeParameterProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	try {
		Change change= fChange;
		if (change != null) {
			String project= null;
			IJavaProject javaProject= fTypeParameter.getJavaProject();
			if (javaProject != null) {
				project= javaProject.getElementName();
			}
			String description= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()));
			String header= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
			String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
			RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER);
			descriptor.setProject(project);
			descriptor.setDescription(description);
			descriptor.setComment(comment);
			descriptor.setFlags(RefactoringDescriptor.NONE);
			descriptor.setJavaElement(fTypeParameter);
			descriptor.setNewName(getNewElementName());
			descriptor.setUpdateReferences(fUpdateReferences);
			change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change});
		}
		return change;
	} finally {
		fChange= null;
		monitor.done();
	}
}
 
Example #22
Source File: RenameEnumConstProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
	final IField field= getField();
	String project= null;
	IJavaProject javaProject= field.getJavaProject();
	if (javaProject != null) {
		project= javaProject.getElementName();
	}
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
	final IType declaring= field.getDeclaringType();
	try {
		if (!Flags.isPrivate(declaring.getFlags())) {
			flags|= RefactoringDescriptor.MULTI_CHANGE;
		}
		if (declaring.isAnonymous() || declaring.isLocal()) {
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		}
	} catch (JavaModelException exception) {
		JavaLanguageServerPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(field.getElementName()), JavaElementLabels.getElementLabel(field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_ENUM_CONSTANT);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(flags);
	descriptor.setJavaElement(field);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	return descriptor;
}
 
Example #23
Source File: RenameSupport.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private RenameSupport(RenameJavaElementDescriptor descriptor) throws CoreException {
	RefactoringStatus refactoringStatus= new RefactoringStatus();
	fRefactoring= (RenameRefactoring) descriptor.createRefactoring(refactoringStatus);
	if (refactoringStatus.hasFatalError()) {
		fPreCheckStatus= refactoringStatus;
	} else {
		preCheck();
		refactoringStatus.merge(fPreCheckStatus);
		fPreCheckStatus= refactoringStatus;
	}
}
 
Example #24
Source File: RenameFieldProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
		TextChange[] changes= fChangeManager.getAllChanges();
		RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
	} finally {
		monitor.done();
	}
}
 
Example #25
Source File: RenameLocalVariableProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameTypeProcessor_creating_changes, 1);

		RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
		fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
		return fChange;
	} finally {
		monitor.done();
	}
}
 
Example #26
Source File: RenameTypeProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4);
		String project = null;
		IJavaProject javaProject = fType.getJavaProject();
		if (javaProject != null) {
			project = javaProject.getElementName();
		}
		int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
		try {
			if (!Flags.isPrivate(fType.getFlags())) {
				flags |= RefactoringDescriptor.MULTI_CHANGE;
			}
			if (fType.isAnonymous() || fType.isLocal()) {
				flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
			}
		} catch (JavaModelException exception) {
			JavaLanguageServerPlugin.log(exception);
		}
		final String description = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName()));
		final String header = Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementLabel() });
		final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
		final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
		descriptor.setProject(project);
		descriptor.setDescription(description);
		descriptor.setComment(comment);
		descriptor.setFlags(flags);
		descriptor.setJavaElement(fType);
		descriptor.setNewName(getNewElementName());
		descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
		descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
		descriptor.setUpdateReferences(fUpdateReferences);
		if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) {
			descriptor.setFileNamePatterns(fFilePatterns);
		}
		descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements);
		descriptor.setMatchStrategy(fRenamingStrategy);
		final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name);

		if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) {
			TextChange textChange = fChangeManager.get(fType.getCompilationUnit());
			if (textChange instanceof TextFileChange) {
				((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE);
			}
		}

		if (willRenameCU()) {
			IResource resource = fType.getCompilationUnit().getResource();
			if (resource != null && resource.isLinked()) {
				result.addAll(fChangeManager.getAllChanges());
				String ext = resource.getFileExtension();
				String renamedResourceName;
				if (ext == null) {
					renamedResourceName = getNewElementName();
				} else {
					renamedResourceName = getNewElementName() + '.' + ext;
				}
				result.add(new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName));
			} else {
				addTypeDeclarationUpdate(fChangeManager);
				addConstructorRenames(fChangeManager);

				result.addAll(fChangeManager.getAllChanges());

				String renamedCUName = JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName());
				result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName));
			}
		} else {
			result.addAll(fChangeManager.getAllChanges());
		}

		monitor.worked(1);
		return result;
	} finally {
		fChangeManager = null;
	}
}
 
Example #27
Source File: RenameTypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 4);
		String project= null;
		IJavaProject javaProject= fType.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
		try {
			if (!Flags.isPrivate(fType.getFlags()))
				flags|= RefactoringDescriptor.MULTI_CHANGE;
			if (fType.isAnonymous() || fType.isLocal())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName()));
		final String header= Messages.format(RefactoringCoreMessages.RenameTypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementLabel()});
		final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
		final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
		descriptor.setProject(project);
		descriptor.setDescription(description);
		descriptor.setComment(comment);
		descriptor.setFlags(flags);
		descriptor.setJavaElement(fType);
		descriptor.setNewName(getNewElementName());
		descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
		descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
		descriptor.setUpdateReferences(fUpdateReferences);
		if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) //$NON-NLS-1$
			descriptor.setFileNamePatterns(fFilePatterns);
		descriptor.setUpdateSimilarDeclarations(fUpdateSimilarElements);
		descriptor.setMatchStrategy(fRenamingStrategy);
		final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeProcessor_change_name);

		if (fChangeManager.containsChangesIn(fType.getCompilationUnit())) {
			TextChange textChange= fChangeManager.get(fType.getCompilationUnit());
			if (textChange instanceof TextFileChange) {
				((TextFileChange) textChange).setSaveMode(TextFileChange.FORCE_SAVE);
			}
		}
		result.addAll(fChangeManager.getAllChanges());
		if (willRenameCU()) {
			IResource resource= fType.getCompilationUnit().getResource();
			if (resource != null && resource.isLinked()) {
				String ext= resource.getFileExtension();
				String renamedResourceName;
				if (ext == null)
					renamedResourceName= getNewElementName();
				else
					renamedResourceName= getNewElementName() + '.' + ext;
				result.add(new RenameResourceChange(fType.getCompilationUnit().getPath(), renamedResourceName));
			} else {
				String renamedCUName= JavaModelUtil.getRenamedCUName(fType.getCompilationUnit(), getNewElementName());
				result.add(new RenameCompilationUnitChange(fType.getCompilationUnit(), renamedCUName));
			}
		}
		monitor.worked(1);
		return result;
	} finally {
		fChangeManager= null;
	}
}
 
Example #28
Source File: JdtRenameSupport.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void initialize(JdtRefactoringContext renameParticipantContext,
		RenameJavaElementDescriptor renameDescriptor) throws CoreException {
	renameSupport = RenameSupport.create(renameDescriptor);
}
 
Example #29
Source File: JdtRenameSupport.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated Use DI and {@link #initialize(JdtRefactoringContext, RenameJavaElementDescriptor)} instead.
 */
@Deprecated
public JdtRenameSupport(RenameJavaElementDescriptor renameDescriptor) throws CoreException {
	renameSupport = RenameSupport.create(renameDescriptor);
}
 
Example #30
Source File: JdtRenameSupport.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Deprecated
protected RenameJavaElementDescriptor createDescriptor(JdtRefactoringContext renameElementContext,
		String newName) throws JavaModelException {
	return jvmRenameRefactorigProvider.createRenameDescriptor(renameElementContext.getJavaElement(), newName);
}