From 796acfa15dadc9a2ee2965730440f7f26fd6d41d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 28 May 2008 13:43:31 +0000 Subject: [PATCH] Code maintenance for refactoring by Emanuel Graf, bug 234348. --- .../NameNVisibilityInformation.java | 8 ++-- .../ui/refactoring/NodeContainer.java | 46 +++++++++---------- .../ExtractConstantRefactoring.java | 40 ++++++---------- .../extractconstant/InputPage.java | 4 +- .../extractfunction/ChooserComposite.java | 8 ++-- .../ExtractFunctionInformation.java | 16 +++---- .../ExtractFunctionRefactoring.java | 17 ++----- .../hidemethod/HideMethodRefactoring.java | 12 ++--- 8 files changed, 63 insertions(+), 88 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java index 4c4ca94b400..95674e6c1fe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java @@ -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 usedNames = new Vector(); + private final ArrayList usedNames = new ArrayList(); public String getName() { return name; @@ -41,7 +41,7 @@ public class NameNVisibilityInformation { this.visibility = visibility; } - public Vector getUsedNames(){ + public ArrayList getUsedNames(){ return usedNames; } @@ -49,7 +49,7 @@ public class NameNVisibilityInformation { usedNames.add(name); } - public void addNamesToUsedNames(Vector names) { + public void addNamesToUsedNames(ArrayList names) { usedNames.addAll(names); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java index f765d9ac581..851f57a5c32 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java @@ -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 vec; - private final Vector names; + private final ArrayList vec; + private final ArrayList names; public class NameInformation { private IASTName name; private IASTName declaration; - private final Vector references; - private Vector referencesAfterCached; + private final ArrayList references; + private ArrayList 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(); + references = new ArrayList(); } public IASTName getDeclaration() { @@ -100,12 +100,12 @@ public class NodeContainer { references.add(name); } - public Vector getReferencesAfterSelection() { + public ArrayList getReferencesAfterSelection() { if (referencesAfterCached == null || lastCachedReferencesHash == references.hashCode()) { lastCachedReferencesHash = references.hashCode(); - referencesAfterCached = new Vector(); + referencesAfterCached = new ArrayList(); 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(); - names = new Vector(); + vec = new ArrayList(); + names = new ArrayList(); } 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 getAllAfterUsedNames() { - Vector declarations = new Vector(); - Vector usedAfter = new Vector(); + public ArrayList getAllAfterUsedNames() { + ArrayList declarations = new ArrayList(); + ArrayList usedAfter = new ArrayList(); if (names.size() <= 0) { findAllNames(); @@ -330,9 +330,9 @@ public class NodeContainer { return usedAfter; } - public Vector getAllAfterUsedNamesChoosenByUser() { - Vector declarations = new Vector(); - Vector usedAfter = new Vector(); + public ArrayList getAllAfterUsedNamesChoosenByUser() { + ArrayList declarations = new ArrayList(); + ArrayList usedAfter = new ArrayList(); for (NameInformation nameInf : names) { if (!declarations.contains(nameInf.getDeclaration())) { @@ -348,9 +348,9 @@ public class NodeContainer { return usedAfter; } - public Vector getUsedNamesUnique() { - Vector declarations = new Vector(); - Vector usedAfter = new Vector(); + public ArrayList getUsedNamesUnique() { + ArrayList declarations = new ArrayList(); + ArrayList usedAfter = new ArrayList(); 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 getAllDeclaredInScope() { - Vector declarations = new Vector(); - Vector usedAfter = new Vector(); + public ArrayList getAllDeclaredInScope() { + ArrayList declarations = new ArrayList(); + ArrayList usedAfter = new ArrayList(); for (NameInformation nameInf : names) { if (nameInf.isDeclarationInScope() @@ -480,7 +480,7 @@ public class NodeContainer { return vec.toString(); } - public Vector getNames() { + public ArrayList getNames() { return names; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java index 52da427325b..e2695b2a091 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java @@ -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 literalsToReplace = new Vector(); + private final ArrayList literalsToReplace = new ArrayList(); 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 literalExpressionVector = findAllLiterals(); - if(literalExpressionVector.isEmpty()){ + Collection 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 findAllDeclaredNames() { - Vectornames = new Vector(); - IASTFunctionDefinition funcDef = getFunctionDefinition(); + private ArrayList findAllDeclaredNames() { + ArrayListnames = new ArrayList(); + 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 literalExpressionVector) { - - + private void findAllNodesForReplacement(Collection 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 literalExpressionVector, Region textSelection) { + private boolean isOneMarked(Collection 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) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java index e46aae3fae3..439a37366ab 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java @@ -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 usedNames; + private final ArrayList usedNames; public InputPage(String name, NameNVisibilityInformation info) { super(name, info); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java index 83ac0597d65..730e2d956ce 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ChooserComposite.java @@ -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