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:
@@ -14,15 +14,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/extensions.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntryProperties />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/InspectionGadgetsSVN.iml" filepath="$PROJECT_DIR$/InspectionGadgetsSVN.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" project-jdk-name="IDEA 3212" />
|
||||
<component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" project-jdk-name="IDEA 3214" />
|
||||
<component name="RmicSettings">
|
||||
<option name="IS_EANABLED" value="false" />
|
||||
<option name="DEBUGGING_INFO" value="true" />
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
Split "Portability Issues" into "Portability Issues" and "JDK issues"
|
||||
QuickFix for "Confusing else Branch"
|
||||
QuickFix for "Integer division in floating point context"
|
||||
Quickfix for "Non-serializable class with..."
|
||||
Quickfix for "Unnecessary default"
|
||||
More detectors and quickfixes for "Simplifiable JUnit Assertion"
|
||||
|
||||
|
||||
+1
-6
@@ -46,15 +46,10 @@ public class NonShortCircuitBooleanInspection extends ExpressionInspection {
|
||||
if (tokenType.equals(JavaTokenType.AND)) {
|
||||
return "&&";
|
||||
}
|
||||
if (tokenType.equals(JavaTokenType.ANDEQ)) {
|
||||
return "&&=";
|
||||
}
|
||||
if (tokenType.equals(JavaTokenType.OR)) {
|
||||
else {
|
||||
return "||";
|
||||
}
|
||||
return "||=";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
|
||||
+53
-29
@@ -6,60 +6,84 @@ import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ClassInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.ui.SingleCheckboxOptionsPanel;
|
||||
|
||||
public class ClassWithoutNoArgConstructorInspection extends ClassInspection {
|
||||
import javax.swing.*;
|
||||
|
||||
public String getDisplayName() {
|
||||
public class ClassWithoutNoArgConstructorInspection extends ClassInspection{
|
||||
public boolean m_ignoreClassesWithNoConstructors = true;
|
||||
|
||||
|
||||
public String getDisplayName(){
|
||||
return "Class without no-arg constructor";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName() {
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.CLASSLAYOUT_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
public JComponent createOptionsPanel(){
|
||||
return new SingleCheckboxOptionsPanel("Ignore if class has default constructor",
|
||||
this,
|
||||
"m_ignoreClassesWithNoConstructors");
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location){
|
||||
return "#ref has no no-arg constructor #loc";
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new ClassWithoutNoArgConstructorVisitor(this, inspectionManager, onTheFly);
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new ClassWithoutNoArgConstructorVisitor(this, inspectionManager,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static class ClassWithoutNoArgConstructorVisitor extends BaseInspectionVisitor {
|
||||
private ClassWithoutNoArgConstructorVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
private class ClassWithoutNoArgConstructorVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private ClassWithoutNoArgConstructorVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitClass(PsiClass aClass) {
|
||||
public void visitClass(PsiClass aClass){
|
||||
// no call to super, so it doesn't drill down
|
||||
if (aClass.isInterface() || aClass.isEnum() || aClass.isAnnotationType()) {
|
||||
if(aClass.isInterface() || aClass.isEnum() ||
|
||||
aClass.isAnnotationType()){
|
||||
return;
|
||||
}
|
||||
if (aClass.getNameIdentifier() == null) {
|
||||
if(aClass.getNameIdentifier() == null){
|
||||
return; //a very hacky test for anonymous classes
|
||||
}
|
||||
if (classHasNoArgConstructor(aClass)) {
|
||||
if(m_ignoreClassesWithNoConstructors &&
|
||||
!classHasConstructor(aClass)){
|
||||
return;
|
||||
}
|
||||
if(classHasNoArgConstructor(aClass)){
|
||||
return;
|
||||
}
|
||||
registerClassError(aClass);
|
||||
}
|
||||
|
||||
private static boolean classHasNoArgConstructor(PsiClass aClass) {
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
final PsiMethod method = methods[i];
|
||||
if (method.isConstructor()) {
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList != null) {
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
if (parameters != null && parameters.length == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean classHasNoArgConstructor(PsiClass aClass){
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
for(int i = 0; i < constructors.length; i++){
|
||||
final PsiMethod constructor = constructors[i];
|
||||
final PsiParameterList parameterList =
|
||||
constructor.getParameterList();
|
||||
if(parameterList != null){
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
if(parameters != null && parameters.length == 0){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean classHasConstructor(PsiClass aClass){
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
return constructors.length != 0;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -79,10 +79,10 @@ public class BadExceptionDeclaredInspection extends MethodInspection {
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
final PsiThrowStatement throwStatement = (PsiThrowStatement) location.getParent();
|
||||
final PsiExpression exception = throwStatement.getException();
|
||||
final PsiType type = exception.getType();
|
||||
final String exceptionName = type.getPresentableText();
|
||||
final PsiJavaCodeReferenceElement reference = (PsiJavaCodeReferenceElement) location;
|
||||
final PsiClass referredClass = (PsiClass) reference.resolve();
|
||||
|
||||
final String exceptionName = referredClass.getName();
|
||||
return "Prohibitted exception '" + exceptionName + "' declared. #loc ";
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class BadExceptionDeclaredInspection extends MethodInspection {
|
||||
});
|
||||
}
|
||||
|
||||
public JComponent getContentPanel() {
|
||||
public JComponent getContentPanel(){
|
||||
return contentPanel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.siyeh.ig.fixes;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
|
||||
public class MakeSerializableFix extends InspectionGadgetsFix {
|
||||
private static final Logger s_logger =
|
||||
Logger.getInstance("MakeSerializableFix");
|
||||
public String getName() {
|
||||
return "Make class Serializable";
|
||||
}
|
||||
|
||||
public void applyFix(Project project, ProblemDescriptor problemDescriptor) {
|
||||
final PsiElement nameElement = problemDescriptor.getPsiElement();
|
||||
final PsiClass containingClass = (PsiClass) PsiTreeUtil.getParentOfType(nameElement, PsiClass.class);
|
||||
final PsiManager psiManager = containingClass.getManager();
|
||||
final PsiElementFactory elementFactory = psiManager.getElementFactory();
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
PsiJavaCodeReferenceElement ref = elementFactory.createReferenceElementByFQClassName("java.io.Serializable", scope);
|
||||
try{
|
||||
containingClass.getImplementsList().add(ref);
|
||||
} catch(IncorrectOperationException e){
|
||||
s_logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -6,6 +6,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import com.siyeh.ig.psiutils.BoolUtils;
|
||||
|
||||
public class StringEqualsEmptyStringInspection extends ExpressionInspection {
|
||||
private final StringEqualsEmptyStringFix fix = new StringEqualsEmptyStringFix();
|
||||
@@ -37,7 +38,15 @@ public class StringEqualsEmptyStringInspection extends ExpressionInspection {
|
||||
final PsiExpression call = (PsiExpression) expression.getParent();
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
final String qualifierText = qualifier.getText();
|
||||
replaceExpression(project, call, qualifierText + ".length()==0");
|
||||
final PsiElement parent = call.getParent();
|
||||
if(parent instanceof PsiExpression && BoolUtils.isNegation( (PsiExpression) parent))
|
||||
{
|
||||
replaceExpression(project, (PsiExpression) parent, qualifierText + ".length()!=0");
|
||||
}
|
||||
else
|
||||
{
|
||||
replaceExpression(project, call, qualifierText + ".length()==0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+63
-35
@@ -10,10 +10,10 @@ import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TrivialStringConcatenationInspection extends ExpressionInspection {
|
||||
public class TrivialStringConcatenationInspection extends ExpressionInspection{
|
||||
private static final Map s_typeToWrapperMap = new HashMap(6);
|
||||
|
||||
static {
|
||||
static{
|
||||
s_typeToWrapperMap.put("short", "Short");
|
||||
s_typeToWrapperMap.put("int", "Integer");
|
||||
s_typeToWrapperMap.put("long", "Long");
|
||||
@@ -23,97 +23,125 @@ public class TrivialStringConcatenationInspection extends ExpressionInspection {
|
||||
s_typeToWrapperMap.put("byte", "Byte");
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
public String getDisplayName(){
|
||||
return "Concatenation with empty string";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName() {
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.PERFORMANCE_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
final String replacementString = calculateReplacementExpression(location);
|
||||
public String buildErrorString(PsiElement location){
|
||||
final String replacementString =
|
||||
calculateReplacementExpression(location);
|
||||
return "#ref can be simplified to " + replacementString + " #loc";
|
||||
}
|
||||
|
||||
private static String calculateReplacementExpression(PsiElement location) {
|
||||
private static String calculateReplacementExpression(PsiElement location){
|
||||
final PsiBinaryExpression expression = (PsiBinaryExpression) location;
|
||||
final PsiExpression lOperand = expression.getLOperand();
|
||||
final PsiExpression rOperand = expression.getROperand();
|
||||
final PsiExpression replacement;
|
||||
if (isEmptyString(lOperand)) {
|
||||
if(isEmptyString(lOperand)){
|
||||
replacement = rOperand;
|
||||
} else {
|
||||
} else{
|
||||
|
||||
replacement = lOperand;
|
||||
}
|
||||
final PsiType type = replacement.getType();
|
||||
final String text = type.getCanonicalText();
|
||||
if (s_typeToWrapperMap.containsKey(text)) {
|
||||
return s_typeToWrapperMap.get(text) + ".toString(" + replacement.getText() + ')';
|
||||
} else {
|
||||
if(s_typeToWrapperMap.containsKey(text)){
|
||||
return s_typeToWrapperMap.get(text) + ".toString(" +
|
||||
replacement.getText() + ')';
|
||||
} else if("java.lang.String".equals(text)){
|
||||
return replacement.getText();
|
||||
} else{
|
||||
return replacement.getText() + ".toString()";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public InspectionGadgetsFix buildFix(PsiElement location) {
|
||||
public InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return new UnnecessaryTemporaryObjectFix((PsiBinaryExpression) location);
|
||||
}
|
||||
|
||||
private static class UnnecessaryTemporaryObjectFix extends InspectionGadgetsFix {
|
||||
private static class UnnecessaryTemporaryObjectFix
|
||||
extends InspectionGadgetsFix{
|
||||
private final String m_name;
|
||||
|
||||
private UnnecessaryTemporaryObjectFix(PsiBinaryExpression expression) {
|
||||
private UnnecessaryTemporaryObjectFix(PsiBinaryExpression expression){
|
||||
super();
|
||||
m_name = "Replace with " + calculateReplacementExpression(expression);
|
||||
m_name = "Replace with " +
|
||||
calculateReplacementExpression(expression);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getName(){
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public void applyFix(Project project, ProblemDescriptor descriptor) {
|
||||
final PsiBinaryExpression expression = (PsiBinaryExpression) descriptor.getPsiElement();
|
||||
final String newExpression = calculateReplacementExpression(expression);
|
||||
public void applyFix(Project project, ProblemDescriptor descriptor){
|
||||
final PsiBinaryExpression expression =
|
||||
(PsiBinaryExpression) descriptor.getPsiElement();
|
||||
final String newExpression =
|
||||
calculateReplacementExpression(expression);
|
||||
replaceExpression(project, expression, newExpression);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new TrivialStringConcatenationVisitor(this, inspectionManager, onTheFly);
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new TrivialStringConcatenationVisitor(this, inspectionManager,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static class TrivialStringConcatenationVisitor extends BaseInspectionVisitor {
|
||||
private TrivialStringConcatenationVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
private class TrivialStringConcatenationVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private TrivialStringConcatenationVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitBinaryExpression(PsiBinaryExpression exp) {
|
||||
public void visitBinaryExpression(PsiBinaryExpression exp){
|
||||
super.visitBinaryExpression(exp);
|
||||
if (!TypeUtils.expressionHasType("java.lang.String", exp)) {
|
||||
if(!TypeUtils.expressionHasType("java.lang.String", exp)){
|
||||
return;
|
||||
}
|
||||
final PsiExpression lhs = exp.getLOperand();
|
||||
if (lhs == null) {
|
||||
if(lhs == null){
|
||||
return;
|
||||
}
|
||||
final PsiExpression rhs = exp.getROperand();
|
||||
if (rhs == null) {
|
||||
if(rhs == null){
|
||||
return;
|
||||
}
|
||||
if (!isEmptyString(lhs) && !isEmptyString(rhs)) {
|
||||
return;
|
||||
if(isEmptyString(lhs)){
|
||||
if(isStringLiteral(rhs)){
|
||||
return;
|
||||
}
|
||||
registerError(exp);
|
||||
} else if(isEmptyString(rhs)){
|
||||
if(isStringLiteral(lhs)){
|
||||
return;
|
||||
}
|
||||
registerError(exp);
|
||||
}
|
||||
registerError(exp);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEmptyString(PsiExpression exp) {
|
||||
private static boolean isStringLiteral(PsiExpression expression){
|
||||
if(!(expression instanceof PsiLiteralExpression)){
|
||||
return false;
|
||||
}
|
||||
final PsiType type = expression.getType();
|
||||
if(type == null){
|
||||
return false;
|
||||
}
|
||||
return "java.lang.String".equals(type.getCanonicalText());
|
||||
}
|
||||
|
||||
private static boolean isEmptyString(PsiExpression exp){
|
||||
|
||||
final String text = exp.getText();
|
||||
return "\"\"".equals(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class BoolUtils {
|
||||
super();
|
||||
}
|
||||
|
||||
private static boolean isNegation(PsiExpression exp) {
|
||||
public static boolean isNegation(PsiExpression exp) {
|
||||
if (!(exp instanceof PsiPrefixExpression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
public class ExpectedTypeUtils{
|
||||
|
||||
private ExpectedTypeUtils(){
|
||||
super();
|
||||
}
|
||||
@@ -20,21 +19,21 @@ public class ExpectedTypeUtils{
|
||||
wrappedExp = (PsiExpression) context;
|
||||
context = context.getParent();
|
||||
}
|
||||
if (context instanceof PsiField) {
|
||||
final PsiField field = (PsiField)context;
|
||||
final PsiExpression initializer = field.getInitializer();
|
||||
if (wrappedExp.equals(initializer)) {
|
||||
return field.getType();
|
||||
}
|
||||
}
|
||||
else if (context instanceof PsiVariable){
|
||||
if(context instanceof PsiField){
|
||||
final PsiField field = (PsiField) context;
|
||||
final PsiExpression initializer = field.getInitializer();
|
||||
if(wrappedExp.equals(initializer)){
|
||||
return field.getType();
|
||||
}
|
||||
} else if(context instanceof PsiVariable){
|
||||
final PsiVariable psiVariable = (PsiVariable) context;
|
||||
return psiVariable.getType();
|
||||
} else if(context instanceof PsiReferenceExpression){
|
||||
final PsiReferenceExpression ref = (PsiReferenceExpression) context;
|
||||
final PsiElement parent = ref.getParent();
|
||||
if(parent instanceof PsiMethodCallExpression){
|
||||
final PsiMethod psiMethod = ((PsiMethodCallExpression) parent).resolveMethod();
|
||||
final PsiMethod psiMethod =
|
||||
((PsiMethodCallExpression) parent).resolveMethod();
|
||||
if(psiMethod == null){
|
||||
return null;
|
||||
}
|
||||
@@ -42,33 +41,39 @@ public class ExpectedTypeUtils{
|
||||
final PsiElementFactory factory = manager.getElementFactory();
|
||||
return factory.createType(aClass);
|
||||
} else if(parent instanceof PsiReferenceExpression){
|
||||
final PsiElement elt = ((PsiReferenceExpression) parent).resolve();
|
||||
final PsiElement elt =
|
||||
((PsiReferenceExpression) parent).resolve();
|
||||
if(elt instanceof PsiField){
|
||||
final PsiClass aClass = ((PsiField) elt).getContainingClass();
|
||||
final PsiElementFactory factory = manager.getElementFactory();
|
||||
final PsiClass aClass =
|
||||
((PsiField) elt).getContainingClass();
|
||||
final PsiElementFactory factory =
|
||||
manager.getElementFactory();
|
||||
return factory.createType(aClass);
|
||||
} else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
} else if(context instanceof PsiArrayInitializerExpression){
|
||||
final PsiArrayInitializerExpression initializer = (PsiArrayInitializerExpression) context;
|
||||
final PsiArrayInitializerExpression initializer =
|
||||
(PsiArrayInitializerExpression) context;
|
||||
final PsiArrayType arrayType = (PsiArrayType) initializer.getType();
|
||||
if(arrayType != null){
|
||||
return arrayType.getComponentType();
|
||||
}
|
||||
} else if(context instanceof PsiArrayAccessExpression){
|
||||
final PsiArrayAccessExpression accessExpression = (PsiArrayAccessExpression) context;
|
||||
final PsiArrayAccessExpression accessExpression =
|
||||
(PsiArrayAccessExpression) context;
|
||||
if(wrappedExp.equals(accessExpression.getIndexExpression())){
|
||||
return PsiType.INT;
|
||||
}
|
||||
} else if(context instanceof PsiAssignmentExpression){
|
||||
final PsiAssignmentExpression assignment = (PsiAssignmentExpression) context;
|
||||
final PsiAssignmentExpression assignment =
|
||||
(PsiAssignmentExpression) context;
|
||||
final PsiExpression rExpression = assignment.getRExpression();
|
||||
if(rExpression != null){
|
||||
if(rExpression.equals(wrappedExp)){
|
||||
final PsiExpression lExpression = assignment.getLExpression();
|
||||
final PsiExpression lExpression =
|
||||
assignment.getLExpression();
|
||||
PsiType lType = lExpression.getType();
|
||||
if(lType == null){
|
||||
return null;
|
||||
@@ -76,19 +81,24 @@ public class ExpectedTypeUtils{
|
||||
// e.g. String += any type
|
||||
if(TypeUtils.isJavaLangString(lType) &&
|
||||
JavaTokenType.PLUSEQ.equals(
|
||||
assignment.getOperationSign().getTokenType())){
|
||||
assignment.getOperationSign()
|
||||
.getTokenType())){
|
||||
return rExpression.getType();
|
||||
}
|
||||
return lType;
|
||||
}
|
||||
}
|
||||
} else if(context instanceof PsiDeclarationStatement){
|
||||
final PsiDeclarationStatement assignment = (PsiDeclarationStatement) context;
|
||||
final PsiElement[] declaredElements = assignment.getDeclaredElements();
|
||||
final PsiDeclarationStatement assignment =
|
||||
(PsiDeclarationStatement) context;
|
||||
final PsiElement[] declaredElements =
|
||||
assignment.getDeclaredElements();
|
||||
for(int i = 0; i < declaredElements.length; i++){
|
||||
if(declaredElements[i] instanceof PsiVariable){
|
||||
final PsiVariable declaredElement = (PsiVariable) declaredElements[i];
|
||||
final PsiExpression initializer = declaredElement.getInitializer();
|
||||
final PsiVariable declaredElement =
|
||||
(PsiVariable) declaredElements[i];
|
||||
final PsiExpression initializer =
|
||||
declaredElement.getInitializer();
|
||||
if(wrappedExp.equals(initializer)){
|
||||
return declaredElement.getType();
|
||||
}
|
||||
@@ -129,10 +139,12 @@ public class ExpectedTypeUtils{
|
||||
final PsiPrefixExpression prefixExp = (PsiPrefixExpression) context;
|
||||
return prefixExp.getType();
|
||||
} else if(context instanceof PsiPostfixExpression){
|
||||
final PsiPostfixExpression postfixExp = (PsiPostfixExpression) context;
|
||||
final PsiPostfixExpression postfixExp =
|
||||
(PsiPostfixExpression) context;
|
||||
return postfixExp.getType();
|
||||
} else if(context instanceof PsiConditionalExpression){
|
||||
final PsiConditionalExpression conditional = (PsiConditionalExpression) context;
|
||||
final PsiConditionalExpression conditional =
|
||||
(PsiConditionalExpression) context;
|
||||
final PsiExpression condition = conditional.getCondition();
|
||||
if(condition.equals(wrappedExp)){
|
||||
return PsiType.BOOLEAN;
|
||||
@@ -140,7 +152,8 @@ public class ExpectedTypeUtils{
|
||||
return conditional.getType();
|
||||
} else if(context instanceof PsiExpressionList){
|
||||
final PsiExpressionList expList = (PsiExpressionList) context;
|
||||
final PsiMethod method = ExpectedTypeUtils.findCalledMethod(expList);
|
||||
final PsiMethod method =
|
||||
ExpectedTypeUtils.findCalledMethod(expList);
|
||||
if(method == null){
|
||||
return null;
|
||||
}
|
||||
@@ -149,7 +162,8 @@ public class ExpectedTypeUtils{
|
||||
return ExpectedTypeUtils.getTypeOfParemeter(method,
|
||||
parameterPosition);
|
||||
} else if(context instanceof PsiReturnStatement){
|
||||
final PsiReturnStatement psiReturnStatement = (PsiReturnStatement) context;
|
||||
final PsiReturnStatement psiReturnStatement =
|
||||
(PsiReturnStatement) context;
|
||||
final PsiMethod method = (PsiMethod) PsiTreeUtil.getParentOfType(
|
||||
psiReturnStatement, PsiMethod.class);
|
||||
if(method == null){
|
||||
@@ -225,7 +239,8 @@ public class ExpectedTypeUtils{
|
||||
private static PsiMethod findCalledMethod(PsiExpressionList expList){
|
||||
final PsiElement parent = expList.getParent();
|
||||
if(parent instanceof PsiMethodCallExpression){
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) parent;
|
||||
final PsiMethodCallExpression methodCall =
|
||||
(PsiMethodCallExpression) parent;
|
||||
return methodCall.resolveMethod();
|
||||
} else if(parent instanceof PsiNewExpression){
|
||||
final PsiNewExpression psiNewExpression = (PsiNewExpression) parent;
|
||||
@@ -233,5 +248,4 @@ public class ExpectedTypeUtils{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-4
@@ -4,13 +4,12 @@ import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
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.MakeSerializableFix;
|
||||
import com.siyeh.ig.psiutils.SerializationUtils;
|
||||
|
||||
public class NonSerializableWithSerialVersionUIDFieldInspection extends ClassInspection {
|
||||
private MakeSerializableFix fix = new MakeSerializableFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Non-serializable class with serialVersionUID";
|
||||
@@ -24,6 +23,10 @@ public class NonSerializableWithSerialVersionUIDFieldInspection extends ClassIns
|
||||
return "Non-serializable class #ref defines a serialVersionUID field #loc";
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new NonSerializableWithSerialVersionUIDVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
+35
-24
@@ -3,61 +3,72 @@ package com.siyeh.ig.serialization;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
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.MakeSerializableFix;
|
||||
import com.siyeh.ig.psiutils.SerializationUtils;
|
||||
|
||||
public class NonSerializableWithSerializationMethodsInspection extends ClassInspection {
|
||||
public class NonSerializableWithSerializationMethodsInspection
|
||||
extends ClassInspection{
|
||||
private MakeSerializableFix fix = new MakeSerializableFix();
|
||||
|
||||
public String getDisplayName() {
|
||||
public String getDisplayName(){
|
||||
return "Non-serializable class with 'readObject()' or 'writeObject()'";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName() {
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.SERIALIZATION_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location) {
|
||||
protected InspectionGadgetsFix buildFix(PsiElement location){
|
||||
return fix;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location){
|
||||
final PsiClass aClass = (PsiClass) location.getParent();
|
||||
final boolean hasReadObject = SerializationUtils.hasReadObject(aClass);
|
||||
final boolean hasWriteObject = SerializationUtils.hasWriteObject(aClass);
|
||||
final boolean hasWriteObject =
|
||||
SerializationUtils.hasWriteObject(aClass);
|
||||
|
||||
if (hasReadObject && hasWriteObject) {
|
||||
if(hasReadObject && hasWriteObject){
|
||||
return "Non-serializable class #ref defines readObject() and writeObject() #loc";
|
||||
} else if (hasWriteObject) {
|
||||
} else if(hasWriteObject){
|
||||
return "Non-serializable class #ref defines writeObject() #loc";
|
||||
} else {
|
||||
} else{
|
||||
return "Non-serializable class #ref defines readObject() #loc";
|
||||
}
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new NonserializableDefinesSerializationMethodsVisitor(this, inspectionManager, onTheFly);
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new NonserializableDefinesSerializationMethodsVisitor(this,
|
||||
inspectionManager,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static class NonserializableDefinesSerializationMethodsVisitor extends BaseInspectionVisitor {
|
||||
private NonserializableDefinesSerializationMethodsVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
private static class NonserializableDefinesSerializationMethodsVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private NonserializableDefinesSerializationMethodsVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitClass(PsiClass aClass) {
|
||||
public void visitClass(PsiClass aClass){
|
||||
// no call to super, so it doesn't drill down
|
||||
if (aClass.isInterface() || aClass.isAnnotationType()) {
|
||||
if(aClass.isInterface() || aClass.isAnnotationType()){
|
||||
return;
|
||||
}
|
||||
if (SerializationUtils.isSerializable(aClass)) {
|
||||
if(SerializationUtils.isSerializable(aClass)){
|
||||
return;
|
||||
}
|
||||
final boolean hasReadObject = SerializationUtils.hasReadObject(aClass);
|
||||
final boolean hasWriteObject = SerializationUtils.hasWriteObject(aClass);
|
||||
if (!hasWriteObject && !hasReadObject) {
|
||||
final boolean hasReadObject =
|
||||
SerializationUtils.hasReadObject(aClass);
|
||||
final boolean hasWriteObject =
|
||||
SerializationUtils.hasWriteObject(aClass);
|
||||
if(!hasWriteObject && !hasReadObject){
|
||||
return;
|
||||
}
|
||||
registerClassError(aClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,12 +72,40 @@ public class MissortedModifiersInspection extends ClassInspection {
|
||||
Collections.sort(simpleModifiers, new ModifierComparator());
|
||||
clearModifiers(simpleModifiers, modifierList);
|
||||
addModifiersInOrder(simpleModifiers, modifierList);
|
||||
|
||||
}
|
||||
|
||||
private static Map NAME_TO_KEYWORD_TYPE_MAP =
|
||||
new HashMap();
|
||||
|
||||
static{
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PUBLIC, JavaTokenType.PUBLIC_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PROTECTED,
|
||||
JavaTokenType.PROTECTED_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PRIVATE,
|
||||
JavaTokenType.PRIVATE_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.STATIC,
|
||||
JavaTokenType.STATIC_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.ABSTRACT,
|
||||
JavaTokenType. ABSTRACT_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.FINAL,
|
||||
JavaTokenType.FINAL_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.NATIVE,
|
||||
JavaTokenType.NATIVE_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.SYNCHRONIZED,
|
||||
JavaTokenType.SYNCHRONIZED_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.STRICTFP,
|
||||
JavaTokenType.STRICTFP_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.TRANSIENT,
|
||||
JavaTokenType.TRANSIENT_KEYWORD);
|
||||
NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.VOLATILE,
|
||||
JavaTokenType.VOLATILE_KEYWORD);
|
||||
}
|
||||
private static void addModifiersInOrder(List modifiers,
|
||||
PsiModifierList modifierList) {
|
||||
for (Iterator iterator = modifiers.iterator(); iterator.hasNext();) {
|
||||
final String modifier = (String) iterator.next();
|
||||
final JavaTokenType keyword = (JavaTokenType) NAME_TO_KEYWORD_TYPE_MAP.get(modifier);
|
||||
try {
|
||||
modifierList.setModifierProperty(modifier, true);
|
||||
} catch (IncorrectOperationException e) {
|
||||
|
||||
@@ -64,10 +64,16 @@ public class UnnecessaryReturnInspection extends StatementInspection{
|
||||
final PsiMethod method =
|
||||
(PsiMethod) PsiTreeUtil.getParentOfType(statement,
|
||||
PsiMethod.class);
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!method.isConstructor() && !returnType.equals(PsiType.VOID)){
|
||||
if(method == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!method.isConstructor()){
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!PsiType.VOID.equals(returnType)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
if(body == null){
|
||||
return;
|
||||
|
||||
+5
@@ -51,6 +51,11 @@ public class MethodOverloadsParentMethodInspection extends MethodInspection {
|
||||
return;
|
||||
}
|
||||
|
||||
final PsiMethod[] superMethods = PsiSuperMethodUtil.findSuperMethods(method);
|
||||
if(superMethods!=null && superMethods.length!=0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PsiClass ancestorClass = aClass.getSuperClass();
|
||||
final Set visitedClasses = new HashSet();
|
||||
while (ancestorClass != null) {
|
||||
|
||||
@@ -3,5 +3,10 @@
|
||||
<font face="verdana" size="-1">
|
||||
This inspection reports any instances of a classes without a no-argument constructor.
|
||||
Such constructors are necessary in some contexts if a class is to be created reflexively.
|
||||
<p>
|
||||
Use the checkbox below to indicate that this inspection should ignore classes which
|
||||
contain no explicit constructors, and thus are provided a default no-argument constructor
|
||||
by the compiler.
|
||||
</p>
|
||||
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
|
||||
</html>
|
||||
@@ -4,5 +4,6 @@
|
||||
This inspection reports instances of string concatenation where one of the arguments is the
|
||||
empty string. Such concatenation is unnecessary and inefficient, particularly when used as
|
||||
an idiom for formatting non-String objects or primitives into Strings.
|
||||
|
||||
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
|
||||
</html>
|
||||
+10
@@ -74,3 +74,13 @@ public class ImplicitNumericConversionInspection
|
||||
System.out.println(d);
|
||||
}
|
||||
}
|
||||
|
||||
class TestQuickFix{
|
||||
public static final long ONE_HOUR = 3600L;
|
||||
|
||||
public void test(){
|
||||
long time = ONE_HOUR;
|
||||
long minutes = (time % (3600 * 1000)) / 1000;
|
||||
long hours = (time % (24 * 3600 * 1000)) / (3600 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -4,5 +4,10 @@ public class TrivialStringConcatenationInspection {
|
||||
|
||||
public void foo() {
|
||||
final String foo = "" + 4 + "" + 3;
|
||||
String bar = "" + new Integer(4);
|
||||
Float aFloat = new Float(3.0);
|
||||
String baz = "" + aFloat;
|
||||
|
||||
String trivial = "" + " ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ import java.util.List;
|
||||
|
||||
public class MethodOverloadsChild extends MethodOverloadsParent
|
||||
{
|
||||
public void foo(Integer x)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void reverse(ArrayList l)
|
||||
{
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.siyeh.igtest.visibility;
|
||||
|
||||
|
||||
public class MethodOverloadsGrandparent {
|
||||
|
||||
public void foo(Object x)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+6
-1
@@ -3,8 +3,13 @@ package com.siyeh.igtest.visibility;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MethodOverloadsParent
|
||||
public class MethodOverloadsParent extends MethodOverloadsGrandparent
|
||||
{
|
||||
public void foo(Integer x)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void reverse(List l)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user