mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Merge remote-tracking branch 'cdt/master' into sd90
This commit is contained in:
commit
5ac21f1de1
12 changed files with 294 additions and 207 deletions
|
@ -12,8 +12,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -32,6 +30,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ASTWriter main class. Generates source code from <code>IASTNode</code>.
|
* ASTWriter main class. Generates source code from <code>IASTNode</code>.
|
||||||
* Uses a {@link ChangeGeneratorWriterVisitor} to generate the code for the given nodes.
|
* Uses a {@link ChangeGeneratorWriterVisitor} to generate the code for the given nodes.
|
||||||
|
@ -82,7 +82,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* before it.
|
* before it.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if the node should be separated by a blank line from the node
|
* @return <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* before it.
|
* before it.
|
||||||
|
@ -99,7 +99,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
* Returns <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* after it.
|
* after it.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if the node should be separated by a blank line from the node
|
* @return <code>true</code> if the node should be separated by a blank line from the node
|
||||||
* after it.
|
* after it.
|
||||||
|
@ -126,7 +126,7 @@ public class ASTWriter {
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if there should be no blank line after this node even if a blank
|
* Returns <code>true</code> if there should be no blank line after this node even if a blank
|
||||||
* line is normally required before the subsequent node.
|
* line is normally required before the subsequent node.
|
||||||
*
|
*
|
||||||
* @param node The node.
|
* @param node The node.
|
||||||
* @return <code>true</code> if there should be no blank line after this node.
|
* @return <code>true</code> if there should be no blank line after this node.
|
||||||
*/
|
*/
|
||||||
|
@ -136,7 +136,7 @@ public class ASTWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <code>true</code> if the two given nodes should be separated by a blank line.
|
* Returns <code>true</code> if the two given nodes should be separated by a blank line.
|
||||||
*
|
*
|
||||||
* @param node1 The first node.
|
* @param node1 The first node.
|
||||||
* @param node2 The second node.
|
* @param node2 The second node.
|
||||||
* @return <code>true</code> if the blank line between the nodes is needed.
|
* @return <code>true</code> if the blank line between the nodes is needed.
|
||||||
|
@ -173,7 +173,7 @@ public class ASTWriter {
|
||||||
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
|
if (isFunctionDeclaration(node1) != isFunctionDeclaration(node2)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (requiresTrailingBlankLine(node1)) {
|
if (node2 != null && requiresTrailingBlankLine(node1)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||||
|
@ -36,6 +34,8 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visits all nodes, prints leading comments and handles macro expansions. The
|
* Visits all nodes, prints leading comments and handles macro expansions. The
|
||||||
* source code generation is delegated to severals {@code NodeWriter}s.
|
* source code generation is delegated to severals {@code NodeWriter}s.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
@ -45,7 +45,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
/**
|
/**
|
||||||
* Generates source code of statement nodes. The actual string operations are delegated
|
* Generates source code of statement nodes. The actual string operations are delegated
|
||||||
* to the <code>Scribe</code> class.
|
* to the <code>Scribe</code> class.
|
||||||
*
|
*
|
||||||
* @see Scribe
|
* @see Scribe
|
||||||
* @see IASTStatement
|
* @see IASTStatement
|
||||||
* @author Emanuel Graf IFS
|
* @author Emanuel Graf IFS
|
||||||
|
@ -75,10 +75,10 @@ public class StatementWriter extends NodeWriter {
|
||||||
super(scribe, visitor, commentMap);
|
super(scribe, visitor, commentMap);
|
||||||
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
|
declWriter = new DeclarationWriter(scribe, visitor, commentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a statement.
|
* Prints a statement.
|
||||||
*
|
*
|
||||||
* @param statement the statement
|
* @param statement the statement
|
||||||
* @param newLine if true print a newline if statement usually have one.
|
* @param newLine if true print a newline if statement usually have one.
|
||||||
* @return {@link ASTVisitor#PROCESS_SKIP}
|
* @return {@link ASTVisitor#PROCESS_SKIP}
|
||||||
|
@ -108,18 +108,18 @@ public class StatementWriter extends NodeWriter {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTCaseStatement) {
|
} else if (statement instanceof IASTCaseStatement) {
|
||||||
writeCaseStatement((IASTCaseStatement) statement);
|
writeCaseStatement((IASTCaseStatement) statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
} else if (statement instanceof IASTDefaultStatement) {
|
} else if (statement instanceof IASTDefaultStatement) {
|
||||||
writeDefaultStatement((IASTDefaultStatement)statement);
|
writeDefaultStatement((IASTDefaultStatement)statement);
|
||||||
} else if (statement instanceof IASTContinueStatement) {
|
} else if (statement instanceof IASTContinueStatement) {
|
||||||
writeContinueStatement((IASTContinueStatement)statement);
|
writeContinueStatement((IASTContinueStatement)statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
} else if (statement instanceof IASTCompoundStatement) {
|
} else if (statement instanceof IASTCompoundStatement) {
|
||||||
writeCompoundStatement((IASTCompoundStatement) statement);
|
|
||||||
if (compoundNoNewLine) {
|
if (compoundNoNewLine) {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
compoundNoNewLine = false;
|
compoundNoNewLine = false;
|
||||||
}
|
}
|
||||||
|
writeCompoundStatement((IASTCompoundStatement) statement);
|
||||||
} else if (statement instanceof IASTBreakStatement) {
|
} else if (statement instanceof IASTBreakStatement) {
|
||||||
writeBreakStatement((IASTBreakStatement) statement);
|
writeBreakStatement((IASTBreakStatement) statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
|
@ -127,7 +127,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
writeSwitchStatement((IASTSwitchStatement) statement);
|
writeSwitchStatement((IASTSwitchStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTIfStatement) {
|
} else if (statement instanceof IASTIfStatement) {
|
||||||
writeIfStatement((IASTIfStatement) statement);
|
writeIfStatement((IASTIfStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTWhileStatement) {
|
} else if (statement instanceof IASTWhileStatement) {
|
||||||
writeWhileStatement((IASTWhileStatement) statement);
|
writeWhileStatement((IASTWhileStatement) statement);
|
||||||
|
@ -149,16 +149,16 @@ public class StatementWriter extends NodeWriter {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTProblemStatement) {
|
} else if (statement instanceof IASTProblemStatement) {
|
||||||
throw new ProblemRuntimeException((IASTProblemStatement)statement);
|
throw new ProblemRuntimeException((IASTProblemStatement)statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeTrailingComments(statement, newLine);
|
writeTrailingComments(statement, newLine);
|
||||||
|
|
||||||
return ASTVisitor.PROCESS_SKIP;
|
return ASTVisitor.PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDoStatement(IASTDoStatement doStatement) {
|
private void writeDoStatement(IASTDoStatement doStatement) {
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
|
|
||||||
scribe.print(DO);
|
scribe.print(DO);
|
||||||
writeBodyStatement(doStatement.getBody(), true);
|
writeBodyStatement(doStatement.getBody(), true);
|
||||||
scribe.print(DO_WHILE);
|
scribe.print(DO_WHILE);
|
||||||
|
@ -186,7 +186,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.printSemicolon();
|
scribe.printSemicolon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visitNodeIfNotNull(forStatement.getIterationExpression());
|
visitNodeIfNotNull(forStatement.getIterationExpression());
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
|
@ -220,13 +220,13 @@ public class StatementWriter extends NodeWriter {
|
||||||
} else {
|
} else {
|
||||||
ifStatement.getConditionExpression().accept(visitor);
|
ifStatement.getConditionExpression().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
IASTStatement elseClause = ifStatement.getElseClause();
|
IASTStatement elseClause = ifStatement.getElseClause();
|
||||||
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
|
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
|
||||||
|
|
||||||
if (elseClause != null) {
|
if (elseClause != null) {
|
||||||
scribe.print(ELSE);
|
scribe.print(ELSE);
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
|
@ -251,7 +251,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
private void writeLabelStatement(IASTLabelStatement labelStatement) {
|
private void writeLabelStatement(IASTLabelStatement labelStatement) {
|
||||||
labelStatement.getName().accept(visitor);
|
labelStatement.getName().accept(visitor);
|
||||||
scribe.print(':');
|
scribe.print(':');
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
labelStatement.getNestedStatement().accept(visitor);
|
labelStatement.getNestedStatement().accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
private void writeNullStatement(IASTNullStatement nullStmt) {
|
private void writeNullStatement(IASTNullStatement nullStmt) {
|
||||||
scribe.printSemicolon();
|
scribe.printSemicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
|
private void writeDeclarationStatement(IASTDeclarationStatement decStmt) {
|
||||||
decStmt.getDeclaration().accept(visitor);
|
decStmt.getDeclaration().accept(visitor);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
cppWhileStatment.getCondition().accept(visitor);
|
cppWhileStatment.getCondition().accept(visitor);
|
||||||
} else {
|
} else {
|
||||||
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
|
writeDeclarationWithoutSemicolon(cppWhileStatment.getConditionDeclaration());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
whileStatment.getCondition().accept(visitor);
|
whileStatment.getCondition().accept(visitor);
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
||||||
nextCompoundIndentationLevelOneMore();
|
nextCompoundIndentationLevelOneMore();
|
||||||
|
|
||||||
if (!switchIsNew) {
|
if (!switchIsNew) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
|
private void writeSwitchStatement(IASTSwitchStatement switchStatement) {
|
||||||
switchIsNew = true;
|
switchIsNew = true;
|
||||||
|
|
||||||
scribe.print(SWITCH_BRACKET);
|
scribe.print(SWITCH_BRACKET);
|
||||||
scribe.noNewLines();
|
scribe.noNewLines();
|
||||||
if (switchStatement instanceof ICPPASTSwitchStatement) {
|
if (switchStatement instanceof ICPPASTSwitchStatement) {
|
||||||
|
@ -359,13 +359,13 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(switchStatement.getBody(), false);
|
writeBodyStatement(switchStatement.getBody(), false);
|
||||||
|
|
||||||
switchIsNew = false;
|
switchIsNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
|
private void writeDefaultStatement(IASTDefaultStatement defaultStatement) {
|
||||||
nextCompoundIndentationLevelOneMore();
|
nextCompoundIndentationLevelOneMore();
|
||||||
|
|
||||||
if (!switchIsNew) {
|
if (!switchIsNew) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
|
@ -373,18 +373,18 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.incrementIndentationLevel();
|
scribe.incrementIndentationLevel();
|
||||||
switchIsNew = false;
|
switchIsNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
|
private void writeCompoundStatement(IASTCompoundStatement compoundStatement) {
|
||||||
scribe.printLBrace();
|
scribe.printLBrace();
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
for (IASTStatement statements : getNestedStatements(compoundStatement)) {
|
for (IASTStatement statements : getNestedStatements(compoundStatement)) {
|
||||||
statements.accept(visitor);
|
statements.accept(visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasFreestandingComments(compoundStatement)) {
|
if (hasFreestandingComments(compoundStatement)) {
|
||||||
writeFreestandingComments(compoundStatement);
|
writeFreestandingComments(compoundStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decrementIndentationLevelOneMore) {
|
if (decrementIndentationLevelOneMore) {
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
decrementIndentationLevelOneMore = false;
|
decrementIndentationLevelOneMore = false;
|
||||||
|
@ -394,9 +394,9 @@ public class StatementWriter extends NodeWriter {
|
||||||
|
|
||||||
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
|
protected IASTStatement[] getNestedStatements(IASTCompoundStatement compoundStatement) {
|
||||||
return compoundStatement.getStatements();
|
return compoundStatement.getStatements();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sprigogin): Rename second parameter
|
// TODO(sprigogin): Invert and rename second parameter
|
||||||
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
//TODO hsr existiert noch eine methode
|
//TODO hsr existiert noch eine methode
|
||||||
|
@ -409,23 +409,23 @@ public class StatementWriter extends NodeWriter {
|
||||||
statement.accept(visitor);
|
statement.accept(visitor);
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
} else {
|
} else {
|
||||||
scribe.incrementIndentationLevel();
|
scribe.incrementIndentationLevel();
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
statement.accept(visitor);
|
statement.accept(visitor);
|
||||||
scribe.decrementIndentationLevel();
|
scribe.decrementIndentationLevel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write no new Line after the next compound statement
|
* Write no new line after the next compound statement
|
||||||
*/
|
*/
|
||||||
protected void nextCompoundNoNewLine() {
|
protected void nextCompoundNoNewLine() {
|
||||||
compoundNoNewLine = true;
|
compoundNoNewLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indent one time more at the end (before the closing brackets)
|
* Indent one time more at the end (before the closing brackets)
|
||||||
* of a compound statement
|
* of a compound statement
|
||||||
*/
|
*/
|
||||||
protected void nextCompoundIndentationLevelOneMore() {
|
protected void nextCompoundIndentationLevelOneMore() {
|
||||||
decrementIndentationLevelOneMore = true;
|
decrementIndentationLevelOneMore = true;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007, 2011 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2007, 2011 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -42,13 +42,54 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a declaration to an existing class via the ModificationCollector. Automatically determines
|
* Adds a declaration to an existing class via the ModificationCollector. Automatically determines
|
||||||
* an appropriate insertion point for the desired visibility.
|
* an appropriate insertion point for the desired visibility.
|
||||||
*
|
*
|
||||||
* @author Mirko Stocker
|
* @author Mirko Stocker
|
||||||
*/
|
*/
|
||||||
public class ClassMemberInserter {
|
public class ClassMemberInserter {
|
||||||
|
public static class InsertionInfo {
|
||||||
|
private final IASTNode parentNode;
|
||||||
|
/**
|
||||||
|
* The node before which the new node should be inserted. A null value indicates insertion
|
||||||
|
* to the end of parentNode
|
||||||
|
*/
|
||||||
|
private IASTNode insertBeforeNode; //
|
||||||
|
/** Visibility label to insert before the new node or null. */
|
||||||
|
private ICPPASTVisibilityLabel prologue;
|
||||||
|
/** Visibility label to insert after the new node or null. */
|
||||||
|
private ICPPASTVisibilityLabel epilogue;
|
||||||
|
|
||||||
|
public InsertionInfo(IASTNode parentNode, IASTNode insertBeforeNode) {
|
||||||
|
this.parentNode = parentNode;
|
||||||
|
this.insertBeforeNode = insertBeforeNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertionInfo(IASTNode parentNode) {
|
||||||
|
this(parentNode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IASTNode getParentNode() {
|
||||||
|
return parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IASTNode getInsertBeforeNode() {
|
||||||
|
return insertBeforeNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICPPASTVisibilityLabel getPrologue() {
|
||||||
|
return prologue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICPPASTVisibilityLabel getEpilogue() {
|
||||||
|
return epilogue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not instantiatable. All methods are static.
|
||||||
|
private ClassMemberInserter() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void createChange(ICPPASTCompositeTypeSpecifier classNode,
|
public static void createChange(ICPPASTCompositeTypeSpecifier classNode,
|
||||||
VisibilityEnum visibility, IASTNode nodeToAdd, boolean isField,
|
VisibilityEnum visibility, IASTNode nodeToAdd, boolean isField,
|
||||||
ModificationCollector collector) {
|
ModificationCollector collector) {
|
||||||
|
@ -58,7 +99,23 @@ public class ClassMemberInserter {
|
||||||
public static void createChange(ICPPASTCompositeTypeSpecifier classNode,
|
public static void createChange(ICPPASTCompositeTypeSpecifier classNode,
|
||||||
VisibilityEnum visibility, List<IASTNode> nodesToAdd, boolean isField,
|
VisibilityEnum visibility, List<IASTNode> nodesToAdd, boolean isField,
|
||||||
ModificationCollector collector) {
|
ModificationCollector collector) {
|
||||||
|
InsertionInfo info = findInsertionPoint(classNode, visibility, isField);
|
||||||
nodesToAdd = new ArrayList<IASTNode>(nodesToAdd);
|
nodesToAdd = new ArrayList<IASTNode>(nodesToAdd);
|
||||||
|
if (info.getPrologue() != null)
|
||||||
|
nodesToAdd.add(0, info.getPrologue());
|
||||||
|
if (info.getEpilogue() != null)
|
||||||
|
nodesToAdd.add(info.getEpilogue());
|
||||||
|
|
||||||
|
ASTRewrite rewrite = collector.rewriterForTranslationUnit(classNode.getTranslationUnit());
|
||||||
|
for (IASTNode node : nodesToAdd) {
|
||||||
|
rewrite.insertBefore(info.getParentNode(), info.getInsertBeforeNode(), node,
|
||||||
|
createEditDescription(classNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InsertionInfo findInsertionPoint(ICPPASTCompositeTypeSpecifier classNode,
|
||||||
|
VisibilityEnum visibility, boolean isField) {
|
||||||
|
InsertionInfo info = new InsertionInfo(classNode);
|
||||||
VisibilityEnum defaultVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ?
|
VisibilityEnum defaultVisibility = classNode.getKey() == IASTCompositeTypeSpecifier.k_struct ?
|
||||||
VisibilityEnum.v_public : VisibilityEnum.v_private;
|
VisibilityEnum.v_public : VisibilityEnum.v_private;
|
||||||
VisibilityEnum currentVisibility = defaultVisibility;
|
VisibilityEnum currentVisibility = defaultVisibility;
|
||||||
|
@ -69,13 +126,13 @@ public class ClassMemberInserter {
|
||||||
int lastMatchingVisibilityIndex = -1;
|
int lastMatchingVisibilityIndex = -1;
|
||||||
int lastPrecedingVisibilityIndex = -1;
|
int lastPrecedingVisibilityIndex = -1;
|
||||||
IASTDeclaration[] members = classNode.getMembers();
|
IASTDeclaration[] members = classNode.getMembers();
|
||||||
|
|
||||||
// Find the insert location by iterating over the elements of the class
|
// Find the insert location by iterating over the elements of the class
|
||||||
// and remembering the last element with the matching visibility and the last element
|
// and remembering the last element with the matching visibility and the last element
|
||||||
// with preceding visibility (according to the visibility order preference).
|
// with preceding visibility (according to the visibility order preference).
|
||||||
for (int i = 0; i < members.length; i++) {
|
for (int i = 0; i < members.length; i++) {
|
||||||
IASTDeclaration declaration = members[i];
|
IASTDeclaration declaration = members[i];
|
||||||
|
|
||||||
if (declaration instanceof ICPPASTVisibilityLabel) {
|
if (declaration instanceof ICPPASTVisibilityLabel) {
|
||||||
currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration);
|
currentVisibility = VisibilityEnum.from((ICPPASTVisibilityLabel) declaration);
|
||||||
}
|
}
|
||||||
|
@ -105,24 +162,19 @@ public class ClassMemberInserter {
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
index = lastPrecedingVisibilityIndex;
|
index = lastPrecedingVisibilityIndex;
|
||||||
index++;
|
index++;
|
||||||
IASTNode nextNode = index < members.length ? members[index] : null;
|
if (index < members.length)
|
||||||
|
info.insertBeforeNode = members[index];
|
||||||
|
|
||||||
if (lastMatchingVisibilityIndex < 0 &&
|
if (lastMatchingVisibilityIndex < 0 &&
|
||||||
!(index == 0 && classNode.getKey() == IASTCompositeTypeSpecifier.k_struct && visibility == defaultVisibility)) {
|
!(index == 0 && classNode.getKey() == IASTCompositeTypeSpecifier.k_struct &&
|
||||||
nodesToAdd.add(0, new CPPASTVisibilityLabel(visibility.getVisibilityLabelValue()));
|
visibility == defaultVisibility)) {
|
||||||
if (index == 0 && nextNode != null && !(nextNode instanceof ICPPASTVisibilityLabel)) {
|
info.prologue = new CPPASTVisibilityLabel(visibility.getVisibilityLabelValue());
|
||||||
nodesToAdd.add(new CPPASTVisibilityLabel(defaultVisibility.getVisibilityLabelValue()));
|
if (index == 0 && info.insertBeforeNode != null &&
|
||||||
|
!(info.insertBeforeNode instanceof ICPPASTVisibilityLabel)) {
|
||||||
|
info.epilogue = new CPPASTVisibilityLabel(defaultVisibility.getVisibilityLabelValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return info;
|
||||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(classNode.getTranslationUnit());
|
|
||||||
for (IASTNode node : nodesToAdd) {
|
|
||||||
rewrite.insertBefore(classNode, nextNode, node, createEditDescription(classNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not instantiatable. All methods are static.
|
|
||||||
private ClassMemberInserter() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TextEditGroup createEditDescription(ICPPASTCompositeTypeSpecifier classNode) {
|
private static TextEditGroup createEditDescription(ICPPASTCompositeTypeSpecifier classNode) {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring;
|
package org.eclipse.cdt.internal.ui.refactoring;
|
||||||
|
|
||||||
public interface EqualityChecker<T> {
|
public interface EqualityChecker<T> {
|
||||||
boolean isEquals(T object1, T object2);
|
boolean isEqual(T object1, T object2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring;
|
package org.eclipse.cdt.internal.ui.refactoring;
|
||||||
|
@ -26,8 +26,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a function or method and adds some useful helper methods to
|
* Represents a function or method and adds some useful helper methods to determine
|
||||||
* determine if methods are in the same class.
|
* if two methods are in the same class.
|
||||||
*/
|
*/
|
||||||
public class MethodContext {
|
public class MethodContext {
|
||||||
public enum ContextType { NONE, FUNCTION, METHOD }
|
public enum ContextType { NONE, FUNCTION, METHOD }
|
||||||
|
@ -55,7 +55,7 @@ public class MethodContext {
|
||||||
public IASTName getMethodDeclarationName() {
|
public IASTName getMethodDeclarationName() {
|
||||||
return declarationName;
|
return declarationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTDeclaration getMethodDeclaration() {
|
public IASTDeclaration getMethodDeclaration() {
|
||||||
IASTNode parent = declarationName.getParent().getParent();
|
IASTNode parent = declarationName.getParent().getParent();
|
||||||
if (parent instanceof IASTDeclaration) {
|
if (parent instanceof IASTDeclaration) {
|
||||||
|
@ -63,7 +63,7 @@ public class MethodContext {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Visibility getMethodDeclarationVisibility() {
|
public Visibility getMethodDeclarationVisibility() {
|
||||||
return Visibility.getVisibility(declarationName);
|
return Visibility.getVisibility(declarationName);
|
||||||
}
|
}
|
||||||
|
@ -71,17 +71,17 @@ public class MethodContext {
|
||||||
public void setMethodQName(ICPPASTQualifiedName qname) {
|
public void setMethodQName(ICPPASTQualifiedName qname) {
|
||||||
this.qname = qname;
|
this.qname = qname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPASTQualifiedName getMethodQName() {
|
public ICPPASTQualifiedName getMethodQName() {
|
||||||
return qname;
|
return qname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSameClass(ICPPASTQualifiedName qname1, ICPPASTQualifiedName qname2) {
|
public static boolean isSameClass(ICPPASTQualifiedName qname1, ICPPASTQualifiedName qname2) {
|
||||||
ICPPClassType bind1 = getClassBinding(qname1);
|
ICPPClassType bind1 = getClassBinding(qname1);
|
||||||
ICPPClassType bind2 = getClassBinding(qname2);
|
ICPPClassType bind2 = getClassBinding(qname2);
|
||||||
return bind1.equals(bind2);
|
return bind1.equals(bind2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSameOrSubClass(MethodContext context1, MethodContext contextOfSameOrSubclass) {
|
public static boolean isSameOrSubClass(MethodContext context1, MethodContext contextOfSameOrSubclass) {
|
||||||
ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
|
ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
|
||||||
ICPPInternalBinding subclassBind = getICPPInternalBinding(contextOfSameOrSubclass);
|
ICPPInternalBinding subclassBind = getICPPInternalBinding(contextOfSameOrSubclass);
|
||||||
|
@ -90,7 +90,7 @@ public class MethodContext {
|
||||||
}
|
}
|
||||||
return isSubclass(bind1,subclassBind);
|
return isSubclass(bind1,subclassBind);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSubclass(ICPPInternalBinding bind1, ICPPInternalBinding subclassBind) {
|
private static boolean isSubclass(ICPPInternalBinding bind1, ICPPInternalBinding subclassBind) {
|
||||||
if (subclassBind instanceof ICPPClassType) {
|
if (subclassBind instanceof ICPPClassType) {
|
||||||
ICPPClassType classType = (ICPPClassType) subclassBind;
|
ICPPClassType classType = (ICPPClassType) subclassBind;
|
||||||
|
@ -110,7 +110,7 @@ public class MethodContext {
|
||||||
ICPPInternalBinding bind2 = getICPPInternalBinding(context2);
|
ICPPInternalBinding bind2 = getICPPInternalBinding(context2);
|
||||||
return isSameClass(bind1,bind2);
|
return isSameClass(bind1,bind2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSameClass(ICPPBase base, ICPPInternalBinding bind2) {
|
private static boolean isSameClass(ICPPBase base, ICPPInternalBinding bind2) {
|
||||||
try {
|
try {
|
||||||
IBinding bind1 = base.getBaseClass();
|
IBinding bind1 = base.getBaseClass();
|
||||||
|
@ -118,12 +118,12 @@ public class MethodContext {
|
||||||
if (scope1 == null)
|
if (scope1 == null)
|
||||||
return false;
|
return false;
|
||||||
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
||||||
|
|
||||||
IScope scope2 = bind2.getScope();
|
IScope scope2 = bind2.getScope();
|
||||||
if (scope2 == null)
|
if (scope2 == null)
|
||||||
return false;
|
return false;
|
||||||
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
||||||
|
|
||||||
if (node1.equals(node2)) {
|
if (node1.equals(node2)) {
|
||||||
if (bind1 instanceof ICPPInternalBinding) {
|
if (bind1 instanceof ICPPInternalBinding) {
|
||||||
ICPPInternalBinding bind1int = (ICPPInternalBinding) bind1;
|
ICPPInternalBinding bind1int = (ICPPInternalBinding) bind1;
|
||||||
|
@ -134,30 +134,30 @@ public class MethodContext {
|
||||||
return false;
|
return false;
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSameClass(ICPPInternalBinding bind1, ICPPInternalBinding bind2) {
|
private static boolean isSameClass(ICPPInternalBinding bind1, ICPPInternalBinding bind2) {
|
||||||
try {
|
try {
|
||||||
IScope scope1 = bind1.getScope();
|
IScope scope1 = bind1.getScope();
|
||||||
if (scope1 == null)
|
if (scope1 == null)
|
||||||
return false;
|
return false;
|
||||||
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
|
||||||
|
|
||||||
IScope scope2 = bind2.getScope();
|
IScope scope2 = bind2.getScope();
|
||||||
if (scope2 == null)
|
if (scope2 == null)
|
||||||
return false;
|
return false;
|
||||||
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
|
||||||
|
|
||||||
if (node1.equals(node2)) {
|
if (node1.equals(node2)) {
|
||||||
return bind1.getDefinition().equals(bind2.getDefinition());
|
return bind1.getDefinition().equals(bind2.getDefinition());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICPPInternalBinding getICPPInternalBinding(MethodContext context) {
|
public static ICPPInternalBinding getICPPInternalBinding(MethodContext context) {
|
||||||
IASTName decl = context.getMethodDeclarationName();
|
IASTName decl = context.getMethodDeclarationName();
|
||||||
IASTNode node = decl;
|
IASTNode node = decl;
|
||||||
|
@ -169,17 +169,17 @@ public class MethodContext {
|
||||||
}
|
}
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInline() {
|
public boolean isInline() {
|
||||||
return qname == null;
|
return qname == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ICPPClassType getClassBinding(ICPPASTQualifiedName qname) {
|
private static ICPPClassType getClassBinding(ICPPASTQualifiedName qname) {
|
||||||
IASTName classname = qname.getNames()[qname.getNames().length - 2];
|
IASTName classname = qname.getNames()[qname.getNames().length - 2];
|
||||||
ICPPClassType bind = (ICPPClassType)classname.resolveBinding();
|
ICPPClassType bind = (ICPPClassType)classname.resolveBinding();
|
||||||
return bind;
|
return bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -31,15 +31,15 @@ public class ExtractFunctionInformation {
|
||||||
private String methodName;
|
private String methodName;
|
||||||
private boolean replaceDuplicates;
|
private boolean replaceDuplicates;
|
||||||
private List<NameInformation> parameters;
|
private List<NameInformation> parameters;
|
||||||
private NameInformation mandatoryReturnVariable;
|
private NameInformation mandatoryReturnVariable;
|
||||||
private ICPPASTFunctionDeclarator declarator;
|
private ICPPASTFunctionDeclarator declarator;
|
||||||
private MethodContext context;
|
private MethodContext context;
|
||||||
private boolean isExtractExpression;
|
private boolean isExtractExpression;
|
||||||
private boolean virtual;
|
private boolean virtual;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the function declarator of the method / function from were the statements
|
* Returns the function declarator of the method or function from were the statements
|
||||||
* are extacted from.
|
* are extracted from.
|
||||||
* @return the function declarator or null
|
* @return the function declarator or null
|
||||||
*/
|
*/
|
||||||
public ICPPASTFunctionDeclarator getDeclarator() {
|
public ICPPASTFunctionDeclarator getDeclarator() {
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ExtractFunctionInputPage extends UserInputWizardPage {
|
||||||
private Text textField;
|
private Text textField;
|
||||||
private boolean firstTime;
|
private boolean firstTime;
|
||||||
private CSourceViewer signaturePreview;
|
private CSourceViewer signaturePreview;
|
||||||
private Document signaturePreviewDocument;
|
private final Document signaturePreviewDocument;
|
||||||
private IDialogSettings settings;
|
private IDialogSettings settings;
|
||||||
|
|
||||||
private static final String DESCRIPTION = Messages.ExtractFunctionInputPage_description;
|
private static final String DESCRIPTION = Messages.ExtractFunctionInputPage_description;
|
||||||
|
@ -252,7 +252,7 @@ public class ExtractFunctionInputPage extends UserInputWizardPage {
|
||||||
|
|
||||||
if (methodName.isEmpty()) {
|
if (methodName.isEmpty()) {
|
||||||
methodName = StubUtility.suggestMethodName("someMethodName", null, //$NON-NLS-1$
|
methodName = StubUtility.suggestMethodName("someMethodName", null, //$NON-NLS-1$
|
||||||
refactoring.getTranslationUnit());
|
refactoring.getTranslationUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
int top = signaturePreview.getTextWidget().getTopPixel();
|
int top = signaturePreview.getTextWidget().getTopPixel();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -108,6 +108,7 @@ import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
|
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescriptor;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter;
|
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter;
|
||||||
|
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter.InsertionInfo;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext.ContextType;
|
import org.eclipse.cdt.internal.ui.refactoring.MethodContext.ContextType;
|
||||||
|
@ -172,17 +173,17 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
ast = getAST(tu, sm.newChild(1));
|
ast = getAST(tu, sm.newChild(1));
|
||||||
nodeFactory = ast.getASTNodeFactory();
|
nodeFactory = ast.getASTNodeFactory();
|
||||||
container = findExtractableNodes();
|
container = findExtractableNodes();
|
||||||
|
|
||||||
if (isProgressMonitorCanceled(sm, initStatus))
|
if (isProgressMonitorCanceled(sm, initStatus))
|
||||||
return initStatus;
|
return initStatus;
|
||||||
|
|
||||||
if (container.isEmpty()) {
|
if (container.isEmpty()) {
|
||||||
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
|
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_NoStmtSelected);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForNonExtractableStatements(container, initStatus);
|
checkForNonExtractableStatements(container, initStatus);
|
||||||
|
|
||||||
List<NameInformation> returnValueCandidates = container.getReturnValueCandidates();
|
List<NameInformation> returnValueCandidates = container.getReturnValueCandidates();
|
||||||
if (returnValueCandidates.size() > 1) {
|
if (returnValueCandidates.size() > 1) {
|
||||||
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
|
initStatus.addFatalError(Messages.ExtractFunctionRefactoring_TooManySelected);
|
||||||
|
@ -190,27 +191,27 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
} else if (returnValueCandidates.size() == 1) {
|
} else if (returnValueCandidates.size() == 1) {
|
||||||
info.setMandatoryReturnVariable(returnValueCandidates.get(0));
|
info.setMandatoryReturnVariable(returnValueCandidates.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
info.setParameters(container.getParameterCandidates());
|
info.setParameters(container.getParameterCandidates());
|
||||||
initStatus.merge(checkParameterAndReturnTypes());
|
initStatus.merge(checkParameterAndReturnTypes());
|
||||||
if (initStatus.hasFatalError())
|
if (initStatus.hasFatalError())
|
||||||
return initStatus;
|
return initStatus;
|
||||||
|
|
||||||
extractor = FunctionExtractor.createFor(container.getNodesToWrite());
|
extractor = FunctionExtractor.createFor(container.getNodesToWrite());
|
||||||
|
|
||||||
if (extractor.canChooseReturnValue() && info.getMandatoryReturnVariable() == null) {
|
if (extractor.canChooseReturnValue() && info.getMandatoryReturnVariable() == null) {
|
||||||
chooseReturnVariable();
|
chooseReturnVariable();
|
||||||
}
|
}
|
||||||
|
|
||||||
IPreferencesService preferences = Platform.getPreferencesService();
|
IPreferencesService preferences = Platform.getPreferencesService();
|
||||||
final boolean outFirst = preferences.getBoolean(CUIPlugin.PLUGIN_ID,
|
final boolean outFirst = preferences.getBoolean(CUIPlugin.PLUGIN_ID,
|
||||||
PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT, false,
|
PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT, false,
|
||||||
PreferenceConstants.getPreferenceScopes(project.getProject()));
|
PreferenceConstants.getPreferenceScopes(project.getProject()));
|
||||||
info.sortParameters(outFirst);
|
info.sortParameters(outFirst);
|
||||||
|
|
||||||
boolean isExtractExpression = container.getNodesToWrite().get(0) instanceof IASTExpression;
|
boolean isExtractExpression = container.getNodesToWrite().get(0) instanceof IASTExpression;
|
||||||
info.setExtractExpression(isExtractExpression);
|
info.setExtractExpression(isExtractExpression);
|
||||||
|
|
||||||
info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0)));
|
info.setDeclarator(getDeclaration(container.getNodesToWrite().get(0)));
|
||||||
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0),
|
MethodContext context = NodeHelper.findMethodContext(container.getNodesToWrite().get(0),
|
||||||
refactoringContext, sm.newChild(1));
|
refactoringContext, sm.newChild(1));
|
||||||
|
@ -347,7 +348,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
if (node != firstNodeToWrite) {
|
if (node != firstNodeToWrite) {
|
||||||
rewriter.remove(node, editGroup);
|
rewriter.remove(node, editGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertCallIntoTree(IASTNode methodCall, List<IASTNode> list, ASTRewrite rewriter,
|
private void insertCallIntoTree(IASTNode methodCall, List<IASTNode> list, ASTRewrite rewriter,
|
||||||
|
@ -379,9 +380,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMethodDefinition(final IASTName methodName, MethodContext context,
|
private void createMethodDefinition(final IASTName methodName, MethodContext context,
|
||||||
IASTNode firstNode, ModificationCollector collector) {
|
IASTNode firstExtractedNode, ModificationCollector collector) {
|
||||||
IASTFunctionDefinition node = CPPVisitor.findAncestorWithType(firstNode, IASTFunctionDefinition.class);
|
IASTFunctionDefinition functionToExtractFrom =
|
||||||
if (node != null) {
|
CPPVisitor.findAncestorWithType(firstExtractedNode, IASTFunctionDefinition.class);
|
||||||
|
if (functionToExtractFrom != 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;
|
||||||
|
@ -389,8 +391,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
title = Messages.ExtractFunctionRefactoring_CreateFunctionDef;
|
title = Messages.ExtractFunctionRefactoring_CreateFunctionDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTRewrite rewriter = collector.rewriterForTranslationUnit(node.getTranslationUnit());
|
ASTRewrite rewriter = collector.rewriterForTranslationUnit(functionToExtractFrom.getTranslationUnit());
|
||||||
addMethod(methodName, context, rewriter, node, new TextEditGroup(title));
|
addMethod(methodName, context, rewriter, functionToExtractFrom, new TextEditGroup(title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,7 +520,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
IASTNode trailNode = trail.get(pos);
|
IASTNode trailNode = trail.get(pos);
|
||||||
trailPos.setObject(Integer.valueOf(pos + 1));
|
trailPos.setObject(Integer.valueOf(pos + 1));
|
||||||
|
|
||||||
if (equalityChecker.isEquals(trailNode, node)) {
|
if (equalityChecker.isEqual(trailNode, node)) {
|
||||||
if (node instanceof ICPPASTQualifiedName || node instanceof IASTNamedTypeSpecifier) {
|
if (node instanceof ICPPASTQualifiedName || node instanceof IASTNamedTypeSpecifier) {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
} else {
|
} else {
|
||||||
|
@ -563,7 +565,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
IASTParameterDeclaration newParameter = declarator.getParameters()[i];
|
IASTParameterDeclaration newParameter = declarator.getParameters()[i];
|
||||||
|
|
||||||
// If not the same break;
|
// If not the same break;
|
||||||
if (!(equalityChecker.isEquals(origParameter.getDeclSpecifier(),
|
if (!(equalityChecker.isEqual(origParameter.getDeclSpecifier(),
|
||||||
newParameter.getDeclSpecifier()) &&
|
newParameter.getDeclSpecifier()) &&
|
||||||
ASTHelper.samePointers(origParameter.getDeclarator().getPointerOperators(),
|
ASTHelper.samePointers(origParameter.getDeclarator().getPointerOperators(),
|
||||||
newParameter.getDeclarator().getPointerOperators(),
|
newParameter.getDeclarator().getPointerOperators(),
|
||||||
|
@ -584,7 +586,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMethod(IASTName methodName, MethodContext context, ASTRewrite rewrite,
|
private void addMethod(IASTName methodName, MethodContext context, ASTRewrite rewrite,
|
||||||
IASTNode insertPoint, TextEditGroup group) {
|
IASTNode functionToExtractFrom, TextEditGroup group) {
|
||||||
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
|
ICPPASTQualifiedName qname = new CPPASTQualifiedName();
|
||||||
if (context.getType() == ContextType.METHOD) {
|
if (context.getType() == ContextType.METHOD) {
|
||||||
if (context.getMethodQName() != null) {
|
if (context.getMethodQName() != null) {
|
||||||
|
@ -600,7 +602,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
|
|
||||||
IASTDeclSpecifier returnType = getReturnType();
|
IASTDeclSpecifier returnType = getReturnType();
|
||||||
func.setDeclSpecifier(returnType);
|
func.setDeclSpecifier(returnType);
|
||||||
|
|
||||||
IASTStandardFunctionDeclarator createdFunctionDeclarator =
|
IASTStandardFunctionDeclarator createdFunctionDeclarator =
|
||||||
extractor.createFunctionDeclarator(qname,
|
extractor.createFunctionDeclarator(qname,
|
||||||
info.getDeclarator(), info.getReturnVariable(), container.getNodesToWrite(),
|
info.getDeclarator(), info.getReturnVariable(), container.getNodesToWrite(),
|
||||||
|
@ -609,22 +611,46 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
|
|
||||||
IASTCompoundStatement compound = new CPPASTCompoundStatement();
|
IASTCompoundStatement compound = new CPPASTCompoundStatement();
|
||||||
func.setBody(compound);
|
func.setBody(compound);
|
||||||
|
|
||||||
ASTRewrite subRewrite;
|
ASTRewrite subRewrite;
|
||||||
IASTNode parent = insertPoint.getParent();
|
IASTNode parent = functionToExtractFrom.getParent();
|
||||||
|
IASTNode nodeToInsert = func;
|
||||||
if (parent instanceof ICPPASTTemplateDeclaration) {
|
if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||||
ICPPASTTemplateDeclaration parentTemplate = (ICPPASTTemplateDeclaration) parent;
|
ICPPASTTemplateDeclaration parentTemplate = (ICPPASTTemplateDeclaration) parent;
|
||||||
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
|
CPPASTTemplateDeclaration templateDeclaration = new CPPASTTemplateDeclaration();
|
||||||
templateDeclaration.setParent(ast);
|
templateDeclaration.setParent(ast);
|
||||||
|
|
||||||
for (ICPPASTTemplateParameter param : parentTemplate.getTemplateParameters()) {
|
for (ICPPASTTemplateParameter param : parentTemplate.getTemplateParameters()) {
|
||||||
templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations));
|
templateDeclaration.addTemplateParameter(param.copy(CopyStyle.withLocations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
functionToExtractFrom = parentTemplate;
|
||||||
templateDeclaration.setDeclaration(func);
|
templateDeclaration.setDeclaration(func);
|
||||||
subRewrite = rewrite.insertBefore(parent.getParent(), parent, templateDeclaration, group);
|
nodeToInsert = templateDeclaration;
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
InsertionInfo insertion;
|
||||||
|
if (parent instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
|
// Inserting into a class declaration
|
||||||
|
insertion = ClassMemberInserter.findInsertionPoint((ICPPASTCompositeTypeSpecifier) parent,
|
||||||
|
info.getVisibility(), false);
|
||||||
} else {
|
} else {
|
||||||
subRewrite = rewrite.insertBefore(parent, insertPoint, func, group);
|
// Inserting into a translation unit or a namespace.
|
||||||
|
// TODO(sprigogin): Use insertBeforeNode instead of functionToExtractFrom when creating InsertionInfo
|
||||||
|
// IASTNode insertBeforeNode = info.getMethodContext().getType() == ContextType.METHOD ?
|
||||||
|
// null : functionToExtractFrom;
|
||||||
|
insertion = new InsertionInfo(parent, functionToExtractFrom);
|
||||||
|
}
|
||||||
|
if (insertion.getPrologue() != null) {
|
||||||
|
rewrite.insertBefore(insertion.getParentNode(),
|
||||||
|
insertion.getInsertBeforeNode(), insertion.getPrologue(), group);
|
||||||
|
}
|
||||||
|
subRewrite = rewrite.insertBefore(insertion.getParentNode(),
|
||||||
|
insertion.getInsertBeforeNode(), nodeToInsert, group);
|
||||||
|
if (insertion.getEpilogue() != null) {
|
||||||
|
rewrite.insertBefore(insertion.getParentNode(),
|
||||||
|
insertion.getInsertBeforeNode(), insertion.getEpilogue(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
extractor.constructMethodBody(compound, container.getNodesToWrite(),
|
extractor.constructMethodBody(compound, container.getNodesToWrite(),
|
||||||
|
@ -777,7 +803,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
||||||
IASTNode node = container.getNodesToWrite().get(0);
|
IASTNode node = container.getNodesToWrite().get(0);
|
||||||
return extractor.createReturnAssignment(node, stmt, callExpression);
|
return extractor.createReturnAssignment(node, stmt, callExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTSimpleDeclaration getDeclaration(IASTName name) {
|
private IASTSimpleDeclaration getDeclaration(IASTName name) {
|
||||||
IASTSimpleDeclaration simpleDecl = new CPPASTSimpleDeclaration();
|
IASTSimpleDeclaration simpleDecl = new CPPASTSimpleDeclaration();
|
||||||
IASTStandardFunctionDeclarator declarator =
|
IASTStandardFunctionDeclarator declarator =
|
||||||
|
|
|
@ -22,7 +22,7 @@ ExtractFunctionRefactoring_CreateFunctionDef=Create Function Definition
|
||||||
ExtractFunctionRefactoring_CreateMethodCall=Create Method Call
|
ExtractFunctionRefactoring_CreateMethodCall=Create Method Call
|
||||||
ExtractFunctionRefactoring_CreateFunctionCall=Create Function Call
|
ExtractFunctionRefactoring_CreateFunctionCall=Create Function Call
|
||||||
ExtractFunctionRefactoring_Error_Return=Extracting return statements is not supported
|
ExtractFunctionRefactoring_Error_Return=Extracting return statements is not supported
|
||||||
ExtractFunctionRefactoring_Error_Continue=Extracting cotinue statements without the surrounding loop is not possible. Please adjust your selection.
|
ExtractFunctionRefactoring_Error_Continue=Extracting continue statements without the surrounding loop is not possible. Please adjust your selection.
|
||||||
ExtractFunctionRefactoring_Error_Break=Extracting break statements without the surrounding loop is not possible. Please adjust your selection.
|
ExtractFunctionRefactoring_Error_Break=Extracting break statements without the surrounding loop is not possible. Please adjust your selection.
|
||||||
ExtractFunctionInputPage_description=Enter new method name and specify the method's visibility
|
ExtractFunctionInputPage_description=Enter new method name and specify the method's visibility
|
||||||
ExtractFunctionInputPage_access_modifier=&Access modifier:
|
ExtractFunctionInputPage_access_modifier=&Access modifier:
|
||||||
|
@ -34,7 +34,7 @@ ExtractFunctionInputPage_label_text=Function &name:
|
||||||
ExtractFunctionInputPage_parameters=&Parameters:
|
ExtractFunctionInputPage_parameters=&Parameters:
|
||||||
ExtractFunctionInputPage_validation_empty_function_name=Provide a method name
|
ExtractFunctionInputPage_validation_empty_function_name=Provide a method name
|
||||||
ExtractFunctionInputPage_validation_empty_parameter_name=Parameter names cannot be empty
|
ExtractFunctionInputPage_validation_empty_parameter_name=Parameter names cannot be empty
|
||||||
ExtractFunctionInputPage_duplicates_none=&Replace additional occurrences of statements with method
|
ExtractFunctionInputPage_duplicates_none=&Replace additional occurrences of statements with a function call
|
||||||
ExtractFunctionInputPage_duplicates_single=&Replace 1 additional occurrence of statements with method
|
ExtractFunctionInputPage_duplicates_single=&Replace 1 additional occurrence of statements with a function call
|
||||||
ExtractFunctionInputPage_duplicates_multi=&Replace {0} additional occurrences of statements with method
|
ExtractFunctionInputPage_duplicates_multi=&Replace {0} additional occurrences of statements with a function call
|
||||||
SimilarFinderVisitor_replaceDuplicateCode=Replace Duplicated Code
|
SimilarFinderVisitor_replaceDuplicateCode=Replace Duplicated Code
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2010 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
|
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||||
|
@ -70,7 +72,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
private final Map<String, Integer> names;
|
private final Map<String, Integer> names;
|
||||||
private final Container<Integer> namesCounter;
|
private final Container<Integer> namesCounter;
|
||||||
private final IIndex index;
|
private final IIndex index;
|
||||||
|
|
||||||
public TrailNodeEqualityChecker(Map<String, Integer> names, Container<Integer> namesCounter,
|
public TrailNodeEqualityChecker(Map<String, Integer> names, Container<Integer> namesCounter,
|
||||||
IIndex index) {
|
IIndex index) {
|
||||||
super();
|
super();
|
||||||
|
@ -78,38 +80,41 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
this.namesCounter = namesCounter;
|
this.namesCounter = namesCounter;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEquals(IASTNode trailNode, IASTNode node) {
|
public boolean isEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if ((trailNode instanceof TrailName && node instanceof IASTName)
|
if ((trailNode instanceof TrailName && node instanceof IASTName)
|
||||||
|| Arrays.equals(getInterfaces(node), getInterfaces(trailNode))) {
|
|| Arrays.equals(getInterfaces(node), getInterfaces(trailNode))) {
|
||||||
// Is same type
|
// Is same type
|
||||||
if (node instanceof IASTExpression) {
|
if (node instanceof IASTExpression) {
|
||||||
return isExpressionEquals(trailNode, node);
|
return isExpressionEqual(trailNode, node);
|
||||||
} else if (node instanceof IASTStatement) {
|
} else if (node instanceof IASTStatement) {
|
||||||
return isStatementEquals(trailNode, node);
|
return isStatementEqual(trailNode, node);
|
||||||
} else if (node instanceof IASTPointerOperator) {
|
} else if (node instanceof IASTPointerOperator) {
|
||||||
return isPointerOperatorEquals(trailNode, node);
|
return isPointerOperatorEqual(trailNode, node);
|
||||||
} else if (node instanceof IASTDeclaration) {
|
} else if (node instanceof IASTDeclaration) {
|
||||||
return isDeclarationEquals(trailNode, node);
|
return isDeclarationEqual(trailNode, node);
|
||||||
} else if (node instanceof IASTDeclarator) {
|
} else if (node instanceof IASTDeclarator) {
|
||||||
return isDeclaratorEquals(trailNode, node);
|
return isDeclaratorEqual(trailNode, node);
|
||||||
} else if (node instanceof IASTInitializer) {
|
} else if (node instanceof IASTInitializer) {
|
||||||
// No speciality, is the same type return true
|
// No special case, the same type means equality
|
||||||
return true;
|
return true;
|
||||||
} else if (node instanceof IASTDeclSpecifier) {
|
} else if (node instanceof IASTDeclSpecifier) {
|
||||||
return isDeclSpecifierEquals(trailNode, node);
|
return isDeclSpecifierEqual(trailNode, node);
|
||||||
|
} else if (node instanceof ICPPASTTypeId) {
|
||||||
|
return idTypeIdEqual((ICPPASTTypeId) trailNode, (ICPPASTTypeId) node);
|
||||||
} else if (node instanceof IASTName) {
|
} else if (node instanceof IASTName) {
|
||||||
return isNameEquals(trailNode, node);
|
return isNameEqual(trailNode, node);
|
||||||
} else {
|
} else {
|
||||||
Assert.isLegal(false, "Unexpected Node, this code shoud nod reached"); //$NON-NLS-1$
|
Assert.isLegal(false, "Unexpected node type " + node.getClass().getSimpleName() + //$NON-NLS-1$
|
||||||
|
", this code shoud not be reached"); //$NON-NLS-1$
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNameEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isNameEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof ICPPASTConversionName) {
|
if (trailNode instanceof ICPPASTConversionName) {
|
||||||
return true;
|
return true;
|
||||||
} else if (trailNode instanceof ICPPASTOperatorName) {
|
} else if (trailNode instanceof ICPPASTOperatorName) {
|
||||||
|
@ -119,21 +124,21 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
} else if (trailNode instanceof TrailName && node instanceof IASTName) {
|
} else if (trailNode instanceof TrailName && node instanceof IASTName) {
|
||||||
TrailName trailName = (TrailName) trailNode;
|
TrailName trailName = (TrailName) trailNode;
|
||||||
IASTName name = (IASTName)node;
|
IASTName name = (IASTName)node;
|
||||||
return isNameEquals(trailName, name);
|
return isNameEqual(trailName, name);
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclSpecifierEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isDeclSpecifierEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof IASTSimpleDeclSpecifier) {
|
if (trailNode instanceof IASTSimpleDeclSpecifier) {
|
||||||
IASTSimpleDeclSpecifier trailDecl = (IASTSimpleDeclSpecifier) trailNode;
|
IASTSimpleDeclSpecifier trailDecl = (IASTSimpleDeclSpecifier) trailNode;
|
||||||
IASTSimpleDeclSpecifier decl = (IASTSimpleDeclSpecifier) node;
|
IASTSimpleDeclSpecifier decl = (IASTSimpleDeclSpecifier) node;
|
||||||
return isSimpleDeclSpecifierEquals(trailDecl, decl);
|
return isSimpleDeclSpecifierEqual(trailDecl, decl);
|
||||||
} else if (trailNode instanceof ICPPASTNamedTypeSpecifier) {
|
} else if (trailNode instanceof ICPPASTNamedTypeSpecifier) {
|
||||||
ICPPASTNamedTypeSpecifier trailDecl = (ICPPASTNamedTypeSpecifier) trailNode;
|
ICPPASTNamedTypeSpecifier trailDecl = (ICPPASTNamedTypeSpecifier) trailNode;
|
||||||
ICPPASTNamedTypeSpecifier decl = (ICPPASTNamedTypeSpecifier) node;
|
ICPPASTNamedTypeSpecifier decl = (ICPPASTNamedTypeSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& isSameNamedTypeSpecifierName(trailDecl, decl)
|
&& isSameNamedTypeSpecifierName(trailDecl, decl)
|
||||||
&& trailDecl.isTypename() == decl.isTypename()
|
&& trailDecl.isTypename() == decl.isTypename()
|
||||||
&& trailDecl.isExplicit() == decl.isExplicit()
|
&& trailDecl.isExplicit() == decl.isExplicit()
|
||||||
|
@ -142,41 +147,41 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
} else if (trailNode instanceof IASTNamedTypeSpecifier) {
|
} else if (trailNode instanceof IASTNamedTypeSpecifier) {
|
||||||
IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode;
|
IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode;
|
||||||
IASTNamedTypeSpecifier decl = (IASTNamedTypeSpecifier) node;
|
IASTNamedTypeSpecifier decl = (IASTNamedTypeSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& isSameNamedTypeSpecifierName(trailDecl, decl);
|
&& isSameNamedTypeSpecifierName(trailDecl, decl);
|
||||||
} else if (trailNode instanceof IASTElaboratedTypeSpecifier) {
|
} else if (trailNode instanceof IASTElaboratedTypeSpecifier) {
|
||||||
IASTElaboratedTypeSpecifier trailDecl = (IASTElaboratedTypeSpecifier) trailNode;
|
IASTElaboratedTypeSpecifier trailDecl = (IASTElaboratedTypeSpecifier) trailNode;
|
||||||
IASTElaboratedTypeSpecifier decl = (IASTElaboratedTypeSpecifier) node;
|
IASTElaboratedTypeSpecifier decl = (IASTElaboratedTypeSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& trailDecl.getKind() == decl.getKind();
|
&& trailDecl.getKind() == decl.getKind();
|
||||||
} else if (trailNode instanceof IASTCompositeTypeSpecifier) {
|
} else if (trailNode instanceof IASTCompositeTypeSpecifier) {
|
||||||
IASTCompositeTypeSpecifier trailDecl = (IASTCompositeTypeSpecifier) trailNode;
|
IASTCompositeTypeSpecifier trailDecl = (IASTCompositeTypeSpecifier) trailNode;
|
||||||
IASTCompositeTypeSpecifier decl = (IASTCompositeTypeSpecifier) node;
|
IASTCompositeTypeSpecifier decl = (IASTCompositeTypeSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& trailDecl.getKey() == decl.getKey();
|
&& trailDecl.getKey() == decl.getKey();
|
||||||
} else if (trailNode instanceof ICPPASTDeclSpecifier) {
|
} else if (trailNode instanceof ICPPASTDeclSpecifier) {
|
||||||
ICPPASTDeclSpecifier trailDecl = (ICPPASTDeclSpecifier) trailNode;
|
ICPPASTDeclSpecifier trailDecl = (ICPPASTDeclSpecifier) trailNode;
|
||||||
ICPPASTDeclSpecifier decl = (ICPPASTDeclSpecifier) node;
|
ICPPASTDeclSpecifier decl = (ICPPASTDeclSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& trailDecl.isExplicit() == decl.isExplicit()
|
&& trailDecl.isExplicit() == decl.isExplicit()
|
||||||
&& trailDecl.isFriend() == decl.isFriend()
|
&& trailDecl.isFriend() == decl.isFriend()
|
||||||
&& trailDecl.isVirtual() == decl.isVirtual();
|
&& trailDecl.isVirtual() == decl.isVirtual();
|
||||||
} else if (trailNode instanceof ICASTDeclSpecifier) {
|
} else if (trailNode instanceof ICASTDeclSpecifier) {
|
||||||
ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode;
|
ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode;
|
||||||
ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node;
|
ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl)
|
return isDeclSpecifierEqual(trailDecl, decl)
|
||||||
&& trailDecl.isRestrict() == decl.isRestrict();
|
&& trailDecl.isRestrict() == decl.isRestrict();
|
||||||
} else if (trailNode instanceof IASTDeclSpecifier) {
|
} else if (trailNode instanceof IASTDeclSpecifier) {
|
||||||
IASTDeclSpecifier trailDecl = (IASTDeclSpecifier) trailNode;
|
IASTDeclSpecifier trailDecl = (IASTDeclSpecifier) trailNode;
|
||||||
IASTDeclSpecifier decl = (IASTDeclSpecifier) node;
|
IASTDeclSpecifier decl = (IASTDeclSpecifier) node;
|
||||||
return isDeclSpecifierEquals(trailDecl, decl);
|
return isDeclSpecifierEqual(trailDecl, decl);
|
||||||
} else {
|
} else {
|
||||||
//is same
|
//is same
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclaratorEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isDeclaratorEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof IASTStandardFunctionDeclarator) {
|
if (trailNode instanceof IASTStandardFunctionDeclarator) {
|
||||||
IASTStandardFunctionDeclarator trailFunc = (IASTStandardFunctionDeclarator) trailNode;
|
IASTStandardFunctionDeclarator trailFunc = (IASTStandardFunctionDeclarator) trailNode;
|
||||||
IASTStandardFunctionDeclarator func = (IASTStandardFunctionDeclarator) node;
|
IASTStandardFunctionDeclarator func = (IASTStandardFunctionDeclarator) node;
|
||||||
|
@ -193,7 +198,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclarationEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isDeclarationEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof IASTASMDeclaration) {
|
if (trailNode instanceof IASTASMDeclaration) {
|
||||||
IASTASMDeclaration trailASMDecl = (IASTASMDeclaration) trailNode;
|
IASTASMDeclaration trailASMDecl = (IASTASMDeclaration) trailNode;
|
||||||
IASTASMDeclaration asmDecl = (IASTASMDeclaration) node;
|
IASTASMDeclaration asmDecl = (IASTASMDeclaration) node;
|
||||||
|
@ -224,7 +229,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPointerOperatorEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isPointerOperatorEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof IASTPointer) {
|
if (trailNode instanceof IASTPointer) {
|
||||||
IASTPointer trailGPointer = (IASTPointer) trailNode;
|
IASTPointer trailGPointer = (IASTPointer) trailNode;
|
||||||
IASTPointer gPointer = (IASTPointer) node;
|
IASTPointer gPointer = (IASTPointer) node;
|
||||||
|
@ -237,7 +242,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isStatementEquals(IASTNode trailNode, IASTNode node) {
|
private boolean isStatementEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof ICPPASTCatchHandler) {
|
if (trailNode instanceof ICPPASTCatchHandler) {
|
||||||
ICPPASTCatchHandler trailCatch = (ICPPASTCatchHandler) trailNode;
|
ICPPASTCatchHandler trailCatch = (ICPPASTCatchHandler) trailNode;
|
||||||
ICPPASTCatchHandler nodeCatch = (ICPPASTCatchHandler) node;
|
ICPPASTCatchHandler nodeCatch = (ICPPASTCatchHandler) node;
|
||||||
|
@ -247,7 +252,11 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExpressionEquals(IASTNode trailNode, IASTNode node) {
|
private boolean idTypeIdEqual(ICPPASTTypeId trailNode, ICPPASTTypeId node) {
|
||||||
|
return trailNode.isPackExpansion() == node.isPackExpansion();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isExpressionEqual(IASTNode trailNode, IASTNode node) {
|
||||||
if (trailNode instanceof IASTBinaryExpression) {
|
if (trailNode instanceof IASTBinaryExpression) {
|
||||||
IASTBinaryExpression trailExpr = (IASTBinaryExpression) trailNode;
|
IASTBinaryExpression trailExpr = (IASTBinaryExpression) trailNode;
|
||||||
IASTBinaryExpression expr = (IASTBinaryExpression) node;
|
IASTBinaryExpression expr = (IASTBinaryExpression) node;
|
||||||
|
@ -284,7 +293,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
} else if (trailNode instanceof ICPPASTSimpleTypeConstructorExpression) {
|
} else if (trailNode instanceof ICPPASTSimpleTypeConstructorExpression) {
|
||||||
ICPPASTSimpleTypeConstructorExpression trailConsExpr = (ICPPASTSimpleTypeConstructorExpression) trailNode;
|
ICPPASTSimpleTypeConstructorExpression trailConsExpr = (ICPPASTSimpleTypeConstructorExpression) trailNode;
|
||||||
ICPPASTSimpleTypeConstructorExpression consExpr = (ICPPASTSimpleTypeConstructorExpression) node;
|
ICPPASTSimpleTypeConstructorExpression consExpr = (ICPPASTSimpleTypeConstructorExpression) node;
|
||||||
return isDeclSpecifierEquals(trailConsExpr.getDeclSpecifier(), consExpr.getDeclSpecifier());
|
return isDeclSpecifierEqual(trailConsExpr.getDeclSpecifier(), consExpr.getDeclSpecifier());
|
||||||
} else {
|
} else {
|
||||||
// same type
|
// same type
|
||||||
return true;
|
return true;
|
||||||
|
@ -302,7 +311,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
return interfaceList.toArray(returnArray);
|
return interfaceList.toArray(returnArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeclSpecifierEquals(IASTDeclSpecifier trailDeclSpeci, IASTDeclSpecifier declSpeci) {
|
private boolean isDeclSpecifierEqual(IASTDeclSpecifier trailDeclSpeci, IASTDeclSpecifier declSpeci) {
|
||||||
if (trailDeclSpeci instanceof ICPPASTDeclSpecifier) {
|
if (trailDeclSpeci instanceof ICPPASTDeclSpecifier) {
|
||||||
ICPPASTDeclSpecifier trailCppDecl= (ICPPASTDeclSpecifier) trailDeclSpeci;
|
ICPPASTDeclSpecifier trailCppDecl= (ICPPASTDeclSpecifier) trailDeclSpeci;
|
||||||
ICPPASTDeclSpecifier cppDecl= (ICPPASTDeclSpecifier) declSpeci;
|
ICPPASTDeclSpecifier cppDecl= (ICPPASTDeclSpecifier) declSpeci;
|
||||||
|
@ -319,8 +328,8 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
&& trailDeclSpeci.getStorageClass() == declSpeci.getStorageClass();
|
&& trailDeclSpeci.getStorageClass() == declSpeci.getStorageClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSimpleDeclSpecifierEquals(IASTSimpleDeclSpecifier trailDeclSpeci, IASTSimpleDeclSpecifier declSpeci) {
|
private boolean isSimpleDeclSpecifierEqual(IASTSimpleDeclSpecifier trailDeclSpeci, IASTSimpleDeclSpecifier declSpeci) {
|
||||||
return isDeclSpecifierEquals(trailDeclSpeci, declSpeci)
|
return isDeclSpecifierEqual(trailDeclSpeci, declSpeci)
|
||||||
&& trailDeclSpeci.isLong() == declSpeci.isLong()
|
&& trailDeclSpeci.isLong() == declSpeci.isLong()
|
||||||
&& trailDeclSpeci.isShort() == declSpeci.isShort()
|
&& trailDeclSpeci.isShort() == declSpeci.isShort()
|
||||||
&& trailDeclSpeci.isSigned() == declSpeci.isSigned()
|
&& trailDeclSpeci.isSigned() == declSpeci.isSigned()
|
||||||
|
@ -331,7 +340,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
&& trailDeclSpeci.isLongLong() == declSpeci.isLongLong();
|
&& trailDeclSpeci.isLongLong() == declSpeci.isLongLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNameEquals(TrailName trailName, IASTName name) {
|
private boolean isNameEqual(TrailName trailName, IASTName name) {
|
||||||
int actCount = namesCounter.getObject().intValue();
|
int actCount = namesCounter.getObject().intValue();
|
||||||
if (names.containsKey(name.getRawSignature())) {
|
if (names.containsKey(name.getRawSignature())) {
|
||||||
Integer nameId = names.get(name.getRawSignature());
|
Integer nameId = names.get(name.getRawSignature());
|
||||||
|
@ -344,7 +353,7 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
|
||||||
|
|
||||||
if (actCount != trailName.getNameNumber()) {
|
if (actCount != trailName.getNameNumber()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trailName.isGloballyQualified()) {
|
if (trailName.isGloballyQualified()) {
|
||||||
IBinding realBind = trailName.getRealName().resolveBinding();
|
IBinding realBind = trailName.getRealName().resolveBinding();
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class ASTHelper {
|
||||||
for (int i = 0; i < pointerOperators2.length; i++) {
|
for (int i = 0; i < pointerOperators2.length; i++) {
|
||||||
IASTPointerOperator operator1 = pointerOperators1[i];
|
IASTPointerOperator operator1 = pointerOperators1[i];
|
||||||
IASTPointerOperator operator2 = pointerOperators2[i];
|
IASTPointerOperator operator2 = pointerOperators2[i];
|
||||||
if (!checker.isEquals(operator1, operator2)) {
|
if (!checker.isEqual(operator1, operator2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue