Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Kalishev
2011-08-03 22:09:19 +04:00
43 changed files with 173 additions and 84 deletions
@@ -99,32 +99,28 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP
@Nullable
private String getShortText() {
if (myNewParametersInfo.length > 4 || myTargetMethod.getParameterList().getParametersCount() > 4) {
final StringBuilder buf = new StringBuilder();
final HashSet<ParameterInfoImpl> newParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> removedParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> changedParams = new HashSet<ParameterInfoImpl>();
getNewParametersInfo(myExpressions, myTargetMethod, mySubstitutor, buf, newParams, removedParams, changedParams);
final StringBuilder buf = new StringBuilder();
final HashSet<ParameterInfoImpl> newParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> removedParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> changedParams = new HashSet<ParameterInfoImpl>();
getNewParametersInfo(myExpressions, myTargetMethod, mySubstitutor, buf, newParams, removedParams, changedParams);
final String targetMethodName = myTargetMethod.getName();
if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) {
if (newParams.size() == 1) {
final ParameterInfoImpl p = newParams.iterator().next();
return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + "nd parameter to method " + targetMethodName;
}
if (removedParams.size() == 1) {
final ParameterInfoImpl p = removedParams.iterator().next();
return "Remove " + (p.getOldIndex() + 1) + "nd parameter from method " + targetMethodName;
}
if (changedParams.size() == 1) {
final ParameterInfoImpl p = changedParams.iterator().next();
return "Change " + (p.getOldIndex() + 1)+ "nd parameter type of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText();
}
final String targetMethodName = myTargetMethod.getName();
if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) {
if (newParams.size() == 1) {
final ParameterInfoImpl p = newParams.iterator().next();
return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + " parameter to method " + targetMethodName;
}
if (removedParams.size() == 1) {
final ParameterInfoImpl p = removedParams.iterator().next();
return "Remove " + (p.getOldIndex() + 1) + " parameter from method " + targetMethodName;
}
if (changedParams.size() == 1) {
final ParameterInfoImpl p = changedParams.iterator().next();
return "Change " + (p.getOldIndex() + 1)+ " parameter of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText();
}
return "<html> Change signature of " + targetMethodName + "(" + buf.toString() + ")</html>";
}
return null;
return "<html> Change signature of " + targetMethodName + "(" + buf.toString() + ")</html>";
}
private static String formatTypesList(ParameterInfoImpl[] infos, PsiElement context) {
@@ -25,7 +25,9 @@ import com.intellij.ide.util.scopeChooser.GroupByScopeTypeAction;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClassOwner;
@@ -92,22 +94,19 @@ public class PackagePatternProvider extends PatternDialectProvider {
if (recursively) return null;
FileNode fNode = (FileNode)node;
final PsiElement element = fNode.getPsiElement();
final StringBuilder buf = new StringBuilder(20);
String qName = null;
if (element instanceof PsiClassOwner) {
final PsiClassOwner javaFile = (PsiClassOwner)element;
String packageName = javaFile.getPackageName();
buf.append(packageName);
if (buf.length() > 0) {
buf.append('.');
}
final VirtualFile virtualFile = javaFile.getVirtualFile();
LOG.assertTrue(virtualFile != null);
final String packageName =
ProjectRootManager.getInstance(element.getProject()).getFileIndex().getPackageNameByDirectory(virtualFile.getParent());
final String name = virtualFile.getNameWithoutExtension();
if (!JavaPsiFacade.getInstance(element.getProject()).getNameHelper().isIdentifier(name)) return null;
buf.append(name);
qName = StringUtil.getQualifiedName(packageName, name);
}
if (buf.length() > 0) {
return new PatternPackageSet(buf.toString(), scope, getModulePattern(node));
if (qName != null) {
return new PatternPackageSet(qName, scope, getModulePattern(node));
}
}
else if (node instanceof GeneralGroupNode) {
@@ -169,9 +169,14 @@ public class TreeModelBuilder {
countFiles(project);
myFileIndex.iterateContent(new ContentIterator() {
PackageDependenciesNode lastParent = null;
VirtualFile dir = null;
public boolean processFile(VirtualFile fileOrDir) {
if (!fileOrDir.isDirectory()) {
if (lastParent != null && dir != fileOrDir.getParent()) {
lastParent = null;
}
lastParent = buildFileNode(fileOrDir, lastParent);
dir = fileOrDir.getParent();
} else {
lastParent = null;
}
@@ -96,7 +96,9 @@ public class MakeStaticUtil {
qualifier.resolve() : PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (refElement instanceof PsiClass) {
if (isPartOf((PsiClass) refElement, containingClass)) {
classRefs.add(new InternalUsageInfo(element, refElement));
if (!(originalMember instanceof PsiClass && isPartOf((PsiClass)refElement, (PsiClass)originalMember))) {
classRefs.add(new InternalUsageInfo(element, refElement));
}
}
}
}
@@ -1,4 +1,4 @@
// "Change signature of 'f(int)' to 'f()'" "true"
// "Remove 1 parameter from method f" "true"
class A {
void f() {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'set(List<T>)' to 'set(List<T>, String)'" "true"
// "Add String as 2 parameter to method set" "true"
import java.util.List;
public class X<T> {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f()'" "true"
// "<html> Change signature of f(<s>int</s>, <s>String</s>)</html>" "true"
class A {
void f() {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f(int, char, String)'" "true"
// "Add char as 2 parameter to method f" "true"
class A {
void f(int i, char c, String s) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int)'" "true"
// "Remove 2 parameter from method f" "true"
class A {
void f(int i, int i2) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int, int)'" "true"
// "Change 2 parameter of method f from String to int" "true"
class A {
void f(int i, int s, int i2) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'A()' to 'A(int, int, String)'" "true"
// "<html> Change signature of A(<b>int</b>, <b>int</b>, <b>String</b>)</html>" "true"
class A {
A(int i, int i1, String s) {
new A<caret>(1,1,"4");
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, int...)' to 'f(int, int, int...)'" "true"
// "Add int as 2 parameter to method f" "true"
public class S {
void f(int k, int i, int... args) {
f(1,1,null)<caret>;// -> f(1,1,null)
@@ -1,4 +1,4 @@
// "Change signature of 'Bar(String)' to 'Bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method Bar" "true"
public class Bar {
Bar(Foo<TypeParamName> typeParamNameFoo, String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'bar(String)' to 'bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method bar" "true"
public class Bar {
static void bar(Foo<TypeParamName> typeParamNameFoo, String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int, String)'" "true"
// "Add int as 1 parameter to method f" "true"
public class S {
void f(int i, String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'Inner2()' to 'Inner2(CoolTest.Inner1)'" "true"
// "Add Inner1 as 1 parameter to method Inner2" "true"
class CoolTest {
class Inner1 {}
@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(String s, int... args) {
f("",1,1);
@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(String s, int... args) {
f("",null);
@@ -1,4 +1,4 @@
// "Change signature of 'f(int)' to 'f()'" "true"
// "Remove 1 parameter from method f" "true"
class A {
void f(int i) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'set(List<T>)' to 'set(List<T>, String)'" "true"
// "Add String as 2 parameter to method set" "true"
import java.util.List;
public class X<T> {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f()'" "true"
// "<html> Change signature of f(<s>int</s>, <s>String</s>)</html>" "true"
class A {
void f(int i,String s) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f(int, char, String)'" "true"
// "Add char as 2 parameter to method f" "true"
class A {
void f(int i,String s) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int)'" "true"
// "Remove 2 parameter from method f" "true"
class A {
void f(int i, String s, int i2) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int, int)'" "true"
// "Change 2 parameter of method f from String to int" "true"
class A {
void f(int i, String s, int i2) {}
public void foo() {
@@ -1,4 +1,4 @@
// "Change signature of 'A()' to 'A(int, int, String)'" "true"
// "<html> Change signature of A(<b>int</b>, <b>int</b>, <b>String</b>)</html>" "true"
class A {
A() {
new A<caret>(1,1,"4");
@@ -1,4 +1,4 @@
// "Change signature of 'f(int, int...)' to 'f(int, int, int...)'" "true"
// "Add int as 2 parameter to method f" "true"
public class S {
void f(int k, int... args) {
f(1,1,null)<caret>;// -> f(1,1,null)
@@ -1,4 +1,4 @@
// "Change signature of 'Bar(String)' to 'Bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method Bar" "true"
public class Bar {
Bar(String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'bar(String)' to 'bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method bar" "true"
public class Bar {
static void bar(String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int)'" "false"
// "Add int as 1 parameter to method f" "false"
public class Foo {
void foo(Bar f) {
f.f<caret>(2);
@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int, String)'" "true"
// "Add int as 1 parameter to method f" "true"
public class S {
void f(String args) {
@@ -1,4 +1,4 @@
// "Change signature of 'parseInt(String)' to 'parseInt(int)'" "false"
// "Change 1 parameter of method parseInt from String to int" "false"
class A {
public void foo() {
<caret>Integer.parseInt(1);
@@ -1,4 +1,4 @@
// "Change signature of 'Inner2()' to 'Inner2(CoolTest.Inner1)'" "true"
// "Add Inner1 as 1 parameter to method Inner2" "true"
class CoolTest {
class Inner1 {}
@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(int... args) {
f("",1,1)<caret>;
@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(int... args) {
f("",null)<caret>;
@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(int..., String)'" "false"
// "Add String as 2nd parameter to method f" "false"
public class S {
void f(int... args) {
f(1,1, "")<caret>;
@@ -0,0 +1,20 @@
public class m {
void aa(){}
}
class Outer extends m{
class I<caret>nner extends Super {
void bar(){
}
void foo() {
super.foo();
this.bar();
Outer.super.aa();
Outer.this.aa();
}
}
}
class Super {
void foo() {}
}
@@ -0,0 +1,26 @@
public class m {
void aa(){}
}
class Outer extends m{
static class Inner extends Super {
private Outer anObject;
public Inner(Outer anObject) {
this.anObject = anObject;
}
void bar(){
}
void foo() {
super.foo();
this.bar();
anObject.aa();
anObject.aa();
}
}
}
class Super {
void foo() {}
}
@@ -40,6 +40,7 @@ public class MakeClassStaticTest extends LightCodeInsightTestCase {
public void testIDEADEV12762() throws Exception { perform(); }
public void testNewExpressionQualifier() throws Exception {perform();}
public void testThisSuperExpressions() throws Exception {perform();}
public void testNonDefaultConstructorAnonymousClass() throws Exception {perform();}
public void testDefaultConstructorAnonymousClass() throws Exception {perform();}
@@ -0,0 +1,34 @@
/*
* Copyright 2000-2011 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.intellij.psi.search.scope.packageSet;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
/**
* User: anna
*/
public class InvalidPackageSet extends AbstractPackageSet {
public InvalidPackageSet(@NotNull String text) {
super(text);
}
@Override
public boolean contains(VirtualFile file, NamedScopesHolder holder) {
return false;
}
}
@@ -145,12 +145,13 @@ public abstract class NamedScopesHolder implements PersistentStateComponent<Elem
private static NamedScope readScope(Element setElement){
String name = setElement.getAttributeValue(NAME_ATT);
PackageSet set = null;
PackageSet set;
final String attributeValue = setElement.getAttributeValue(PATTERN_ATT);
try {
set = PackageSetFactory.getInstance().compile(setElement.getAttributeValue(PATTERN_ATT));
set = PackageSetFactory.getInstance().compile(attributeValue);
}
catch (ParsingException e) {
// Skip damaged set
set = new InvalidPackageSet(attributeValue);
}
return new NamedScope(name, set);
}
@@ -22,10 +22,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.NamedConfigurable;
import com.intellij.openapi.util.Comparing;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import com.intellij.psi.search.scope.packageSet.PackageSet;
import com.intellij.psi.search.scope.packageSet.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -114,16 +111,16 @@ public class ScopeConfigurable extends NamedConfigurable<NamedScope> {
public boolean isModified() {
if (mySharedCheckbox.isSelected() != myShareScope) return true;
final PackageSet currentScope = myPanel.getCurrentScope();
return !Comparing.strEqual(myPackageSet, currentScope != null ? currentScope.getText() : null);
final String currentScope = myPanel.getPatternText();
return !Comparing.strEqual(myPackageSet, currentScope);
}
public void apply() throws ConfigurationException {
try {
myPanel.apply();
final PackageSet packageSet = myPanel.getCurrentScope();
myScope = new NamedScope(myScope.getName(), packageSet);
myPackageSet = packageSet != null ? packageSet.getText() : null;
myPackageSet = myPanel.getPatternText();
myScope = new NamedScope(myScope.getName(), packageSet == null ? new InvalidPackageSet(myPackageSet) : packageSet);
myShareScope = mySharedCheckbox.isSelected();
}
catch (ConfigurationException e) {
@@ -382,12 +382,14 @@ public class ScopeEditorPanel {
public void run() {
myIsInUpdate = true;
if (updateText) {
final String text = myCurrentScope != null ? myCurrentScope.getText() : "";
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myPatternField.setText(text);
}
});
final String text = myCurrentScope != null ? myCurrentScope.getText() : null;
if (text != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myPatternField.setText(text);
}
});
}
}
try {
if (!myProject.isDisposed()) {
@@ -494,15 +496,16 @@ public class ScopeEditorPanel {
}
public void apply() throws ConfigurationException {
if (myCurrentScope == null) {
throw new ConfigurationException(IdeBundle.message("error.correct.pattern.syntax.errors.first"));
}
}
public PackageSet getCurrentScope() {
return myCurrentScope;
}
public String getPatternText() {
return myPatternField.getText();
}
public void reset(PackageSet packageSet, @Nullable Runnable runnable) {
myCurrentScope = packageSet;
myPatternField.setText(myCurrentScope == null ? "" : myCurrentScope.getText());
@@ -528,10 +528,15 @@ public class FileTreeModelBuilder {
private class MyContentIterator implements ContentIterator {
PackageDependenciesNode lastParent = null;
VirtualFile dir;
public boolean processFile(VirtualFile fileOrDir) {
if (!fileOrDir.isDirectory()) {
if (lastParent != null && dir != fileOrDir.getParent()) {
lastParent = null;
}
lastParent = buildFileNode(fileOrDir, lastParent);
dir = fileOrDir.getParent();
} else {
lastParent = null;
}