Skip to content

Commit f416f02

Browse files
committedMar 21, 2016
Tidy up code samples and wrap at 80 chars #IJSDK-24
1 parent 8aaf13b commit f416f02

File tree

127 files changed

+2715
-2584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2715
-2584
lines changed
 

‎code_samples/comparing_references_inspection/source/META-INF/plugin.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<description>Inspection for (probably) inappropriate use of equality relation operation.</description>
44
<version>1.0</version>
55
<vendor>JetBrains</vendor>
6-
<!--
7-
<idea-version since-build="3000"/>
8-
-->
6+
<!--
7+
<idea-version since-build="3000"/>
8+
-->
99

1010
<extensions defaultExtensionNs="com.intellij">
1111
<inspectionToolProvider implementation="com.intellij.codeInspection.ComparingReferencesProvider"/>

‎code_samples/comparing_references_inspection/source/com/intellij/codeInspection/ComparingReferencesInspection.java

+36-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.intellij.codeInsight.daemon.GroupNames;
44
import com.intellij.openapi.diagnostic.Logger;
55
import com.intellij.openapi.project.Project;
6-
import com.intellij.openapi.util.Ref;
76
import com.intellij.psi.*;
87
import com.intellij.psi.tree.IElementType;
98
import com.intellij.ui.DocumentAdapter;
@@ -14,8 +13,6 @@
1413
import javax.swing.*;
1514
import javax.swing.event.DocumentEvent;
1615
import java.awt.*;
17-
import java.util.ArrayList;
18-
import java.util.Arrays;
1916
import java.util.StringTokenizer;
2017

2118
/**
@@ -26,13 +23,17 @@ public class ComparingReferencesInspection extends BaseJavaLocalInspectionTool {
2623

2724
private final LocalQuickFix myQuickFix = new MyQuickFix();
2825

29-
@SuppressWarnings({"WeakerAccess"}) @NonNls public String CHECKED_CLASSES = "java.lang.String;java.util.Date";
30-
@NonNls private static final String DESCRIPTION_TEMPLATE = InspectionsBundle.message("inspection.comparing.references.problem.descriptor");
26+
@SuppressWarnings({"WeakerAccess"})
27+
@NonNls
28+
public String CHECKED_CLASSES = "java.lang.String;java.util.Date";
29+
@NonNls
30+
private static final String DESCRIPTION_TEMPLATE =
31+
InspectionsBundle.message("inspection.comparing.references.problem.descriptor");
3132

3233
@NotNull
3334
public String getDisplayName() {
3435

35-
return "'==' or '!=' instead of 'equals()'";
36+
return "'==' or '!=' instead of 'equals()'";
3637
}
3738

3839
@NotNull
@@ -57,32 +58,33 @@ private boolean isCheckedType(PsiType type) {
5758
return false;
5859
}
5960

60-
@NotNull
61-
@Override
62-
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
63-
return new JavaElementVisitor() {
61+
@NotNull
62+
@Override
63+
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
64+
return new JavaElementVisitor() {
6465

65-
@Override
66-
public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) {
67-
}
66+
@Override
67+
public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) {
68+
}
6869

6970

70-
@Override public void visitBinaryExpression(PsiBinaryExpression expression) {
71-
super.visitBinaryExpression(expression);
71+
@Override
72+
public void visitBinaryExpression(PsiBinaryExpression expression) {
73+
super.visitBinaryExpression(expression);
7274
IElementType opSign = expression.getOperationTokenType();
73-
if (opSign == JavaTokenType.EQEQ || opSign == JavaTokenType.NE) {
74-
PsiExpression lOperand = expression.getLOperand();
75-
PsiExpression rOperand = expression.getROperand();
76-
if (rOperand == null || isNullLiteral(lOperand) || isNullLiteral(rOperand)) return;
77-
78-
PsiType lType = lOperand.getType();
79-
PsiType rType = rOperand.getType();
80-
81-
if (isCheckedType(lType) || isCheckedType(rType)) {
82-
holder.registerProblem(expression,
83-
DESCRIPTION_TEMPLATE, myQuickFix);
84-
}
75+
if (opSign == JavaTokenType.EQEQ || opSign == JavaTokenType.NE) {
76+
PsiExpression lOperand = expression.getLOperand();
77+
PsiExpression rOperand = expression.getROperand();
78+
if (rOperand == null || isNullLiteral(lOperand) || isNullLiteral(rOperand)) return;
79+
80+
PsiType lType = lOperand.getType();
81+
PsiType rType = rOperand.getType();
82+
83+
if (isCheckedType(lType) || isCheckedType(rType)) {
84+
holder.registerProblem(expression,
85+
DESCRIPTION_TEMPLATE, myQuickFix);
8586
}
87+
}
8688
}
8789
};
8890
}
@@ -94,35 +96,35 @@ private static boolean isNullLiteral(PsiExpression expr) {
9496
private static class MyQuickFix implements LocalQuickFix {
9597
@NotNull
9698
public String getName() {
97-
// The test (see the TestThisPlugin class) uses this string to identify the quick fix action.
99+
// The test (see the TestThisPlugin class) uses this string to identify the quick fix action.
98100
return InspectionsBundle.message("inspection.comparing.references.use.quickfix");
99101
}
100102

101103

102104
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
103105
try {
104-
PsiBinaryExpression binaryExpression = (PsiBinaryExpression)descriptor.getPsiElement();
106+
PsiBinaryExpression binaryExpression = (PsiBinaryExpression) descriptor.getPsiElement();
105107
IElementType opSign = binaryExpression.getOperationTokenType();
106108
PsiExpression lExpr = binaryExpression.getLOperand();
107109
PsiExpression rExpr = binaryExpression.getROperand();
108110
if (rExpr == null)
109111
return;
110112

111113
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
112-
PsiMethodCallExpression equalsCall = (PsiMethodCallExpression)factory.createExpressionFromText("a.equals(b)", null);
114+
PsiMethodCallExpression equalsCall =
115+
(PsiMethodCallExpression) factory.createExpressionFromText("a.equals(b)", null);
113116

114117
equalsCall.getMethodExpression().getQualifierExpression().replace(lExpr);
115118
equalsCall.getArgumentList().getExpressions()[0].replace(rExpr);
116119

117-
PsiExpression result = (PsiExpression)binaryExpression.replace(equalsCall);
120+
PsiExpression result = (PsiExpression) binaryExpression.replace(equalsCall);
118121

119122
if (opSign == JavaTokenType.NE) {
120-
PsiPrefixExpression negation = (PsiPrefixExpression)factory.createExpressionFromText("!a", null);
123+
PsiPrefixExpression negation = (PsiPrefixExpression) factory.createExpressionFromText("!a", null);
121124
negation.getOperand().replace(result);
122125
result.replace(negation);
123126
}
124-
}
125-
catch (IncorrectOperationException e) {
127+
} catch (IncorrectOperationException e) {
126128
LOG.error(e);
127129
}
128130
}

0 commit comments

Comments
 (0)
Please sign in to comment.