mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -13,13 +13,36 @@
|
||||
Paired open/close for Sockets
|
||||
Paired open/close for Channels
|
||||
Paired acquire/release for Locks
|
||||
|
||||
Questionable name
|
||||
Local variable may be moved to first use;
|
||||
Duplicate condition
|
||||
Boolean method name must begin with
|
||||
Non-Boolean method name cannot begin with
|
||||
Equals methods that do not check parameter type
|
||||
Call to simple getter or setter from within class
|
||||
Copyright comment
|
||||
Tail recursion quickfix
|
||||
Make "Merge else-if" understand chained returning ifs
|
||||
"Extract method" as quickfix to overly complex expression
|
||||
Static inheritance fix
|
||||
Fixes for the assignment and return encapsulation inspections
|
||||
Static import fix
|
||||
Fixes for call to super for JUnit setUp() and tearDown()
|
||||
Check IDs for all inspections
|
||||
Flag inspections with default on-off and default warning level
|
||||
Check that refactoring quickfixes are only available on-the-fly
|
||||
Quick fix for "Constant StringBuffer may be String"
|
||||
Quick fix for Non-constant String should be StringBuffer
|
||||
Quick fix for "String concatenation in loop"
|
||||
Quick fix for "StringBuffer may be StringBuilder"
|
||||
Genericize "StringBuffer.toString() in concatenation"
|
||||
Split "Portability Issues" into "Portability Issues" and "JDK issues"
|
||||
QuickFix for "Confusing else Branch"
|
||||
QuickFix for "Conditional expression with negated condition"
|
||||
QuickFix for "Method names differing only by case"
|
||||
QuickFix for "Integer difision in floating point context"
|
||||
Quickfix for "Non-serializable class with..."
|
||||
Quickfix for "Unnecessary default"
|
||||
|
||||
|
||||
Inheritance as type def (change the EmptyClass inspection)
|
||||
changing multiply/divide to shift may change precedence!
|
||||
|
||||
@@ -114,7 +114,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
|
||||
final Class aClass = classes[i];
|
||||
final String className = aClass.getName();
|
||||
final String simpleClassName = className.substring(className.lastIndexOf('.') + 1, className.length() - "Inspection".length());
|
||||
final String fileName = "C:/InspectionGadgetsCVS/src/inspectionDescriptions/" + simpleClassName + ".html";
|
||||
final String fileName = "C:/InspectionGadgetsSVN/src/inspectionDescriptions/" + simpleClassName + ".html";
|
||||
if (!new File(fileName).exists()) {
|
||||
out.println("Couldn't find documentation file " + fileName);
|
||||
}
|
||||
|
||||
+8
-4
@@ -2,12 +2,12 @@ package com.siyeh.ig.classlayout;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ClassInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.MoveAnonymousToInnerClassFix;
|
||||
|
||||
public class AnonymousInnerClassInspection extends ClassInspection {
|
||||
private final MoveAnonymousToInnerClassFix fix =
|
||||
new MoveAnonymousToInnerClassFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Anonymous inner class";
|
||||
@@ -21,6 +21,10 @@ public class AnonymousInnerClassInspection extends ClassInspection {
|
||||
return "Anonymous inner class #ref #loc";
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new AnonymousInnerClassVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
+7
-4
@@ -2,13 +2,12 @@ package com.siyeh.ig.classlayout;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ClassInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.MoveClassFix;
|
||||
|
||||
public class LimitedScopeInnerClassInspection extends ClassInspection {
|
||||
|
||||
private final MoveClassFix fix = new MoveClassFix();
|
||||
public String getDisplayName() {
|
||||
return "Limited-scope class";
|
||||
}
|
||||
@@ -21,6 +20,10 @@ public class LimitedScopeInnerClassInspection extends ClassInspection {
|
||||
return "Limited-scope inner class #ref #loc";
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new LimitedScopeInnerClassVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
+122
-18
@@ -1,55 +1,159 @@
|
||||
package com.siyeh.ig.confusing;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ExpressionInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.psiutils.WellFormednessUtils;
|
||||
|
||||
public class AssignmentToCatchBlockParameterInspection extends ExpressionInspection {
|
||||
public class AssignmentToCatchBlockParameterInspection
|
||||
extends ExpressionInspection{
|
||||
private AssignmentToCatchBlockParameterFix fix =
|
||||
new AssignmentToCatchBlockParameterFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
public String getDisplayName(){
|
||||
return "Assignment to catch block parameter";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName() {
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.CONFUSING_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
public String buildErrorString(PsiElement location){
|
||||
return "Assignment to catch block parameter #ref #loc ";
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new AssignmentToCatchBlockParameterVisitor(this, inspectionManager, onTheFly);
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
private static class AssignmentToCatchBlockParameterVisitor extends BaseInspectionVisitor {
|
||||
private AssignmentToCatchBlockParameterVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
private static class AssignmentToCatchBlockParameterFix
|
||||
extends InspectionGadgetsFix{
|
||||
public String getName(){
|
||||
return "Extract parameter as local variable";
|
||||
}
|
||||
|
||||
public void applyFix(Project project,
|
||||
ProblemDescriptor problemDescriptor){
|
||||
try{
|
||||
final PsiExpression variable =
|
||||
(PsiExpression) problemDescriptor.getPsiElement();
|
||||
final PsiCatchSection catchSection =
|
||||
(PsiCatchSection) PsiTreeUtil.getParentOfType(variable,
|
||||
PsiCatchSection.class);
|
||||
|
||||
final PsiCodeBlock body = catchSection.getCatchBlock();
|
||||
final String replacementText;
|
||||
final PsiType type = variable.getType();
|
||||
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
|
||||
final CodeStyleManager codeStyleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
final String originalVariableName = variable.getText();
|
||||
final SuggestedNameInfo suggestions =
|
||||
codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE,
|
||||
originalVariableName +
|
||||
'1',
|
||||
variable, type);
|
||||
final String[] names = suggestions.names;
|
||||
final String baseName;
|
||||
if(names != null && names.length > 0){
|
||||
baseName = names[0];
|
||||
} else{
|
||||
baseName = "value";
|
||||
}
|
||||
final String variableName =
|
||||
codeStyleManager.suggestUniqueVariableName(baseName,
|
||||
catchSection,
|
||||
false);
|
||||
final String className = type.getPresentableText();
|
||||
final PsiElement[] children = body.getChildren();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
for(int i = 1; i < children.length; i++){
|
||||
replaceVariableName(children[i], variableName,
|
||||
originalVariableName, buffer);
|
||||
}
|
||||
replacementText = '{' + className + ' ' + variableName + " = " +
|
||||
originalVariableName +
|
||||
';' +
|
||||
buffer.toString();
|
||||
|
||||
final PsiElementFactory elementFactory =
|
||||
psiManager.getElementFactory();
|
||||
final PsiCodeBlock block =
|
||||
elementFactory.createCodeBlockFromText(replacementText,
|
||||
null);
|
||||
body.replace(block);
|
||||
codeStyleManager.reformat(catchSection);
|
||||
} catch(IncorrectOperationException e){
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceVariableName(PsiElement element,
|
||||
String newName,
|
||||
String originalName,
|
||||
StringBuffer out){
|
||||
|
||||
final String text = element.getText();
|
||||
if(element instanceof PsiReferenceExpression){
|
||||
if(text.equals(originalName)){
|
||||
out.append(newName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiElement[] children = element.getChildren();
|
||||
if(children.length == 0){
|
||||
out.append(text);
|
||||
} else{
|
||||
for(int i = 0; i < children.length; i++){
|
||||
final PsiElement child = children[i];
|
||||
replaceVariableName(child, newName,
|
||||
originalName, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new AssignmentToCatchBlockParameterVisitor(this,
|
||||
inspectionManager,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static class AssignmentToCatchBlockParameterVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private AssignmentToCatchBlockParameterVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression){
|
||||
super.visitAssignmentExpression(expression);
|
||||
if(!WellFormednessUtils.isWellFormed(expression)){
|
||||
return;
|
||||
}
|
||||
final PsiExpression lhs = expression.getLExpression();
|
||||
if (!(lhs instanceof PsiReferenceExpression)) {
|
||||
if(!(lhs instanceof PsiReferenceExpression)){
|
||||
return;
|
||||
}
|
||||
final PsiReferenceExpression ref = (PsiReferenceExpression) lhs;
|
||||
final PsiElement variable = ref.resolve();
|
||||
if (!(variable instanceof PsiParameter)) {
|
||||
if(!(variable instanceof PsiParameter)){
|
||||
return;
|
||||
}
|
||||
if (!(((PsiParameter)variable).getDeclarationScope() instanceof PsiCatchSection)) {
|
||||
if(!(((PsiParameter) variable).getDeclarationScope() instanceof PsiCatchSection)){
|
||||
return;
|
||||
}
|
||||
registerError(expression);
|
||||
registerError(lhs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+129
-29
@@ -1,38 +1,138 @@
|
||||
package com.siyeh.ig.confusing;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ExpressionInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.psiutils.WellFormednessUtils;
|
||||
|
||||
public class AssignmentToMethodParameterInspection extends ExpressionInspection {
|
||||
public class AssignmentToMethodParameterInspection extends ExpressionInspection{
|
||||
private AssignmentToMethodParameterFix fix =
|
||||
new AssignmentToMethodParameterFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
public String getDisplayName(){
|
||||
return "Assignment to method parameter";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName() {
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.CONFUSING_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
public String buildErrorString(PsiElement location){
|
||||
return "Assignment to method parameter #ref #loc ";
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new AssignmentToMethodParameterVisitor(this, inspectionManager, onTheFly);
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
private static class AssignmentToMethodParameterVisitor extends BaseInspectionVisitor {
|
||||
private AssignmentToMethodParameterVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
private static class AssignmentToMethodParameterFix
|
||||
extends InspectionGadgetsFix{
|
||||
public String getName(){
|
||||
return "Extract parameter as local variable";
|
||||
}
|
||||
|
||||
public void applyFix(Project project,
|
||||
ProblemDescriptor problemDescriptor){
|
||||
try{
|
||||
final PsiExpression variable =
|
||||
(PsiExpression) problemDescriptor.getPsiElement();
|
||||
final PsiMethod method =
|
||||
(PsiMethod) PsiTreeUtil.getParentOfType(variable,
|
||||
PsiMethod.class);
|
||||
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
final String replacementText;
|
||||
final PsiType type = variable.getType();
|
||||
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
|
||||
final CodeStyleManager codeStyleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
final String originalVariableName = variable.getText();
|
||||
final SuggestedNameInfo suggestions =
|
||||
codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE,
|
||||
originalVariableName + '1', variable, type);
|
||||
final String[] names = suggestions.names;
|
||||
final String baseName;
|
||||
if(names != null && names.length > 0){
|
||||
baseName = names[0];
|
||||
} else{
|
||||
baseName = "value";
|
||||
}
|
||||
final String variableName =
|
||||
codeStyleManager.suggestUniqueVariableName(baseName,
|
||||
method,
|
||||
false);
|
||||
final String className = type.getPresentableText();
|
||||
final PsiElement[] children = body.getChildren();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
for(int i = 1; i < children.length; i++){
|
||||
replaceVariableName( children[i], variableName, originalVariableName, buffer);
|
||||
}
|
||||
replacementText = '{' + className + ' ' + variableName + " = " +
|
||||
originalVariableName +
|
||||
';' +
|
||||
buffer.toString();
|
||||
|
||||
final PsiElementFactory elementFactory =
|
||||
psiManager.getElementFactory();
|
||||
final PsiCodeBlock block =
|
||||
elementFactory.createCodeBlockFromText(replacementText,
|
||||
null);
|
||||
body.replace(block);
|
||||
codeStyleManager.reformat(method);
|
||||
} catch(IncorrectOperationException e){
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceVariableName(PsiElement element,
|
||||
String newName,
|
||||
String originalName,
|
||||
StringBuffer out){
|
||||
|
||||
final String text = element.getText();
|
||||
if(element instanceof PsiReferenceExpression){
|
||||
if(text.equals(originalName)){
|
||||
out.append(newName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiElement[] children = element.getChildren();
|
||||
if(children.length == 0){
|
||||
out.append(text);
|
||||
} else{
|
||||
for(int i = 0; i < children.length; i++){
|
||||
final PsiElement child = children[i];
|
||||
replaceVariableName(child, newName,
|
||||
originalName, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new AssignmentToMethodParameterVisitor(this, inspectionManager,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static class AssignmentToMethodParameterVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private AssignmentToMethodParameterVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
|
||||
public void visitAssignmentExpression(PsiAssignmentExpression expression){
|
||||
super.visitAssignmentExpression(expression);
|
||||
if(!WellFormednessUtils.isWellFormed(expression)){
|
||||
return;
|
||||
@@ -41,56 +141,56 @@ public class AssignmentToMethodParameterInspection extends ExpressionInspection
|
||||
checkForMethodParam(lhs);
|
||||
}
|
||||
|
||||
public void visitPrefixExpression(PsiPrefixExpression expression) {
|
||||
public void visitPrefixExpression(PsiPrefixExpression expression){
|
||||
super.visitPrefixExpression(expression);
|
||||
final PsiJavaToken sign = expression.getOperationSign();
|
||||
if (sign == null) {
|
||||
if(sign == null){
|
||||
return;
|
||||
}
|
||||
final IElementType tokenType = sign.getTokenType();
|
||||
if (!tokenType.equals(JavaTokenType.PLUSPLUS) &&
|
||||
!tokenType.equals(JavaTokenType.MINUSMINUS)) {
|
||||
if(!tokenType.equals(JavaTokenType.PLUSPLUS) &&
|
||||
!tokenType.equals(JavaTokenType.MINUSMINUS)){
|
||||
return;
|
||||
}
|
||||
final PsiExpression operand = expression.getOperand();
|
||||
if (operand == null) {
|
||||
if(operand == null){
|
||||
return;
|
||||
}
|
||||
checkForMethodParam(operand);
|
||||
}
|
||||
|
||||
public void visitPostfixExpression(PsiPostfixExpression expression) {
|
||||
public void visitPostfixExpression(PsiPostfixExpression expression){
|
||||
super.visitPostfixExpression(expression);
|
||||
final PsiJavaToken sign = expression.getOperationSign();
|
||||
if (sign == null) {
|
||||
if(sign == null){
|
||||
return;
|
||||
}
|
||||
final IElementType tokenType = sign.getTokenType();
|
||||
if (!tokenType.equals(JavaTokenType.PLUSPLUS) &&
|
||||
!tokenType.equals(JavaTokenType.MINUSMINUS)) {
|
||||
if(!tokenType.equals(JavaTokenType.PLUSPLUS) &&
|
||||
!tokenType.equals(JavaTokenType.MINUSMINUS)){
|
||||
return;
|
||||
}
|
||||
final PsiExpression operand = expression.getOperand();
|
||||
if (operand == null) {
|
||||
if(operand == null){
|
||||
return;
|
||||
}
|
||||
checkForMethodParam(operand);
|
||||
}
|
||||
|
||||
private void checkForMethodParam(PsiExpression expression) {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
private void checkForMethodParam(PsiExpression expression){
|
||||
if(!(expression instanceof PsiReferenceExpression)){
|
||||
return;
|
||||
}
|
||||
final PsiReferenceExpression ref = (PsiReferenceExpression) expression;
|
||||
final PsiReferenceExpression ref =
|
||||
(PsiReferenceExpression) expression;
|
||||
final PsiElement variable = ref.resolve();
|
||||
if (!(variable instanceof PsiParameter)) {
|
||||
if(!(variable instanceof PsiParameter)){
|
||||
return;
|
||||
}
|
||||
if (((PsiParameter)variable).getDeclarationScope() instanceof PsiCatchSection) {
|
||||
if(((PsiParameter) variable).getDeclarationScope() instanceof PsiCatchSection){
|
||||
return;
|
||||
}
|
||||
registerError(expression);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.*;
|
||||
|
||||
public class ImplicitCallToSuperInspection extends MethodInspection {
|
||||
private final AddExplicitSuperCall fix = new AddExplicitSuperCall();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Implicit call to super()";
|
||||
@@ -24,7 +25,7 @@ public class ImplicitCallToSuperInspection extends MethodInspection {
|
||||
}
|
||||
|
||||
public InspectionGadgetsFix buildFix(PsiElement location) {
|
||||
return new AddExplicitSuperCall();
|
||||
return fix;
|
||||
}
|
||||
|
||||
private static class AddExplicitSuperCall extends InspectionGadgetsFix {
|
||||
|
||||
+8
-4
@@ -3,10 +3,8 @@ package com.siyeh.ig.confusing;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.StatementInspection;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.ExtractMethodFix;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import com.siyeh.ig.ui.SingleIntegerFieldOptionsPanel;
|
||||
|
||||
@@ -17,6 +15,8 @@ public class OverlyComplexArithmeticExpressionInspection extends StatementInspec
|
||||
|
||||
public int m_limit = TERM_LIMIT; //this is public for the DefaultJDOMExternalizer thingy
|
||||
|
||||
private InspectionGadgetsFix fix = new ExtractMethodFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Overly complex arithmetic expression";
|
||||
}
|
||||
@@ -38,6 +38,10 @@ public class OverlyComplexArithmeticExpressionInspection extends StatementInspec
|
||||
return "Overly complex arithmetic expression #loc";
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new SwitchStatementWithTooManyBranchesVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
+12
-4
@@ -3,10 +3,8 @@ package com.siyeh.ig.confusing;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.StatementInspection;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.ExtractMethodFix;
|
||||
import com.siyeh.ig.ui.SingleIntegerFieldOptionsPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -16,6 +14,8 @@ public class OverlyComplexBooleanExpressionInspection extends StatementInspectio
|
||||
|
||||
public int m_limit = TERM_LIMIT; //this is public for the DefaultJDOMExternalizer thingy
|
||||
|
||||
private InspectionGadgetsFix fix = new ExtractMethodFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Overly complex boolean expression";
|
||||
}
|
||||
@@ -33,6 +33,14 @@ public class OverlyComplexBooleanExpressionInspection extends StatementInspectio
|
||||
this, "m_limit");
|
||||
}
|
||||
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
|
||||
return true;
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
protected String buildErrorString(PsiElement location) {
|
||||
return "Overly complex boolean expression #loc";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.siyeh.ig.fixes;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.RefactoringActionHandlerFactory;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
|
||||
public class ExtractMethodFix extends InspectionGadgetsFix {
|
||||
|
||||
public String getName() {
|
||||
return "Extract method";
|
||||
}
|
||||
|
||||
public void applyFix(Project project, ProblemDescriptor problemDescriptor) {
|
||||
final PsiExpression expression = (PsiExpression) problemDescriptor.getPsiElement();
|
||||
final RefactoringActionHandlerFactory factory =
|
||||
RefactoringActionHandlerFactory.getInstance();
|
||||
final RefactoringActionHandler inlineHandler = factory.createExtractMethodHandler();
|
||||
inlineHandler.invoke(project, new PsiElement[]{expression}, null);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import org.jdom.Element;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -19,6 +20,7 @@ import java.util.List;
|
||||
|
||||
public class QuestionableNameInspection extends ClassInspection{
|
||||
public String nameCheckString = "foo,bar,baz";
|
||||
private final RenameFix fix = new RenameFix();
|
||||
|
||||
private List nameList = new ArrayList(32);
|
||||
|
||||
@@ -72,6 +74,14 @@ public class QuestionableNameInspection extends ClassInspection{
|
||||
return form.getContentPanel();
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location){
|
||||
return "Questionable name '#ref'. #loc ";
|
||||
}
|
||||
|
||||
+54
-8
@@ -1,20 +1,18 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.MethodInspection;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.ui.SingleCheckboxOptionsPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class SynchronizedMethodInspection extends MethodInspection {
|
||||
public boolean m_includeNativeMethods = true;
|
||||
private SynchronizedMethodFix fix = new SynchronizedMethodFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "'synchronized' method";
|
||||
@@ -30,6 +28,16 @@ public class SynchronizedMethodInspection extends MethodInspection {
|
||||
return "Method " + method.getName() + "() declared '#ref' #loc";
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
final PsiMethod method = (PsiMethod) location.getParent().getParent();
|
||||
if(method.getBody()== null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return fix;
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new SynchronizedMethodVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
@@ -39,6 +47,44 @@ public class SynchronizedMethodInspection extends MethodInspection {
|
||||
this, "m_includeNativeMethods");
|
||||
}
|
||||
|
||||
public static class SynchronizedMethodFix extends InspectionGadgetsFix{
|
||||
public String getName(){
|
||||
return "Move synchronization into method";
|
||||
}
|
||||
|
||||
public void applyFix(Project project,
|
||||
ProblemDescriptor problemDescriptor){
|
||||
try{
|
||||
final PsiElement nameElement =
|
||||
problemDescriptor.getPsiElement();
|
||||
final PsiMethod method =
|
||||
(PsiMethod) nameElement.getParent().getParent();
|
||||
method.getModifierList()
|
||||
.setModifierProperty(PsiModifier.SYNCHRONIZED, false);
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
final String text = body.getText();
|
||||
final String replacementText;
|
||||
if(method.hasModifierProperty(PsiModifier.STATIC)){
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final String className = containingClass.getName();
|
||||
replacementText = "{ synchronized(" + className + ".class){" +
|
||||
text.substring(1) + '}';
|
||||
} else{
|
||||
replacementText = "{ synchronized(this){" + text.substring(1) + '}';
|
||||
}
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiElementFactory elementFactory =
|
||||
psiManager.getElementFactory();
|
||||
final PsiCodeBlock block =
|
||||
elementFactory.createCodeBlockFromText(replacementText,
|
||||
null);
|
||||
body.replace(block);
|
||||
psiManager.getCodeStyleManager().reformat(method);
|
||||
} catch(IncorrectOperationException e){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SynchronizedMethodVisitor extends BaseInspectionVisitor {
|
||||
private SynchronizedMethodVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
|
||||
@@ -61,9 +61,13 @@ public class ExtendsObjectInspection extends ClassInspection {
|
||||
final PsiJavaCodeReferenceElement[] elements = extendsList.getReferenceElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
final PsiJavaCodeReferenceElement element = elements[i];
|
||||
final String text = element.getText();
|
||||
if ("Object".equals(text) || "java.lang.Object".equals(text)) {
|
||||
registerClassError(aClass);
|
||||
final PsiElement referent = element.resolve();
|
||||
if(referent instanceof PsiClass)
|
||||
{
|
||||
final String className = ((PsiClass) referent).getQualifiedName();
|
||||
if ( "java.lang.Object".equals(className)) {
|
||||
registerClassError(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -1,11 +1,13 @@
|
||||
package com.siyeh.igtest.threading;
|
||||
|
||||
public class SynchronizedMethodInspection
|
||||
{
|
||||
public synchronized void fooBar()
|
||||
{
|
||||
|
||||
public class SynchronizedMethodInspection {
|
||||
public synchronized void fooBar() {
|
||||
System.out.println("foo");
|
||||
}
|
||||
|
||||
|
||||
public static synchronized void bar() {
|
||||
System.out.println("foo");
|
||||
}
|
||||
|
||||
public synchronized native void fooBaz();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user