Merge remote-tracking branch 'origin/master'

This commit is contained in:
Konstantin Bulenkov
2012-10-18 16:56:21 +02:00
705 changed files with 1528 additions and 1564 deletions
@@ -270,6 +270,15 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
}
}
private static boolean isExternalizableNoParameterConstructor(PsiMethod method, RefClass refClass) {
if (!method.isConstructor()) return false;
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) return false;
final PsiParameterList parameterList = method.getParameterList();
if (parameterList.getParametersCount() != 0) return false;
final PsiClass aClass = method.getContainingClass();
return aClass == null || isExternalizable(aClass, refClass);
}
private static boolean isSerializationImplicitlyUsedField(PsiField field) {
@NonNls final String name = field.getName();
if (!HighlightUtil.SERIAL_VERSION_UID_FIELD_NAME.equals(name) && !"serialPersistentFields".equals(name)) return false;
@@ -330,6 +339,15 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
return false;
}
private static boolean isExternalizable(PsiClass aClass, RefClass refClass) {
final GlobalSearchScope scope = aClass.getResolveScope();
final PsiClass externalizableClass = JavaPsiFacade.getInstance(aClass.getProject()).findClass("java.io.Externalizable", scope);
if (externalizableClass == null) {
return false;
}
return isSerializable(aClass, refClass, externalizableClass);
}
private static boolean isSerializable(PsiClass aClass, RefClass refClass, PsiClass serializableClass) {
if (aClass == null) return false;
if (aClass.isInheritor(serializableClass, true)) return true;
@@ -600,7 +618,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
private static boolean isSerializablePatternMethod(PsiMethod psiMethod, RefClass refClass) {
return isReadObjectMethod(psiMethod, refClass) || isWriteObjectMethod(psiMethod, refClass) || isReadResolveMethod(psiMethod, refClass) ||
isWriteReplaceMethod(psiMethod, refClass);
isWriteReplaceMethod(psiMethod, refClass) || isExternalizableNoParameterConstructor(psiMethod, refClass);
}
private void enqueueMethodUsages(final RefMethod refMethod) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -24,7 +24,6 @@ import com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCalls
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
@@ -82,7 +81,7 @@ public class RedundantCastInspection extends GenericsInspectionToolBase {
@Override
public JComponent createOptionsPanel() {
final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
optionsPanel.addCheckbox("Ignore casts appeared in suspicious collections method calls", "IGNORE_SUSPICIOUS_METHOD_CALLS");
optionsPanel.addCheckbox("Ignore casts in suspicious collections method calls", "IGNORE_SUSPICIOUS_METHOD_CALLS");
optionsPanel.addCheckbox("Ignore casts to invoke @NotNull method which overrides @Nullable", "IGNORE_ANNOTATED_METHODS");
return optionsPanel;
}
@@ -167,9 +167,7 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
PsiReferenceExpression methodRef = (PsiReferenceExpression) element;
PsiElement parent = methodRef.getParent();
LOG.assertTrue(parent instanceof PsiMethodCallExpression);
PsiMethodCallExpression methodCall = (PsiMethodCallExpression) parent;
PsiExpression instanceRef;
instanceRef = methodRef.getQualifierExpression();
@@ -192,21 +190,25 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
if (mySettings.getNewParametersNumber() > 1) {
int copyingSafetyLevel = RefactoringUtil.verifySafeCopyExpression(instanceRef);
if (copyingSafetyLevel == RefactoringUtil.EXPR_COPY_PROHIBITED) {
String tempVar = RefactoringUtil.createTempVar(instanceRef, methodCall, true);
String tempVar = RefactoringUtil.createTempVar(instanceRef, parent, true);
instanceRef = factory.createExpressionFromText(tempVar, null);
}
}
PsiElement anchor = null;
PsiExpressionList argList = methodCall.getArgumentList();
PsiExpression[] exprs = argList.getExpressions();
if (mySettings.isMakeClassParameter()) {
if (exprs.length > 0) {
anchor = argList.addBefore(instanceRef, exprs[0]);
}
else {
anchor = argList.add(instanceRef);
PsiExpressionList argList = null;
PsiExpression[] exprs = new PsiExpression[0];
if (parent instanceof PsiMethodCallExpression) {
argList = ((PsiMethodCallExpression)parent).getArgumentList();
exprs = argList.getExpressions();
if (mySettings.isMakeClassParameter()) {
if (exprs.length > 0) {
anchor = argList.addBefore(instanceRef, exprs[0]);
}
else {
anchor = argList.add(instanceRef);
}
}
}
@@ -31,14 +31,17 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.refactoring.HelpID;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.util.CommonRefactoringUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -83,7 +86,7 @@ public class MakeStaticHandler implements RefactoringActionHandler {
invoke(member);
}
public static void invoke(PsiTypeParameterListOwner member) {
public static void invoke(final PsiTypeParameterListOwner member) {
final Project project = member.getProject();
final InternalUsageInfo[] classRefsInMember = MakeStaticUtil.findClassRefsInMember(member, false);
@@ -95,7 +98,26 @@ public class MakeStaticHandler implements RefactoringActionHandler {
AbstractMakeStaticDialog dialog;
if (!ApplicationManager.getApplication().isUnitTestMode()) {
if (classRefsInMember.length > 0) {
final boolean[] hasMethodReferenceOnInstance = new boolean[] {false};
if (member instanceof PsiMethod) {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
hasMethodReferenceOnInstance[0] = !MethodReferencesSearch.search((PsiMethod)member).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference reference) {
final PsiElement element = reference.getElement();
if (element instanceof PsiMethodReferenceExpression) {
return false;
}
return true;
}
});
}
}, "Search for method references", true, project)) return;
}
if (classRefsInMember.length > 0 || hasMethodReferenceOnInstance[0]) {
final PsiType type = JavaPsiFacade.getInstance(project).getElementFactory().createType(member.getContainingClass());
//TODO: callback
String[] nameSuggestions =
@@ -0,0 +1,9 @@
class Test4 {
void test() {
Foo2<Test4> f = Test4::yyy;
}
static void yyy(Test4 anObject) {}
}
interface Foo2<T> {
void bar(T j);
}
@@ -0,0 +1,9 @@
class Test4 {
void test() {
Foo2<Test4> f = Test4::yyy;
}
void yy<caret>y() {}
}
interface Foo2<T> {
void bar(T j);
}
@@ -19,7 +19,6 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiTypeParameterListOwner;
import com.intellij.refactoring.makeStatic.MakeMethodStaticProcessor;
import com.intellij.refactoring.makeStatic.MakeStaticUtil;
import com.intellij.refactoring.makeStatic.Settings;
@@ -186,13 +185,21 @@ public class MakeMethodStaticTest extends LightRefactoringTestCase {
assertFalse(MakeStaticUtil.isParameterNeeded((PsiMethod)element));
}
public void testMethodReference() throws Exception {
doTest(true);
}
public void testPreserveParametersAlignment() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}
private void doTest(final boolean addClassParameter) throws Exception {
configureByFile("/refactoring/makeMethodStatic/before" + getTestName(false) + ".java");
perform(false);
perform(addClassParameter);
checkResultByFile("/refactoring/makeMethodStatic/after" + getTestName(false) + ".java");
}