mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code maintenance for refactoring by Emanuel Graf, bug 234348.
This commit is contained in:
parent
c377be5b0e
commit
796acfa15d
8 changed files with 63 additions and 88 deletions
|
@ -11,7 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class NameNVisibilityInformation {
|
|||
|
||||
private String name = ""; //$NON-NLS-1$
|
||||
private VisibilityEnum visibility = VisibilityEnum.v_public;
|
||||
private final Vector<String> usedNames = new Vector<String>();
|
||||
private final ArrayList<String> usedNames = new ArrayList<String>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -41,7 +41,7 @@ public class NameNVisibilityInformation {
|
|||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public Vector<String> getUsedNames(){
|
||||
public ArrayList<String> getUsedNames(){
|
||||
return usedNames;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class NameNVisibilityInformation {
|
|||
usedNames.add(name);
|
||||
}
|
||||
|
||||
public void addNamesToUsedNames(Vector<String> names) {
|
||||
public void addNamesToUsedNames(ArrayList<String> names) {
|
||||
usedNames.addAll(names);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.runtime.ILog;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -49,14 +49,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
|
|||
|
||||
public class NodeContainer {
|
||||
|
||||
private final Vector<IASTNode> vec;
|
||||
private final Vector<NameInformation> names;
|
||||
private final ArrayList<IASTNode> vec;
|
||||
private final ArrayList<NameInformation> names;
|
||||
|
||||
public class NameInformation {
|
||||
private IASTName name;
|
||||
private IASTName declaration;
|
||||
private final Vector<IASTName> references;
|
||||
private Vector<IASTName> referencesAfterCached;
|
||||
private final ArrayList<IASTName> references;
|
||||
private ArrayList<IASTName> referencesAfterCached;
|
||||
private int lastCachedReferencesHash;
|
||||
private boolean isReference;
|
||||
private boolean isReturnValue;
|
||||
|
@ -77,7 +77,7 @@ public class NodeContainer {
|
|||
public NameInformation(IASTName name) {
|
||||
super();
|
||||
this.name = name;
|
||||
references = new Vector<IASTName>();
|
||||
references = new ArrayList<IASTName>();
|
||||
}
|
||||
|
||||
public IASTName getDeclaration() {
|
||||
|
@ -100,12 +100,12 @@ public class NodeContainer {
|
|||
references.add(name);
|
||||
}
|
||||
|
||||
public Vector<IASTName> getReferencesAfterSelection() {
|
||||
public ArrayList<IASTName> getReferencesAfterSelection() {
|
||||
if (referencesAfterCached == null
|
||||
|| lastCachedReferencesHash == references.hashCode()) {
|
||||
|
||||
lastCachedReferencesHash = references.hashCode();
|
||||
referencesAfterCached = new Vector<IASTName>();
|
||||
referencesAfterCached = new ArrayList<IASTName>();
|
||||
for (IASTName ref : references) {
|
||||
IASTFileLocation loc = ref.getFileLocation();
|
||||
if (loc.getNodeOffset() >= getEndOffset()) {
|
||||
|
@ -242,8 +242,8 @@ public class NodeContainer {
|
|||
|
||||
public NodeContainer() {
|
||||
super();
|
||||
vec = new Vector<IASTNode>();
|
||||
names = new Vector<NameInformation>();
|
||||
vec = new ArrayList<IASTNode>();
|
||||
names = new ArrayList<NameInformation>();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
|
@ -308,9 +308,9 @@ public class NodeContainer {
|
|||
* Returns all local names in the selection which will be used after the
|
||||
* selection expected the ones which are pointers
|
||||
*/
|
||||
public Vector<NameInformation> getAllAfterUsedNames() {
|
||||
Vector<IASTName> declarations = new Vector<IASTName>();
|
||||
Vector<NameInformation> usedAfter = new Vector<NameInformation>();
|
||||
public ArrayList<NameInformation> getAllAfterUsedNames() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
if (names.size() <= 0) {
|
||||
findAllNames();
|
||||
|
@ -330,9 +330,9 @@ public class NodeContainer {
|
|||
return usedAfter;
|
||||
}
|
||||
|
||||
public Vector<NameInformation> getAllAfterUsedNamesChoosenByUser() {
|
||||
Vector<IASTName> declarations = new Vector<IASTName>();
|
||||
Vector<NameInformation> usedAfter = new Vector<NameInformation>();
|
||||
public ArrayList<NameInformation> getAllAfterUsedNamesChoosenByUser() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
for (NameInformation nameInf : names) {
|
||||
if (!declarations.contains(nameInf.getDeclaration())) {
|
||||
|
@ -348,9 +348,9 @@ public class NodeContainer {
|
|||
return usedAfter;
|
||||
}
|
||||
|
||||
public Vector<NameInformation> getUsedNamesUnique() {
|
||||
Vector<IASTName> declarations = new Vector<IASTName>();
|
||||
Vector<NameInformation> usedAfter = new Vector<NameInformation>();
|
||||
public ArrayList<NameInformation> getUsedNamesUnique() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
if (names.size() <= 0) {
|
||||
findAllNames();
|
||||
|
@ -372,9 +372,9 @@ public class NodeContainer {
|
|||
* selection expected the ones which are pointers
|
||||
* XXX Was soll dieser Kommentar aussagen? --Mirko
|
||||
*/
|
||||
public Vector<NameInformation> getAllDeclaredInScope() {
|
||||
Vector<IASTName> declarations = new Vector<IASTName>();
|
||||
Vector<NameInformation> usedAfter = new Vector<NameInformation>();
|
||||
public ArrayList<NameInformation> getAllDeclaredInScope() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
for (NameInformation nameInf : names) {
|
||||
if (nameInf.isDeclarationInScope()
|
||||
|
@ -480,7 +480,7 @@ public class NodeContainer {
|
|||
return vec.toString();
|
||||
}
|
||||
|
||||
public Vector<NameInformation> getNames() {
|
||||
public ArrayList<NameInformation> getNames() {
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
@ -78,7 +77,7 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
|||
public class ExtractConstantRefactoring extends CRefactoring {
|
||||
|
||||
private IASTLiteralExpression target = null;
|
||||
private final Vector<IASTExpression> literalsToReplace = new Vector<IASTExpression>();
|
||||
private final ArrayList<IASTExpression> literalsToReplace = new ArrayList<IASTExpression>();
|
||||
private final NameNVisibilityInformation info;
|
||||
|
||||
public ExtractConstantRefactoring(IFile file, ISelection selection, NameNVisibilityInformation info){
|
||||
|
@ -92,8 +91,8 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
SubMonitor sm = SubMonitor.convert(pm, 9);
|
||||
super.checkInitialConditions(sm.newChild(6));
|
||||
|
||||
Collection<IASTLiteralExpression> literalExpressionVector = findAllLiterals();
|
||||
if(literalExpressionVector.isEmpty()){
|
||||
Collection<IASTLiteralExpression> literalExpressionCollection = findAllLiterals();
|
||||
if(literalExpressionCollection.isEmpty()){
|
||||
initStatus.addFatalError(Messages.ExtractConstantRefactoring_LiteralMustBeSelected);
|
||||
return initStatus;
|
||||
}
|
||||
|
@ -101,7 +100,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
sm.worked(1);
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
boolean oneMarked = region != null && isOneMarked(literalExpressionVector, region);
|
||||
boolean oneMarked = region != null && isOneMarked(literalExpressionCollection, region);
|
||||
if(!oneMarked){
|
||||
//No or more than one marked
|
||||
if(target == null){
|
||||
|
@ -117,7 +116,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
||||
findAllNodesForReplacement(literalExpressionVector);
|
||||
findAllNodesForReplacement(literalExpressionCollection);
|
||||
|
||||
info.addNamesToUsedNames(findAllDeclaredNames());
|
||||
info.setName(getDefaultName(target));
|
||||
|
@ -148,9 +147,9 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
return '_' + nameString;
|
||||
}
|
||||
|
||||
private Vector<String> findAllDeclaredNames() {
|
||||
Vector<String>names = new Vector<String>();
|
||||
IASTFunctionDefinition funcDef = getFunctionDefinition();
|
||||
private ArrayList<String> findAllDeclaredNames() {
|
||||
ArrayList<String>names = new ArrayList<String>();
|
||||
IASTFunctionDefinition funcDef = NodeHelper.findFunctionDefinitionInAncestors(target);
|
||||
ICPPASTCompositeTypeSpecifier comTypeSpec = getCompositeTypeSpecifier(funcDef);
|
||||
if(comTypeSpec != null) {
|
||||
for(IASTDeclaration dec : comTypeSpec.getMembers()) {
|
||||
|
@ -183,23 +182,10 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
return null;
|
||||
}
|
||||
|
||||
private IASTFunctionDefinition getFunctionDefinition() {
|
||||
IASTNode node = target;
|
||||
while((node = node.getParent()) != null){
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition funcDef = (IASTFunctionDefinition) node;
|
||||
return funcDef;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void findAllNodesForReplacement(Collection<IASTLiteralExpression> literalExpressionVector) {
|
||||
|
||||
|
||||
private void findAllNodesForReplacement(Collection<IASTLiteralExpression> literalExpressionCollection) {
|
||||
if (target.getParent() instanceof IASTUnaryExpression) {
|
||||
IASTUnaryExpression unary = (IASTUnaryExpression) target.getParent();
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
for (IASTLiteralExpression expression : literalExpressionCollection) {
|
||||
if( target.getKind() == expression.getKind()
|
||||
&& target.toString().equals( expression.toString() )
|
||||
&& expression.getParent() instanceof IASTUnaryExpression
|
||||
|
@ -208,7 +194,7 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
for (IASTLiteralExpression expression : literalExpressionCollection) {
|
||||
if( target.getKind() == expression.getKind()
|
||||
&& target.toString().equals( expression.toString() ) ) {
|
||||
literalsToReplace.add( expression );
|
||||
|
@ -217,9 +203,9 @@ public class ExtractConstantRefactoring extends CRefactoring {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isOneMarked(Collection<IASTLiteralExpression> literalExpressionVector, Region textSelection) {
|
||||
private boolean isOneMarked(Collection<IASTLiteralExpression> literalExpressionCollection, Region textSelection) {
|
||||
boolean oneMarked = false;
|
||||
for (IASTLiteralExpression expression : literalExpressionVector) {
|
||||
for (IASTLiteralExpression expression : literalExpressionCollection) {
|
||||
boolean isInSameFileSelection = SelectionHelper.isInSameFileSelection(textSelection, expression, file);
|
||||
if(isInSameFileSelection){
|
||||
if(target == null) {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractconstant;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
|
@ -20,7 +20,7 @@ import org.eclipse.cdt.internal.ui.refactoring.dialogs.ExtractInputPage;
|
|||
|
||||
public class InputPage extends ExtractInputPage {
|
||||
|
||||
private final Vector<String> usedNames;
|
||||
private final ArrayList<String> usedNames;
|
||||
|
||||
public InputPage(String name, NameNVisibilityInformation info) {
|
||||
super(name, info);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.TableEditor;
|
||||
|
@ -55,8 +55,8 @@ public class ChooserComposite extends Composite {
|
|||
hasNoPredefinedReturnValue = false;
|
||||
}
|
||||
|
||||
final Vector<Button> returnButtons = new Vector<Button>();
|
||||
final Vector<Button> referenceButtons = new Vector<Button>();
|
||||
final ArrayList<Button> returnButtons = new ArrayList<Button>();
|
||||
final ArrayList<Button> referenceButtons = new ArrayList<Button>();
|
||||
|
||||
final Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FILL);
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class ChooserComposite extends Composite {
|
|||
column.setWidth(100);
|
||||
}
|
||||
|
||||
void onVisibilityOrReturnChange(Vector<NameInformation> name){
|
||||
void onVisibilityOrReturnChange(ArrayList<NameInformation> name){
|
||||
String variableUsedAfterBlock = null;
|
||||
for (NameInformation information : name) {
|
||||
if(information.isUsedAfterReferences()
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
|
||||
|
@ -29,8 +29,8 @@ public class ExtractFunctionInformation {
|
|||
private VisibilityEnum visibility = VisibilityEnum.v_private;
|
||||
private String methodName;
|
||||
private boolean replaceDuplicates;
|
||||
private Vector<NameInformation> allAfterUsedNames;
|
||||
private Vector<NameInformation> allUsedNames;
|
||||
private ArrayList<NameInformation> allAfterUsedNames;
|
||||
private ArrayList<NameInformation> allUsedNames;
|
||||
private NameInformation inScopeDeclaredVariable;
|
||||
private NameInformation returnVariable;
|
||||
private ICPPASTFunctionDeclarator declarator;
|
||||
|
@ -66,9 +66,9 @@ public class ExtractFunctionInformation {
|
|||
this.replaceDuplicates = replaceDuplicates;
|
||||
}
|
||||
|
||||
public Vector<NameInformation> getAllAfterUsedNames() {
|
||||
public ArrayList<NameInformation> getAllAfterUsedNames() {
|
||||
if(allAfterUsedNames == null){
|
||||
allAfterUsedNames = new Vector<NameInformation>();
|
||||
allAfterUsedNames = new ArrayList<NameInformation>();
|
||||
for (NameInformation name : getAllUsedNames()) {
|
||||
if(name.isReference()||name.isReturnValue()){
|
||||
allAfterUsedNames.add(name);
|
||||
|
@ -79,7 +79,7 @@ public class ExtractFunctionInformation {
|
|||
return allAfterUsedNames;
|
||||
}
|
||||
|
||||
public void setAllAfterUsedNames(Vector<NameInformation> allAfterUsedNames) {
|
||||
public void setAllAfterUsedNames(ArrayList<NameInformation> allAfterUsedNames) {
|
||||
this.allAfterUsedNames = allAfterUsedNames;
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,11 @@ public class ExtractFunctionInformation {
|
|||
this.inScopeDeclaredVariable = inScopeDeclaredVariable;
|
||||
}
|
||||
|
||||
public Vector<NameInformation> getAllUsedNames() {
|
||||
public ArrayList<NameInformation> getAllUsedNames() {
|
||||
return allUsedNames;
|
||||
}
|
||||
|
||||
public void setAllUsedNames(Vector<NameInformation> allUsedNames) {
|
||||
public void setAllUsedNames(ArrayList<NameInformation> allUsedNames) {
|
||||
this.allUsedNames = allUsedNames;
|
||||
}
|
||||
|
||||
|
|
|
@ -165,8 +165,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
status
|
||||
.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
|
||||
} else if (container.getAllDeclaredInScope().size() == 1) {
|
||||
info.setInScopeDeclaredVariable(container.getAllDeclaredInScope()
|
||||
.firstElement());
|
||||
info.setInScopeDeclaredVariable(container.getAllDeclaredInScope().get(0));
|
||||
}
|
||||
|
||||
extractedFunctionConstructionHelper = ExtractedFunctionConstructionHelper
|
||||
|
@ -320,18 +319,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
MethodContext context, IASTNode firstNode,
|
||||
final IFile implementationFile, ModificationCollector collector) {
|
||||
|
||||
IASTNode node = firstNode;
|
||||
boolean found = false;
|
||||
|
||||
while (node != null && !found) {
|
||||
node = node.getParent();
|
||||
if (node instanceof IASTFunctionDefinition) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found && node != null) {
|
||||
|
||||
IASTFunctionDefinition node = NodeHelper.findFunctionDefinitionInAncestors(firstNode);
|
||||
if (node != null) {
|
||||
String title;
|
||||
if (context.getType() == MethodContext.ContextType.METHOD) {
|
||||
title = Messages.ExtractFunctionRefactoring_CreateMethodDef;
|
||||
|
|
|
@ -105,7 +105,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
return initStatus;
|
||||
}
|
||||
if(!(methodToHideDecl.getParent() instanceof ICPPASTCompositeTypeSpecifier)) {
|
||||
methodToHideDecl = NodeHelper.findFunctionDefinition(methodToHide);
|
||||
methodToHideDecl = NodeHelper.findFunctionDefinitionInAncestors(methodToHide);
|
||||
}
|
||||
|
||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||
|
@ -134,7 +134,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
|
||||
sm.worked(1);
|
||||
|
||||
IASTCompositeTypeSpecifier classNode = NodeHelper.findEnclosingClass(methodToHide);
|
||||
IASTCompositeTypeSpecifier classNode = NodeHelper.findClassInAncestors(methodToHide);
|
||||
if(classNode == null) {
|
||||
initStatus.addError(Messages.HideMethodRefactoring_EnclosingClassNotFound);
|
||||
}
|
||||
|
@ -193,13 +193,13 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
IASTFunctionDeclarator funcDec = findEnclosingFunction(expName);
|
||||
IASTCompositeTypeSpecifier encClass2;
|
||||
if(funcDec == null) {
|
||||
encClass2 = NodeHelper.findEnclosingClass(expName);
|
||||
encClass2 = NodeHelper.findClassInAncestors(expName);
|
||||
}
|
||||
else {
|
||||
encClass2 = NodeHelper.findEnclosingClass(funcDec);
|
||||
encClass2 = NodeHelper.findClassInAncestors(funcDec);
|
||||
}
|
||||
|
||||
IASTCompositeTypeSpecifier encClass = NodeHelper.findEnclosingClass(methodToHide);
|
||||
IASTCompositeTypeSpecifier encClass = NodeHelper.findClassInAncestors(methodToHide);
|
||||
|
||||
if(!NodeHelper.isSameNode(encClass, encClass2)) {
|
||||
finalConditions.addWarning(Messages.HideMethodRefactoring_HasExternalReferences);
|
||||
|
@ -210,7 +210,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
}
|
||||
|
||||
private IASTFunctionDeclarator findEnclosingFunction(IASTNode node) throws CoreException {
|
||||
IASTCompoundStatement compStat = NodeHelper.findCompoundStatementInParent(node);
|
||||
IASTCompoundStatement compStat = NodeHelper.findCompoundStatementInAncestors(node);
|
||||
if(compStat == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue