Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringDescriptor#MULTI_CHANGE

The following examples show how to use org.eclipse.ltk.core.refactoring.RefactoringDescriptor#MULTI_CHANGE . 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: ReplaceInvocationsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	// TODO: update for fSelectionStart == -1
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fSelectionTypeRoot.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final IMethodBinding binding= fSourceProvider.getDeclaration().resolveBinding();
	int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	if (!Modifier.isPrivate(binding.getModifiers()))
		flags|= RefactoringDescriptor.MULTI_CHANGE;
	final String description= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName()));
	final String header= Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringClass(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.ReplaceInvocationsRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	if (!fTargetProvider.isSingle())
		comment.addSetting(RefactoringCoreMessages.ReplaceInvocationsRefactoring_replace_references);
	final JavaRefactoringDescriptor descriptor= new JavaRefactoringDescriptor(ID_REPLACE_INVOCATIONS, project, description, comment.asString(), arguments, flags){}; //REVIEW Unregistered ID!
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionTypeRoot));
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$
	arguments.put(ATTRIBUTE_MODE, new Integer(fTargetProvider.isSingle() ? 0 : 1).toString());
	return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ReplaceInvocationsRefactoring_change_name, fChangeManager.getAllChanges());
}
 
Example 2
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<String, String>();
	final int length= fPackageFragmentRoots.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1 ? Messages.format(getHeaderPatternSingular(), new String[] { fPackageFragmentRoots[0].getElementName(), getDestinationLabel() }) : Messages.format(
			getHeaderPatternPlural(), new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_ROOTS, new Integer(fPackageFragmentRoots.length).toString());
	for (int offset= 0; offset < fPackageFragmentRoots.length; offset++)
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fPackageFragmentRoots[offset]));
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 3
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 4
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<String, String>();
	final int length= fJavaElements.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1 ? Messages.format(getHeaderPatternSingular(), new String[] {
			JavaElementLabels.getTextLabel(fJavaElements[0].getElementName(), JavaElementLabels.ALL_FULLY_QUALIFIED), getDestinationLabel() }) : Messages.format(getHeaderPatternPlural(),
			new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_MIGRATION | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_MEMBERS, new Integer(fJavaElements.length).toString());
	for (int offset= 0; offset < fJavaElements.length; offset++)
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fJavaElements[offset]));
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 5
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<String, String>();
	final int length= fPackageFragments.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1
			? Messages.format(getHeaderPatternSingular(), new String[] { (fPackageFragments[0]).getElementName(), getDestinationLabel() })
			: Messages.format(getHeaderPatternPlural(), new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_MIGRATION | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_FRAGMENTS, new Integer(fPackageFragments.length).toString());
	for (int offset= 0; offset < fPackageFragments.length; offset++)
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fPackageFragments[offset]));
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 6
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<>();
	final int length= fJavaElements.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1 ? Messages.format(getHeaderPatternSingular(), new String[] {
			JavaElementLabels.getTextLabel(fJavaElements[0].getElementName(), JavaElementLabels.ALL_FULLY_QUALIFIED), getDestinationLabel() }) : Messages.format(getHeaderPatternPlural(),
			new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_MIGRATION | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_MEMBERS, new Integer(fJavaElements.length).toString());
	for (int offset= 0; offset < fJavaElements.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fJavaElements[offset]));
	}
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 7
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<>();
	final int length= fPackageFragments.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1
			? Messages.format(getHeaderPatternSingular(), new String[] { (fPackageFragments[0]).getElementName(), getDestinationLabel() })
			: Messages.format(getHeaderPatternPlural(), new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_MIGRATION | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_FRAGMENTS, new Integer(fPackageFragments.length).toString());
	for (int offset= 0; offset < fPackageFragments.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fPackageFragments[offset]));
	}
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 8
Source File: ExtractClassRefactoringDescriptor.java    From JDeodorant with MIT License 5 votes vote down vote up
protected ExtractClassRefactoringDescriptor(String project, String description, String comment,
		CompilationUnit sourceCompilationUnit, TypeDeclaration sourceTypeDeclaration, IFile sourceFile,
		Set<VariableDeclaration> extractedFieldFragments, Set<MethodDeclaration> extractedMethods,
		Set<MethodDeclaration> delegateMethods, String extractedTypeName) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.sourceCompilationUnit = sourceCompilationUnit;
	this.sourceTypeDeclaration = sourceTypeDeclaration;
	this.sourceFile = sourceFile;
	this.extractedFieldFragments = extractedFieldFragments;
	this.extractedMethods = extractedMethods;
	this.delegateMethods = delegateMethods;
	this.extractedTypeName = extractedTypeName;
}
 
Example 9
Source File: ReplaceConditionalWithPolymorphismDescriptor.java    From JDeodorant with MIT License 5 votes vote down vote up
protected ReplaceConditionalWithPolymorphismDescriptor(String project, String description, String comment,
		IFile sourceFile, CompilationUnit sourceCompilationUnit,
		TypeDeclaration sourceTypeDeclaration, TypeCheckElimination typeCheckElimination) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.sourceFile = sourceFile;
	this.sourceCompilationUnit = sourceCompilationUnit;
	this.sourceTypeDeclaration = sourceTypeDeclaration;
	this.typeCheckElimination = typeCheckElimination;
}
 
Example 10
Source File: MoveMethodRefactoringDescriptor.java    From JDeodorant with MIT License 5 votes vote down vote up
public MoveMethodRefactoringDescriptor(String project, String description, String comment,
		CompilationUnit sourceCompilationUnit, CompilationUnit targetCompilationUnit, 
		TypeDeclaration sourceTypeDeclaration, TypeDeclaration targetTypeDeclaration, MethodDeclaration sourceMethod,
		Map<MethodInvocation, MethodDeclaration> additionalMethodsToBeMoved, boolean leaveDelegate, String movedMethodName) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.sourceCompilationUnit = sourceCompilationUnit;
	this.targetCompilationUnit = targetCompilationUnit;
	this.sourceTypeDeclaration = sourceTypeDeclaration;
	this.targetTypeDeclaration = targetTypeDeclaration;
	this.sourceMethod = sourceMethod;
	this.additionalMethodsToBeMoved = additionalMethodsToBeMoved;
	this.leaveDelegate = leaveDelegate;
	this.movedMethodName = movedMethodName;
}
 
Example 11
Source File: InlineConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	try {
		pm.beginTask(RefactoringCoreMessages.InlineConstantRefactoring_preview, 2);
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		IJavaProject javaProject= fSelectionCu.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		try {
			if (!Flags.isPrivate(fField.getFlags()))
				flags|= RefactoringDescriptor.MULTI_CHANGE;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description_short, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_DEFAULT));
		final String header= Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		comment.addSetting(Messages.format(RefactoringCoreMessages.InlineConstantRefactoring_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		if (fRemoveDeclaration)
			comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_remove_declaration);
		if (fReplaceAllReferences)
			comment.addSetting(RefactoringCoreMessages.InlineConstantRefactoring_replace_references);
		final InlineConstantDescriptor descriptor= RefactoringSignatureDescriptorFactory.createInlineConstantDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSelectionCu));
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); //$NON-NLS-1$
		arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemoveDeclaration).toString());
		arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllReferences).toString());
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.InlineConstantRefactoring_inline, fChanges);
	} finally {
		pm.done();
		fChanges= null;
	}
}
 
Example 12
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public final ChangeDescriptor getDescriptor() {
	final Map<String, String> arguments= new HashMap<>();
	final int length= fFiles.length + fFolders.length + fCus.length;
	final String description= length == 1 ? getDescriptionSingular() : getDescriptionPlural();
	final IProject resource= getSingleProject();
	final String project= resource != null ? resource.getName() : null;
	final String header= length == 1 ? Messages.format(getHeaderPatternSingular(), new String[] { getSingleElementName(), getDestinationLabel() }) : Messages.format(
			getHeaderPatternPlural(),
			new String[] { String.valueOf(length), getDestinationLabel() });
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	arguments.put(ATTRIBUTE_POLICY, getPolicyId());
	arguments.put(ATTRIBUTE_FILES, new Integer(fFiles.length).toString());
	for (int offset= 0; offset < fFiles.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.resourceToHandle(project, fFiles[offset]));
	}
	arguments.put(ATTRIBUTE_FOLDERS, new Integer(fFolders.length).toString());
	for (int offset= 0; offset < fFolders.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fFiles.length + 1), JavaRefactoringDescriptorUtil.resourceToHandle(project, fFolders[offset]));
	}
	arguments.put(ATTRIBUTE_UNITS, new Integer(fCus.length).toString());
	for (int offset= 0; offset < fCus.length; offset++) {
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fFolders.length + fFiles.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fCus[offset]));
	}
	arguments.putAll(getRefactoringArguments(project));
	final JavaRefactoringDescriptor descriptor= createRefactoringDescriptor(comment, arguments, description, project, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example 13
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 14
Source File: ReplaceTypeCodeWithStateStrategyDescriptor.java    From JDeodorant with MIT License 5 votes vote down vote up
protected ReplaceTypeCodeWithStateStrategyDescriptor(String project, String description, String comment,
		IFile sourceFile, CompilationUnit sourceCompilationUnit,
		TypeDeclaration sourceTypeDeclaration, TypeCheckElimination typeCheckElimination) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.sourceFile = sourceFile;
	this.sourceCompilationUnit = sourceCompilationUnit;
	this.sourceTypeDeclaration = sourceTypeDeclaration;
	this.typeCheckElimination = typeCheckElimination;
}
 
Example 15
Source File: SelfEncapsulateFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	final Map<String, String> arguments = new HashMap<>();
	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) {
		JavaLanguageServerPlugin.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 ("".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, Integer.valueOf(fVisibility).toString());
	arguments.put(ATTRIBUTE_INSERTION, Integer.valueOf(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;
}
 
Example 16
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
	try {
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IType declaring= getDeclaringType();
		final IJavaProject javaProject= declaring.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		try {
			if (declaring.isLocal() || declaring.isAnonymous())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description_short_multi, BasicElementLabels.getJavaElementName(fMembersToMove[0].getElementName())) : RefactoringCoreMessages.PushDownRefactoring_descriptor_description_short;
		final String header= fMembersToMove.length == 1 ? Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description_full, new String[] { JavaElementLabels.getElementLabel(fMembersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) }) : Messages.format(RefactoringCoreMessages.PushDownRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) });
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		final String[] settings= new String[fMembersToMove.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.PushDownRefactoring_pushed_members_pattern, settings));
		addSuperTypeSettings(comment, true);
		final PushDownDescriptor descriptor= RefactoringSignatureDescriptorFactory.createPushDownDescriptor(project, description, comment.asString(), arguments, flags);
		if (fCachedDeclaringType != null)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCachedDeclaringType));
		for (int index= 0; index < fMembersToMove.length; index++) {
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[index]));
			for (int offset= 0; offset < fMemberInfos.length; offset++) {
				if (fMemberInfos[offset].getMember().equals(fMembersToMove[index])) {
					switch (fMemberInfos[offset].getAction()) {
						case MemberActionInfo.PUSH_ABSTRACT_ACTION:
							arguments.put(ATTRIBUTE_ABSTRACT + (index + 1), Boolean.valueOf(true).toString());
							break;
						case MemberActionInfo.PUSH_DOWN_ACTION:
							arguments.put(ATTRIBUTE_PUSH + (index + 1), Boolean.valueOf(true).toString());
							break;
					}
				}
			}
		}
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.PushDownRefactoring_change_name, fChangeManager.getAllChanges());
	} finally {
		pm.done();
		clearCaches();
	}
}
 
Example 17
Source File: ExtractCloneRefactoringDescriptor.java    From JDeodorant with MIT License 4 votes vote down vote up
protected ExtractCloneRefactoringDescriptor(String project,
		String description, String comment, List<? extends DivideAndConquerMatcher> mappers) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.mappers = mappers;
}
 
Example 18
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask("", 6); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_creating);
		final TextChange[] changes= fChangeManager.getAllChanges();
		if (changes.length == 1)
			return changes[0];
		final List<TextChange> list= new ArrayList<TextChange>(changes.length);
		list.addAll(Arrays.asList(changes));
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IJavaProject javaProject= fMethod.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		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.MoveInstanceMethodProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
		final String header= Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(fTarget, JavaElementLabels.ALL_FULLY_QUALIFIED) });
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_moved_element_pattern, RefactoringCoreMessages.JavaRefactoringDescriptor_not_available));
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_target_element_pattern, BindingLabelProvider.getBindingLabel(fTarget, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_method_name_pattern, BasicElementLabels.getJavaElementName(getMethodName())));
		if (needsTargetNode())
			comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_parameter_name_pattern, BasicElementLabels.getJavaElementName(getTargetName())));
		final MoveMethodDescriptor descriptor= RefactoringSignatureDescriptorFactory.createMoveMethodDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fMethod));
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fMethodName);
		arguments.put(ATTRIBUTE_TARGET_NAME, fTargetName);
		arguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDelegateDeprecation).toString());
		arguments.put(ATTRIBUTE_REMOVE, Boolean.valueOf(fRemove).toString());
		arguments.put(ATTRIBUTE_INLINE, Boolean.valueOf(fInline).toString());
		arguments.put(ATTRIBUTE_USE_GETTER, Boolean.valueOf(fUseGetters).toString());
		arguments.put(ATTRIBUTE_USE_SETTER, Boolean.valueOf(fUseSetters).toString());
		arguments.put(ATTRIBUTE_TARGET_INDEX, new Integer(getTargetIndex()).toString());
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.MoveInstanceMethodRefactoring_name, list.toArray(new Change[list.size()]));
	} finally {
		monitor.done();
	}
}
 
Example 19
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 20
Source File: ExtractMethodRefactoringDescriptor.java    From JDeodorant with MIT License 4 votes vote down vote up
protected ExtractMethodRefactoringDescriptor(String project, String description, String comment,
		CompilationUnit sourceCompilationUnit, ASTSlice slice) {
	super(REFACTORING_ID, project, description, comment, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
	this.sourceCompilationUnit = sourceCompilationUnit;
	this.slice = slice;
}