Skip to content

Commit

Permalink
chore: apply spotless plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjedynak committed Feb 17, 2024
1 parent 8adbcba commit ed7ba5e
Show file tree
Hide file tree
Showing 77 changed files with 1,738 additions and 1,248 deletions.
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("org.jetbrains.intellij") version "1.17.1"
id("com.diffplug.spotless") version "6.25.0"
}

group = "pl.mjedynak"
Expand Down Expand Up @@ -43,3 +44,10 @@ tasks {
gradleVersion = "8.6"
}
}

spotless {
java {
palantirJavaFormat()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

import com.intellij.codeInsight.navigation.GotoTargetHandler;

public abstract class AbstractBuilderAdditionalAction implements GotoTargetHandler.AdditionalAction {

}
public abstract class AbstractBuilderAdditionalAction implements GotoTargetHandler.AdditionalAction {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GenerateBuilderAction extends AbstractBuilderAction {
picoContainer.registerComponentImplementation(GenerateBuilderActionHandler.class);
picoContainer.registerComponentImplementation(GenerateBuilderPopupDisplayer.class);
picoContainer.registerComponentImplementation(GenerateBuilderPopupListFactory.class);
builderActionHandler = (AbstractBuilderActionHandler) picoContainer.getComponentInstanceOfType(GenerateBuilderActionHandler.class);
builderActionHandler = (AbstractBuilderActionHandler)
picoContainer.getComponentInstanceOfType(GenerateBuilderActionHandler.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package pl.mjedynak.idea.plugins.builder.action;

import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;

import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;

public class GenerateBuilderAdditionalAction extends AbstractBuilderAdditionalAction {

private static final String TEXT = "Create New Builder...";
private static final Icon ICON = IconLoader.getIcon("/actions/intentionBulb.png", GenerateBuilderAdditionalAction.class);
private static final Icon ICON =
IconLoader.getIcon("/actions/intentionBulb.png", GenerateBuilderAdditionalAction.class);

@NotNull
@Override
Expand All @@ -22,6 +22,5 @@ public Icon getIcon() {
}

@Override
public void execute() {
}
public void execute() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GoToBuilderAction extends AbstractBuilderAction {
picoContainer.registerComponentImplementation(GoToBuilderActionHandler.class);
picoContainer.registerComponentImplementation(GoToBuilderPopupDisplayer.class);
picoContainer.registerComponentImplementation(GoToBuilderPopupListFactory.class);
builderActionHandler = (AbstractBuilderActionHandler) picoContainer.getComponentInstanceOfType(GoToBuilderActionHandler.class);
builderActionHandler =
(AbstractBuilderActionHandler) picoContainer.getComponentInstanceOfType(GoToBuilderActionHandler.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package pl.mjedynak.idea.plugins.builder.action;

import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;

import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;

public class GoToBuilderAdditionalAction extends AbstractBuilderAdditionalAction {

Expand All @@ -22,6 +21,5 @@ public Icon getIcon() {
}

@Override
public void execute() {
}
public void execute() {}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package pl.mjedynak.idea.plugins.builder.action;

import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;

import javax.swing.Icon;
import org.jetbrains.annotations.NotNull;

public class RegenerateBuilderAdditionalAction extends AbstractBuilderAdditionalAction {

Expand All @@ -22,6 +21,5 @@ public Icon getIcon() {
}

@Override
public void execute() {
}
public void execute() {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.mjedynak.idea.plugins.builder.action.handler;

import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
Expand All @@ -21,8 +21,13 @@ public abstract class AbstractBuilderActionHandler extends EditorActionHandler {
protected AbstractPopupListFactory popupListFactory;
protected DisplayChoosers displayChoosers;

public AbstractBuilderActionHandler(PsiHelper psiHelper, BuilderVerifier builderVerifier, BuilderFinder builderFinder, AbstractPopupDisplayer popupDisplayer,
AbstractPopupListFactory popupListFactory, DisplayChoosers displayChoosers) {
public AbstractBuilderActionHandler(
PsiHelper psiHelper,
BuilderVerifier builderVerifier,
BuilderFinder builderFinder,
AbstractPopupDisplayer popupDisplayer,
AbstractPopupListFactory popupListFactory,
DisplayChoosers displayChoosers) {
this.psiHelper = psiHelper;
this.builderVerifier = builderVerifier;
this.builderFinder = builderFinder;
Expand Down Expand Up @@ -65,8 +70,9 @@ private PsiClass findClassToGo(PsiClass psiClassFromEditor, boolean isBuilder) {
return builderFinder.findBuilderForClass(psiClassFromEditor);
}

protected abstract void doActionWhenClassToGoIsFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder, PsiClass classToGo);

protected abstract void doActionWhenClassToGoIsNotFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder);
protected abstract void doActionWhenClassToGoIsFound(
Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder, PsiClass classToGo);

protected abstract void doActionWhenClassToGoIsNotFound(
Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiPackage;
import java.util.List;
import pl.mjedynak.idea.plugins.builder.factory.CreateBuilderDialogFactory;
import pl.mjedynak.idea.plugins.builder.factory.MemberChooserDialogFactory;
import pl.mjedynak.idea.plugins.builder.factory.PsiFieldsForBuilderFactory;
Expand All @@ -16,8 +17,6 @@
import pl.mjedynak.idea.plugins.builder.writer.BuilderContext;
import pl.mjedynak.idea.plugins.builder.writer.BuilderWriter;

import java.util.List;

public class DisplayChoosers {

private PsiClass psiClassFromEditor;
Expand All @@ -30,9 +29,13 @@ public class DisplayChoosers {
private final BuilderWriter builderWriter;
private final PsiFieldsForBuilderFactory psiFieldsForBuilderFactory;

public DisplayChoosers(PsiHelper psiHelper, CreateBuilderDialogFactory createBuilderDialogFactory,
PsiFieldSelector psiFieldSelector, MemberChooserDialogFactory memberChooserDialogFactory,
BuilderWriter builderWriter, PsiFieldsForBuilderFactory psiFieldsForBuilderFactory) {
public DisplayChoosers(
PsiHelper psiHelper,
CreateBuilderDialogFactory createBuilderDialogFactory,
PsiFieldSelector psiFieldSelector,
MemberChooserDialogFactory memberChooserDialogFactory,
BuilderWriter builderWriter,
PsiFieldsForBuilderFactory psiFieldsForBuilderFactory) {
this.psiHelper = psiHelper;
this.createBuilderDialogFactory = createBuilderDialogFactory;
this.psiFieldSelector = psiFieldSelector;
Expand All @@ -50,33 +53,58 @@ public void run(PsiClass existingBuilder) {
boolean innerBuilder = createBuilderDialog.isInnerBuilder();
boolean useSingleField = createBuilderDialog.useSingleField();
boolean hasButMethod = createBuilderDialog.hasButMethod();
List<PsiElementClassMember<?>> fieldsToDisplay = getFieldsToIncludeInBuilder(psiClassFromEditor, innerBuilder, useSingleField, hasButMethod);
com.intellij.ide.util.MemberChooser<PsiElementClassMember<?>> memberChooserDialog = memberChooserDialogFactory.getMemberChooserDialog(fieldsToDisplay, project);
List<PsiElementClassMember<?>> fieldsToDisplay =
getFieldsToIncludeInBuilder(psiClassFromEditor, innerBuilder, useSingleField, hasButMethod);
com.intellij.ide.util.MemberChooser<PsiElementClassMember<?>> memberChooserDialog =
memberChooserDialogFactory.getMemberChooserDialog(fieldsToDisplay, project);
memberChooserDialog.show();
writeBuilderIfNecessary(targetDirectory, className, methodPrefix, memberChooserDialog, createBuilderDialog, existingBuilder);
writeBuilderIfNecessary(
targetDirectory,
className,
methodPrefix,
memberChooserDialog,
createBuilderDialog,
existingBuilder);
}
}

private void writeBuilderIfNecessary(
PsiDirectory targetDirectory, String className, String methodPrefix, com.intellij.ide.util.MemberChooser<PsiElementClassMember<?>> memberChooserDialog, CreateBuilderDialog createBuilderDialog, PsiClass existingBuilder) {
PsiDirectory targetDirectory,
String className,
String methodPrefix,
com.intellij.ide.util.MemberChooser<PsiElementClassMember<?>> memberChooserDialog,
CreateBuilderDialog createBuilderDialog,
PsiClass existingBuilder) {
if (memberChooserDialog.isOK()) {
List<PsiElementClassMember<?>> selectedElements = memberChooserDialog.getSelectedElements();
PsiFieldsForBuilder psiFieldsForBuilder = psiFieldsForBuilderFactory.createPsiFieldsForBuilder(selectedElements, psiClassFromEditor);
PsiFieldsForBuilder psiFieldsForBuilder =
psiFieldsForBuilderFactory.createPsiFieldsForBuilder(selectedElements, psiClassFromEditor);
BuilderContext context = new BuilderContext(
project, psiFieldsForBuilder, targetDirectory, className, psiClassFromEditor, methodPrefix, createBuilderDialog.isInnerBuilder(), createBuilderDialog.hasButMethod(), createBuilderDialog.useSingleField(), createBuilderDialog.hasAddCopyConstructor());
project,
psiFieldsForBuilder,
targetDirectory,
className,
psiClassFromEditor,
methodPrefix,
createBuilderDialog.isInnerBuilder(),
createBuilderDialog.hasButMethod(),
createBuilderDialog.useSingleField(),
createBuilderDialog.hasAddCopyConstructor());
builderWriter.writeBuilder(context, existingBuilder);
}
}

private CreateBuilderDialog showDialog(PsiClass existingBuilder) {
PsiDirectory srcDir = psiHelper.getPsiFileFromEditor(editor, project).getContainingDirectory();
PsiPackage srcPackage = psiHelper.getPackage(srcDir);
CreateBuilderDialog dialog = createBuilderDialogFactory.createBuilderDialog(psiClassFromEditor, project, srcPackage, existingBuilder);
CreateBuilderDialog dialog = createBuilderDialogFactory.createBuilderDialog(
psiClassFromEditor, project, srcPackage, existingBuilder);
dialog.show();
return dialog;
}

private List<PsiElementClassMember<?>> getFieldsToIncludeInBuilder(PsiClass clazz, boolean innerBuilder, boolean useSingleField, boolean hasButMethod) {
private List<PsiElementClassMember<?>> getFieldsToIncludeInBuilder(
PsiClass clazz, boolean innerBuilder, boolean useSingleField, boolean hasButMethod) {
return psiFieldSelector.selectFieldsToIncludeInBuilder(clazz, innerBuilder, useSingleField, hasButMethod);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiClass;
import javax.swing.JList;
import pl.mjedynak.idea.plugins.builder.action.GoToBuilderAdditionalAction;
import pl.mjedynak.idea.plugins.builder.action.RegenerateBuilderAdditionalAction;
import pl.mjedynak.idea.plugins.builder.factory.GenerateBuilderPopupListFactory;
Expand All @@ -11,23 +12,33 @@
import pl.mjedynak.idea.plugins.builder.psi.PsiHelper;
import pl.mjedynak.idea.plugins.builder.verifier.BuilderVerifier;

import javax.swing.JList;

public class GenerateBuilderActionHandler extends AbstractBuilderActionHandler {

public GenerateBuilderActionHandler(PsiHelper psiHelper, BuilderVerifier builderVerifier, BuilderFinder builderFinder, GenerateBuilderPopupDisplayer popupDisplayer, GenerateBuilderPopupListFactory popupListFactory, DisplayChoosers displayChoosersRunnable) {
public GenerateBuilderActionHandler(
PsiHelper psiHelper,
BuilderVerifier builderVerifier,
BuilderFinder builderFinder,
GenerateBuilderPopupDisplayer popupDisplayer,
GenerateBuilderPopupListFactory popupListFactory,
DisplayChoosers displayChoosersRunnable) {
super(psiHelper, builderVerifier, builderFinder, popupDisplayer, popupListFactory, displayChoosersRunnable);
}

@Override
protected void doActionWhenClassToGoIsFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder, PsiClass classToGo) {
protected void doActionWhenClassToGoIsFound(
Editor editor,
PsiClass psiClassFromEditor,
DataContext dataContext,
boolean isBuilder,
PsiClass classToGo) {
if (!isBuilder) {
displayPopup(editor, classToGo);
}
}

@Override
protected void doActionWhenClassToGoIsNotFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder) {
protected void doActionWhenClassToGoIsNotFound(
Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder) {
if (!isBuilder) {
displayChoosers.run(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiClass;
import javax.swing.JList;
import pl.mjedynak.idea.plugins.builder.factory.GoToBuilderPopupListFactory;
import pl.mjedynak.idea.plugins.builder.finder.BuilderFinder;
import pl.mjedynak.idea.plugins.builder.gui.displayer.GoToBuilderPopupDisplayer;
import pl.mjedynak.idea.plugins.builder.psi.PsiHelper;
import pl.mjedynak.idea.plugins.builder.verifier.BuilderVerifier;

import javax.swing.JList;

public class GoToBuilderActionHandler extends AbstractBuilderActionHandler {

public GoToBuilderActionHandler(PsiHelper psiHelper, BuilderVerifier builderVerifier, BuilderFinder builderFinder, GoToBuilderPopupDisplayer popupDisplayer, GoToBuilderPopupListFactory popupListFactory, DisplayChoosers displayChoosersRunnable) {
public GoToBuilderActionHandler(
PsiHelper psiHelper,
BuilderVerifier builderVerifier,
BuilderFinder builderFinder,
GoToBuilderPopupDisplayer popupDisplayer,
GoToBuilderPopupListFactory popupListFactory,
DisplayChoosers displayChoosersRunnable) {
super(psiHelper, builderVerifier, builderFinder, popupDisplayer, popupListFactory, displayChoosersRunnable);
}

@Override
protected void doActionWhenClassToGoIsFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder, PsiClass classToGo) {
protected void doActionWhenClassToGoIsFound(
Editor editor,
PsiClass psiClassFromEditor,
DataContext dataContext,
boolean isBuilder,
PsiClass classToGo) {
psiHelper.navigateToClass(classToGo);
}

@Override
protected void doActionWhenClassToGoIsNotFound(Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder) {
protected void doActionWhenClassToGoIsNotFound(
Editor editor, PsiClass psiClassFromEditor, DataContext dataContext, boolean isBuilder) {
if (!isBuilder) {
displayPopup(editor);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package pl.mjedynak.idea.plugins.builder.factory;

import pl.mjedynak.idea.plugins.builder.renderer.ActionCellRenderer;

import javax.swing.JList;
import pl.mjedynak.idea.plugins.builder.renderer.ActionCellRenderer;

public abstract class AbstractPopupListFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ public class CreateBuilderDialogFactory {
private final ReferenceEditorComboWithBrowseButtonFactory referenceEditorComboWithBrowseButtonFactory;
private final GuiHelper guiHelper;

public CreateBuilderDialogFactory(PsiHelper psiHelper, ReferenceEditorComboWithBrowseButtonFactory referenceEditorComboWithBrowseButtonFactory, GuiHelper guiHelper) {
public CreateBuilderDialogFactory(
PsiHelper psiHelper,
ReferenceEditorComboWithBrowseButtonFactory referenceEditorComboWithBrowseButtonFactory,
GuiHelper guiHelper) {
this.psiHelper = psiHelper;
this.referenceEditorComboWithBrowseButtonFactory = referenceEditorComboWithBrowseButtonFactory;
this.guiHelper = guiHelper;
}

public CreateBuilderDialog createBuilderDialog(PsiClass sourceClass, Project project, PsiPackage srcPackage, PsiClass existingBuilder) {
return new CreateBuilderDialog(project, DIALOG_NAME, sourceClass, sourceClass.getName() + BUILDER_SUFFIX, srcPackage, psiHelper, guiHelper,
referenceEditorComboWithBrowseButtonFactory, existingBuilder);
public CreateBuilderDialog createBuilderDialog(
PsiClass sourceClass, Project project, PsiPackage srcPackage, PsiClass existingBuilder) {
return new CreateBuilderDialog(
project,
DIALOG_NAME,
sourceClass,
sourceClass.getName() + BUILDER_SUFFIX,
srcPackage,
psiHelper,
guiHelper,
referenceEditorComboWithBrowseButtonFactory,
existingBuilder);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package pl.mjedynak.idea.plugins.builder.factory;

import static java.util.Arrays.asList;

import com.intellij.ui.components.JBList;
import javax.swing.JList;
import pl.mjedynak.idea.plugins.builder.action.GoToBuilderAdditionalAction;
import pl.mjedynak.idea.plugins.builder.action.RegenerateBuilderAdditionalAction;

import javax.swing.JList;

import static java.util.Arrays.asList;

public class GenerateBuilderPopupListFactory extends AbstractPopupListFactory {

@Override
Expand Down
Loading

0 comments on commit ed7ba5e

Please sign in to comment.