mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[jvm-lang] add JvmClass#findMethodsByName
This commit is contained in:
@@ -1,21 +1,8 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.lang.jvm;
|
||||
|
||||
import com.intellij.lang.jvm.types.JvmReferenceType;
|
||||
import com.intellij.lang.jvm.util.JvmClassDefaults;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -70,6 +57,15 @@ public interface JvmClass extends JvmTypeParametersOwner, JvmTypeDeclaration {
|
||||
@NotNull
|
||||
JvmMethod[] getMethods();
|
||||
|
||||
/**
|
||||
* @return methods (excluding inherited) with the specified name
|
||||
* @see Class#getDeclaredMethod
|
||||
*/
|
||||
@NotNull
|
||||
default JvmMethod[] findMethodsByName(@NotNull String methodName) {
|
||||
return JvmClassDefaults.findMethodsByName(this, methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all (static, private, etc) fields declared by this class but excluding inherited ones
|
||||
* @see Class#getDeclaredFields
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public interface JvmMethod extends JvmTypeParametersOwner {
|
||||
|
||||
JvmMethod[] EMPTY_ARRAY = new JvmMethod[0];
|
||||
|
||||
/**
|
||||
* @return {@code true} if this method is a constructor
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.lang.jvm.util;
|
||||
|
||||
import com.intellij.lang.jvm.JvmClass;
|
||||
import com.intellij.lang.jvm.JvmMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.containers.ContainerUtil.filter;
|
||||
|
||||
/**
|
||||
* This class holds default implementations of {@link JvmClass} methods.
|
||||
*/
|
||||
public class JvmClassDefaults {
|
||||
|
||||
private JvmClassDefaults() {}
|
||||
|
||||
@NotNull
|
||||
public static JvmMethod[] findMethodsByName(@NotNull JvmClass clazz, @NotNull String methodName) {
|
||||
List<JvmMethod> result = filter(clazz.getMethods(), it -> it.getName().equals(methodName));
|
||||
return result.toArray(JvmMethod.EMPTY_ARRAY);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.lang.jvm.JvmClass;
|
||||
import com.intellij.lang.jvm.JvmClassKind;
|
||||
import com.intellij.lang.jvm.JvmMethod;
|
||||
import com.intellij.lang.jvm.types.JvmReferenceType;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.pom.PomRenameableTarget;
|
||||
@@ -244,6 +231,12 @@ public interface PsiClass
|
||||
@NotNull
|
||||
PsiMethod[] findMethodsBySignature(PsiMethod patternMethod, boolean checkBases);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default JvmMethod[] findMethodsByName(@NotNull String methodName) {
|
||||
return findMethodsByName(methodName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the class (and optionally its superclasses) for the methods with the specified name.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user