Skip to content

Commit 00305e5

Browse files
committed
Fixed PMD issues
1 parent b213d0d commit 00305e5

13 files changed

+91
-93
lines changed

src/com/magento/idea/magento2plugin/actions/generation/CreateAPluginAction.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import com.magento.idea.magento2plugin.project.Settings;
2424

2525
public class CreateAPluginAction extends DumbAwareAction {
26-
public static String ACTION_NAME = "Create a new Plugin for this method";
27-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
28-
private final IsPluginAllowedForMethod isPluginAllowed;
26+
public static final String ACTION_NAME = "Create a new Plugin for this method";
27+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
28+
private final IsPluginAllowedForMethod isPluginAllowed;// NOPMD
2929
private final GetFirstClassOfFile getFirstClassOfFile;
3030
private Method targetMethod;
3131
private PhpClass targetClass;
@@ -36,18 +36,19 @@ public CreateAPluginAction() {
3636
this.getFirstClassOfFile = GetFirstClassOfFile.getInstance();
3737
}
3838

39-
public void update(AnActionEvent event) {
40-
targetClass = null;
41-
targetMethod = null;
42-
Project project = event.getData(PlatformDataKeys.PROJECT);
39+
@Override
40+
public void update(final AnActionEvent event) {
41+
targetClass = null;// NOPMD
42+
targetMethod = null;// NOPMD
43+
final Project project = event.getData(PlatformDataKeys.PROJECT);
4344
if (Settings.isEnabled(project)) {
44-
Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
45-
PsiFile psiFile = pair.getFirst();
46-
PhpClass phpClass = pair.getSecond();
47-
if ((phpClass == null || psiFile == null)
48-
|| !(psiFile instanceof PhpFile)
49-
|| phpClass.isFinal()
50-
|| this.targetMethod == null
45+
final Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
46+
final PsiFile psiFile = pair.getFirst();
47+
final PhpClass phpClass = pair.getSecond();
48+
if (phpClass == null
49+
|| !(psiFile instanceof PhpFile)
50+
|| phpClass.isFinal()
51+
|| this.targetMethod == null
5152
) {
5253
this.setStatus(event, false);
5354
return;
@@ -60,23 +61,23 @@ public void update(AnActionEvent event) {
6061
this.setStatus(event, false);
6162
}
6263

63-
private void setStatus(AnActionEvent event, boolean status) {
64+
private void setStatus(final AnActionEvent event, final boolean status) {
6465
event.getPresentation().setVisible(status);
6566
event.getPresentation().setEnabled(status);
6667
}
6768

6869
@Override
69-
public void actionPerformed(@NotNull AnActionEvent e) {
70-
CreateAPluginDialog.open(e.getProject(), this.targetMethod, this.targetClass);
70+
public void actionPerformed(@NotNull final AnActionEvent event) {
71+
CreateAPluginDialog.open(event.getProject(), this.targetMethod, this.targetClass);
7172
}
7273

7374
@Override
7475
public boolean isDumbAware() {
7576
return false;
7677
}
7778

78-
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull AnActionEvent event) {
79-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
79+
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event) {
80+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
8081

8182
PhpClass phpClass = null;
8283
if (psiFile instanceof PhpFile) {
@@ -87,23 +88,23 @@ private Pair<PsiFile, PhpClass> findPhpClass(@NotNull AnActionEvent event) {
8788
return Pair.create(psiFile, phpClass);
8889
}
8990

90-
private void fetchTargetMethod(@NotNull AnActionEvent event, PsiFile psiFile, PhpClass phpClass) {
91-
Caret caret = event.getData(PlatformDataKeys.CARET);
91+
private void fetchTargetMethod(@NotNull final AnActionEvent event, final PsiFile psiFile, final PhpClass phpClass) {
92+
final Caret caret = event.getData(PlatformDataKeys.CARET);
9293
if (caret == null) {
9394
return;
9495
}
95-
int offset = caret.getOffset();
96-
PsiElement element = psiFile.findElementAt(offset);
96+
final int offset = caret.getOffset();
97+
final PsiElement element = psiFile.findElementAt(offset);
9798
if (element == null) {
9899
return;
99100
}
100-
if (element instanceof Method && element.getParent() == phpClass && isPluginAllowed.check((Method)element)) {
101-
this.targetMethod = (Method)element;
101+
if (element instanceof Method && element.getParent() == phpClass && isPluginAllowed.check((Method) element)) {
102+
this.targetMethod = (Method) element;
102103
return;
103104
}
104-
PsiElement parent = element.getParent();
105-
if (parent instanceof Method && parent.getParent() == phpClass && isPluginAllowed.check((Method)parent)) {
106-
this.targetMethod = (Method)parent;
105+
final PsiElement parent = element.getParent();
106+
if (parent instanceof Method && parent.getParent() == phpClass && isPluginAllowed.check((Method) parent)) {
107+
this.targetMethod = (Method) parent;
107108
}
108109
}
109110
}

src/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ public CreateAnObserverAction() {
3535
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
3636
}
3737

38-
public void update(AnActionEvent event) {
39-
Project project = event.getData(PlatformDataKeys.PROJECT);
38+
@Override
39+
public void update(final AnActionEvent event) {
40+
final Project project = event.getData(PlatformDataKeys.PROJECT);
4041
if (!Settings.isEnabled(project)) {
4142
this.setStatus(event, false);
4243
return;
4344
}
44-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
45+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
4546
if (!(psiFile instanceof PhpFile)) {
4647
this.setStatus(event, false);
4748
return;
4849
}
4950

50-
PsiElement element = getElement(event);
51+
final PsiElement element = getElement(event);
5152
if (element == null) {
5253
this.setStatus(event, false);
5354
return;
@@ -62,87 +63,73 @@ public void update(AnActionEvent event) {
6263
this.setStatus(event, false);
6364
}
6465

65-
private PsiElement getElement(@NotNull AnActionEvent event) {
66-
Caret caret = event.getData(PlatformDataKeys.CARET);
67-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
66+
private PsiElement getElement(@NotNull final AnActionEvent event) {
67+
final Caret caret = event.getData(PlatformDataKeys.CARET);
6868
if (caret == null) {
6969
return null;
7070
}
71-
int offset = caret.getOffset();
72-
PsiElement element = psiFile.findElementAt(offset);
71+
final int offset = caret.getOffset();
72+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
73+
final PsiElement element = psiFile.findElementAt(offset);
7374
if (element == null) {
7475
return null;
7576
}
7677
return element;
7778
}
7879

79-
private boolean isObserverEventNameClicked(@NotNull PsiElement element) {
80-
if (checkIsElementStringLiteral(element)) {
81-
if (checkIsParametersList(element.getParent().getParent()) &&
82-
checkIsMethodReference(element.getParent().getParent().getParent()) &&
83-
checkIsEventDispatchMethod((MethodReference) element.getParent().getParent().getParent())) {
84-
return true;
85-
}
86-
}
87-
return false;
80+
private boolean isObserverEventNameClicked(@NotNull final PsiElement element) {
81+
return checkIsElementStringLiteral(element) &&
82+
checkIsParametersList(element.getParent().getParent()) &&
83+
checkIsMethodReference(element.getParent().getParent().getParent()) &&
84+
checkIsEventDispatchMethod((MethodReference) element.getParent().getParent().getParent());
8885
}
8986

90-
private boolean checkIsParametersList(@NotNull PsiElement element) {
91-
if (element instanceof ParameterList) {
92-
return true;
93-
}
94-
return false;
87+
private boolean checkIsParametersList(@NotNull final PsiElement element) {
88+
return element instanceof ParameterList;
9589
}
9690

97-
private boolean checkIsMethodReference(@NotNull PsiElement element) {
98-
if (element instanceof MethodReference) {
99-
return true;
100-
}
101-
return false;
91+
private boolean checkIsMethodReference(@NotNull final PsiElement element) {
92+
return element instanceof MethodReference;
10293
}
10394

104-
private boolean checkIsEventDispatchMethod(MethodReference element) {
105-
PsiReference elementReference = element.getReference();
95+
private boolean checkIsEventDispatchMethod(final MethodReference element) {
96+
final PsiReference elementReference = element.getReference();
10697
if (elementReference == null) {
10798
return false;
10899
}
109-
PsiElement method = elementReference.resolve();
100+
final PsiElement method = elementReference.resolve();
110101
if (!(method instanceof Method)) {
111102
return false;
112103
}
113104
if (!((Method) method).getName().equals(Observer.DISPATCH_METHOD)) {
114105
return false;
115106
}
116-
PsiElement phpClass = method.getParent();
107+
final PsiElement phpClass = method.getParent();
117108
if (!(phpClass instanceof PhpClass)) {
118109
return false;
119110
}
120-
String fqn = ((PhpClass) phpClass).getPresentableFQN();
111+
final String fqn = ((PhpClass) phpClass).getPresentableFQN();
121112
return fqn.equals(Observer.INTERFACE);
122113
}
123114

124-
private boolean checkIsElementStringLiteral(@NotNull PsiElement element) {
125-
ASTNode astNode = element.getNode();
115+
private boolean checkIsElementStringLiteral(@NotNull final PsiElement element) {
116+
final ASTNode astNode = element.getNode();
126117
if (astNode == null) {
127118
return false;
128119
}
129-
IElementType elementType = astNode.getElementType();
130-
131-
if (elementType != PhpTokenTypes.STRING_LITERAL && elementType != PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE) {
132-
return false;
133-
}
120+
final IElementType elementType = astNode.getElementType();
134121

135-
return true;
122+
return elementType == PhpTokenTypes.STRING_LITERAL || elementType == PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE;
136123
}
137124

138-
private void setStatus(AnActionEvent event, boolean status) {
125+
private void setStatus(final AnActionEvent event, final boolean status) {
139126
event.getPresentation().setVisible(status);
140127
event.getPresentation().setEnabled(status);
141128
}
142129

143130
@Override
144-
public void actionPerformed(@NotNull AnActionEvent e) {
145-
CreateAnObserverDialog.open(e.getProject(), this.targetEvent);
131+
public void actionPerformed(@NotNull final AnActionEvent event) {
132+
CreateAnObserverDialog.open(event.getProject(), this.targetEvent);
146133
}
147134

148135
@Override

src/com/magento/idea/magento2plugin/actions/generation/NewBlockAction.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@
1313
import org.jetbrains.annotations.NotNull;
1414

1515
public class NewBlockAction extends AnAction {
16-
public static String ACTION_NAME = "Magento 2 Block";
17-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 Block";
16+
public static final String ACTION_NAME = "Magento 2 Block";
17+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Block";
1818

19-
NewBlockAction() {
19+
public NewBlockAction() {
2020
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
2121
}
2222

2323
@Override
24-
public void actionPerformed(@NotNull AnActionEvent e) {
25-
DataContext dataContext = e.getDataContext();
26-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
24+
public void actionPerformed(@NotNull final AnActionEvent event) {
25+
final DataContext dataContext = event.getDataContext();
26+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
2727
if (view == null) {
2828
return;
2929
}
3030

31-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
31+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
3232
if (project == null) {
3333
return;
3434
}
3535

36-
PsiDirectory directory = view.getOrChooseDirectory();
36+
final PsiDirectory directory = view.getOrChooseDirectory();
3737
if (directory == null) {
3838
return;
3939
}

src/com/magento/idea/magento2plugin/actions/generation/NewUiComponentGridAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public NewUiComponentGridAction() {
3333
*
3434
* @param event Action event
3535
*/
36+
@Override
3637
public void actionPerformed(final AnActionEvent event) {
3738
final DataContext dataContext = event.getDataContext();
3839
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

src/com/magento/idea/magento2plugin/actions/generation/OverrideClassByAPreferenceAction.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import org.jetbrains.annotations.NotNull;
2020

2121
public class OverrideClassByAPreferenceAction extends DumbAwareAction {
22-
public static String ACTION_NAME = "Override this class by a new Preference";
23-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 Preference";
22+
public static final String ACTION_NAME = "Override this class by a new Preference";
23+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Preference";
2424
private final GetFirstClassOfFile getFirstClassOfFile;
2525
private PhpClass targetClass;
2626

@@ -29,13 +29,14 @@ public OverrideClassByAPreferenceAction() {
2929
this.getFirstClassOfFile = GetFirstClassOfFile.getInstance();
3030
}
3131

32-
public void update(AnActionEvent event) {
33-
targetClass = null;
34-
Project project = event.getData(PlatformDataKeys.PROJECT);
32+
@Override
33+
public void update(final AnActionEvent event) {
34+
targetClass = null;// NOPMD
35+
final Project project = event.getData(PlatformDataKeys.PROJECT);
3536
if (Settings.isEnabled(project)) {
36-
Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
37-
PsiFile psiFile = pair.getFirst();
38-
PhpClass phpClass = pair.getSecond();
37+
final Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
38+
final PsiFile psiFile = pair.getFirst();
39+
final PhpClass phpClass = pair.getSecond();
3940
targetClass = phpClass;
4041
if (psiFile instanceof PhpFile && phpClass != null) {
4142
this.setStatus(event, true);
@@ -47,23 +48,23 @@ public void update(AnActionEvent event) {
4748
}
4849
}
4950

50-
private void setStatus(AnActionEvent event, boolean status) {
51+
private void setStatus(final AnActionEvent event, final boolean status) {
5152
event.getPresentation().setVisible(status);
5253
event.getPresentation().setEnabled(status);
5354
}
5455

5556
@Override
56-
public void actionPerformed(@NotNull AnActionEvent e) {
57-
OverrideClassByAPreferenceDialog.open(e.getProject(), this.targetClass);
57+
public void actionPerformed(@NotNull final AnActionEvent event) {
58+
OverrideClassByAPreferenceDialog.open(event.getProject(), this.targetClass);
5859
}
5960

6061
@Override
6162
public boolean isDumbAware() {
6263
return false;
6364
}
6465

65-
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull AnActionEvent event) {
66-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
66+
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event) {
67+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
6768

6869
PhpClass phpClass = null;
6970
if (psiFile instanceof PhpFile) {

src/com/magento/idea/magento2plugin/actions/generation/OverrideInThemeAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public OverrideInThemeAction() {
3434
*
3535
* @param event AnActionEvent
3636
*/
37+
@Override
3738
public void update(final @NotNull AnActionEvent event) {
3839
boolean status = false;
3940
final Project project = event.getData(PlatformDataKeys.PROJECT);

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public CreateAPluginDialog(
131131

132132
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
133133
addWindowListener(new WindowAdapter() {
134+
@Override
134135
public void windowClosing(final WindowEvent event) {
135136
onCancel();
136137
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) {
8181
// call onCancel() when cross is clicked
8282
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
8383
addWindowListener(new WindowAdapter() {
84+
@Override
8485
public void windowClosing(final WindowEvent event) {
8586
onCancel();
8687
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
9696
// call onCancel() when cross is clicked
9797
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
9898
addWindowListener(new WindowAdapter() {
99+
@Override
99100
public void windowClosing(final WindowEvent event) {
100101
onCancel();
101102
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public NewCronGroupDialog(final Project project, final PsiDirectory directory) {
8888
// call onCancel() when cross is clicked
8989
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
9090
addWindowListener(new WindowAdapter() {
91+
@Override
9192
public void windowClosing(final WindowEvent event) {
9293
onCancel();
9394
}

0 commit comments

Comments
 (0)