use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange in project che by eclipse.
the class RenameMethodProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
try {
final TextChange[] changes = fChangeManager.getAllChanges();
final List<TextChange> list = new ArrayList<TextChange>(changes.length);
list.addAll(Arrays.asList(changes));
String project = null;
IJavaProject javaProject = fMethod.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
try {
if (!Flags.isPrivate(fMethod.getFlags()))
flags |= RefactoringDescriptor.MULTI_CHANGE;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final IType declaring = fMethod.getDeclaringType();
try {
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.RenameMethodProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.RenameMethodProcessor_descriptor_description, new String[] { JavaElementLabels.getTextLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) });
final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(fMethod);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setKeepOriginal(fDelegateUpdating);
descriptor.setDeprecateDelegate(fDelegateDeprecation);
return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameMethodProcessor_change_name, list.toArray(new Change[list.size()]));
} finally {
monitor.done();
}
}
use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange in project che by eclipse.
the class RenameTypeProcessor method createChange.
@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 (//$NON-NLS-1$
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);
}
}
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;
}
}
use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fField.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
final IType declaring = fField.getDeclaringType();
try {
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.SelfEncapsulateField_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_getter_pattern, BasicElementLabels.getJavaElementName(fGetterName)));
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_setter_pattern, BasicElementLabels.getJavaElementName(fSetterName)));
String visibility = JdtFlags.getVisibilityString(fVisibility);
if (//$NON-NLS-1$
"".equals(visibility))
visibility = RefactoringCoreMessages.SelfEncapsulateField_default_visibility;
comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_visibility_pattern, visibility));
if (fEncapsulateDeclaringClass)
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_use_accessors);
else
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_do_not_use_accessors);
if (fGenerateJavadoc)
comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_generate_comments);
final EncapsulateFieldDescriptor descriptor = RefactoringSignatureDescriptorFactory.createEncapsulateFieldDescriptor(project, description, comment.asString(), arguments, flags);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fField));
arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
arguments.put(ATTRIBUTE_INSERTION, new Integer(fInsertionIndex).toString());
arguments.put(ATTRIBUTE_SETTER, fSetterName);
arguments.put(ATTRIBUTE_GETTER, fGetterName);
arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());
arguments.put(ATTRIBUTE_DECLARING, Boolean.valueOf(fEncapsulateDeclaringClass).toString());
final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, getName());
TextChange[] changes = fChangeManager.getAllChanges();
pm.beginTask(NO_NAME, changes.length);
pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_create_changes);
for (int i = 0; i < changes.length; i++) {
result.add(changes[i]);
pm.worked(1);
}
pm.done();
return result;
}
use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange in project che by eclipse.
the class IntroduceFactoryRefactoring method createChange.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
try {
pm.beginTask(RefactoringCoreMessages.IntroduceFactory_createChanges, fAllCallsTo.length);
final ITypeBinding binding = fFactoryOwningClass.resolveBinding();
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fCUHandle.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
if (binding.isNested() && !binding.isMember())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
final String description = Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fCtorOwningClass.getName().getIdentifier()));
final String header = Messages.format(RefactoringCoreMessages.IntroduceFactory_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fNewMethodName), BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(fCtorBinding, JavaElementLabels.ALL_FULLY_QUALIFIED) });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(fCtorBinding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_factory_pattern, BasicElementLabels.getJavaElementName(fNewMethodName)));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceFactoryRefactoring_owner_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
if (fProtectConstructor)
comment.addSetting(RefactoringCoreMessages.IntroduceFactoryRefactoring_declare_private);
final IntroduceFactoryDescriptor descriptor = RefactoringSignatureDescriptorFactory.createIntroduceFactoryDescriptor(project, description, comment.asString(), arguments, flags);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCUHandle));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fNewMethodName);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1, JavaRefactoringDescriptorUtil.elementToHandle(project, binding.getJavaElement()));
//$NON-NLS-1$
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString());
arguments.put(ATTRIBUTE_PROTECT, Boolean.valueOf(fProtectConstructor).toString());
final DynamicValidationStateChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.IntroduceFactory_name);
boolean hitInFactoryClass = false;
boolean hitInCtorClass = false;
for (int i = 0; i < fAllCallsTo.length; i++) {
SearchResultGroup rg = fAllCallsTo[i];
ICompilationUnit unitHandle = rg.getCompilationUnit();
CompilationUnitChange cuChange = new CompilationUnitChange(getName(), unitHandle);
if (addAllChangesFor(rg, unitHandle, cuChange))
result.add(cuChange);
if (unitHandle.equals(fFactoryUnitHandle))
hitInFactoryClass = true;
if (unitHandle.equals(ASTCreator.getCu(fCtorOwningClass)))
hitInCtorClass = true;
pm.worked(1);
if (pm.isCanceled())
throw new OperationCanceledException();
}
if (!hitInFactoryClass) {
// Handle factory class if no search hits there
CompilationUnitChange cuChange = new CompilationUnitChange(getName(), fFactoryUnitHandle);
addAllChangesFor(null, fFactoryUnitHandle, cuChange);
result.add(cuChange);
}
if (!hitInCtorClass && !fFactoryUnitHandle.equals(ASTCreator.getCu(fCtorOwningClass))) {
// Handle constructor-owning class if no search hits there
CompilationUnitChange cuChange = new CompilationUnitChange(getName(), ASTCreator.getCu(fCtorOwningClass));
addAllChangesFor(null, ASTCreator.getCu(fCtorOwningClass), cuChange);
result.add(cuChange);
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange in project che by eclipse.
the class IntroduceIndirectionRefactoring method createChange.
// ******************** CHANGE CREATION ***********************
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fTargetMethod.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
final IType declaring = fTargetMethod.getDeclaringType();
try {
if (declaring.isLocal() || declaring.isAnonymous())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fTargetMethod.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_descriptor_description, new String[] { JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_original_pattern, JavaElementLabels.getTextLabel(fTargetMethod, JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_method_pattern, BasicElementLabels.getJavaElementName(fIntermediaryMethodName)));
comment.addSetting(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_declaring_pattern, JavaElementLabels.getTextLabel(fIntermediaryType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
if (fUpdateReferences)
comment.addSetting(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references);
final IntroduceIndirectionDescriptor descriptor = RefactoringSignatureDescriptorFactory.createIntroduceIndirectionDescriptor(project, description, comment.asString(), arguments, flags);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fTargetMethod));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fIntermediaryMethodName);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + 1, JavaRefactoringDescriptorUtil.elementToHandle(project, fIntermediaryType));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES, Boolean.valueOf(fUpdateReferences).toString());
return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.IntroduceIndirectionRefactoring_introduce_indirection, fTextChangeManager.getAllChanges());
}
Aggregations