Skip to content

Commit

Permalink
Tweak logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohnstn committed Nov 8, 2024
1 parent b3e8fdc commit 5982e03
Showing 1 changed file with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,54 +530,56 @@ public boolean visit(MethodInvocation node) {

private void checkShadowing2(RefactoringStatus result) {
try {
ICompilationUnit icu= fMethod.getCompilationUnit();
CompilationUnit cu= Checks.convertICUtoCU(icu);
if (cu == null) {
return;
}
ShadowedMethodVisitor visitor= new ShadowedMethodVisitor();
try {
AbstractTypeDeclaration methodTypeDecl= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(fMethod.getDeclaringType(), cu);
if (methodTypeDecl != null) {
methodTypeDecl.accept(visitor);
}
} catch (AbortSearchException e) {
MethodInvocation method= visitor.getMethod();
RefactoringStatusContext context= JavaStatusContext.create(icu, new SourceRange(method.getStartPosition(), method.getLength()));
String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_name_will_shadow2, new Object[] {fMethod.getElementName(), fMethodName});
if (fMethod.getParameterNames().length == 0) {
result.addFatalError(msg, context);
} else {
result.addError(msg, context);
if (!fMethodName.equals(fMethod.getElementName())) {
ICompilationUnit icu= fMethod.getCompilationUnit();
CompilationUnit cu= Checks.convertICUtoCU(icu);
if (cu == null) {
return;
}
return;
}
if (!fMethodName.equals(fMethod.getElementName()) && !Modifier.isPrivate(fMethod.getFlags())) {
SearchResultGroup[] matches= findImplementors(fMethod.getDeclaringType(), new NullProgressMonitor());
for (SearchResultGroup match : matches) {
icu= match.getCompilationUnit();
cu= Checks.convertICUtoCU(icu);
if (cu == null) {
return;
ShadowedMethodVisitor visitor= new ShadowedMethodVisitor();
try {
AbstractTypeDeclaration methodTypeDecl= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(fMethod.getDeclaringType(), cu);
if (methodTypeDecl != null) {
methodTypeDecl.accept(visitor);
}
for (SearchMatch matchResult : match.getSearchResults()) {
if (matchResult instanceof TypeReferenceMatch typeMatch && typeMatch.getElement() instanceof IType type) {
final TypeDeclaration typeDecl= ASTNodeSearchUtil.getTypeDeclarationNode(type, cu);
if (typeDecl != null) {
ITypeBinding typeBinding= typeDecl.resolveBinding();
if (Modifier.isPublic(fMethod.getFlags()) || Modifier.isProtected(fMethod.getFlags()) ||
typeBinding != null && typeBinding.getPackage().getName().equals(fMethod.getDeclaringType().getPackageFragment().getElementName())) {
visitor= new ShadowedMethodVisitor();
try {
typeDecl.accept(visitor);
} catch (AbortSearchException e) {
MethodInvocation method= visitor.getMethod();
RefactoringStatusContext context= JavaStatusContext.create(icu, new SourceRange(method.getStartPosition(), method.getLength()));
String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_name_will_shadow2, new Object[] {fMethod.getElementName(), fMethodName});
if (fMethod.getParameterNames().length == 0) {
result.addFatalError(msg, context);
} else {
result.addError(msg, context);
} catch (AbortSearchException e) {
MethodInvocation method= visitor.getMethod();
RefactoringStatusContext context= JavaStatusContext.create(icu, new SourceRange(method.getStartPosition(), method.getLength()));
String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_name_will_shadow2, new Object[] {fMethod.getElementName(), fMethodName});
if (fMethod.getParameterNames().length == 0) {
result.addFatalError(msg, context);
} else {
result.addError(msg, context);
}
return;
}
if (!Modifier.isPrivate(fMethod.getFlags())) {
SearchResultGroup[] matches= findImplementors(fMethod.getDeclaringType(), new NullProgressMonitor());
for (SearchResultGroup match : matches) {
icu= match.getCompilationUnit();
cu= Checks.convertICUtoCU(icu);
if (cu == null) {
return;
}
for (SearchMatch matchResult : match.getSearchResults()) {
if (matchResult instanceof TypeReferenceMatch typeMatch && typeMatch.getElement() instanceof IType type) {
final TypeDeclaration typeDecl= ASTNodeSearchUtil.getTypeDeclarationNode(type, cu);
if (typeDecl != null) {
ITypeBinding typeBinding= typeDecl.resolveBinding();
if (Modifier.isPublic(fMethod.getFlags()) || Modifier.isProtected(fMethod.getFlags()) ||
typeBinding != null && typeBinding.getPackage().getName().equals(fMethod.getDeclaringType().getPackageFragment().getElementName())) {
visitor= new ShadowedMethodVisitor();
try {
typeDecl.accept(visitor);
} catch (AbortSearchException e) {
MethodInvocation method= visitor.getMethod();
RefactoringStatusContext context= JavaStatusContext.create(icu, new SourceRange(method.getStartPosition(), method.getLength()));
String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_name_will_shadow2, new Object[] {fMethod.getElementName(), fMethodName});
if (fMethod.getParameterNames().length == 0) {
result.addFatalError(msg, context);
} else {
result.addError(msg, context);
}
}
}
}
Expand Down

0 comments on commit 5982e03

Please sign in to comment.