mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Bug 500178 - NPE in Rename refactoring
Change-Id: Ia448bf943b7139370ab5b570fb074e79ca6f6f23
This commit is contained in:
parent
8d2d30bf52
commit
215c3d7ce5
2 changed files with 26 additions and 24 deletions
|
@ -32,7 +32,7 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IName getScopeName(){
|
public IName getScopeName() {
|
||||||
IASTNode node = getPhysicalNode();
|
IASTNode node = getPhysicalNode();
|
||||||
if (node instanceof IASTCompoundStatement) {
|
if (node instanceof IASTCompoundStatement) {
|
||||||
final IASTNode parent= node.getParent();
|
final IASTNode parent= node.getParent();
|
||||||
|
|
|
@ -127,9 +127,9 @@ public class ASTManager implements IDisposable {
|
||||||
|
|
||||||
// TODO(sprigogin): Replace fSharedAST and fTranslationUnits with CRefactoringContext.
|
// TODO(sprigogin): Replace fSharedAST and fTranslationUnits with CRefactoringContext.
|
||||||
private IASTTranslationUnit fSharedAST;
|
private IASTTranslationUnit fSharedAST;
|
||||||
private Map<IFile, IASTTranslationUnit> fTranslationUnits= new HashMap<>();
|
private final Map<IFile, IASTTranslationUnit> fTranslationUnits= new HashMap<>();
|
||||||
private Set<String> fProblemUnits= new HashSet<>();
|
private final Set<String> fProblemUnits= new HashSet<>();
|
||||||
private CRefactoringArgument fArgument;
|
private final CRefactoringArgument fArgument;
|
||||||
private IBinding[] fValidBindings;
|
private IBinding[] fValidBindings;
|
||||||
private String fRenameTo;
|
private String fRenameTo;
|
||||||
private HashMap<IBinding, Integer> fKnownBindings;
|
private HashMap<IBinding, Integer> fKnownBindings;
|
||||||
|
@ -356,8 +356,6 @@ public class ASTManager implements IDisposable {
|
||||||
if (s1.getKind() == EScopeKind.eGlobal && s2.getKind() == EScopeKind.eGlobal)
|
if (s1.getKind() == EScopeKind.eGlobal && s2.getKind() == EScopeKind.eGlobal)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
String name1= getName(s1);
|
|
||||||
String name2= getName(s2);
|
|
||||||
|
|
||||||
if (s1 instanceof ICPPBlockScope) {
|
if (s1 instanceof ICPPBlockScope) {
|
||||||
if (s2 instanceof ICPPBlockScope) {
|
if (s2 instanceof ICPPBlockScope) {
|
||||||
|
@ -365,6 +363,9 @@ public class ASTManager implements IDisposable {
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String name1= getName(s1);
|
||||||
|
String name2= getName(s2);
|
||||||
if (s1 instanceof ICPPNamespaceScope) {
|
if (s1 instanceof ICPPNamespaceScope) {
|
||||||
if (s2 instanceof ICPPNamespaceScope) {
|
if (s2 instanceof ICPPNamespaceScope) {
|
||||||
ICPPNamespaceScope n1= (ICPPNamespaceScope) s1;
|
ICPPNamespaceScope n1= (ICPPNamespaceScope) s1;
|
||||||
|
@ -373,7 +374,7 @@ public class ASTManager implements IDisposable {
|
||||||
if (r1 == TRUE) {
|
if (r1 == TRUE) {
|
||||||
return r1;
|
return r1;
|
||||||
}
|
}
|
||||||
if (!name1.equals(name2)) {
|
if (name1 == null || name2 == null || !name1.equals(name2)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return isSameScope(n1.getParent(), n2.getParent(), fileStatic);
|
return isSameScope(n1.getParent(), n2.getParent(), fileStatic);
|
||||||
|
@ -381,7 +382,7 @@ public class ASTManager implements IDisposable {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name1.equals(name2)) {
|
if (name1 != null && name2 != null && !name1.equals(name2)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,6 +393,7 @@ public class ASTManager implements IDisposable {
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
// Functions.
|
||||||
if (s1 instanceof ICPPFunctionScope) {
|
if (s1 instanceof ICPPFunctionScope) {
|
||||||
if (s2 instanceof ICPPFunctionScope) {
|
if (s2 instanceof ICPPFunctionScope) {
|
||||||
return hasSameLocation(node1, node2, true);
|
return hasSameLocation(node1, node2, true);
|
||||||
|
@ -410,40 +412,40 @@ public class ASTManager implements IDisposable {
|
||||||
return isSameScope(s1.getParent(), s2.getParent(), fileStatic);
|
return isSameScope(s1.getParent(), s2.getParent(), fileStatic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getName(IScope s1) {
|
public static String getName(IScope scope) {
|
||||||
String name= null;
|
String name= null;
|
||||||
if (s1 instanceof IIndexScope) {
|
if (scope instanceof IIndexScope) {
|
||||||
IIndexScope indexScope= (IIndexScope) s1;
|
IIndexScope indexScope= (IIndexScope) scope;
|
||||||
final IIndexName scopeName = indexScope.getScopeName();
|
final IIndexName scopeName = indexScope.getScopeName();
|
||||||
if (scopeName != null) {
|
if (scopeName != null) {
|
||||||
name= scopeName.toString();
|
name= scopeName.toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name= getNameOrNull(ASTInternal.getPhysicalNodeOfScope(s1));
|
name= getNameOrNull(ASTInternal.getPhysicalNodeOfScope(scope));
|
||||||
}
|
}
|
||||||
return name == null ? s1.toString() : name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int hasSameSignature(IFunction b1, IFunction b2) throws DOMException {
|
public static int hasSameSignature(IFunction f1, IFunction f2) throws DOMException {
|
||||||
if (b1.takesVarArgs() != b2.takesVarArgs())
|
if (f1.takesVarArgs() != f2.takesVarArgs())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (b1 instanceof ICPPMethod != b2 instanceof ICPPMethod)
|
if (f1 instanceof ICPPMethod != f2 instanceof ICPPMethod)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return hasSameSignature(b1.getType(), b2.getType());
|
return hasSameSignature(f1.getType(), f2.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int hasSameSignature(IFunctionType b1, IFunctionType b2) throws DOMException {
|
public static int hasSameSignature(IFunctionType t1, IFunctionType t2) throws DOMException {
|
||||||
if (b1 instanceof ICPPFunctionType && b2 instanceof ICPPFunctionType) {
|
if (t1 instanceof ICPPFunctionType && t2 instanceof ICPPFunctionType) {
|
||||||
ICPPFunctionType cppb1= (ICPPFunctionType) b1;
|
ICPPFunctionType cppt1= (ICPPFunctionType) t1;
|
||||||
ICPPFunctionType cppb2= (ICPPFunctionType) b2;
|
ICPPFunctionType cppt2= (ICPPFunctionType) t2;
|
||||||
if (cppb1.isConst() != cppb2.isConst())
|
if (cppt1.isConst() != cppt2.isConst())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (cppb1.isVolatile() != cppb2.isVolatile())
|
if (cppt1.isVolatile() != cppt2.isVolatile())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return isSameParameterList(b1.getParameterTypes(), b2.getParameterTypes());
|
return isSameParameterList(t1.getParameterTypes(), t2.getParameterTypes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int isSameParameterList(IType[] p1, IType[] p2) throws DOMException {
|
private static int isSameParameterList(IType[] p1, IType[] p2) throws DOMException {
|
||||||
|
|
Loading…
Add table
Reference in a new issue