Author: dazarov
Date: 2012-01-31 14:54:17 -0500 (Tue, 31 Jan 2012)
New Revision: 38343
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerFieldBean.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerMethodBean.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/AbstractRefactorTest.java
Log:
Rename named bean action does work for Producer Fields and Producer Methods
https://issues.jboss.org/browse/JBIDE-10741
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java 2012-01-31
19:42:00 UTC (rev 38342)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java 2012-01-31
19:54:17 UTC (rev 38343)
@@ -12,11 +12,9 @@
import java.util.ArrayList;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
@@ -29,7 +27,6 @@
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
-import org.jboss.tools.common.model.project.ProjectHome;
import org.jboss.tools.common.refactoring.BaseFileChange;
import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerFieldBean.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerFieldBean.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerFieldBean.java 2012-01-31
19:54:17 UTC (rev 38343)
@@ -0,0 +1,10 @@
+package org.jboss.jsr299.tck.tests.jbt.refactoring;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+public class ProducerFieldBean {
+ @Produces @Named("sField") String s;
+
+ String s1 = "#{sField.charAt(0)}";
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerFieldBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerMethodBean.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerMethodBean.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerMethodBean.java 2012-01-31
19:54:17 UTC (rev 38343)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.jbt.refactoring;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+public class ProducerMethodBean {
+ @Produces
+ @Named("infoMethod")
+ String info(){
+ return "info";
+ }
+
+ String s1 = "#{infoMethod.charAt(0)}";
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/refactoring/ProducerMethodBean.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java 2012-01-31
19:42:00 UTC (rev 38342)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/NamedBeanRefactoringTest.java 2012-01-31
19:54:17 UTC (rev 38343)
@@ -33,8 +33,7 @@
private static final String newName = "abcde";
private static final int NUM_OF_CHAR = 5;
- public void testNamedBeanRename() throws CoreException {
-
+ public void testNamedBeanClassRename() throws CoreException {
ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
TestChangeStructure structure = new TestChangeStructure(tckProject, FILE_NAME1);
@@ -43,19 +42,19 @@
list.add(structure);
structure = new TestChangeStructure(tckProject, FILE_NAME2);
- change = new TestTextChange(526, NUM_OF_CHAR, newName);
+ change = new TestTextChange(/*526*/"gamme}", NUM_OF_CHAR, newName);
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(tckProject, FILE_NAME3);
- change = new TestTextChange(789, NUM_OF_CHAR, newName);
+ change = new TestTextChange(/*789*/"gamme.check}", NUM_OF_CHAR, newName);
structure.addTextChange(change);
- change = new TestTextChange(924, NUM_OF_CHAR, newName);
+ change = new TestTextChange(/*924*/"gamme.reset}", NUM_OF_CHAR, newName);
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(tckProject, FILE_NAME4);
- change = new TestTextChange(293, NUM_OF_CHAR, newName);
+ change = new TestTextChange(/*293*/"gamme.biggest}", NUM_OF_CHAR, newName);
structure.addTextChange(change);
list.add(structure);
@@ -69,7 +68,49 @@
AbstractRefactorTest.checkRename(processor, list);
}
+
+ public void testNamedBeanProducerFieldRename() throws CoreException {
+ ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
+ TestChangeStructure structure = new TestChangeStructure(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/ProducerFieldBean.java");
+ TestTextChange change = new TestTextChange("sField\")", 6,
"uField");
+ structure.addTextChange(change);
+ change = new TestTextChange("sField.charAt(0)}", 6, "uField");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ IFile sourceFile =
tckProject.getProject().getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/ProducerFieldBean.java");
+
+ IBean bean = getBean(sourceFile, "sField");
+ assertNotNull("Can't get the bean.", bean);
+
+ RenameNamedBeanProcessor processor = new RenameNamedBeanProcessor(bean);
+ processor.setNewName("uField");
+
+ AbstractRefactorTest.checkRename(processor, list);
+ }
+
+ public void testNamedBeanProducerMethodRename() throws CoreException {
+ ArrayList<TestChangeStructure> list = new
ArrayList<TestChangeStructure>();
+
+ TestChangeStructure structure = new TestChangeStructure(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/ProducerMethodBean.java");
+ TestTextChange change = new TestTextChange("infoMethod\")", 10,
"memoMethod");
+ structure.addTextChange(change);
+ change = new TestTextChange("infoMethod.charAt(0)}", 10,
"memoMethod");
+ structure.addTextChange(change);
+ list.add(structure);
+
+ IFile sourceFile =
tckProject.getProject().getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/ProducerMethodBean.java");
+
+ IBean bean = getBean(sourceFile, "infoMethod");
+ assertNotNull("Can't get the bean.", bean);
+
+ RenameNamedBeanProcessor processor = new RenameNamedBeanProcessor(bean);
+ processor.setNewName("memoMethod");
+
+ AbstractRefactorTest.checkRename(processor, list);
+ }
+
private IBean getBean(IFile file, String name) {
CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
assertNotNull("Can't get CDI nature.", cdiNature);
Modified:
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/AbstractRefactorTest.java
===================================================================
---
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/AbstractRefactorTest.java 2012-01-31
19:42:00 UTC (rev 38342)
+++
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/AbstractRefactorTest.java 2012-01-31
19:54:17 UTC (rev 38343)
@@ -35,6 +35,7 @@
import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.text.edits.MultiTextEdit;
import org.jboss.tools.common.refactoring.BaseFileChange;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.test.util.JobUtils;
public class AbstractRefactorTest extends TestCase{
@@ -44,6 +45,8 @@
}
public static void checkRename(RenameProcessor processor,
List<TestChangeStructure> changeList) throws CoreException{
+ processTestChanges(changeList);
+
JobUtils.waitForIdle(2000);
// Test before renaming
@@ -74,7 +77,22 @@
checkChanges(rootChange, changeList);
}
+ private static void processTestChanges(List<TestChangeStructure> structureList)
throws CoreException{
+ for(TestChangeStructure tStructure : structureList){
+ IFile file = tStructure.getProject().getFile(tStructure.getFileName());
+ String fileContent = FileUtil.readStream(file);
+ for(TestTextChange tChange : tStructure.getTextChanges()){
+ if(tChange.getOffset() == -1){
+ int offset = fileContent.indexOf(tChange.getSearchText());
+ tChange.setOffset(offset);
+ }
+ }
+ }
+ }
+
public static void checkMove(RefactoringProcessor processor, IResource oldObject,
IResource destinationObject, MoveParticipant participant, List<TestChangeStructure>
changeList) throws CoreException {
+ processTestChanges(changeList);
+
JobUtils.waitForIdle(2000);
// Test before moving
@@ -104,6 +122,8 @@
}
public static void checkRename(RefactoringProcessor processor, IResource oldObject,
String newName, RenameParticipant participant, List<TestChangeStructure> changeList)
throws CoreException {
+ processTestChanges(changeList);
+
JobUtils.waitForIdle(2000);
// Test before renaming
@@ -234,6 +254,7 @@
}
public static class TestTextChange{
+ private String searchText;
private int offset;
private int length;
private String text;
@@ -244,6 +265,21 @@
this.text = text;
}
+ public TestTextChange(String searchText, int length, String text){
+ this.offset = -1;
+ this.searchText = searchText;
+ this.length = length;
+ this.text = text;
+ }
+
+ public void setOffset(int offset){
+ this.offset = offset;
+ }
+
+ public String getSearchText(){
+ return searchText;
+ }
+
public int getOffset(){
return offset;
}