From 9bc829ac7356a0181898242111aec39b0f0964c2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 30 May 2014 17:54:09 -0700 Subject: [PATCH] WIP --- core/org.eclipse.cdt.ui/plugin.properties | 4 +- core/org.eclipse.cdt.ui/plugin.xml | 56 ++++++++++++---- .../rename/HeaderFileMoveParticipant.java | 64 +++++++++++++++++++ .../rename/HeaderFileRenameParticipant.java | 59 +++++++++++++++++ .../rename/RenameCSourceFolderChange.java | 18 +++--- .../ui/refactoring/rename/RenameMessages.java | 6 +- .../rename/RenameMessages.properties | 8 ++- .../rename/RenameSourceFolder.java | 9 +-- 8 files changed, 191 insertions(+), 33 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileMoveParticipant.java create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileRenameParticipant.java diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index be1b67e5126..28069ba36a4 100755 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -604,7 +604,9 @@ preferenceKeywords.smarttyping=editor typing type close comment tabs indentation historyAction.label = History... createScriptAction.label = Create Script... applyScriptAction.label = Apply Script... -renameParticipant.name = Source Folder Rename +renameFolderParticipant.name = Source Folder Rename +headerFileMoveParticipant.name = Header File Move +headerFileRenameParticipant.name = Header File Rename FormatAction.label= &Format IndentAction.label= Correct &Indentation diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index c50d54b410c..91985c6b1f1 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4396,23 +4396,55 @@ id="org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + - - - + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileMoveParticipant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileMoveParticipant.java new file mode 100644 index 00000000000..fb50540aaa1 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileMoveParticipant.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2014 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.rename; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.MoveArguments; +import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; + +public class HeaderFileMoveParticipant extends MoveParticipant { + private IResource element; + + public HeaderFileMoveParticipant() { + } + + @Override + protected boolean initialize(Object element) { + if (element instanceof IResource) { + this.element = (IResource) element; + return true; + } + return false; + } + + @Override + public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) + throws OperationCanceledException { + return RefactoringStatus.create(Status.OK_STATUS); + } + + @Override + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + MoveArguments args = getArguments(); + if (!args.getUpdateReferences()) + return null; + Object destination = args.getDestination(); + if (!(destination instanceof IContainer)) + return null; + IPath destinationLocation = ((IContainer) destination).getLocation(); + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + return RenameMessages.HeaderFileMoveParticipant_name; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileRenameParticipant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileRenameParticipant.java new file mode 100644 index 00000000000..ff8d83d7756 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/HeaderFileRenameParticipant.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2014 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sergey Prigogin (Google) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.refactoring.rename; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Status; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.RenameArguments; +import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; + +public class HeaderFileRenameParticipant extends RenameParticipant { + private IResource element; + + public HeaderFileRenameParticipant() { + } + + @Override + protected boolean initialize(Object element) { + if (element instanceof IResource) { + this.element = (IResource) element; + return true; + } + return false; + } + + @Override + public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) + throws OperationCanceledException { + return RefactoringStatus.create(Status.OK_STATUS); + } + + @Override + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + RenameArguments arguments = getArguments(); + if (!arguments.getUpdateReferences()) + return null; + String newName = arguments.getNewName(); + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + return RenameMessages.HeaderFileRenameParticipant_name; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameCSourceFolderChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameCSourceFolderChange.java index f5b94402f32..5f91e31cec8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameCSourceFolderChange.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameCSourceFolderChange.java @@ -93,25 +93,25 @@ public class RenameCSourceFolderChange extends Change { CCorePlugin.getDefault().setProjectDescription(project, des, false, new NullProgressMonitor()); } - private ICSourceEntry[] renameEntry(ICSourceEntry[] entries){ + private ICSourceEntry[] renameEntry(ICSourceEntry[] entries) { Set set = new HashSet<>(); - for (ICSourceEntry se : entries){ - String seLocation = se.getName(); + for (ICSourceEntry entry : entries){ + String seLocation = entry.getName(); if (seLocation.equals(oldName.toPortableString())) { - ICSourceEntry newSE = new CSourceEntry(newName, se.getExclusionPatterns(), se.getFlags()); + ICSourceEntry newSE = new CSourceEntry(newName, entry.getExclusionPatterns(), entry.getFlags()); set.add(newSE); } else { - Set exPatters = new HashSet<>(); - for (IPath filter : se.getExclusionPatterns()) { + Set exclusionPatterns = new HashSet<>(); + for (IPath filter : entry.getExclusionPatterns()) { IPath oldSegments = oldName.removeFirstSegments(oldName.segmentCount() -1); if (filter.equals(oldSegments)) { - exPatters.add(newName.removeFirstSegments(newName.segmentCount() - 1)); + exclusionPatterns.add(newName.removeFirstSegments(newName.segmentCount() - 1)); } else { - exPatters.add(filter); + exclusionPatterns.add(filter); } } - set.add(new CSourceEntry(se.getValue(), exPatters.toArray(new IPath[exPatters.size()]), se.getFlags())); + set.add(new CSourceEntry(entry.getValue(), exclusionPatterns.toArray(new IPath[exclusionPatterns.size()]), entry.getFlags())); } } return set.toArray(new ICSourceEntry[set.size()]); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java index 07482025cda..20e2ec7b1ee 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 Wind River Systems, Inc. + * Copyright (c) 2004, 2014 Wind River Systems, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -97,9 +97,11 @@ class RenameMessages extends NLS { public static String CRenameTopProcessor_virtualMethod; public static String CRenameTopProcessor_wizard_backup_title; public static String CRenameTopProcessor_wizard_title; + public static String HeaderFileMoveParticipant_name; + public static String HeaderFileRenameParticipant_name; public static String RenameCSourceFolderChange_ErrorMsg; public static String RenameCSourceFolderChange_Name0; - public static String RenameSourceFolder_0; + public static String RenameSourceFolder_name; public static String RenameInformationPopup_delayJobName; public static String RenameInformationPopup_EnterNewName; public static String RenameInformationPopup_menu; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.properties index e3c27856bd7..25606c38d50 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2005, 2010 IBM Corporation and others. +# Copyright (c) 2005, 2014 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -10,7 +10,7 @@ # Markus Schorn, Wind River Systems Inc. # Sergey Prigogin (Google) ############################################################################### -ASTManager_error_macro_name_conflict=''{0}'' conflicts with the name of an existing macro! +ASTManager_error_macro_name_conflict=''{0}'' conflicts with the name of an existing macro. ASTManager_subtask_analyzing=Analyzing {0} files ASTManager_task_analyze=Analyzing source code ASTManager_task_generateAst=Generating AST @@ -93,9 +93,11 @@ CRenameTopProcessor_type=type CRenameTopProcessor_virtualMethod=virtual method CRenameTopProcessor_wizard_backup_title=Rename CRenameTopProcessor_wizard_title=Rename ''{0}'' +HeaderFileMoveParticipant_name=Header File Move +HeaderFileRenameParticipant_name=Header File Rename RenameCSourceFolderChange_ErrorMsg=Folder {0} does not exist RenameCSourceFolderChange_Name0=Rename source folder {0} to {1} -RenameSourceFolder_0=Rename C/C++ Source Folder +RenameSourceFolder_name=Rename C/C++ Source Folder RenameInformationPopup_SnapTo=&Snap To RenameInformationPopup_snap_under_left=&Under Left RenameInformationPopup_snap_under_right=U&nder Right diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameSourceFolder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameSourceFolder.java index f7ea3a0be0b..e25fd9fe48c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameSourceFolder.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/RenameSourceFolder.java @@ -20,7 +20,6 @@ import org.eclipse.core.runtime.Status; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameArguments; import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; /** @@ -28,7 +27,6 @@ import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; */ public class RenameSourceFolder extends RenameParticipant { private IFolder oldFolder; - private String newName; public RenameSourceFolder() { } @@ -36,21 +34,20 @@ public class RenameSourceFolder extends RenameParticipant { @Override public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { - RenameArguments arg = getArguments(); - newName = arg.getNewName(); return RefactoringStatus.create(Status.OK_STATUS); } @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { IPath oldFolderPath = oldFolder.getFullPath(); - IPath newFolderPath = oldFolder.getFullPath().uptoSegment(oldFolder.getFullPath().segmentCount() - 1).append(newName); + String newName = getArguments().getNewName(); + IPath newFolderPath = oldFolderPath.removeLastSegments(1).append(newName); return new RenameCSourceFolderChange(oldFolderPath, newFolderPath, oldFolder.getProject(), oldFolder); } @Override public String getName() { - return RenameMessages.RenameSourceFolder_0; + return RenameMessages.RenameSourceFolder_name; } @Override