Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2014-10-06 15:33:18 +02:00
64 changed files with 892 additions and 240 deletions
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiUtil;
@@ -104,7 +105,25 @@ public class RemoveUnusedVariableUtil {
sideEffects.add(element);
return true;
}
PsiElement[] children = element.getChildren();
IElementType tokenType = null;
PsiExpression operand = null;
if (element instanceof PsiPrefixExpression) {
operand = ((PsiPrefixExpression)element).getOperand();
tokenType = ((PsiPrefixExpression)element).getOperationTokenType();
} else if (element instanceof PsiPostfixExpression) {
operand = ((PsiPostfixExpression)element).getOperand();
tokenType = ((PsiPostfixExpression)element).getOperationTokenType();
}
if (JavaTokenType.MINUSMINUS.equals(tokenType) || JavaTokenType.PLUSPLUS.equals(tokenType)) {
operand = PsiUtil.deparenthesizeExpression(operand);
if (!(operand instanceof PsiReferenceExpression && ((PsiReferenceExpression)operand).resolve() == variable)) {
sideEffects.add(element);
return true;
}
}
PsiElement[] children = element.getChildren();
for (PsiElement child : children) {
checkSideEffects(child, variable, sideEffects);
@@ -203,8 +203,10 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo
@Override public void visitClass(PsiClass aClass) {
// Don't go into classes (anonymous, locals).
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final LanguageLevel effectiveLanguageLevel = getEffectiveLanguageLevel(ModuleUtilCore.findModuleForPsiElement(aClass));
if (!effectiveLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) &&
final Module module = ModuleUtilCore.findModuleForPsiElement(aClass);
final LanguageLevel effectiveLanguageLevel = module != null ? getEffectiveLanguageLevel(module) : null;
if (effectiveLanguageLevel != null &&
!effectiveLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) &&
JavaVersionService.getInstance().getJavaSdkVersion(aClass).isAtLeast(JavaSdkVersion.JDK_1_8)) {
final List<PsiMethod> methods = new ArrayList<PsiMethod>();
for (HierarchicalMethodSignature methodSignature : aClass.getVisibleSignatures()) {
@@ -375,8 +375,9 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
public void visitReturnStatement(PsiReturnStatement statement) {
super.visitReturnStatement(statement);
if (IGNORE_UNCHECKED_ASSIGNMENT) return;
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(statement, PsiLambdaExpression.class);
final PsiMethod method = PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
if (method != null) {
if (method != null && (lambdaExpression == null || PsiTreeUtil.isAncestor(lambdaExpression, method, true))) {
final PsiType returnType = method.getReturnType();
if (returnType != null && returnType != PsiType.VOID) {
final PsiExpression returnValue = statement.getReturnValue();
@@ -28,7 +28,8 @@ import com.intellij.psi.tree.TokenSet;
public class JavaPairedBraceMatcher extends PairedBraceMatcherAdapter {
private static final TokenSet TYPE_TOKENS =
TokenSet.orSet(StdTokenSets.WHITE_SPACE_OR_COMMENT_BIT_SET,
TokenSet.create(JavaTokenType.IDENTIFIER, JavaTokenType.COMMA,
TokenSet.create(JavaTokenType.IDENTIFIER, JavaTokenType.COMMA,
JavaTokenType.AT,//anno
JavaTokenType.RBRACKET, JavaTokenType.LBRACKET, //arrays
JavaTokenType.QUEST, JavaTokenType.EXTENDS_KEYWORD, JavaTokenType.SUPER_KEYWORD));//wildcards
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -31,7 +31,6 @@ import org.jetbrains.annotations.NotNull;
* @author ven
*/
public class AddOverrideAnnotationAction implements IntentionAction {
private static final String JAVA_LANG_OVERRIDE = "java.lang.Override";
@Override
@NotNull
@@ -51,11 +50,11 @@ public class AddOverrideAnnotationAction implements IntentionAction {
if (!file.getManager().isInProject(file)) return false;
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method == null) return false;
if (method.getModifierList().findAnnotation(JAVA_LANG_OVERRIDE) != null) return false;
if (method.getModifierList().findAnnotation(CommonClassNames.JAVA_LANG_OVERRIDE) != null) return false;
PsiMethod[] superMethods = method.findSuperMethods();
for (PsiMethod superMethod : superMethods) {
if (!superMethod.hasModifierProperty(PsiModifier.ABSTRACT)
&& new AddAnnotationFix(JAVA_LANG_OVERRIDE, method).isAvailable(project, editor, file)) {
&& new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method).isAvailable(project, editor, file)) {
return true;
}
}
@@ -67,7 +66,7 @@ public class AddOverrideAnnotationAction implements IntentionAction {
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method != null) {
new AddAnnotationFix(JAVA_LANG_OVERRIDE, method).invoke(project, editor, file);
new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method).invoke(project, editor, file);
}
}
@@ -56,13 +56,11 @@ public class InvertBooleanHandler implements RefactoringActionHandler {
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, var)) return;
if (var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)((PsiParameter)var).getDeclarationScope();
final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
if (superMethod != null) {
var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)];
}
if (superMethod == null) return;
var = superMethod.getParameterList().getParameters()[method.getParameterList().getParameterIndex((PsiParameter)var)];
}
new InvertBooleanDialog(var).show();
@@ -87,9 +85,8 @@ public class InvertBooleanHandler implements RefactoringActionHandler {
}
final PsiMethod superMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
if (superMethod != null) method = superMethod;
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method)) return;
if (superMethod == null) return;
method = superMethod;
new InvertBooleanDialog(method).show();
}
@@ -0,0 +1,65 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
class Test {
private Repository repository = null;
public Stream<Person> test() {
return repository.all()
.flatMap(foo -> {
class AB {
List<String> a() {
return <warning descr="Unchecked assignment: 'java.util.ArrayList' to 'java.util.List<java.lang.String>'">new ArrayList()</warning>;
}
}
AB ab = new AB();
System.out.println(ab);
if (foo != null) {
return repository.update();
}
return Stream.empty();
})
.map(UpdateResult::getPerson);
}
public static class Repository {
public Stream<Person> all() {
return Stream.empty();
}
public Stream<UpdateResult> update() {
return Stream.empty();
}
}
public static class Person {
}
public static class UpdateResult {
private final Person person;
private final Object metadata;
public UpdateResult(Person person, Object metadata) {
this.person = person;
this.metadata = metadata;
}
public Person getPerson() {
return person;
}
public Object getMetadata() {
return metadata;
}
}
}
@@ -762,6 +762,10 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testIDEA78402() { doTest(); }
public void testUncheckedWarningInsideLambdaReturnStatement() throws Exception {
doTest(true);
}
private void doTest() {
doTest(false);
}
@@ -24,10 +24,10 @@ public class JavaBraceMatcherTest extends LightCodeInsightFixtureTestCase {
public void testGenerics() {
myFixture.configureByText("a.java", "import java.util.ArrayList;" +
"class A {" +
" ArrayList<caret><? extends String[]> f;" +
" ArrayList<caret><? extends @Anno String[]> f;" +
"}");
final int offset = BraceMatchingUtil.getMatchedBraceOffset(myFixture.getEditor(), true, myFixture.getFile());
assertEquals(66, offset);
assertEquals(72, offset);
}
public void testBrokenText() {