1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Use ArrayList instead of Vector.

This commit is contained in:
Sergey Prigogin 2012-01-09 15:45:21 -08:00
parent ecd14f70f8
commit 9b83d66132
8 changed files with 79 additions and 89 deletions

View file

@ -13,9 +13,9 @@ package org.eclipse.cdt.core.parser.tests.rewrite;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;
import org.eclipse.cdt.core.tests.BaseTestFramework;
import org.eclipse.core.resources.IFile;
@ -38,8 +38,8 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
protected RewriteBaseTest(String name) {
super(name);
}
public RewriteBaseTest(String name, Vector<TestSourceFile> files) {
public RewriteBaseTest(String name, List<TestSourceFile> files) {
super(name);
for (TestSourceFile file : files) {
fileMap.put(file.getName(), file);

View file

@ -18,7 +18,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -59,7 +59,7 @@ public class RewriteTester extends TestSuite {
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
String line;
Vector<TestSourceFile> files = new Vector<TestSourceFile>();
List<TestSourceFile> files = new ArrayList<TestSourceFile>();
TestSourceFile actFile = null;
MatcherState matcherState = MatcherState.skip;
ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
@ -72,7 +72,7 @@ public class RewriteTester extends TestSuite {
if (!bevorFirstTest) {
RewriteBaseTest test = createTestClass(className, testName, files);
testCases.add(test);
files = new Vector<TestSourceFile>();
files = new ArrayList<TestSourceFile>();
className = null;
testName = null;
}
@ -114,17 +114,11 @@ public class RewriteTester extends TestSuite {
}
private static RewriteBaseTest createTestClass(String className, String testName,
Vector<TestSourceFile> files) throws Exception {
List<TestSourceFile> files) throws Exception {
try {
Class<?> refClass = Class.forName(className);
Class<?> paratypes[] = new Class[2];
paratypes[0] = testName.getClass();
paratypes[1] = files.getClass();
Constructor<?> ct = refClass.getConstructor(paratypes);
Object arglist[] = new Object[2];
arglist[0] = testName;
arglist[1] = files;
RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(arglist);
Constructor<?> ct = refClass.getConstructor(new Class[] { String.class, List.class });
RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(new Object[] { testName, files });
for (TestSourceFile file : files) {
TextSelection sel = file.getSelection();
if (sel != null) {

View file

@ -15,7 +15,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -85,7 +84,7 @@ public class CommentHandlingTest extends RewriteBaseTest {
private static final String TRAILING_COMMENT_TITLE = "<<<=== Trailing Comment Test Section ===>>>"; //$NON-NLS-1$
private static final String FREESTANDING_COMMENT_TITLE = "<<<=== Freestanding Comment Test Section ===>>>"; //$NON-NLS-1$
public CommentHandlingTest(String name, Vector<TestSourceFile> files) {
public CommentHandlingTest(String name, List<TestSourceFile> files) {
super(name, files);
}

View file

@ -22,8 +22,8 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* Startup class for Eclipse. Creates a class loader using
* supplied URL of platform installation, loads and calls
@ -181,14 +181,14 @@ protected Object basicRun(String[] args) throws Exception {
private String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals(""))
return new String[0];
Vector list = new Vector();
List<String> list = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.equals(""))
list.addElement(token);
list.add(token);
}
return list.isEmpty() ? new String[0] : (String[]) list.toArray(new String[0]);
return list.toArray(new String[list.size()]);
}
/**
* Creates and returns a platform <code>BootLoader</code> which can be used to start
@ -404,10 +404,10 @@ public static void endSplash() {
* @exception Exception thrown if a problem occurs during launching
*/
public static void main(String argString) throws Exception {
Vector list = new Vector(5);
List<String> list = new ArrayList<String>(5);
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();)
list.addElement(tokens.nextElement());
main((String[]) list.toArray(new String[list.size()]));
list.add((String) tokens.nextElement());
main(list.toArray(new String[list.size()]));
}
/**

View file

@ -14,18 +14,17 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* Application is responsible for calling core launch api
*/
public class NewMain extends Main {
private static final String DEFAULT_APPLICATION= "org.eclipse.ui.workbench";
public NewMain(String application, String location, URL pluginPathLocation, String bootLocation, boolean debug) throws IOException {
this.application= application;
this.location= location;
@ -44,17 +43,16 @@ public class NewMain extends Main {
System.exit(0);
}
/**
* Run this launcher with the arguments specified in the given string.
* This is a short cut method for people running the launcher from
* a scrapbook (i.e., swip-and-doit facility).
*/
public static void main(String argString) throws Exception {
Vector list= new Vector(5);
List<String> list= new ArrayList<String>(5);
for (StringTokenizer tokens= new StringTokenizer(argString, " "); tokens.hasMoreElements();)
list.addElement(tokens.nextElement());
main((String[]) list.toArray(new String[list.size()]));
list.add((String) tokens.nextElement());
main(list.toArray(new String[list.size()]));
}
public static String getLocationFromProperties(String key) {

View file

@ -12,7 +12,8 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTComment;
@ -63,13 +64,13 @@ public class NodeCommenter {
protected ASTVisitor visitor;
protected CommentHandler commHandler;
protected NodeCommentMap commentMap;
protected Vector<IASTNode> children;
protected List<IASTNode> children;
public NodeCommenter(ASTVisitor visitor, CommentHandler commHandler, NodeCommentMap commentMap) {
this.visitor = visitor;
this.commHandler = commHandler;
this.commentMap = commentMap;
this.children = new Vector<IASTNode>();
this.children = new ArrayList<IASTNode>();
}
protected void writeNodeList(IASTNode[] nodes) {

View file

@ -17,7 +17,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
@ -434,7 +433,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
}
final Vector<IASTNode> initTrail = getTrail(nodesToRewriteWithoutComments);
final List<IASTNode> initTrail = getTrail(nodesToRewriteWithoutComments);
final String title;
if (contextType == MethodContext.ContextType.METHOD) {
title = Messages.ExtractFunctionRefactoring_CreateMethodCall;
@ -448,8 +447,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
}
protected Vector<IASTNode> getTrail(List<IASTNode> stmts) {
final Vector<IASTNode> trail = new Vector<IASTNode>();
protected List<IASTNode> getTrail(List<IASTNode> stmts) {
final List<IASTNode> trail = new ArrayList<IASTNode>();
nameTrail = new HashMap<String, Integer>();
final Container<Integer> trailCounter = new Container<Integer>(NULL_INTEGER);
@ -465,8 +464,9 @@ public class ExtractFunctionRefactoring extends CRefactoring {
trail.add(node);
return PROCESS_SKIP;
} else if (node instanceof IASTName) {
if (node instanceof ICPPASTConversionName && node instanceof ICPPASTOperatorName
&& node instanceof ICPPASTTemplateId) {
if (node instanceof ICPPASTConversionName &&
node instanceof ICPPASTOperatorName &&
node instanceof ICPPASTTemplateId) {
trail.add(node);
return super.visitAll(node);
} else {
@ -483,8 +483,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
trailName.setNameNumber(actCount);
if (info.getReturnVariable() != null
&& info.getReturnVariable().getName().getRawSignature().equals(
if (info.getReturnVariable() != null &&
info.getReturnVariable().getName().getRawSignature().equals(
name.getRawSignature())) {
returnNumber.setObject(Integer.valueOf(actCount));
}
@ -498,13 +498,12 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
}
});
}
return trail;
}
protected boolean isStatementInTrail(IASTStatement stmt, final Vector<IASTNode> trail, IIndex index) {
protected boolean isStatementInTrail(IASTStatement stmt, final List<IASTNode> trail, IIndex index) {
final Container<Boolean> same = new Container<Boolean>(Boolean.TRUE);
final TrailNodeEqualityChecker equalityChecker = new TrailNodeEqualityChecker(names, namesCounter, index);
@ -591,8 +590,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
return true;
}
private void addMethod(IASTName astMethodName, MethodContext context,
ASTRewrite rewriter, IASTNode insertpoint, TextEditGroup group) {
private void addMethod(IASTName astMethodName, MethodContext context, ASTRewrite rewriter,
IASTNode insertpoint, TextEditGroup group) {
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
if (context.getType() == ContextType.METHOD) {
if (context.getMethodQName() != null) {
@ -609,10 +608,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
IASTDeclSpecifier returnType = getReturnType();
func.setDeclSpecifier(returnType);
IASTStandardFunctionDeclarator createdFunctionDeclarator = extractedFunctionConstructionHelper
.createFunctionDeclarator(qname, info.getDeclarator(), info
.getReturnVariable(), container.getNodesToWrite(), info
.getAllUsedNames(), ast.getASTNodeFactory());
IASTStandardFunctionDeclarator createdFunctionDeclarator =
extractedFunctionConstructionHelper.createFunctionDeclarator(qname,
info.getDeclarator(), info.getReturnVariable(), container.getNodesToWrite(),
info.getAllUsedNames(), ast.getASTNodeFactory());
func.setDeclarator(createdFunctionDeclarator);
IASTCompoundStatement compound = new CPPASTCompoundStatement();
@ -623,8 +622,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
templateDeclaration.setParent(ast);
for (ICPPASTTemplateParameter templateParameter : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) {
templateDeclaration.addTemplateParameter(templateParameter.copy(CopyStyle.withLocations));
for (ICPPASTTemplateParameter param : ((ICPPASTTemplateDeclaration) insertpoint.getParent()).getTemplateParameters()) {
templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations));
}
templateDeclaration.setDeclaration(func);
@ -664,8 +663,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
private IASTDeclSpecifier getReturnType() {
IASTNode firstNodeToWrite = container.getNodesToWrite().get(0);
NameInformation returnVariable = info.getReturnVariable();
return extractedFunctionConstructionHelper.determineReturnType(firstNodeToWrite, returnVariable);
return extractedFunctionConstructionHelper.determineReturnType(firstNodeToWrite,
returnVariable);
}
protected IASTNode getMethodCall(IASTName astMethodName,
@ -678,30 +677,28 @@ public class ExtractFunctionRefactoring extends CRefactoring {
idExpression.setName(astMethodName);
List<IASTInitializerClause> args = new ArrayList<IASTInitializerClause>();
Vector<IASTName> declarations = new Vector<IASTName>();
List<IASTName> declarations = new ArrayList<IASTName>();
IASTName retName = null;
boolean theRetName = false;
for (NameInformation nameInfo : myContainer.getNames()) {
Integer trailSeqNumber = trailNameTable.get(nameInfo.getDeclaration().getRawSignature());
String orgName = null;
String origName = null;
for (Entry<String, Integer> entry : similarNameTable.entrySet()) {
if (entry.getValue().equals(trailSeqNumber)) {
orgName = entry.getKey();
if (info.getReturnVariable() != null
&& trailSeqNumber.equals(returnNumber.getObject())) {
origName = entry.getKey();
if (info.getReturnVariable() != null &&
trailSeqNumber.equals(returnNumber.getObject())) {
theRetName = true;
}
}
}
if (orgName != null) {
if (origName != null) {
boolean found = false;
for (NameInformation simNameInfo : mySimilarContainer.getNames()) {
if (orgName.equals(simNameInfo.getDeclaration()
.getRawSignature())) {
addAParameterIfPossible(args, declarations,
simNameInfo);
if (origName.equals(simNameInfo.getDeclaration().getRawSignature())) {
addParameterIfPossible(args, declarations, simNameInfo);
found = true;
if (theRetName) {
@ -715,7 +712,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
if (!found) {
// should be a field, use the old name
IASTIdExpression expression = new CPPASTIdExpression();
CPPASTName fieldName = new CPPASTName(orgName.toCharArray());
CPPASTName fieldName = new CPPASTName(origName.toCharArray());
expression.setName(fieldName);
args.add(expression);
@ -763,7 +760,6 @@ public class ExtractFunctionRefactoring extends CRefactoring {
decl.setDeclSpecifier(orgDecl.getDeclSpecifier().copy(CopyStyle.withLocations));
IASTDeclarator declarator = new CPPASTDeclarator();
declarator.setName(retname);
for (IASTPointerOperator pointer : orgDecl.getDeclarators()[0].getPointerOperators()) {
@ -792,31 +788,30 @@ public class ExtractFunctionRefactoring extends CRefactoring {
private IASTNode getReturnAssignment(IASTExpressionStatement stmt,
IASTExpression callExpression) {
IASTNode node = container.getNodesToWrite().get(0);
return extractedFunctionConstructionHelper.createReturnAssignment(node,
stmt, callExpression);
return extractedFunctionConstructionHelper.createReturnAssignment(node, stmt, callExpression);
}
private IASTSimpleDeclaration getDeclaration(IASTName name) {
IASTSimpleDeclaration simpleDecl = new CPPASTSimpleDeclaration();
IASTStandardFunctionDeclarator declarator =
extractedFunctionConstructionHelper.createFunctionDeclarator(name,
info.getDeclarator(), info.getReturnVariable(),
container.getNodesToWrite(), info.getAllUsedNames(), ast.getASTNodeFactory());
info.getDeclarator(), info.getReturnVariable(), container.getNodesToWrite(),
info.getAllUsedNames(), ast.getASTNodeFactory());
simpleDecl.addDeclarator(declarator);
return simpleDecl;
}
private IASTSimpleDeclaration getDeclaration(ModificationCollector collector,IASTName name) {
private IASTSimpleDeclaration getDeclaration(ModificationCollector collector, IASTName name) {
IASTDeclSpecifier declSpec = getReturnType();
IASTSimpleDeclaration simpleDecl = factory.newSimpleDeclaration(declSpec);
if (info.isVirtual() && declSpec instanceof ICPPASTDeclSpecifier) {
((ICPPASTDeclSpecifier)declSpec).setVirtual(true);
((ICPPASTDeclSpecifier) declSpec).setVirtual(true);
}
simpleDecl.setParent(ast);
IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper
.createFunctionDeclarator(name, info.getDeclarator(), info
.getReturnVariable(), container.getNodesToWrite(), info
.getAllUsedNames(), ast.getASTNodeFactory());
IASTStandardFunctionDeclarator declarator =
extractedFunctionConstructionHelper.createFunctionDeclarator(name,
info.getDeclarator(), info.getReturnVariable(), container.getNodesToWrite(),
info.getAllUsedNames(), ast.getASTNodeFactory());
simpleDecl.addDeclarator(declarator);
return simpleDecl;
}
@ -852,17 +847,17 @@ public class ExtractFunctionRefactoring extends CRefactoring {
public List<IASTInitializerClause> getCallParameters() {
List<IASTInitializerClause> args = new ArrayList<IASTInitializerClause>();
Vector<IASTName> declarations = new Vector<IASTName>();
for (NameInformation nameInf : container.getNames()) {
addAParameterIfPossible(args, declarations, nameInf);
List<IASTName> declarations = new ArrayList<IASTName>();
for (NameInformation nameInfo : container.getNames()) {
addParameterIfPossible(args, declarations, nameInfo);
}
return args;
}
private void addAParameterIfPossible(List<IASTInitializerClause> args,
Vector<IASTName> declarations, NameInformation nameInf) {
if (!nameInf.isDeclarationInScope()) {
IASTName declaration = nameInf.getDeclaration();
private void addParameterIfPossible(List<IASTInitializerClause> args,
List<IASTName> declarations, NameInformation nameInfо) {
if (!nameInfо.isDeclarationInScope()) {
IASTName declaration = nameInfо.getDeclaration();
if (!declarations.contains(declaration)) {
declarations.add(declaration);
IASTIdExpression expression = new CPPASTIdExpression();
@ -875,7 +870,9 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap();
RefactoringDescriptor desc = new ExtractFunctionRefactoringDescription(project.getProject().getName(), "Extract Method Refactoring", "Create method " + info.getMethodName(), arguments); //$NON-NLS-1$//$NON-NLS-2$
RefactoringDescriptor desc =
new ExtractFunctionRefactoringDescription(project.getProject().getName(),
"Extract Method Refactoring", "Create method " + info.getMethodName(), arguments); //$NON-NLS-1$//$NON-NLS-2$
return desc;
}
@ -884,8 +881,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
arguments.put(CRefactoringDescription.FILE_NAME, file.getLocationURI().toString());
arguments.put(CRefactoringDescription.SELECTION, region.getOffset() + "," + region.getLength()); //$NON-NLS-1$
arguments.put(ExtractFunctionRefactoringDescription.NAME, info.getMethodName());
arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY, info.getVisibility().toString());
arguments.put(ExtractFunctionRefactoringDescription.REPLACE_DUPLICATES, Boolean.toString(info.isReplaceDuplicates()));
arguments.put(ExtractFunctionRefactoringDescription.VISIBILITY,
info.getVisibility().toString());
arguments.put(ExtractFunctionRefactoringDescription.REPLACE_DUPLICATES,
Boolean.toString(info.isReplaceDuplicates()));
return arguments;
}
}

View file

@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.text.edits.TextEditGroup;
@ -32,7 +31,7 @@ import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation;
final class SimilarFinderVisitor extends ASTVisitor {
private final ExtractFunctionRefactoring refactoring;
private final Vector<IASTNode> trail;
private final List<IASTNode> trail;
private final IASTName name;
private final List<IASTNode> statements;
private int statementCount;
@ -42,7 +41,7 @@ final class SimilarFinderVisitor extends ASTVisitor {
private final ModificationCollector collector;
SimilarFinderVisitor(ExtractFunctionRefactoring refactoring, ModificationCollector collector,
Vector<IASTNode> trail, IFile file, IASTName name, List<IASTNode> statements,
List<IASTNode> trail, IFile file, IASTName name, List<IASTNode> statements,
String title) {
this.refactoring = refactoring;
this.trail = trail;