[java] - unused declaration rework for functional expressions

GitOrigin-RevId: e2f2188edf79fddd902c038bdfdea072eed01bfe
This commit is contained in:
Ilyas Selimov
2021-10-11 11:37:39 +07:00
committed by intellij-monorepo-bot
parent edae7f4aa0
commit 6b74c12eab
62 changed files with 1342 additions and 430 deletions

View File

@@ -311,6 +311,10 @@ inspection.redundant.type.problem.descriptor=Explicit type arguments can be infe
inspection.redundant.type.remove.quickfix=Remove type arguments
inspection.reference.anonymous.name=anonymous ({0})
inspection.reference.implicit.constructor.name=implicit constructor of {0}
inspection.reference.lambda.name=lambda ({0})
inspection.reference.default.lambda.name=lambda
inspection.reference.method.reference.name=method reference ({0})
inspection.reference.default.method.reference.name=method reference
inspection.reference.jsp.holder.method.anonymous.name=<% page content %>
inspection.requires.auto.module.message='requires' directive for an automatic module
inspection.requires.auto.module.option=Highlight only transitive dependencies

View File

@@ -13,9 +13,9 @@ import org.jetbrains.annotations.NotNull;
public abstract class HTMLJavaHTMLComposer implements HTMLComposerExtension<HTMLJavaHTMLComposer> {
public static final Key<HTMLJavaHTMLComposer> COMPOSER = Key.create("HTMLJavaComposer");
public abstract void appendClassOrInterface(@NotNull StringBuilder buf, RefClass refClass, boolean capitalizeFirstLetter);
public abstract void appendClassOrInterface(@NotNull StringBuilder buf, @NotNull RefClass refClass, boolean capitalizeFirstLetter);
public static String getClassOrInterface(RefClass refClass, boolean capitalizeFirstLetter) {
public static String getClassOrInterface(@NotNull RefClass refClass, boolean capitalizeFirstLetter) {
if (refClass.isInterface()) {
return capitalizeFirstLetter ? AnalysisBundle.message("inspection.export.results.capitalized.interface") : AnalysisBundle.message("inspection.export.results.interface");
}
@@ -27,17 +27,19 @@ public abstract class HTMLJavaHTMLComposer implements HTMLComposerExtension<HTML
}
}
public abstract void appendClassExtendsImplements(@NotNull StringBuilder buf, RefClass refClass);
public abstract void appendClassExtendsImplements(@NotNull StringBuilder buf, @NotNull RefClass refClass);
public abstract void appendDerivedClasses(@NotNull StringBuilder buf, RefClass refClass);
public abstract void appendDerivedClasses(@NotNull StringBuilder buf, @NotNull RefClass refClass);
public abstract void appendLibraryMethods(@NotNull StringBuilder buf, RefClass refClass);
public abstract void appendLibraryMethods(@NotNull StringBuilder buf, @NotNull RefClass refClass);
public abstract void appendSuperMethods(@NotNull StringBuilder buf, RefMethod refMethod);
public abstract void appendSuperMethods(@NotNull StringBuilder buf, @NotNull RefMethod refMethod);
public abstract void appendDerivedMethods(@NotNull StringBuilder buf, RefMethod refMethod);
public abstract void appendDerivedMethods(@NotNull StringBuilder buf, @NotNull RefMethod refMethod);
public abstract void appendTypeReferences(@NotNull StringBuilder buf, RefClass refClass);
public abstract void appendDerivedFunctionalExpressions(@NotNull StringBuilder buf, @NotNull RefMethod refMethod);
public abstract void appendTypeReferences(@NotNull StringBuilder buf, @NotNull RefClass refClass);
@Override
public Key<HTMLJavaHTMLComposer> getID() {

View File

@@ -6,10 +6,11 @@ import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.uast.UClass;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public interface RefClass extends RefJavaElement {
public interface RefClass extends RefJavaElement, RefOverridable {
@NotNull
Set<RefClass> getBaseClasses();
@@ -70,4 +71,14 @@ public interface RefClass extends RefJavaElement {
default PsiClass getElement() {
return ObjectUtils.tryCast(getPsiElement(), PsiClass.class);
}
@Override
default @NotNull Collection<? extends RefOverridable> getDerivedReferences() {
return getSubClasses();
}
@Override
default void addDerivedReference(@NotNull RefOverridable reference) {
// do nothing
}
}

View File

@@ -0,0 +1,32 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.reference;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.uast.UExpression;
import java.util.List;
/**
* A node in the reference graph corresponding to lambda expressions and method references.
*/
public interface RefFunctionalExpression extends RefJavaElement, RefOverridable {
/**
* @return list of parameters of corresponding functional expression
*/
@NotNull
List<RefParameter> getParameters();
/**
* @return expression, which this node is based on
*/
@Override
@Nullable
UExpression getUastElement();
/**
* @return true, if the lambda expression's body is empty, false if not.
* Note that method reference always contains a body.
*/
boolean hasEmptyBody();
}

View File

@@ -28,6 +28,7 @@ public abstract class RefJavaManager implements RefManagerExtension<RefJavaManag
@NonNls static final String PARAMETER = "parameter";
@NonNls static final String JAVA_MODULE = "java.module";
@NonNls public static final String PACKAGE = "package";
static final String FUNCTIONAL_EXPRESSION = "functional.expression";
public static final Key<RefJavaManager> MANAGER = Key.create("RefJavaManager");
@@ -47,13 +48,11 @@ public abstract class RefJavaManager implements RefManagerExtension<RefJavaManag
*
* @param param the parameter for which the reference graph node is requested.
* @param index the index of the parameter in its parameter list.
* @param refMethod
* @param refElement
* @return the node for the element, or null if the element is not valid or does not have
* a corresponding reference graph node type (is not a field, method, class or file).
*/
public abstract RefParameter getParameterReference(UParameter param,
int index,
RefMethod refMethod);
public abstract RefParameter getParameterReference(UParameter param, int index, RefElement refElement);
public abstract RefPackage getDefaultPackage();

View File

@@ -6,16 +6,18 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.uast.UDeclaration;
import org.jetbrains.uast.UElement;
import org.jetbrains.uast.UExpression;
import org.jetbrains.uast.UMethod;
public abstract class RefJavaUtil {
/**
* @deprecated use {@link RefJavaUtil#addReferencesTo} instead
*/
@Deprecated
public abstract void addReferences(@NotNull PsiModifierListOwner psiFrom, @NotNull RefJavaElement ref, @Nullable PsiElement findIn);
public void addReferencesTo(@NotNull UDeclaration decl, @NotNull RefJavaElement ref, UElement @Nullable ... findIn) {
public void addReferencesTo(@NotNull UElement elem, @NotNull RefJavaElement ref, UElement @Nullable ... findIn) {
throw new UnsupportedOperationException("Should be implemented");
}

View File

@@ -40,6 +40,10 @@ public class RefJavaVisitor extends RefVisitor {
visitElement(aClass);
}
public void visitFunctionalExpression(@NotNull RefFunctionalExpression functionalExpression) {
visitElement(functionalExpression);
}
public void visitPackage(@NotNull RefPackage aPackage) {
visitElement(aPackage);
}

View File

@@ -30,7 +30,7 @@ import java.util.Collection;
*
* @author anna
*/
public interface RefMethod extends RefJavaElement {
public interface RefMethod extends RefJavaElement, RefOverridable {
/**
* Returns the collection of the direct super methods of this method in the
* analysis scope.
@@ -170,5 +170,16 @@ public interface RefMethod extends RefJavaElement {
throw new UnsupportedOperationException();
}
@NotNull
@Override
default Collection<? extends RefOverridable> getDerivedReferences() {
return getDerivedMethods();
}
@Override
default void addDerivedReference(@NotNull RefOverridable reference) {
// do nothing
}
boolean isCalledOnSubClass();
}

View File

@@ -0,0 +1,22 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.reference;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* A node in the reference graph corresponding to entities that may contain derived references, e.g. RefMethod.
*/
public interface RefOverridable extends RefJavaElement {
/**
* @return the collection of derived references, e.g. RefMethod may contain at least RefMethod, RefFunctionalExpression as derived reference,
* RefFunctionalExpression contains nothing.
*/
@NotNull Collection<? extends RefOverridable> getDerivedReferences();
/**
* Adds derived reference to collection of derived references.
*/
void addDerivedReference(@NotNull RefOverridable reference);
}