mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method refs: process local classes (IDEA-100452)
This commit is contained in:
+15
-7
@@ -205,34 +205,42 @@ public class LambdaCanBeMethReferenceInspection extends BaseJavaLocalInspectionT
|
||||
final String methodReferenceName = methodExpression.getReferenceName();
|
||||
if (qualifierExpression != null) {
|
||||
boolean isReceiverType = PsiMethodReferenceUtil.isReceiverType(functionalInterfaceType, containingClass, psiMethod);
|
||||
methodRefText = (isReceiverType ? containingClass.getQualifiedName() : qualifierExpression.getText()) + "::" + ((PsiMethodCallExpression)element).getTypeArgumentList().getText() + methodReferenceName;
|
||||
methodRefText = (isReceiverType ? getClassReferenceName(containingClass) : qualifierExpression.getText()) + "::" + ((PsiMethodCallExpression)element).getTypeArgumentList().getText() + methodReferenceName;
|
||||
}
|
||||
else {
|
||||
methodRefText =
|
||||
(psiMethod.hasModifierProperty(PsiModifier.STATIC) ? containingClass.getQualifiedName() : "this") + "::" + methodReferenceName;
|
||||
(psiMethod.hasModifierProperty(PsiModifier.STATIC) ? getClassReferenceName(containingClass) : "this") + "::" + methodReferenceName;
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiNewExpression) {
|
||||
final PsiMethod constructor = ((PsiNewExpression)element).resolveConstructor();
|
||||
PsiClass containingClass = null;
|
||||
if (constructor != null) {
|
||||
final PsiClass containingClass = constructor.getContainingClass();
|
||||
containingClass = constructor.getContainingClass();
|
||||
LOG.assertTrue(containingClass != null);
|
||||
methodRefText = containingClass.getQualifiedName() + "::new";
|
||||
}
|
||||
else {
|
||||
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)element).getClassOrAnonymousClassReference();
|
||||
if (classReference != null) {
|
||||
final JavaResolveResult resolve = classReference.advancedResolve(false);
|
||||
final PsiElement containingClass = resolve.getElement();
|
||||
if (containingClass instanceof PsiClass) {
|
||||
methodRefText = ((PsiClass)containingClass).getQualifiedName() + "::new";
|
||||
final PsiElement resolveElement = resolve.getElement();
|
||||
if (resolveElement instanceof PsiClass) {
|
||||
containingClass = (PsiClass)resolveElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (containingClass != null) {
|
||||
methodRefText = getClassReferenceName(containingClass) + "::new";
|
||||
}
|
||||
}
|
||||
return methodRefText;
|
||||
}
|
||||
|
||||
private static String getClassReferenceName(PsiClass containingClass) {
|
||||
final String qualifiedName = containingClass.getQualifiedName();
|
||||
return qualifiedName != null ? qualifiedName : containingClass.getName();
|
||||
}
|
||||
|
||||
private static class ReplaceWithMethodRefFix implements LocalQuickFix {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// "Replace lambda with method reference" "true"
|
||||
public class IDEA100452 {
|
||||
public static <T> MatchOp<T> match(MatchOp.MatchKind matchKind) {
|
||||
class MatchSink extends BooleanTerminalSink<T> {
|
||||
|
||||
private MatchSink() {
|
||||
super(matchKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(T t) {
|
||||
}
|
||||
}
|
||||
|
||||
Supplier<BooleanTerminalSink<T>> s = MatchSink::new;
|
||||
return new MatchOp<>(1, matchKind, s);
|
||||
}
|
||||
|
||||
static abstract class BooleanTerminalSink<T> {
|
||||
public BooleanTerminalSink(MatchOp.MatchKind matchKind) {
|
||||
|
||||
}
|
||||
|
||||
public abstract void accept(T t);
|
||||
}
|
||||
static interface Supplier<T> {
|
||||
public T get();
|
||||
}
|
||||
|
||||
static class MatchOp<H> {
|
||||
public MatchOp(int i, MatchKind matchKind, Supplier<BooleanTerminalSink<H>> s) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
static enum MatchKind {}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// "Replace lambda with method reference" "true"
|
||||
public class IDEA100452 {
|
||||
public static <T> MatchOp<T> match(MatchOp.MatchKind matchKind) {
|
||||
class MatchSink extends BooleanTerminalSink<T> {
|
||||
|
||||
private MatchSink() {
|
||||
super(matchKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(T t) {
|
||||
}
|
||||
}
|
||||
|
||||
Supplier<BooleanTerminalSink<T>> s = () -> new Match<caret>Sink();
|
||||
return new MatchOp<>(1, matchKind, s);
|
||||
}
|
||||
|
||||
static abstract class BooleanTerminalSink<T> {
|
||||
public BooleanTerminalSink(MatchOp.MatchKind matchKind) {
|
||||
|
||||
}
|
||||
|
||||
public abstract void accept(T t);
|
||||
}
|
||||
static interface Supplier<T> {
|
||||
public T get();
|
||||
}
|
||||
|
||||
static class MatchOp<H> {
|
||||
public MatchOp(int i, MatchKind matchKind, Supplier<BooleanTerminalSink<H>> s) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
static enum MatchKind {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user