From 6e4fe83ed6a8d3684c6c1c6061cad6a7721cc5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Tue, 5 Dec 2023 15:35:52 +0100 Subject: [PATCH] fix "The static method should be accessed directly" warnings via quickfix --- .../ui/tests/refactoring/ccp/CopyTest.java | 4 +-- .../ccp/CopyToClipboardActionTest.java | 18 +++++------ .../LocalCorrectionsSubProcessor.java | 4 +-- .../ui/text/correction/QuickFixProcessor.java | 2 +- .../UnresolvedElementsSubProcessor.java | 30 +++++++++---------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java index de8471197cb..314c4a2a70b 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyTest.java @@ -71,7 +71,7 @@ import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaCopyProcessor; import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgDestinationFactory; import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory; -import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils; +import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtilsCore; import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping; import org.eclipse.jdt.ui.tests.refactoring.GenericRefactoringTest; @@ -2482,7 +2482,7 @@ public void testCopy_Package_to_JavaProject_That_Is_Root() throws Exception { IPackageFragment newPackage= null; for (IPackageFragmentRoot root : otherProject.getAllPackageFragmentRoots()) { - if (ReorgUtils.isSourceFolder(root)) { + if (ReorgUtilsCore.isSourceFolder(root)) { newPackage= root.getPackageFragment(getPackageP().getElementName()); assertTrue("new package does not exist after copying", newPackage.exists()); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyToClipboardActionTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyToClipboardActionTest.java index 0c86458844b..8ca40425ab9 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyToClipboardActionTest.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/CopyToClipboardActionTest.java @@ -47,7 +47,7 @@ import org.eclipse.jdt.internal.core.manipulation.util.Strings; import org.eclipse.jdt.internal.corext.refactoring.TypedSource; import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaElementTransfer; -import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtils; +import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgUtilsCore; import org.eclipse.jdt.ui.JavaElementLabelProvider; import org.eclipse.jdt.ui.tests.refactoring.GenericRefactoringTest; @@ -159,7 +159,7 @@ private void checkEnabled(Object[] elements) throws Exception { private void checkClipboard(Object[] elementsCopied) throws Exception { IResource[] resourcesCopied= getResources(elementsCopied); IJavaElement[] javaElementsCopied= getJavaElements(elementsCopied); - IType[] mainTypesCopied= ReorgUtils.getMainTypes(javaElementsCopied); + IType[] mainTypesCopied= ReorgUtilsCore.getMainTypes(javaElementsCopied); IResource[] resourcesExpected= computeResourcesExpectedInClipboard(resourcesCopied, mainTypesCopied, javaElementsCopied); IJavaElement[] javaElementsExpected= computeJavaElementsExpectedInClipboard(javaElementsCopied, mainTypesCopied); @@ -188,12 +188,12 @@ private void checkTypedSources(IJavaElement[] javaElementsCopied, TypedSource[] } private IResource[] computeResourcesExpectedInClipboard(IResource[] resourcesCopied, IType[] mainTypesCopied, IJavaElement[] javaElementsCopied) { - IResource[] cuResources= ReorgUtils.getResources(getCompilationUnits(javaElementsCopied)); - return ReorgUtils.union(cuResources, ReorgUtils.union(resourcesCopied, ReorgUtils.getResources(ReorgUtils.getCompilationUnits(mainTypesCopied)))); + IResource[] cuResources= ReorgUtilsCore.getResources(getCompilationUnits(javaElementsCopied)); + return ReorgUtilsCore.union(cuResources, ReorgUtilsCore.union(resourcesCopied, ReorgUtilsCore.getResources(ReorgUtilsCore.getCompilationUnits(mainTypesCopied)))); } private static IJavaElement[] computeJavaElementsExpectedInClipboard(IJavaElement[] javaElementsExpected, IType[] mainTypesCopied) { - return ReorgUtils.union(javaElementsExpected, ReorgUtils.getCompilationUnits(mainTypesCopied)); + return ReorgUtilsCore.union(javaElementsExpected, ReorgUtilsCore.getCompilationUnits(mainTypesCopied)); } private String getName(IResource resource){ @@ -243,7 +243,7 @@ private void checkNames(IResource[] resourcesCopied, IJavaElement[] javaElements assertTrue("name not in set:" + name, stringLines.contains(name)); } for (IJavaElement element : javaElementsCopied) { - if (! ReorgUtils.isInsideCompilationUnit(element)){ + if (! ReorgUtilsCore.isInsideCompilationUnit(element)){ String name= getName(element); assertTrue("name not in set:" + name, stringLines.contains(name)); } @@ -279,16 +279,16 @@ private static int countResources(IJavaElement[] javaElementsCopied) { } private static IJavaElement[] getCompilationUnits(IJavaElement[] javaElements) { - List cus= ReorgUtils.getElementsOfType(javaElements, IJavaElement.COMPILATION_UNIT); + List cus= ReorgUtilsCore.getElementsOfType(javaElements, IJavaElement.COMPILATION_UNIT); return cus.toArray(new ICompilationUnit[cus.size()]); } private static IResource[] getResources(Object[] elements) { - return ReorgUtils.getResources(Arrays.asList(elements)); + return ReorgUtilsCore.getResources(Arrays.asList(elements)); } private static IJavaElement[] getJavaElements(Object[] elements) { - return ReorgUtils.getJavaElements(Arrays.asList(elements)); + return ReorgUtilsCore.getJavaElements(Arrays.asList(elements)); } private IJavaElement[] getClipboardJavaElements() { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java index 8bf354c8459..30c971b032d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java @@ -2711,8 +2711,8 @@ public static void addServiceProviderConstructorProposals(IInvocationContext con JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE))); } else { // no-arg constructor does not exist, need to create it - String[] args= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving - .getMethodSignature(org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(targetBinding), new ITypeBinding[0], false) }; + String[] args= new String[] { ASTResolving + .getMethodSignature(ASTResolving.getTypeSignature(targetBinding), new ITypeBinding[0], false) }; String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconstructor_description, args); Image image= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, JavaElementImageDescriptor.CONSTRUCTOR, JavaElementImageProvider.SMALL_SIZE); proposals.add(new NewMethodCorrectionProposal(label, targetCU, targetRoot, new ArrayList<>(), targetBinding, IProposalRelevance.CREATE_CONSTRUCTOR, image)); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java index 7323ce2d1d2..df19e04ca7a 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java @@ -342,7 +342,7 @@ public boolean hasCorrections(ICompilationUnit cu, int problemId) { case IProblem.IllegalFallthroughToPattern: return true; default: - return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId) + return SuppressWarningsSubProcessorCore.hasSuppressWarningsProposal(cu.getJavaProject(), problemId) || ConfigureProblemSeveritySubProcessor.hasConfigureProblemSeverityProposal(problemId); } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java index 85f1b6833f4..0affded2971 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/UnresolvedElementsSubProcessor.java @@ -411,7 +411,7 @@ private static void addNewFieldForType(ICompilationUnit targetCU, ITypeBinding b String label; Image image; if (senderDeclBinding.isEnum() && !isWriteAccess) { - label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createenum_description, new Object[] { nameLabel, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(senderDeclBinding) }); + label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createenum_description, new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) }); image= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); proposals.add(new NewVariableCorrectionProposal(label, targetCU, NewVariableCorrectionProposalCore.ENUM_CONST, simpleName, senderDeclBinding, 10, image)); } else { @@ -420,7 +420,7 @@ private static void addNewFieldForType(ICompilationUnit targetCU, ITypeBinding b label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createfield_description, nameLabel); image= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE); } else { - label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createfield_other_description, new Object[] { nameLabel, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(senderDeclBinding) } ); + label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createfield_other_description, new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) } ); image= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); } int fieldRelevance= StubUtility.hasFieldName(targetCU.getJavaProject(), name) ? IProposalRelevance.CREATE_FIELD_PREFIX_OR_SUFFIX_MATCH : IProposalRelevance.CREATE_FIELD; @@ -432,7 +432,7 @@ private static void addNewFieldForType(ICompilationUnit targetCU, ITypeBinding b label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconst_description, nameLabel); image= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE); } else { - label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconst_other_description, new Object[] { nameLabel, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(senderDeclBinding) } ); + label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconst_other_description, new Object[] { nameLabel, ASTResolving.getTypeSignature(senderDeclBinding) } ); image= JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC); } int constRelevance= StubUtility.hasConstantName(targetCU.getJavaProject(), name) ? IProposalRelevance.CREATE_CONSTANT_PREFIX_OR_SUFFIX_MATCH : IProposalRelevance.CREATE_CONSTANT; @@ -545,7 +545,7 @@ private static void addSimilarVariableProposals(ICompilationUnit cu, Compilation if (NameMatcher.isSimilarName(curr.getName(), identifier)) { AST ast= astRoot.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); - String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetomethod_description, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(curr)); + String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetomethod_description, ASTResolving.getMethodSignature(curr)); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.CHANGE_TO_METHOD, image); newProposals.add(proposal); @@ -1437,7 +1437,7 @@ private static void addNewMethodProposals(ICompilationUnit cu, CompilationUnit a Image image; ITypeBinding[] parameterTypes= getParameterTypes(arguments); if (parameterTypes != null) { - String sig= org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodName, parameterTypes, false); + String sig= ASTResolving.getMethodSignature(methodName, parameterTypes, false); boolean is18OrHigher= JavaModelUtil.is1d8OrHigher(targetCU.getJavaProject()); boolean isSenderTypeAbstractClass = (senderDeclBinding.getModifiers() & Modifier.ABSTRACT) > 0; boolean isSenderBindingInterface= senderDeclBinding.isInterface(); @@ -1470,7 +1470,7 @@ private static void addNewMethodProposals(ICompilationUnit cu, CompilationUnit a isSenderTypeAbstractClass = (senderDeclBinding.getModifiers() & Modifier.ABSTRACT) > 0; if (!senderDeclBinding.isAnonymous()) { if (is18OrHigher || !isSenderBindingInterface) { - String[] args= new String[] { sig, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(senderDeclBinding) }; + String[] args= new String[] { sig, ASTResolving.getTypeSignature(senderDeclBinding) }; label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_other_description, args); labelAbstract= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createmethod_abstract_other_description, args); if (isSenderBindingInterface) { @@ -1631,7 +1631,7 @@ private static void doMoreParameters(IInvocationContext context, ASTNode invocat // add arguments { - String[] arg= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodBinding) }; + String[] arg= new String[] { ASTResolving.getMethodSignature(methodBinding) }; String label; if (diff == 1) { label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addargument_description, arg); @@ -1660,7 +1660,7 @@ private static void doMoreParameters(IInvocationContext context, ASTNode invocat changeDesc[idx]= new RemoveDescription(); changedTypes[i]= declParameterTypes[idx]; } - String[] arg= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodDecl), getTypeNames(changedTypes) }; + String[] arg= new String[] { ASTResolving.getMethodSignature(methodDecl), getTypeNames(changedTypes) }; String label; if (methodDecl.isConstructor()) { if (diff == 1) { @@ -1688,7 +1688,7 @@ private static String getTypeNames(ITypeBinding[] types) { if (i > 0) { buf.append(", "); //$NON-NLS-1$ } - buf.append(org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(types[i])); + buf.append(ASTResolving.getTypeSignature(types[i])); } return BasicElementLabels.getJavaElementName(buf.toString()); } @@ -1735,7 +1735,7 @@ private static void doMoreArguments(IInvocationContext context, ASTNode invocati for (int i= diff - 1; i >= 0; i--) { rewrite.remove(arguments.get(indexSkipped[i]), null); } - String[] arg= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodRef) }; + String[] arg= new String[] { ASTResolving.getMethodSignature(methodRef) }; String label; if (diff == 1) { label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_removeargument_description, arg); @@ -1780,7 +1780,7 @@ private static void doMoreArguments(IInvocationContext context, ASTNode invocati changeDesc[idx]= new InsertDescription(newType, name); changeTypes[i]= newType; } - String[] arg= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodDecl), getTypeNames(changeTypes) }; + String[] arg= new String[] { ASTResolving.getMethodSignature(methodDecl), getTypeNames(changeTypes) }; String label; if (methodDecl.isConstructor()) { if (diff == 1) { @@ -1911,7 +1911,7 @@ private static void doEqualNumberOfParameters(IInvocationContext context, ASTNod ITypeBinding[] declParamTypes= methodDecl.getParameterTypes(); ITypeBinding[] swappedTypes= new ITypeBinding[] { declParamTypes[idx1], declParamTypes[idx2] }; - String[] args= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodDecl), getTypeNames(swappedTypes) }; + String[] args= new String[] { ASTResolving.getMethodSignature(methodDecl), getTypeNames(swappedTypes) }; String label; if (methodDecl.isConstructor()) { label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_swapparams_constr_description, args); @@ -1948,7 +1948,7 @@ private static void doEqualNumberOfParameters(IInvocationContext context, ASTNod return; } boolean isVarArgs= methodDecl.isVarargs() && newParamTypes.length > 0 && newParamTypes[newParamTypes.length - 1].isArray(); - String[] args= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodDecl), org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature(methodDecl.getName(), newParamTypes, isVarArgs) }; + String[] args= new String[] { ASTResolving.getMethodSignature(methodDecl), ASTResolving.getMethodSignature(methodDecl.getName(), newParamTypes, isVarArgs) }; String label; if (methodDecl.isConstructor()) { label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changeparamsignature_constr_description, args); @@ -2036,7 +2036,7 @@ private static void addQualifierToOuterProposal(IInvocationContext context, Meth ASTRewrite rewrite= ASTRewrite.create(invocationNode.getAST()); - String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetoouter_description, org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(currType)); + String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetoouter_description, ASTResolving.getTypeSignature(currType)); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.QUALIFY_WITH_ENCLOSING_TYPE, image); @@ -2126,7 +2126,7 @@ public static void getConstructorProposals(IInvocationContext context, IProblemL ICompilationUnit targetCU= ASTResolving.findCompilationUnitForBinding(cu, astRoot, targetDecl); if (targetCU != null) { - String[] args= new String[] { org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getMethodSignature( org.eclipse.jdt.internal.ui.text.correction.ASTResolving.getTypeSignature(targetDecl), getParameterTypes(arguments), false) }; + String[] args= new String[] { ASTResolving.getMethodSignature( ASTResolving.getTypeSignature(targetDecl), getParameterTypes(arguments), false) }; String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_createconstructor_description, args); Image image= JavaElementImageProvider.getDecoratedImage(JavaPluginImages.DESC_MISC_PUBLIC, JavaElementImageDescriptor.CONSTRUCTOR, JavaElementImageProvider.SMALL_SIZE); proposals.add(new NewMethodCorrectionProposal(label, targetCU, selectedNode, arguments, targetDecl, IProposalRelevance.CREATE_CONSTRUCTOR, image));