Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2014-02-18 15:30:33 +04:00
7 changed files with 74 additions and 21 deletions
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NonNls;
name = "ExportToHTMLSettings",
storages = {
@Storage(
file = StoragePathMacros.PROJECT_FILE
file = StoragePathMacros.WORKSPACE_FILE
)}
)
public class ExportToHTMLSettings implements PersistentStateComponent<ExportToHTMLSettings> {
@@ -15,17 +15,17 @@
*/
package com.siyeh.ig.bugs;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.psi.*;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.ExceptionUtils;
import com.siyeh.ig.psiutils.IteratorUtils;
import com.siyeh.ig.psiutils.MethodUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import java.util.List;
public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
extends BaseInspection {
@@ -65,9 +65,7 @@ public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
HardcodedMethodConstants.NEXT)) {
return;
}
final Set<PsiClassType> exceptions =
ExceptionUtils.calculateExceptionsThrown(method);
for (final PsiType exception : exceptions) {
for (final PsiType exception : ExceptionUtil.getThrownExceptions(method)) {
if (exception.equalsToText(
"java.util.NoSuchElementException")) {
return;
@@ -103,8 +101,7 @@ public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
if (method == null) {
return;
}
final Set<PsiClassType> exceptions =
ExceptionUtils.calculateExceptionsThrown(method);
final List<PsiClassType> exceptions = ExceptionUtil.getThrownExceptions(method);
for (final PsiType exception : exceptions) {
if (exception.equalsToText(
"java.util.NoSuchElementException")) {
@@ -61,8 +61,7 @@ public class StaticCallOnSubclassInspection extends BaseInspection {
@Override
@NotNull
public String getName() {
return InspectionGadgetsBundle.message(
"static.method.via.subclass.rationalize.quickfix");
return InspectionGadgetsBundle.message("static.method.via.subclass.rationalize.quickfix");
}
@Override
@NotNull
@@ -73,15 +72,12 @@ public class StaticCallOnSubclassInspection extends BaseInspection {
@Override
public void doFix(Project project, ProblemDescriptor descriptor)
throws IncorrectOperationException {
final PsiIdentifier name =
(PsiIdentifier)descriptor.getPsiElement();
final PsiReferenceExpression expression =
(PsiReferenceExpression)name.getParent();
final PsiIdentifier name = (PsiIdentifier)descriptor.getPsiElement();
final PsiReferenceExpression expression = (PsiReferenceExpression)name.getParent();
if (expression == null) {
return;
}
final PsiMethodCallExpression call =
(PsiMethodCallExpression)expression.getParent();
final PsiMethodCallExpression call = (PsiMethodCallExpression)expression.getParent();
final String methodName = expression.getReferenceName();
if (call == null) {
return;
@@ -95,11 +91,9 @@ public class StaticCallOnSubclassInspection extends BaseInspection {
if (containingClass == null) {
return;
}
final String containingClassName =
containingClass.getQualifiedName();
final String containingClassName = containingClass.getQualifiedName();
final String argText = argumentList.getText();
PsiReplacementUtil.replaceExpressionAndShorten(call, containingClassName + '.' +
methodName + argText);
PsiReplacementUtil.replaceExpressionAndShorten(call, containingClassName + '.' + call.getTypeArgumentList().getText() + methodName + argText);
}
}
@@ -16,6 +16,7 @@
package com.siyeh.ig.junit;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.siyeh.InspectionGadgetsBundle;
@@ -25,6 +26,7 @@ import com.siyeh.ig.psiutils.ExceptionUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
public class ExpectedExceptionNeverThrownInspection extends BaseInspection {
@@ -84,7 +86,7 @@ public class ExpectedExceptionNeverThrownInspection extends BaseInspection {
InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_ERROR)) {
return;
}
final Set<PsiClassType> exceptionsThrown = ExceptionUtils.calculateExceptionsThrown(body);
final List<PsiClassType> exceptionsThrown = ExceptionUtil.getThrownExceptions(body);
if (exceptionsThrown.contains(classType)) {
return;
}
@@ -0,0 +1,11 @@
class Super {
static <T> void foo() {}
}
class Child extends Super {}
class Bar {
{
Super.<String>foo();
}
}
@@ -0,0 +1,11 @@
class Super {
static <T> void foo() {}
}
class Child extends Super {}
class Bar {
{
Child.<String>f<caret>oo();
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.fixes.bugs;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.IGQuickFixesTestCase;
import com.siyeh.ig.bugs.CastConflictsWithInstanceofInspection;
import com.siyeh.ig.bugs.StaticCallOnSubclassInspection;
public class StaticCallOnSubclassTest extends IGQuickFixesTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(new StaticCallOnSubclassInspection());
}
public void testPreserveTypeArgs() {
doTest("preserveTypeArgs", InspectionGadgetsBundle.message("static.method.via.subclass.rationalize.quickfix"));
}
@Override
protected String getRelativePath() {
return "bugs/staticCallOnSubclass";
}
}