diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java index 13d0d67d2a4..93d5ca243ff 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java @@ -35,7 +35,6 @@ public final class Messages extends NLS { public static String Refactoring_CantLoadTU; public static String Refactoring_Ambiguity; public static String Refactoring_ParsingError; - public static String NodeContainer_Name; public static String NO_FILE; public static String RefactoringSaveHelper_unexpected_exception; public static String RefactoringSaveHelper_saving; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties index 6ae45bc3622..04adb314e15 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.properties @@ -31,7 +31,6 @@ Refactoring_CantLoadTU=Can not load translation unit. Refactoring_Ambiguity=Translation unit is ambiguous. Refactoring_ParsingError=Unable to parse {0}. NO_FILE=File not found. -NodeContainer_Name=name: RefactoringSaveHelper_unexpected_exception=An unexpected exception occurred. See the error log for more details. RefactoringSaveHelper_saving=Saving Resources RefactoringSaveHelper_always_save=&Always save all modified resources automatically prior to refactoring 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 169f1400639..6b86328d49f 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 @@ -50,14 +50,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter; public class NodeContainer { public final NameInformation NULL_NAME_INFORMATION = new NameInformation(new CPPASTName()); - private final ArrayList vec; - private final ArrayList names; + private final List nodes; + private final List names; public class NameInformation { private IASTName name; private IASTName declaration; - private final ArrayList references; - private ArrayList referencesAfterCached; + private final List references; + private List referencesAfterCached; private int lastCachedReferencesHash; private boolean isReference; private boolean isReturnValue; @@ -103,9 +103,8 @@ public class NodeContainer { references.add(name); } - public ArrayList getReferencesAfterSelection() { - if (referencesAfterCached == null - || lastCachedReferencesHash != references.hashCode()) { + public List getReferencesAfterSelection() { + if (referencesAfterCached == null || lastCachedReferencesHash != references.hashCode()) { lastCachedReferencesHash = references.hashCode(); referencesAfterCached = new ArrayList(); for (IASTName ref : references) { @@ -196,18 +195,17 @@ public class NodeContainer { return writer.write(declSpec); } - public boolean isDeclarationInScope() { + public boolean isDeclarationExtracted() { if (declaration != null && declaration.toCharArray().length > 0) { int declOffset = declaration.getFileLocation().getNodeOffset(); - return declOffset >= getStartOffset() - && declOffset <= getEndOffset(); + return declOffset >= getStartOffset() && declOffset <= getEndOffset(); } return true; } @Override public String toString() { - return Messages.NodeContainer_Name + name + ' ' + isDeclarationInScope(); + return name.toString() + ": " + (isDeclarationExtracted() ? "with declaration" : "without declaration"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } public boolean isReference() { @@ -269,24 +267,24 @@ public class NodeContainer { public NodeContainer() { super(); - vec = new ArrayList(); + nodes = new ArrayList(); names = new ArrayList(); } public final int size() { - return vec.size(); + return nodes.size(); } public final boolean isEmpty() { - return vec.isEmpty(); + return nodes.isEmpty(); } public void add(IASTNode node) { - vec.add(node); + nodes.add(node); } public void findAllNames() { - for (IASTNode node : vec) { + for (IASTNode node : nodes) { node.accept(new ASTVisitor() { { shouldVisitNames = true; @@ -343,7 +341,7 @@ public class NodeContainer { * Returns all local names in the selection which will be used after the * selection expected the ones which are pointers */ - public ArrayList getAllAfterUsedNames() { + public List getAllAfterUsedNames() { ArrayList declarations = new ArrayList(); ArrayList usedAfter = new ArrayList(); @@ -364,13 +362,12 @@ public class NodeContainer { return usedAfter; } - public ArrayList getAllAfterUsedNamesChoosenByUser() { + public List getAllAfterUsedNamesChoosenByUser() { ArrayList declarations = new ArrayList(); ArrayList usedAfter = new ArrayList(); for (NameInformation nameInf : names) { if (!declarations.contains(nameInf.getDeclaration())) { - declarations.add(nameInf.getDeclaration()); if (nameInf.isUserSetIsReference() || nameInf.isUserSetIsReturnValue()) { usedAfter.add(nameInf); @@ -381,7 +378,7 @@ public class NodeContainer { return usedAfter; } - public ArrayList getUsedNamesUnique() { + public List getUsedNamesUnique() { ArrayList declarations = new ArrayList(); ArrayList usedAfter = new ArrayList(); @@ -411,18 +408,19 @@ public class NodeContainer { * selection expected the ones which are pointers * XXX Was soll dieser Kommentar aussagen? --Mirko */ - public ArrayList getAllDeclaredInScope() { + public List getAllDeclaredInScope() { ArrayList declarations = new ArrayList(); ArrayList usedAfter = new ArrayList(); - for (NameInformation nameInf : names) { - if (nameInf.isDeclarationInScope() - && !declarations.contains(nameInf.getDeclaration()) && nameInf.isUsedAfterReferences()) { - declarations.add(nameInf.getDeclaration()); - usedAfter.add(nameInf); - // is return value candidate, set return value to true and reference to false - nameInf.setReturnValue(true); - nameInf.setReference(false); + for (NameInformation nameInfo : names) { + if (nameInfo.isDeclarationExtracted() && + !declarations.contains(nameInfo.getDeclaration()) && + nameInfo.isUsedAfterReferences()) { + declarations.add(nameInfo.getDeclaration()); + usedAfter.add(nameInfo); + // Is return value candidate, set return value to true and reference to false + nameInfo.setReturnValue(true); + nameInfo.setReference(false); } } @@ -430,7 +428,7 @@ public class NodeContainer { } public List getNodesToWrite() { - return vec; + return nodes; } public int getStartOffset() { @@ -444,7 +442,7 @@ public class NodeContainer { private int getOffset(boolean includeComments) { int start = Integer.MAX_VALUE; - for (IASTNode node : vec) { + for (IASTNode node : nodes) { int nodeStart = Integer.MAX_VALUE; IASTNodeLocation[] nodeLocations = node.getNodeLocations(); @@ -483,7 +481,7 @@ public class NodeContainer { private int getEndOffset(boolean includeComments) { int end = 0; - for (IASTNode node : vec) { + for (IASTNode node : nodes) { int fileOffset = 0; int length = 0; @@ -514,7 +512,7 @@ public class NodeContainer { @Override public String toString() { - return vec.toString(); + return nodes.toString(); } public List getNames() { 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 26f450d94c3..8ec5231fee4 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 @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring.extractfunction; import java.util.ArrayList; +import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; @@ -38,13 +39,13 @@ public class ChooserComposite extends Composite { private Button voidReturn; - private final ExtractFunctionInputPage ip; + private final ExtractFunctionInputPage page; public ChooserComposite(Composite parent, final ExtractFunctionInformation info, - ExtractFunctionInputPage ip) { + ExtractFunctionInputPage page) { super(parent, SWT.NONE); - this.ip = ip; + this.page = page; GridLayout layout = new GridLayout(); setLayout(layout); @@ -75,7 +76,7 @@ public class ChooserComposite extends Composite { addColumnToTable(table, ""); //$NON-NLS-1$ for (int i = 0; i < info.getAllUsedNames().size(); i++) { - if (!info.getAllUsedNames().get(i).isDeclarationInScope()) { + if (!info.getAllUsedNames().get(i).isDeclarationExtracted()) { TableItem item = new TableItem(table, SWT.NONE); TableEditor editor = new TableEditor(table); @@ -212,15 +213,15 @@ public class ChooserComposite extends Composite { column.setWidth(100); } - void onVisibilityOrReturnChange(ArrayList name) { + void onVisibilityOrReturnChange(List name) { String variableUsedAfterBlock = null; for (NameInformation information : name) { - if (information.isUsedAfterReferences() - && !(information.isUserSetIsReference() || information.isUserSetIsReturnValue())) { + if (information.isUsedAfterReferences() && + !(information.isUserSetIsReference() || information.isUserSetIsReturnValue())) { variableUsedAfterBlock = information.getName().toString(); } } - ip.errorWithAfterUsedVariable(variableUsedAfterBlock); + page.errorWithAfterUsedVariable(variableUsedAfterBlock); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java index c4555e77a57..5a93af1cab0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java @@ -53,7 +53,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction; import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; /** - * Handles the extraction of expression nodes, like return type determination. + * Handles the extraction of expression nodes, for example, return type determination. * * @author Mirko Stocker */ @@ -64,7 +64,8 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper { public void constructMethodBody(IASTCompoundStatement compound, List list, ASTRewrite rewrite, TextEditGroup group) { CPPASTReturnStatement statement = new CPPASTReturnStatement(); - IASTExpression nullReturnExp = new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, ZERO); + IASTExpression nullReturnExp = + new CPPASTLiteralExpression(IASTLiteralExpression.lk_integer_constant, ZERO); statement.setReturnValue(nullReturnExp); ASTRewrite nestedRewrite = rewrite.insertBefore(compound, null, statement, group); @@ -72,11 +73,11 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper { } private IASTExpression getExpression(List list) { - if (list.size()> 1) { + if (list.size() > 1) { CPPASTBinaryExpression bExp = new CPPASTBinaryExpression(); bExp.setParent(list.get(0).getParent()); bExp.setOperand1((IASTExpression) list.get(0).copy(CopyStyle.withLocations)); - bExp.setOperator(((IASTBinaryExpression)list.get(1).getParent()).getOperator()); + bExp.setOperator(((IASTBinaryExpression) list.get(1).getParent()).getOperator()); bExp.setOperand2(getExpression(list.subList(1, list.size()))); return bExp; } else { @@ -154,7 +155,7 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper { } @Override - protected boolean isReturnTypeAPointer(IASTNode node) { + protected boolean hasPointerReturnType(IASTNode node) { if (node instanceof ICPPASTNewExpression) { return true; } else if (!(node instanceof IASTFunctionCallExpression)) { @@ -186,11 +187,13 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper { } private static boolean hasDeclaration(CPPFunction function) { - return function != null && function.getDeclarations() != null && function.getDeclarations().length > 0; + return function != null && function.getDeclarations() != null && + function.getDeclarations().length > 0; } @Override - public IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt, IASTExpression callExpression) { + public IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt, + IASTExpression callExpression) { return callExpression; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java index 64f9b8d8d24..14782828a76 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInformation.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.refactoring.extractfunction; import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; @@ -20,15 +21,11 @@ import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; public class ExtractFunctionInformation { - public final int VISIBILITY_PRIVATE = 1; - public final int VISIBILITY_PROTECTED = 3; - public final int VISIBILITY_PUBLIC = 2; - private VisibilityEnum visibility = VisibilityEnum.v_private; private String methodName; private boolean replaceDuplicates; - private ArrayList allAfterUsedNames; - private ArrayList allUsedNames; + private List allAfterUsedNames; + private List allUsedNames; private NameInformation inScopeDeclaredVariable; private NameInformation returnVariable; private ICPPASTFunctionDeclarator declarator; @@ -65,7 +62,7 @@ public class ExtractFunctionInformation { this.replaceDuplicates = replaceDuplicates; } - public ArrayList getAllAfterUsedNames() { + public List getAllAfterUsedNames() { if (allAfterUsedNames == null) { allAfterUsedNames = new ArrayList(); for (NameInformation name : getAllUsedNames()) { @@ -101,11 +98,11 @@ public class ExtractFunctionInformation { this.inScopeDeclaredVariable = inScopeDeclaredVariable; } - public ArrayList getAllUsedNames() { + public List getAllUsedNames() { return allUsedNames; } - public void setAllUsedNames(ArrayList allUsedNames) { + public void setAllUsedNames(List allUsedNames) { this.allUsedNames = allUsedNames; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 6fa612a08b8..580b8ac18b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -201,7 +201,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { info.getInScopeDeclaredVariable().setUserSetIsReturnValue(true); } for (int i = 0; i < info.getAllUsedNames().size(); i++) { - if (!info.getAllUsedNames().get(i).isDeclarationInScope()) { + if (!info.getAllUsedNames().get(i).isDeclarationExtracted()) { NameInformation name = info.getAllUsedNames().get(i); if (!name.isReturnValue()) { name.setUserSetIsReference(name.isReference()); @@ -856,7 +856,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { private void addParameterIfPossible(List args, List declarations, NameInformation nameInfо) { - if (!nameInfо.isDeclarationInScope()) { + if (!nameInfо.isDeclarationExtracted()) { IASTName declaration = nameInfо.getDeclaration(); if (!declarations.contains(declaration)) { declarations.add(declaration); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractStatement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractStatement.java index 77c306e4db3..221b6a47bc8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractStatement.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractStatement.java @@ -36,13 +36,14 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper { @Override public void constructMethodBody(IASTCompoundStatement compound, List list, ASTRewrite rewrite, TextEditGroup group) { - for (IASTNode each : list) { - rewrite.insertBefore(compound, null, each, group); + for (IASTNode node : list) { + rewrite.insertBefore(compound, null, node, group); } } @Override - public IASTDeclSpecifier determineReturnType(IASTNode extractedNode, NameInformation returnVariable) { + public IASTDeclSpecifier determineReturnType(IASTNode extractedNode, + NameInformation returnVariable) { if (returnVariable != null) { IASTNode decl = ASTHelper.getDeclarationForNode(returnVariable.getDeclaration()); return ASTHelper.getDeclarationSpecifier(decl).copy(CopyStyle.withLocations); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java index 5b5543fa357..19b869c6124 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Institute for Software - initial API and implementation + * Institute for Software - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.extractfunction; @@ -55,13 +55,14 @@ public abstract class ExtractedFunctionConstructionHelper { public abstract IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt, IASTExpression callExpression); - protected boolean isReturnTypeAPointer(IASTNode node) { + protected boolean hasPointerReturnType(IASTNode node) { return false; } IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, IASTStandardFunctionDeclarator functionDeclarator, NameInformation returnVariable, - List nodesToWrite, Collection allUsedNames, INodeFactory nodeFactory) { + List nodesToWrite, Collection allUsedNames, + INodeFactory nodeFactory) { IASTStandardFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name); if (functionDeclarator instanceof ICPPASTFunctionDeclarator && @@ -83,17 +84,18 @@ public abstract class ExtractedFunctionConstructionHelper { declarator.addParameterDeclaration(param); } - if (isReturnTypeAPointer(nodesToWrite.get(0))) { + if (hasPointerReturnType(nodesToWrite.get(0))) { declarator.addPointerOperator(nodeFactory.newPointer()); } return declarator; } - public Collection getParameterDeclarations(Collection allUsedNames, INodeFactory nodeFactory) { - Collection result = new ArrayList(); + public List getParameterDeclarations( + Collection allUsedNames, INodeFactory nodeFactory) { + List result = new ArrayList(); for (NameInformation name : allUsedNames) { - if (!name.isDeclarationInScope()) { + if (!name.isDeclarationExtracted()) { result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory)); } }