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

View file

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

View file

@ -7,7 +7,7 @@
* 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.extractfunction; 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.NodeContainer.NameInformation;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionInformation { public class ExtractFunctionInformation {
public final int VISIBILITY_PRIVATE = 1; public final int VISIBILITY_PRIVATE = 1;
public final int VISIBILITY_PROTECTED = 3; public final int VISIBILITY_PROTECTED = 3;
public final int VISIBILITY_PUBLIC = 2; public final int VISIBILITY_PUBLIC = 2;
@ -68,10 +66,10 @@ public class ExtractFunctionInformation {
} }
public ArrayList<NameInformation> getAllAfterUsedNames() { public ArrayList<NameInformation> getAllAfterUsedNames() {
if(allAfterUsedNames == null){ if (allAfterUsedNames == null) {
allAfterUsedNames = new ArrayList<NameInformation>(); allAfterUsedNames = new ArrayList<NameInformation>();
for (NameInformation name : getAllUsedNames()) { for (NameInformation name : getAllUsedNames()) {
if(name.isReference()||name.isReturnValue()){ if (name.isReference()||name.isReturnValue()) {
allAfterUsedNames.add(name); allAfterUsedNames.add(name);
} }
} }
@ -89,7 +87,7 @@ public class ExtractFunctionInformation {
} }
public void setReturnVariable(NameInformation returnVariable) { public void setReturnVariable(NameInformation returnVariable) {
if(returnVariable != null) { if (returnVariable != null) {
returnVariable.setUserSetIsReturnValue(true); returnVariable.setUserSetIsReturnValue(true);
} }
this.returnVariable = returnVariable; this.returnVariable = returnVariable;

View file

@ -7,8 +7,8 @@
* 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
* IBM Corporation * IBM Corporation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction; 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.IdentifierResult;
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum; import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
public class ExtractFunctionInputPage extends UserInputWizardPage { public class ExtractFunctionInputPage extends UserInputWizardPage {
private final ExtractFunctionInformation info; private final ExtractFunctionInformation info;
private ExtractFunctionComposite comp; private ExtractFunctionComposite comp;
protected final String NO_NAME_ERROR_LABEL = Messages.ExtractFunctionInputPage_EnterName; protected final String NO_NAME_ERROR_LABEL = Messages.ExtractFunctionInputPage_EnterName;
public ExtractFunctionInputPage(String name, ExtractFunctionInformation info) { public ExtractFunctionInputPage(String name, ExtractFunctionInformation info) {
super(name); super(name);
this.info = info; this.info = info;
} }
@Override
public void createControl(final Composite parent) { public void createControl(final Composite parent) {
comp = new ExtractFunctionComposite(parent, info, this); comp = new ExtractFunctionComposite(parent, info, this);
setPageComplete(false); setPageComplete(false);
comp.getMethodNameText().addModifyListener(new ModifyListener() { comp.getMethodNameText().addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
info.setMethodName(comp.getMethodName()); info.setMethodName(comp.getMethodName());
checkName(); checkName();
} }
}); });
for (Control buttons : comp.getVisibiltyGroup().getChildren()) { for (Control buttons : comp.getVisibiltyGroup().getChildren()) {
buttons.addMouseListener(new MouseAdapter() { 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) { public void widgetDefaultSelected(SelectionEvent e) {
info.setReplaceDuplicates(comp.getReplaceSimilarButton().isEnabled()); info.setReplaceDuplicates(comp.getReplaceSimilarButton().isEnabled());
} }
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e); widgetDefaultSelected(e);
} }
}); });
setControl(comp); setControl(comp);
} }
protected void visibilityChange(String text) { protected void visibilityChange(String text) {
info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(text)); info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(text));
} }
private void checkName() { private void checkName() {
String methodName = comp.getMethodName(); String methodName = comp.getMethodName();
IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName); IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName);
if(result.isCorrect()){ if (result.isCorrect()) {
setErrorMessage(null); setErrorMessage(null);
setPageComplete(true); setPageComplete(true);
} } else {
else{
setErrorMessage(Messages.ExtractFunctionInputPage_CheckFunctionName + " " + result.getMessage()); //$NON-NLS-1$ setErrorMessage(Messages.ExtractFunctionInputPage_CheckFunctionName + " " + result.getMessage()); //$NON-NLS-1$
setPageComplete(false); setPageComplete(false);
} }
} }
public void errorWithAfterUsedVariable(String variableUsedAfterBlock ) { public void errorWithAfterUsedVariable(String variableUsedAfterBlock ) {
if(variableUsedAfterBlock == null) { if (variableUsedAfterBlock == null) {
setErrorMessage(null); setErrorMessage(null);
checkName(); checkName();
}else { } else {
setErrorMessage("The parameter '" + variableUsedAfterBlock + "' " + Messages.ExtractFunctionInputPage_1); //$NON-NLS-1$ //$NON-NLS-2$ 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.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; 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.CRefactoring;
import org.eclipse.cdt.internal.ui.refactoring.CRefactoringDescription; 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.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;
@ -389,7 +389,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
} }
private IASTBinaryExpression getRootBinExp(IASTBinaryExpression binExp, List<IASTNode> nodeList) { 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(); binExp = (IASTBinaryExpression) binExp.getParent();
} }
return binExp; return binExp;
@ -412,10 +412,10 @@ public class ExtractFunctionRefactoring extends CRefactoring {
} }
} }
private void createMethodDeclaration(final IASTName astMethodName, private void createMethodDeclaration(final IASTName astMethodName, MethodContext context,
MethodContext context, ModificationCollector collector) { ModificationCollector collector) {
ICPPASTCompositeTypeSpecifier classDeclaration = (ICPPASTCompositeTypeSpecifier) context ICPPASTCompositeTypeSpecifier classDeclaration =
.getMethodDeclaration().getParent(); (ICPPASTCompositeTypeSpecifier) context.getMethodDeclaration().getParent();
IASTSimpleDeclaration methodDeclaration = getDeclaration(collector, astMethodName); IASTSimpleDeclaration methodDeclaration = getDeclaration(collector, astMethodName);
@ -831,7 +831,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override @Override
public int visit(IASTStatement stmt) { public int visit(IASTStatement stmt) {
if ( SelectionHelper.isSelectedFile(region, stmt, file)) { if (SelectionHelper.isSelectedFile(region, stmt, file)) {
container.add(stmt); container.add(stmt);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@ -875,7 +875,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
@Override @Override
protected RefactoringDescriptor getRefactoringDescriptor() { protected RefactoringDescriptor getRefactoringDescriptor() {
Map<String, String> arguments = getArgumentMap(); 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; return desc;
} }

View file

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

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; 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 * @author Emanuel Graf IFS
*
*/ */
public class ExtractFunctionRefactoringDescription extends CRefactoringDescription { public class ExtractFunctionRefactoringDescription extends CRefactoringDescription {
protected static final String NAME = "name"; //$NON-NLS-1$ protected static final String NAME = "name"; //$NON-NLS-1$
protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$ protected static final String VISIBILITY = "visibility"; //$NON-NLS-1$
protected static final String REPLACE_DUPLICATES = "replaceDuplicates"; //$NON-NLS-1$ protected static final String REPLACE_DUPLICATES = "replaceDuplicates"; //$NON-NLS-1$
public ExtractFunctionRefactoringDescription(String project, String description, public ExtractFunctionRefactoringDescription(String project, String description, String comment,
String comment, Map<String, String> arguments) { Map<String, String> arguments) {
super(ExtractFunctionRefactoring.ID, project, description, comment, RefactoringDescriptor.MULTI_CHANGE, arguments); super(ExtractFunctionRefactoring.ID, project, description, comment,
RefactoringDescriptor.MULTI_CHANGE, arguments);
} }
@Override @Override
@ -55,5 +55,4 @@ public class ExtractFunctionRefactoringDescription extends CRefactoringDescripti
ISelection selection = getSelection(); ISelection selection = getSelection();
return new ExtractFunctionRefactoring(file, selection, info, proj); return new ExtractFunctionRefactoring(file, selection, info, proj);
} }
} }

View file

@ -7,7 +7,7 @@
* 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.extractfunction; package org.eclipse.cdt.internal.ui.refactoring.extractfunction;

View file

@ -7,7 +7,7 @@
* 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.extractfunction; 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; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
public class ExtractFunctionRefactoringWizard extends RefactoringWizard { public class ExtractFunctionRefactoringWizard extends RefactoringWizard {
private final ExtractFunctionInformation info;
private ExtractFunctionInformation info;
public ExtractFunctionRefactoringWizard(Refactoring refactoring, ExtractFunctionInformation info) { public ExtractFunctionRefactoringWizard(Refactoring refactoring, ExtractFunctionInformation info) {
super(refactoring, WIZARD_BASED_USER_INTERFACE); super(refactoring, WIZARD_BASED_USER_INTERFACE);
@ -26,11 +25,10 @@ public class ExtractFunctionRefactoringWizard extends RefactoringWizard {
@Override @Override
protected void addUserInputPages() { protected void addUserInputPages() {
UserInputWizardPage page = new ExtractFunctionInputPage(Messages.ExtractFunctionRefactoringWizard_FunctionName,info); UserInputWizardPage page = new ExtractFunctionInputPage(
Messages.ExtractFunctionRefactoringWizard_FunctionName,info);
page.setTitle(Messages.ExtractFunctionRefactoringWizard_FunctionName); page.setTitle(Messages.ExtractFunctionRefactoringWizard_FunctionName);
addPage(page); addPage(page);
} }
} }

View file

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

View file

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

View file

@ -7,7 +7,7 @@
* 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.extractfunction; package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -22,12 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
class NonExtractableStmtFinder extends ASTVisitor{ class NonExtractableStmtFinder extends ASTVisitor{
private boolean containsContinueStmt;
private boolean containsContinueStmt = false; private boolean containsBreakStmt;
private boolean containsBreakStmt = false;
{ {
shouldVisitStatements = true; shouldVisitStatements = true;
@ -38,12 +36,12 @@ class NonExtractableStmtFinder extends ASTVisitor{
if (statement instanceof IASTContinueStatement) { if (statement instanceof IASTContinueStatement) {
containsContinueStmt = true; containsContinueStmt = true;
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
}else if (statement instanceof IASTBreakStatement) { } else if (statement instanceof IASTBreakStatement) {
containsBreakStmt = true; containsBreakStmt = true;
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
}else if(statement instanceof IASTForStatement|| //Extracting hole loop statements is ok } else if (statement instanceof IASTForStatement || //Extracting hole loop statements is ok
statement instanceof IASTWhileStatement|| statement instanceof IASTWhileStatement ||
statement instanceof IASTSwitchStatement|| statement instanceof IASTSwitchStatement ||
statement instanceof IASTDoStatement) { statement instanceof IASTDoStatement) {
return ASTVisitor.PROCESS_SKIP; return ASTVisitor.PROCESS_SKIP;
} }

View file

@ -7,7 +7,7 @@
* 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.extractfunction; package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -17,13 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
/** /**
* @author Emanuel Graf IFS * @author Emanuel Graf IFS
*
*/ */
class ReturnStatementFinder extends ASTVisitor{ class ReturnStatementFinder extends ASTVisitor{
private boolean containsReturnStmt;
private boolean containsReturnStmt = false;
{ {
shouldVisitStatements = true; shouldVisitStatements = true;
} }
@ -40,5 +37,4 @@ class ReturnStatementFinder extends ASTVisitor{
public boolean containsReturn() { public boolean containsReturn() {
return containsReturnStmt; return containsReturnStmt;
} }
} }

View file

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

View file

@ -7,7 +7,7 @@
* 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.extractfunction; 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; import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper;
class TrailName extends ASTNode{ class TrailName extends ASTNode {
private int nameNumber; private int nameNumber;
private IASTNode declaration = null; private final IASTNode declaration = null;
private IASTName realName = null; private IASTName realName = null;
public TrailName(IASTName realName) { public TrailName(IASTName realName) {
@ -61,10 +60,12 @@ class TrailName extends ASTNode{
return false; return false;
} }
@Override
public IASTNode copy() { public IASTNode copy() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public IASTNode copy(CopyStyle style) { public IASTNode copy(CopyStyle style) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View file

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