mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Use interfaces instead of concrete classes in method signatures.
This commit is contained in:
parent
9b83d66132
commit
6985289cff
9 changed files with 71 additions and 71 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<IASTNode> vec;
|
||||
private final ArrayList<NameInformation> names;
|
||||
private final List<IASTNode> nodes;
|
||||
private final List<NameInformation> names;
|
||||
|
||||
public class NameInformation {
|
||||
private IASTName name;
|
||||
private IASTName declaration;
|
||||
private final ArrayList<IASTName> references;
|
||||
private ArrayList<IASTName> referencesAfterCached;
|
||||
private final List<IASTName> references;
|
||||
private List<IASTName> referencesAfterCached;
|
||||
private int lastCachedReferencesHash;
|
||||
private boolean isReference;
|
||||
private boolean isReturnValue;
|
||||
|
@ -103,9 +103,8 @@ public class NodeContainer {
|
|||
references.add(name);
|
||||
}
|
||||
|
||||
public ArrayList<IASTName> getReferencesAfterSelection() {
|
||||
if (referencesAfterCached == null
|
||||
|| lastCachedReferencesHash != references.hashCode()) {
|
||||
public List<IASTName> getReferencesAfterSelection() {
|
||||
if (referencesAfterCached == null || lastCachedReferencesHash != references.hashCode()) {
|
||||
lastCachedReferencesHash = references.hashCode();
|
||||
referencesAfterCached = new ArrayList<IASTName>();
|
||||
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<IASTNode>();
|
||||
nodes = new ArrayList<IASTNode>();
|
||||
names = new ArrayList<NameInformation>();
|
||||
}
|
||||
|
||||
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<NameInformation> getAllAfterUsedNames() {
|
||||
public List<NameInformation> getAllAfterUsedNames() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
|
@ -364,13 +362,12 @@ public class NodeContainer {
|
|||
return usedAfter;
|
||||
}
|
||||
|
||||
public ArrayList<NameInformation> getAllAfterUsedNamesChoosenByUser() {
|
||||
public List<NameInformation> getAllAfterUsedNamesChoosenByUser() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
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<NameInformation> getUsedNamesUnique() {
|
||||
public List<NameInformation> getUsedNamesUnique() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
|
@ -411,18 +408,19 @@ public class NodeContainer {
|
|||
* selection expected the ones which are pointers
|
||||
* XXX Was soll dieser Kommentar aussagen? --Mirko
|
||||
*/
|
||||
public ArrayList<NameInformation> getAllDeclaredInScope() {
|
||||
public List<NameInformation> getAllDeclaredInScope() {
|
||||
ArrayList<IASTName> declarations = new ArrayList<IASTName>();
|
||||
ArrayList<NameInformation> usedAfter = new ArrayList<NameInformation>();
|
||||
|
||||
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<IASTNode> 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<NameInformation> getNames() {
|
||||
|
|
|
@ -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<NameInformation> name) {
|
||||
void onVisibilityOrReturnChange(List<NameInformation> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IASTNode> 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<IASTNode> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<NameInformation> allAfterUsedNames;
|
||||
private ArrayList<NameInformation> allUsedNames;
|
||||
private List<NameInformation> allAfterUsedNames;
|
||||
private List<NameInformation> allUsedNames;
|
||||
private NameInformation inScopeDeclaredVariable;
|
||||
private NameInformation returnVariable;
|
||||
private ICPPASTFunctionDeclarator declarator;
|
||||
|
@ -65,7 +62,7 @@ public class ExtractFunctionInformation {
|
|||
this.replaceDuplicates = replaceDuplicates;
|
||||
}
|
||||
|
||||
public ArrayList<NameInformation> getAllAfterUsedNames() {
|
||||
public List<NameInformation> getAllAfterUsedNames() {
|
||||
if (allAfterUsedNames == null) {
|
||||
allAfterUsedNames = new ArrayList<NameInformation>();
|
||||
for (NameInformation name : getAllUsedNames()) {
|
||||
|
@ -101,11 +98,11 @@ public class ExtractFunctionInformation {
|
|||
this.inScopeDeclaredVariable = inScopeDeclaredVariable;
|
||||
}
|
||||
|
||||
public ArrayList<NameInformation> getAllUsedNames() {
|
||||
public List<NameInformation> getAllUsedNames() {
|
||||
return allUsedNames;
|
||||
}
|
||||
|
||||
public void setAllUsedNames(ArrayList<NameInformation> allUsedNames) {
|
||||
public void setAllUsedNames(List<NameInformation> allUsedNames) {
|
||||
this.allUsedNames = allUsedNames;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<IASTInitializerClause> args,
|
||||
List<IASTName> declarations, NameInformation nameInfо) {
|
||||
if (!nameInfо.isDeclarationInScope()) {
|
||||
if (!nameInfо.isDeclarationExtracted()) {
|
||||
IASTName declaration = nameInfо.getDeclaration();
|
||||
if (!declarations.contains(declaration)) {
|
||||
declarations.add(declaration);
|
||||
|
|
|
@ -36,13 +36,14 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper {
|
|||
@Override
|
||||
public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> 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);
|
||||
|
|
|
@ -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<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
|
||||
List<IASTNode> nodesToWrite, Collection<NameInformation> 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<IASTParameterDeclaration> getParameterDeclarations(Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
|
||||
Collection<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>();
|
||||
public List<IASTParameterDeclaration> getParameterDeclarations(
|
||||
Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
|
||||
List<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>();
|
||||
for (NameInformation name : allUsedNames) {
|
||||
if (!name.isDeclarationInScope()) {
|
||||
if (!name.isDeclarationExtracted()) {
|
||||
result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue