This commit is contained in:
Alexey Kudravtsev
2017-04-14 15:20:30 +03:00
parent 6b248d23f0
commit 8ca9a64189
16 changed files with 96 additions and 186 deletions
@@ -65,7 +65,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
private Set<RefElement> myInTypeReferences;
private Set<RefElement> myInstanceReferences;
private List<RefJavaElement> myClassExporters;
private RefModule myRefModule;
private final RefModule myRefModule;
RefClassImpl(PsiClass psiClass, RefManager manager) {
super(psiClass, manager);
@@ -89,9 +89,10 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
} else if (psiParent instanceof PsiJavaFile) {
PsiJavaFile psiFile = (PsiJavaFile) psiParent;
String packageName = psiFile.getPackageName();
if (!"".equals(packageName)) {
if (!packageName.isEmpty()) {
((RefPackageImpl)getRefJavaManager().getPackage(packageName)).add(this);
} else {
}
else {
((RefPackageImpl)getRefJavaManager().getDefaultPackage()).add(this);
}
}
@@ -373,7 +374,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
return myInTypeReferences;
}
public void addTypeReference(RefJavaElement from) {
void addTypeReference(RefJavaElement from) {
if (from != null) {
if (myInTypeReferences == null){
myInTypeReferences = new THashSet<>(1);
@@ -391,7 +392,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
return myInstanceReferences;
}
public void addInstanceReference(RefElement from) {
void addInstanceReference(RefElement from) {
if (myInstanceReferences == null){
myInstanceReferences = new THashSet<>(1);
}
@@ -410,7 +411,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
myConstructors.add(refConstructor);
}
public void addLibraryOverrideMethod(RefMethod refMethod) {
void addLibraryOverrideMethod(RefMethod refMethod) {
if (myOverridingMethods == null){
myOverridingMethods = new ArrayList<>(2);
}
@@ -457,7 +458,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
@Nullable
public static RefClass classFromExternalName(RefManager manager, String externalName) {
static RefClass classFromExternalName(RefManager manager, String externalName) {
return (RefClass) manager.getReference(ClassUtil.findPsiClass(PsiManager.getInstance(manager.getProject()), externalName));
}
@@ -485,7 +486,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
}
}
protected void methodRemoved(RefMethod method) {
void methodRemoved(RefMethod method) {
getConstructors().remove(method);
getLibraryMethods().remove(method);
@@ -542,7 +543,7 @@ public class RefClassImpl extends RefJavaElementImpl implements RefClass {
return false;
}
public void addClassExporter(RefJavaElement exporter) {
void addClassExporter(RefJavaElement exporter) {
if (myClassExporters == null) myClassExporters = new ArrayList<>(1);
if (myClassExporters.contains(exporter)) return;
myClassExporters.add(exporter);
@@ -142,17 +142,14 @@ public class RefFieldImpl extends RefJavaElementImpl implements RefField {
@Override
public String getExternalName() {
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
PsiField psiField = getElement();
return psiField != null ? PsiFormatUtil.getExternalName(psiField) : null;
}
return ApplicationManager.getApplication().runReadAction((Computable<String>)() -> {
PsiField psiField = getElement();
return psiField != null ? PsiFormatUtil.getExternalName(psiField) : null;
});
}
@Nullable
public static RefField fieldFromExternalName(RefManager manager, String externalName) {
static RefField fieldFromExternalName(RefManager manager, String externalName) {
return (RefField)manager.getReference(findPsiField(PsiManager.getInstance(manager.getProject()), externalName));
}
@@ -161,9 +158,9 @@ public class RefFieldImpl extends RefJavaElementImpl implements RefField {
int classNameDelimiter = externalName.lastIndexOf(' ');
if (classNameDelimiter > 0 && classNameDelimiter < externalName.length() - 1) {
final String className = externalName.substring(0, classNameDelimiter);
final String fieldName = externalName.substring(classNameDelimiter + 1);
final PsiClass psiClass = ClassUtil.findPsiClass(manager, className);
if (psiClass != null) {
final String fieldName = externalName.substring(classNameDelimiter + 1);
return psiClass.findFieldByName(fieldName, false);
}
}
@@ -173,8 +170,7 @@ public class RefFieldImpl extends RefJavaElementImpl implements RefField {
@Override
public boolean isSuspicious() {
if (isEntry()) return false;
if (super.isSuspicious()) return true;
return isUsedForReading() != isUsedForWriting();
return super.isSuspicious() || isUsedForReading() != isUsedForWriting();
}
@Override
@@ -63,12 +63,7 @@ public class RefImplicitConstructorImpl extends RefMethodImpl implements RefImpl
@Override
public boolean isValid() {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return getOwnerClass().isValid();
}
}).booleanValue();
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>)getOwnerClass()::isValid).booleanValue();
}
@Override
@@ -59,10 +59,6 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
}
}
protected RefJavaElementImpl(PsiFile file, RefManager manager) {
super(file, manager);
}
protected RefJavaElementImpl(PsiModifierListOwner elem, RefManager manager) {
super(getName(elem), elem, manager);
@@ -85,7 +81,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
return myOutTypeReferences;
}
public void addOutTypeRefernce(RefClass refClass){
void addOutTypeRefernce(RefClass refClass){
if (myOutTypeReferences == null){
myOutTypeReferences = new THashSet<>();
}
@@ -137,7 +133,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
return checkFlag(IS_USES_DEPRECATION_MASK);
}
public void setUsesDeprecatedApi(boolean usesDeprecatedApi) {
void setUsesDeprecatedApi(boolean usesDeprecatedApi) {
setFlag(usesDeprecatedApi, IS_USES_DEPRECATION_MASK);
}
@@ -154,7 +150,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
return checkFlag(IS_SYNTHETIC_JSP_ELEMENT_MASK);
}
public void setSyntheticJSP(boolean b) {
private void setSyntheticJSP(boolean b) {
setFlag(b, IS_SYNTHETIC_JSP_ELEMENT_MASK);
}
@@ -262,7 +258,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
getRefManager().fireNodeMarkedReferenced(this, refFrom, false, forReading, forWriting);
}
protected void setUsedQualifiedOutsidePackageFlag(RefElementImpl refFrom, PsiReferenceExpression expressionFrom) {
void setUsedQualifiedOutsidePackageFlag(RefElementImpl refFrom, PsiReferenceExpression expressionFrom) {
if (!checkFlag(IS_USED_QUALIFIED_OUTSIDE_PACKAGE_MASK) && expressionFrom != null &&
expressionFrom.isQualified() && RefJavaUtil.getPackage(refFrom) != RefJavaUtil.getPackage(this)) {
setFlag(true, IS_USED_QUALIFIED_OUTSIDE_PACKAGE_MASK);
@@ -273,7 +269,7 @@ public abstract class RefJavaElementImpl extends RefElementImpl implements RefJa
return checkFlag(IS_USED_QUALIFIED_OUTSIDE_PACKAGE_MASK);
}
protected RefJavaManager getRefJavaManager() {
RefJavaManager getRefJavaManager() {
return getRefManager().getExtension(RefJavaManager.MANAGER);
}
@@ -15,10 +15,7 @@
*/
package com.intellij.codeInspection.reference;
import com.intellij.codeInspection.BatchSuppressManager;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.SuppressionUtil;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase;
import com.intellij.codeInspection.ex.*;
import com.intellij.openapi.diagnostic.Logger;
@@ -119,10 +116,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
if (tool.isTestEntryPoints()) return true;
final PsiElement element = refElement.getElement();
final VirtualFile file = PsiUtilCore.getVirtualFile(element);
if (file != null) {
return !ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInTestSourceContent(file);
}
return false;
return file != null && !ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInTestSourceContent(file);
}
@Nullable
@@ -250,7 +244,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
if (elem instanceof PsiClass) {
return new RefClassImpl((PsiClass)elem, myRefManager);
}
else if (elem instanceof PsiMethod) {
if (elem instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)elem;
final RefElement ref = myRefManager.getReference(method.getContainingClass(), true);
if (ref instanceof RefClass) {
@@ -268,7 +262,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
return new RefJavaFileImpl((PsiJavaFile)elem, myRefManager);
}
else if (elem instanceof PsiJavaModule) {
return new RefJavaModuleImpl(((PsiJavaModule)elem), myRefManager);
return new RefJavaModuleImpl((PsiJavaModule)elem, myRefManager);
}
return null;
}
@@ -282,16 +276,16 @@ public class RefJavaManagerImpl extends RefJavaManager {
if (METHOD.equals(type)) {
return RefMethodImpl.methodFromExternalName(myRefManager, fqName);
}
else if (CLASS.equals(type)) {
if (CLASS.equals(type)) {
return RefClassImpl.classFromExternalName(myRefManager, fqName);
}
else if (FIELD.equals(type)) {
if (FIELD.equals(type)) {
return RefFieldImpl.fieldFromExternalName(myRefManager, fqName);
}
else if (PARAMETER.equals(type)) {
if (PARAMETER.equals(type)) {
return RefParameterImpl.parameterFromExternalName(myRefManager, fqName);
}
else if (PACKAGE.equals(type)) {
if (PACKAGE.equals(type)) {
return RefPackageImpl.packageFromFQName(myRefManager, fqName);
}
return null;
@@ -303,22 +297,22 @@ public class RefJavaManagerImpl extends RefJavaManager {
if (ref instanceof RefImplicitConstructor) {
return IMPLICIT_CONSTRUCTOR;
}
else if (ref instanceof RefMethod) {
if (ref instanceof RefMethod) {
return METHOD;
}
else if (ref instanceof RefClass) {
if (ref instanceof RefClass) {
return CLASS;
}
else if (ref instanceof RefField) {
if (ref instanceof RefField) {
return FIELD;
}
else if (ref instanceof RefParameter) {
if (ref instanceof RefParameter) {
return PARAMETER;
}
else if (ref instanceof RefPackage) {
if (ref instanceof RefPackage) {
return PACKAGE;
}
else if (ref instanceof RefJavaModule) {
if (ref instanceof RefJavaModule) {
return JAVA_MODULE;
}
return null;
@@ -372,21 +366,6 @@ public class RefJavaManagerImpl extends RefJavaManager {
if (isEntryPoint(refElement)) {
getEntryPointsManager().addEntryPoint(refElement, false);
}
/*if (psiElement instanceof PsiClass) {
PsiClass psiClass = (PsiClass)psiElement;
EntryPointsManager entryPointsManager = getEntryPointsManager();
if (psiClass.isAnnotationType()){
entryPointsManager.addEntryPoint(refElement, false);
for (PsiMethod psiMethod : psiClass.getMethods()) {
entryPointsManager.addEntryPoint(myRefManager.getReference(psiMethod), false);
}
}
else if (psiClass.isEnum()) {
entryPointsManager.addEntryPoint(refElement, false);
}
}*/
}
private static void appendPackageElement(final Element element, final String packageName) {
@@ -420,7 +399,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
private class MyJavaElementVisitor extends JavaElementVisitor {
private final RefJavaUtil myRefUtil;
public MyJavaElementVisitor() {
MyJavaElementVisitor() {
myRefUtil = RefJavaUtil.getInstance();
}
@@ -488,9 +467,9 @@ public class RefJavaManagerImpl extends RefJavaManager {
super.visitDocComment(comment);
final PsiDocTag[] tags = comment.getTags();
for (PsiDocTag tag : tags) {
if (Comparing.strEqual(tag.getName(), SuppressionUtil.SUPPRESS_INSPECTIONS_TAG_NAME)) {
if (Comparing.strEqual(tag.getName(), SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME)) {
final PsiElement[] dataElements = tag.getDataElements();
if (dataElements != null && dataElements.length > 0) {
if (dataElements.length > 0) {
final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(comment, PsiModifierListOwner.class);
if (listOwner != null) {
final RefElementImpl element = (RefElementImpl)myRefManager.getReference(listOwner);
@@ -37,7 +37,7 @@ public class RefJavaModuleImpl extends RefElementImpl implements RefJavaModule {
private Map<String, List<String>> myExportedPackageNames;
private List<RequiredModule> myRequiredModules;
public RefJavaModuleImpl(@NotNull PsiJavaModule javaModule, @NotNull RefManagerImpl manager) {
RefJavaModuleImpl(@NotNull PsiJavaModule javaModule, @NotNull RefManagerImpl manager) {
super(javaModule.getName(), javaModule, manager);
myRefModule = manager.getRefModule(ModuleUtilCore.findModuleForPsiElement(javaModule));
}
@@ -75,6 +75,7 @@ public class RefJavaModuleImpl extends RefElementImpl implements RefJavaModule {
return myExportedPackageNames != null ? myExportedPackageNames : Collections.emptyMap();
}
@Override
@NotNull
public List<RequiredModule> getRequiredModules() {
return myRequiredModules != null ? myRequiredModules : Collections.emptyList();
@@ -146,7 +146,7 @@ public class RefJavaUtilImpl extends RefJavaUtil{
}
final Collection<PsiClassType> exceptionTypes = body != null ? ExceptionUtil.collectUnhandledExceptions(body, topElement, false)
: Collections.<PsiClassType>emptyList();
: Collections.emptyList();
RefElement refResolved = refFrom.getRefManager().getReference(interfaceMethod);
if (refResolved instanceof RefMethodImpl) {
for (final PsiClassType exceptionType : exceptionTypes) {
@@ -301,7 +301,7 @@ public class RefJavaUtilImpl extends RefJavaUtil{
public RefClass getTopLevelClass(@NotNull RefElement refElement) {
RefEntity refParent = refElement.getOwner();
while (refParent != null && refParent instanceof RefElement && !(refParent instanceof RefFile)) {
while (refParent instanceof RefElement && !(refParent instanceof RefFile)) {
refElement = (RefElementImpl)refParent;
refParent = refParent.getOwner();
}
@@ -458,13 +458,13 @@ public class RefJavaUtilImpl extends RefJavaUtil{
if (a == PsiModifier.PRIVATE) {
return 0;
}
else if (a == PsiModifier.PACKAGE_LOCAL) {
if (a == PsiModifier.PACKAGE_LOCAL) {
return 1;
}
else if (a == PsiModifier.PROTECTED) {
if (a == PsiModifier.PROTECTED) {
return 2;
}
else if (a == PsiModifier.PUBLIC) return 3;
if (a == PsiModifier.PUBLIC) return 3;
return -1;
}
@@ -88,7 +88,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
public List<RefEntity> getChildren() {
List<RefEntity> superChildren = super.getChildren();
if (myParameters == null) return superChildren;
if (superChildren.isEmpty()) return Arrays.<RefEntity>asList(myParameters);
if (superChildren.isEmpty()) return Arrays.asList(myParameters);
List<RefEntity> allChildren = new ArrayList<>(superChildren.size() + myParameters.length);
allChildren.addAll(superChildren);
@@ -426,17 +426,13 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
if (psiMethod instanceof SyntheticElement) {
return psiMethod.getName();
}
else {
return PsiFormatUtil.formatMethod(psiMethod,
PsiSubstitutor.EMPTY,
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
PsiFormatUtilBase.SHOW_TYPE
);
}
return PsiFormatUtil.formatMethod(psiMethod,
PsiSubstitutor.EMPTY,
PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
PsiFormatUtilBase.SHOW_TYPE);
});
} else {
return super.getName();
}
return super.getName();
}
@Override
@@ -449,7 +445,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
}
@Nullable
public static RefMethod methodFromExternalName(RefManager manager, String externalName) {
static RefMethod methodFromExternalName(RefManager manager, String externalName) {
return (RefMethod) manager.getReference(findPsiMethod(PsiManager.getInstance(manager.getProject()), externalName));
}
@@ -498,7 +494,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
return super.isSuspicious();
}
public void setReturnValueUsed(boolean value) {
void setReturnValueUsed(boolean value) {
if (checkFlag(IS_RETURN_VALUE_USED_MASK) == value) return;
setFlag(value, IS_RETURN_VALUE_USED_MASK);
for (RefMethod refSuper : getSuperMethods()) {
@@ -511,7 +507,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
return checkFlag(IS_RETURN_VALUE_USED_MASK);
}
public void updateReturnValueTemplate(PsiExpression expression) {
void updateReturnValueTemplate(PsiExpression expression) {
if (myReturnValueTemplate == null) return;
if (!getSuperMethods().isEmpty()) {
@@ -549,7 +545,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
}
}
public void updateParameterValues(PsiExpression[] args) {
void updateParameterValues(PsiExpression[] args) {
if (isExternalOverride()) return;
if (!getSuperMethods().isEmpty()) {
@@ -560,12 +556,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
final RefParameter[] params = getParameters();
if (params.length <= args.length && params.length > 0) {
for (int i = 0; i < args.length; i++) {
RefParameter refParameter;
if (params.length <= i){
refParameter = params[params.length - 1];
} else {
refParameter = params[i];
}
RefParameter refParameter = params.length <= i ? params[params.length - 1] : params[i];
((RefParameterImpl)refParameter).updateTemplateValue(args[i]);
}
}
@@ -667,12 +658,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
return checkFlag(IS_CALLED_ON_SUBCLASS_MASK);
}
public void setCalledOnSubClass(boolean isCalledOnSubClass){
void setCalledOnSubClass(boolean isCalledOnSubClass){
setFlag(isCalledOnSubClass, IS_CALLED_ON_SUBCLASS_MASK);
}
private static String extractMethodName(String methodSignature) {
final String returnTypeAndName = methodSignature.substring(0, methodSignature.indexOf('('));
return returnTypeAndName.substring(returnTypeAndName.indexOf(' ') + 1);
}
}
@@ -32,7 +32,7 @@ import javax.swing.*;
public class RefPackageImpl extends RefEntityImpl implements RefPackage {
public RefPackageImpl(@NotNull String name, @NotNull RefManager refManager) {
RefPackageImpl(@NotNull String name, @NotNull RefManager refManager) {
super(name, refManager);
}
@@ -45,7 +45,7 @@ public class RefPackageImpl extends RefEntityImpl implements RefPackage {
}
}
public static RefEntity packageFromFQName(final RefManager manager, final String name) {
static RefEntity packageFromFQName(final RefManager manager, final String name) {
return manager.getExtension(RefJavaManager.MANAGER).getPackage(name);
}
@@ -28,6 +28,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiFormatUtil;
import com.intellij.psi.util.PsiFormatUtilBase;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -106,7 +107,7 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter
}
}
public void updateTemplateValue(PsiExpression expression) {
void updateTemplateValue(PsiExpression expression) {
if (myActualValueTemplate == null) return;
String newTemplate = null;
@@ -121,14 +122,16 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter
if (psiField.hasModifierProperty(PsiModifier.STATIC) &&
psiField.hasModifierProperty(PsiModifier.FINAL) &&
psiField.getContainingClass().getQualifiedName() != null) {
newTemplate = PsiFormatUtil.formatVariable(psiField, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, PsiSubstitutor.EMPTY);
newTemplate = PsiFormatUtil.formatVariable(psiField, PsiFormatUtilBase.SHOW_NAME |
PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_FQ_NAME, PsiSubstitutor.EMPTY);
}
}
}
if (myActualValueTemplate == VALUE_UNDEFINED) {
myActualValueTemplate = newTemplate;
} else if (!Comparing.equal(myActualValueTemplate, newTemplate)) {
}
else if (!Comparing.equal(myActualValueTemplate, newTemplate)) {
myActualValueTemplate = null;
}
}
@@ -158,10 +161,9 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter
}
@Nullable
public static RefElement parameterFromExternalName(final RefManager manager, final String fqName) {
static RefElement parameterFromExternalName(final RefManager manager, final String fqName) {
final int idx = fqName.lastIndexOf(' ');
if (idx > 0) {
final String paramName = fqName.substring(idx + 1);
final String method = fqName.substring(0, idx);
final RefMethod refMethod = RefMethodImpl.methodFromExternalName(manager, method);
if (refMethod != null) {
@@ -169,6 +171,7 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter
final PsiParameterList list = element.getParameterList();
final PsiParameter[] parameters = list.getParameters();
int paramIdx = 0;
final String paramName = fqName.substring(idx + 1);
for (PsiParameter parameter : parameters) {
final String name = parameter.getName();
if (name != null && name.equals(paramName)) {
@@ -180,25 +183,4 @@ public class RefParameterImpl extends RefJavaElementImpl implements RefParameter
}
return null;
}
@Nullable
public static PsiParameter findPsiParameter(String fqName, final PsiManager manager) {
final int idx = fqName.lastIndexOf(' ');
if (idx > 0) {
final String paramName = fqName.substring(idx + 1);
final String method = fqName.substring(0, idx);
final PsiMethod psiMethod = RefMethodImpl.findPsiMethod(manager, method);
if (psiMethod != null) {
final PsiParameterList list = psiMethod.getParameterList();
final PsiParameter[] parameters = list.getParameters();
for (PsiParameter parameter : parameters) {
final String name = parameter.getName();
if (name != null && name.equals(paramName)) {
return parameter;
}
}
}
}
return null;
}
}
@@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull;
* @author Dmitry Avdeev
* Date: 1/19/12
*/
@FunctionalInterface
public interface UnusedDeclarationFixProvider {
ExtensionPointName<UnusedDeclarationFixProvider> EP_NAME = ExtensionPointName.create("com.intellij.unusedDeclarationFixProvider");
@@ -56,7 +56,7 @@ public abstract class RefElementImpl extends RefEntityImpl implements RefElement
private List<RefElement> myOutReferences;
private List<RefElement> myInReferences;
private String[] mySuppressions = null;
private String[] mySuppressions;
private boolean myIsDeleted ;
protected static final int IS_REACHABLE_MASK = 0x40;
@@ -64,7 +64,7 @@ public class RefFileImpl extends RefElementImpl implements RefFile {
}
@Nullable
public static RefElement fileFromExternalName(final RefManager manager, final String fqName) {
static RefElement fileFromExternalName(final RefManager manager, final String fqName) {
final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(PathMacroManager.getInstance(manager.getProject()).expandPath(fqName));
if (virtualFile != null) {
final PsiFile psiFile = PsiManager.getInstance(manager.getProject()).findFile(virtualFile);
@@ -118,7 +118,7 @@ public class RefManagerImpl extends RefManager {
}
}
public String internName(@NotNull String name) {
String internName(@NotNull String name) {
synchronized (myNameInterner) {
return myNameInterner.intern(name);
}
@@ -167,31 +167,31 @@ public class RefManagerImpl extends RefManager {
}
public void fireNodeInitialized(RefElement refElement) {
private void fireNodeInitialized(RefElement refElement) {
for (RefGraphAnnotator annotator : myGraphAnnotators) {
annotator.onInitialize(refElement);
}
}
public void fireNodeMarkedReferenced(RefElement refWhat,
RefElement refFrom,
boolean referencedFromClassInitializer,
final boolean forReading,
final boolean forWriting) {
void fireNodeMarkedReferenced(RefElement refWhat,
RefElement refFrom,
boolean referencedFromClassInitializer,
final boolean forReading,
final boolean forWriting) {
for (RefGraphAnnotator annotator : myGraphAnnotators) {
annotator.onMarkReferenced(refWhat, refFrom, referencedFromClassInitializer, forReading, forWriting);
}
}
public void fireNodeMarkedReferenced(PsiElement what,
PsiElement from,
boolean referencedFromClassInitializer) {
void fireNodeMarkedReferenced(PsiElement what,
PsiElement from,
boolean referencedFromClassInitializer) {
for (RefGraphAnnotator annotator : myGraphAnnotators) {
annotator.onMarkReferenced(what, from, referencedFromClassInitializer);
}
}
public void fireBuildReferences(RefElement refElement) {
void fireBuildReferences(RefElement refElement) {
for (RefGraphAnnotator annotator : myGraphAnnotators) {
annotator.onReferencesBuild(refElement);
}
@@ -311,11 +311,11 @@ public class RefManagerImpl extends RefManager {
if (groupName != null) return groupName;
}
final LinkedList<String> containingDirs = new LinkedList<>();
RefEntity parent = entity.getOwner();
while (parent != null && !(parent instanceof RefDirectory)) {
parent = parent.getOwner();
}
final LinkedList<String> containingDirs = new LinkedList<>();
while (parent instanceof RefDirectory) {
containingDirs.addFirst(parent.getName());
parent = parent.getOwner();
@@ -365,7 +365,7 @@ public class RefManagerImpl extends RefManager {
myOfflineView = true;
}
public boolean isOfflineView() {
boolean isOfflineView() {
return myOfflineView;
}
@@ -386,7 +386,7 @@ public class RefManagerImpl extends RefManager {
}
@NotNull
public List<RefElement> getSortedElements() {
List<RefElement> getSortedElements() {
List<RefElement> answer;
synchronized (myRefTableLock) {
if (mySortedRefs != null) return mySortedRefs;
@@ -447,12 +447,7 @@ public class RefManagerImpl extends RefManager {
@NotNull
private static PsiAnchor createAnchor(@NotNull final PsiElement element) {
return ApplicationManager.getApplication().runReadAction(
new Computable<PsiAnchor>() {
@Override
public PsiAnchor compute() {
return PsiAnchor.create(element);
}
}
(Computable<PsiAnchor>)() -> PsiAnchor.create(element)
);
}
@@ -501,13 +496,8 @@ public class RefManagerImpl extends RefManager {
@Nullable
public RefElement getReference(final PsiElement elem, final boolean ignoreScope) {
if (ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return elem == null || !elem.isValid() ||
elem instanceof LightElement || !(elem instanceof PsiDirectory) && !belongsToScope(elem, ignoreScope);
}
})) {
if (ApplicationManager.getApplication().runReadAction((Computable<Boolean>)() -> elem == null || !elem.isValid() ||
elem instanceof LightElement || !(elem instanceof PsiDirectory) && !belongsToScope(elem, ignoreScope))) {
return null;
}
@@ -572,12 +562,12 @@ public class RefManagerImpl extends RefManager {
}
@Nullable
protected <T extends RefElement> T getFromRefTableOrCache(final PsiElement element, @NotNull NullableFactory<T> factory) {
<T extends RefElement> T getFromRefTableOrCache(final PsiElement element, @NotNull NullableFactory<T> factory) {
return getFromRefTableOrCache(element, factory, null);
}
@Nullable
private <T extends RefElement> T getFromRefTableOrCache(final PsiElement element,
private <T extends RefElement> T getFromRefTableOrCache(@NotNull PsiElement element,
@NotNull NullableFactory<T> factory,
@Nullable Consumer<T> whenCached) {
@@ -632,24 +622,15 @@ public class RefManagerImpl extends RefManager {
private boolean belongsToScope(final PsiElement psiElement, final boolean ignoreScope) {
if (psiElement == null || !psiElement.isValid()) return false;
if (psiElement instanceof PsiCompiledElement) return false;
final PsiFile containingFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@Override
public PsiFile compute() {
return psiElement.getContainingFile();
}
});
final PsiFile containingFile = ApplicationManager.getApplication().runReadAction((Computable<PsiFile>)psiElement::getContainingFile);
if (containingFile == null) {
return false;
}
for (RefManagerExtension extension : myExtensions.values()) {
if (!extension.belongsToScope(psiElement)) return false;
}
final Boolean inProject = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return psiElement.getManager().isInProject(psiElement);
}
});
final Boolean inProject = ApplicationManager.getApplication().runReadAction(
(Computable<Boolean>)() -> psiElement.getManager().isInProject(psiElement));
return inProject.booleanValue() && (ignoreScope || getScope() == null || getScope().contains(psiElement));
}
@@ -675,7 +656,7 @@ public class RefManagerImpl extends RefManager {
if (!deletedRefs.contains(refElement)) deletedRefs.add(refElement);
}
protected boolean isValidPointForReference() {
boolean isValidPointForReference() {
return myIsInProcess || myOfflineView || ApplicationManager.getApplication().isUnitTestMode();
}
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
public class RefProjectImpl extends RefEntityImpl implements RefProject {
public RefProjectImpl(@NotNull RefManager refManager) {
RefProjectImpl(@NotNull RefManager refManager) {
super(refManager.getProject().getName(), refManager);
}
@@ -58,13 +58,6 @@ public class SmartRefElementPointerImpl implements SmartRefElementPointer {
myType = type;
}
public SmartRefElementPointerImpl(final String type, final String fqName, final RefManager manager) {
myIsPersistent = false;
myFQName = fqName;
myType = type;
resolve(manager);
}
@Override
public boolean isPersistent() {
return myIsPersistent;
@@ -91,8 +84,7 @@ public class SmartRefElementPointerImpl implements SmartRefElementPointer {
@Override
public boolean resolve(@NotNull RefManager manager) {
if (myRefElement != null) {
if (myRefElement instanceof RefElement && myRefElement.isValid()) return true;
return false;
return myRefElement instanceof RefElement && myRefElement.isValid();
}
myRefElement = manager.getReference(myType, getFQName());
return myRefElement != null;