Author: dazarov
Date: 2010-04-05 10:52:52 -0400 (Mon, 05 Apr 2010)
New Revision: 21265
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/messages.properties
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/RenameNamedBeanProcessor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5927
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java 2010-04-05
14:42:59 UTC (rev 21264)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreMessages.java 2010-04-05
14:52:52 UTC (rev 21265)
@@ -29,4 +29,8 @@
public static String CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE;
public static String CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE;
public static String CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE;
+ public static String RENAME_NAMED_BEAN_PROCESSOR_TITLE;
+ public static String RENAME_NAMED_BEAN_PROCESSOR_ERROR;
+ public static String CDI_RENAME_PROCESSOR_BEAN_HAS_NO_FILE;
+ public static String CDI_RENAME_PROCESSOR_BEAN_HAS_NO_NAME_LOCATION;
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/messages.properties 2010-04-05
14:42:59 UTC (rev 21264)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/messages.properties 2010-04-05
14:52:52 UTC (rev 21265)
@@ -1,3 +1,10 @@
CDI_FACET_INSTALL_ABSTRACT_DELEGATE_ERROR=Error
CDI_FACET_INSTALL_ABSTRACT_DELEGATE_ERRORS_OCCURED=Error occured during installing CDI
facet
-CDI_FACET_INSTALL_ABSTRACT_DELEGATE_CHECK_ERROR_LOG_VIEW=Check Errors View for details
\ No newline at end of file
+CDI_FACET_INSTALL_ABSTRACT_DELEGATE_CHECK_ERROR_LOG_VIEW=Check Errors View for details
+CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE=Cannot change file. File ''{0}'' is
not in sync.
+CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE=Cannot change phantom file:
''{0}''.
+CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE=Cannot change read-only file:
''{0}''.
+RENAME_NAMED_BEAN_PROCESSOR_TITLE=Rename @Named Bean
+RENAME_NAMED_BEAN_PROCESSOR_ERROR=This is not a @Named Bean
+CDI_RENAME_PROCESSOR_BEAN_HAS_NO_FILE=Named Bean does not have a file
+CDI_RENAME_PROCESSOR_BEAN_HAS_NO_NAME_LOCATION=Named Bean does not have a name location
\ No newline at end of file
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 2010-04-05
14:42:59 UTC (rev 21264)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java 2010-04-05
14:52:52 UTC (rev 21265)
@@ -11,7 +11,6 @@
package org.jboss.tools.cdi.internal.core.refactoring;
import java.util.ArrayList;
-import java.util.Set;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -30,24 +29,17 @@
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.jboss.tools.cdi.core.CDICoreMessages;
-import org.jboss.tools.cdi.core.CDICorePlugin;
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.text.ITextSourceReference;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.web.kb.refactoring.RefactorSearcher;
/**
* @author Daniel Azarov
*/
public abstract class CDIRenameProcessor extends RenameProcessor {
- protected static final String JAVA_EXT = "java"; //$NON-NLS-1$
- protected static final String XML_EXT = "xml"; //$NON-NLS-1$
- protected static final String XHTML_EXT = "xhtml"; //$NON-NLS-1$
- protected static final String JSP_EXT = "jsp"; //$NON-NLS-1$
- protected static final String PROPERTIES_EXT = "properties"; //$NON-NLS-1$
-
protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
protected RefactoringStatus status;
@@ -110,96 +102,26 @@
}
- private boolean isBadLocation(ITextSourceReference location, IFile file){
- boolean flag=false;
- return flag;
- }
-
- private void changeXMLNode(ITextSourceReference location, IFile file){
- if(isBadLocation(location, file))
- return;
+ private void changeDeclarations(IBean bean) throws CoreException{
+ declarationFile = (IFile)bean.getResource();
- if(!isFileCorrect(file))
+ if(declarationFile == null){
+ status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_FILE);
return;
-
- String content = null;
- try {
- content = FileUtil.readStream(file);
- } catch (CoreException e) {
- CDICorePlugin.getDefault().logError(e);
}
-
- String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
- if(text.startsWith("<")){ //$NON-NLS-1$
- int position = text.lastIndexOf("/>"); //$NON-NLS-1$
- if(position < 0){
- position = text.lastIndexOf(">"); //$NON-NLS-1$
- }
- change(file, location.getStartPosition()+position, 0, "
name=\""+getNewName()+"\""); //$NON-NLS-1$ //$NON-NLS-2$
- }else{
- change(file, location.getStartPosition(), location.getLength(), getNewName());
- }
- }
-
- private void changeAnnotation(ITextSourceReference location, IFile file){
- if(isBadLocation(location, file))
- return;
- if(!isFileCorrect(file))
+ ITextSourceReference nameLocation = bean.getNameLocation();
+
+ if(nameLocation == null){
+ status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_NAME_LOCATION);
return;
-
- String content = null;
- try {
- content = FileUtil.readStream(file);
- } catch (CoreException e) {
- CDICorePlugin.getDefault().logError(e);
}
-
- String text = content.substring(location.getStartPosition(),
location.getStartPosition()+location.getLength());
- int openBracket = text.indexOf("("); //$NON-NLS-1$
- int openQuote = text.indexOf("\""); //$NON-NLS-1$
- if(openBracket >= 0){
- int closeBracket = text.indexOf(")", openBracket); //$NON-NLS-1$
-
- int equals = text.indexOf("=", openBracket); //$NON-NLS-1$
- int value = text.indexOf("value", openBracket); //$NON-NLS-1$
-
- if(closeBracket == openBracket+1){ // empty brackets
- String newText = "\""+getNewName()+"\""; //$NON-NLS-1$
//$NON-NLS-2$
- change(file, location.getStartPosition()+openBracket+1, 0, newText);
- }else if(value > 0){ // construction value="name" found so change name
- String newText = text.replace(getOldName(), getNewName());
- change(file, location.getStartPosition(), location.getLength(), newText);
- }else if(equals > 0){ // other parameters are found
- String newText = "value=\""+getNewName()+"\",";
//$NON-NLS-1$ //$NON-NLS-2$
- change(file, location.getStartPosition()+openBracket+1, 0, newText);
- }else{ // other cases
- String newText = text.replace(getOldName(), getNewName());
- change(file, location.getStartPosition(), location.getLength(), newText);
- }
- }else if(openQuote >= 0){
- int closeQuota = text.indexOf("\"", openQuote); //$NON-NLS-1$
-
- if(closeQuota == openQuote+1){ // empty quotas
- String newText = "\""+getNewName()+"\""; //$NON-NLS-1$
//$NON-NLS-2$
- change(file, location.getStartPosition()+openQuote+1, 0, newText);
- }else{ // the other cases
- String newText = text.replace(getOldName(), getNewName());
- change(file, location.getStartPosition(), location.getLength(), newText);
- }
- }else{
- String newText = "(\""+getNewName()+"\")"; //$NON-NLS-1$
//$NON-NLS-2$
- change(file, location.getStartPosition()+location.getLength(), 0, newText);
- }
+
+ String newText = "@Named(\""+getNewName()+"\")";
//$NON-NLS-1$ //$NON-NLS-2$
+ change(declarationFile, nameLocation.getStartPosition(), nameLocation.getLength(),
newText);
}
-
- private void changeDeclarations(IBean bean) throws CoreException{
- }
- protected void checkDeclarations(IBean bean) throws CoreException{
- }
-
protected boolean isFileCorrect(IFile file){
if(!file.isSynchronized(IResource.DEPTH_ZERO)){
status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE,
file.getFullPath().toString()));
@@ -220,6 +142,8 @@
clearChanges();
+ this.bean = bean;
+
findDeclarations(bean);
if(status.hasFatalError())
@@ -251,7 +175,7 @@
class CDISearcher extends RefactorSearcher{
public CDISearcher(IFile declarationFile, String oldName){
- super(declarationFile, oldName);
+ super(declarationFile, oldName, bean.getBeanClass());
}
@Override
@@ -285,11 +209,16 @@
@Override
protected IProject[] getProjects() {
- return null;
+ return new IProject[]{baseFile.getProject()};
}
-
+
@Override
protected IContainer getViewFolder(IProject project) {
+ IPath path = ProjectHome.getFirstWebContentPath(baseFile.getProject());
+
+ if(path != null)
+ return project.getFolder(path.removeFirstSegments(1));
+
return null;
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java 2010-04-05
14:42:59 UTC (rev 21264)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java 2010-04-05
14:52:52 UTC (rev 21265)
@@ -18,8 +18,8 @@
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
-import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.IBean;
/**
@@ -56,13 +56,8 @@
OperationCanceledException {
status = new RefactoringStatus();
if(bean != null){
- checkDeclarations(bean);
+ rootChange = new CompositeChange(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_TITLE);
- if(status.hasFatalError())
- return status;
-
- rootChange = new CompositeChange("Rename @Named Bean");
-
renameBean(pm, bean);
}
return status;
@@ -77,7 +72,7 @@
throws CoreException, OperationCanceledException {
RefactoringStatus result = new RefactoringStatus();
if(bean==null) {
- result.addFatalError("This is not a @Named Bean");
+ result.addFatalError(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_ERROR);
}
return result;
}
@@ -118,7 +113,7 @@
*/
@Override
public String getProcessorName() {
- return "Rename @Named Bean";
+ return CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_TITLE;
}
/*