Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jbide 19696 Rename of an exception class does not work properly #321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,10 +16,10 @@
<include class="batch.RenamableException"/>
</skippable-exception-classes>
<retryable-exception-classes>
<include class="batch.RenamableException"/>
<include class="batch.SecondRenamableException"/>
</retryable-exception-classes>
<no-rollback-exception-classes>
<exclude class="batch.RenamableException"/>
<exclude class="batch.SecondRenamableException"/>
</no-rollback-exception-classes>
</chunk>
</step>
Expand Down
@@ -0,0 +1,6 @@
package batch;

public class SecondRenamableException extends Exception{
private static final long serialVersionUID = 2L;

}
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor;
import org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.batch.ui.participants.BatchArtifactRenameParticipant;
import org.jboss.tools.common.base.test.AbstractRefactorTest;
Expand All @@ -45,7 +46,7 @@ public BatchRenameParticipantTest() {
super("Batch Rename Participants Test");
}

public void testBatchArtifactRename() throws CoreException{
public void testBatchArtifactRename() throws CoreException, BadLocationException{
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project, "/src/META-INF/batch-jobs/job-refactor.xml");
Expand All @@ -59,7 +60,7 @@ public void testBatchArtifactRename() throws CoreException{
RenameParticipantTestUtil.checkRenameParticipant(type, renameProcessor, new BatchArtifactRenameParticipant(), "abcdmableBatchlet", list);
}

public void testBatchPropertyRename() throws CoreException{
public void testBatchPropertyRename() throws CoreException, BadLocationException{
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project, "/src/META-INF/batch-jobs/job-refactor.xml");
Expand All @@ -73,25 +74,35 @@ public void testBatchPropertyRename() throws CoreException{
RenameParticipantTestUtil.checkRenameParticipant(field, renameProcessor, new BatchArtifactRenameParticipant(), "abcdeName", list);
}

public void testClassRename() throws CoreException{
public void testClassRename() throws CoreException, BadLocationException{
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project, "/src/META-INF/batch-jobs/job-refactor.xml");
TestTextChange change = new TestTextChange("batch.RenamableException", 24, "batch.AbcdmableException");
TestTextChange change = new TestTextChange("batch.SecondRenamableException", 30, "batch.AbcdefRenamableException");
structure.addTextChange(change);
list.add(structure);

change = new TestTextChange("batch.RenamableException", 24, "batch.AbcdmableException");
change = new TestTextChange("batch.SecondRenamableException", 30, "batch.AbcdefRenamableException");
structure.addTextChange(change);

change = new TestTextChange("batch.RenamableException", 24, "batch.AbcdmableException");
IType type = RenameParticipantTestUtil.getJavaType(project, "batch.SecondRenamableException");
RenameTypeProcessor renameProcessor = new RenameTypeProcessor(type);

RenameParticipantTestUtil.checkRenameParticipant(type, renameProcessor, new BatchArtifactRenameParticipant(), "AbcdefRenamableException", list);
}

public void testClassRename2() throws CoreException, BadLocationException{
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project, "/src/META-INF/batch-jobs/job-refactor.xml");
TestTextChange change = new TestTextChange("batch.RenamableException", 24, "batch.RenamableExceptio2");
structure.addTextChange(change);
list.add(structure);

IType type = RenameParticipantTestUtil.getJavaType(project, "batch.RenamableException");
RenameTypeProcessor renameProcessor = new RenameTypeProcessor(type);

RenameParticipantTestUtil.checkRenameParticipant(type, renameProcessor, new BatchArtifactRenameParticipant(), "AbcdmableException", list);

RenameParticipantTestUtil.checkRenameParticipant(type, renameProcessor, new BatchArtifactRenameParticipant(), "RenamableExceptio2", list);
}

}
Expand Up @@ -114,9 +114,9 @@ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsCon
newName = BeanUtil.getDefaultBeanName(getArguments().getNewName());
}
} else { // rename exception
String fullyQualifiedName = type.getFullyQualifiedName();
String fullyQualifiedName = type.getFullyQualifiedName();
StringBuilder b = new StringBuilder(fullyQualifiedName);
b.replace(fullyQualifiedName.lastIndexOf(type.getElementName()), fullyQualifiedName.lastIndexOf(type.getElementName()) + 1, getArguments().getNewName() );
b.replace(fullyQualifiedName.lastIndexOf(type.getElementName()), fullyQualifiedName.lastIndexOf(type.getElementName()) + type.getElementName().length(), getArguments().getNewName() );
newName = b.toString();
}
searchInProject(batchProject, artifact, property, pm);
Expand Down
Expand Up @@ -13,8 +13,11 @@
import java.util.ArrayList;
import java.util.Collection;

import javax.inject.Named;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBean;
Expand All @@ -23,7 +26,6 @@
import org.jboss.tools.common.base.test.AbstractRefactorTest;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestChangeStructure;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestTextChange;
import org.jboss.tools.common.util.FileUtil;

public class NamedBeanRefactoringTest extends TCKTest {
private static final String FILE_NAME1 = "JavaSource/org/jboss/jsr299/tck/tests/jbt/refactoring/Gamme.java";
Expand All @@ -34,15 +36,13 @@ public class NamedBeanRefactoringTest extends TCKTest {
private static final String newName = "abcde";
private static final int NUM_OF_CHAR = 5;

public void testNamedBeanClassRename() throws CoreException {
public void testNamedBeanClassRename() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

IFile sourceFile = tckProject.getProject().getFile(FILE_NAME1);
String sourceFileContent = FileUtil.getContentFromEditorOrFile(sourceFile);
int position = sourceFileContent.indexOf("@Named") + 8;

TestChangeStructure structure = new TestChangeStructure(tckProject, FILE_NAME1);
TestTextChange change = new TestTextChange(/*328*/position, NUM_OF_CHAR, newName);
TestTextChange change = new TestTextChange("@Named", 15, "@Named(\"abcde\")");
structure.addTextChange(change);
list.add(structure);

Expand Down Expand Up @@ -72,11 +72,11 @@ public void testNamedBeanClassRename() throws CoreException {
AbstractRefactorTest.checkRename(processor, list);
}

public void testNamedBeanProducerFieldRename() throws CoreException {
public void testNamedBeanProducerFieldRename() throws CoreException, BadLocationException {
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");
TestTextChange change = new TestTextChange("@Named(\"sField\")", 16, "@Named(\"uField\")");
structure.addTextChange(change);
change = new TestTextChange("sField.charAt(0)}", 6, "uField");
structure.addTextChange(change);
Expand All @@ -93,11 +93,11 @@ public void testNamedBeanProducerFieldRename() throws CoreException {
AbstractRefactorTest.checkRename(processor, list);
}

public void testNamedBeanProducerMethodRename() throws CoreException {
public void testNamedBeanProducerMethodRename() throws CoreException, BadLocationException {
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");
TestTextChange change = new TestTextChange("@Named(\"infoMethod\")", 20, "@Named(\"memoMethod\")");
structure.addTextChange(change);
change = new TestTextChange("infoMethod.charAt(0)}", 10, "memoMethod");
structure.addTextChange(change);
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.jboss.tools.common.base.test.AbstractRefactorTest;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestChangeStructure;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestTextChange;
Expand All @@ -37,7 +38,7 @@ protected void setUp() throws Exception {
project = ProjectImportTestSetup.loadProject(projectName);
}

public void testELVariableRename() throws CoreException {
public void testELVariableRename() throws CoreException, BadLocationException {

ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ltk.internal.core.refactoring.resource.MoveResourcesProcessor;
import org.eclipse.ltk.internal.core.refactoring.resource.RenameResourceProcessor;
import org.jboss.tools.common.base.test.AbstractRefactorTest;
Expand All @@ -39,7 +40,7 @@ protected void setUp() throws Exception {
project = ProjectImportTestSetup.loadProject(PROJECT_NAME);
}

public void testRenameCompositeComponentFile() throws CoreException {
public void testRenameCompositeComponentFile() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project.getProject(), "/WebContent/pages/inputname.xhtml");
Expand All @@ -57,11 +58,11 @@ public void testRenameCompositeComponentFile() throws CoreException {
checkRename(processor, sourceFile, "input2.xhtml", participant, list);
}

public void testRenameCompositeComponentFolder() throws CoreException {
public void testRenameCompositeComponentFolder() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project.getProject(), "/WebContent/pages/inputtype.xhtml");
TestTextChange change = new TestTextChange(382, 5, "type2");
TestTextChange change = new TestTextChange("http://java.sun.com/jsf/composite/type"/*382*/, 39, "http://java.sun.com/jsf/composite/type2");
structure.addTextChange(change);
list.add(structure);

Expand All @@ -75,11 +76,11 @@ public void testRenameCompositeComponentFolder() throws CoreException {
checkRename(processor, sourceFolder, "type2", participant, list);
}

public void testMoveCompositeComponentFile() throws CoreException {
public void testMoveCompositeComponentFile() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project.getProject(), "/WebContent/pages/inputdata.xhtml");
TestTextChange change = new TestTextChange(382, 3, "new");
TestTextChange change = new TestTextChange("http://java.sun.com/jsf/composite/data"/*382*/, 37, "http://java.sun.com/jsf/composite/new");
structure.addTextChange(change);
list.add(structure);

Expand All @@ -94,11 +95,11 @@ public void testMoveCompositeComponentFile() throws CoreException {
checkMove(processor, sourceFile, destinationFolder, participant, list);
}

public void testMoveCompositeComponentFolder() throws CoreException {
public void testMoveCompositeComponentFolder() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(project.getProject(), "/WebContent/pages/inputnmbr.xhtml");
TestTextChange change = new TestTextChange(382, 8, "new/nmbr");
TestTextChange change = new TestTextChange("http://java.sun.com/jsf/composite/nmbr"/*382*/, 42, "http://java.sun.com/jsf/composite/new/nmbr");
structure.addTextChange(change);
list.add(structure);

Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.TextSelection;
import org.jboss.tools.common.base.test.AbstractRefactorTest;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestChangeStructure;
Expand All @@ -41,7 +42,7 @@ protected void setUp() throws Exception {
project = ProjectImportTestSetup.loadProject(projectName);
}

public void testMessagePropertyRename() throws CoreException {
public void testMessagePropertyRename() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

IFile sourceFile = project.getProject().getFile("/WebContent/pages/hello.jsp");
Expand Down
Expand Up @@ -5,6 +5,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor;
import org.eclipse.jface.text.BadLocationException;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestChangeStructure;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil.TestTextChange;
Expand All @@ -16,16 +17,18 @@ public ELReferencesRenameTest(){
super("Rename Method Refactoring Test");
}

public void testRenameMethod() throws CoreException {
public void testRenameMethod() throws CoreException, BadLocationException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();

TestChangeStructure structure = new TestChangeStructure(jsfProject, "/WebContent/pages/hello.jsp");
TestTextChange change = new TestTextChange(353, 5, "alias");
TestTextChange change = new TestTextChange("name", 5, "alias");
change.setOffset(353);
structure.addTextChange(change);
list.add(structure);

structure = new TestChangeStructure(jsfProject, "/WebContent/pages/inputUserName.jsp");
change = new TestTextChange(499, 5, "alias");
change = new TestTextChange("name", 5, "alias");
change.setOffset(499);
structure.addTextChange(change);
list.add(structure);

Expand Down
Expand Up @@ -8,6 +8,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.MultiTextEdit;
import org.jboss.tools.common.base.test.RenameParticipantTestUtil;
Expand All @@ -18,6 +20,7 @@
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.internal.core.refactoring.RenameComponentProcessor;
import org.jboss.tools.test.util.ResourcesUtils;
import org.junit.Assert;

public class SeamComponentRefactoringTest extends SeamRefactoringTest {

Expand Down Expand Up @@ -114,7 +117,26 @@ private void renameComponent(ISeamProject seamProject, String componentName, Str
// Rename Seam Component
RenameComponentProcessor processor = new RenameComponentProcessor(component);
processor.setNewName(newName);
processor.checkFinalConditions(new NullProgressMonitor(), null);
RefactoringStatus status = processor.checkInitialConditions(new NullProgressMonitor());

RefactoringStatusEntry[] entries = status.getEntries();
for (RefactoringStatusEntry entry : entries) {
System.out.println("Refactor status - " + entry.getMessage());
}

Assert.assertNull("Rename processor returns fatal error",
status.getEntryMatchingSeverity(RefactoringStatus.FATAL));

status = processor.checkFinalConditions(new NullProgressMonitor(), null);

entries = status.getEntries();
for (RefactoringStatusEntry entry : entries) {
System.out.println("Refactor status - " + entry.getMessage());
}

Assert.assertNull("Rename processor returns fatal error",
status.getEntryMatchingSeverity(RefactoringStatus.FATAL));

CompositeChange rootChange = (CompositeChange)processor.createChange(new NullProgressMonitor());

assertEquals("There is unexpected number of changes",changeList.size(), rootChange.getChildren().length);
Expand Down