Skip to content

Commit

Permalink
fix "The static method should be accessed directly" warnings
Browse files Browse the repository at this point in the history
via quickfix
  • Loading branch information
EcljpseB0T committed Dec 5, 2023
1 parent 3ecf44a commit 6e4fe83
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 6e4fe83

Please sign in to comment.