Author: dazarov
Date: 2011-12-07 17:31:16 -0500 (Wed, 07 Dec 2011)
New Revision: 37085
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AbstractCDIProcessor.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AddQualifiersToBeanProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRefactoringProcessor.java
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:
EL refactoring for @Named beans doesn't work properly
https://issues.jboss.org/browse/JBIDE-10210
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AbstractCDIProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AbstractCDIProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AbstractCDIProcessor.java 2011-12-07
22:31:16 UTC (rev 37085)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.internal.core.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+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.eclipse.osgi.util.NLS;
+import org.jboss.tools.cdi.core.CDICoreMessages;
+
+public abstract class AbstractCDIProcessor extends RenameProcessor {
+ private static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
+
+ protected RefactoringStatus status;
+
+ protected CompositeChange rootChange;
+
+ private String label;
+
+ public AbstractCDIProcessor(String label){
+ this.label = label;
+ }
+
+ @Override
+ public String getProcessorName() {
+ return label;
+ }
+
+ @Override
+ public boolean isApplicable() throws CoreException {
+ return true;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+
+ return rootChange;
+ }
+
+ @Override
+ public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
+ SharableParticipants sharedParticipants) throws CoreException {
+ return EMPTY_REF_PARTICIPANT;
+ }
+
+ public String getLabel(){
+ return label;
+ }
+
+ protected boolean isFileCorrect(IFile file){
+ if(file == null){
+ status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_FILE_NOT_FOUND);
+ return false;
+ }else if(!file.isSynchronized(IResource.DEPTH_ZERO)){
+ status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_OUT_OF_SYNC_PROJECT,
file.getProject().getFullPath().toString()));
+ return false;
+ }else if(file.isPhantom()){
+ status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isReadOnly()){
+ status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return getClass().getName();
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AbstractCDIProcessor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AddQualifiersToBeanProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AddQualifiersToBeanProcessor.java 2011-12-07
22:13:59 UTC (rev 37084)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/AddQualifiersToBeanProcessor.java 2011-12-07
22:31:16 UTC (rev 37085)
@@ -14,14 +14,10 @@
import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
@@ -81,20 +77,10 @@
return status;
}
- private ICompilationUnit getCompilationUnit(IFile file) throws CoreException{
- IProject project = file.getProject();
- IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
- IJavaElement element = javaProject.findElement(file.getProjectRelativePath());
- if(element instanceof ICompilationUnit)
- return (ICompilationUnit)element;
-
- return null;
- }
-
@Override
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- rootChange = new CompositeChange(label);
+ rootChange = new CompositeChange(getLabel());
IFile file = (IFile)selectedBean.getBeanClass().getResource();
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRefactoringProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRefactoringProcessor.java 2011-12-07
22:13:59 UTC (rev 37084)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRefactoringProcessor.java 2011-12-07
22:31:16 UTC (rev 37085)
@@ -13,18 +13,12 @@
import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
-import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
-import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.MultiTextEdit;
import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.CDICoreNature;
@@ -33,28 +27,23 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
-public abstract class CDIRefactoringProcessor extends RefactoringProcessor {
- protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
+public abstract class CDIRefactoringProcessor extends AbstractCDIProcessor {
protected IFile file;
- protected RefactoringStatus status;
- protected String label;
- protected CompositeChange rootChange;
protected TextFileChange change;
protected IClassBean bean;
-
public CDIRefactoringProcessor(IFile file, String label){
- this(label);
+ super(label);
this.file = file;
}
public CDIRefactoringProcessor(String label){
- this.label = label;
+ super(label);
}
protected void createRootChange(){
- rootChange = new CompositeChange(label);
+ rootChange = new CompositeChange(getLabel());
change = new CDIFileChange(file.getName(), file);
if(CDIFileChange.getAndReloadEditor(file) != null)
@@ -68,7 +57,6 @@
rootChange.markAsSynthetic();
}
-
private IClassBean findClassBean(){
CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
if(cdiNature == null)
@@ -88,23 +76,6 @@
return null;
}
-
- protected boolean isFileCorrect(IFile file){
- if(file == null){
- status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_FILE_NOT_FOUND);
- return false;
- }else if(!file.isSynchronized(IResource.DEPTH_ZERO)){
- status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_OUT_OF_SYNC_PROJECT,
file.getProject().getFullPath().toString()));
- return false;
- }else if(file.isPhantom()){
- status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
- return false;
- }else if(file.isReadOnly()){
- status.addFatalError(NLS.bind(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
- return false;
- }
- return true;
- }
@Override
public Object[] getElements() {
@@ -112,21 +83,6 @@
}
@Override
- public String getIdentifier() {
- return "";
- }
-
- @Override
- public String getProcessorName() {
- return label;
- }
-
- @Override
- public boolean isApplicable() throws CoreException {
- return true;
- }
-
- @Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
throws CoreException, OperationCanceledException {
status = new RefactoringStatus();
@@ -138,16 +94,4 @@
return status;
}
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
- return rootChange;
- }
-
- @Override
- public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
- SharableParticipants sharedParticipants) throws CoreException {
- return EMPTY_REF_PARTICIPANT;
- }
}
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 2011-12-07
22:13:59 UTC (rev 37084)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/CDIRenameProcessor.java 2011-12-07
22:31:16 UTC (rev 37085)
@@ -18,11 +18,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
-import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
@@ -32,18 +30,12 @@
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.jst.web.kb.refactoring.RefactorSearcher;
/**
* @author Daniel Azarov
*/
-public abstract class CDIRenameProcessor extends RenameProcessor {
- protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
-
- protected RefactoringStatus status;
-
- protected CompositeChange rootChange;
+public abstract class CDIRenameProcessor extends AbstractCDIProcessor {
protected TextFileChange lastChange;
protected IFile declarationFile=null;
@@ -52,7 +44,23 @@
private CDISearcher searcher = null;
protected IBean bean;
+
+ public CDIRenameProcessor(String label, IBean bean) {
+ super(label);
+ this.bean = bean;
+ setOldName(bean.getName());
+ }
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+ RefactoringStatus result = new RefactoringStatus();
+ if(bean==null) {
+ result.addFatalError(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_ERROR);
+ }
+ return result;
+ }
+
protected CDISearcher getSearcher(){
if(searcher == null){
searcher = new CDISearcher(declarationFile, getOldName());
@@ -102,64 +110,15 @@
return lastChange;
}
- protected void findDeclarations(IBean bean) throws CoreException{
- changeDeclarations(bean);
- }
- private void changeDeclarations(IBean bean) throws CoreException{
- declarationFile = (IFile)bean.getResource();
-
- if(declarationFile == null){
- status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_FILE);
- return;
- }
-
- //1. Get @Named declared directly, not in stereotype.
- ITextSourceReference nameLocation = bean.getNameLocation(false);
- //2. Get stereotype declaration declaring @Named, if @Named is not declared directly.
- ITextSourceReference stereotypeLocation = nameLocation != null ? null :
bean.getNameLocation(true);
-
- if(nameLocation == null && stereotypeLocation == null) {
- status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_NAME_LOCATION);
- return;
- }
-
- String newText = "@Named(\""+getNewName()+"\")";
//$NON-NLS-1$ //$NON-NLS-2$
- if(nameLocation != null) {
- change(declarationFile, nameLocation.getStartPosition(), nameLocation.getLength(),
newText);
- } else if(stereotypeLocation != null) {
- change(declarationFile, stereotypeLocation.getStartPosition() +
stereotypeLocation.getLength(), 0, " " + newText);
- }
- }
-
- protected void renameBean(IProgressMonitor pm, IBean bean)throws CoreException{
- pm.beginTask("", 3);
-
- clearChanges();
-
- this.bean = bean;
-
- findDeclarations(bean);
-
- if(status.hasFatalError())
- return;
-
- pm.worked(1);
-
- getSearcher().findELReferences();
-
- pm.done();
- }
-
ArrayList<String> keys = new ArrayList<String>();
- private void clearChanges(){
+ protected void clearChanges(){
keys.clear();
}
- private void change(IFile file, int offset, int length, String text){
- //System.out.println("change file - "+file.getFullPath()+" offset -
"+offset+" len - "+length+" text"+text);
+ protected void change(IFile file, int offset, int length, String text){
String key = file.getFullPath().toString()+" "+offset;
if(!keys.contains(key)){
TextFileChange change = getChange(file);
@@ -221,4 +180,14 @@
return null;
}
}
+
+ @Override
+ public boolean isApplicable() throws CoreException {
+ return bean!=null;
+ }
+
+ @Override
+ public Object[] getElements() {
+ return new IBean[]{bean};
+ }
}
\ No newline at end of file
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 2011-12-07
22:13:59 UTC (rev 37084)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/RenameNamedBeanProcessor.java 2011-12-07
22:31:16 UTC (rev 37085)
@@ -10,46 +10,29 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.refactoring;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
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.SharableParticipants;
import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.common.text.ITextSourceReference;
/**
* @author Daniel Azarov
*/
public class RenameNamedBeanProcessor extends CDIRenameProcessor {
- private IBean bean;
+
/**
- * @param component Renamed component
+ * @param bean Renamed bean
*/
public RenameNamedBeanProcessor(IBean bean) {
- super();
- setBean(bean);
+ super(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_TITLE, bean);
}
- public IBean getBean() {
- return bean;
- }
-
- public void setBean(IBean bean) {
- this.bean = bean;
- setOldName(bean.getName());
- }
-
-
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor,
org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
- */
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
CheckConditionsContext context) throws CoreException,
@@ -58,80 +41,52 @@
if(bean != null){
rootChange = new CompositeChange(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_TITLE);
- renameBean(pm, bean);
+ renameBean(pm);
}
return status;
}
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
- throws CoreException, OperationCanceledException {
- RefactoringStatus result = new RefactoringStatus();
- if(bean==null) {
- result.addFatalError(CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_ERROR);
- }
- return result;
+ private void renameBean(IProgressMonitor pm)throws CoreException{
+ pm.beginTask("", 3);
+
+ clearChanges();
+
+ changeDeclarations();
+
+ if(status.hasFatalError())
+ return;
+
+ pm.worked(1);
+
+ getSearcher().findELReferences();
+
+ pm.done();
}
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
+ private void changeDeclarations() throws CoreException{
+ declarationFile = (IFile)bean.getResource();
- return rootChange;
+ if(declarationFile == null){
+ status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_FILE);
+ return;
+ }
+
+ //1. Get @Named declared directly, not in stereotype.
+ ITextSourceReference nameLocation = bean.getNameLocation(false);
+ //2. Get stereotype declaration declaring @Named, if @Named is not declared directly.
+ ITextSourceReference stereotypeLocation = nameLocation != null ? null :
bean.getNameLocation(true);
+
+ if(nameLocation == null && stereotypeLocation == null) {
+ status.addFatalError(CDICoreMessages.CDI_RENAME_PROCESSOR_BEAN_HAS_NO_NAME_LOCATION);
+ return;
+ }
+
+ String newText = "@Named(\""+getNewName()+"\")";
//$NON-NLS-1$ //$NON-NLS-2$
+ if(nameLocation != null) {
+ change(declarationFile, nameLocation.getStartPosition(), nameLocation.getLength(),
newText);
+ } else if(stereotypeLocation != null) {
+ change(declarationFile, stereotypeLocation.getStartPosition() +
stereotypeLocation.getLength(), 0, " " + newText);
+ }
}
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
- */
- @Override
- public Object[] getElements() {
- return new IBean[]{bean};
- }
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
- */
- @Override
- public String getIdentifier() {
- return getClass().getName();
- }
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
- */
- @Override
- public String getProcessorName() {
- return CDICoreMessages.RENAME_NAMED_BEAN_PROCESSOR_TITLE;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
- */
- @Override
- public boolean isApplicable() throws CoreException {
- return bean!=null;
- }
-
- /*
- * (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#loadParticipants(org.eclipse.ltk.core.refactoring.RefactoringStatus,
org.eclipse.ltk.core.refactoring.participants.SharableParticipants)
- */
- @Override
- public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
- SharableParticipants sharedParticipants) throws CoreException {
- return EMPTY_REF_PARTICIPANT;
- }
}
\ No newline at end of file