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

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-01-07 13:54:53 -08:00
parent fc976f6d9f
commit 8ab95e93b5
16 changed files with 200 additions and 285 deletions

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -30,21 +30,18 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation;
public class ChooserComposite extends Composite {
private static final String COLUMN_RETURN = Messages.ChooserComposite_Return;
private static final String COLUMN_REFERENCE = Messages.ChooserComposite_CallByRef;
private static final String COLUMN_NAME = Messages.ChooserComposite_Name;
private static final String COLUMN_TYPE = Messages.ChooserComposite_Type;
private Button voidReturn;
private final ExtractFunctionInputPage ip;
public ChooserComposite(Composite parent,
final ExtractFunctionInformation info, ExtractFunctionInputPage ip) {
public ChooserComposite(Composite parent, final ExtractFunctionInformation info,
ExtractFunctionInputPage ip) {
super(parent, SWT.NONE);
this.ip = ip;
@ -72,7 +69,7 @@ public class ChooserComposite extends Composite {
addColumnToTable(table, COLUMN_NAME);
addColumnToTable(table, COLUMN_REFERENCE);
addColumnToTable(table, Messages.ChooserComposite_const);
if(!info.isExtractExpression()) {
if (!info.isExtractExpression()) {
addColumnToTable(table, COLUMN_RETURN);
}
addColumnToTable(table, ""); //$NON-NLS-1$
@ -93,26 +90,24 @@ public class ChooserComposite extends Composite {
// Button
editor = new TableEditor(table);
final Button referenceButton = new Button(table, SWT.CHECK);
if(name.hasReferenceOperartor((IASTDeclarator) name.getDeclaration().getParent()))
{
if (name.hasReferenceOperartor((IASTDeclarator) name.getDeclaration().getParent())) {
referenceButton.setSelection(true);
referenceButton.setEnabled(false);
}else {
} else {
referenceButton.setSelection(name.isReference());
}
referenceButton.setBackground(table.getBackground());
referenceButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
name.setUserSetIsReference(referenceButton
.getSelection());
name.setUserSetIsReference(referenceButton.getSelection());
onVisibilityOrReturnChange(info.getAllUsedNames());
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
referenceButton.pack();
editor.minimumWidth = referenceButton.getSize().x;
@ -129,26 +124,24 @@ public class ChooserComposite extends Composite {
constButton.setBackground(table.getBackground());
constButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
name.setConst(constButton
.getSelection());
name.setConst(constButton.getSelection());
onVisibilityOrReturnChange(info.getAllUsedNames());
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
constButton.pack();
editor.minimumWidth = constButton.getSize().x;
editor.horizontalAlignment = SWT.CENTER;
// referenceButtons.add(referenceButton);
editor.setEditor(constButton, item, columnIndex++);
if(info.isExtractExpression())
if (info.isExtractExpression())
continue; // Skip the return radiobutton
// Button
@ -159,28 +152,23 @@ public class ChooserComposite extends Composite {
returnButton.setEnabled(hasNoPredefinedReturnValue);
returnButton.setBackground(table.getBackground());
returnButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
name.setUserSetIsReturnValue(returnButton
.getSelection());
name.setUserSetIsReturnValue(returnButton.getSelection());
if (returnButton.getSelection()) {
referenceButton.setSelection(false);
referenceButton.notifyListeners(SWT.Selection,
new Event());
} else {
if (name.isReference()) {
referenceButton.setSelection(true);
referenceButton.notifyListeners(SWT.Selection,
new Event());
}
referenceButton.notifyListeners(SWT.Selection, new Event());
} else if (name.isReference()) {
referenceButton.setSelection(true);
referenceButton.notifyListeners(SWT.Selection, new Event());
}
onVisibilityOrReturnChange(info.getAllUsedNames());
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
returnButton.pack();
editor.minimumWidth = returnButton.getSize().x;
@ -190,12 +178,12 @@ public class ChooserComposite extends Composite {
}
}
if(!info.isExtractExpression()) {
if (!info.isExtractExpression()) {
voidReturn = new Button(parent, SWT.CHECK | SWT.LEFT);
voidReturn.setText(Messages.ChooserComposite_NoReturnValue);
voidReturn.setEnabled(hasNoPredefinedReturnValue);
voidReturn.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
info.setReturnVariable(null);
@ -205,14 +193,13 @@ public class ChooserComposite extends Composite {
button.notifyListeners(SWT.Selection, new Event());
}
button.setEnabled(!voidReturn.getSelection());
}
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
}
@ -225,16 +212,15 @@ public class ChooserComposite extends Composite {
column.setWidth(100);
}
void onVisibilityOrReturnChange(ArrayList<NameInformation> name){
void onVisibilityOrReturnChange(ArrayList<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);
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -26,13 +26,13 @@ import org.eclipse.cdt.internal.ui.refactoring.dialogs.NameAndVisibilityComposit
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionComposite extends Composite {
private Button replaceSimilar;
private ChooserComposite comp;
private NameAndVisibilityComposite nameVisiComp;
private final ExtractFunctionInformation info;
public ExtractFunctionComposite(Composite parent, ExtractFunctionInformation info, ExtractFunctionInputPage ip) {
public ExtractFunctionComposite(Composite parent, ExtractFunctionInformation info,
ExtractFunctionInputPage ip) {
super(parent, SWT.NONE);
this.info = info;
setLayout(new GridLayout());
@ -46,13 +46,12 @@ public class ExtractFunctionComposite extends Composite {
if (info.getMethodContext().getType() == MethodContext.ContextType.METHOD) {
visibilityPanelSetVisible(true);
}else {
} else {
visibilityPanelSetVisible(false);
}
layout();
}
private Group createReturnGroup(Composite parent) {
Group returnGroup = new Group(parent,SWT.NONE);
@ -65,19 +64,16 @@ public class ExtractFunctionComposite extends Composite {
return returnGroup;
}
private void createReturnValueChooser(Composite parent, ExtractFunctionInformation info, ExtractFunctionInputPage ip) {
private void createReturnValueChooser(Composite parent, ExtractFunctionInformation info,
ExtractFunctionInputPage ip) {
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
comp = new ChooserComposite(parent, info, ip);
comp.setLayoutData(gridData);
comp.redraw();
}
public Text getMethodNameText() {
return nameVisiComp.getConstantNameText();
}
@ -91,11 +87,10 @@ public class ExtractFunctionComposite extends Composite {
}
private void createNewMethodNameComposite(Composite parent) {
String label;
if (info.getMethodContext().getType() == MethodContext.ContextType.METHOD) {
label = Messages.ExtractFunctionComposite_MethodName;
}else {
} else {
label = Messages.ExtractFunctionComposite_FunctionName;
}
nameVisiComp = new NameAndVisibilityComposite(parent, label, VisibilityEnum.v_private, ""); //$NON-NLS-1$
@ -106,15 +101,12 @@ public class ExtractFunctionComposite extends Composite {
final Button virtual = new Button(nameVisiComp, SWT.CHECK);
virtual.setText(Messages.ExtractFunctionComposite_Virtual);
virtual.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
info.setVirtual(virtual.getSelection());
}
});
}
private void createReplaceCheckBox(Composite parent) {
replaceSimilar = new Button(parent, SWT.CHECK | SWT.LEFT);
@ -123,7 +115,6 @@ public class ExtractFunctionComposite extends Composite {
replaceSimilar.setLayoutData(buttonLayoutData);
replaceSimilar.setText(Messages.ExtractFunctionComposite_ReplaceDuplicates);
}
public ChooserComposite getReturnChooser() {
return comp;
@ -133,9 +124,7 @@ public class ExtractFunctionComposite extends Composite {
return nameVisiComp.getConstantNameText().getText();
}
public Composite getVisibiltyGroup() {
return nameVisiComp.getVisibiltyGroup();
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -19,9 +19,7 @@ import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
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;
@ -68,10 +66,10 @@ public class ExtractFunctionInformation {
}
public ArrayList<NameInformation> getAllAfterUsedNames() {
if(allAfterUsedNames == null){
if (allAfterUsedNames == null) {
allAfterUsedNames = new ArrayList<NameInformation>();
for (NameInformation name : getAllUsedNames()) {
if(name.isReference()||name.isReturnValue()){
if (name.isReference()||name.isReturnValue()) {
allAfterUsedNames.add(name);
}
}
@ -89,7 +87,7 @@ public class ExtractFunctionInformation {
}
public void setReturnVariable(NameInformation returnVariable) {
if(returnVariable != null) {
if (returnVariable != null) {
returnVariable.setUserSetIsReturnValue(true);
}
this.returnVariable = returnVariable;

View file

@ -7,8 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* IBM Corporation
* Institute for Software - initial API and implementation
* IBM Corporation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -27,35 +27,30 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionInputPage extends UserInputWizardPage {
private final ExtractFunctionInformation info;
private ExtractFunctionComposite comp;
protected final String NO_NAME_ERROR_LABEL = Messages.ExtractFunctionInputPage_EnterName;
public ExtractFunctionInputPage(String name, ExtractFunctionInformation info) {
super(name);
this.info = info;
}
@Override
public void createControl(final Composite parent) {
comp = new ExtractFunctionComposite(parent, info, this);
setPageComplete(false);
comp.getMethodNameText().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
info.setMethodName(comp.getMethodName());
checkName();
}
});
for (Control buttons : comp.getVisibiltyGroup().getChildren()) {
buttons.addMouseListener(new MouseAdapter() {
@ -67,46 +62,42 @@ public class ExtractFunctionInputPage extends UserInputWizardPage {
});
}
comp.getReplaceSimilarButton().addSelectionListener(new SelectionListener(){
comp.getReplaceSimilarButton().addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
info.setReplaceDuplicates(comp.getReplaceSimilarButton().isEnabled());
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
setControl(comp);
}
protected void visibilityChange(String text) {
info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(text));
}
private void checkName() {
String methodName = comp.getMethodName();
IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName);
if(result.isCorrect()){
if (result.isCorrect()) {
setErrorMessage(null);
setPageComplete(true);
}
else{
} else {
setErrorMessage(Messages.ExtractFunctionInputPage_CheckFunctionName + " " + result.getMessage()); //$NON-NLS-1$
setPageComplete(false);
}
}
public void errorWithAfterUsedVariable(String variableUsedAfterBlock ) {
if(variableUsedAfterBlock == null) {
if (variableUsedAfterBlock == null) {
setErrorMessage(null);
checkName();
}else {
} else {
setErrorMessage("The parameter '" + variableUsedAfterBlock + "' " + Messages.ExtractFunctionInputPage_1); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -95,9 +95,9 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription;
import org.eclipse.cdt.internal.ui.refactoring.ClassMemberInserter;
import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
import org.eclipse.cdt.internal.ui.refactoring.MethodContext.ContextType;
@ -389,7 +389,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
private IASTBinaryExpression getRootBinExp(IASTBinaryExpression binExp, List<IASTNode> nodeList) {
while(binExp.getParent() instanceof IASTBinaryExpression && nodeList.contains(((IASTBinaryExpression) binExp.getParent()).getOperand2())) {
while (binExp.getParent() instanceof IASTBinaryExpression && nodeList.contains(((IASTBinaryExpression) binExp.getParent()).getOperand2())) {
binExp = (IASTBinaryExpression) binExp.getParent();
}
return binExp;
@ -412,10 +412,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
}
private void createMethodDeclaration(final IASTName astMethodName,
MethodContext context, ModificationCollector collector) {
ICPPASTCompositeTypeSpecifier classDeclaration = (ICPPASTCompositeTypeSpecifier) context
.getMethodDeclaration().getParent();
private void createMethodDeclaration(final IASTName astMethodName, MethodContext context,
ModificationCollector collector) {
ICPPASTCompositeTypeSpecifier classDeclaration =
(ICPPASTCompositeTypeSpecifier) context.getMethodDeclaration().getParent();
IASTSimpleDeclaration methodDeclaration = getDeclaration(collector, astMethodName);
@ -831,7 +831,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override
public int visit(IASTStatement stmt) {
if ( SelectionHelper.isSelectedFile(region, stmt, file)) {
if (SelectionHelper.isSelectedFile(region, stmt, file)) {
container.add(stmt);
return PROCESS_SKIP;
}
@ -875,7 +875,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override
protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap();
RefactoringDescriptor desc = new ExtractFunctionRefactoringDescription( project.getProject().getName(), "Extract Method Refactoring", "Create method " + info.getMethodName(), arguments); //$NON-NLS-1$//$NON-NLS-2$
RefactoringDescriptor desc = new ExtractFunctionRefactoringDescription(project.getProject().getName(), "Extract Method Refactoring", "Create method " + info.getMethodName(), arguments); //$NON-NLS-1$//$NON-NLS-2$
return desc;
}

View file

@ -21,7 +21,6 @@ import org.eclipse.cdt.internal.ui.refactoring.CRefactoringContribution;
* @author Emanuel Graf IFS
*/
public class ExtractFunctionRefactoringContribution extends CRefactoringContribution {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public RefactoringDescriptor createDescriptor(String id, String project, String description,

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software (IFS)- initial API and implementation
* Institute for Software (IFS)- initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -27,16 +27,16 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
/**
* @author Emanuel Graf IFS
*
*/
public class ExtractFunctionRefactoringDescription extends CRefactoringDescription {
protected static final String NAME = "name"; //$NON-NLS-1$
protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$
protected static final String REPLACE_DUPLICATES = "replaceDuplicates"; //$NON-NLS-1$
public ExtractFunctionRefactoringDescription(String project, String description,
String comment, Map<String, String> arguments) {
super(ExtractFunctionRefactoring.ID, project, description, comment, RefactoringDescriptor.MULTI_CHANGE, arguments);
public ExtractFunctionRefactoringDescription(String project, String description, String comment,
Map<String, String> arguments) {
super(ExtractFunctionRefactoring.ID, project, description, comment,
RefactoringDescriptor.MULTI_CHANGE, arguments);
}
@Override
@ -55,5 +55,4 @@ public class ExtractFunctionRefactoringDescription extends CRefactoringDescripti
ISelection selection = getSelection();
return new ExtractFunctionRefactoring(file, selection, info, proj);
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -16,8 +16,7 @@ import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
public class ExtractFunctionRefactoringWizard extends RefactoringWizard {
private ExtractFunctionInformation info;
private final ExtractFunctionInformation info;
public ExtractFunctionRefactoringWizard(Refactoring refactoring, ExtractFunctionInformation info) {
super(refactoring, WIZARD_BASED_USER_INTERFACE);
@ -26,11 +25,10 @@ public class ExtractFunctionRefactoringWizard extends RefactoringWizard {
@Override
protected void addUserInputPages() {
UserInputWizardPage page = new ExtractFunctionInputPage(Messages.ExtractFunctionRefactoringWizard_FunctionName,info);
UserInputWizardPage page = new ExtractFunctionInputPage(
Messages.ExtractFunctionRefactoringWizard_FunctionName,info);
page.setTitle(Messages.ExtractFunctionRefactoringWizard_FunctionName);
addPage(page);
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -31,14 +31,11 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper;
/**
* @author Mirko Stocker
*
*/
public class ExtractStatement extends ExtractedFunctionConstructionHelper {
@Override
public void constructMethodBody(IASTCompoundStatement compound,
List<IASTNode> list, ASTRewrite rewrite, TextEditGroup group) {
public void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> list,
ASTRewrite rewrite, TextEditGroup group) {
for (IASTNode each : list) {
rewrite.insertBefore(compound, null, each, group);
}
@ -46,18 +43,18 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper {
@Override
public IASTDeclSpecifier determineReturnType(IASTNode extractedNode, NameInformation returnVariable) {
if(returnVariable != null) {
if (returnVariable != null) {
IASTNode decl = ASTHelper.getDeclarationForNode(returnVariable.getDeclaration());
return ASTHelper.getDeclarationSpecifier(decl).copy(CopyStyle.withLocations);
}
IASTDeclSpecifier declSpec = new CPPASTSimpleDeclSpecifier();
((IASTSimpleDeclSpecifier)declSpec).setType(IASTSimpleDeclSpecifier.t_void);
((IASTSimpleDeclSpecifier) declSpec).setType(IASTSimpleDeclSpecifier.t_void);
return declSpec.copy(CopyStyle.withLocations);
}
@Override
public IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt, IASTExpression callExpression) {
public IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt,
IASTExpression callExpression) {
stmt.setExpression(callExpression);
return stmt;
}

View file

@ -36,38 +36,42 @@ import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation;
/**
* @author Mirko Stocker
*
*/
public abstract class ExtractedFunctionConstructionHelper {
public static ExtractedFunctionConstructionHelper createFor (List<IASTNode> list) {
if(list.get(0) instanceof IASTExpression) {
public static ExtractedFunctionConstructionHelper createFor(List<IASTNode> list) {
if (list.get(0) instanceof IASTExpression) {
return new ExtractExpression();
}
return new ExtractStatement();
}
public abstract void constructMethodBody(IASTCompoundStatement compound,
List<IASTNode> list, ASTRewrite rewrite, TextEditGroup group);
public abstract void constructMethodBody(IASTCompoundStatement compound, List<IASTNode> list,
ASTRewrite rewrite, TextEditGroup group);
public abstract IASTDeclSpecifier determineReturnType(IASTNode extractedNode, NameInformation returnVariable);
public abstract IASTDeclSpecifier determineReturnType(IASTNode extractedNode,
NameInformation returnVariable);
public abstract IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt, IASTExpression callExpression);
public abstract IASTNode createReturnAssignment(IASTNode node, IASTExpressionStatement stmt,
IASTExpression callExpression);
protected boolean isReturnTypeAPointer(IASTNode node) {
return false;
}
IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, IASTStandardFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name,
IASTStandardFunctionDeclarator functionDeclarator, NameInformation returnVariable,
List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
IASTStandardFunctionDeclarator declarator = nodeFactory.newFunctionDeclarator(name);
if (functionDeclarator instanceof ICPPASTFunctionDeclarator && declarator instanceof ICPPASTFunctionDeclarator) {
if (functionDeclarator instanceof ICPPASTFunctionDeclarator &&
declarator instanceof ICPPASTFunctionDeclarator) {
if (((ICPPASTFunctionDeclarator) functionDeclarator).isConst()) {
((ICPPASTFunctionDeclarator) declarator).setConst(true);
}
}
if(returnVariable != null) {
if (returnVariable != null) {
IASTDeclarator decl = (IASTDeclarator) returnVariable.getDeclaration().getParent();
IASTPointerOperator[] pointers = decl.getPointerOperators();
for (IASTPointerOperator operator : pointers) {
@ -79,7 +83,7 @@ public abstract class ExtractedFunctionConstructionHelper {
declarator.addParameterDeclaration(param);
}
if(isReturnTypeAPointer(nodesToWrite.get(0))) {
if (isReturnTypeAPointer(nodesToWrite.get(0))) {
declarator.addPointerOperator(nodeFactory.newPointer());
}
@ -89,7 +93,7 @@ public abstract class ExtractedFunctionConstructionHelper {
public Collection<IASTParameterDeclaration> getParameterDeclarations(Collection<NameInformation> allUsedNames, INodeFactory nodeFactory) {
Collection<IASTParameterDeclaration> result = new ArrayList<IASTParameterDeclaration>();
for (NameInformation name : allUsedNames) {
if(!name.isDeclarationInScope()){
if (!name.isDeclarationInScope()) {
result.add(name.getParameterDeclaration(name.isUserSetIsReference(), nodeFactory));
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -22,12 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
/**
* @author Emanuel Graf IFS
*
*/
class NonExtractableStmtFinder extends ASTVisitor{
private boolean containsContinueStmt = false;
private boolean containsBreakStmt = false;
private boolean containsContinueStmt;
private boolean containsBreakStmt;
{
shouldVisitStatements = true;
@ -38,12 +36,12 @@ class NonExtractableStmtFinder extends ASTVisitor{
if (statement instanceof IASTContinueStatement) {
containsContinueStmt = true;
return ASTVisitor.PROCESS_SKIP;
}else if (statement instanceof IASTBreakStatement) {
} else if (statement instanceof IASTBreakStatement) {
containsBreakStmt = true;
return ASTVisitor.PROCESS_SKIP;
}else if(statement instanceof IASTForStatement|| //Extracting hole loop statements is ok
statement instanceof IASTWhileStatement||
statement instanceof IASTSwitchStatement||
} else if (statement instanceof IASTForStatement || //Extracting hole loop statements is ok
statement instanceof IASTWhileStatement ||
statement instanceof IASTSwitchStatement ||
statement instanceof IASTDoStatement) {
return ASTVisitor.PROCESS_SKIP;
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -17,13 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
/**
* @author Emanuel Graf IFS
*
*/
class ReturnStatementFinder extends ASTVisitor{
private boolean containsReturnStmt;
private boolean containsReturnStmt = false;
{
shouldVisitStatements = true;
}
@ -40,5 +37,4 @@ class ReturnStatementFinder extends ASTVisitor{
public boolean containsReturn() {
return containsReturnStmt;
}
}

View file

@ -13,8 +13,8 @@ package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.Map.Entry;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.text.edits.TextEditGroup;
@ -34,52 +34,49 @@ final class SimilarFinderVisitor extends ASTVisitor {
private final Vector<IASTNode> trail;
private final IASTName name;
private final List<IASTNode> stmts;
private int i;
private final List<IASTNode> statements;
private int statementCount;
private NodeContainer similarContainer;
private final List<IASTStatement> stmtToReplace = new ArrayList<IASTStatement>();
private final ModificationCollector collector;
SimilarFinderVisitor(ExtractFunctionRefactoring refactoring,
ModificationCollector collector, Vector<IASTNode> trail, IFile file, IASTName name,
List<IASTNode> stmts, String title) {
SimilarFinderVisitor(ExtractFunctionRefactoring refactoring, ModificationCollector collector,
Vector<IASTNode> trail, IFile file, IASTName name, List<IASTNode> statements,
String title) {
this.refactoring = refactoring;
this.trail = trail;
this.name = name;
this.stmts = stmts;
this.statements = statements;
this.collector = collector;
this.similarContainer = new NodeContainer();
shouldVisitStatements = true;
}
@Override
public int visit(IASTStatement stmt) {
boolean isAllreadyInMainRefactoring = isInSelection(stmt);
public int visit(IASTStatement statement) {
if (!isInSelection(statement) &&
refactoring.isStatementInTrail(statement, trail, refactoring.getIndex())) {
stmtToReplace.add(statement);
similarContainer.add(statement);
++statementCount;
if ((!isAllreadyInMainRefactoring)
&& this.refactoring.isStatementInTrail(stmt, trail, this.refactoring.getIndex())) {
stmtToReplace.add(stmt);
similarContainer.add(stmt);
++i;
if (i == stmts.size()) {
if (statementCount == statements.size()) {
// Found similar code
boolean similarOnReturnWays = true;
for (NameInformation nameInfo : similarContainer.getAllAfterUsedNames()) {
if (this.refactoring.names.containsKey(nameInfo.getDeclaration().getRawSignature())) {
Integer nameOrderNumber = this.refactoring.names.get(nameInfo.getDeclaration().getRawSignature());
if (this.refactoring.nameTrail.containsValue(nameOrderNumber)) {
if (refactoring.names.containsKey(nameInfo.getDeclaration().getRawSignature())) {
Integer nameOrderNumber = refactoring.names.get(nameInfo.getDeclaration().getRawSignature());
if (refactoring.nameTrail.containsValue(nameOrderNumber)) {
String orgName = null;
boolean found = false;
for (Entry<String, Integer> entry : this.refactoring.nameTrail.entrySet()) {
for (Entry<String, Integer> entry : refactoring.nameTrail.entrySet()) {
if (entry.getValue().equals(nameOrderNumber)) {
orgName = entry.getKey();
}
}
if (orgName != null) {
for (NameInformation orgNameInfo : this.refactoring.container.getAllAfterUsedNamesChoosenByUser()) {
for (NameInformation orgNameInfo : refactoring.container.getAllAfterUsedNamesChoosenByUser()) {
if (orgName.equals(orgNameInfo.getDeclaration().getRawSignature())) {
found = true;
}
@ -95,8 +92,8 @@ final class SimilarFinderVisitor extends ASTVisitor {
if (similarOnReturnWays) {
IASTNode call = refactoring.getMethodCall(name,
this.refactoring.nameTrail, this.refactoring.names,
this.refactoring.container, similarContainer);
refactoring.nameTrail, refactoring.names,
refactoring.container, similarContainer);
ASTRewrite rewrite =
collector.rewriterForTranslationUnit(stmtToReplace.get(0).getTranslationUnit());
TextEditGroup editGroup = new TextEditGroup(Messages.SimilarFinderVisitor_replaceDuplicateCode);
@ -112,12 +109,12 @@ final class SimilarFinderVisitor extends ASTVisitor {
return PROCESS_SKIP;
} else {
clear();
return super.visit(stmt);
return super.visit(statement);
}
}
private boolean isInSelection(IASTStatement stmt) {
List<IASTNode>nodes = this.refactoring.container.getNodesToWrite();
List<IASTNode>nodes = refactoring.container.getNodesToWrite();
for (IASTNode node : nodes) {
if (node.equals(stmt)) {
return true;
@ -127,11 +124,11 @@ final class SimilarFinderVisitor extends ASTVisitor {
}
private void clear() {
i = 0;
this.refactoring.names.clear();
statementCount = 0;
refactoring.names.clear();
similarContainer = new NodeContainer();
this.refactoring.namesCounter.setObject(ExtractFunctionRefactoring.NULL_INTEGER);
this.refactoring.trailPos.setObject(ExtractFunctionRefactoring.NULL_INTEGER);
refactoring.namesCounter.setObject(ExtractFunctionRefactoring.NULL_INTEGER);
refactoring.trailPos.setObject(ExtractFunctionRefactoring.NULL_INTEGER);
stmtToReplace.clear();
}
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -22,10 +22,9 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper;
class TrailName extends ASTNode{
class TrailName extends ASTNode {
private int nameNumber;
private IASTNode declaration = null;
private final IASTNode declaration = null;
private IASTName realName = null;
public TrailName(IASTName realName) {
@ -61,10 +60,12 @@ class TrailName extends ASTNode{
return false;
}
@Override
public IASTNode copy() {
throw new UnsupportedOperationException();
}
@Override
public IASTNode copy(CopyStyle style) {
throw new UnsupportedOperationException();
}

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Institute for Software - initial API and implementation
* Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -66,10 +66,9 @@ import org.eclipse.cdt.internal.ui.refactoring.Container;
import org.eclipse.cdt.internal.ui.refactoring.EqualityChecker;
public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
private final Map<String, Integer> names;
private final Container<Integer> namesCounter;
private IIndex index;
private final IIndex index;
public TrailNodeEqualityChecker(Map<String, Integer> names, Container<Integer> namesCounter, IIndex index) {
super();
@ -78,26 +77,27 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
this.index = index;
}
@Override
public boolean isEquals(IASTNode trailNode, IASTNode node) {
if( (trailNode instanceof TrailName && node instanceof IASTName)
|| Arrays.equals(getInterfaces(node), getInterfaces(trailNode)) ) {
if ((trailNode instanceof TrailName && node instanceof IASTName)
|| Arrays.equals(getInterfaces(node), getInterfaces(trailNode))) {
//Is same type
if(node instanceof IASTExpression){
if (node instanceof IASTExpression) {
return isExpressionEquals(trailNode, node);
} else if(node instanceof IASTStatement){
} else if (node instanceof IASTStatement) {
return isStatementEquals(trailNode, node);
} else if(node instanceof IASTPointerOperator){
} else if (node instanceof IASTPointerOperator) {
return isPointerOperatorEquals(trailNode, node);
} else if(node instanceof IASTDeclaration){
} else if (node instanceof IASTDeclaration) {
return isDeclarationEquals(trailNode, node);
} else if(node instanceof IASTDeclarator){
} else if (node instanceof IASTDeclarator) {
return isDeclaratorEquals(trailNode, node);
} else if(node instanceof IASTInitializer){
} else if (node instanceof IASTInitializer) {
//no speciality, is the same type return true
return true;
} else if(node instanceof IASTDeclSpecifier){
} else if (node instanceof IASTDeclSpecifier) {
return isDeclSpecifierEquals(trailNode, node);
} else if(node instanceof IASTName){
} else if (node instanceof IASTName) {
return isNameEquals(trailNode, node);
} else {
Assert.isLegal(false, "Unexpected Node, this code shoud nod reached"); //$NON-NLS-1$
@ -105,22 +105,18 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
}
}
return false;
}
private boolean isNameEquals(IASTNode trailNode, IASTNode node) {
if(trailNode instanceof ICPPASTConversionName) {
if (trailNode instanceof ICPPASTConversionName) {
return true;
} else if(trailNode instanceof ICPPASTOperatorName) {
ICPPASTOperatorName trailName= ( ICPPASTOperatorName )trailNode;
ICPPASTOperatorName name = ( ICPPASTOperatorName )node;
} else if (trailNode instanceof ICPPASTOperatorName) {
ICPPASTOperatorName trailName= (ICPPASTOperatorName) trailNode;
ICPPASTOperatorName name = (ICPPASTOperatorName) node;
return trailName.equals(name);
} else if(trailNode instanceof TrailName && node instanceof IASTName) {
} else if (trailNode instanceof TrailName && node instanceof IASTName) {
TrailName trailName = (TrailName) trailNode;
IASTName name = (IASTName)node;
return isNameEquals(trailName, name);
} else {
return true;
@ -131,55 +127,46 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof IASTSimpleDeclSpecifier) {
IASTSimpleDeclSpecifier trailDecl = (IASTSimpleDeclSpecifier) trailNode;
IASTSimpleDeclSpecifier decl = (IASTSimpleDeclSpecifier) node;
return isSimpleDeclSpecifierEquals(trailDecl, decl);
} else if (trailNode instanceof ICPPASTNamedTypeSpecifier) {
ICPPASTNamedTypeSpecifier trailDecl = (ICPPASTNamedTypeSpecifier) trailNode;
ICPPASTNamedTypeSpecifier decl = (ICPPASTNamedTypeSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& isSameNamedTypeSpecifierName(trailDecl, decl)
&& trailDecl.isTypename() == decl.isTypename()
&& trailDecl.isExplicit() == decl.isExplicit()
&& trailDecl.isFriend() == decl.isFriend()
&& trailDecl.isVirtual() == decl.isVirtual();
&& isSameNamedTypeSpecifierName(trailDecl, decl)
&& trailDecl.isTypename() == decl.isTypename()
&& trailDecl.isExplicit() == decl.isExplicit()
&& trailDecl.isFriend() == decl.isFriend()
&& trailDecl.isVirtual() == decl.isVirtual();
} else if (trailNode instanceof IASTNamedTypeSpecifier) {
IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode;
IASTNamedTypeSpecifier decl = (IASTNamedTypeSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& isSameNamedTypeSpecifierName(trailDecl, decl);
&& isSameNamedTypeSpecifierName(trailDecl, decl);
} else if (trailNode instanceof IASTElaboratedTypeSpecifier) {
IASTElaboratedTypeSpecifier trailDecl = (IASTElaboratedTypeSpecifier) trailNode;
IASTElaboratedTypeSpecifier decl = (IASTElaboratedTypeSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& trailDecl.getKind() == decl.getKind();
&& trailDecl.getKind() == decl.getKind();
} else if (trailNode instanceof IASTCompositeTypeSpecifier) {
IASTCompositeTypeSpecifier trailDecl = (IASTCompositeTypeSpecifier) trailNode;
IASTCompositeTypeSpecifier decl = (IASTCompositeTypeSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& trailDecl.getKey() == decl.getKey();
&& trailDecl.getKey() == decl.getKey();
} else if (trailNode instanceof ICPPASTDeclSpecifier) {
ICPPASTDeclSpecifier trailDecl = (ICPPASTDeclSpecifier) trailNode;
ICPPASTDeclSpecifier decl = (ICPPASTDeclSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& trailDecl.isExplicit() == decl.isExplicit()
&& trailDecl.isFriend() == decl.isFriend()
&& trailDecl.isVirtual() == decl.isVirtual();
&& trailDecl.isExplicit() == decl.isExplicit()
&& trailDecl.isFriend() == decl.isFriend()
&& trailDecl.isVirtual() == decl.isVirtual();
} else if (trailNode instanceof ICASTDeclSpecifier) {
ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode;
ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& trailDecl.isRestrict() == decl.isRestrict();
&& trailDecl.isRestrict() == decl.isRestrict();
} else if (trailNode instanceof IASTDeclSpecifier) {
IASTDeclSpecifier trailDecl = (IASTDeclSpecifier) trailNode;
IASTDeclSpecifier decl = (IASTDeclSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl);
} else {
//is same
@ -191,15 +178,13 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof IASTStandardFunctionDeclarator) {
IASTStandardFunctionDeclarator trailFunc = (IASTStandardFunctionDeclarator) trailNode;
IASTStandardFunctionDeclarator func = (IASTStandardFunctionDeclarator) node;
return trailFunc.takesVarArgs() == func.takesVarArgs();
} else if (trailNode instanceof ICPPASTFunctionDeclarator) {
ICPPASTFunctionDeclarator trailFunc = (ICPPASTFunctionDeclarator) trailNode;
ICPPASTFunctionDeclarator func = (ICPPASTFunctionDeclarator) node;
return trailFunc.isConst() == func.isConst()
&& trailFunc.isPureVirtual() == func.isPureVirtual()
&& trailFunc.isVolatile() == func.isVolatile();
&& trailFunc.isPureVirtual() == func.isPureVirtual()
&& trailFunc.isVolatile() == func.isVolatile();
} else {
//same type
return true;
@ -210,32 +195,26 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof IASTASMDeclaration) {
IASTASMDeclaration trailASMDecl = (IASTASMDeclaration) trailNode;
IASTASMDeclaration asmDecl = (IASTASMDeclaration) node;
return trailASMDecl.getAssembly().equals(asmDecl.getAssembly());
} else if (trailNode instanceof ICPPASTExplicitTemplateInstantiation) {
ICPPASTExplicitTemplateInstantiation trailTempl = (ICPPASTExplicitTemplateInstantiation) trailNode;
ICPPASTExplicitTemplateInstantiation templ = (ICPPASTExplicitTemplateInstantiation) node;
return trailTempl.getModifier() == templ.getModifier();
} else if (trailNode instanceof ICPPASTLinkageSpecification) {
ICPPASTLinkageSpecification trailLink = (ICPPASTLinkageSpecification) trailNode;
ICPPASTLinkageSpecification link = (ICPPASTLinkageSpecification) node;
return trailLink.getLiteral().equals(link.getLiteral());
} else if (trailNode instanceof ICPPASTTemplateDeclaration) {
ICPPASTTemplateDeclaration trailTempl = (ICPPASTTemplateDeclaration) trailNode;
ICPPASTTemplateDeclaration templ = (ICPPASTTemplateDeclaration) node;
return trailTempl.isExported() == templ.isExported();
} else if (trailNode instanceof ICPPASTUsingDeclaration) {
ICPPASTUsingDeclaration trailUsing = (ICPPASTUsingDeclaration) trailNode;
ICPPASTUsingDeclaration using = (ICPPASTUsingDeclaration) node;
return trailUsing.isTypename() == using.isTypename();
} else if (trailNode instanceof ICPPASTVisibilityLabel) {
ICPPASTVisibilityLabel trailVisibility = (ICPPASTVisibilityLabel) trailNode;
ICPPASTVisibilityLabel visibility = (ICPPASTVisibilityLabel) node;
return trailVisibility.getVisibility() == visibility.getVisibility();
} else {
//same type
@ -247,10 +226,9 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof IASTPointer) {
IASTPointer trailGPointer = (IASTPointer) trailNode;
IASTPointer gPointer = (IASTPointer) node;
return trailGPointer.isConst() == gPointer.isConst()
&& trailGPointer.isRestrict() == gPointer.isRestrict()
&& trailGPointer.isVolatile() == gPointer.isVolatile();
&& trailGPointer.isRestrict() == gPointer.isRestrict()
&& trailGPointer.isVolatile() == gPointer.isVolatile();
} else {
//same type
return true;
@ -261,7 +239,6 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof ICPPASTCatchHandler) {
ICPPASTCatchHandler trailCatch = (ICPPASTCatchHandler) trailNode;
ICPPASTCatchHandler nodeCatch = (ICPPASTCatchHandler) node;
return trailCatch.isCatchAll() == nodeCatch.isCatchAll();
}
//same type
@ -272,51 +249,42 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (trailNode instanceof IASTBinaryExpression) {
IASTBinaryExpression trailExpr = (IASTBinaryExpression) trailNode;
IASTBinaryExpression expr = (IASTBinaryExpression) node;
return trailExpr.getOperator() == expr.getOperator();
} else if (trailNode instanceof ICPPASTFieldReference) {
ICPPASTFieldReference trailFieldRef = (ICPPASTFieldReference) trailNode;
ICPPASTFieldReference fieldRef = (ICPPASTFieldReference) node;
return trailFieldRef.isPointerDereference() == fieldRef.isPointerDereference()
&& trailFieldRef.isTemplate() == fieldRef.isTemplate();
&& trailFieldRef.isTemplate() == fieldRef.isTemplate();
} else if (trailNode instanceof IASTFieldReference) {
IASTFieldReference trailFieldRef = (IASTFieldReference) trailNode;
IASTFieldReference fieldRef = (IASTFieldReference) node;
return trailFieldRef.isPointerDereference() == fieldRef.isPointerDereference();
} else if (trailNode instanceof IASTLiteralExpression) {
IASTLiteralExpression trailLiteral = (IASTLiteralExpression) trailNode;
IASTLiteralExpression literal = (IASTLiteralExpression) node;
return trailLiteral.getKind() == literal.getKind() && trailLiteral.toString().equals(literal.toString());
} else if (trailNode instanceof IASTUnaryExpression) {
IASTUnaryExpression trailExpr = (IASTUnaryExpression) trailNode;
IASTUnaryExpression expr = (IASTUnaryExpression) node;
return trailExpr.getOperator() == expr.getOperator();
} else if (trailNode instanceof IASTTypeIdExpression) {
IASTTypeIdExpression trailIdExpr = (IASTTypeIdExpression) trailNode;
IASTTypeIdExpression idExpr = (IASTTypeIdExpression) node;
return trailIdExpr.getTypeId() == idExpr.getTypeId();
} else if (trailNode instanceof ICPPASTDeleteExpression) {
ICPPASTDeleteExpression trailDelete = (ICPPASTDeleteExpression) trailNode;
ICPPASTDeleteExpression delete = (ICPPASTDeleteExpression) node;
return trailDelete.isGlobal() == delete.isGlobal() && trailDelete.isVectored() == delete.isVectored();
} else if (trailNode instanceof ICPPASTNewExpression) {
ICPPASTNewExpression trailNew = (ICPPASTNewExpression) trailNode;
ICPPASTNewExpression nodeNew = (ICPPASTNewExpression) node;
return trailNew.isGlobal() == nodeNew.isGlobal() && trailNew.isNewTypeId() == nodeNew.isNewTypeId();
} else if (trailNode instanceof ICPPASTSimpleTypeConstructorExpression) {
ICPPASTSimpleTypeConstructorExpression trailConsExpr = (ICPPASTSimpleTypeConstructorExpression) trailNode;
ICPPASTSimpleTypeConstructorExpression consExpr = (ICPPASTSimpleTypeConstructorExpression) node;
return isDeclSpecifierEquals(trailConsExpr.getDeclSpecifier(), consExpr.getDeclSpecifier());
} else {
// same type
// same type
return true;
}
}
@ -331,41 +299,39 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
Class<?>[] returnArray = new Class[interfaceList.size()];
return interfaceList.toArray(returnArray);
}
private boolean isDeclSpecifierEquals(IASTDeclSpecifier trailDeclSpeci, IASTDeclSpecifier declSpeci){
private boolean isDeclSpecifierEquals(IASTDeclSpecifier trailDeclSpeci, IASTDeclSpecifier declSpeci) {
if (trailDeclSpeci instanceof ICPPASTDeclSpecifier) {
ICPPASTDeclSpecifier trailCppDecl= (ICPPASTDeclSpecifier) trailDeclSpeci;
ICPPASTDeclSpecifier cppDecl= (ICPPASTDeclSpecifier) declSpeci;
if (trailCppDecl.isExplicit() == cppDecl.isExplicit()
&& trailCppDecl.isFriend() == cppDecl.isFriend()
&& trailCppDecl.isVirtual() == cppDecl.isVirtual()) {
// ok
} else {
if (trailCppDecl.isExplicit() != cppDecl.isExplicit()
|| trailCppDecl.isFriend() != cppDecl.isFriend()
|| trailCppDecl.isVirtual() != cppDecl.isVirtual()) {
return false;
}
}
return trailDeclSpeci.isConst() == declSpeci.isConst()
&& trailDeclSpeci.isInline() == declSpeci.isInline()
&& trailDeclSpeci.isVolatile() == declSpeci.isVolatile()
&& trailDeclSpeci.isRestrict() == declSpeci.isRestrict()
&& trailDeclSpeci.getStorageClass() == declSpeci.getStorageClass();
return trailDeclSpeci.isConst() == declSpeci.isConst()
&& trailDeclSpeci.isInline() == declSpeci.isInline()
&& trailDeclSpeci.isVolatile() == declSpeci.isVolatile()
&& trailDeclSpeci.isRestrict() == declSpeci.isRestrict()
&& trailDeclSpeci.getStorageClass() == declSpeci.getStorageClass();
}
private boolean isSimpleDeclSpecifierEquals(IASTSimpleDeclSpecifier trailDeclSpeci, IASTSimpleDeclSpecifier declSpeci){
private boolean isSimpleDeclSpecifierEquals(IASTSimpleDeclSpecifier trailDeclSpeci, IASTSimpleDeclSpecifier declSpeci) {
return isDeclSpecifierEquals(trailDeclSpeci, declSpeci)
&& trailDeclSpeci.isLong() == declSpeci.isLong()
&& trailDeclSpeci.isShort() == declSpeci.isShort()
&& trailDeclSpeci.isSigned() == declSpeci.isSigned()
&& trailDeclSpeci.isUnsigned() == declSpeci.isUnsigned()
&& trailDeclSpeci.getType() == declSpeci.getType()
&& trailDeclSpeci.isComplex() == declSpeci.isComplex()
&& trailDeclSpeci.isImaginary() == declSpeci.isImaginary()
&& trailDeclSpeci.isLongLong() == declSpeci.isLongLong();
&& trailDeclSpeci.isLong() == declSpeci.isLong()
&& trailDeclSpeci.isShort() == declSpeci.isShort()
&& trailDeclSpeci.isSigned() == declSpeci.isSigned()
&& trailDeclSpeci.isUnsigned() == declSpeci.isUnsigned()
&& trailDeclSpeci.getType() == declSpeci.getType()
&& trailDeclSpeci.isComplex() == declSpeci.isComplex()
&& trailDeclSpeci.isImaginary() == declSpeci.isImaginary()
&& trailDeclSpeci.isLongLong() == declSpeci.isLongLong();
}
private boolean isNameEquals(TrailName trailName, IASTName name) {
int actCount = namesCounter.getObject().intValue();
if(names.containsKey(name.getRawSignature())){
if (names.containsKey(name.getRawSignature())) {
Integer nameId = names.get(name.getRawSignature());
actCount = nameId.intValue();
} else {
@ -374,45 +340,41 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
names.put(name.getRawSignature(), namesCounter.getObject());
}
if(actCount != trailName.getNameNumber()){
if (actCount != trailName.getNameNumber()) {
return false;
}
if(trailName.isGloballyQualified()) {
if (trailName.isGloballyQualified()) {
IBinding realBind = trailName.getRealName().resolveBinding();
IBinding nameBind = name.resolveBinding();
try {
index.acquireReadLock();
IIndexName[] realDecs = index.findDeclarations(realBind);
IIndexName[] nameDecs = index.findDeclarations(nameBind);
if(realDecs.length == nameDecs.length) {
for(int i = 0; i < realDecs.length; ++i) {
if (realDecs.length == nameDecs.length) {
for (int i = 0; i < realDecs.length; ++i) {
IASTFileLocation rfl = realDecs[i].getFileLocation();
IASTFileLocation nfl = nameDecs[i].getFileLocation();
if(rfl.getNodeOffset() == nfl.getNodeOffset() && rfl.getFileName().equals(nfl.getFileName())) {
continue;
}else {
if (rfl.getNodeOffset() != nfl.getNodeOffset() || !rfl.getFileName().equals(nfl.getFileName()))
return false;
}
}
return true;
}else {
} else {
return false;
}
} catch (InterruptedException e) {}
catch (CoreException e) {}
finally {
} catch (InterruptedException e) {
} catch (CoreException e) {
} finally {
index.releaseReadLock();
}
}else {
} else {
IType oType = getType(trailName.getRealName().resolveBinding());
IType nType = getType(name.resolveBinding());
if (oType == null || nType == null)
return false;
if(oType.isSameType(nType)) {
if (oType.isSameType(nType))
return true;
}
}
return false;
}