Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import consulo.annotation.component.ComponentScope;
import consulo.annotation.component.ExtensionAPI;
import consulo.component.extension.ExtensionPointName;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

Expand Down Expand Up @@ -60,12 +59,7 @@ public abstract class DocumentationDelegateProvider {

@Nullable
public static PsiDocCommentOwner findDocumentationDelegate(@Nonnull PsiMember method) {
for (DocumentationDelegateProvider delegator : EP_NAME.getExtensionList()) {
PsiDocCommentOwner type = delegator.computeDocumentationDelegate(method);
if (type != null) {
return type;
}
}
return null;
return method.getApplication().getExtensionPoint(DocumentationDelegateProvider.class)
.computeSafeIfAny(delegator -> delegator.computeDocumentationDelegate(method));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ public abstract class VariableTypeCalculator {
*/
@Nonnull
public static PsiType getVarTypeAt(@Nonnull PsiVariable var, @Nonnull PsiElement place) {
for (VariableTypeCalculator calculator : EP_NAME.getExtensionList()) {
PsiType type = calculator.inferVarTypeAt(var, place);
if (type != null) {
return type;
}
}

return var.getType();
PsiType varType = var.getApplication().getExtensionPoint(VariableTypeCalculator.class)
.computeSafeIfAny(calculator -> calculator.inferVarTypeAt(var, place));
return varType != null ? varType : var.getType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ private static LocalQuickFix[] getChangeVariableTypeFixes(
LOG.assertTrue(parameter.isValid());
List<LocalQuickFix> result = new ArrayList<>();
if (itemType != null) {
for (ChangeVariableTypeQuickFixProvider fixProvider : ChangeVariableTypeQuickFixProvider.EP_NAME.getExtensionList()) {
parameter.getApplication().getExtensionPoint(ChangeVariableTypeQuickFixProvider.class).forEach(fixProvider -> {
for (IntentionAction action : fixProvider.getFixes(parameter, itemType)) {
if (action instanceof LocalQuickFix fix) {
result.add(fix);
}
}
}
});
}

if (generifyFixes.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.application.Application;
import consulo.java.deadCodeNotWorking.OldStyleInspection;
import consulo.language.editor.FileModificationService;
import consulo.language.editor.IdentifierUtil;
Expand All @@ -54,19 +55,14 @@
import consulo.project.Project;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.inject.Inject;

import javax.swing.*;
import java.awt.*;
import java.util.List;

@ExtensionImpl
public class VisibilityInspection extends GlobalJavaInspectionTool implements OldStyleInspection {
private static final Logger LOG = Logger.getInstance(VisibilityInspection.class);
public boolean SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = true;
public boolean SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = true;
public boolean SUGGEST_PRIVATE_FOR_INNERS = false;
private static final String SHORT_NAME = "WeakerAccess";

private class OptionsPanel extends JPanel {
private final JCheckBox myPackageLocalForMembersCheckbox;
private final JCheckBox myPrivateForInnersCheckbox;
Expand Down Expand Up @@ -109,6 +105,19 @@ private OptionsPanel() {
}
}

private static final Logger LOG = Logger.getInstance(VisibilityInspection.class);
private static final String SHORT_NAME = "WeakerAccess";

private final Application myApplication;
public boolean SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS = true;
public boolean SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES = true;
public boolean SUGGEST_PRIVATE_FOR_INNERS = false;

@Inject
public VisibilityInspection(Application application) {
myApplication = application;
}

@Override
public JComponent createOptionsPanel() {
return new OptionsPanel();
Expand Down Expand Up @@ -459,9 +468,8 @@ protected boolean queryExternalUsagesRequests(
ignoreElement(processor, entryPoint);
}

for (VisibilityExtension addin : VisibilityExtension.EP_NAME.getExtensions()) {
addin.fillIgnoreList(manager, processor);
}
myApplication.getExtensionPoint(VisibilityExtension.class)
.forEach(addin -> addin.fillIgnoreList(manager, processor));
manager.iterate(new RefJavaVisitor() {
@Override
public void visitElement(@Nonnull RefEntity refEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,8 @@ private static PsiClass getSubjectClass(Editor editor, PsiFile file) {
}

//exclude interfaces, non-java classes etc
for (GenerateToStringClassFilter filter : GenerateToStringClassFilter.EP_NAME.getExtensionList()) {
if (!filter.canGenerateToString(clazz)) {
return null;
}
}
return clazz;
return file.getApplication().getExtensionPoint(GenerateToStringClassFilter.class)
.allMatchSafe(filter -> filter.canGenerateToString(clazz)) ? clazz : null;
}

public static class MemberChooserHeaderPanel extends JPanel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import consulo.ui.ex.tree.PresentationData;
import consulo.ui.image.Image;
import consulo.virtualFileSystem.VirtualFile;

import jakarta.annotation.Nonnull;

import java.util.ArrayList;
import java.util.Collection;

public abstract class BaseSmartPointerPsiNode<Type extends SmartPsiElementPointer> extends ProjectViewNode<Type> implements
PsiElementNavigationItem {
public abstract class BaseSmartPointerPsiNode<Type extends SmartPsiElementPointer> extends ProjectViewNode<Type>
implements PsiElementNavigationItem {
private static final Logger LOG = Logger.getInstance(BaseSmartPointerPsiNode.class);

protected BaseSmartPointerPsiNode(Project project, Type value, ViewSettings viewSettings) {
Expand Down Expand Up @@ -112,9 +111,8 @@ public void update(PresentationData data) {
data.setAttributesKey(CodeInsightColors.DEPRECATED_ATTRIBUTES);
}
updateImpl(data);
for (ProjectViewNodeDecorator decorator : ProjectViewNodeDecorator.EP_NAME.getExtensionList(myProject)) {
decorator.decorate(this, data);
}
value.getProject().getExtensionPoint(ProjectViewNodeDecorator.class)
.forEach(decorator -> decorator.decorate(this, data));
}

private boolean isDeprecated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import consulo.module.content.layer.orderEntry.DependencyScope;
import consulo.project.Project;
import consulo.util.concurrent.AsyncResult;
import jakarta.annotation.Nonnull;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import jakarta.annotation.Nonnull;

import java.util.Collection;

/**
Expand All @@ -38,22 +37,19 @@
@Singleton
@ServiceImpl
public class JavaProjectModelModificationServiceImpl extends JavaProjectModelModificationService {
@Nonnull
private final Project myProject;

@Inject
public JavaProjectModelModificationServiceImpl(Project project) {
public JavaProjectModelModificationServiceImpl(@Nonnull Project project) {
myProject = project;
}

@Override
public AsyncResult<Void> addDependency(@Nonnull Module from, @Nonnull Module to, @Nonnull DependencyScope scope) {
for (JavaProjectModelModifier modifier : getModelModifiers()) {
AsyncResult<Void> asyncResult = modifier.addModuleDependency(from, to, scope);
if (asyncResult != null) {
return asyncResult;
}
}
return AsyncResult.rejected();
AsyncResult<Void> asyncResult = myProject.getExtensionPoint(JavaProjectModelModifier.class)
.computeSafeIfAny(modifier -> modifier.addModuleDependency(from, to, scope));
return asyncResult != null ? asyncResult : AsyncResult.rejected();
}

@Override
Expand All @@ -62,39 +58,22 @@ public AsyncResult<Void> addDependency(
@Nonnull ExternalLibraryDescriptor libraryDescriptor,
@Nonnull DependencyScope scope
) {
for (JavaProjectModelModifier modifier : getModelModifiers()) {
AsyncResult<Void> asyncResult = modifier.addExternalLibraryDependency(from, libraryDescriptor, scope);
if (asyncResult != null) {
return asyncResult;
}
}
return AsyncResult.rejected();
AsyncResult<Void> asyncResult = myProject.getExtensionPoint(JavaProjectModelModifier.class)
.computeSafeIfAny(modifier -> modifier.addExternalLibraryDependency(from, libraryDescriptor, scope));
return asyncResult != null ? asyncResult : AsyncResult.rejected();
}

@Override
public AsyncResult<Void> addDependency(@Nonnull Module from, @Nonnull Library library, @Nonnull DependencyScope scope) {
for (JavaProjectModelModifier modifier : getModelModifiers()) {
AsyncResult<Void> asyncResult = modifier.addLibraryDependency(from, library, scope);
if (asyncResult != null) {
return asyncResult;
}
}
return AsyncResult.rejected();
AsyncResult<Void> asyncResult = myProject.getExtensionPoint(JavaProjectModelModifier.class)
.computeSafeIfAny(modifier -> modifier.addLibraryDependency(from, library, scope));
return asyncResult != null ? asyncResult : AsyncResult.rejected();
}

@Override
public AsyncResult<Void> changeLanguageLevel(@Nonnull Module module, @Nonnull LanguageLevel languageLevel) {
for (JavaProjectModelModifier modifier : getModelModifiers()) {
AsyncResult<Void> asyncResult = modifier.changeLanguageLevel(module, languageLevel);
if (asyncResult != null) {
return asyncResult;
}
}
return AsyncResult.rejected();
}

@Nonnull
private JavaProjectModelModifier[] getModelModifiers() {
return JavaProjectModelModifier.EP_NAME.getExtensions(myProject);
AsyncResult<Void> asyncResult = myProject.getExtensionPoint(JavaProjectModelModifier.class)
.computeSafeIfAny(modifier -> modifier.changeLanguageLevel(module, languageLevel));
return asyncResult != null ? asyncResult : AsyncResult.rejected();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public SearchScope getAdditionalResolveScope(@Nonnull VirtualFile file, Project

FileType fileType = file.getFileType();
if (fileType == JavaFileType.INSTANCE || fileType == JavaClassFileType.INSTANCE) {
for (PsiElementFinder finder : PsiElementFinder.EP_NAME.getExtensionList(project)) {
return project.getExtensionPoint(PsiElementFinder.class).computeSafeIfAny(finder -> {
if (finder instanceof NonClasspathClassFinder nonClasspathClassFinder) {
List<VirtualFile> roots = nonClasspathClassFinder.getClassRoots();
for (VirtualFile root : roots) {
Expand All @@ -40,7 +40,8 @@ public SearchScope getAdditionalResolveScope(@Nonnull VirtualFile file, Project
}
}
}
}
return null;
});
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.intellij.java.language.psi.*;
import com.intellij.java.language.psi.util.*;
import com.intellij.java.language.util.VisibilityUtil;
import consulo.component.extension.ExtensionPoint;
import consulo.java.impl.refactoring.changeSignature.ChangeSignatureUsageProcessorEx;
import consulo.language.codeStyle.CodeStyleManager;
import consulo.language.editor.refactoring.changeSignature.ChangeSignatureProcessorBase;
Expand Down Expand Up @@ -185,14 +186,19 @@ protected void refreshElements(PsiElement[] elements) {
@Override
@RequiredUIAccess
protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsages) {
for (ChangeSignatureUsageProcessor processor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
if (processor instanceof ChangeSignatureUsageProcessorEx changeSignatureUsageProcessorEx
&& changeSignatureUsageProcessorEx.setupDefaultValues(myChangeInfo, refUsages, myProject)) {
return false;
}
ExtensionPoint<ChangeSignatureUsageProcessor> extensionPoint =
myProject.getApplication().getExtensionPoint(ChangeSignatureUsageProcessor.class);

boolean defaultValuesSet = extensionPoint.noneMatchSafe(
processor -> processor instanceof ChangeSignatureUsageProcessorEx changeSignatureUsageProcessorEx
&& changeSignatureUsageProcessorEx.setupDefaultValues(myChangeInfo, refUsages, myProject)
);
if (defaultValuesSet) {
return false;
}

MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
for (ChangeSignatureUsageProcessor usageProcessor : ChangeSignatureUsageProcessor.EP_NAME.getExtensions()) {
extensionPoint.forEach(usageProcessor -> {
MultiMap<PsiElement, String> conflicts = usageProcessor.findConflicts(myChangeInfo, refUsages);
for (PsiElement key : conflicts.keySet()) {
Collection<String> collection = conflictDescriptions.get(key);
Expand All @@ -202,7 +208,7 @@ protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsag
collection.addAll(conflicts.get(key));
conflictDescriptions.put(key, collection);
}
}
});

UsageInfo[] usagesIn = refUsages.get();
RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ protected boolean preprocessUsages(SimpleReference<UsageInfo[]> refUsages) {
}
}

for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
processor.findConflicts(this, refUsages.get(), conflicts);
}
myProject.getApplication().getExtensionPoint(IntroduceParameterMethodUsagesProcessor.class)
.forEach(processor -> processor.findConflicts(this, refUsages.get(), conflicts));

myHasConflicts = !conflicts.isEmpty();
return showConflicts(conflicts, usagesIn);
Expand Down
Loading