Author: dazarov
Date: 2009-06-26 10:57:39 -0400 (Fri, 26 Jun 2009)
New Revision: 16223
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameSeamContextVariableProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
Log:
Rename Seam Context Variable
https://jira.jboss.org/jira/browse/JBIDE-1077
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java 2009-06-26
11:28:27 UTC (rev 16222)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreMessages.java 2009-06-26
14:57:39 UTC (rev 16223)
@@ -44,6 +44,7 @@
public static String RENAME_SEAM_COMPONENT_PROCESSOR_TITLE;
public static String RENAME_SEAM_COMPONENT_PROCESSOR_THIS_IS_NOT_A_SEAM_COMPONENT;
public static String RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_TITLE;
+ public static String
RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_CAN_NOT_FIND_CONTEXT_VARIABLE;
public static String SEAM_RENAME_PROCESSOR_COMPONENT_HAS_DECLARATION_FROM_JAR;
public static String SEAM_RENAME_PROCESSOR_OUT_OF_SYNC_FILE;
public static String SEAM_RENAME_PROCESSOR_ERROR_PHANTOM_FILE;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties 2009-06-26
11:28:27 UTC (rev 16222)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/messages.properties 2009-06-26
14:57:39 UTC (rev 16223)
@@ -32,6 +32,7 @@
RENAME_SEAM_COMPONENT_PROCESSOR_TITLE=Rename Seam Component
RENAME_SEAM_COMPONENT_PROCESSOR_THIS_IS_NOT_A_SEAM_COMPONENT=This is not a Seam
Component.
RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_TITLE=Rename Seam Context Variable
+RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_CAN_NOT_FIND_CONTEXT_VARIABLE=Can not find Seam
Context Variable: ''{0}''.
SEAM_RENAME_PROCESSOR_COMPONENT_HAS_DECLARATION_FROM_JAR=Component
''{0}'' has a declaration which is located in jar file:
''{1}''. Press next to force rename.
SEAM_RENAME_PROCESSOR_OUT_OF_SYNC_FILE=File ''{0}'' is not in sync. Press
next to force rename.
SEAM_RENAME_PROCESSOR_ERROR_PHANTOM_FILE=Cannot change phantom file:
''{0}''.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameSeamContextVariableProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameSeamContextVariableProcessor.java 2009-06-26
11:28:27 UTC (rev 16222)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/RenameSeamContextVariableProcessor.java 2009-06-26
14:57:39 UTC (rev 16223)
@@ -23,6 +23,9 @@
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.eclipse.ltk.internal.core.refactoring.Messages;
+import org.jboss.tools.seam.core.BijectedAttributeType;
+import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamContextShortVariable;
import org.jboss.tools.seam.core.ISeamContextVariable;
@@ -30,12 +33,15 @@
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCoreMessages;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamProjectsSet;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
/**
* @author Daniel Azarov
*/
public class RenameSeamContextVariableProcessor extends SeamRenameProcessor {
IFile file;
+ private ISeamComponent component;
/**
* @param file where refactor was called
*/
@@ -54,17 +60,14 @@
CheckConditionsContext context) throws CoreException,
OperationCanceledException {
status = new RefactoringStatus();
- ISeamComponent component = checkComponent();
+
+ rootChange = new
CompositeChange(SeamCoreMessages.RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_TITLE);
if(component != null){
checkDeclarations(component);
- rootChange = new
CompositeChange(SeamCoreMessages.RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_TITLE);
-
renameComponent(pm, component);
}else{
- Set<ISeamFactory> factories = checkFactories();
- if(factories != null)
- renameFactories(pm, factories);
+ renameSeamContextVariable(pm, file);
}
return status;
}
@@ -77,6 +80,16 @@
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException {
RefactoringStatus result = new RefactoringStatus();
+ boolean status = false;
+ component = checkComponent();
+
+ if(component == null){
+ status = checkContextVariable();
+ }else{
+ setOldName(component.getName());
+ }
+ if(component == null && !status)
+ result.addFatalError(Messages.format(SeamCoreMessages.RENAME_SEAM_CONTEXT_VARIABLE_PROCESSOR_CAN_NOT_FIND_CONTEXT_VARIABLE,
getOldName()));
return result;
}
@@ -88,33 +101,41 @@
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
-
-
return rootChange;
}
- private boolean checked = false;
-
- public String getOldName(){
- if(!checked){
- ISeamComponent component = checkComponent();
- if(component != null){
- setOldName(component.getName());
+ private ISeamComponent checkComponent(){
+ ISeamComponent comp;
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(file.getProject(), true);
+ projectsSet = new SeamProjectsSet(file.getProject());
+
+ comp = checkComponent(seamProject);
+ if(comp != null)
+ return comp;
+
+ IProject[] projects = projectsSet.getAllProjects();
+ for (IProject project : projects) {
+ ISeamProject sProject = SeamCorePlugin.getSeamProject(project, true);
+ if(sProject != null){
+ comp = checkComponent(sProject);
+ if(comp != null)
+ return comp;
}
- checked = true;
}
- return super.getOldName();
+ return null;
}
- private ISeamComponent checkComponent(){
- IProject project = file.getProject();
- ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ private ISeamComponent checkComponent(ISeamProject seamProject){
if (seamProject != null) {
- ISeamComponent component = seamProject.getComponent(super.getOldName());
+ ISeamComponent component = seamProject.getComponent(getOldName());
if(component != null)
return component;
- Set<ISeamContextVariable> variables =
seamProject.getVariablesByName(super.getOldName());
+ Set<ISeamContextVariable> variables =
seamProject.getVariablesByName(getOldName());
+
+ if(variables == null)
+ return null;
+
for(ISeamContextVariable variable : variables){
if(variable instanceof ISeamContextShortVariable){
ISeamContextVariable original =
((ISeamContextShortVariable)variable).getOriginal();
@@ -126,15 +147,67 @@
return null;
}
- private Set<ISeamFactory> checkFactories(){
- IProject project = file.getProject();
- ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ private boolean checkContextVariable(){
+ boolean status = false;
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(file.getProject(), true);
+
+ status = checkFactories(seamProject);
+ if(status)
+ return status;
+
+ status = checkOuts(seamProject);
+ if(status)
+ return status;
+
+ status = checkDataModels(seamProject);
+ if(status)
+ return status;
+
+ IProject[] projects = projectsSet.getAllProjects();
+ for (IProject project : projects) {
+ ISeamProject sProject = SeamCorePlugin.getSeamProject(project, true);
+ if(sProject != null){
+ status = checkFactories(sProject);
+ if(status)
+ return status;
+
+ status = checkOuts(sProject);
+ if(status)
+ return status;
+
+ status = checkDataModels(sProject);
+ if(status)
+ return status;
+ }
+ }
+ return status;
+ }
+
+ private boolean checkFactories(ISeamProject seamProject){
if (seamProject != null) {
- return seamProject.getFactoriesByName(getOldName());
+ return seamProject.getFactoriesByName(getOldName()) != null;
}
- return null;
+ return false;
}
+ private boolean checkOuts(ISeamProject seamProject){
+ if (seamProject != null) {
+ Set<IBijectedAttribute> variables =
seamProject.getBijectedAttributesByName(getOldName(), BijectedAttributeType.OUT);
+
+ return variables != null;
+ }
+ return false;
+ }
+
+ private boolean checkDataModels(ISeamProject seamProject){
+ if (seamProject != null) {
+ Set<IBijectedAttribute> variables =
seamProject.getBijectedAttributesByName(getOldName(), BijectedAttributeType.DATA_BINDER);
+
+ return variables != null;
+ }
+ return false;
+ }
+
/*
* (non-Javadoc)
* @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-06-26
11:28:27 UTC (rev 16222)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-06-26
14:57:39 UTC (rev 16223)
@@ -166,24 +166,40 @@
return;
files.clear();
- findAnnotations(seamProject, true);
+ findInFactoryAnnotations(seamProject, true);
IProject[] projects = projectsSet.getAllProjects();
for (IProject project : projects) {
ISeamProject sProject = SeamCorePlugin.getSeamProject(project, true);
if(sProject != null){
- findAnnotations(sProject, false);
+ findInFactoryAnnotations(sProject, false);
}
}
}
- private void findAnnotations(ISeamProject seamProject, boolean force){
+ private void findInFactoryAnnotations(ISeamProject seamProject, boolean force){
// find @In annotations
- Set<IBijectedAttribute> inSet =
seamProject.getBijectedAttributesByName(getOldName(), BijectedAttributeType.IN);
+ findAnnotations(seamProject, force, BijectedAttributeType.IN,
SeamAnnotations.IN_ANNOTATION_TYPE);
+
+ findFactories(seamProject, force);
+ }
+
+ private void findFactories(ISeamProject seamProject, boolean force){
+ // find @Factory annotations
+ Set<ISeamFactory> factorySet = seamProject.getFactoriesByName(getOldName());
+
+ for(ISeamFactory factory : factorySet){
+ changeFactory(factory, force);
+ }
+ }
+
+ private void findAnnotations(ISeamProject seamProject, boolean force,
BijectedAttributeType type, String locationPath){
+ Set<IBijectedAttribute> inSet =
seamProject.getBijectedAttributesByName(getOldName(), type);
+
for(IBijectedAttribute inAtt : inSet){
- ITextSourceReference location =
inAtt.getLocationFor(SeamAnnotations.IN_ANNOTATION_TYPE);
+ ITextSourceReference location = inAtt.getLocationFor(locationPath);
if(location != null){
if(!files.contains(inAtt.getResource().getFullPath())){
files.add(inAtt.getResource().getFullPath());
@@ -192,17 +208,11 @@
changeAnnotation(location, (IFile)inAtt.getResource());
}
}
-
- // find @Factory annotations
- Set<ISeamFactory> factorySet = seamProject.getFactoriesByName(getOldName());
-
- for(ISeamFactory factory : factorySet){
- changeFactory(factory, force);
- }
}
private void changeFactory(ISeamFactory factory, boolean force){
IFile file = (IFile)factory.getResource();
+
if(file.getFileExtension().equalsIgnoreCase(JAVA_EXT)){
ITextSourceReference location =
factory.getLocationFor(SeamAnnotations.FACTORY_ANNOTATION_TYPE);
if(location != null){
@@ -692,8 +702,45 @@
pm.worked(1);
}
+ pm.done();
+ }
+
+ protected void renameSeamContextVariable(IProgressMonitor pm, IFile sourceFile)throws
CoreException{
+ pm.beginTask("", 2);
+
+ declarationFile = sourceFile;
+
+ findOutDataModelFactory();
+
+ pm.worked(1);
+
findELReferences();
pm.done();
}
+
+ protected void findOutDataModelFactory(){
+ if(declarationFile == null)
+ return;
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(declarationFile.getProject(),
true);
+
+ if(seamProject == null)
+ return;
+
+ files.clear();
+ findAnnotations(seamProject, true, BijectedAttributeType.OUT,
SeamAnnotations.OUT_ANNOTATION_TYPE);
+ findAnnotations(seamProject, true, BijectedAttributeType.DATA_BINDER,
"name"/*SeamAnnotations.DATA_MODEL_ANNOTATION_TYPE*/);
+ findFactories(seamProject, true);
+
+ IProject[] projects = projectsSet.getAllProjects();
+ for (IProject project : projects) {
+ ISeamProject sProject = SeamCorePlugin.getSeamProject(project, true);
+ if(sProject != null){
+ findAnnotations(sProject, false, BijectedAttributeType.OUT,
SeamAnnotations.OUT_ANNOTATION_TYPE);
+ findAnnotations(sProject, false, BijectedAttributeType.DATA_BINDER,
"name"/*SeamAnnotations.DATA_MODEL_ANNOTATION_TYPE*/);
+ findFactories(sProject, false);
+ }
+ }
+ }
}