mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
Code maintenance for refactoring by Emanuel Graf, bug 234348.
This commit is contained in:
parent
796acfa15d
commit
0417976c9e
8 changed files with 19 additions and 23 deletions
|
@ -73,7 +73,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
||||||
info.setReplaceDuplicates(replaceDuplicates);
|
info.setReplaceDuplicates(replaceDuplicates);
|
||||||
if(info.getInScopeDeclaredVariable() == null){
|
if(info.getInScopeDeclaredVariable() == null){
|
||||||
if(returnValue) {
|
if(returnValue) {
|
||||||
info.setReturnVariable(info.getAllAfterUsedNames().elementAt(returnParameterIndex));
|
info.setReturnVariable(info.getAllAfterUsedNames().get(returnParameterIndex));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info.setReturnVariable( info.getInScopeDeclaredVariable() );
|
info.setReturnVariable( info.getInScopeDeclaredVariable() );
|
||||||
|
|
|
@ -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.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -326,8 +326,8 @@ public abstract class CRefactoring extends Refactoring {
|
||||||
return fIndex;
|
return fIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Vector<IASTName> findAllMarkedNames() {
|
protected ArrayList<IASTName> findAllMarkedNames() {
|
||||||
final Vector<IASTName> namesVector = new Vector<IASTName>();
|
final ArrayList<IASTName> namesVector = new ArrayList<IASTName>();
|
||||||
|
|
||||||
unit.accept(new CPPASTVisitor() {
|
unit.accept(new CPPASTVisitor() {
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -73,11 +72,11 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring {
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTName getSelectedName() {
|
private IASTName getSelectedName() {
|
||||||
Vector<IASTName> names = findAllMarkedNames();
|
ArrayList<IASTName> names = findAllMarkedNames();
|
||||||
if (names.size() < 1) {
|
if (names.size() < 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return names.lastElement();
|
return names.get(names.size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void findDeclarations() {
|
protected void findDeclarations() {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
package org.eclipse.cdt.internal.ui.refactoring.hidemethod;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -78,15 +78,12 @@ public class HideMethodRefactoring extends CRefactoring {
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||||
|
|
||||||
IASTName name;
|
IASTName name;
|
||||||
Vector<IASTName> names = findAllMarkedNames();
|
ArrayList<IASTName> names = findAllMarkedNames();
|
||||||
if(names.size() > 1) {
|
if (names.size() < 1) {
|
||||||
name = names.lastElement();
|
|
||||||
} else if (names.size() < 1) {
|
|
||||||
initStatus.addFatalError(Messages.HideMethodRefactoring_NoNameSelected);
|
initStatus.addFatalError(Messages.HideMethodRefactoring_NoNameSelected);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}else {
|
|
||||||
name = names.get(0);
|
|
||||||
}
|
}
|
||||||
|
name = names.get(names.size()-1);
|
||||||
sm.worked(1);
|
sm.worked(1);
|
||||||
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
if(isProgressMonitorCanceld(sm, initStatus)) return initStatus;
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -105,20 +105,20 @@ public class MethodDefinitionInsertLocationFinder {
|
||||||
* @return all declarations, sorted in reverse order
|
* @return all declarations, sorted in reverse order
|
||||||
*/
|
*/
|
||||||
private static Collection<IASTSimpleDeclaration> getAllPreviousIASTSimpleDeclarationsFromClassInReverseOrder(IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
private static Collection<IASTSimpleDeclaration> getAllPreviousIASTSimpleDeclarationsFromClassInReverseOrder(IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
||||||
Vector<IASTSimpleDeclaration> allIASTSimpleDeclarations = new Vector<IASTSimpleDeclaration>();
|
ArrayList<IASTSimpleDeclaration> allIASTSimpleDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
||||||
for (IASTDeclaration decl : declarations) {
|
for (IASTDeclaration decl : declarations) {
|
||||||
if (decl.getFileLocation().getStartingLineNumber() >= methodPosition.getStartingLineNumber()) {
|
if (decl.getFileLocation().getStartingLineNumber() >= methodPosition.getStartingLineNumber()) {
|
||||||
return allIASTSimpleDeclarations;
|
return allIASTSimpleDeclarations;
|
||||||
}
|
}
|
||||||
if (isMemberFunctionDeclaration(decl)) {
|
if (isMemberFunctionDeclaration(decl)) {
|
||||||
allIASTSimpleDeclarations.insertElementAt((IASTSimpleDeclaration) decl, 0);
|
allIASTSimpleDeclarations.add(0, (IASTSimpleDeclaration) decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allIASTSimpleDeclarations;
|
return allIASTSimpleDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<IASTSimpleDeclaration> getAllFollowingIASTSimpleDeclarationsFromClass(IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
private static Collection<IASTSimpleDeclaration> getAllFollowingIASTSimpleDeclarationsFromClass(IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
||||||
Vector<IASTSimpleDeclaration> allIASTSimpleDeclarations = new Vector<IASTSimpleDeclaration>();
|
ArrayList<IASTSimpleDeclaration> allIASTSimpleDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
||||||
|
|
||||||
for (IASTDeclaration decl : declarations) {
|
for (IASTDeclaration decl : declarations) {
|
||||||
if (isMemberFunctionDeclaration(decl) && decl.getFileLocation().getStartingLineNumber() > methodPosition.getStartingLineNumber() ) {
|
if (isMemberFunctionDeclaration(decl) && decl.getFileLocation().getStartingLineNumber() > methodPosition.getStartingLineNumber() ) {
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class NodeHelper {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTCompoundStatement findCompoundStatementInParent(IASTNode node) {
|
public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) {
|
||||||
while(node != null){
|
while(node != null){
|
||||||
if (node instanceof IASTCompoundStatement) {
|
if (node instanceof IASTCompoundStatement) {
|
||||||
return (IASTCompoundStatement) node;
|
return (IASTCompoundStatement) node;
|
||||||
|
@ -138,7 +138,7 @@ public class NodeHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTCompositeTypeSpecifier findEnclosingClass(IASTNode node) {
|
public static IASTCompositeTypeSpecifier findClassInAncestors(IASTNode node) {
|
||||||
while(!(node instanceof IASTCompositeTypeSpecifier)){
|
while(!(node instanceof IASTCompositeTypeSpecifier)){
|
||||||
if(node instanceof IASTTranslationUnit) {
|
if(node instanceof IASTTranslationUnit) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -148,7 +148,7 @@ public class NodeHelper {
|
||||||
return (IASTCompositeTypeSpecifier) node;
|
return (IASTCompositeTypeSpecifier) node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTFunctionDefinition findFunctionDefinition(IASTNode node) {
|
public static IASTFunctionDefinition findFunctionDefinitionInAncestors(IASTNode node) {
|
||||||
while(node != null){
|
while(node != null){
|
||||||
if (node instanceof IASTFunctionDefinition) {
|
if (node instanceof IASTFunctionDefinition) {
|
||||||
return (IASTFunctionDefinition) node;
|
return (IASTFunctionDefinition) node;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps to generate new unsused names.
|
* Helps to generate new unused names.
|
||||||
*
|
*
|
||||||
* @author Mirko Stocker
|
* @author Mirko Stocker
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to suport operations conserning a selection.
|
* Helper class to support operations concerning a selection.
|
||||||
*
|
*
|
||||||
* @author Mirko Stocker, Lukas Felber
|
* @author Mirko Stocker, Lukas Felber
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue