1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-03 13:43:31 +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

@ -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;
@ -93,8 +90,7 @@ 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 {
@ -102,17 +98,16 @@ public class ChooserComposite extends Composite {
}
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,17 +124,16 @@ 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;
@ -147,7 +141,6 @@ public class ChooserComposite extends Composite {
// referenceButtons.add(referenceButton);
editor.setEditor(constButton, item, columnIndex++);
if (info.isExtractExpression())
continue; // Skip the return radiobutton
@ -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.notifyListeners(SWT.Selection, new Event());
} else if (name.isReference()) {
referenceButton.setSelection(true);
referenceButton.notifyListeners(SWT.Selection,
new Event());
}
referenceButton.notifyListeners(SWT.Selection, new Event());
}
onVisibilityOrReturnChange(info.getAllUsedNames());
}
@Override
public void widgetSelected(SelectionEvent e) {
widgetDefaultSelected(e);
}
});
returnButton.pack();
editor.minimumWidth = returnButton.getSize().x;
@ -195,7 +183,7 @@ public class ChooserComposite extends Composite {
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);
}
});
}
@ -235,6 +222,5 @@ public class ChooserComposite extends Composite {
}
ip.errorWithAfterUsedVariable(variableUsedAfterBlock);
}
}

View file

@ -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());
@ -52,7 +52,6 @@ public class ExtractFunctionComposite extends Composite {
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,7 +87,6 @@ public class ExtractFunctionComposite extends Composite {
}
private void createNewMethodNameComposite(Composite parent) {
String label;
if (info.getMethodContext().getType() == MethodContext.ContextType.METHOD) {
label = Messages.ExtractFunctionComposite_MethodName;
@ -106,16 +101,13 @@ 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);
GridData buttonLayoutData = new GridData(SWT.None);
@ -124,7 +116,6 @@ public class ExtractFunctionComposite extends Composite {
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

@ -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;

View file

@ -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() {
@ -68,35 +63,31 @@ public class ExtractFunctionInputPage extends UserInputWizardPage {
}
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()) {
setErrorMessage(null);
setPageComplete(true);
}
else{
} else {
setErrorMessage(Messages.ExtractFunctionInputPage_CheckFunctionName + " " + result.getMessage()); //$NON-NLS-1$
setPageComplete(false);
}

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;
@ -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);

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

@ -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

@ -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

@ -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,7 +43,6 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper {
@Override
public IASTDeclSpecifier determineReturnType(IASTNode extractedNode, NameInformation returnVariable) {
if (returnVariable != null) {
IASTNode decl = ASTHelper.getDeclarationForNode(returnVariable.getDeclaration());
return ASTHelper.getDeclarationSpecifier(decl).copy(CopyStyle.withLocations);
@ -57,7 +53,8 @@ public class ExtractStatement extends ExtractedFunctionConstructionHelper {
}
@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,7 +36,6 @@ import org.eclipse.cdt.internal.ui.refactoring.NodeContainer.NameInformation;
/**
* @author Mirko Stocker
*
*/
public abstract class ExtractedFunctionConstructionHelper {
@ -47,21 +46,26 @@ public abstract class ExtractedFunctionConstructionHelper {
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);
}

View file

@ -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;

View file

@ -17,12 +17,9 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
/**
* @author Emanuel Graf IFS
*
*/
class ReturnStatementFinder extends ASTVisitor{
private boolean containsReturnStmt = false;
private boolean containsReturnStmt;
{
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

@ -23,9 +23,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.ui.refactoring.utils.ASTHelper;
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

@ -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,6 +77,7 @@ 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))) {
@ -105,8 +105,6 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
}
}
return false;
}
private boolean isNameEquals(IASTNode trailNode, IASTNode node) {
@ -115,12 +113,10 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
} 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) {
TrailName trailName = (TrailName) trailNode;
IASTName name = (IASTName)node;
return isNameEquals(trailName, name);
} else {
return true;
@ -131,13 +127,10 @@ 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()
@ -147,25 +140,21 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
} else if (trailNode instanceof IASTNamedTypeSpecifier) {
IASTNamedTypeSpecifier trailDecl = (IASTNamedTypeSpecifier) trailNode;
IASTNamedTypeSpecifier decl = (IASTNamedTypeSpecifier) node;
return isDeclSpecifierEquals(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();
} else if (trailNode instanceof IASTCompositeTypeSpecifier) {
IASTCompositeTypeSpecifier trailDecl = (IASTCompositeTypeSpecifier) trailNode;
IASTCompositeTypeSpecifier decl = (IASTCompositeTypeSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& 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()
@ -173,13 +162,11 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
} else if (trailNode instanceof ICASTDeclSpecifier) {
ICASTDeclSpecifier trailDecl = (ICASTDeclSpecifier) trailNode;
ICASTDeclSpecifier decl = (ICASTDeclSpecifier) node;
return isDeclSpecifierEquals(trailDecl, decl)
&& 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,12 +178,10 @@ 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();
@ -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,7 +226,6 @@ 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();
@ -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,48 +249,39 @@ 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();
} 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
@ -336,11 +304,9 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
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;
}
}
@ -389,19 +355,16 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
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 {
return false;
}
} catch (InterruptedException e) {}
catch (CoreException e) {}
finally {
} catch (InterruptedException e) {
} catch (CoreException e) {
} finally {
index.releaseReadLock();
}
} else {
@ -410,10 +373,9 @@ public class TrailNodeEqualityChecker implements EqualityChecker<IASTNode> {
if (oType == null || nType == null)
return false;
if(oType.isSameType(nType)) {
if (oType.isSameType(nType))
return true;
}
}
return false;
}