summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Metchev2013-08-12 02:00:13 (EDT)
committerNoopur Gupta2013-08-12 02:00:13 (EDT)
commit085afe749ee60f18409d04bca0d108b88e42575d (patch)
tree0feb2c21fb6d7302ee7bddb57faac64e4910ac72
parent8aa67180d9653d80eb3ee3be018a6c687ca98283 (diff)
downloadeclipse.jdt.ui-085afe749ee60f18409d04bca0d108b88e42575d.zip
eclipse.jdt.ui-085afe749ee60f18409d04bca0d108b88e42575d.tar.gz
eclipse.jdt.ui-085afe749ee60f18409d04bca0d108b88e42575d.tar.bz2
Fixed bug 124978: [refactoring][convert anonymous] gets confused with
generic methods Signed-off-by: Nikolay Metchev <nikolaymetchev@gmail.com>
-rw-r--r--org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java22
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalVariableNameCollector.java29
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java34
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerContentProvider.java8
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java5
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformChangeOperation.java7
-rw-r--r--org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java44
7 files changed, 139 insertions, 10 deletions
diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java
index 61cbb5c..cddd789 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java
@@ -29,8 +29,11 @@ import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.jdt.core.ElementChangedEvent;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IElementChangedListener;
+import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
@@ -156,6 +159,25 @@ public class ContentProviderTests6 extends TestCase {
assertions();
}
+ public void testChangeClassInProject() throws Exception {
+ IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src");
+ IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null);
+ ICompilationUnit cu= pack1.createCompilationUnit("A.java", "hello", false, null);
+
+ //send a delta indicating file changed
+ JavaElementDelta delta= new JavaElementDelta(sourceFolder.getJavaModel());
+ delta.changed(cu, IJavaElementDelta.F_CHILDREN);
+ IElementChangedListener listener= (IElementChangedListener)fProvider;
+ listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));
+
+ //force events from display
+ while (fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
+ }
+
+ assertTrue("Refresh happened", fMyPart.hasRefreshHappened()); //$NON-NLS-1$
+ assertTrue("Project not refreshed", !fMyPart.wasObjectRefreshed(fJProject)); //$NON-NLS-1$
+ }
+
private void assertions() {
assertTrue("Refresh happened", fMyPart.hasRefreshHappened()); //$NON-NLS-1$
assertTrue("LibraryContainer Refreshed", fMyPart.wasObjectRefreshed(new LibraryContainer(fJProject))); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalVariableNameCollector.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalVariableNameCollector.java
new file mode 100644
index 0000000..d55d434
--- /dev/null
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/LocalVariableNameCollector.java
@@ -0,0 +1,29 @@
+package org.eclipse.jdt.internal.corext.refactoring.code;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
+
+public class LocalVariableNameCollector extends GenericVisitor {
+ private final List<String> names= new ArrayList<String>();
+
+ @Override
+ public boolean visit(VariableDeclarationFragment fragment) {
+ names.add(fragment.getName().getIdentifier());
+ return false;
+ }
+
+ @Override
+ public boolean visit(SingleVariableDeclaration node) {
+ names.add(node.getName().getIdentifier());
+ return false;
+ }
+
+ public List<String> getNames() {
+ return names;
+ }
+}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java
index e5b6c8d..648b942 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -59,6 +59,7 @@ import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Statement;
import org.eclipse.jdt.core.dom.SwitchStatement;
import org.eclipse.jdt.core.dom.Type;
@@ -76,6 +77,7 @@ import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatur
import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
+import org.eclipse.jdt.internal.corext.dom.GenericVisitor;
import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor;
import org.eclipse.jdt.internal.corext.dom.ModifierRewrite;
import org.eclipse.jdt.internal.corext.fix.LinkedProposalModel;
@@ -452,14 +454,40 @@ public class PromoteTempToFieldRefactoring extends Refactoring {
try{
RefactoringStatus result= new RefactoringStatus();
result.merge(checkClashesWithExistingFields());
- if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR)
- result.merge(checkClashesInConstructors());
+ if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR)
+ result.merge(checkClashesInConstructors());
+ result.merge(checkClashesInCurrentMethod());
return result;
} finally {
pm.done();
}
}
+ private RefactoringStatus checkClashesInCurrentMethod() {
+ final List<String> names= new ArrayList<String>();
+ getMethodDeclaration().accept(new GenericVisitor() {
+ @Override
+ public boolean visit(VariableDeclarationFragment fragment) {
+ names.add(fragment.getName().getIdentifier());
+ return false;
+ }
+
+ @Override
+ public boolean visit(SingleVariableDeclaration node) {
+ names.add(node.getName().getIdentifier());
+ return false;
+ }
+ });
+ names.remove(fTempDeclarationNode.getName().getIdentifier());
+ if (names.contains(fFieldName)) {
+ String[] keys= { BasicElementLabels.getJavaElementName(fFieldName),
+ BindingLabelProvider.getBindingLabel(getMethodDeclaration().resolveBinding(), JavaElementLabels.ALL_FULLY_QUALIFIED) };
+ String msg= Messages.format(RefactoringCoreMessages.PromoteTempToFieldRefactoring_Name_conflict, keys);
+ return RefactoringStatus.createWarningStatus(msg);
+ }
+ return null;
+ }
+
private RefactoringStatus checkClashesInConstructors() {
Assert.isTrue(fInitializeIn == INITIALIZE_IN_CONSTRUCTOR);
Assert.isTrue(!isDeclaredInAnonymousClass());
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerContentProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerContentProvider.java
index 6873e3b..1a12165 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerContentProvider.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerContentProvider.java
@@ -725,10 +725,12 @@ public class PackageExplorerContentProvider extends StandardJavaElementContentPr
}
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=357450
int result= flags & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_CHILDREN);
- if (result == IJavaElementDelta.F_CONTENT || result == IJavaElementDelta.F_CHILDREN) {
- Object parent= internalGetParent(element);
+ Object parent= internalGetParent(element);
+ boolean isParentLibrayContainer= parent instanceof LibraryContainer;
+ if (result == IJavaElementDelta.F_CONTENT ||
+ (result == IJavaElementDelta.F_CHILDREN && isParentLibrayContainer)) {
postRefresh(parent, PARENT, element, runnables);
- if (parent instanceof LibraryContainer) {
+ if (isParentLibrayContainer) {
IResource resource= element.getResource();
if (resource != null && ((LibraryContainer) parent).getJavaProject().getResource().equals(resource.getProject()))
postRefresh(resource, ORIGINAL, element, runnables);
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
index edcd774..fffe3cb 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
@@ -351,7 +351,7 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
* In 3.3 we only support the above required proposals, see
* CompletionProposal#getRequiredProposals()
*/
- Assert.isTrue(false);
+ Assert.isTrue(false);
}
}
}
@@ -1003,6 +1003,7 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
return null;
int length= getReplacementOffset() + getReplacementLength() - modelCaret;
+ getReplacementString();
Color foreground= getForegroundColor();
Color background= getBackgroundColor();
@@ -1021,7 +1022,7 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
StyleRange range= createStyleRange(viewer);
if (range == null)
return;
-
+
fRememberedStyleRange= range;
if (viewer instanceof ITextViewerExtension4) {
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformChangeOperation.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformChangeOperation.java
index 0a3984f..761a41f 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformChangeOperation.java
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformChangeOperation.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -261,6 +261,11 @@ public class PerformChangeOperation implements IWorkspaceRunnable {
} finally {
if (fUndoManager != null) {
ResourcesPlugin.getWorkspace().checkpoint(false);
+ /* try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }*/
if (aboutToPerformChangeCalled)
fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
}
diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java
index 364d64d..c3937f3 100644
--- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java
+++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoManager2.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -107,8 +107,34 @@ public class UndoManager2 implements IUndoManager {
private ListenerList fListeners;
+ /*private IOperationHistoryListener fLocalOperationHistoryListener;
+
+ private boolean doneEventReceived= false;*/
+
public UndoManager2() {
fOperationHistory= OperationHistoryFactory.getOperationHistory();
+ /*fLocalOperationHistoryListener= new IOperationHistoryListener() {
+
+ public void historyNotification(OperationHistoryEvent event) {
+ // TODO Auto-generated method stub
+ IUndoableOperation op= event.getOperation();
+ if (op instanceof TriggeredOperations) {
+ op= ((TriggeredOperations)op).getTriggeringOperation();
+ }
+ UndoableOperation2ChangeAdapter changeOperation= null;
+ if (op instanceof UndoableOperation2ChangeAdapter) {
+ changeOperation= (UndoableOperation2ChangeAdapter)op;
+ }
+ if (changeOperation == null)
+ return;
+ Change change= changeOperation.getChange();
+ switch (event.getEventType()) {
+ case OperationHistoryEvent.OPERATION_ADDED:
+ doneEventReceived= true;
+ }
+ }
+ };
+ fOperationHistory.addOperationHistoryListener(fLocalOperationHistoryListener);*/
}
public void addListener(IUndoManagerListener listener) {
@@ -138,6 +164,7 @@ public class UndoManager2 implements IUndoManager {
fActiveOperation.addContext(RefactoringCorePlugin.getUndoContext());
fOperationHistory.openOperation(fActiveOperation, IOperationHistory.EXECUTE);
fIsOpen= true;
+ //doneEventReceived= false;
}
/**
@@ -150,6 +177,21 @@ public class UndoManager2 implements IUndoManager {
public void changePerformed(Change change, boolean successful) {
if (fIsOpen && fActiveOperation != null) {
+ /*try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }*/
+ /*while (!doneEventReceived) {
+ try {
+ Thread.sleep(0);
+ System.out.println(doneEventReceived);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }*/
fOperationHistory.closeOperation(successful, false, IOperationHistory.EXECUTE);
fIsOpen= false;
}