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