Merge remote branch 'origin/master'

This commit is contained in:
Eugene Zhuravlev
2011-12-06 15:59:26 +01:00
13 changed files with 115 additions and 34 deletions
@@ -38,7 +38,6 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.refactoring.MoveDestination;
import com.intellij.refactoring.RefactorJBundle;
import com.intellij.refactoring.extractclass.usageInfo.*;
@@ -427,28 +426,8 @@ public class ExtractClassProcessor extends FixableUsagesRefactoringProcessor {
fieldBuffer.append('>');
}
fieldBuffer.append('(');
boolean isFirst = true;
if (requiresBackpointer) {
fieldBuffer.append("this");
isFirst = false;
}
for (PsiField field : fields) {
if (field.hasModifierProperty(PsiModifier.STATIC)) {
continue;
}
if (!field.hasInitializer()) {
continue;
}
final PsiExpression initializer = field.getInitializer();
if (PsiUtil.isConstantExpression(initializer)) {
continue;
}
if (!isFirst) {
fieldBuffer.append(", ");
}
isFirst = false;
assert initializer != null;
fieldBuffer.append(initializer.getText());
}
fieldBuffer.append(");");
@@ -121,7 +121,7 @@ public abstract class DestinationFolderComboBox extends ComboboxWithBrowseButton
final ComboBoxModel model = getComboBox().getModel();
for (int i = 0; i < model.getSize(); i++) {
DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper)model.getElementAt(i);
if (fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()) == root) {
if (item != null && fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()) == root) {
getComboBox().setSelectedItem(item);
return;
}
@@ -0,0 +1,13 @@
public class Extracted {
private final Test test;
String myT;
public Extracted(Test test) {
this.test = test;
this.myT = test.foo();
}
void bar() {
System.out.println(myT);
}
}
@@ -0,0 +1,15 @@
class Test {
final Extracted extracted = new Extracted(this);
void bar(){
extracted.bar();
}
String foo() {
return "";
}
void bazz() {
extracted.bar();
}
}
@@ -0,0 +1,15 @@
class Test {
String myT = foo();
void bar(){
System.out.println(myT);
}
String foo() {
return "";
}
void bazz() {
bar();
}
}
@@ -0,0 +1,10 @@
public class Extracted {
String myT = "";
public Extracted() {
}
void bar() {
System.out.println(myT);
}
}
@@ -0,0 +1,11 @@
class Test {
final Extracted extracted = new Extracted();
void bar(){
extracted.bar();
}
void foo() {
extracted.bar();
}
}
@@ -0,0 +1,11 @@
class Test {
String myT = "";
void bar(){
System.out.println(myT);
}
void foo() {
bar();
}
}
@@ -101,6 +101,14 @@ public class ExtractClassTest extends MultiFileTestCase{
doTestMethod();
}
public void testNoConstructorParams() throws Exception {
doTestFieldAndMethod();
}
public void testConstructorParams() throws Exception {
doTestFieldAndMethod();
}
private void doTestFieldAndMethod() throws Exception {
doTestFieldAndMethod("bar");
}
@@ -98,8 +98,7 @@ class ShowDiffFromAnnotation extends AnAction implements LineNumberListener {
final FilePath[] targetPath = new FilePath[1];
ProgressManager.getInstance().run(new Task.Backgroundable(myVcs.getProject(),
"Loading revision " + revisionNumber.asString() + " contents", true,
BackgroundFromStartOption
.getInstance()) {
BackgroundFromStartOption.getInstance()) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final CommittedChangesProvider provider = myVcs.getCommittedChangesProvider();
@@ -112,7 +111,7 @@ class ShowDiffFromAnnotation extends AnAction implements LineNumberListener {
targetPath[0] = pair.getSecond() == null ? new FilePathImpl(myFile) : pair.getSecond();
final CommittedChangeList cl = pair.getFirst();
changes.addAll(cl.getChanges());
Collections.sort(changes, ChangesComparator.getInstance());
Collections.sort(changes, ChangesComparator.getInstance(true));
}
catch (VcsException e1) {
exc[0] = e1;
@@ -185,7 +185,7 @@ public class DiffShelvedChangesAction extends AnAction implements DumbAware {
}
public int compare(final ShelvedChange o1, final ShelvedChange o2) {
return ChangesComparator.getInstance().compare(o1.getChange(myProject), o2.getChange(myProject));
return ChangesComparator.getInstance(true).compare(o1.getChange(myProject), o2.getChange(myProject));
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* 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.
@@ -313,8 +313,8 @@ public class ChangesBrowser extends JPanel implements TypeSafeDataProvider {
return sortChanges(list);
}
protected static List<Change> sortChanges(final List<Change> list) {
Collections.sort(list, ChangesComparator.getInstance());
protected List<Change> sortChanges(final List<Change> list) {
Collections.sort(list, ChangesComparator.getInstance(myViewer.isShowFlatten()));
return list;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* 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.
@@ -15,22 +15,42 @@
*/
package com.intellij.openapi.vcs.changes.ui;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangesUtil;
import java.util.Comparator;
public class ChangesComparator implements Comparator<Change> {
private static final ChangesComparator ourInstance = new ChangesComparator();
private static final ChangesComparator ourFlattenedInstance = new ChangesComparator(false);
private static final ChangesComparator ourTreeInstance = new ChangesComparator(true);
private final boolean myTreeCompare;
public static ChangesComparator getInstance() {
return ourInstance;
public static ChangesComparator getInstance(boolean flattened) {
if (flattened) {
return ourFlattenedInstance;
} else {
return ourTreeInstance;
}
}
private ChangesComparator() {
private ChangesComparator(boolean treeCompare) {
myTreeCompare = treeCompare;
}
public int compare(final Change o1, final Change o2) {
final FilePath filePath1 = ChangesUtil.getFilePath(o1);
final FilePath filePath2 = ChangesUtil.getFilePath(o2);
if (myTreeCompare) {
final FilePath parentPath1 = filePath1.getParentPath();
final FilePath parentPath2 = filePath2.getParentPath();
if (parentPath1 != null && parentPath1.isUnder(parentPath2, true)) {
return -1;
}
if (parentPath2 != null && parentPath2.isUnder(parentPath1, true)) {
return 1;
}
}
return ChangesUtil.getFilePath(o1).getName().compareToIgnoreCase(ChangesUtil.getFilePath(o2).getName());
}
}