Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c0bec58f65e5af78b63d102c2cba3d91996bd215 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*******************************************************************************
 * Copyright (c) 2005, 2010 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html  
 * 
 * Contributors: 
 *     Markus Schorn - initial API and implementation 
 ******************************************************************************/ 
package org.eclipse.cdt.internal.ui.refactoring.rename;

import java.util.ArrayList;
import java.util.Arrays;

import org.eclipse.ltk.core.refactoring.RefactoringStatus;

import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;

/**
 * Processor adding constructor and destructor to the bindings to be renamed.
 */
public class CRenameClassProcessor extends CRenameTypeProcessor {

    public CRenameClassProcessor(CRenameProcessor processor, String kind) {
        super(processor, kind);
    }
    
    @Override
	protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
        CRefactoringArgument argument= getArgument();
        IBinding binding= argument.getBinding();
        ArrayList<IBinding> bindings= new ArrayList<>();
        if (binding != null) {
            bindings.add(binding);
        }
        if (binding instanceof ICPPClassType) {
            ICPPClassType ctype= (ICPPClassType) binding;
            ICPPConstructor[] ctors= ctype.getConstructors();
			if (ctors != null) {
			    bindings.addAll(Arrays.asList(ctors));
			}
			
			IScope scope= ctype.getCompositeScope();
			if (scope != null) {
			    IBinding[] dtors= scope.find("~" + argument.getName()); //$NON-NLS-1$
			    if (dtors != null) {
			        bindings.addAll(Arrays.asList(dtors));
			    }
			}
        }
        return bindings.toArray(new IBinding[bindings.size()]);
    }
}

Back to the top